--- lam.test local test = {} local eval = require("eval").eval local read_string = require("read").read_string local type = require("type") local luatype, lamtype = type.luatype, type.lamtype function test.expect (form, expected) -- TODO: get equality of tables local diag = string.format("%s == %s", form, expected) 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 ~= "expect" and name ~= "runtests" then print() print(">>>>>>>", name) fn() end end end 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 --- return test