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 --- test.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 12 deletions(-) (limited to 'test.lua') 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