Skip to content

Commit

Permalink
Correct behavior when *print-length* is set to 0
Browse files Browse the repository at this point in the history
Consistent with Clojure 1.6.0
  • Loading branch information
darwin committed Feb 6, 2015
1 parent a3c9683 commit fc7c91c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/cljs/cljs/core.cljs
Expand Up @@ -8109,17 +8109,21 @@ reduces them without incurring seq initialization"
(-write writer "#")
(do
(-write writer begin)
(when (seq coll)
(print-one (first coll) writer opts))
(loop [coll (next coll) n (dec (:print-length opts))]
(if (and coll (or (nil? n) (not (zero? n))))
(do
(-write writer sep)
(print-one (first coll) writer opts)
(recur (next coll) (dec n)))
(when (and (seq coll) (zero? n))
(-write writer sep)
(-write writer (or (:more-text opts) "...")))))
(if (zero? (:print-length opts))
(if (seq coll)
(-write writer (or (:more-text opts) "...")))
(do
(when (seq coll)
(print-one (first coll) writer opts))
(loop [coll (next coll) n (dec (:print-length opts))]
(if (and coll (or (nil? n) (not (zero? n))))
(do
(-write writer sep)
(print-one (first coll) writer opts)
(recur (next coll) (dec n)))
(when (and (seq coll) (zero? n))
(-write writer sep)
(-write writer (or (:more-text opts) "...")))))))
(-write writer end)))))

(defn write-all [writer & ss]
Expand Down
4 changes: 4 additions & 0 deletions test/cljs/cljs/core_test.cljs
Expand Up @@ -1472,6 +1472,8 @@

(deftest test-print-knobs
(testing "Testing printing knobs"
(is (= (binding [*print-length* 0] (str [1 2 3 4 5 6 7 8 9 0]))
"[...]"))
(is (= (binding [*print-length* 1] (str [1 2 3 4 5 6 7 8 9 0]))
"[1 ...]"))
(is (= (binding [*print-length* 2] (str [1 2 3 4 5 6 7 8 9 0]))
Expand All @@ -1481,6 +1483,8 @@
;; CLJS-804
(is (= (binding [*print-length* 10] (str {:foo "bar"}))
"{:foo \"bar\"}"))
(is (= (binding [*print-length* 0] (str {:foo "bar" :baz "woz"}))
"{...}"))
(is (= (binding [*print-length* 1] (str {:foo "bar" :baz "woz"}))
"{:foo \"bar\", ...}"))
(is (= (binding [*print-length* 10] (str {:foo "bar" :baz "woz"}))
Expand Down

0 comments on commit fc7c91c

Please sign in to comment.