test printall_recurse

develop
myk002 2021-08-15 08:31:42 -07:00
parent c5bb139282
commit 0f0ae156c3
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 64 additions and 1 deletions

@ -106,6 +106,69 @@ function test.printall_ipairs_userdata()
end) end)
end end
local function validate_patterns(start_idx, patterns)
for i,pattern in ipairs(patterns) do
expect.true_(mock_print.call_args[start_idx+i-1][1]:find(pattern))
end
return start_idx + #patterns
end
function test.printall_recurse() function test.printall_recurse()
-- TODO local udatatable = new_int_vector()
dfhack.with_temp_object(udatatable, function()
local udataint = df.new('uint32_t')
dfhack.with_temp_object(udataint, function ()
udatatable:insert(0, 10)
udatatable:insert(1, 20)
udatatable:insert(2, 20)
udatatable:insert(3, 20)
udatatable:insert(4, 0)
udatatable:insert(5, 0)
local t2 = {}
local t = {num=5,
bool=false,
fn=function() end,
udatatable=udatatable,
udataint=udataint,
table=t2}
t2.cyclic = t
printall_recurse(t)
expect.eq(49, mock_print.call_count)
expect.true_(mock_print.call_args[1][1]:find('^table: '))
local idx = 2
local EQ = '^%s+= $'
while idx <= 49 do
expect.eq('', mock_print.call_args[idx][1])
idx = idx + 1
local str = mock_print.call_args[idx][1]
if str:startswith('num') then
idx = validate_patterns(idx, {'^num$', EQ, '^5$'})
elseif str:startswith('bool') then
idx = validate_patterns(idx, {'^bool$', EQ, '^false$'})
elseif str:startswith('fn') then
idx = validate_patterns(idx, {'^fn$', EQ, '^function: '})
elseif str:startswith('udatatable') then
idx = validate_patterns(idx,
{'^udatatable$', EQ, '^<vector<int32_t>%[6%]: ',
'%s+', '^0$', EQ, '^10$',
'%s+', '^1$', EQ, '^20$',
'Repeated 2 times',
'%s+', '^4$', EQ, '^0$',
'Repeated 1 times'}) -- [sic]
elseif str:startswith('udataint') then
idx = validate_patterns(idx,
{'^udataint$', EQ, '^<uint32_t: ',
'%s+', '^value$', EQ, '^0$'})
elseif str:startswith('table') then
idx = validate_patterns(idx,
{'^table$', EQ, '^table: ',
'%s+', '^cyclic$', EQ, '^table: ',
'%s+', '^<Cyclic reference'})
else
expect.fail('unhandled print output')
break
end
end
end)
end)
end end