Module:Lua banner/testcases

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

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

-- 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) if #moduleLinks == 0 then return self:box(' Error: no modules specified ') else return self:box('Uses Lua:\n' .. mList.makeList('bulleted', moduleLinks)) end end

function p:testRenderBox local func = require('Module:' .. p:module).renderBox self:assertEquals(func{}, self:boxFromList{}) self:assertEquals(func{'Module:Lua banner'}, 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), '') self:assertEquals(func({}, {}, templateTitle), '') self:assertEquals(func({}, {}, templateDocTitle), '') self:assertEquals(func({}, {'Module:Lua banner'}, moduleTitle), '') self:assertEquals(func({}, {'Module:Lua banner'}, templateTitle), '') self:assertEquals(func({}, {'Module:Lua banner'}, templateDocTitle), '') self:assertEquals(func({}, {'Module:Lua banner', 'Module:String'}, moduleTitle), '') self:assertEquals(func({}, {'Module:Lua banner', 'Module:String'}, templateTitle), '') self:assertEquals(func({}, {'Module:Lua banner', 'Module:String'}, templateDocTitle), '') self:assertEquals(func({}, {'Module:String', 'Module:Lua banner'}, moduleTitle), '') self:assertEquals(func({}, {'Module:String', 'Module:Lua banner'}, templateTitle), '') self:assertEquals(func({}, {'Module:String', 'Module:Lua banner'}, templateDocTitle), '') end

function p:testRenderTrackingCategoriesWithNocat 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({nocat='true'}, {}, moduleTitle), '') self:assertEquals(func({nocat='true'}, {}, templateTitle), '') self:assertEquals(func({nocat='true'}, {}, templateDocTitle), '') self:assertEquals(func({nocat='true'}, {'Module:Lua banner'}, moduleTitle), '') self:assertEquals(func({nocat='true'}, {'Module:Lua banner'}, templateTitle), '') self:assertEquals(func({nocat='true'}, {'Module:Lua banner'}, templateDocTitle), '') self:assertEquals(func({nocat='true'}, {'Module:Lua banner', 'Module:String'}, moduleTitle), '') self:assertEquals(func({nocat='true'}, {'Module:Lua banner', 'Module:String'}, templateTitle), '') self:assertEquals(func({nocat='true'}, {'Module:Lua banner', 'Module:String'}, templateDocTitle), '') self:assertEquals(func({nocat='true'}, {'Module:String', 'Module:Lua banner'}, moduleTitle), '') self:assertEquals(func({nocat='true'}, {'Module:String', 'Module:Lua banner'}, templateTitle), '') self:assertEquals(func({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), '') self:assertEquals(func({category='catname'}, {}, templateTitle), '') self:assertEquals(func({category='catname'}, {}, templateDocTitle), '') self:assertEquals(func({category='catname'}, {'Module:Lua banner'}, moduleTitle), '') self:assertEquals(func({category='catname'}, {'Module:Lua banner'}, templateTitle), '') self:assertEquals(func({category='catname'}, {'Module:Lua banner'}, templateDocTitle), '') self:assertEquals(func({category='catname'}, {'Module:Lua banner', 'Module:String'}, moduleTitle), '') self:assertEquals(func({category='catname'}, {'Module:Lua banner', 'Module:String'}, templateTitle), '') self:assertEquals(func({category='catname'}, {'Module:Lua banner', 'Module:String'}, templateDocTitle), '') self:assertEquals(func({category='catname'}, {'Module:String', 'Module:Lua banner'}, moduleTitle), '') self:assertEquals(func({category='catname'}, {'Module:String', 'Module:Lua banner'}, templateTitle), '') self:assertEquals(func({category='catname'}, {'Module:String', 'Module:Lua banner'}, templateDocTitle), '') end

function p:testMain local func = require('Module:' .. p:module)._main 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{}, self:boxFromList{} .. '') self:assertEquals(func{nil}, self:boxFromList{} .. '') self:assertEquals(func{'Module:Lua banner'}, self:boxFromList{'Module:Lua banner'}) self:assertEquals(func{nil, 'Module:Lua banner'}, self:boxFromList{'Module:Lua banner'}) end

return p