Module:Sandbox/Andy M. Wang/Sandbox/testcases

-- Unit tests for Module:Sandbox/Andy M. Wang/Sandbox. Click talk page to run tests.

local moduleName = 'Sandbox/Andy M. Wang/Sandbox' -- 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 = '' 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:preprocess_equals(invokeResult, expected) end

function suite:assertInvokeEqual(funcName, testTable, convertNumber) testTable = testTable or {} local expected = testTable[1] local args = testTable[2] or {} self:assertInvokeEquals(expected, funcName, args, convertNumber) end

function suite:assertInvokeEqualMany(funcName, testTables, convertNumber) for i, testTable in ipairs(testTables) do       self:assertInvokeEqual(funcName, testTable, convertNumber) end end

Tests

return suite