diff options
Diffstat (limited to 'test.lua')
-rw-r--r-- | test.lua | 43 |
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 | ||
4 | local test = {} | 3 | local test = {} |
5 | local eval = require("eval").eval | 4 | local eval = require("eval").eval |
6 | local read = require("read").read | 5 | local read = require("read").read |
6 | local luatype = require("type").luatype | ||
7 | 7 | ||
8 | function test.lambda () | 8 | function 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 | 16 | end |
17 | io.write(string.format("%s == %s\n\t", l, target)) | 17 | |
18 | local value = eval(read(l)) | 18 | function 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 |
25 | end | 28 | end |
26 | 29 | ||
30 | function 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) | ||
36 | end | ||
37 | |||
27 | --- | 38 | --- |
28 | return test | 39 | return test |