~subsetpark/ec

ref: big ec/test/env.janet -rw-r--r-- 1.3 KiB
3f9b6ebe — Zach Smith Support bigints (note: this does not work on account of floats being coerced to big ints) 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(import /src/calc)
(import /src/parser)
(import /src/eval)
(import /src/env)

(import /src/operations :prefix "o/")
(import /src/adverbs :prefix "a/")

(use testament)
(use /test-support)

(deftest not-found
  (let [s (env/new-env)]
    (is (thrown? (eval/lookup s "foo")))))

(deftest atom-definition
  (let [s (env/new-env)
        parsed (parser/parse "40 'foo def")]
    (eval-all s parsed)
    (let [lookup (eval/lookup s "foo")]
      (is (calc/Int? lookup))
      (is (= 40 (lookup :value))))))

(deftest quotation-definition
  (let [s (env/new-env)
        parsed (parser/parse "(1 +) 'inc def")]
    (eval-all s parsed)
    (let [lookup (eval/lookup s "inc")]
      (is (calc/Thunk? lookup))
      (let [[one plus] (lookup :data)]
        (is (calc/Int? one))
        (is (= 1 (one :value)))

        (is (calc/Symbol? plus))
        (is (= "+" (plus :value)))))))

(deftest quotation-application
  (let [s (env/new-env)
        parsed (parser/parse "(1 +) 'inc def 10 inc")]
    (eval-all s parsed)
    (let [eleven (calc/peek s)]
      (is (calc/Float? eleven))
      (is (= 11 (eleven :value))))))

(deftest map-vector
  (let [s (env/new-env)
        parsed (parser/parse "[1 2 3 4] (1 +) map")]
    (eval-all s parsed)
    (let [vec (calc/peek s)]
      (vec= [2 3 4 5] vec))))

(run-tests!)