Skip to content

Commit 06722b5

Browse files
committed
More tests and fixes
1 parent 055d43b commit 06722b5

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/basilisp/pprint.lpy

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,9 @@
206206
[buffer]
207207
(let [nl (first buffer)
208208
block (.-block nl)
209-
;;_ (pdebug "nl-block=" (python/id (.-block nl)) " " (.-block nl))
210209
comparator (fn [token]
211-
(if (instance? Newline token)
212-
(let [is-ancestor? (ancestor? (.-block token) block)]
213-
#_(pdebug "token=" [(.-kind token) (.-block token)]
214-
" block=" block
215-
" is-ancestor?=" is-ancestor?)
216-
is-ancestor?)
217-
false))]
210+
(and (instance? Newline token)
211+
(ancestor? (.-block token) block)))]
218212
(split-queue-with comparator (pop buffer))))
219213

220214
(defprotocol PrettyWriter
@@ -300,19 +294,16 @@
300294
EndBlock (.-suffix (.-block token)))]
301295
(.write writer s))))
302296

303-
;; Write a single line and possibly emit a trailing conditional newline.
297+
;; Write a single line and possibly emit a conditional newline.
304298
(write-line []
305299
(let [{:keys [buffer]} @state
306300
[s buf] (split-at-newline buffer)]
307-
#_(pdebug {:buffer (map repr buf) :s (map repr s)})
308301
(when (seq s)
309302
(write-tokens s))
310303
(vswap! state #(assoc % :buffer buf))
311304
;; check if buffer still exceeds length; if so, we'll need to emit newlines
312305
(when (seq buf)
313306
(let [[section remainder] (get-section buf)
314-
;;_ (pdebug {:section (map repr section)
315-
;; :remainder (map repr remainder)})
316307
maybe-nl (first buf)
317308
buf (if (emit-nl? maybe-nl section)
318309
(do
@@ -321,7 +312,6 @@
321312
buf)]
322313
(if-not (tokens-fit? buf)
323314
(do
324-
#_(pdebug "writing section " (map repr section))
325315
(write-tokens section)
326316
(vswap! state #(assoc % :buffer remainder)))
327317
(vswap! state #(assoc % :buffer buf)))))))
@@ -654,6 +644,11 @@
654644
[obj]
655645
(print-map "#py {" "}" (.items obj)))
656646

647+
;; Disambiguate `Var` from `IDeref`
648+
(defmethod simple-dispatch basilisp.lang.runtime/Var
649+
[obj]
650+
(pr obj))
651+
657652
(defmethod simple-dispatch basilisp.lang.interfaces/IDeref
658653
[obj]
659654
(let [classname (.-__name__ (.-__class__ obj))

tests/basilisp/test_pprint.lpy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
(81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99)]"
129129
(vector (range 20) (range 21 40) :a :b :c (range 41 80) (range 81 100))))
130130

131+
(testing "printing collections with long elements"
132+
(is (= "[\"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\"]\n"
133+
(with-out-str
134+
(pprint/pprint
135+
["abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"])))))
136+
131137
(testing "printing meta"
132138
(are [res expr] (= res (str/rtrim
133139
(binding [*print-meta* true]
@@ -179,7 +185,8 @@
179185
(let [s (with-out-str (pprint/pprint v))]
180186
(drop 1 (re-matches #"#<(\w+)@0x[0-9a-f]+: ([^>]+)>\r?\n" s))))
181187

182-
(def ^:private ideref-value :var)
188+
(deftest pprint-var-test
189+
(is (= "#'basilisp.core/map\n" (with-out-str (pprint/pprint #'map)))))
183190

184191
(deftest pprint-ideref-test
185192
(testing "delay"
@@ -204,9 +211,6 @@
204211
(deliver p :delivered)
205212
(is (= ["Promise" ":delivered"] (match-ideref p)))))
206213

207-
(testing "var"
208-
(is (= ["Var" ":var"] (match-ideref #'ideref-value))))
209-
210214
(testing "volatile"
211215
(let [v (volatile! nil)]
212216
(is (= ["Volatile" "nil"] (match-ideref v)))

0 commit comments

Comments
 (0)