-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
86 lines (70 loc) · 1.68 KB
/
test.sh
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
startup() {
cargo test
if [[ $? -ne 0 ]]; then
exit 1
fi
cargo build
}
test() {
wanted="$1"
jisp_content="$2"
printf "%s" "$jisp_content" > /tmp/e2e_test.jisp
result=$(./target/debug/jisp /tmp/e2e_test.jisp)
if [ "$result" = "$wanted" ]; then
echo "$jisp_content => $result"
else
echo "$jisp_content => $wanted expected, got $result"
exit 1
fi
}
cleanup() {
rm /tmp/e2e_test.jisp
}
startup
test 0 '0'
test 1 '1'
test 2 '2'
test 2 '(+ 1 1)'
test 3 '(+ 1 2)'
test 350 '(+ 100 250)'
test 15 '(+ 1 2 3 4 5)'
test 15 '(+ (+ 1 2) (+ 3 4 5))'
test 4 '(+ 1 1 (- 4 2))'
test 5 '(+ 5 (- 5 2 3) (- 13 13))'
test 20 '(* 4 5)'
test 3 '(/ 12 4)'
test 23 '(+ (/ 12 4) (* 4 5))'
test true '(== (/ 12 4) (+ 1 2))'
test false '(!= (/ 12 4) (+ 1 2))'
test true '(< 1 3)'
test true '(<= 1 3)'
test false '(<= 4 3)'
test true '(> 4 3)'
test true '(>= 4 3)'
test false '(> 3 3)'
test true '(>= 3 3)'
test 25 '(let a 13) (let b 12) (+ a b)'
test 6 '(let a (+ 4 5)) (let b (/ 21 7)) (- a b)'
test 2 '(if (== 2 1) 1 (* 2 1))'
test 20 '(let n 5) (if (== n 1) 1 (* n (- n 1)))'
test '"hello world"' '"hello world"'
test '"hello"' '(let h "hello") (let w "world") (if (== 1 1) h w)'
test 5 '(fn ret5 [] 5) (ret5)'
test 11 '(fn bar [] 3) (fn foo [] (+ (bar) 5)) (+ (bar) (foo))'
test 8 '(fn add [x y] (+ x y)) (add 3 5)'
test 120 '(fn fac [x] (if (== x 0) 1 (* (fac (- x 1)) x))) (fac 5)'
test 120 '(x_fac 5)'
test 5 '(do (+ 10 10) 5)'
test 50 '
(fn foo [] 5)
(fn repeat [times f]
(if (!= times 0)
(do
(let a (f))
(let b (repeat (- times 1) f))
(+ a b))
0))
(repeat 10 foo)
'
cleanup