Skip to content

Commit a5c0c18

Browse files
alexander-yakushevbbatsov
authored andcommitted
[inspect] Custom messages for inspecting nil
1 parent 8675eb9 commit a5c0c18

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/orchard/inspect.clj

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,20 @@
729729

730730
(defmethod inspect :nil [inspector _obj]
731731
(-> inspector
732-
(render-ln "nil")))
732+
(render-ln "Value: nil")
733+
(render-section-header "Contents")
734+
(indent)
735+
(render-indent-ln
736+
(rand-nth ["You have gazed into the void and it winked back."
737+
"You've reached the end of the universe. Time to turn back."
738+
"There's nothing here… or is there? Nope. Still nothing."
739+
"Welcome to Nil. Population: 0."
740+
"I sometimes come here too, to enjoy the peace and quiet."
741+
"Here lies no data. Rest in peace, little bytes."
742+
"Warning: staring too long at nil may summon cosmic horrors."
743+
"This whole trip might have been for nothing! Zero, zilch, zip, nada, nothing."
744+
"No data found. Please insert meaning manually."]))
745+
(unindent)))
733746

734747
(defn- inspect-coll [inspector obj]
735748
(-> (render-class-name inspector obj)
@@ -1035,22 +1048,23 @@
10351048
(if (and (seq path) (not-any? #(= % '<unknown>) path))
10361049
(-> (render-section-header inspector "Path")
10371050
(indent)
1038-
(render-indent (str/join " " (:path inspector)))
1051+
(render-indent-ln (str/join " " (:path inspector)))
10391052
(unindent))
10401053
inspector)))
10411054

1042-
(defn render-view-mode [inspector]
1043-
(let [{:keys [view-mode pretty-print]} inspector
1044-
supported (filter #(view-mode-supported? inspector %) view-mode-order)
1045-
add-circle #(if %2 (str "" %1) %1)
1046-
view-mode-str (str (->> supported
1047-
(map #(add-circle (name %) (= % view-mode)))
1048-
(str/join " "))
1049-
" " (add-circle "pretty" pretty-print))]
1050-
(-> (render-section-header inspector "View mode (press 'v' to cycle, 'P' to pretty-print)")
1051-
(indent)
1052-
(render-indent view-mode-str)
1053-
(unindent))))
1055+
(defn render-view-mode [{:keys [value view-mode pretty-print] :as inspector}]
1056+
(if (some? value)
1057+
(let [supported (filter #(view-mode-supported? inspector %) view-mode-order)
1058+
add-circle #(if %2 (str "" %1) %1)
1059+
view-mode-str (str (->> supported
1060+
(map #(add-circle (name %) (= % view-mode)))
1061+
(str/join " "))
1062+
" " (add-circle "pretty" pretty-print))]
1063+
(-> (render-section-header inspector "View mode (press 'v' to cycle, 'P' to pretty-print)")
1064+
(indent)
1065+
(render-indent view-mode-str)
1066+
(unindent)))
1067+
inspector))
10541068

10551069
(defn inspect-render
10561070
([{:keys [max-atom-length max-value-length max-coll-size max-nested-depth value pretty-print]

test/orchard/inspect_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
;; Simplifies writing test structures for `match?`.
2929

3030
(def nil-result
31-
["nil" [:newline] [:newline] #"--- View mode" [:newline] " ●normal object pretty"])
31+
["Value: nil" [:newline] [:newline] "--- Contents:" [:newline] string? [:newline]])
3232

3333
(def code "(sorted-map :a {:b 1} :c \"a\" :d 'e :f [2 3])")
3434

0 commit comments

Comments
 (0)