Module:Convert/tester: Difference between revisions

Content deleted Content added
a unit tester for convert; hoping that simplicity will allow many tests to be run
 
fiddle so output with disp=table works in a table cell
Line 94:
return text:gsub('\n', '\\n')
end
local function show_multilinesafe_cell(text, multiline)
-- This is possibly adequate for testing {{convert}} where want wikitext
return text:gsub('\\n', '<br />')
-- like '[[kilogram|kg]]' to be unchanged so the link works and so the
-- rendered text is short, but need more work if want to use this module
-- to test arbitrary templates.
text = text:gsub('{', '&#123;')
if text:find('align%s*=') then
-- This makes text like 'align="right"|12.3' safe for display in a table cell,
-- while leaving text like '[[kilogram|kg]]' unchanged.
text = text:gsub('|', '&#124;')
end
if multiline then
return text = text:gsub('\\n', '<br />')
end
return text
end
local stats = { pass = 0, fail = 0, ignored = 0 }
Line 104 ⟶ 117:
expected = strip(expected)
local actual = collapse_multiline(run_template(frame, template))
local clean_template = '&#123;' .. template:sub(2):gsub('|', '&#124;') -- 123="{", 124="|"
local actual, sbox = status_box(stats, expected, actual)
result:add('|-')
result:add('| ' .. clean_templatesafe_cell(template))
result:add('| ' .. show_multilinesafe_cell(expected, true))
result:add('| ' .. show_multilinesafe_cell(actual, true))
result:add('| ' .. sbox)
end