Skip to content

Commit 5b2ee13

Browse files
authored
Print commas between key/value pairs of maps (#1319)
Fixes #1275
1 parent 53a1623 commit 5b2ee13

7 files changed

Lines changed: 36 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
* Ratios which reduce to an integer are now returned from the reader as integers (#1305)
3030
* `mod`, `quot`, and `rem` return values are now consistent with the Clojure return values for the same inputs (#1305)
3131
* `derive` will throw exceptions if the provided hierarchy is invalid or if the tag and parent are invalid types (#1305)
32+
* Map types now print out comma separators between key/value pairs (#1275)
3233

3334
### Fixed
3435
* Fix a bug where `import` refers would incorrectly be applied to all import modules in the same form (#1274)

src/basilisp/lang/map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ReduceKVFunction,
2222
)
2323
from basilisp.lang.obj import (
24-
PRINT_SEPARATOR,
24+
MAP_PRINT_SEPARATOR,
2525
SURPASSED_PRINT_LENGTH,
2626
SURPASSED_PRINT_LEVEL,
2727
PrintSettings,
@@ -194,7 +194,7 @@ def entry_reprs():
194194
else:
195195
items = list(entry_reprs())
196196

197-
seq_lrepr = PRINT_SEPARATOR.join(items + trailer)
197+
seq_lrepr = MAP_PRINT_SEPARATOR.join(items + trailer)
198198

199199
ns_prefix = ("#:" + ns_name_shared) if ns_name_shared else ""
200200
if kwargs["print_meta"] and meta:

src/basilisp/lang/obj.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
PRINT_META = False
2727
PRINT_NAMESPACE_MAPS = False
2828
PRINT_READABLY = True
29-
PRINT_SEPARATOR = " "
29+
SEQ_PRINT_SEPARATOR = " "
30+
MAP_PRINT_SEPARATOR = ", "
3031

3132

3233
class PrintSettings(TypedDict, total=False):
@@ -115,7 +116,7 @@ def seq_lrepr(
115116
kw_items = kwargs.copy()
116117
kw_items["human_readable"] = False
117118
items = list(map(lambda o: lrepr(o, **kw_items), items))
118-
seq_lrepr = PRINT_SEPARATOR.join(items + trailer)
119+
seq_lrepr = SEQ_PRINT_SEPARATOR.join(items + trailer)
119120

120121
print_meta = kwargs["print_meta"]
121122
if print_meta and meta:

tests/basilisp/core/test_defrecord.lpy

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,19 @@
194194
(is (= {:tag Point} (meta (with-meta p {:tag Point})))))
195195

196196
(testing "repr"
197-
(is (contains? #{"#tests.basilisp.core.test-defrecord.Point{:x 1 :y 2 :z 3}"
198-
"#tests.basilisp.core.test-defrecord.Point{:y 2 :z 3 :x 1}"
199-
"#tests.basilisp.core.test-defrecord.Point{:z 3 :x 1 :y 2}"
200-
"#tests.basilisp.core.test-defrecord.Point{:y 2 :x 1 :z 3}"
201-
"#tests.basilisp.core.test-defrecord.Point{:x 1 :z 3 :y 2}"
202-
"#tests.basilisp.core.test-defrecord.Point{:z 3 :y 2 :x 1}"}
197+
(is (contains? #{"#tests.basilisp.core.test-defrecord.Point{:x 1, :y 2, :z 3}"
198+
"#tests.basilisp.core.test-defrecord.Point{:y 2, :z 3, :x 1}"
199+
"#tests.basilisp.core.test-defrecord.Point{:z 3, :x 1, :y 2}"
200+
"#tests.basilisp.core.test-defrecord.Point{:y 2, :x 1, :z 3}"
201+
"#tests.basilisp.core.test-defrecord.Point{:x 1, :z 3, :y 2}"
202+
"#tests.basilisp.core.test-defrecord.Point{:z 3, :y 2, :x 1}"}
203203
(repr p)))
204-
(is (contains? #{"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:x 1 :y 2 :z 3}"
205-
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:y 2 :z 3 :x 1}"
206-
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:z 3 :x 1 :y 2}"
207-
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:y 2 :x 1 :z 3}"
208-
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:x 1 :z 3 :y 2}"
209-
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:z 3 :y 2 :x 1}"}
204+
(is (contains? #{"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:x 1, :y 2, :z 3}"
205+
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:y 2, :z 3, :x 1}"
206+
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:z 3, :x 1, :y 2}"
207+
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:y 2, :x 1, :z 3}"
208+
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:x 1, :z 3, :y 2}"
209+
"^{:interesting :yes} #tests.basilisp.core.test-defrecord.Point{:z 3, :y 2, :x 1}"}
210210
(binding [*print-meta* true]
211211
(repr (with-meta p {:interesting :yes}))))))))
212212

