summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-11-18 18:36:57 +0100
committertomsmeding <tom.smeding@gmail.com>2019-11-18 18:36:57 +0100
commit481884fb892f949478dad8d801ced704baea986c (patch)
tree8c5bcf1d306c8ad3d39d449da8def74cb24dca2d /tests
parent4746aa52f85f4dc3ce8e195f0a5fd8afe2d54378 (diff)
Automatic testing of examples
Diffstat (limited to 'tests')
-rw-r--r--tests/closuretest.lisp7
-rw-r--r--tests/closuretest.out2
-rw-r--r--tests/data.lisp9
-rw-r--r--tests/data.out5
-rw-r--r--tests/disabled/match.lisp15
-rw-r--r--tests/f.lisp7
-rw-r--r--tests/f.out5
-rw-r--r--tests/fibo.lisp156
-rw-r--r--tests/fibo.out25
-rw-r--r--tests/fiboY.lisp24
-rw-r--r--tests/fiboY.out25
-rw-r--r--tests/filetest.lisp3
-rw-r--r--tests/filetest.out4
-rw-r--r--tests/let-fail.lisp8
-rw-r--r--tests/let-fail.out1
-rw-r--r--tests/stdlib.lisp28
-rw-r--r--tests/stdlib.out0
-rw-r--r--tests/symbols.lisp3
-rw-r--r--tests/symbols.out3
19 files changed, 330 insertions, 0 deletions
diff --git a/tests/closuretest.lisp b/tests/closuretest.lisp
new file mode 100644
index 0000000..d743481
--- /dev/null
+++ b/tests/closuretest.lisp
@@ -0,0 +1,7 @@
+(print (((lambda (x) (lambda (y) (+ x y))) 1) 2))
+
+((lambda (f)
+ ((lambda (g1 g2)
+ (print (g1 10) (g1 20)))
+ (f 42)))
+ (lambda (x) (lambda (y) (+ x y))))
diff --git a/tests/closuretest.out b/tests/closuretest.out
new file mode 100644
index 0000000..542797d
--- /dev/null
+++ b/tests/closuretest.out
@@ -0,0 +1,2 @@
+3
+52, 62
diff --git a/tests/data.lisp b/tests/data.lisp
new file mode 100644
index 0000000..1e77aae
--- /dev/null
+++ b/tests/data.lisp
@@ -0,0 +1,9 @@
+#include "stdlib.lisp"
+
+(define li (list 1 2 3))
+
+(print (car li))
+(print (cadr li))
+(print (caddr li))
+(print (list 1 2 3 4 5 6))
+(print '(1 2 3 4 5 6))
diff --git a/tests/data.out b/tests/data.out
new file mode 100644
index 0000000..40c5dd4
--- /dev/null
+++ b/tests/data.out
@@ -0,0 +1,5 @@
+1
+2
+3
+[1,2,3,4,5,6]
+[1,2,3,4,5,6]
diff --git a/tests/disabled/match.lisp b/tests/disabled/match.lisp
new file mode 100644
index 0000000..84503e0
--- /dev/null
+++ b/tests/disabled/match.lisp
@@ -0,0 +1,15 @@
+(define f (x)
+ (match x
+ ((1 2 3) "1-2-3")
+ ((1) "just 1")
+ ((1 ...) "1 something")
+ ((n ...) "number something")
+ ('v "something quoted")
+ "dunno"))
+
+(print (f '(1 2 3)))
+(print (f '(1)))
+(print (f '(1 2 3 4 5)))
+(print (f '(2 3 4 5)))
+(print (f ''"kaas"))
+(print (f "kaas"))
diff --git a/tests/f.lisp b/tests/f.lisp
new file mode 100644
index 0000000..5644138
--- /dev/null
+++ b/tests/f.lisp
@@ -0,0 +1,7 @@
+(print 42)
+(print "kaas")
+(if 42 (print "ja") (print "nee"))
+(define f (lambda (a) (print a)))
+(f "iets")
+(define f (lambda (a) (print a a)))
+(f "iets")
diff --git a/tests/f.out b/tests/f.out
new file mode 100644
index 0000000..297955d
--- /dev/null
+++ b/tests/f.out
@@ -0,0 +1,5 @@
+42
+kaas
+ja
+iets
+iets, iets
diff --git a/tests/fibo.lisp b/tests/fibo.lisp
new file mode 100644
index 0000000..3beae63
--- /dev/null
+++ b/tests/fibo.lisp
@@ -0,0 +1,156 @@
+(define fibo1 (n)
+ (if (<= n 0) 0
+ (if (<= n 2) 1
+ (+ (fibo1 (- n 1)) (fibo1 (- n 2))))))
+
+; == main lambda ==
+; Params: 1
+; B0:
+; t0 <- param 0
+; t1 <- callf "<=" [t0 0]
+; br t1 B1 B2
+; B1:
+; t2 <- assign 0
+; jmp B5
+; B2:
+; t3 <- param 0
+; t4 <- callf "<=" [t3 2]
+; br t4 B3 B4
+; B3:
+; t2 <- assign 1
+; jmp B5
+; B4:
+; t5 <- param 0
+; t6 <- callf "-" [t5 1]
+; t7 <- callf "fibo1" [t6] ; patched up (statically known address, afterwards)
+; t8 <- param 0
+; t9 <- callf "-" [t8 2]
+; t10 <- callf "fibo1" [t9] ; patched up
+; t2 <- callf "+" [t7 t10]
+; jmp B5
+; B5:
+; return t2
+
+
+(define fibo2help (a b n)
+ (if (<= n 0) b
+ (fibo2help b (+ a b) (- n 1))))
+
+(define fibo2 (n)
+ (if (<= n 0) 0
+ (if (<= n 2) 1
+ (fibo2help 1 1 (- n 2)))))
+
+
+(define fibo3 (n)
+ ((lambda (helper)
+ (if (<= n 0) 0
+ (if (<= n 2) 1
+ (helper helper 1 1 (- n 2)))))
+ (lambda (recur a b n)
+ (if (<= n 0) b
+ (recur recur b (+ a b) (- n 1))))))
+
+; == L1 ==
+; Params: 1
+; Closure slots: 1
+; B0:
+; t0 <- closure 0
+; t1 <- callf "<=" [t0 0]
+; br t1 B1 B2
+; B1:
+; t2 <- assign 0
+; jmp B5
+; B2:
+; t3 <- closure 0
+; t4 <- callf "<=" [t3 2]
+; br t4 B3 B4
+; B3:
+; t2 <- assign 1
+; jmp B5
+; B4:
+; t5 <- param 0
+; t6 <- param 0
+; t7 <- closure 0
+; t8 <- callf "-" [t7 2]
+; t2 <- callc t5 [t6 1 1 t8]
+; jmp B5
+; B5:
+; return t2
+;
+; == L2 ==
+; Params: 4
+; B0:
+; t0 <- param 3
+; t1 <- callf "<=" [t0 0]
+; br t1 B1 B2
+; B1:
+; t2 <- param 2
+; jmp B3
+; B2:
+; t3 <- param 0
+; t4 <- param 0
+; t5 <- param 2
+; t6 <- param 1
+; t7 <- param 2
+; t8 <- callf "+" [t6 t7]
+; t9 <- param 3
+; t10 <- callf "-" [t9 1]
+; t2 <- callc t3 [t4 t5 t8 t10]
+; jmp B3
+; B3:
+; return t2
+;
+; == main lambda ==
+; Params: 1
+; B0:
+; t0 <- param 0
+; t1 <- alloc-closure L1 [t0]
+; t2 <- callc t1 [C(L2)]
+; free-closure t1
+; return t2
+
+
+(define for (start end f)
+ (if (<= start end)
+ (do (f start) (for (+ start 1) end f))
+ '()))
+
+; == main lambda ==
+; Params: 3
+; Data table:
+; 0: ()
+; B0:
+; t0 <- param 0
+; t1 <- param 1
+; t2 <- callf "<=" [t0 t1]
+; br t2 B1 B2
+; B1:
+; t3 <- param 2
+; t4 <- param 0
+; _ <- callc t3 [t4]
+; t5 <- param 0
+; t6 <- callf "+" [t5 1]
+; t7 <- param 1
+; t8 <- param 2
+; t9 <- callf "for" [t6 t7 t8] ; patched up
+; jmp B3
+; B2:
+; t9 <- data 0
+; jmp B3
+; B3:
+; return t9
+
+(for 1 25 (lambda (n) (print (fibo3 n))))
+
+; == L1 ==
+; Params: 1
+; B0:
+; t0 <- param 0
+; t1 <- callf "fibo3" [t0]
+; t2 <- callf "print" [t1]
+; return t2
+;
+; == global code ==
+; B0:
+; _ <- callf "for" [1 25 C(L1)]
diff --git a/tests/fibo.out b/tests/fibo.out
new file mode 100644
index 0000000..14950e3
--- /dev/null
+++ b/tests/fibo.out
@@ -0,0 +1,25 @@
+1
+1
+2
+3
+5
+8
+13
+21
+34
+55
+89
+144
+233
+377
+610
+987
+1597
+2584
+4181
+6765
+10946
+17711
+28657
+46368
+75025
diff --git a/tests/fiboY.lisp b/tests/fiboY.lisp
new file mode 100644
index 0000000..d12a5ab
--- /dev/null
+++ b/tests/fiboY.lisp
@@ -0,0 +1,24 @@
+(define cadr (l) (car (cdr l)))
+(define caddr (l) (car (cdr (cdr l))))
+
+(define YY (recur) (lambda (f) (lambda (a) (f ((recur recur) f) a))))
+(define Y (YY YY))
+
+(define forX (recur low_high_func)
+ (if (<= (car low_high_func) (cadr low_high_func))
+ (do
+ ((caddr low_high_func) (car low_high_func))
+ (recur (list (+ (car low_high_func) 1) (cadr low_high_func) (caddr low_high_func))))
+ '()))
+
+(define for (Y forX))
+
+(define fibohelperX (recur n_a_b)
+ (if (<= (car n_a_b) 0) (cadr n_a_b)
+ (recur (list (- (car n_a_b) 1) (caddr n_a_b) (+ (cadr n_a_b) (caddr n_a_b))))))
+
+(define fibohelper (Y fibohelperX))
+
+(define fibo (n) (fibohelper (list n 0 1)))
+
+(for (list 1 25 (lambda (n) (print (fibo n)))))
diff --git a/tests/fiboY.out b/tests/fiboY.out
new file mode 100644
index 0000000..14950e3
--- /dev/null
+++ b/tests/fiboY.out
@@ -0,0 +1,25 @@
+1
+1
+2
+3
+5
+8
+13
+21
+34
+55
+89
+144
+233
+377
+610
+987
+1597
+2584
+4181
+6765
+10946
+17711
+28657
+46368
+75025
diff --git a/tests/filetest.lisp b/tests/filetest.lisp
new file mode 100644
index 0000000..b37d2fe
--- /dev/null
+++ b/tests/filetest.lisp
@@ -0,0 +1,3 @@
+#include "stdlib.lisp"
+
+(print (read-file "tests/filetest.lisp"))
diff --git a/tests/filetest.out b/tests/filetest.out
new file mode 100644
index 0000000..7d444f6
--- /dev/null
+++ b/tests/filetest.out
@@ -0,0 +1,4 @@
+#include "stdlib.lisp"
+
+(print (read-file "tests/filetest.lisp"))
+
diff --git a/tests/let-fail.lisp b/tests/let-fail.lisp
new file mode 100644
index 0000000..005cfc9
--- /dev/null
+++ b/tests/let-fail.lisp
@@ -0,0 +1,8 @@
+(print
+ (
+ (lambda (fid)
+ (let ((x (lambda (arg) fid)))
+ (x 42)))
+ 123
+ )
+)
diff --git a/tests/let-fail.out b/tests/let-fail.out
new file mode 100644
index 0000000..190a180
--- /dev/null
+++ b/tests/let-fail.out
@@ -0,0 +1 @@
+123
diff --git a/tests/stdlib.lisp b/tests/stdlib.lisp
new file mode 100644
index 0000000..380fa2a
--- /dev/null
+++ b/tests/stdlib.lisp
@@ -0,0 +1,28 @@
+(define cadr (x) (car (cdr x)))
+(define caddr (x) (car (cdr (cdr x))))
+(define cadddr (x) (car (cdr (cdr (cdr x)))))
+
+(define YY (recur) (lambda (f) (lambda (a) (f ((recur recur) f) a))))
+(define Y (YY YY))
+
+(define for (start end f)
+ (if (<= start end)
+ (do (f start) (for (+ start 1) end f))
+ '()))
+
+(define with-open-file (path mode f)
+ (let ((fid (sys-open-file mode path)))
+ (let ((value (f fid)))
+ (do
+ (sys-close-file fid)
+ value))))
+
+(define read-file (path)
+ (with-open-file path 0 (lambda (fid)
+ ; (print (sys-get-char fid))
+ ; (print (let ((x (lambda (arg) fid))) (x 42)))
+ (let ((helper (Y (lambda (recur s)
+ (let ((ch (sys-get-char fid)))
+ (if (null? ch) s (recur (+ s ch))))))))
+ (helper ""))
+ )))
diff --git a/tests/stdlib.out b/tests/stdlib.out
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/stdlib.out
diff --git a/tests/symbols.lisp b/tests/symbols.lisp
new file mode 100644
index 0000000..cba1302
--- /dev/null
+++ b/tests/symbols.lisp
@@ -0,0 +1,3 @@
+(print '(1 2 3))
+(print (list 1 2 3))
+(print (= 'hoi 'hoi))
diff --git a/tests/symbols.out b/tests/symbols.out
new file mode 100644
index 0000000..16f9c5e
--- /dev/null
+++ b/tests/symbols.out
@@ -0,0 +1,3 @@
+[1,2,3]
+[1,2,3]
+1