Module:Template parameter value/testcases

--Go to the talk page to see the results of the tests. See Template:Template parameter value/testpage for the content used in testing local p = require('Module:UnitTests') local TestPage = "Template:Template parameter value/testpage"

function p:_internal_test(module, name) module.test = function(...) local s,r = module.getValue(...) if not s then return " " .. r		else return r		end end

--Basic errors tests self:equals(name.."error test 1", module.test, " Missing required parameters 'templates' and 'parameter'") self:equals(name.."error test 2", module.test("", "", ""), " Requested title doesn't exist") self:equals(name.."error test 3", module.test(TestPage, "", ""), " No valid template found")

--Test _id grabbing for the TemplateN series self:equals(name.."basic grabbing 1", module.test(TestPage, "X13", "_id"), "1") self:equals(name.."basic grabbing 2", module.test(TestPage, "X11", "_id"), "2") self:equals(name.."basic grabbing 3", module.test(TestPage, "X11", "_id", {template_index=1}), "2") self:equals(name.."basic grabbing 4", module.test(TestPage, "X12", "_id"), "3") self:equals(name.."basic grabbing 5", module.test(TestPage, "X11", "_id", {template_index=2}), "4") self:equals(name.."basic grabbing 6", module.test(TestPage, "X11", "_id", {template_index=3}), "5") self:equals(name.."basic grabbing 7", module.test(TestPage, "X11", "_id", {template_index=4}), "subtemplate") self:equals(name.."basic grabbing 8", module.test(TestPage, "X11", "_id", {template_index=4, parameter_index=2}), "6") self:equals(name.."basic grabbing 9", module.test(TestPage, "X11", "_id", {template_index=4, ignore_subtemplates=true}), "6") --Test grabbing for the other tests (NumericalParameters, HeavyNesting) self:equals(name.."numerical parameters 1", module.test(TestPage, "X21", "1"), "X") self:equals(name.."numerical parameters 2", module.test(TestPage, "X21", "2"), "Y") self:equals(name.."numerical parameters 3", module.test(TestPage, "X21", "3"), "Z") self:equals(name.."numerical parameters 4", module.test(TestPage, "X21", "4"), "W") self:equals(name.."numerical parameters 5", module.test(TestPage, "X21", "5"), "") self:equals(name.."numerical parameters 6", module.test(TestPage, "X21", "6"), "P") self:equals(name.."nesting templates 1", module.test(TestPage, "X22", "1"), "2") self:equals(name.."nesting templates 2", module.test(TestPage, "X22", "1", {ignore_subtemplates=true}), "") self:equals(name.."nesting templates 3", module.test(TestPage, "X22", "A1"), "Nest1") self:equals(name.."nesting templates 4", module.test(TestPage, "X22", "A2"), "Nest2 Content", {nowiki=1}) self:equals(name.."nesting templates 5", module.test(TestPage, "X22", "A3a"), "A", {nowiki=1}) self:equals(name.."nesting templates 6", module.test(TestPage, "X22", "A3b"), "1A2", {nowiki=1}) self:equals(name.."nesting templates 7", module.test(TestPage, "X22", "A4", {parameter_index=2}), "A5") self:equals(name.."nesting templates 8", module.test(TestPage, "X22", "A4", {parameter_index=3}), "Help:Example", {nowiki=1}) self:equals(name.."nesting templates 9", module.test(TestPage, "X22", "A5"), "") self:equals(name.."nesting templates 10", module.test(TestPage, "X22", "A6"), "") self:equals(name.."nesting templates 11", module.test(TestPage, "X22", "A7"), "", {nowiki=1}) end

function p:test_live p:_internal_test(require("Module:Template parameter value"), "Live ") end

function p:test_sandbox p:_internal_test(require("Module:Template parameter value/sandbox"), "Sandbox ") end

return p