Module:Template invocation/testcases: Difference between revisions
Appearance
Content deleted Content added
try testing both live and sandbox |
wrap all the things in [[mw:Extension:Scribunto/Lua_reference_manual#mw.text.nowiki |
||
Line 3: | Line 3: | ||
local p = ScribuntoUnit:new() |
local p = ScribuntoUnit:new() |
||
local protect = require('Module:Protect') |
local protect = require('Module:Protect') |
||
local function nw(o) |
|||
return mw.text.nowiki(tostring(o)) |
|||
end |
|||
local function test(a, expected) |
local function test(a, expected) |
||
Line 9: | Line 13: | ||
local liveRes = protect(mTemplateInvocation.invocation)('foo', a) |
local liveRes = protect(mTemplateInvocation.invocation)('foo', a) |
||
local sandboxRes = protect(mTemplateInvocation2.invocation)('foo', a) |
local sandboxRes = protect(mTemplateInvocation2.invocation)('foo', a) |
||
local message = 'Expected ' .. |
local message = 'Expected ' .. nw(expected) .. '. Got ' |
||
p:assertEquals(expected, liveRes, message .. |
p:assertEquals(expected, liveRes, message .. nw(liveRes) .. ' from live module.') |
||
p:assertEquals(expected, sandboxRes, message .. |
p:assertEquals(expected, sandboxRes, message .. nw(sandboxRes) .. ' from sandbox.') |
||
end |
end |
||
Revision as of 09:39, 23 May 2020
![]() | This is the test cases page for the module Module:Template invocation. Results of the test cases. |
-- Unit tests for [[Module:Template invocation]]. Click talk page to run tests.
local ScribuntoUnit = require('Module:ScribuntoUnit')
local p = ScribuntoUnit:new()
local protect = require('Module:Protect')
local function nw(o)
return mw.text.nowiki(tostring(o))
end
local function test(a, expected)
local mTemplateInvocation = require('Module:Template invocation')
local mTemplateInvocation2 = require('Module:Template invocation/sandbox')
local liveRes = protect(mTemplateInvocation.invocation)('foo', a)
local sandboxRes = protect(mTemplateInvocation2.invocation)('foo', a)
local message = 'Expected ' .. nw(expected) .. '. Got '
p:assertEquals(expected, liveRes, message .. nw(liveRes) .. ' from live module.')
p:assertEquals(expected, sandboxRes, message .. nw(sandboxRes) .. ' from sandbox.')
end
function p:test_hello()
local a = {'bar', 'baz', abc = 'def'}; a[6]=666; a[7]=777; a['7']='777s'; a[3]=333; a['4']='444s'
return test(a, '{{foo|bar|baz|333|444s|abc=def}}')
end
function p:test_equals_sign()
local a = {'bar', 'baz', '{{=}}'}
return test(a, '{{foo|bar|baz|{{=}}}}')
end
function p:test_numbered()
local a = {}
a[1] = 'aaa'
a[2] = 'bbb'
a[5] = 'eee'
return test(a, '{{foo|aaa|bbb|5=eee}}')
end
return p