Jump to content

Module:Template invocation/testcases: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
try testing both live and sandbox
Line 4: Line 4:
local protect = require('Module:Protect')
local protect = require('Module:Protect')


local function test(a)
local function test(a, expected)
local mTemplateInvocation = require('Module:Template invocation')
local mTemplateInvocation = require('Module:Template invocation')
local mTemplateInvocation2 = require('Module:Template invocation/sandbox')
local mTemplateInvocation2 = require('Module:Template invocation/sandbox')
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 ' .. tostring(expected) .. '. Got '
p:assertEquals(liveRes, sandboxRes)
p:assertEquals(expected, liveRes, message .. tostring(liveRes) .. ' from live module.')
p:assertEquals(expected, sandboxRes, message .. tostring(sandboxRes) .. ' from sandbox.')
end
end


function p:test_hello()
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'
local a = {'bar', 'baz', abc = 'def'}; a[6]=666; a[7]=777; a['7']='777s'; a[3]=333; a['4']='444s'
return test(a)
return test(a, '{{foo|bar|baz|333|444s|abc=def}}')
end
end


function p:test_equals_sign()
function p:test_equals_sign()
local a = {'bar', 'baz', '{{=}}'}
local a = {'bar', 'baz', '{{=}}'}
return test(a)
return test(a, '{{foo|bar|baz|{{=}}}}')
end
end


Line 27: Line 29:
a[2] = 'bbb'
a[2] = 'bbb'
a[5] = 'eee'
a[5] = 'eee'
return test(a)
return test(a, '{{foo|aaa|bbb|5=eee}}')
end
end



Revision as of 09:37, 23 May 2020

-- 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 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 ' .. tostring(expected) .. '. Got '
	p:assertEquals(expected, liveRes, message .. tostring(liveRes) .. ' from live module.')
	p:assertEquals(expected, sandboxRes, message .. tostring(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