Module:Tmpl/testcases

From BoyWiki
Revision as of 22:10, 21 December 2021 by UpgradeTest1 (talk | contribs) (Created page with "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:ass...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Tmpl/testcases/doc

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