Difference between revisions of "Module:ISO 639 name/testcases/ISO 639-1 code to name"

From blackwiki
Jump to navigation Jump to search
blackwiki>Trappist the monk
m (Trappist the monk moved page Module:ISO 639 name/testcases/ISO 639-1-2 to Module:ISO 639 name/testcases/ISO 639-1 without leaving a redirect: 639-1 codes are two-character codes; no need to split into two testcases;)
blackwiki>Gonnym
(auto-generate list from /data)
Line 2: Line 2:
  
 
function p:test_iso_639_1()
 
function p:test_iso_639_1()
 +
local language_codes = mw.loadData("Module:Language/data/iana languages")
 +
local unordered_table = {}
 +
for language_code in pairs(language_codes) do
 +
if string.len(language_code) == 2 then
 +
table.insert(unordered_table, language_code)
 +
end
 +
end
 +
 +
local ordered_table = {}
 +
table.sort(unordered_table)
 +
for _, key in ipairs(unordered_table) do
 +
table.insert(ordered_table, {key})
 +
end
 +
 
     self:preprocess_equals_preprocess_many(
 
     self:preprocess_equals_preprocess_many(
 
     '{{#invoke:ISO 639 name/sandbox|iso_639_code_to_name|link=yes|', '}}', '{{#invoke:ISO 639 name|iso_639_code_to_name|link=yes|', '}}',
 
     '{{#invoke:ISO 639 name/sandbox|iso_639_code_to_name|link=yes|', '}}', '{{#invoke:ISO 639 name|iso_639_code_to_name|link=yes|', '}}',
{
+
ordered_table,
{'aa'},
 
{'ab'},
 
{'ae'},
 
{'af'},
 
{'ak'},
 
{'am'},
 
{'an'},
 
{'ar'},
 
{'as'},
 
{'av'},
 
{'ay'},
 
{'az'},
 
{'ba'},
 
{'be'},
 
{'bg'},
 
{'bh'},
 
{'bi'},
 
{'bm'},
 
{'bn'},
 
{'bo'},
 
{'br'},
 
{'bs'},
 
{'ca'},
 
{'ce'},
 
{'ch'},
 
{'co'},
 
{'cr'},
 
{'cs'},
 
{'cu'},
 
{'cv'},
 
{'cy'},
 
{'da'},
 
{'de'},
 
{'dv'},
 
{'dz'},
 
{'ee'},
 
{'el'},
 
{'en'},
 
{'eo'},
 
{'es'},
 
{'et'},
 
{'eu'},
 
{'fa'},
 
{'ff'},
 
{'fi'},
 
{'fj'},
 
{'fo'},
 
{'fr'},
 
{'fy'},
 
{'ga'},
 
{'gd'},
 
{'gl'},
 
{'gn'},
 
{'gu'},
 
{'gv'},
 
{'ha'},
 
{'he'},
 
{'hi'},
 
{'ho'},
 
{'hr'},
 
{'ht'},
 
{'hu'},
 
{'hy'},
 
{'hz'},
 
{'ia'},
 
{'id'},
 
{'ie'},
 
{'ig'},
 
{'ii'},
 
{'ik'},
 
{'io'},
 
{'is'},
 
{'it'},
 
{'iu'},
 
{'ja'},
 
{'jv'},
 
{'ka'},
 
{'kg'},
 
{'ki'},
 
{'kj'},
 
{'kk'},
 
{'kl'},
 
{'km'},
 
{'kn'},
 
{'ko'},
 
{'kr'},
 
{'ks'},
 
{'ku'},
 
{'kv'},
 
{'kw'},
 
{'ky'},
 
{'la'},
 
{'lb'},
 
{'lg'},
 
{'li'},
 
{'ln'},
 
{'lo'},
 
{'lt'},
 
{'lu'},
 
{'lv'},
 
{'mg'},
 
{'mh'},
 
{'mi'},
 
{'mk'},
 
{'ml'},
 
{'mn'},
 
{'mr'},
 
{'ms'},
 
{'mt'},
 
{'my'},
 
{'na'},
 
{'nb'},
 
{'nd'},
 
{'ne'},
 
{'ng'},
 
{'nl'},
 
{'nn'},
 
{'no'},
 
{'nr'},
 
{'nv'},
 
{'ny'},
 
{'oc'},
 
{'oj'},
 
{'om'},
 
{'or'},
 
{'os'},
 
{'pa'},
 
{'pi'},
 
{'pl'},
 
{'ps'},
 
{'pt'},
 
{'qu'},
 
{'rm'},
 
{'rn'},
 
{'ro'},
 
{'ru'},
 
{'rw'},
 
{'sa'},
 
{'sc'},
 
{'sd'},
 
{'se'},
 
{'sg'},
 
{'sh'},
 
{'si'},
 
{'sk'},
 
{'sl'},
 
{'sm'},
 
{'sn'},
 
{'so'},
 
{'sq'},
 
{'sr'},
 
{'ss'},
 
{'st'},
 
{'su'},
 
{'sv'},
 
{'sw'},
 
{'ta'},
 
{'te'},
 
{'tg'},
 
{'th'},
 
{'ti'},
 
{'tk'},
 
{'tl'},
 
{'tn'},
 
{'to'},
 
{'tr'},
 
{'ts'},
 
{'tt'},
 
{'tw'},
 
{'ty'},
 
{'ug'},
 
{'uk'},
 
{'ur'},
 
{'uz'},
 
{'ve'},
 
{'vi'},
 
{'vo'},
 
{'wa'},
 
{'wo'},
 
{'xh'},
 
{'yi'},
 
{'yo'},
 
{'za'},
 
{'zh'},
 
{'zu'},
 
},
 
 
{nowiki=false, templatestyles=true}
 
{nowiki=false, templatestyles=true}
 
)
 
)

Revision as of 10:49, 18 September 2020

Documentation for this module may be created at Module:ISO 639 name/testcases/ISO 639-1 code to name/doc

local p = require('Module:UnitTests')

function p:test_iso_639_1()
	local language_codes = mw.loadData("Module:Language/data/iana languages")
	local unordered_table = {}
	for language_code in pairs(language_codes) do
		if string.len(language_code) == 2 then
			table.insert(unordered_table, language_code)
		end
	end

	local ordered_table = {}
	table.sort(unordered_table)
	for _, key in ipairs(unordered_table) do
		table.insert(ordered_table, {key})
	end

    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639_code_to_name|link=yes|', '}}', '{{#invoke:ISO 639 name|iso_639_code_to_name|link=yes|', '}}',
		ordered_table,
		{nowiki=false, templatestyles=true}
	)
end

return p