Module:Lua banner/testcases

local mList = require('Module:List') local mMessageBox = require('Module:Message box')

local p = require('Module:ScribuntoUnit'):new

local noWishConfig = { subpage_blacklist = { ['doc'] = true },	allow_wishes = false, error_category = 'ERRCAT_TITLE', -- wish_category = nil, -- should not be accessed default_category = 'DEFCAT_TITLE', module_categories = { ['String'] = 'STRINGCAT_TITLE' } } local withWishConfig = { subpage_blacklist = { ['doc'] = true },	allow_wishes = true, -- error_category = nil, -- should not be accessed wish_category = 'WISHCAT_TITLE', default_category = 'DEFCAT_TITLE', module_categories = { ['String'] = 'STRINGCAT_TITLE' } } local configMetatable = { __index = function(t, k) error("Unexpected field '" .. k .. "' accessed.") end } setmetatable(noWishConfig, configMetatable) setmetatable(withWishConfig, configMetatable)

-- Allow test runner to use both the Module:XXX itself and Module:XXX/sandbox with the same testcases function p:module return self.frame and self.frame.args and self.frame.args.module or 'Lua banner' end

function p:box(text) local boxArgs = { text = text, type = 'notice', small = true, image = '' }	return mMessageBox.main('mbox', boxArgs) end

function p:boxFromList(moduleLinks, withWishes) if #moduleLinks == 0 then if withWishes then return self:box('This template should use Lua') else return self:box(' Error: no modules specified ') end else return self:box('Uses Lua:\n' .. mList.makeList('bulleted', moduleLinks)) end end

function p:assertTCBoth(args, modules, titleObj, expected) local func = require('Module:' .. p:module).renderTrackingCategories self:assertEquals(func(args, modules, titleObj, noWishConfig), expected) self:assertEquals(func(args, modules, titleObj, withWishConfig), expected) end

local function ignoreStripMarkersExceptNoWiki(s) -- return mw.text.unstrip(s); return mw.text.killMarkers(mw.text.unstripNoWiki(s)); end

function p:assertEqualsIgnoreStripMarkers(a, b, ...) if (type(a) == "string") then a = ignoreStripMarkersExceptNoWiki(a); end if (type(b) == "string") then b = ignoreStripMarkersExceptNoWiki(b); end return self:assertEquals(a, b, ...); end

function p:testRenderBox local func = require('Module:' .. p:module).renderBox self:assertEqualsIgnoreStripMarkers(func({}, noWishConfig), self:boxFromList{}) self:assertEqualsIgnoreStripMarkers(func({}, withWishConfig), self:boxFromList({}, true)) self:assertEqualsIgnoreStripMarkers(func({'Module:Lua banner'}, noWishConfig), self:boxFromList{'Module:Lua banner'}) self:assertEqualsIgnoreStripMarkers(func({'Module:Lua banner'}, withWishConfig), self:boxFromList{'Module:Lua banner'}) end

function p:testRenderTrackingCategories local func = require('Module:' .. p:module).renderTrackingCategories local moduleTitle = mw.title.new('Module:Lua banner') local templateTitle = mw.title.new('Template:Lua') local templateDocTitle = mw.title.new('Template:Lua/doc') self:assertEquals(func({}, {}, moduleTitle, noWishConfig), '') self:assertEquals(func({}, {}, moduleTitle, withWishConfig), '') self:assertEquals(func({}, {}, templateTitle, noWishConfig), '') self:assertEquals(func({}, {}, templateTitle, withWishConfig), '') self:assertEquals(func({}, {}, templateDocTitle, noWishConfig), '') self:assertEquals(func({}, {}, templateDocTitle, withWishConfig), '') self:assertTCBoth({}, {'Module:Lua banner'}, moduleTitle, '') self:assertTCBoth({}, {'Module:Lua banner'}, templateTitle, '') self:assertTCBoth({}, {'Module:Lua banner'}, templateDocTitle, '') self:assertTCBoth({}, {'Module:Lua banner', 'Module:String'}, moduleTitle, '') self:assertTCBoth({}, {'Module:Lua banner', 'Module:String'}, templateTitle, '') self:assertTCBoth({}, {'Module:Lua banner', 'Module:String'}, templateDocTitle, '') self:assertTCBoth({}, {'Module:String', 'Module:Lua banner'}, moduleTitle, '') self:assertTCBoth({}, {'Module:String', 'Module:Lua banner'}, templateTitle, '') self:assertTCBoth({}, {'Module:String', 'Module:Lua banner'}, templateDocTitle, '') end

