From 9b5f5cd2bd81187a4c4fdb25e9038f629da86c12 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 3 Apr 2024 22:48:36 -0500 Subject: Update tests and readme --- README.md | 10 ++++++---- 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 written in lua that isn't fennel. -it's still very much a work-in-progress -while i work toward a lam 1500 release. +it's still very much a work-in-progress. ## installing lam @@ -24,8 +23,9 @@ it might work on other luae, though. ## using lam run `make repl` to set up a testing repl of the lam interpreter. -you can also run `make test` to start a lua repl -with all of lam's modules preloaded. +you can also run `make` to start a lua repl +with all of lam's modules preloaded, +or `make test` to run the (very incomplete) test suite. ## license @@ -42,6 +42,7 @@ see COPYING for details. - [Lua 5.1 reference](https://www.lua.org/manual/5.1/manual.html) - [Luajit](https://luajit.org/) +- [R5RS](https://conservatory.scheme.org/schemers/Documents/Standards/R5RS/HTML/) - [R7RS](https://standards.scheme.org/corrected-r7rs/r7rs.html) ## thanks @@ -49,5 +50,6 @@ see COPYING for details. thanks to peter norvig's [series on lisp interpreters][norvig] and to m455 and to my friends +and the #shittylisp channel on tilde.town irc [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 @@ local test = {} local eval = require("eval").eval -local read = require("read").read -local luatype = require("type").luatype +local read_string = require("read").read_string +local type = require("type") +local luatype, lamtype = type.luatype, type.lamtype -function test.test (form, expected) +function test.expect (form, expected) + -- TODO: get equality of tables local diag = string.format("%s == %s", form, expected) - local value = eval(read(form)) + local value = eval(read_string(form)) if value == expected then print(string.format("ok: %s", diag)) + return true else print(string.format("not ok: %s != %s", diag, value)) + return false end end function test.runtests () for name, fn in pairs(test) do if luatype(fn) == "function" - and name ~= "test" + and name ~= "expect" and name ~= "runtests" then - print(">>>", name) + print() + 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) +function test.lambda_sequencing () + test.expect([[((lambda (x) (+ x x)) 3)]], 6) + test.expect([[((lambda () 100))]], 100) + test.expect([[((lambda (x) 1 2 3) 4)]], 3) + test.expect([[((lambda () 1 2 3))]], 3) + test.expect([[((lambda (x) x (+ x x) (+ x x x)) 9)]], 27) +end + +function test.lambda_args () + test.expect([[((lambda (x) x) 3)]], 3) +end + +function test.eqv () + -- true + test.expect([[(eqv? #t #t)]], true) + test.expect([[(eqv? #f #f)]], true) + test.expect([[(eqv? 'something 'something)]], true) + test.expect([[(eqv? 50 50)]], true) + -- todo: exact/inexact + -- todo: chars + test.expect([[(eqv? '() '())]], true) + test.expect([[((lambda () (define a '(1 . 2)) (eqv? a a)))]], true) + -- todo: procedures (?) + -- false + test.expect([[(eqv? 12 'a)]], false) + test.expect([[(eqv? #t #f)]], false) + test.expect([[(eqv? 'something 'somethingelse)]], false) + test.expect([[(eqv? 12 320)]], false) + --todo: exact/inexact + --todo: chars + test.expect([[(eqv? '() '(1 2 3))]], false) + test.expect([[(eqv? '(1 2 3) '(1 2 3))]], false) + test.expect([[(eqv? '(1 2 3) '(a b c))]], false) + -- todo: procedures (?) end --- -- cgit 1.4.1-21-gabe81