diff options
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | test.lua | 57 |
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 | |||
11 | written in lua | 11 | written in lua |
12 | that isn't fennel. | 12 | that isn't fennel. |
13 | 13 | ||
14 | it's still very much a work-in-progress | 14 | it's still very much a work-in-progress. |
15 | while 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 | ||
26 | run `make repl` to set up a testing repl of the lam interpreter. | 25 | run `make repl` to set up a testing repl of the lam interpreter. |
27 | you can also run `make test` to start a lua repl | 26 | you can also run `make` to start a lua repl |
28 | with all of lam's modules preloaded. | 27 | with all of lam's modules preloaded, |
28 | or `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. | |||
49 | thanks to peter norvig's [series on lisp interpreters][norvig] | 50 | thanks to peter norvig's [series on lisp interpreters][norvig] |
50 | and to m455 | 51 | and to m455 |
51 | and to my friends | 52 | and to my friends |
53 | and 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 | ||
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 | --- |