Module:Yesno/testcases: Difference between revisions

Content deleted Content added
m fix whitespace
test live module alongside the sandbox (refactor; extract compareLiveAndSandbox; fix message in runYesnoTestWithDefault)
 
(4 intermediate revisions by the same user not shown)
Line 1:
local yesno = require('Module:Yesno/sandbox')
local yesnoSandbox = require('Module:Yesno/sandbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
 
local function compareLiveAndSandbox(expected, liveValue, sandboxValue)
local message = "Expected " .. tostring(expected) .. ". Got " ..
suite:assertEquals(expected, yesno(inputValue)liveValue, message .. " from sandbox"tostring(liveValue)
.. " 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 " ..
tostring(yesno local sandboxValue = yesnoSandbox(inputValue))
compareLiveAndSandbox(expected, liveValue, sandboxValue)
suite:assertEquals(expected, yesno(inputValue), message .. " from sandbox")
end
 
local function runYesnoTestWithDefault(expected, inputValue)
suite:assertEquals(expected,local liveValue = yesno(inputValue, 'default'))
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