about summary refs log tree commit diff stats
path: root/test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test.lua')
-rw-r--r--test.lua43
1 files changed, 27 insertions, 16 deletions
diff --git a/test.lua b/test.lua index ce8c034..1d90df2 100644 --- a/test.lua +++ b/test.lua
@@ -1,28 +1,39 @@
1--- lam.test 1--- lam.test
2-- testing helpers
3 2
4local test = {} 3local test = {}
5local eval = require("eval").eval 4local eval = require("eval").eval
6local read = require("read").read 5local read = require("read").read
6local luatype = require("type").luatype
7 7
8function test.lambda () 8function test.test (form, expected)
9 local ls = { 9 local diag = string.format("%s == %s", form, expected)
10 [ [[((lambda (x) (+ x x)) 3)]] ] = 6, 10 local value = eval(read(form))
11 [ [[((lambda () 100))]] ] = 100, 11 if value == expected then
12 [ [[((lambda (x) 1 2 3) 4)]] ] = 3, 12 print(string.format("ok: %s", diag))
13 [ [[((lambda () 1 2 3))]] ] = 3, 13 else
14 [ [[((lambda (x) x (+ x x) (+ x x x)) 9)]] ] = 27, 14 print(string.format("not ok: %s != %s", diag, value))
15 } 15 end
16 for l, target in pairs(ls) do 16end
17 io.write(string.format("%s == %s\n\t", l, target)) 17
18 local value = eval(read(l)) 18function test.runtests ()
19 if value == target then 19 for name, fn in pairs(test) do
20 print "ok" 20 if luatype(fn) == "function"
21 else 21 and name ~= "test"
22 print(string.format("not ok : %s", value)) 22 and name ~= "runtests"
23 then
24 print(">>>", name)
25 fn()
23 end 26 end
24 end 27 end
25end 28end
26 29
30function test.lambda ()
31 test.test([[((lambda (x) (+ x x)) 3)]], 6)
32 test.test([[((lambda () 100))]], 100)
33 test.test([[((lambda (x) 1 2 3) 4)]], 3)
34 test.test([[((lambda () 1 2 3))]], 3)
35 test.test([[((lambda (x) x (+ x x) (+ x x x)) 9)]], 27)
36end
37
27--- 38---
28return test 39return test