Skip to content

Commit

Permalink
CLJS-804: Binding *print-length* breaks str
Browse files Browse the repository at this point in the history
fix pr-sequential-writer to properly handle :print-length option
  • Loading branch information
swannodette committed May 10, 2014
1 parent 56ea020 commit 337d30c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/cljs/cljs/core.cljs
Expand Up @@ -6800,14 +6800,15 @@ reduces them without incurring seq initialization"
(-write writer begin) (-write writer begin)
(when (seq coll) (when (seq coll)
(print-one (first coll) writer opts)) (print-one (first coll) writer opts))
(loop [coll (next coll) n (:print-length opts)] (loop [coll (next coll) n (dec (:print-length opts))]
(when (and coll (or (nil? n) (not (zero? n)))) (if (and coll (or (nil? n) (not (zero? n))))
(-write writer sep) (do
(print-one (first coll) writer opts) (-write writer sep)
(recur (next coll) (dec n)))) (print-one (first coll) writer opts)
(when (:print-length opts) (recur (next coll) (dec n)))
(-write writer sep) (when (and (seq coll) (zero? n))
(print-one "..." writer opts)) (-write writer sep)
(-write writer "..."))))
(-write writer end))))) (-write writer end)))))


(defn write-all [writer & ss] (defn write-all [writer & ss]
Expand Down
15 changes: 15 additions & 0 deletions test/cljs/cljs/core_test.cljs
Expand Up @@ -2194,5 +2194,20 @@
(-rest [this] (make-seq (rest from-seq)))))) (-rest [this] (make-seq (rest from-seq))))))
[[:bar 2] [:baz 3]]))))) [[:bar 2] [:baz 3]])))))


;; printing customization
(assert (= (binding [*print-length* 1] (str [1 2 3 4 5 6 7 8 9 0]))
"[1 ...]"))
(assert (= (binding [*print-length* 2] (str [1 2 3 4 5 6 7 8 9 0]))
"[1 2 ...]"))
(assert (= (binding [*print-length* 10] (str [1 2 3 4 5 6 7 8 9 0]))
"[1 2 3 4 5 6 7 8 9 0]"))
;; CLJS-804
(assert (= (binding [*print-length* 10] (str {:foo "bar"}))
"{:foo \"bar\"}"))
(assert (= (binding [*print-length* 1] (str {:foo "bar" :baz "woz"}))
"{:foo \"bar\", ...}"))
(assert (= (binding [*print-length* 10] (str {:foo "bar" :baz "woz"}))
"{:foo \"bar\", :baz \"woz\"}"))

:ok :ok
) )

0 comments on commit 337d30c

Please sign in to comment.