Skip to content

Commit 946320d

Browse files
yuhan0bbatsov
authored andcommitted
Truncate maps in inspector according to config
Have maps show *max-coll-size* number of elements before truncating them, similar to the other collections.
1 parent f763175 commit 946320d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/orchard/inspect.clj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
(atom? value) :atom
206206
(and (instance? Seqable value) (empty? value)) :seq-empty
207207
(and (map? value) (short? value)) :map
208+
(map-entry? value) :map-entry
208209
(map? value) :map-long
209210
(and (vector? value) (short? value)) :vector
210211
(vector? value) :vector-long
@@ -230,19 +231,17 @@
230231
(defmethod inspect-value :atom [value]
231232
(truncate-string (pr-str value)))
232233

234+
(defmethod inspect-value :map-entry [[k v]]
235+
(str (inspect-value k) " " (inspect-value v)))
236+
233237
(defmethod inspect-value :seq-empty [value]
234238
(pr-str value))
235239

236240
(defmethod inspect-value :map [value]
237-
(->> value
238-
(map (fn [[k v]]
239-
(str (inspect-value k) " " (inspect-value v))))
240-
(s/join ", ")
241-
(format "{ %s }")))
241+
(safe-pr-seq value ", " "{ %s }"))
242242

243243
(defmethod inspect-value :map-long [value]
244-
(let [[k v] (first value)]
245-
(str "{ " (inspect-value k) " " (inspect-value v) ", ... }")))
244+
(safe-pr-seq (take *max-coll-size* value) ", " "{ %s ... }"))
246245

247246
(defmethod inspect-value :vector [value]
248247
(safe-pr-seq value "[ %s ]"))

test/orchard/inspect_test.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
"#{ :a }" #{:a}
260260
"( 1 1 1 1 1 ... )" (repeat 1)
261261
"[ ( 1 1 1 1 1 ... ) ]" [(repeat 1)]
262-
"{ :a { ( 0 1 2 3 4 ... ) 1, ... } }" {:a {(range 10) 1, 2 3, 4 5, 6 7, 8 9, 10 11}}
262+
"{ :a { ( 0 1 2 3 4 ... ) 1, 2 3, 4 5, 6 7, 8 9 ... } }" {:a {(range 10) 1, 2 3, 4 5, 6 7, 8 9, 10 11}}
263263
"( 1 2 3 )" (lazy-seq '(1 2 3))
264264
"( 1 1 1 1 1 ... )" (java.util.ArrayList. (repeat 100 1))
265265
"( 1 2 3 )" (java.util.ArrayList. [1 2 3])
@@ -279,9 +279,11 @@
279279
"( :a :b )" '(:a :b)
280280
"[ 1 2 ... ]" [1 2 3]
281281
"{ :a 1, :b 2 }" {:a 1 :b 2}
282+
"{ :a 1, :b 2 ... }" {:a 1 :b 2 :c 3}
283+
"{ :a 1, :b 2 ... }" (sorted-map :d 4 :b 2 :a 1 :c 3)
282284
"( 1 1 ... )" (repeat 1)
283285
"[ ( 1 1 ... ) ]" [(repeat 1)]
284-
"{ :a { ( 0 1 ... ) \"ab..., ... } }" {:a {(range 10) "abcdefg", 2 3, 4 5, 6 7, 8 9, 10 11}}
286+
"{ :a { ( 0 1 ... ) \"ab..., 2 3 ... } }" {:a {(range 10) "abcdefg", 2 3, 4 5, 6 7, 8 9, 10 11}}
285287
"java.lang.Long[] { 0, 1 ... }" (into-array Long (range 10))))
286288
(binding [inspect/*max-coll-size* 6]
287289
(are [result form] (= result (inspect/inspect-value form))

0 commit comments

Comments
 (0)