Skip to content

Commit

Permalink
remove duplication in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
puredanger committed Nov 26, 2024
1 parent 101354d commit dbff2f7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/test/clojure/clojure/data/json_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
[clojure.test :refer :all]
[clojure.string :as str]))

(defn pbr
([s]
(pbr s 64))
([s size]
(if (< size 64)
(throw (RuntimeException. "Size must be >= 64"))
(java.io.PushbackReader. (java.io.StringReader. s) size))))

(deftest read-from-pushback-reader
(let [s (java.io.PushbackReader. (java.io.StringReader. "42"))]
(is (= 42 (json/read s)))))
(is (= 42 (json/read (pbr "42"))))
(is (= ["abc" "def"] (json/read (pbr "[\"abc\", \"def\"]")))))

;; DJSON-50 - pass PBR to safely do reapeated read
;; DJSON-50 - pass PBR to safely do repeated read
(deftest read-multiple
(let [st "{\"foo\":\"some string\"}{\"foo\":\"another string\"}"
srdr (java.io.StringReader. st)
pbr (java.io.PushbackReader. srdr 64)]
pbr (pbr st)]
(is (= {"foo" "some string"} (json/read pbr)))
(is (= {"foo" "another string"} (json/read pbr))))

(let [st "{\"foo\":\"some string\"}{\"foo\":\"another long ......................................................... string\"}"
srdr (java.io.StringReader. st)
pbr (java.io.PushbackReader. srdr 64)]
pbr (pbr st)]
(is (= {"foo" "some string"} (json/read pbr)))
(is (= {"foo" "another long ......................................................... string"} (json/read pbr)))))

Expand Down

0 comments on commit dbff2f7

Please sign in to comment.