about summary refs log tree commit diff stats
path: root/test.lua
diff options
context:
space:
mode:
authorCase Duckworth2024-04-03 22:48:36 -0500
committerCase Duckworth2024-04-03 22:48:36 -0500
commit9b5f5cd2bd81187a4c4fdb25e9038f629da86c12 (patch)
tree12ce2627e80efd4fa84595cc97faf59f2ddc1399 /test.lua
parentUh logo stuff oops (diff)
downloadlam-9b5f5cd2bd81187a4c4fdb25e9038f629da86c12.tar.gz
lam-9b5f5cd2bd81187a4c4fdb25e9038f629da86c12.zip
Update tests and readme
Diffstat (limited to 'test.lua')
-rw-r--r--test.lua57
1 files changed, 45 insertions, 12 deletions
diff --git a/test.lua b/test.lua index 1d90df2..3a7e8a4 100644 --- a/test.lua +++ b/test.lua
@@ -2,37 +2,70 @@
2 2
3local test = {} 3local test = {}
4local eval = require("eval").eval 4local eval = require("eval").eval
5local read = require("read").read 5local read_string = require("read").read_string
6local luatype = require("type").luatype 6local type = require("type")
7local luatype, lamtype = type.luatype, type.lamtype
7 8
8function test.test (form, expected) 9function test.expect (form, expected)
10 -- TODO: get equality of tables
9 local diag = string.format("%s == %s", form, expected) 11 local diag = string.format("%s == %s", form, expected)
10 local value = eval(read(form)) 12 local value = eval(read_string(form))
11 if value == expected then 13 if value == expected then
12 print(string.format("ok: %s", diag)) 14 print(string.format("ok: %s", diag))
15 return true
13 else 16 else
14 print(string.format("not ok: %s != %s", diag, value)) 17 print(string.format("not ok: %s != %s", diag, value))
18 return false
15 end 19 end
16end 20end
17 21
18function test.runtests () 22function test.runtests ()
19 for name, fn in pairs(test) do 23 for name, fn in pairs(test) do
20 if luatype(fn) == "function" 24 if luatype(fn) == "function"
21 and name ~= "test" 25 and name ~= "expect"
22 and name ~= "runtests" 26 and name ~= "runtests"
23 then 27 then
24 print(">>>", name) 28 print()
29 print(">>>>>>>", name)
25 fn() 30 fn()
26 end 31 end
27 end 32 end
28end 33end
29 34
30function test.lambda () 35function test.lambda_sequencing ()
31 test.test([[((lambda (x) (+ x x)) 3)]], 6) 36 test.expect([[((lambda (x) (+ x x)) 3)]], 6)
32 test.test([[((lambda () 100))]], 100) 37 test.expect([[((lambda () 100))]], 100)
33 test.test([[((lambda (x) 1 2 3) 4)]], 3) 38 test.expect([[((lambda (x) 1 2 3) 4)]], 3)
34 test.test([[((lambda () 1 2 3))]], 3) 39 test.expect([[((lambda () 1 2 3))]], 3)
35 test.test([[((lambda (x) x (+ x x) (+ x x x)) 9)]], 27) 40 test.expect([[((lambda (x) x (+ x x) (+ x x x)) 9)]], 27)
41end
42
43function test.lambda_args ()
44 test.expect([[((lambda (x) x) 3)]], 3)
45end
46
47function test.eqv ()
48 -- true
49 test.expect([[(eqv? #t #t)]], true)
50 test.expect([[(eqv? #f #f)]], true)
51 test.expect([[(eqv? 'something 'something)]], true)
52 test.expect([[(eqv? 50 50)]], true)
53 -- todo: exact/inexact
54 -- todo: chars
55 test.expect([[(eqv? '() '())]], true)
56 test.expect([[((lambda () (define a '(1 . 2)) (eqv? a a)))]], true)
57 -- todo: procedures (?)
58 -- false
59 test.expect([[(eqv? 12 'a)]], false)
60 test.expect([[(eqv? #t #f)]], false)
61 test.expect([[(eqv? 'something 'somethingelse)]], false)
62 test.expect([[(eqv? 12 320)]], false)
63 --todo: exact/inexact
64 --todo: chars
65 test.expect([[(eqv? '() '(1 2 3))]], false)
66 test.expect([[(eqv? '(1 2 3) '(1 2 3))]], false)
67 test.expect([[(eqv? '(1 2 3) '(a b c))]], false)
68 -- todo: procedures (?)
36end 69end
37 70
38--- 71---