Skip to content

Commit ea85c54

Browse files
[inspect] Display sort-maps status
1 parent f200f69 commit ea85c54

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

src/orchard/inspect.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@
11091109
(unindent))
11101110
inspector)))
11111111

1112-
(defn render-view-mode [{:keys [value view-mode pretty-print only-diff] :as inspector}]
1112+
(defn render-view-mode [{:keys [value view-mode pretty-print sort-maps only-diff] :as inspector}]
11131113
(if (some? value)
11141114
(let [supported (filter #(view-mode-supported? inspector %) view-mode-order)
11151115
add-circle #(if %2 (str "" %1) %1)
@@ -1118,9 +1118,10 @@
11181118
(map #(add-circle (name %) (= % view-mode)))
11191119
(str/join " "))
11201120
" " (add-circle "pretty" pretty-print)
1121+
" " (add-circle "sort-maps" sort-maps)
11211122
(when diff?
11221123
(str " " (add-circle "only-diff" only-diff))))
1123-
caption (format "View mode (press 'v' to cycle, 'P' to pretty-print%s)"
1124+
caption (format "View mode (press 'v' to cycle, 'P' to pretty-print, 'S' to sort maps%s)"
11241125
(if diff? ", 'D' to show only diffs" ""))]
11251126
(-> (render-section-header inspector caption)
11261127
(indent)

test/orchard/inspect_test.clj

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
[:newline]
5252
" " [:value ":f" 7] " = " [:value "[2 3]" 8]
5353
[:newline] [:newline]
54-
#"--- View mode" [:newline] " ●normal object pretty"])
54+
#"--- View mode" [:newline] " ●normal object pretty sort-maps"])
5555

5656
(def long-sequence (range 70))
5757
(def long-vector (vec (range 70)))
@@ -1376,7 +1376,7 @@
13761376
" " [:value "_first" pos?] " = " [:value "1" pos?] [:newline]
13771377
" " [:value "_hash" pos?] " = " [:value "0" pos?] [:newline]])
13781378
(section rendered "Instance fields"))
1379-
(is+ [#"--- View mode" [:newline] " normal ●object pretty"]
1379+
(is+ [#"--- View mode" [:newline] " normal ●object pretty sort-maps"]
13801380
(section rendered "View mode")))
13811381

13821382
(let [rendered (-> (atom "foo")
@@ -1391,7 +1391,7 @@
13911391
" " [:value "validator" pos?] " = " [:value "nil" pos?] [:newline]
13921392
" " [:value "watches" pos?] " = " [:value "{}" pos?]])
13931393
(section rendered "Instance fields"))
1394-
(is+ [#"--- View mode" [:newline] " normal ●object pretty"]
1394+
(is+ [#"--- View mode" [:newline] " normal ●object pretty sort-maps"]
13951395
(section rendered "View mode"))))
13961396

13971397
(testing "navigating away from an object changes the view mode back to normal"
@@ -1430,7 +1430,7 @@
14301430
" | " [:value "4" pos?] " | " [:value "-4" pos?] " | "
14311431
[:value "\"444\"" pos?] " | " [:value "(4 3 2 1)" pos?] " | "]
14321432
(contents-section rendered))
1433-
(is+ [#"--- View mode" [:newline] " normal ●table object pretty"]
1433+
(is+ [#"--- View mode" [:newline] " normal ●table object pretty sort-maps"]
14341434
(section rendered "View mode"))))
14351435

14361436
(testing "in :table view-mode lists of vectors are rendered as tables"
@@ -1454,7 +1454,7 @@
14541454
" | " [:value "4" pos?] " | " [:value "-4" pos?] " | "
14551455
[:value "\"444\"" pos?] " | " [:value "(4 3 2 1)" pos?] " | "]
14561456
(contents-section rendered))
1457-
(is+ [#"--- View mode" [:newline] " normal ●table object pretty"]
1457+
(is+ [#"--- View mode" [:newline] " normal ●table object pretty sort-maps"]
14581458
(section rendered "View mode"))))
14591459

14601460
(testing "breaks if table mode is requested for unsupported value"
@@ -1532,7 +1532,7 @@
15321532
" 0x00000050 │ 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f │ PQRSTUVWXYZ[\\]^_" [:newline]
15331533
" 0x00000060 │ 60 61 62 63 │ `abc"]
15341534
(contents-section rendered))
1535-
(is+ [#"--- View mode" [:newline] " ●hex normal object pretty"]
1535+
(is+ [#"--- View mode" [:newline] " ●hex normal object pretty sort-maps"]
15361536
(section rendered "View mode"))))
15371537

15381538
(testing "works with paging"
@@ -1580,20 +1580,20 @@
15801580

15811581
(deftest toggle-view-mode-test
15821582
(is+ :normal (-> (repeat 10 [1 2]) inspect :view-mode))
1583-
(is+ " ●normal table object pretty"
1583+
(is+ " ●normal table object pretty sort-maps"
15841584
(-> (repeat 10 [1 2]) inspect render (section "View mode") last))
15851585

15861586
(is+ :table (-> (repeat 10 [1 2]) inspect inspect/toggle-view-mode :view-mode))
1587-
(is+ " normal ●table object pretty"
1587+
(is+ " normal ●table object pretty sort-maps"
15881588
(-> (repeat 10 [1 2]) inspect inspect/toggle-view-mode render (section "View mode") last))
15891589

15901590
(is+ :object (-> (repeat 10 [1 2]) inspect inspect/toggle-view-mode inspect/toggle-view-mode :view-mode))
1591-
(is+ " normal table ●object pretty"
1591+
(is+ " normal table ●object pretty sort-maps"
15921592
(-> (repeat 10 [1 2]) inspect inspect/toggle-view-mode inspect/toggle-view-mode render (section "View mode") last))
15931593

15941594
(is+ :normal (-> (repeat 10 [1 2]) inspect inspect/toggle-view-mode inspect/toggle-view-mode inspect/toggle-view-mode :view-mode))
15951595

1596-
(is+ " ●normal table object ●pretty"
1596+
(is+ " ●normal table object ●pretty sort-maps"
15971597
(-> (repeat 10 [1 2]) (inspect {:pretty-print true}) render (section "View mode") last)))
15981598

15991599
(deftest pretty-print-map-test
@@ -1619,7 +1619,7 @@
16191619
" {:a -1, :bb \"111\", :ccc [1]}\n"
16201620
" {:a 2, :bb \"222\", :ccc [1 2]}]") 8]]
16211621
(contents-section rendered))
1622-
(is+ [#"--- View mode" [:newline] " ●normal object ●pretty"]
1622+
(is+ [#"--- View mode" [:newline] " ●normal object ●pretty sort-maps"]
16231623
(section rendered "View mode")))))
16241624

16251625
(deftest pretty-print-map-in-object-view-test
@@ -1668,7 +1668,7 @@
16681668
":ccc (3 2 1)}\n {:a -4, :bb \"444\", "
16691669
":ccc (4 3 2 1)})}") 2]]
16701670
(contents-section rendered))
1671-
(is+ [#"--- View mode" [:newline] " ●normal table object ●pretty"]
1671+
(is+ [#"--- View mode" [:newline] " ●normal table object ●pretty sort-maps"]
16721672
(section rendered "View mode")))))
16731673

16741674
(deftest pretty-print-map-as-key-test
@@ -1706,7 +1706,7 @@
17061706
"\"333\", :ccc [3 2 1]}\n {:a -4, :bb "
17071707
"\"444\", :ccc [4 3 2 1]}]}") 2]]
17081708
(contents-section rendered))
1709-
(is+ [#"--- View mode" [:newline] " ●normal object ●pretty"]
1709+
(is+ [#"--- View mode" [:newline] " ●normal object ●pretty sort-maps"]
17101710
(section rendered "View mode")))))
17111711

17121712
(deftest pretty-print-seq-of-map-as-key-test
@@ -1736,22 +1736,25 @@
17361736
":bb \"111\", :ccc [1]}\n {:a 2, :bb \"222\", "
17371737
":ccc [1 2]}]}") 2]]
17381738
(contents-section rendered))
1739-
(is+ [#"--- View mode" [:newline] " ●normal object ●pretty"]
1739+
(is+ [#"--- View mode" [:newline] " ●normal object ●pretty sort-maps"]
17401740
(section rendered "View mode")))))
17411741

