diff options
Diffstat (limited to 'test.lua')
-rw-r--r-- | test.lua | 57 |
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 | ||
3 | local test = {} | 3 | local test = {} |
4 | local eval = require("eval").eval | 4 | local eval = require("eval").eval |
5 | local read = require("read").read | 5 | local read_string = require("read").read_string |
6 | local luatype = require("type").luatype | 6 | local type = require("type") |
7 | local luatype, lamtype = type.luatype, type.lamtype | ||
7 | 8 | ||
8 | function test.test (form, expected) | 9 | function 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 |
16 | end | 20 | end |
17 | 21 | ||
18 | function test.runtests () | 22 | function 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 |
28 | end | 33 | end |
29 | 34 | ||
30 | function test.lambda () | 35 | function 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) |
41 | end | ||
42 | |||
43 | function test.lambda_args () | ||
44 | test.expect([[((lambda (x) x) 3)]], 3) | ||
45 | end | ||
46 | |||
47 | function 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 (?) | ||
36 | end | 69 | end |
37 | 70 | ||
38 | --- | 71 | --- |