Module:Tmpl/testcases: Difference between revisions
Jump to navigation
Jump to search
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..." |
(No difference)
|
Latest revision as of 21:33, 2 November 2025
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