Content deleted Content added
+custom message for assert |
test live module alongside the sandbox (refactor; extract compareLiveAndSandbox; fix message in runYesnoTestWithDefault) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1:
local yesno = require('Module:Yesno
local yesnoSandbox = require('Module:Yesno/sandbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local function compareLiveAndSandbox(expected, liveValue, sandboxValue)
.. " from live module.")
suite:assertEquals(expected, sandboxValue, message .. tostring(sandboxValue)
.. " from sandbox.")
end
local function runYesnoTest(expected, inputValue)
local liveValue = yesno(inputValue)
▲ local message = "Expected " .. tostring(expected) .. ". Got " ..
compareLiveAndSandbox(expected, liveValue, sandboxValue)
▲ suite:assertEquals(expected, yesno(inputValue), message .. " from sandbox")
end
local function runYesnoTestWithDefault(expected, inputValue)
local liveValue
local sandboxValue = yesnoSandbox(inputValue, 'default')
compareLiveAndSandbox(expected, liveValue, sandboxValue)
end
Line 27 ⟶ 38:
function suite:testTrueText()
runYesnoTest(true, 'true')
end
function suite:testT()
runYesnoTest(true, 't')
end
Line 51 ⟶ 66:
function suite:testN()
runYesnoTest(false, 'n')
end
function suite:testF()
runYesnoTest(false, 'f')
end
Line 89 ⟶ 108:
function suite:testYCaps()
runYesnoTest(true, 'Y')
end
function suite:testTCaps()
runYesnoTest(true, 'T')
end
Line 111 ⟶ 134:
function suite:testNCaps()
runYesnoTest(false, 'N')
end
function suite:testFCaps()
runYesnoTest(false, 'F')
end
|