Skip to content

Commit 5ab751b

Browse files
test juxt (#756)
* test `juxt` * Update test/clojure/core_test/juxt.cljc Co-authored-by: Emma Griffin <[email protected]> * Balance parens --------- Co-authored-by: Emma Griffin <[email protected]> Co-authored-by: Emma Griffin <[email protected]>
1 parent 66502af commit 5ab751b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/clojure/core_test/juxt.cljc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(ns clojure.core-test.juxt
2+
(:require [clojure.test :as t :refer [deftest testing is are]]
3+
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
4+
5+
(when-var-exists juxt
6+
(deftest test-juxt
7+
(testing "'returns a function'"
8+
(is (ifn? (juxt juxt partial comp :foo)))
9+
(is (ifn? (juxt nil)))
10+
(is (ifn? (juxt (range)))))
11+
12+
(testing "'the returned fn...returns a vector'"
13+
(is (vector? ((juxt inc) 5))))
14+
15+
(testing "'The returned fn takes a variable number of args'"
16+
(is (= ["12345678910" 1 10]
17+
((juxt str min max) 1 2 3 4 5 6 7 8 9 10))))
18+
19+
(testing "'returns a fn that is the juxtaposition of those fns'"
20+
(is (let [arg 10]
21+
(= (vector (inc arg) (dec arg) (identity arg))
22+
((juxt inc dec identity) arg))))
23+
(is (= ["foo" nil "bar"]
24+
((juxt :foo :missing :bar) {:foo "foo", :bar "bar"})))
25+
(is (= [:namespace/keyword "keyword" "namespace"]
26+
((juxt identity name namespace) :namespace/keyword)))
27+
(is (= [:v] ((juxt {:k :v}) :k)))
28+
(is (= [:v] ((juxt :k) {:k :v})))
29+
30+
(is (= [:v :value "value"]
31+
((juxt {:k :v}
32+
#(get {:k :value} %)
33+
(fn [x] (get {:k "value"} x)))
34+
:k))))
35+
36+
(testing "wrong-shape input is mostly accepted (and throws when invoked)"
37+
#?(:cljs (is (thrown? :default ((juxt nil))))
38+
:clj (is (thrown? java.lang.NullPointerException ((juxt nil))))
39+
:clr (is (thrown? System.NullReferenceException ((juxt nil)))))
40+
#?@(:cljs [(is (thrown? :default ((juxt (range)))))
41+
(is (thrown? :default ((juxt 1))))]
42+
:default [(is (thrown? Exception ((juxt (range)))))
43+
(is (thrown? Exception ((juxt 1))))]))))

0 commit comments

Comments
 (0)