Module:UnitTests: Difference between revisions

Content deleted Content added
Update deprecated HTML code (Special:LintErrors/obsolete-tag)
add iterate method; single nullop
Line 15:
end
return max + 1
end
 
local function return_varargs(...)
return ...
end
 
Line 25 ⟶ 29:
num_failures = num_failures + 1
end
local maybe_nowiki = (options and options.nowiki) and mw.text.nowiki or function(...) return ... endreturn_varargs
local differs_at = self.differs_at and (' \n| ' .. first_difference(expected, actual)) or ''
result_table = result_table .. ' \n| ' .. mw.text.nowiki(text) .. ' \n| ' .. maybe_nowiki(expected) .. ' \n| ' .. maybe_nowiki(actual) .. differs_at .. "\n|-\n"
Line 45 ⟶ 49:
num_failures = num_failures + 1
end
local maybe_nowiki = (options and options.nowiki) and mw.text.nowiki or function(...) return ... endreturn_varargs
local differs_at = self.differs_at and (' \n| ' .. first_difference(expected, actual)) or ''
result_table = result_table .. ' \n| ' .. mw.text.nowiki(text1) .. ' \n| ' .. maybe_nowiki(expected) .. ' \n| ' .. maybe_nowiki(actual) .. differs_at .. "\n|-\n"
Line 63 ⟶ 67:
num_failures = num_failures + 1
end
local maybe_nowiki = (options and options.nowiki) and mw.text.nowiki or function(...) return ... endreturn_varargs
local differs_at = self.differs_at and (' \n| ' .. first_difference(expected, actual)) or ''
local display = options and options.display or function(x) return x end
Line 131 ⟶ 135:
num_failures = num_failures + 1
end
local maybe_nowiki = (options and options.nowiki) and mw.text.nowiki or function(...) return ... endreturn_varargs
local actual_str = val_to_str(actual)
local expected_str = val_to_str(expected)
local differs_at = self.differs_at and (' \n| ' .. first_difference(expected_str, actual_str)) or ''
result_table = result_table .. ' \n| ' .. name .. ' \n| ' .. maybe_nowiki(expected_str) .. ' \n| ' .. maybe_nowiki(actual_str) .. differs_at .. "\n|-\n"
end
 
function UnitTester:iterate(examples, func)
if type(examples) ~= 'table' then
error('First argument of iterate should be a table, not ' .. type(examples) .. '.')
end
if type(func) == 'string' then
func = self[func]
for i, example in ipairs(examples) do
if type(example) == 'table' then
func(self, unpack(example))
else
error('iterate does not know what to do with example number ' .. i .. ', whose type is ' .. type(example) .. '.')
end
end
elseif type(func) == 'function' then
for i, example in ipairs(examples) do
if type(example) == 'table' then
func(self, unpack(example))
else
error('iterate does not know what to do with example number ' .. i .. ', whose type is ' .. type(example) .. '.')
end
end
else
error('Second argument of iterate should be a function or a string, not ' .. type(func) .. '.')
end
end