Jump to content

Module:Sandbox/BrandonXLF/Module:Map params/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 06:33, 5 September 2024 (Add up to Sparse). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:{{ROOTPAGENAME}}]]. Click talk page to run tests,.
local p = {}

local tests = {
	{
		name = 'Basic',
		args = {'<nowiki>{{{@}}}&lt;/nowiki>'},
		parentArgs = {'A', 'B', 'C'}
	},
	{
		name = 'Separator',
		args = {'<nowiki>{{{@}}}&lt;/nowiki>', sep = '{{sp}}+{{sp}}'},
		parentArgs = {'A', 'B', 'C'}
	},
	{
		name = 'Conjunction',
		args = {'<nowiki>{{{@}}}&lt;/nowiki>', sep = '{{sp}}+{{sp}}', conj = '{{sp}}={{sp}}'},
		parentArgs = {'A', 'B', 'C'}
	},
	{
		name = 'Start',
		args = {'<nowiki>{{I}} = {{{@}}}&lt;/nowiki>', start = 3, sep = ',{{sp}}'},
		parentArgs = {'A', 'B', 'C', 'D', 'E'}
	},
	{
		name = 'Extra',
		args = {'<nowiki>{{{@}}}{{{suffix}}}&lt;/nowiki>', extra = 'suffix', sep = '{{sp}}+{{sp}}'},
		parentArgs = {'A', 'B', 'C', suffix = 'i'}
	},
	{
		name = 'Sparse',
		args = {'<nowiki>{{{i}}} = {{{@}}}&lt;/nowiki>', sep = ',{{sp}}', sparse = 'y'},
		parentArgs = {'A', 'B', 'C', 'D', [1000] = 'E'}
	}
}

function p.test(frame)
	local out = ''
	
	for _, cfg in ipairs(tests) do
		out = out .. '==' .. cfg.name .. '==\n'
		
		local sourceCode = '{{#invoke:Sandbox/BrandonXLF/Module:Map params|map'
		
		for k, v in pairs(cfg.args) do
			sourceCode = sourceCode .. '|' .. k .. '=' .. v
		end
		
		sourceCode = sourceCode .. '}}'
		
		cfg.parentArgs.sourceCode = sourceCode
		
		out = out .. frame:expandTemplate{
			title = 'Template:Call wikitext',
			args = cfg.parentArgs
		} .. '\n'
	end
	
	return out
end

return p