blob: 1d90df236a637771c53a3de12de4520809a62ca2 (
plain)
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
|
--- lam.test
local test = {}
local eval = require("eval").eval
local read = require("read").read
local luatype = require("type").luatype
function test.test (form, expected)
local diag = string.format("%s == %s", form, expected)
local value = eval(read(form))
if value == expected then
print(string.format("ok: %s", diag))
else
print(string.format("not ok: %s != %s", diag, value))
end
end
function test.runtests ()
for name, fn in pairs(test) do
if luatype(fn) == "function"
and name ~= "test"
and name ~= "runtests"
then
print(">>>", name)
fn()
end
end
end
function test.lambda ()
test.test([[((lambda (x) (+ x x)) 3)]], 6)
test.test([[((lambda () 100))]], 100)
test.test([[((lambda (x) 1 2 3) 4)]], 3)
test.test([[((lambda () 1 2 3))]], 3)
test.test([[((lambda (x) x (+ x x) (+ x x x)) 9)]], 27)
end
---
return test
|