~subsetpark/ec

ref: big ec/test/parser.janet -rw-r--r-- 1.1 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/operations :prefix "o/")
(import /src/adverbs :prefix "a/")

(use testament)
(use /test-support)

(deftest brackets
  (let [[parsed] (parser/parse "()")]
    (is (== nil (parsed :shape)))
    (is (== [] (parsed :data)))))

(deftest vector
  (let [[parsed] (parser/parse "[]")]
    (is (== [0] (parsed :shape)))
    (is (== [] (parsed :data)))))

(deftest num
  (let [[int] (parser/parse "5")
        [float] (parser/parse "5.0")
        [neg] (parser/parse "-5")
        [underscored] (parser/parse "5_000")]

    (is (= 5 (int :value)))
    (is (calc/Int? int))

    (is (= 5 (float :value)))
    (is (calc/Float? float))

    (is (= -5 (neg :value)))
    (is (calc/Int? neg))

    (is (= 5000 (underscored :value)))
    (is (calc/Int? underscored))))

(deftest word
  (let [[add i] (parser/parse "+ i")]
    (is (= "+" (add :value)))
    (is (calc/Symbol? add))

    (is (= "i" (i :value)))
    (is (calc/Symbol? i))))

(deftest symbol
  (let [[parsed] (parser/parse "'foo")]
    (is (calc/Symbol? parsed))
    (is (= true (parsed :quoted?)))
    (is (= "foo" (parsed :value)))))

(run-tests!)