From d672b6b21ab16099d596428fb872bcde1f9ff029 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sun, 11 Apr 2021 15:21:49 +0800 Subject: [PATCH 1/2] Truncate maps in inspector according to config Have maps show *max-coll-size* number of elements before truncating them, similar to the other collections. --- src/orchard/inspect.clj | 13 ++++++------- test/orchard/inspect_test.clj | 6 ++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/orchard/inspect.clj b/src/orchard/inspect.clj index de9d5fc7..0ed761c2 100644 --- a/src/orchard/inspect.clj +++ b/src/orchard/inspect.clj @@ -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 @@ -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 ]")) diff --git a/test/orchard/inspect_test.clj b/test/orchard/inspect_test.clj index 0a368a4c..a7178a23 100644 --- a/test/orchard/inspect_test.clj +++ b/test/orchard/inspect_test.clj @@ -259,7 +259,7 @@ "#{ :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]) @@ -279,9 +279,11 @@ "( :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}} + "{ :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)) From 7a61ab5c5fe62ade67e0c6a5d16556b2e6b35b2d Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Mon, 12 Apr 2021 12:05:12 +0800 Subject: [PATCH 2/2] Add comma before ... in ,-separated colls --- src/orchard/inspect.clj | 4 ++-- test/orchard/inspect_test.clj | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/orchard/inspect.clj b/src/orchard/inspect.clj index 0ed761c2..cc63600f 100644 --- a/src/orchard/inspect.clj +++ b/src/orchard/inspect.clj @@ -241,7 +241,7 @@ (safe-pr-seq value ", " "{ %s }")) (defmethod inspect-value :map-long [value] - (safe-pr-seq (take *max-coll-size* value) ", " "{ %s ... }")) + (safe-pr-seq (take *max-coll-size* value) ", " "{ %s, ... }")) (defmethod inspect-value :vector [value] (safe-pr-seq value "[ %s ]")) @@ -274,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)) diff --git a/test/orchard/inspect_test.clj b/test/orchard/inspect_test.clj index a7178a23..6d13e8e6 100644 --- a/test/orchard/inspect_test.clj +++ b/test/orchard/inspect_test.clj @@ -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, 2 3, 4 5, 6 7, 8 9 ... } }" {: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"))) (testing "inspect-value adjust length and size" @@ -279,12 +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) + "{ :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..., 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)))) + "{ :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)]