FANDOM


--<pre>
local testcases = {{'#mod=if|test1|test2|test3', 'test2'},
        {'#mod=if||test2|test3', 'test3'},
        {'#mod=autochangecat|test2|test3|days=0', '[[Category:test3]]'},
        {'#modulename=autochangecat|test2|test3|days=0', '[[Category:test3]]'},
        {'#modulename=autochangecat|#fname=main|test2|test3|days=0', '[[Category:test3]]'},
        {'#mod=Module:If|test1|test2|test3', 'test2'},
        {'#mod=dev:If|test1|test2|test3', 'test2'},
        {'#mod=dev:if|test1|test2|test3', 'test2'},
        {'#mod=devif', '<strong class="error">Error: could not find a module called `Devif` on dev.wikia.</strong>'},
        {'#mod=moduleif', '<strong class="error">Error: could not find a module called `Moduleif` on dev.wikia.</strong>'},
        {'#mod=Devmodule/testmodule|#fname=isleapyear', '<strong class="error">Error: that module does not have a function called `isleapyear`.</strong>'},
        {'#mod=x_x','<strong class="error">Error: could not find a module called `X_x` on dev.wikia.</strong>'},
        {'#mod=if|fname=x_x',"nil"},
        {'','<strong class="error">Error: no `#mod` parameter given (should be the name of a module on dev.wikia).</strong>'},
        {'#mod=Devmodule/testmodule|#fname=dontCallMe', '<strong class="error">Error: leave me alone.</strong>'},
}
--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', '[[Category:test3]]'},
        {'#modulename=autochangecat|test2|test3|days=0', '[[Category:test3]]'},
        {'#modulename=autochangecat|#fname=main|test2|test3|days=0', '[[Category:test3]]'},
        {'#mod=Module:If|test1|test2|test3', 'test2'},
        {'#mod=dev:If|test1|test2|test3', 'test2'},
        {'#mod=dev:if|test1|test2|test3', 'test2'},
        {'#mod=devif', '<strong class="error">Error: could not find a module called `Devif` on dev.wikia.</strong>'},
        {'#mod=moduleif', '<strong class="error">Error: could not find a module called `Moduleif` on dev.wikia.</strong>'},
        {'#mod=Devmodule/testmodule|#fname=isleapyear', '<strong class="error">Error: that module does not have a function called `isleapyear`.</strong>'},
        {'#mod=x_x','<strong class="error">Error: could not find a module called `X_x` on dev.wikia.</strong>'},
        {'#mod=if|fname=x_x',"nil"},
        {'','<strong class="error">Error: no `#mod` parameter given (should be the name of a module on dev.wikia).</strong>'},
        {'#mod=Devmodule/testmodule|#fname=dontCallMe', '<strong class="error">Error: leave me alone.</strong>'},
}
--
local p = require('Dev:ScribuntoUnit')
local suite = p:new()
 
function invoke(moduleName, args)
    --Helper function for invoking
    local invokeCmd = "{{#invoke:"..moduleName 
    local frame = mw.getCurrentFrame()
 
    for i,v in pairs(args) do
        invokeCmd = invokeCmd .. "|"..i .."=".. v
    end
 
    invokeCmd = 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('<strong class="error">', 
        invoke(moduleName,{["#mod"]='Devmodule/testmodule'}),
        true,'This test only passes if testmodule does not contain function "main"')
    suite:assertStringContains('<strong class="error">', 
        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 ='{{#invoke:'..moduleName..'|main|' .. 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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.