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 14:26, 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 = {
	{'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'}
}

function p.makeCell(fu, pa)
	if fu == 'callstrip' then
		return '<td>'..'{{#invoke:ISO 3166|'..fu..'|'..pa[1]..'}}'..(pa[2] and ' {{#invoke:ISO 3166|'..fu..'|'..pa[2]..'}}' or '')..'</td>'
	else
		return '<td>'..'{{#invoke:ISO 3166|'..fu..'|'..pa[1]..(pa[2] and '|'..pa[2] or '')..'}}'..'</td>'
	end
end

function p.makeRow(frame, fu, pa)
	local out = p.makeCell(fu, pa) -- Live
	out = out..p.makeCell(fu, pa):gsub('ISO 3166','ISO 3166/sandbox') -- Sandbox
	out = out..p.makeCell(fu, pa):gsub('<td>','<td><code><nowiki>'):gsub('</td>','</nowiki></code></td>') -- Code
	return frame:preprocess('<tr>'..out..'</tr>')
end

function p.makeTable(frame, fu)
	local out = '<tr><th>Live</th><th>Sandbox</th><th>Code</th></tr>'
	for k,v in ipairs(arguments) do
		out = out..p.makeRow(frame, fu, v)
	end
	return '<table class="wikitable">'..out..'</table>'
end

function p.run(frame)
	return p.makeTable(frame, frame.args[1])
end

return p