about summary refs log tree commit diff stats
path: root/test.lua
blob: 3a7e8a4e62e06d7335cc016526765a0093948ddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--- 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