about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README.md10
-rw-r--r--test.lua57
2 files changed, 51 insertions, 16 deletions
diff --git a/README.md b/README.md index 152b0c7..6732535 100644 --- a/README.md +++ b/README.md
@@ -11,8 +11,7 @@ lam is a little toy lisp evaluator
11written in lua 11written in lua
12that isn't fennel. 12that isn't fennel.
13 13
14it's still very much a work-in-progress 14it's still very much a work-in-progress.
15while i work toward a lam 1500 release.
16 15
17## installing lam 16## installing lam
18 17
@@ -24,8 +23,9 @@ it might work on other luae, though.
24## using lam 23## using lam
25 24
26run `make repl` to set up a testing repl of the lam interpreter. 25run `make repl` to set up a testing repl of the lam interpreter.
27you can also run `make test` to start a lua repl 26you can also run `make` to start a lua repl
28with all of lam's modules preloaded. 27with all of lam's modules preloaded,
28or `make test` to run the (very incomplete) test suite.
29 29
30## license 30## license
31 31
@@ -42,6 +42,7 @@ see COPYING for details.
42 42
43- [Lua 5.1 reference](https://www.lua.org/manual/5.1/manual.html) 43- [Lua 5.1 reference](https://www.lua.org/manual/5.1/manual.html)
44- [Luajit](https://luajit.org/) 44- [Luajit](https://luajit.org/)
45- [R5RS](https://conservatory.scheme.org/schemers/Documents/Standards/R5RS/HTML/)
45- [R7RS](https://standards.scheme.org/corrected-r7rs/r7rs.html) 46- [R7RS](https://standards.scheme.org/corrected-r7rs/r7rs.html)
46 47
47## thanks 48## thanks
@@ -49,5 +50,6 @@ see COPYING for details.
49thanks to peter norvig's [series on lisp interpreters][norvig] 50thanks to peter norvig's [series on lisp interpreters][norvig]
50and to m455 51and to m455
51and to my friends 52and to my friends
53and the #shittylisp channel on tilde.town irc
52 54
53[norvig]: https://norvig.com/lispy.html 55[norvig]: https://norvig.com/lispy.html
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---