Jump to content

Module:Template link with magic/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pppery (talk | contribs) at 23:53, 22 April 2019 (Pppery moved page Module:Template link/testcases to Module:Tlm/testcases without leaving a redirect). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Test cases for [[Module:Template link]]. Click on the talk page to run the tests.

local tl = require('Module:Template link')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

local pipe = '|'
local equals = '='
local leftBrackets = '{{'
local rightBrackets = '}}'

function suite:testInvocationNoTemplate()
	local success, message = pcall(tl.constructInvocation, {}, {})
	self:assertFalse(success)
	self:assertEquals('Template name not specified', message)
end

function suite:testInvocationNoParams()
	self:assertEquals(leftBrackets .. 'Foo' .. rightBrackets, tl.constructInvocation({}, {template = 'Foo'}))
end

function suite:testInvocationLink()
	self:assertEquals(leftBrackets .. '[[Template:Foo|Foo]]' .. rightBrackets, tl.constructInvocation({}, {template = 'Foo', link = true}))
end

function suite:testInvocationNowiki()
	self:assertEquals(leftBrackets .. 'Foo' .. pipe .. mw.text.nowiki('[[Foo|Bar]]') .. rightBrackets, tl.constructInvocation({'[[Foo|Bar]]'}, {template = 'Foo', nowiki = true}))
end

function suite:testInvocationNotNowiki()
	self:assertEquals(leftBrackets .. 'Foo' .. pipe .. '[[Foo|Bar]]' .. rightBrackets, tl.constructInvocation({'[[Foo|Bar]]'}, {template = 'Foo'}))
end

function suite:testInvocationNumberedParams()
	self:assertEquals(leftBrackets .. 'Foo' .. pipe .. 'Bar' .. pipe .. 'Baz' .. rightBrackets, tl.constructInvocation({'Bar', 'Baz'}, {template = 'Foo'}))
end

function suite:testInvocationExplicitNumberedParams()
	self:assertEquals(leftBrackets .. 'Foo' .. pipe .. '5' .. equals .. 'Bar' .. rightBrackets, tl.constructInvocation({[5] = 'Bar'}, {template = 'Foo'}))
end

function suite:testInvocationNamedParams()
	self:assertEquals(leftBrackets .. 'Foo' .. pipe .. 'bar' .. equals .. 'Baz' .. rightBrackets, tl.constructInvocation({bar = 'Baz'}, {template = 'Foo'}))
end

return suite