Skip to content

Commit b96a880

Browse files
committed
Test replace \r\n with \n
1 parent a1b31a5 commit b96a880

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

tests/basilisp/test_pprint.lpy

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,27 @@
77
os
88
textwrap))
99

10+
(defn trim-and-replace-newlines
11+
[s]
12+
(-> (str/trim s)
13+
(str/replace "\n" os/linesep)))
14+
1015
(deftest column-writer-test
1116
(let [write (fn [s]
1217
(with [buf (io/StringIO)]
1318
(let [writer (@#'pprint/get-column-writer buf)]
1419
(.write writer s)
1520
(select-keys @writer [:col :line]))) )]
1621
(is (= {:line 0 :col 5} (write "hello")))
17-
(is (= {:line 1 :col 15} (write "hello\nthere my friend")))
18-
(is (= {:line 2 :col 0} (write "hello\nthere my friend\n")))
22+
(is (= {:line 1 :col 15} (write (str "hello" os/linesep "there my friend"))))
23+
(is (= {:line 2 :col 0} (write (str "hello" os/linesep "there my friend" os/linesep))))
1924
(is (= {:line 0 :col 0} (write "")))))
2025

2126
(deftest pprint-test
2227
(testing "scalars"
23-
(are [res expr] (= res (str/rtrim (with-out-str (pprint/pprint expr))))
28+
(are [res expr] (= res (trim-and-replace-newlines
29+
(with-out-str
30+
(pprint/pprint expr))))
2431
"nil" nil
2532
"true" true
2633
"false" false
@@ -41,7 +48,9 @@
4148
"long.ns/sym" 'long.ns/sym))
4249

4350
(testing "collections"
44-
(are [res expr] (= res (str/rtrim (with-out-str (pprint/pprint expr))))
51+
(are [res expr] (= res (trim-and-replace-newlines
52+
(with-out-str
53+
(pprint/pprint expr))))
4554
"{}" {}
4655
"{:a 1}" {:a 1}
4756

@@ -64,7 +73,9 @@
6473
"#{:a}" #{:a}))
6574

6675
(testing "python collections"
67-
(are [res expr] (= res (str/rtrim (with-out-str (pprint/pprint expr))))
76+
(are [res expr] (= res (trim-and-replace-newlines
77+
(with-out-str
78+
(pprint/pprint expr))))
6879
"#py {}" (python/dict)
6980
"#py {:a 1}" (python/dict {:a 1})
7081

@@ -80,7 +91,9 @@
8091
"#py #{:a}" (python/set [:a])))
8192

8293
(testing "large collections"
83-
(are [res expr] (= res (str/rtrim (with-out-str (pprint/pprint expr))))
94+
(are [res expr] (= res (trim-and-replace-newlines
95+
(with-out-str
96+
(pprint/pprint expr))))
8497
"[(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
8598
(21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39)
8699
:a
@@ -135,7 +148,7 @@
135148
["abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"])))))
136149

137150
(testing "printing meta"
138-
(are [res expr] (= res (str/rtrim
151+
(are [res expr] (= res (trim-and-replace-newlines
139152
(binding [*print-meta* true]
140153
(with-out-str (pprint/pprint expr)))))
141154
"[]" []
@@ -158,7 +171,7 @@
158171
(let [long-map (into {} (map #(vector (keyword (python/chr %1)) %2)
159172
(range (python/ord "a") (python/ord "z"))
160173
(range)))]
161-
(are [res len expr] (= res (str/rtrim
174+
(are [res len expr] (= res (trim-and-replace-newlines
162175
(binding [pprint/*print-sort-keys* true
163176
*print-length* len]
164177
(with-out-str
@@ -183,7 +196,7 @@
183196
...}" 15 long-map)))
184197

185198
(deftest pprint-base-and-radix-test
186-
(are [res base expr] (= res (str/rtrim
199+
(are [res base expr] (= res (trim-and-replace-newlines
187200
(binding [pprint/*print-radix* true
188201
pprint/*print-base* base]
189202
(with-out-str
@@ -208,21 +221,25 @@
208221
"#18r1" 18 1
209222
"#18r27" 18 43))
210223

211-
(defn ^:private match-ideref
212-
[v]
213-
(let [s (with-out-str (pprint/pprint v))]
214-
(drop 1 (re-matches #"#<(\w+)@0x[0-9a-f]+: ([^>]+)>\r?\n" s))))
215-
216224
(deftest pprint-var-test
217-
(is (= "#'basilisp.core/map\n" (with-out-str (pprint/pprint #'map)))))
225+
(is (= "#'basilisp.core/map"
226+
(str/rtrim
227+
(with-out-str
228+
(pprint/pprint #'map))))))
218229

219230
(defrecord Point [x y z])
220231

221232
(deftest pprint-record-test
222-
(is (= "#Point{:x 1 :y 2 :z 3}\n"
223-
(with-out-str
224-
(binding [pprint/*print-sort-keys* true]
225-
(pprint/pprint (->Point 1 2 3)))))))
233+
(is (= "#Point{:x 1 :y 2 :z 3}"
234+
(str/rtrim
235+
(with-out-str
236+
(binding [pprint/*print-sort-keys* true]
237+
(pprint/pprint (->Point 1 2 3))))))))
238+
239+
(defn ^:private match-ideref
240+
[v]
241+
(let [s (trim-and-replace-newlines (with-out-str (pprint/pprint v)))]
242+
(drop 1 (re-matches #"#<(\w+)@0x[0-9a-f]+: ([^>]+)>" s))))
226243

227244
(deftest pprint-ideref-test
228245
(testing "delay"
@@ -315,7 +332,7 @@
315332

316333
(deftest pprint-miser-test
317334
(binding [pprint/*print-pprint-dispatch* miser-dispatch]
318-
(are [res margin] (= res (str/rtrim
335+
(are [res margin] (= res (trim-and-replace-newlines
319336
(binding [pprint/*print-right-margin* margin]
320337
(with-out-str
321338
(pprint/pprint [:abcdefghijklmnop [:abcdefghijklmn :a]])))))
@@ -327,7 +344,7 @@
327344
"[:abcdefghijklmnop [:abcdefghijklmn :a]]" 50)))
328345

329346
(deftest pprint-print-level-test
330-
(are [res plen expr] (= res (str/rtrim
347+
(are [res plen expr] (= res (trim-and-replace-newlines
331348
(binding [*print-level* plen]
332349
(with-out-str
333350
(pprint/pprint expr)))))
@@ -337,7 +354,7 @@
337354
"[[:a :b :c] [#]]" 2 [[:a :b :c] [[]]]))
338355

339356
(deftest pprint-print-length-test
340-
(are [res plen expr] (= res (str/rtrim
357+
(are [res plen expr] (= res (trim-and-replace-newlines
341358
(binding [*print-length* plen]
342359
(with-out-str
343360
(pprint/pprint expr)))))

0 commit comments

Comments
 (0)