Module:Devmodule/testcases

-- local testcases = {{'#mod=if|test1|test2|test3', 'test2'}, {'#mod=if||test2|test3', 'test3'}, {'#mod=autochangecat|test2|test3|days=0', ''}, {'#modulename=autochangecat|test2|test3|days=0', ''}, {'#modulename=autochangecat|#fname=main|test2|test3|days=0', ''}, {'#mod=Module:If|test1|test2|test3', 'test2'}, {'#mod=dev:If|test1|test2|test3', 'test2'}, {'#mod=dev:if|test1|test2|test3', 'test2'}, {'#mod=devif', ' Error: could not find a module called `Devif` on dev.wikia. '},       {'#mod=moduleif', ' Error: could not find a module called `Moduleif` on dev.wikia. '},       {'#mod=Devmodule/testmodule|#fname=isleapyear', ' Error: that module does not have a function called `isleapyear`. '},       {'#mod=x_x',' Error: could not find a module called `X_x` on dev.wikia. '},       {'#mod=if|fname=x_x',"nil"}, {'',' Error: no `#mod` parameter given (should be the name of a module on dev.wikia). '},       {'#mod=Devmodule/testmodule|#fname=dontCallMe', ' Error: leave me alone. '}, } --Add or remove new testcases here local testSandbox = {{'#mod=if|test1|test2|test3', 'test2'}, {'#mod=if||test2|test3', 'test3'}, {'#mod=autochangecat|test2|test3|days=0', ''}, {'#modulename=autochangecat|test2|test3|days=0', ''}, {'#modulename=autochangecat|#fname=main|test2|test3|days=0', ''}, {'#mod=Module:If|test1|test2|test3', 'test2'}, {'#mod=dev:If|test1|test2|test3', 'test2'}, {'#mod=dev:if|test1|test2|test3', 'test2'}, {'#mod=devif', ' Error: could not find a module called `Devif` on dev.wikia. '},       {'#mod=moduleif', ' Error: could not find a module called `Moduleif` on dev.wikia. '},       {'#mod=Devmodule/testmodule|#fname=isleapyear', ' Error: that module does not have a function called `isleapyear`. '},       {'#mod=x_x',' Error: could not find a module called `X_x` on dev.wikia. '},       {'#mod=if|fname=x_x',"nil"}, {'',' Error: no `#mod` parameter given (should be the name of a module on dev.wikia). '},       {'#mod=Devmodule/testmodule|#fname=dontCallMe', ' Error: leave me alone. '}, } -- local p = require('Dev:ScribuntoUnit') local suite = p:new

function invoke(moduleName, args) --Helper function for invoking local invokeCmd = "" return frame:preprocess(invokeCmd) end

function create_errors(moduleName) -- Tests deliberate errors. This is needed because of strip markers. local moduleName = moduleName or "devmodule" local frame = mw.getCurrentFrame suite:assertStringContains(' ',        invoke(moduleName,{["#mod"]='Devmodule/testmodule'}),        true,'This test only passes if testmodule does not contain function "main"') suite:assertStringContains(' ',        invoke(moduleName,{["#mod"]='Devmodule/testmodule',["#fname"]='error2'}),        true,'Function error2 does not have any errors (add some). ') end -- tests for sandbox function suite:test_errors suite:test_localized_module_namespace create_errors end

function p.tests(testsuite,moduleName,testTable) local processedActual, expected

testTable = testTable or testcases for _,testData in pairs(testTable) do       processedActual = testData[1] expected = testData[2] processedActual ='' testsuite:assertResultEquals(expected,processedActual) end end

function suite:test_sandbox_module --Runs sandbox tests from table "testsandbox" local moduleName = "devmodule/sandbox" create_errors(moduleName) p.tests(self, moduleName,testSandbox) end

function suite:test_main_module --Runs all tests in table testcases local moduleName = "devmodule" p.tests(self,moduleName,testcases) end

function suite:test_localized_module_namespace suite:assertTrue(invoke("Devmodule",{["#mod"]='모듈:Sandbox'})) suite:assertTrue(invoke("Devmodule",{["#mod"]='Módulo:Sandbox'})) end

return suite