isolate some tests from settings
[view.love.git] / test.lua
blobb2b6f3cdca4ea5ff9c26c84f81e01d7ad1588805
1 -- Some primitives for tests.
2 --
3 -- Success indicators go to the terminal; failures go to the window.
4 -- I don't know what I am doing.
6 function check(x, msg)
7 if x then
8 io.write('.')
9 else
10 error(msg)
11 end
12 end
14 function check_nil(x, msg)
15 if x == nil then
16 io.write('.')
17 else
18 error(msg..'; should be nil but got "'..x..'"')
19 end
20 end
22 function check_eq(x, expected, msg)
23 if eq(x, expected) then
24 io.write('.')
25 else
26 error(msg..'; got "'..x..'"')
27 end
28 end
30 function eq(a, b)
31 if type(a) ~= type(b) then return false end
32 if type(a) == 'table' then
33 if #a ~= #b then return false end
34 for k, v in pairs(a) do
35 if b[k] ~= v then
36 return false
37 end
38 end
39 for k, v in pairs(b) do
40 if a[k] ~= v then
41 return false
42 end
43 end
44 return true
45 end
46 return a == b
47 end