Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/orchard/inspect.clj
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
(atom? value) :atom
(and (instance? Seqable value) (empty? value)) :seq-empty
(and (map? value) (short? value)) :map
(map-entry? value) :map-entry
(map? value) :map-long
(and (vector? value) (short? value)) :vector
(vector? value) :vector-long
Expand All @@ -230,19 +231,17 @@
(defmethod inspect-value :atom [value]
(truncate-string (pr-str value)))

(defmethod inspect-value :map-entry [[k v]]
(str (inspect-value k) " " (inspect-value v)))

(defmethod inspect-value :seq-empty [value]
(pr-str value))

(defmethod inspect-value :map [value]
(->> value
(map (fn [[k v]]
(str (inspect-value k) " " (inspect-value v))))
(s/join ", ")
(format "{ %s }")))
(safe-pr-seq value ", " "{ %s }"))

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

(defmethod inspect-value :vector [value]
(safe-pr-seq value "[ %s ]"))
Expand Down Expand Up @@ -275,7 +274,7 @@

(defmethod inspect-value :array-long [value]
(let [ct (.getName (or (.getComponentType (class value)) Object))]
(safe-pr-seq (take *max-coll-size* value) ", " (str ct "[] { %s ... }"))))
(safe-pr-seq (take *max-coll-size* value) ", " (str ct "[] { %s, ... }"))))
(defmethod inspect-value java.lang.Class [value]
(pr-str value))

Expand Down
10 changes: 6 additions & 4 deletions test/orchard/inspect_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@
"#{ :a }" #{:a}
"( 1 1 1 1 1 ... )" (repeat 1)
"[ ( 1 1 1 1 1 ... ) ]" [(repeat 1)]
"{ :a { ( 0 1 2 3 4 ... ) 1, ... } }" {:a {(range 10) 1, 2 3, 4 5, 6 7, 8 9, 10 11}}
"{ :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}}
"( 1 2 3 )" (lazy-seq '(1 2 3))
"( 1 1 1 1 1 ... )" (java.util.ArrayList. (repeat 100 1))
"( 1 2 3 )" (java.util.ArrayList. [1 2 3])
"{ :a 1, :b 2 }" (java.util.HashMap. {:a 1 :b 2})
"long[] { 1, 2, 3, 4 }" (long-array [1 2 3 4])
"java.lang.Long[] { 0, 1, 2, 3, 4 ... }" (into-array Long (range 10))
"java.lang.Long[] { 0, 1, 2, 3, 4, ... }" (into-array Long (range 10))
"#<MyTestType test1>" (MyTestType. "test1")))

(testing "inspect-value adjust length and size"
Expand All @@ -279,10 +279,12 @@
"( :a :b )" '(:a :b)
"[ 1 2 ... ]" [1 2 3]
"{ :a 1, :b 2 }" {:a 1 :b 2}
"{ :a 1, :b 2, ... }" {:a 1 :b 2 :c 3}
"{ :a 1, :b 2, ... }" (sorted-map :d 4 :b 2 :a 1 :c 3)
"( 1 1 ... )" (repeat 1)
"[ ( 1 1 ... ) ]" [(repeat 1)]
"{ :a { ( 0 1 ... ) \"ab..., ... } }" {:a {(range 10) "abcdefg", 2 3, 4 5, 6 7, 8 9, 10 11}}
"java.lang.Long[] { 0, 1 ... }" (into-array Long (range 10))))
"{ :a { ( 0 1 ... ) \"ab..., 2 3, ... } }" {:a {(range 10) "abcdefg", 2 3, 4 5, 6 7, 8 9, 10 11}}
"java.lang.Long[] { 0, 1, ... }" (into-array Long (range 10))))
(binding [inspect/*max-coll-size* 6]
(are [result form] (= result (inspect/inspect-value form))
"[ ( 1 1 1 1 1 1 ... ) ]" [(repeat 1)]
Expand Down