@@ -259,8 +259,8 @@
259259
(is (= "^{:interesting :yes} #tests.basilisp.core.test-defrecord.Circle{:radius 1}"
260260
(binding [*print-meta* true]
261261
(pr-str (with-meta c {:interesting :yes})))))
262-
(is (contains? #{"#tests.basilisp.core.test-defrecord.Circle{:radius 1 :name \"Kurt\"}"
263-
"#tests.basilisp.core.test-defrecord.Circle{:name \"Kurt\" :radius 1}"}
262+
(is (contains? #{"#tests.basilisp.core.test-defrecord.Circle{:radius 1, :name \"Kurt\"}"
263+
"#tests.basilisp.core.test-defrecord.Circle{:name \"Kurt\", :radius 1}"}
264264
(repr c1))))
265265

266266
(testing "str"

tests/basilisp/core/test_printing_fns.lpy

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
(is (= "#py #:a{:x 5}" (binding [*print-namespace-maps* true] (pr-str #py {:a/x 5}))))
2929

3030
(are [res m b] (contains? res (binding [*print-namespace-maps* b] (pr-str m)))
31-
#{"{:a/x 5}"} {:a/x 5} false
32-
#{"#:a{:x 5}"} {:a/x 5} true
33-
#{"{:x 5}"} {:x 5} true
34-
#{"{1 2}"} {1 2} false
35-
#{"{1 2}"} {1 2} true
36-
#{"{:a/y 6 :a/x 5}" "{:a/x 5 :a/y 6}"} {:a/x 5 :a/y 6} false
37-
#{"#:a{:y 6 :x 5}" "#:a{:x 5 :y 6}"} {:a/x 5 :a/y 6} true
38-
#{"{6 6 :a/x 5}" "{:a/x 5 6 6}"} {:a/x 5 6 6} false
39-
#{"{6 6 :a/x 5}" "{:a/x 5 6 6}"} {:a/x 5 6 6} true
40-
#{"{:a/x 5 :b/y 6}" "{:b/y 6 :a/x 5}"} {:a/x 5 :b/y 6} true
41-
#{"#:a{y 6 x 5}" "#:a{x 5 y 6}"} {'a/x 5 'a/y 6} true
42-
#{"#:a{y 6 :x 5}" "#:a{:x 5 y 6}"} {:a/x 5 'a/y 6} true
43-
#{"{y 6 :a/x 5}" "{:a/x 5 y 6}"} {:a/x 5 'y 6} true)
31+
#{"{:a/x 5}"} {:a/x 5} false
32+
#{"#:a{:x 5}"} {:a/x 5} true
33+
#{"{:x 5}"} {:x 5} true
34+
#{"{1 2}"} {1 2} false
35+
#{"{1 2}"} {1 2} true
36+
#{"{:a/y 6, :a/x 5}" "{:a/x 5, :a/y 6}"} {:a/x 5 :a/y 6} false
37+
#{"#:a{:y 6, :x 5}" "#:a{:x 5, :y 6}"} {:a/x 5 :a/y 6} true
38+
#{"{6 6, :a/x 5}" "{:a/x 5, 6 6}"} {:a/x 5 6 6} false
39+
#{"{6 6, :a/x 5}" "{:a/x 5, 6 6}"} {:a/x 5 6 6} true
40+
#{"{:a/x 5, :b/y 6}" "{:b/y 6, :a/x 5}"} {:a/x 5 :b/y 6} true
41+
#{"#:a{y 6, x 5}" "#:a{x 5, y 6}"} {'a/x 5 'a/y 6} true
42+
#{"#:a{y 6, :x 5}" "#:a{:x 5, y 6}"} {:a/x 5 'a/y 6} true
43+
#{"{y 6, :a/x 5}" "{:a/x 5, y 6}"} {:a/x 5 'y 6} true)
4444

4545
(are [res m pnm pm] (= res (binding [*print-namespace-maps* pnm
4646
*print-meta* pm]

tests/basilisp/lrepr_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def test_print_length(lcompile: CompileFn, s: str, code: str):
5252

5353
def test_print_length_maps(lcompile: CompileFn):
5454
assert lcompile("(binding [*print-length* 1] (pr-str {:a 1 :b 2}))") in {
55-
"{:a 1 ...}",
56-
"{:b 2 ...}",
55+
"{:a 1, ...}",
56+
"{:b 2, ...}",
5757
}
5858

5959

tests/basilisp/map_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def test_map_repr():
232232
assert repr(m) == '{:key "val"}'
233233

234234
m = lmap.map({keyword("key1"): "val1", keyword("key2"): 3})
235-
assert repr(m) in ['{:key2 3 :key1 "val1"}', '{:key1 "val1" :key2 3}']
235+
assert repr(m) in ['{:key2 3, :key1 "val1"}', '{:key1 "val1", :key2 3}']
236236

237237

238238
def test_hash_map_creator():

0 commit comments

Comments
 (0)