File tree 1 file changed +44
-0
lines changed
test/clojure/test_clojure
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 67
67
(is (= {:baz :quux } (meta (first expanded))))
68
68
(is (= {:bar :baz } (meta (second expanded))))
69
69
(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 )))))
You can’t perform that action at this time.
0 commit comments