|
47 | 47 | (is (= {"x" "y"} (meta ^{"x" "y"} [])))
|
48 | 48 | ))
|
49 | 49 |
|
50 |
| -(deftest test-bit-operations |
51 |
| - (testing "Testing bit operations" |
52 |
| - (is (= [1 0 0 40 43 49 49]) |
53 |
| - [(bit-xor 0 1) |
54 |
| - (bit-xor 1 1) |
55 |
| - (bit-xor 1 0) |
56 |
| - (bit-xor 41 1) |
57 |
| - (bit-xor 42 1) |
58 |
| - (bit-xor 42 1 26) |
59 |
| - (apply bit-xor [42 1 26])]) |
60 |
| - (is (= [0 0 1 0 1 1 1] |
61 |
| - [(bit-and 1 0) |
62 |
| - (bit-and 0 0) |
63 |
| - (bit-and 1 1) |
64 |
| - (bit-and 42 1) |
65 |
| - (bit-and 41 1) |
66 |
| - (bit-and 41 1 27) |
67 |
| - (apply bit-and [41 1 27])])) |
68 |
| - (is (= [1 0 1 43 41 59 59] |
69 |
| - [(bit-or 1 0) |
70 |
| - (bit-or 0 0) |
71 |
| - (bit-or 1 1) |
72 |
| - (bit-or 42 1) |
73 |
| - (bit-or 41 1) |
74 |
| - (bit-or 41 1 26) |
75 |
| - (apply bit-or [41 1 26])])) |
76 |
| - (is (= [1 0 0 42 32 32] |
77 |
| - [(bit-and-not 1 0) |
78 |
| - (bit-and-not 0 0) |
79 |
| - (bit-and-not 1 1) |
80 |
| - (bit-and-not 42 1) |
81 |
| - (bit-and-not 41 1 27) |
82 |
| - (apply bit-and-not [41 1 27])])) |
83 |
| - (is (= [0 2 968 16649 0] |
84 |
| - [(bit-clear 1 0) |
85 |
| - (bit-clear 2 0) |
86 |
| - (bit-clear 1000 5) |
87 |
| - (bit-clear 16713 6) |
88 |
| - (bit-clear 1024 10)])) |
89 |
| - (is (= [0 0 992 18761 0] |
90 |
| - [(bit-flip 1 0) |
91 |
| - (bit-flip 2 1) |
92 |
| - (bit-flip 1000 3) |
93 |
| - (bit-flip 16713 11) |
94 |
| - (bit-flip 1024 10)])) |
95 |
| - (is (= [-2 -3 999 -16714 -1025] |
96 |
| - [(bit-not 1) |
97 |
| - (bit-not 2) |
98 |
| - (bit-not -1000) |
99 |
| - (bit-not 16713) |
100 |
| - (bit-not 1024)])) |
101 |
| - (is (= [1 2 1000 18761 1024] |
102 |
| - [(bit-set 1 0) |
103 |
| - (bit-set 2 1) |
104 |
| - (bit-set 1000 3) |
105 |
| - (bit-set 16713 11) |
106 |
| - (bit-set 1024 10)])) |
107 |
| - (is (= [true true true false true] |
108 |
| - [(bit-test 1 0) |
109 |
| - (bit-test 2 1) |
110 |
| - (bit-test 1000 3) |
111 |
| - (bit-test 16713 11) |
112 |
| - (bit-test 1024 10)])))) |
113 |
| - |
114 | 50 | (deftest test-vectors
|
115 | 51 | (testing "Testing vectors"
|
116 | 52 | (is (= :a (nth [:a :b :c :d] 0)))
|
|
185 | 121 | (is (= () (rest [1])))
|
186 | 122 | (is (= () (rest (array 1))))))
|
187 | 123 |
|
188 |
| -(deftest test-apply |
189 |
| - (testing "Testing apply" |
190 |
| - (is (= 0 (apply + nil))) |
191 |
| - (is (= 0 (apply + (list)))) |
192 |
| - (is (= 1 (apply + (list 1)))) |
193 |
| - (is (= 3 (apply + 1 (list 2)))) |
194 |
| - (is (= 7 (apply + 1 2 (list 4)))) |
195 |
| - (is (= 15 (apply + 1 2 4 (list 8)))) |
196 |
| - (is (= 31 (apply + 1 2 4 8 (list 16)))) |
197 |
| - (is (= 63 (apply + 1 2 4 8 16 (list 32)))) |
198 |
| - (is (= 127 (apply + 1 2 4 8 16 (list 32 64)))) |
199 |
| - (is (= 4950 (apply + (take 100 (iterate inc 0))))) |
200 |
| - (is (= () (apply list []))) |
201 |
| - (is (= [1 2 3] (apply list [1 2 3]))) |
202 |
| - (is (= 6 (apply apply [+ [1 2 3]]))) |
203 |
| - ;; apply with infinite sequence |
204 |
| - (is (= 3 (apply (fn [& args] |
205 |
| - (+ (nth args 0) |
206 |
| - (nth args 1) |
207 |
| - (nth args 2))) |
208 |
| - (iterate inc 0)))) |
209 |
| - (is (= [0 1 2 3 4] (take 5 (apply (fn [& m] m) (iterate inc 0))))) |
210 |
| - (is (= [1 2 3 4 5] (take 5 (apply (fn [x & m] m) (iterate inc 0))))) |
211 |
| - (is (= [2 3 4 5 6] (take 5 (apply (fn [x y & m] m) (iterate inc 0))))) |
212 |
| - (is (= [3 4 5 6 7] (take 5 (apply (fn [x y z & m] m) (iterate inc 0))))) |
213 |
| - (is (= [4 5 6 7 8] (take 5 (apply (fn [x y z a & m] m) (iterate inc 0))))) |
214 |
| - (is (= [5 6 7 8 9] (take 5 (apply (fn [x y z a b & m] m) (iterate inc 0))))) |
215 |
| - ;; apply arity tests |
216 |
| - (let [single-arity-non-variadic (fn [x y z] [z y x]) |
217 |
| - multiple-arity-non-variadic (fn ([x] x) ([x y] [y x]) ([x y z] [z y x])) |
218 |
| - single-arity-variadic-fixedargs (fn [x y & more] [more y x]) |
219 |
| - single-arity-variadic-nofixedargs (fn [& more] more) |
220 |
| - multiple-arity-variadic (fn ([x] x) ([x y] [y x]) ([x y & more] [more y x]))] |
221 |
| - (testing "arities" |
222 |
| - (is (= [3 2 1] (apply single-arity-non-variadic [1 2 3]))) |
223 |
| - (is (= [3 2 1] (apply single-arity-non-variadic 1 [2 3]))) |
224 |
| - (is (= [3 2 1] (apply single-arity-non-variadic 1 2 [3]))) |
225 |
| - (is (= 42 (apply multiple-arity-non-variadic [42]))) |
226 |
| - (is (= [2 1] (apply multiple-arity-non-variadic [1 2]))) |
227 |
| - (is (= [2 1] (apply multiple-arity-non-variadic 1 [2]))) |
228 |
| - (is (= [3 2 1] (apply multiple-arity-non-variadic [1 2 3]))) |
229 |
| - (is (= [3 2 1] (apply multiple-arity-non-variadic 1 [2 3]))) |
230 |
| - (is (= [3 2 1] (apply multiple-arity-non-variadic 1 2 [3]))) |
231 |
| - (is (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs [1 2 3 4 5]))) |
232 |
| - (is (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 [2 3 4 5]))) |
233 |
| - (is (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 [3 4 5]))) |
234 |
| - (is (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 3 [4 5]))) |
235 |
| - (is (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 3 4 [5]))) |
236 |
| - (is (= [3 4 5] (take 3 (first (apply single-arity-variadic-fixedargs (iterate inc 1)))))) |
237 |
| - (is (= [2 1] (rest (apply single-arity-variadic-fixedargs (iterate inc 1))))) |
238 |
| - (is (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs [1 2 3 4 5]))) |
239 |
| - (is (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 [2 3 4 5]))) |
240 |
| - (is (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 [3 4 5]))) |
241 |
| - (is (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 3 [4 5]))) |
242 |
| - (is (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 3 4 [5]))) |
243 |
| - (is (= [1 2 3 4 5] (take 5 (apply single-arity-variadic-nofixedargs (iterate inc 1))))) |
244 |
| - (is (= 42 (apply multiple-arity-variadic [42]))) |
245 |
| - (is (= [2 1] (apply multiple-arity-variadic [1 2]))) |
246 |
| - (is (= [2 1] (apply multiple-arity-variadic 1 [2]))) |
247 |
| - (is (= [[3 4 5] 2 1] (apply multiple-arity-variadic [1 2 3 4 5]))) |
248 |
| - (is (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 [2 3 4 5]))) |
249 |
| - (is (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 [3 4 5]))) |
250 |
| - (is (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 3 [4 5]))) |
251 |
| - (is (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 3 4 [5]))) |
252 |
| - (is (= [3 4 5] (take 3 (first (apply multiple-arity-variadic (iterate inc 1)))))) |
253 |
| - (is (= [2 1] (rest (apply multiple-arity-variadic (iterate inc 1))))))))) |
254 |
| - |
255 | 124 | ;; this fails in v8 - why?
|
256 | 125 | ;; (assert (= "symbol\"'string" (pr-str (str 'symbol \" \' "string"))))
|
257 | 126 | (deftest test-misc
|
|
398 | 267 | (is (try (do (take-nth nil [1 2 3]) false)
|
399 | 268 | (catch js/Error e true)))))
|
400 | 269 |
|
401 |
| -(deftest test-booleans |
402 |
| - (testing "Testing boolean predicates" |
403 |
| - (is (= [true false true false false false true true false false] |
404 |
| - [(true? true) |
405 |
| - (true? false) |
406 |
| - (false? false) |
407 |
| - (false? true) |
408 |
| - (true? js/undefined) |
409 |
| - (false? js/undefined) |
410 |
| - (boolean? true) |
411 |
| - (boolean? false) |
412 |
| - (boolean? nil) |
413 |
| - (boolean? js/undefined)])))) |
414 |
| - |
415 | 270 | (deftest test-fn-with-metadata
|
416 | 271 | (let [f (fn [x] (* x 2))
|
417 | 272 | m {:foo "bar"}
|
|
513 | 368 | (is (empty? e-queue))
|
514 | 369 | (is (= {:b :c} (meta e-queue)))))))
|
515 | 370 |
|
516 |
| -(deftest test-try-catch |
517 |
| - (let [a (atom nil)] |
518 |
| - (testing "Testing try/catch" |
519 |
| - (is (= 1 (try 1))) |
520 |
| - (is (= 2 (try 1 (throw (js/Error.)) (catch js/Error e 2)))) |
521 |
| - (is (= 2 (try 1 (throw (js/Error.)) (catch js/Error e 1 2)))) |
522 |
| - (is (= 2 (try 1 (throw (js/Error.)) (catch js/Error e 2) (catch :default e 3)))) |
523 |
| - (is (= 3 (try 1 (throw true) (catch js/Error e 2) (catch :default e 3)))) |
524 |
| - (is (= 2 (try 1 (throw 2) (catch js/Error e 3) (catch :default e e)))) |
525 |
| - (is (= 1 (try 1 (finally (reset! a 42))))) |
526 |
| - (is (= 42 (deref a)))))) |
527 |
| - |
528 |
| -(deftest test-list-comprehensions |
529 |
| - (let [v [1 2 3]] |
530 |
| - (testing "Testing list comprehensions" |
531 |
| - (is (= v (for [e v] e))) |
532 |
| - (is (= [[1 1] [2 4] [3 9]] (for [e v :let [m (* e e)]] [e m]))) |
533 |
| - (is (= [1 2] (for [e v :while (< e 3)] e))) |
534 |
| - (is (= [3] (for [e v :when (> e 2)] e))) |
535 |
| - (is (= [[1 1] [2 4]] (for [e v :while (< e 3) :let [m (* e e)]] [e m])))))) |
536 |
| - |
537 |
| -(deftest test-partial-and-comp |
538 |
| - (let [a10 (partial + 10) |
539 |
| - a20 (partial + 10 10) |
540 |
| - a21 (partial + 10 10 1) |
541 |
| - a22 (partial + 10 5 4 3) |
542 |
| - a23 (partial + 10 5 4 3 1)] |
543 |
| - (testing "Testing partial" |
544 |
| - (is (= 110 (a10 100))) |
545 |
| - (is (= 120 (a20 100))) |
546 |
| - (is (= 121 (a21 100))) |
547 |
| - (is (= 122 (a22 100))) |
548 |
| - (is (= 123 (a23 100))))) |
549 |
| - (let [n2 (comp first rest) |
550 |
| - n3 (comp first rest rest) |
551 |
| - n4 (comp first rest rest rest) |
552 |
| - n5 (comp first rest rest rest rest) |
553 |
| - n6 (comp first rest rest rest rest rest)] |
554 |
| - (testing "Testing comp" |
555 |
| - (is (= 2 (n2 [1 2 3 4 5 6 7]))) |
556 |
| - (is (= 3 (n3 [1 2 3 4 5 6 7]))) |
557 |
| - (is (= 4 (n4 [1 2 3 4 5 6 7]))) |
558 |
| - (is (= 5 (n5 [1 2 3 4 5 6 7]))) |
559 |
| - (is (= 6 (n6 [1 2 3 4 5 6 7])))))) |
560 |
| - |
561 | 371 | (deftest test-sets
|
562 | 372 | (testing "Testing persistent sets"
|
563 | 373 | (is (set []))
|
|
636 | 446 | (is (= (distinct [#{1 2} #{1 2}]) [#{1 2}]))
|
637 | 447 | (is (= (distinct [#{} #{}]) [#{}]))))
|
638 | 448 |
|
639 |
| -(deftest test-regexps |
640 |
| - (testing "Testing regexps" |
641 |
| - (let [r1 #"foo", r2 (re-pattern r1)] |
642 |
| - (is (= r1 r2))) |
643 |
| - (is (= (str (re-pattern "f(.)o")) (str (js* "/f(.)o/")))) |
644 |
| - (is (= (re-find (re-pattern "foo") "foo bar foo baz foo zot") "foo")) |
645 |
| - (is (= (re-find (re-pattern "f(.)o") "foo bar foo baz foo zot") ["foo" "o"])) |
646 |
| - (is (= (re-matches (re-pattern "foo") "foo") "foo")) |
647 |
| - (is (= (re-matches (re-pattern "foo") "foo bar foo baz foo zot") nil)) |
648 |
| - (is (= (re-matches (re-pattern "foo.*") "foo bar foo baz foo zot") "foo bar foo baz foo zot")) |
649 |
| - (is (= (re-seq (re-pattern "foo") "foo bar foo baz foo zot") (list "foo" "foo" "foo"))) |
650 |
| - (is (= (re-seq (re-pattern "f(.)o") "foo bar foo baz foo zot") (list ["foo" "o"] ["foo" "o"] ["foo" "o"]))) |
651 |
| - (is (= (re-matches (re-pattern "(?i)foo") "Foo") "Foo")) |
652 |
| - ; new RegExp("").source => "(?:)" on webkit-family envs, "" elsewhere |
653 |
| - (is (#{"#\"\"" "#\"(?:)\""} (pr-str #""))) |
654 |
| - (is (= (re-find (re-pattern "[\u2028]") " \u2028 ") "\u2028")))) ; regression test for CLJS-889 |
655 |
| - |
656 | 449 | (deftest test-destructuring
|
657 | 450 | (testing "Testing destructuring"
|
658 | 451 | (is (= [2 1] (let [[a b] [1 2]] [b a])))
|
|
0 commit comments