Module:ScribuntoUnit/sandbox: Difference between revisions

Content deleted Content added
100 characters is still a little too much to view comfortably
testing if we can use a single column "message" instead of the two columns "actual" and "expected"
Line 105:
function ScribuntoUnit:assertTrue(actual, message)
if not actual then
DebugHelper.raise({ScribuntoUnit = true,
text = string.format("Failed to assert that %s is true", tostring(actual)),
message = message}, 2)
}, end2)
end
end
Line 115 ⟶ 118:
function ScribuntoUnit:assertFalse(actual, message)
if actual then
DebugHelper.raise({ScribuntoUnit = true,
text = string.format("Failed to assert that %s is false", tostring(actual)),
message = message}, 2)
}, else2)
end
end
Line 124 ⟶ 130:
-- @param plain search is made with a plain string instead of a ustring pattern
--
function ScribuntoUnit:assertContainsassertStringContains(pattern, s, plain, message)
if type(pattern) ~= 'string' then
DebugHelper.raise({
ScribuntoUnit = true,
text = mw.ustring.format("Pattern type error (expected string, got %s)", type(pattern)),
message = message
}, 2)
end
if type(s) ~= 'string' then
DebugHelper.raise({
ScribuntoUnit = true,
text = mw.ustring.format("String type error (expected string, got %s)", type(s)),
message = message
}, 2)
end
if not mw.ustring.find(s, pattern, nil, plain) then
local display = s
if #display > 70 then
display = mw.ustring.sub(display, 1, 60) .. " ... " .. mw.ustring.sub(display, -10, -1)
end
DebugHelper.raise({
ScribuntoUnit = true,
text = mw.ustring.format('Failed to find %s "%s" in string "%s"', plain and "plain string" or "pattern", pattern, display),
message = message
}, 2)
end
end
 
Line 159 ⟶ 165:
function ScribuntoUnit:assertEquals(expected, actual, message)
 
if type(expected) == 'number' and type(actual) == 'number' then
self:assertWithinDelta(expected, actual, 1e-8, message)
 
elseif expected ~= actual then
DebugHelper.raise({
ScribuntoUnit = true,
Line 255 ⟶ 261:
if processed1 ~= processed2 then
DebugHelper.raise({
ScribuntoUnit = true,
text = string.format("Failed to assert that %s equals expected %s after preprocessing", processed1, processed2),
actual = processed1,
actualRaw = text1,
expected = processed2,
expectedRaw = text2,
message = message,
}, 2)
Line 414 ⟶ 416:
local successIcon, failIcon = self.frame:preprocess('{{tick}}'), self.frame:preprocess('{{cross}}')
local text = '{| class="wikitable scribunto-test-table"\n'
text = text .. '! !! Name !! Expected !! ActualMessage\n'
for _, result in ipairs(testData.results) do
text = text .. '|-\n'
if result.error then
text = text .. '| ' .. failIcon .. ' || ' .. result.name .. ' || '
iftext (result.expected= andtext .. result.actual)message .. then'\n'
text = text .. tostring(result.expected) .. ' || ' .. tostring(result.actual) .. '\n'
else
text = text .. ' colspan="2" | ' .. result.message .. '\n'
end
else
text = text .. '| ' .. successIcon .. ' || ' .. result.name .. ' || ||\n'