|
8 | 8 |
|
9 | 9 | (deftest test-eval |
10 | 10 | #?(:cljs nil |
11 | | - :default (testing "Strings, numbers, characters, true, false, nil and keywords evaluate to themselves." |
12 | | - (are [expected form] (= expected (eval form)) |
13 | | - ;; lots of Clojure objects just evaluate to themselves |
14 | | - 1 1 |
15 | | - 0 0 |
16 | | - -1 -1 |
17 | | - 1.0 1.0 |
18 | | - 1N 1N |
19 | | - 1.0M 1.0M |
20 | | - 1/2 1/2 |
21 | | - "a string" "a string" |
22 | | - "(+ 1 2)" "(+ 1 2)" ; strings are just evaluated as strings |
23 | | - \x \x |
24 | | - true true |
25 | | - false false |
26 | | - nil nil |
27 | | - :a-keyword :a-keyword))) |
28 | | - #?(:cljs nil |
29 | | - :default (testing "Symbol resolution" |
30 | | - ;; namespace qualified |
31 | | - (is (= 42 (eval 'clojure.core-test.eval/x))))) |
32 | | - #?(:cljs nil |
33 | | - :default (testing "Vectors, Maps, Sets" |
34 | | - ;; basic literal collections |
35 | | - (is (= [:a :b] (eval [:a :b]))) |
36 | | - (is (= {:a :b} (eval {:a :b}))) |
37 | | - (is (= #{:a :b} (eval #{:a :b}))) |
38 | | - ;; collections with embedded symbols |
39 | | - (is (= [:a :b 42] (eval [:a :b 'clojure.core-test.eval/x]))))) |
40 | | - #?(:cljs nil |
41 | | - :default (testing "Lists, function application, and macros" |
42 | | - ;; empty list evaluates to itself |
43 | | - (is (= '() (eval '()))) |
44 | | - ;; function calls |
45 | | - (is (= 5 (eval '(+ 2 3)))) |
46 | | - (is (= 6 (eval '(* 2 3)))) |
47 | | - ;; macros |
48 | | - (is (= 42 (eval '(or false clojure.core-test.eval/x)))) |
49 | | - (is (= 42 (eval '(and (+ 2 3) clojure.core-test.eval/x)))) |
50 | | - ;; special forms |
51 | | - (is (= 43 (eval '(let [y 43] (or false y))))) |
52 | | - (is (= 43 (eval '(loop [y 0] (if (= y 43) y (recur (inc y))))))))))) |
| 11 | + :default |
| 12 | + (do (testing "Strings, numbers, characters, true, false, nil and keywords evaluate to themselves." |
| 13 | + (are [expected form] (= expected (eval form)) |
| 14 | + ;; lots of Clojure objects just evaluate to themselves |
| 15 | + 1 1 |
| 16 | + 0 0 |
| 17 | + -1 -1 |
| 18 | + 1.0 1.0 |
| 19 | + 1N 1N |
| 20 | + 1.0M 1.0M |
| 21 | + 1/2 1/2 |
| 22 | + "a string" "a string" |
| 23 | + "(+ 1 2)" "(+ 1 2)" ; strings are just evaluated as strings |
| 24 | + \x \x |
| 25 | + true true |
| 26 | + false false |
| 27 | + nil nil |
| 28 | + :a-keyword :a-keyword)) |
| 29 | + |
| 30 | + (testing "Symbol resolution" |
| 31 | + ;; namespace qualified |
| 32 | + (is (= 42 (eval 'clojure.core-test.eval/x)))) |
| 33 | + |
| 34 | + (testing "Vectors, Maps, Sets" |
| 35 | + ;; basic literal collections |
| 36 | + (is (= [:a :b] (eval [:a :b]))) |
| 37 | + (is (= {:a :b} (eval {:a :b}))) |
| 38 | + (is (= #{:a :b} (eval #{:a :b}))) |
| 39 | + ;; collections with embedded symbols |
| 40 | + (is (= [:a :b 42] (eval [:a :b 'clojure.core-test.eval/x])))) |
| 41 | + |
| 42 | + (testing "Lists, function application, and macros" |
| 43 | + ;; empty list evaluates to itself |
| 44 | + (is (= '() (eval '()))) |
| 45 | + ;; function calls |
| 46 | + (is (= 5 (eval '(+ 2 3)))) |
| 47 | + (is (= 6 (eval '(* 2 3)))) |
| 48 | + ;; macros |
| 49 | + (is (= 42 (eval '(or false clojure.core-test.eval/x)))) |
| 50 | + (is (= 42 (eval '(and (+ 2 3) clojure.core-test.eval/x)))) |
| 51 | + ;; special forms |
| 52 | + (is (= 43 (eval '(let [y 43] (or false y))))) |
| 53 | + (is (= 43 (eval '(loop [y 0] (if (= y 43) y (recur (inc y)))))))))))) |
0 commit comments