Skip to content

Commit 3ad83e9

Browse files
committed
Miser width tests
1 parent b8ef8f1 commit 3ad83e9

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/basilisp/pprint.lpy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162

163163
(deftype Indent [block relative-to offset start end]
164164
(__repr__ [self]
165-
(str [(python/id block) relative-to offset])))
165+
(str [:indent (python/id block) relative-to offset])))
166166

167167
(deftype Newline [block kind start end]
168168
(__repr__ [self]
@@ -284,7 +284,7 @@
284284
max-col (:max @writer)]
285285
(and miser-width
286286
max-col
287-
(>= (.-start-col (.-block token)) (- max miser-width))
287+
(>= (.-start-col (.-block token)) (- max-col miser-width))
288288
(emit-linear-nl? token section)))
289289
;; TODO: figure out how to handle these newline types
290290
:fill nil))

tests/basilisp/test_pprint.lpy

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,41 @@
283283
28
284284
29)"] (match-ideref v))))))
285285

286+
(defmulti miser-dispatch type)
287+
288+
(defmethod miser-dispatch :default
289+
[o]
290+
(pr o))
291+
292+
(defmethod miser-dispatch basilisp.lang.interfaces/IPersistentVector
293+
[o]
294+
(pprint/pprint-logical-block :prefix "[" :suffix "]"
295+
(pprint/print-length-loop [binding o]
296+
(when (seq binding)
297+
(pprint/pprint-logical-block
298+
(pprint/write-out (first binding))
299+
(when (next binding)
300+
(.write *out* " ")
301+
(pprint/pprint-newline :miser)
302+
(pprint/write-out (second binding))))
303+
(when-let [remaining (next (rest binding))]
304+
(.write *out* " ")
305+
(pprint/pprint-newline :linear)
306+
(recur remaining))))))
307+
308+
(deftest pprint-miser-test
309+
(binding [pprint/*print-pprint-dispatch* miser-dispatch]
310+
(are [res margin] (= res (str/rtrim
311+
(binding [pprint/*print-right-margin* margin]
312+
(with-out-str
313+
(pprint/pprint [:abcdefghijklmnop [:abcdefghijklmn :a]])))))
314+
"[:abcdefghijklmnop
315+
[:abcdefghijklmn
316+
:a]]" 20
317+
"[:abcdefghijklmnop
318+
[:abcdefghijklmn :a]]" 25
319+
"[:abcdefghijklmnop [:abcdefghijklmn :a]]" 50)))
320+
286321
(deftest pprint-print-level-test
287322
(are [res plen expr] (= res (str/rtrim
288323
(binding [*print-level* plen]

0 commit comments

Comments
 (0)