Jump to content

Module:ISO 3166/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 23:20, 12 February 2019. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
--SEE: Module talk:ISO 3166/testcases
local p = {}

local arguments = {
	-- {{Positional/numbered parameters},{named arguments}}
	{{'Canada'}},
	{{'United States'}},
	{{'The United States of America'}},
	{{'US'}},
	{{'US', 'New York'}},
	{{'USA', 'New York'}},
	{{'US-NY'}},
	{{'United States', 'New York'}},
	{{'United States', 'New York (State)'}},
	{{'United States', '[[New York (State)]]'}},
	{{'United States', '[[New York (State)|Test]]'}},
	{{'Áfghanistan'}},
	{{'[[United States|THE PLACE]]'}},
	{{'[[File:Flag_of_Canada.svg|20px]]'}},
	{{'{{flag|India}}'}},
	{{'{{CAN}}'}},
	{{'[[Canada]]'}},
	{{[[C"A'NA‘,DA(AAA)']]}},
	{{'Taiwan, Province of China'}},
	{{'Taiwan'}},
	{{'Republic of China'}},
	{{'TW'}},
	{{'TWN'}},
	{{'158'}},
	{{'{{PRC}}'}},
	{{'{{USA}}'}},
	{{'United States<ref name=A>{{cite web|url=http://www.example.com}}</ref>'}},
	{{'United States<ref name="A">{{cite web|url=http://www.example.com}}</ref>'}},
	{{'United States<ref name="B" />'}},
	{{'[[Russia]]', '[[Sakha Republic]]'}}
}
local function makeCell(func, params)
	local code = '<td>{{#invoke:ISO 3166|'..func
	if params[1] then
		for k,v in ipairs(params[1]) do
			code = code..'|'..k..' = '..v..''
		end
	end
	if params[2] then
		for k,v in pairs(params[2]) do
			code = code..'|'..k..' = '..v..''
		end
	end
	return code..'}}</td>'
end
local function makeRow(frame, func, params)
	local out = ''
	out = out..makeCell(func, params) -- Live
	out = out..makeCell(func, params):gsub('ISO 3166','ISO 3166/sandbox') -- Sandbox
	out = out..makeCell(func, params):gsub('<td>','<td><code><nowiki>'):gsub('</td>','</nowiki></code></td>') -- Code
	return frame:preprocess('<tr>'..out..'</tr>')
end
function p.run(frame)
	local out = '<tr><th>Live</th><th>Sandbox</th><th>Code</th></tr>'
	for k,v in ipairs(arguments) do
		out = out..makeRow(frame, frame.args[1], v)
	end
	return '<table class="wikitable">'..out..'</table>'
end
return p