Skip to content

Commit 595cc17

Browse files
jonasestuarthalloway
authored andcommitted
CLJ-1562: Add missing threading macro tests
Signed-off-by: Stuart Halloway <stu@cognitect.com>
1 parent 5e655b5 commit 595cc17

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/clojure/test_clojure/macros.clj

+44
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,47 @@
6767
(is (= {:baz :quux} (meta (first expanded))))
6868
(is (= {:bar :baz} (meta (second expanded))))
6969
(is (= {:foo :bar} (meta (last (second expanded))))))))
70+
71+
(def constantly-nil (constantly nil))
72+
73+
(deftest some->test
74+
(is (nil? (some-> nil)))
75+
(is (= 0 (some-> 0)))
76+
(is (= -1 (some-> 1 (- 2))))
77+
(is (nil? (some-> 1 constantly-nil (- 2)))))
78+
79+
(deftest some->>test
80+
(is (nil? (some->> nil)))
81+
(is (= 0 (some->> 0)))
82+
(is (= 1 (some->> 1 (- 2))))
83+
(is (nil? (some->> 1 constantly-nil (- 2)))))
84+
85+
(deftest cond->test
86+
(is (= 0 (cond-> 0)))
87+
(is (= -1 (cond-> 0 true inc true (- 2))))
88+
(is (= 0 (cond-> 0 false inc)))
89+
(is (= -1 (cond-> 1 true (- 2) false inc))))
90+
91+
(deftest cond->>test
92+
(is (= 0 (cond->> 0)))
93+
(is (= 1 (cond->> 0 true inc true (- 2))))
94+
(is (= 0 (cond->> 0 false inc)))
95+
(is (= 1 (cond->> 1 true (- 2) false inc))))
96+
97+
(deftest as->test
98+
(is (= 0 (as-> 0 x)))
99+
(is (= 1 (as-> 0 x (inc x))))
100+
(is (= 2 (as-> [0 1] x
101+
(map inc x)
102+
(reverse x)
103+
(first x)))))
104+
105+
(deftest threading-loop-recur
106+
(is (nil? (loop []
107+
(as-> 0 x
108+
(when-not (zero? x)
109+
(recur))))))
110+
(is (nil? (loop [x nil] (some-> x recur))))
111+
(is (nil? (loop [x nil] (some->> x recur))))
112+
(is (= 0 (loop [x 0] (cond-> x false recur))))
113+
(is (= 0 (loop [x 0] (cond->> x false recur)))))

0 commit comments

Comments
 (0)