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:28, 5 September 2024 (Try using config for testcases). 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'}
	}
}

-- Example unit test.
function p.main(frame)
	local out = ''
	
	for _, cfg in ipairs(tests) do
		out = out .. '==' .. cfg.name .. '==\n'
		
		local sourceCode = '{{#invoke:Sandbox/BrandonXLF/Module:Map params'
		
		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