function p:testRenderTrackingCategoriesWithNocat local moduleTitle = mw.title.new('Module:Lua banner') local templateTitle = mw.title.new('Template:Lua') local templateDocTitle = mw.title.new('Template:Lua/doc') self:assertTCBoth({nocat='true'}, {}, moduleTitle, '') self:assertTCBoth({nocat='true'}, {}, templateTitle, '') self:assertTCBoth({nocat='true'}, {}, templateDocTitle, '') self:assertTCBoth({nocat='true'}, {'Module:Lua banner'}, moduleTitle, '') self:assertTCBoth({nocat='true'}, {'Module:Lua banner'}, templateTitle, '') self:assertTCBoth({nocat='true'}, {'Module:Lua banner'}, templateDocTitle, '') self:assertTCBoth({nocat='true'}, {'Module:Lua banner', 'Module:String'}, moduleTitle, '') self:assertTCBoth({nocat='true'}, {'Module:Lua banner', 'Module:String'}, templateTitle, '') self:assertTCBoth({nocat='true'}, {'Module:Lua banner', 'Module:String'}, templateDocTitle, '') self:assertTCBoth({nocat='true'}, {'Module:String', 'Module:Lua banner'}, moduleTitle, '') self:assertTCBoth({nocat='true'}, {'Module:String', 'Module:Lua banner'}, templateTitle, '') self:assertTCBoth({nocat='true'}, {'Module:String', 'Module:Lua banner'}, templateDocTitle, '') end

function p:testRenderTrackingCategoriesWithCategory local func = require('Module:' .. p:module).renderTrackingCategories local moduleTitle = mw.title.new('Module:Lua banner') local templateTitle = mw.title.new('Template:Lua') local templateDocTitle = mw.title.new('Template:Lua/doc') self:assertEquals(func({category='catname'}, {}, moduleTitle, noWishConfig), '') self:assertEquals(func({category='catname'}, {}, moduleTitle, withWishConfig), '') self:assertEquals(func({category='catname'}, {}, templateTitle, noWishConfig), '') self:assertEquals(func({category='catname'}, {}, templateTitle, withWishConfig), '') self:assertEquals(func({category='catname'}, {}, templateDocTitle, noWishConfig), '') self:assertEquals(func({category='catname'}, {}, templateDocTitle, withWishConfig), '') self:assertTCBoth({category='catname'}, {'Module:Lua banner'}, moduleTitle, '') self:assertTCBoth({category='catname'}, {'Module:Lua banner'}, templateTitle, '') self:assertTCBoth({category='catname'}, {'Module:Lua banner'}, templateDocTitle, '') self:assertTCBoth({category='catname'}, {'Module:Lua banner', 'Module:String'}, moduleTitle, '') self:assertTCBoth({category='catname'}, {'Module:Lua banner', 'Module:String'}, templateTitle, '') self:assertTCBoth({category='catname'}, {'Module:Lua banner', 'Module:String'}, templateDocTitle, '') self:assertTCBoth({category='catname'}, {'Module:String', 'Module:Lua banner'}, moduleTitle, '') self:assertTCBoth({category='catname'}, {'Module:String', 'Module:Lua banner'}, templateTitle, '') self:assertTCBoth({category='catname'}, {'Module:String', 'Module:Lua banner'}, templateDocTitle, '') end

function p:testMain local func = require('Module:' .. p:module)._main self:assertEqualsIgnoreStripMarkers(func({}, noWishConfig), self:boxFromList{} .. '') self:assertEqualsIgnoreStripMarkers(func({}, withWishConfig), self:boxFromList({}, true)) self:assertEqualsIgnoreStripMarkers(func({nil}, noWishConfig), self:boxFromList{} .. '') self:assertEqualsIgnoreStripMarkers(func({nil}, withWishConfig), self:boxFromList({}, true)) self:assertEqualsIgnoreStripMarkers(func({'Module:Lua banner'}, noWishConfig), self:boxFromList{'Module:Lua banner'}) self:assertEqualsIgnoreStripMarkers(func({'Module:Lua banner'}, withWishConfig), self:boxFromList{'Module:Lua banner'}) self:assertEqualsIgnoreStripMarkers(func({nil, 'Module:Lua banner'}, noWishConfig), self:boxFromList{'Module:Lua banner'}) self:assertEqualsIgnoreStripMarkers(func({nil, 'Module:Lua banner'}, withWishConfig), self:boxFromList{'Module:Lua banner'}) end

return p