Module:Roman/testcases
Appearance
![]() | This is the test cases page for the module Module:Roman. Results of the test cases. |
-- Unit tests for [[Module:Roman/sandbox]]. Click talk page to run tests.
local moduleName = 'Roman/sandbox' -- assigning this to a variable as it is later used to generate an #invoke statement.
local mainFuncName = 'main'
local mm = require('Module:' .. moduleName)
local suite = require('Module:UnitTests')
function suite.buildInvocation(funcName, args)
args = args or {}
local argsClone = mw.clone(args)
-- Build a module invocation equivalent to the args table. Taken from [[Module:Unsubst]].
-- Numbered args first.
local ret = '{{#invoke:' .. moduleName .. '|' .. funcName
for k, v in ipairs(argsClone) do
v = tostring(v)
if string.find(v, '=', 1, true) then
-- likely something like 1=foo=bar, we need to do it as a named arg
break
end
ret = ret .. '|' .. v
argsClone[k] = nil
end
for k, v in pairs(argsClone) do
k = tostring(k)
v = tostring(v)
ret = ret .. '|' .. k .. '=' .. v
end
return ret .. '}}'
end
function suite:getInvokeResult(funcName, args, convertNumber) -- Unless convertNumber is false, the number is converted to a number, if possible, on re-entry to Lua.
args = args or {}
local invocation = self.buildInvocation(funcName, args)
local result = self.frame:preprocess(invocation)
if convertNumber ~= false and tonumber(result) then
return tonumber(result)
else
return result
end
end
function suite:assertInvokeEquals(expected, funcName, args, convertNumber)
args = args or {}
local invokeResult = self:getInvokeResult(funcName, args, convertNumber)
self:assertEquals(expected, invokeResult)
end
function p:test_preliminary()
local argarray = {
{},
{},
}
self:assertInvokeEquals('N', 'main', {'0'})
end
return suite