Module:Tmpl/testcases

Wikibooks වෙතින්
local p = require('Module:ScribuntoUnit'):new()
local m = require('Module:Tmpl')

local function callWithArgs(arg0, args)
	local templateArgs = {}
	if args then
		for k, v in pairs(args) do
			local n = tonumber(k) or 0
			if (n >= 1) then
				templateArgs[n] = v
			end
		end
		templateArgs[0] = arg0
	end
	local frame = (mw.getCurrentFrame()
		:newChild{ args = templateArgs }
		:newChild{ args = {} })
	return m.renderTmpl(frame)
end

function p:testRenderTmpl()
	self:assertEquals('test a b c', callWithArgs('test $1 $2 $3', { 'a', 'b', 'c' }))
	self:assertEquals('test a $3', callWithArgs('test $1 $3', { 'a', 'b' }))
	self:assertEquals('test $1 b', callWithArgs('test $1 $2', { [2] = 'b' }))
	self:assertEquals('test $1 $2', callWithArgs('test $1 $2', {}))
end

return p
"https://si.wikibooks.org/w/index.php?title=Module:Tmpl/testcases&oldid=24274" වෙතින් සම්ප්‍රවේශනය කෙරිණි