This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
/
test.sh
executable file
路120 lines (109 loc) 路 4.58 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
LISP="${1:-./mlisp89}"
TOTAL=0
SUCCESS=0
success-counter() {
if [ $? -eq 0 ]; then
echo Test OK
SUCCESS=$((SUCCESS + 1))
else
echo Test FAIL
fi
TOTAL=$((TOTAL + 1))
}
check-ok() {
echo "$1 -> $2"
echo "$1" | $LISP | grep -q "^$2$"
success-counter
}
check-file-ok() {
echo "$1 -> $2"
cat $1 | $LISP | grep -q "^$2$"
success-counter
}
check-repl-ok() {
echo "$1 -> $2"
echo $1 | cat examples/repl0.lisp - | $LISP | grep -q "^$2$"
success-counter
}
check-repl-file-ok() {
echo "$1 -> $2"
cat examples/repl0.lisp $1 | $LISP | grep -q "^$2$"
success-counter
}
check-ok '(car (quote (1 2 3 4)))' '1'
check-ok '(cdr (quote (1 2 3 4)))' '(2 3 4)'
check-ok '(cons (quote 1) (cons (quote 2) (quote ())))' '(1 2)'
check-ok '((lambda (x) (cons x (cons (quote 1) (quote ())))) (quote 7))' '(7 1)'
check-ok '((lambda (x) (cons x (quote 1))) (quote 7))' '(7 . 1)'
check-ok '(pair? (quote (1 2 3)))' '#t'
check-ok '(eq? (quote hello) (quote hello))' '#t'
check-ok '(eq? (quote hello) (quote world))' '()'
check-ok '(pair? (cons (quote hello) (quote world)))' '#t'
check-ok '(pair? (quote hello))' '()'
check-ok '(quote ())' '()'
check-ok '((lambda (x) (write x)) (quote hello))' 'hello'
check-ok '(write (quote (cons (quote 1) (quote 2))))' '(cons (quote 1) (quote 2))'
check-ok '(cons (quote 1) (cons (quote 2) (cons (quote 3) (cons (quote 4) (quote ())))))' '(1 2 3 4)'
check-ok '(quote (1 2 3 4))' '(1 2 3 4)'
check-ok '(cons (quote 1) (cons (quote 2) (quote ())))' '(1 2)'
check-ok '(write (cons (quote (hello world)) (quote ())))' '((hello world))'
check-ok '((lambda (x y) (cons y (cons x (quote ())))) (quote 67) (quote 89))' '(89 67)'
check-ok '(quote a-symbol-that-is-longer-than-thirty-two-bytes)' 'a-symbol-that-is-longer-than-th'
check-ok '((lambda (f x) (f)) ((lambda (x) (lambda () x)) (quote x)) (quote y))' 'x'
check-ok '(cond ((quote t) (quote ok)))' 'ok'
check-ok '(cond ((quote ()) (quote ok)))' '()'
check-ok '"hello world"' '"hello world"'
check-ok '1234' '1234'
check-ok '(+ 1 2)' '3'
check-ok '(- 10 3 2 1)' '4'
check-ok '(foldr cons '\''() '\''(1 2 3))' '(1 2 3)'
check-ok '(foldl cons '\''() '\''(1 2 3))' '(3 2 1)'
check-ok '((curry + 1) 3)' '4'
check-ok '(let ((zero? (curry = 0))) (zero? 0))' '#t'
check-ok '((compose (lambda (x) (+ x 1)) (lambda (x) (* x 2))) 2)' '5'
check-ok '(let* ((a 1) (b 2)) (+ a b))' '3'
check-ok '(eval '\''(+ 1 2) (environment))' '3'
check-ok '(eval '\''a '\''((a 5)))' '5'
check-file-ok examples/assoc.lisp 'lisp'
check-file-ok examples/apply.lisp '(a b c)'
check-file-ok examples/apply2.lisp '(fn (1 2 3 4))'
check-file-ok examples/reverse.lisp '(9 8 7 6 5 4 3 2 1)'
check-file-ok examples/map.lisp '((1 0) (2 0) (3 0))'
check-file-ok examples/list.lisp '(a b c)'
check-file-ok examples/lambda-logic.lisp '(true false true false)'
check-file-ok examples/ycomb.lisp '(1 2 3)'
check-file-ok examples/u-comb.lisp '(9 8 7 6 5 4 3 2 1)'
check-file-ok examples/u-comb-reverse.lisp '(9 8 7 6 5 4 3 2 1)'
check-file-ok examples/y-comb-reverse.lisp '(9 8 7 6 5 4 3 2 1)'
check-file-ok examples/y-comb-reverse-apply.lisp '(9 8 7 6 5 4 3 2 1)'
check-file-ok examples/macro.lisp 'this'
check-file-ok examples/macro-ex.lisp '(bar qux)'
check-file-ok examples/lambda-rest.lisp '2'
check-file-ok examples/append.lisp '(1 2 3 4 5 6)'
check-file-ok examples/curry.lisp '(HEAD TAIL)'
check-file-ok examples/quasiquote.lisp '(a b e d)'
check-file-ok examples/cond.lisp 'e'
check-file-ok examples/built-in-map.lisp '(2 3 4)'
check-file-ok examples/let.lisp '3'
check-file-ok examples/format.lisp 'hello 21553 test world
#t'
check-file-ok examples/letrec.lisp '(4 3 2 1)'
check-file-ok examples/expand.lisp '(let ((x (Y (lambda (x) (lambda (y r) (if (= y 0) r (cons y (x (- y 1) r)))))))) (x 4 (quote ())))'
check-file-ok examples/90-min-example.lisp '10946'
# Meta Circular Interpreter Tests
#check-repl-ok 'hello' 'carl'
#check-repl-ok '(quote (write hello))' '(write hello)'
#check-repl-ok '(write (cons (quote hello) (cons (quote world) null)))' '(hello world)'
#check-repl-ok '(apply write (cons (cons (quote hello) (cons (quote world) null)) null))' '(hello world)'
#
#check-repl-file-ok examples/eval.lisp 'hello'
#check-repl-file-ok examples/assoc.lisp 'lisp'
#check-repl-file-ok examples/apply.lisp '(fn 1 2 3 4)'
#check-repl-file-ok examples/apply2.lisp '(fn (1 2 3 4))'
#check-repl-file-ok examples/reverse.lisp '(9 8 7 6 5 4 3 2 1)'
#check-repl-file-ok examples/map.lisp '((1 0) (2 0) (3 0))'
#check-repl-file-ok examples/lambda-logic.lisp '(true false true false)'
#check-repl-file-ok examples/ycomb.lisp '(1 2 3)'
echo "Passed $SUCCESS of $TOTAL"
exit $(( $TOTAL - $SUCCESS ))