Module:ScribuntoUnit/sandbox: Difference between revisions

Content deleted Content added
the error in the results table wikicode was in the row with success, not in the header
sync from main module
Line 1:
local deepToString = require("Module:User:Anomie/deepToString")
 
-------------------------------------------------------------------------------
-- Unit tests for Scribunto.
Line 107 ⟶ 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)
text = string.format("Failed to assert that %s is true", tostring(actual)),
message = message
}, 2)
end
end
Line 120 ⟶ 115:
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)
text = string.format("Failed to assert that %s is false", tostring(actual)),
message = message
}, 2)
end
end
Line 133 ⟶ 125:
--
function ScribuntoUnit:assertStringContains(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 167 ⟶ 159:
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,
text = string.format('"Failed to assert that "%s" equals expected "%s"', tostring(actual), tostring(expected)),
actual = actual,
expected = expected,
Line 226 ⟶ 218:
DebugHelper.raise({
ScribuntoUnit = true,
text = string.format("Failed to assert that %s equals expected %s", tostring(actual), tostring(expected)),
deepToString.deepToString(actual),
deepToString.deepToString(expected)),
actual = actual,
expected = expected,
Line 265 ⟶ 255:
if processed1 ~= processed2 then
DebugHelper.raise({
ScribuntoUnit = true,
text = string.format("Failed to assert that %s equals expected %s after preprocessing", processed1, processed2),
messageactual = messageprocessed1,
messageactualRaw = messagetext1,
expected = processed2,
expectedRaw = text2,
message = message,
}, 2)
Line 420 ⟶ 414:
local successIcon, failIcon = self.frame:preprocess('{{tick}}'), self.frame:preprocess('{{cross}}')
local text = '{| class="wikitable scribunto-test-table"\n'
text = text .. '! !! TestName name!! Expected !! ErrorActual\n'
for _, result in ipairs(testData.results) do
text = text .. '|-\n'
if result.error then
text = text .. '| ' .. failIcon .. ' || ' .. result.name .. ' || '
textif =(result.expected text ..and result.message ..actual) '\n'then
text = text .. tostring(result.expected) .. ' || ' .. tostring(result.actual) .. '\n'
}, 2) else
text = text .. ' colspan="2" | ' .. result.message .. '\n'
}, 2) end
else
text = text .. '| ' .. successIcon .. ' || ' .. result.name .. ' || ||\n'
end
end