Merge lines.love
[view.love.git] / test.lua
blobcc94d9462ef6deae5fbcc40bdadbf7311a44a3d7
1 -- Some primitives for tests.
3 function check(x, msg)
4 if not x then
5 error(msg)
6 end
7 end
9 function check_nil(x, msg)
10 if x ~= nil then
11 error(msg..'; should be nil but got "'..x..'"')
12 end
13 end
15 function check_eq(x, expected, msg)
16 if not eq(x, expected) then
17 error(msg..'; should be "'..expected..'" but got "'..x..'"')
18 end
19 end
21 function eq(a, b)
22 if type(a) ~= type(b) then return false end
23 if type(a) == 'table' then
24 if #a ~= #b then return false end
25 for k, v in pairs(a) do
26 if not eq(b[k], v) then
27 return false
28 end
29 end
30 for k, v in pairs(b) do
31 if not eq(a[k], v) then
32 return false
33 end
34 end
35 return true
36 end
37 return a == b
38 end