17421742
(deftest sort-maps-test
17431743
(testing "with :sort-map-keys enabled, map keys are sorted"
1744-
(is+ (matchers/prefix
1745-
["--- Contents:" [:newline]
1746-
" " [:value "0" pos?] " = " [:value "0" pos?] [:newline]
1747-
" " [:value "1" pos?] " = " [:value "1" pos?] [:newline]
1748-
" " [:value "2" pos?] " = " [:value "2" pos?] [:newline]
1749-
" " [:value "3" pos?] " = " [:value "3" pos?] [:newline]])
1750-
(-> (zipmap (range 100) (range 100))
1751-
inspect
1752-
(inspect/refresh {:sort-maps true})
1753-
render
1754-
contents-section)))
1744+
(let [rendered (-> (zipmap (range 100) (range 100))
1745+
inspect
1746+
(inspect/refresh {:sort-maps true})
1747+
render)]
1748+
(is+ (matchers/prefix
1749+
["--- Contents:" [:newline]
1750+
" " [:value "0" pos?] " = " [:value "0" pos?] [:newline]
1751+
" " [:value "1" pos?] " = " [:value "1" pos?] [:newline]
1752+
" " [:value "2" pos?] " = " [:value "2" pos?] [:newline]
1753+
" " [:value "3" pos?] " = " [:value "3" pos?] [:newline]])
1754+
(contents-section rendered))
1755+
1756+
(is+ [#"--- View mode" [:newline] " ●normal object pretty ●sort-maps"]
1757+
(section rendered "View mode"))))
17551758

17561759
(testing "works if map is smaller than page size"
17571760
(is+ ["--- Contents:" [:newline]
@@ -2004,7 +2007,7 @@
20042007
" 3. " [:value "#±[3 ~~ 4]" pos?]]
20052008
(section rendered "Diff"))
20062009

2007-
(is+ [string? [:newline] " ●normal pretty only-diff"]
2010+
(is+ [string? [:newline] " ●normal pretty sort-maps only-diff"]
20082011
(section rendered "View mode")))
20092012

20102013
(is+ ["--- Diff contents:" [:newline]
@@ -2051,7 +2054,7 @@
20512054
" 3. " [:value "#±[3 ~~ 4]" pos?]]
20522055
(section rendered "Diff"))
20532056

2054-
(is+ [string? [:newline] " ●normal pretty ●only-diff"]
2057+
(is+ [string? [:newline] " ●normal pretty sort-maps ●only-diff"]
20552058
(section rendered "View mode")))
20562059

20572060
(is+ ["--- Diff contents:" [:newline]

0 commit comments

Comments
 (0)