make table_eq check recursive equality
and add tests. to write test the table_eq function itself, I expose it in the text env via expect_raw. if we don't want to do this, alternatives could be: 1. add the test to main.lua itself 2. expose the expect.table_eq function via a test_hooks variable. then test.lua could require main.lua and access the function via the hook. may need to update main.lua a bit to ensure it does not run when it is "require"ddevelop
parent
b302289864
commit
f176310bcd
@ -1,3 +1,31 @@
|
||||
function test.internal_in_test()
|
||||
expect.true_(dfhack.internal.IN_TEST)
|
||||
end
|
||||
|
||||
function test.table_eq()
|
||||
expect.true_(expect_raw.table_eq({}, {}))
|
||||
expect.true_(expect_raw.table_eq({'a'}, {'a'}))
|
||||
expect.true_(expect_raw.table_eq({{'a', k='val'}, 'b'},
|
||||
{{'a', k='val'}, 'b'}))
|
||||
|
||||
expect.false_(expect_raw.table_eq({}, {''}))
|
||||
expect.false_(expect_raw.table_eq({''}, {}))
|
||||
expect.false_(expect_raw.table_eq({'a', {}}, {'a'}))
|
||||
expect.false_(expect_raw.table_eq({{'a', k='val1'}, 'b'},
|
||||
{{'a', k='val2'}, 'b'}))
|
||||
|
||||
local tab = {a='a', b='b'}
|
||||
expect.true_(expect_raw.table_eq(tab, tab))
|
||||
expect.true_(expect_raw.table_eq({tab}, {tab}))
|
||||
|
||||
local tab1, tab2 = {'a'}, {'a'}
|
||||
tab1.self, tab2.self = tab1, tab2
|
||||
expect.true_(expect_raw.table_eq(tab1, tab2))
|
||||
|
||||
tab1.other, tab2.other = tab2, tab1
|
||||
expect.true_(expect_raw.table_eq(tab1, tab2))
|
||||
|
||||
local tabA, tabB, tabC, tabD = {k='a'}, {k='a'}, {k='a'}, {k='a'}
|
||||
tabA.next, tabB.next, tabC.next, tabD.next = tabB, tabC, tabD, tabA
|
||||
expect.true_(expect_raw.table_eq(tabA, tabB))
|
||||
end
|
||||
|
Loading…
Reference in New Issue