Skip to content

Commit

Permalink
Add some tests for parse-stream-strict.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauli Jaakkola committed Feb 8, 2019
1 parent b980d98 commit e19bc5a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions test/cheshire/test/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,23 @@
(is (= "{\"foo\":\"a\"}" (json/encode {:foo \a}))))

(deftest test-streams
(is (= {"foo" "bar"}
(json/parse-stream
(BufferedReader. (StringReader. "{\"foo\":\"bar\"}\n")))))
(let [sw (StringWriter.)
bw (BufferedWriter. sw)]
(json/generate-stream {"foo" "bar"} bw)
(is (= "{\"foo\":\"bar\"}" (.toString sw))))
(is (= {(keyword "foo baz") "bar"}
(with-open [rdr (StringReader. "{\"foo baz\":\"bar\"}\n")]
(json/parse-stream rdr true)))))
(testing "parse-stream"
(are [parsed parse parsee] (= parsed
(parse (BufferedReader. (StringReader. parsee))))
{"foo" "bar"} json/parse-stream "{\"foo\":\"bar\"}\n"
{"foo" "bar"} json/parse-stream-strict "{\"foo\":\"bar\"}\n")

(are [parsed parse parsee] (= parsed
(with-open [rdr (StringReader. parsee)]
(parse rdr true)))
{(keyword "foo baz") "bar"} json/parse-stream "{\"foo baz\":\"bar\"}\n"
{(keyword "foo baz") "bar"} json/parse-stream-strict "{\"foo baz\":\"bar\"}\n"))

(testing "generate-stream"
(let [sw (StringWriter.)
bw (BufferedWriter. sw)]
(json/generate-stream {"foo" "bar"} bw)
(is (= "{\"foo\":\"bar\"}" (.toString sw))))))

(deftest serial-writing
(is (= "[\"foo\",\"bar\"]"
Expand Down

0 comments on commit e19bc5a

Please sign in to comment.