Permalink
Browse files

CLJS-804: Binding *print-length* breaks str

fix pr-sequential-writer to properly handle :print-length option
  • Loading branch information...
1 parent 56ea020 commit 337d30cf3a98a0c28f658e230855fc2e09abdeaa @swannodette swannodette committed May 10, 2014
Showing with 24 additions and 8 deletions.
  1. +9 −8 src/cljs/cljs/core.cljs
  2. +15 −0 test/cljs/cljs/core_test.cljs
View
17 src/cljs/cljs/core.cljs
@@ -6800,14 +6800,15 @@ reduces them without incurring seq initialization"
(-write writer begin)
(when (seq coll)
(print-one (first coll) writer opts))
- (loop [coll (next coll) n (:print-length opts)]
- (when (and coll (or (nil? n) (not (zero? n))))
- (-write writer sep)
- (print-one (first coll) writer opts)
- (recur (next coll) (dec n))))
- (when (:print-length opts)
- (-write writer sep)
- (print-one "..." 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 "..."))))
(-write writer end)))))
(defn write-all [writer & ss]
View
15 test/cljs/cljs/core_test.cljs
@@ -2194,5 +2194,20 @@
(-rest [this] (make-seq (rest from-seq))))))
[[: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
)

0 comments on commit 337d30c

Please sign in to comment.