blob: b2b6f3cdca4ea5ff9c26c84f81e01d7ad1588805 (
plain) (
blame)
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
|
-- Some primitives for tests.
--
-- Success indicators go to the terminal; failures go to the window.
-- I don't know what I am doing.
function check(x, msg)
if x then
io.write('.')
else
error(msg)
end
end
function check_nil(x, msg)
if x == nil then
io.write('.')
else
error(msg..'; should be nil but got "'..x..'"')
end
end
function check_eq(x, expected, msg)
if eq(x, expected) then
io.write('.')
else
error(msg..'; got "'..x..'"')
end
end
function eq(a, b)
if type(a) ~= type(b) then return false end
if type(a) == 'table' then
if #a ~= #b then return false end
for k, v in pairs(a) do
if b[k] ~= v then
return false
end
end
for k, v in pairs(b) do
if a[k] ~= v then
return false
end
end
return true
end
return a == b
end
|