|
45 | 45 | {:b "b"}))))
|
46 | 46 |
|
47 | 47 | (testing "vectors in position 2+ are treated as map-entries, per `conj`"
|
48 |
| - (is (thrown? #?(:cljs :default, :clj java.lang.IllegalArgumentException, :clr Exception) |
49 |
| - (merge {} []))) |
50 |
| - (is (thrown? #?(:cljs :default, :clj java.lang.IllegalArgumentException, :clr Exception) |
51 |
| - (merge {} [:foo]))) |
| 48 | + #?(:cljs (is (thrown? js/Error (merge {} []))) |
| 49 | + :clj (is (thrown? java.lang.IllegalArgumentException (merge {} []))) |
| 50 | + :default (is (thrown? Exception (merge {} [])))) |
| 51 | + #?(:cljs (is (thrown? js/Error (merge {} [:foo]))) |
| 52 | + :clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo]))) |
| 53 | + :default (is (thrown? Exception (merge {} [:foo])))) |
52 | 54 | (is (= {:foo "foo"} (merge {} [:foo "foo"])))
|
53 | 55 | (is (= {"x" 1} (merge {} ["x" 1])))
|
54 | 56 | (is (= {'x 10, 'y 10} (merge {'x 10} ['y 10])))
|
55 | 57 | (testing "In CLJS (unlike other dialects) vectors with >2 arguments are treated as map-entries (where the latter values are ignored)"
|
56 | 58 | #?(:cljs (is (= {:foo :bar} (merge {} [:foo :bar :baz]))),
|
57 |
| - :clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo :bar :baz]))), |
58 |
| - :clr (is (thrown? Exception (merge {} [:foo :bar :baz]))))) |
| 59 | + :clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo :bar :baz]))), |
| 60 | + :clr (is (thrown? Exception (merge {} [:foo :bar :baz]))))) |
59 | 61 |
|
60 | 62 | (is (= {:foo "foo", :bar "bar"} (merge {} [:foo "foo"] [:bar "bar"])))
|
61 | 63 | (is (= {'x 10, 'y 10, 'z 10} (merge {'x 10} ['y 10] ['z 10])))
|
62 | 64 | (testing "In CLJS (unlike other dialects) vectors with >2 arguments are treated as map-entries (where the latter values are ignored)"
|
63 | 65 | #?(:cljs (is (= {:foo :bar} (merge {} [:foo :bar :baz :bar]))),
|
64 |
| - :clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo :bar :baz :bar]))), |
65 |
| - :clr (is (thrown? Exception (merge {} [:foo :bar :baz :bar])))))) |
| 66 | + :clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo :bar :baz :bar]))), |
| 67 | + :clr (is (thrown? Exception (merge {} [:foo :bar :baz :bar])))))) |
66 | 68 |
|
67 | 69 | (testing "atomic values in position 2+ throw"
|
68 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
69 |
| - (merge {} 1))) |
70 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
71 |
| - (merge {} 1 2))) |
72 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
73 |
| - (merge {} :foo))) |
74 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
75 |
| - (merge {} "str")))) |
| 70 | + #?@(:cljs [(is (thrown? js/Error (merge {} 1))) |
| 71 | + (is (thrown? js/Error (merge {} 1 2))) |
| 72 | + (is (thrown? js/Error (merge {} :foo))) |
| 73 | + (is (thrown? js/Error (merge {} "str")))] |
| 74 | + :default [(is (thrown? Exception (merge {} 1))) |
| 75 | + (is (thrown? Exception (merge {} 1 2))) |
| 76 | + (is (thrown? Exception (merge {} :foo))) |
| 77 | + (is (thrown? Exception (merge {} "str")))])) |
76 | 78 |
|
77 | 79 | (testing "undefined `merge` behavior on non-maps"
|
78 | 80 | ;; Behavior for non-map input is undefined. We intentionally do not test
|
|
83 | 85 | (is (any? (merge (first {:a "a"}) {:b "b"} {:c "c"})))
|
84 | 86 | (is (= [:foo] (merge [:foo])))
|
85 | 87 | (is (= :foo (merge :foo)))
|
86 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
87 |
| - (merge :foo :bar))) |
88 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
89 |
| - (merge 100 :foo))) |
90 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
91 |
| - (merge "str" :foo))) |
92 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
93 |
| - (merge nil (range)))) |
94 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
95 |
| - (merge {} '(1 2)))) |
96 |
| - (is (thrown? #?(:cljs :default, :clj Exception, :clr Exception) |
97 |
| - (merge {} 1 2))))))) |
| 88 | + #?@(:cljs [(is (thrown? js/Error (merge :foo :bar))) |
| 89 | + (is (thrown? js/Error (merge 100 :foo))) |
| 90 | + (is (thrown? js/Error (merge "str" :foo))) |
| 91 | + (is (thrown? js/Error (merge nil (range)))) |
| 92 | + (is (thrown? js/Error (merge {} '(1 2)))) |
| 93 | + (is (thrown? js/Error (merge {} 1 2)))] |
| 94 | + :default [(is (thrown? Exception (merge :foo :bar))) |
| 95 | + (is (thrown? Exception (merge 100 :foo))) |
| 96 | + (is (thrown? Exception (merge "str" :foo))) |
| 97 | + (is (thrown? Exception (merge nil (range)))) |
| 98 | + (is (thrown? Exception (merge {} '(1 2)))) |
| 99 | + (is (thrown? Exception (merge {} 1 2)))]))))) |
0 commit comments