Jump to content

Module:ISO 639 name/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 12:49, 13 August 2020. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
--[=[
Unit tests for [[Module:Citation/CS1]] error messages.  This is not intended to test every possible thing that
can make an error message; rather, it is to test the creation and rendering of the messages themselves.

Click talk page to run tests.

]=]

local p = require('Module:UnitTests')

--[[--------------------------< I S O _ 6 3 9 >----------------------------------------------------------------
]]

function p:test_iso_639()
    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639|', '}}', '{{#invoke:ISO 639 name|iso_639|', '}}',
		{
			{''},																-- no code param
			{'xx'},																-- not a 639-1 code
			{'nv'},																-- 639-1 code
			{'cic'},															-- 639-2 code
			{'nav'},															-- 639-3 code
			{'apa'},															-- 639-5 code

			{'|'},																-- no code param, no 639-part param
			{'xx|1'},															-- not a 639-1 code
			{'nv|1'},															-- 639-1 code
			{'nav|2'},															-- 639-2 code
			{'cic|3'},															-- 639-3 code
			{'apa|5'},															-- 639-5 code

			{'apa|6'},															-- invalid 639-part

			{'el'},																-- 639-1 code in override table
			{'ang'},															-- 639-2 code in override table
			{'egy'},															-- 639-3 code in override table
--			{''},																-- 639-5 code at this writing override table is empty

--language names --
			{'Navajo'},															-- 639-1 name
			{'Navajo'},															-- 639-2 name
			{'Navaho'},															-- 639-3 name
			{'Apache languages'},												-- 639-5 name

			{'Navajo|1'},														-- 639-1 name
			{'Navajo|2'},														-- 639-2 name
			{'Navaho|3'},														-- 639-3 name
			{'Apache languages|5'},												-- 639-5 name

			{'Navajo|5'},														-- name not in 639-5
			{'Apache languages|3'},												-- name not in 639-3
			{'Chickasaw|2'},													-- name not in 639-2
			{'Apache languages|1'},												-- name not in 639-1
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< I S O _ 6 3 9 _ C O D E _ T O _ N A M E >--------------------------------------

cannot specify part

]]

function p:test_iso_639_code_to_name()
    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639_code_to_name|', '}}', '{{#invoke:ISO 639 name|iso_639_code_to_name|', '}}',	-- TODO: update function name to iso_639_code_to_name
		{
			{''},																-- no language param
			{'xx'},																-- not a 639-1 code
			{'xxx'},															-- not a 639-2, 3, 5 code
			{'nv'},																-- 639-1 code
			{'nav'},															-- 639-2 code
			{'nav'},															-- 639-3 code
			{'apa'},															-- 639-5 code

			{'el'},																-- 639-1 code in override table
			{'ang'},															-- 639-2 code in override table
			{'egy'},															-- 639-3 code in override table
--			{''},																-- 639-5 code at this writing override table is empty

-- link & label
			{'nv|link=yes'},													-- links to 639-1 name
			{'nav|link=yes|label=Navaho'},										-- links to 639-2 name with alt spelling label
			{'nav|label=Navaho'},												-- does not link; |label= is ignored
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< I S O _ 6 3 9 _ C O D E _ 1 _ T O _ N A M E >----------------------------------
]]

function p:test_iso_639_code_1_to_name()
    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639_code_1_to_name|', '}}', '{{#invoke:ISO 639 name|iso_639_code_1_to_name|', '}}',	-- TODO: update function name to iso_639_code_1_to_name
		{
			{''},																-- no language param
			{'xx'},																-- not a 639-1 code
			{'xx|hide-err=yes'},												-- not a 639-1 code
			{'nv-Latn'},														-- ietf tag
			{'nv'},																-- 639-1 code
			{'nav'},															-- 639-2 code
			{'el'},																-- override 639-1 code

			{'nv|link=yes'},													-- linked
			{'nv|link=yes|label=Navaho'},										-- linked with alt label
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< I S O _ 6 3 9 _ C O D E _ 2 _ T O _ N A M E >----------------------------------
]]

function p:test_iso_639_code_2_to_name()
    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639_code_2_to_name|', '}}', '{{#invoke:ISO 639 name|iso_639_code_2_to_name|', '}}',	-- TODO: update function name to iso_639_code_2_to_name
		{
			{''},																-- no language param
			{'xxx'},															-- not a 639-2 code
			{'xxx|hide-err=yes'},												-- not a 639-2 code
			{'nav-Latn'},														-- ietf tag
			{'nv'},																-- 639-1 code
			{'nav'},															-- 639-2 code
			{'mga'},															-- override 639-2 code

			{'nav|link=yes'},													-- linked
			{'nav|link=yes|label=Navaho'},										-- linked with alt label
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< I S O _ 6 3 9 _ C O D E _ 3 _ T O _ N A M E >----------------------------------
]]

function p:test_iso_639_code_3_to_name()
    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639_code_3_to_name|', '}}', '{{#invoke:ISO 639 name|iso_639_code_3_to_name|', '}}',	-- TODO: update function name to iso_639_code_3_to_name
		{
			{''},																-- no language param
			{'xxx'},															-- not a 639-3 code
			{'xxx|hide-err=yes'},												-- not a 639-3 code
			{'nav-Latn'},														-- ietf tag
			{'nv'},																-- 639-1 code
			{'nav'},															-- 639-3 code
			{'pms'},															-- override 639-3 code

			{'nav|link=yes'},													-- linked
			{'nav|link=yes|label=Navajo'},										-- linked with alt label
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< I S O _ 6 3 9 _ C O D E _ 5 _ T O _ N A M E >----------------------------------
]]

function p:test_iso_639_code_5_to_name()
    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639_code_5_to_name|', '}}', '{{#invoke:ISO 639 name|iso_639_code_5_to_name|', '}}',	-- TODO: update function name to iso_639_code_5_to_name
		{
			{''},																-- no language param
			{'xxx'},															-- not a 639-5 code
			{'xxx|hide-err=yes'},												-- not a 639-5 code
			{'nav-Latn'},														-- ietf tag
			{'nv'},																-- 639-1 code
			{'apa'},															-- 639-5 code
--			{''},																-- override 639-5 code; none at this writing

			{'apa|link=yes'},													-- linked
			{'apa|link=yes|label=Apache'},										-- linked with alt label
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< I S O _ 6 3 9 _ N A M E _ T O _ C O D E >--------------------------------------
]]

function p:test_iso_639_name_to_code()
    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639_name_to_code|', '}}', '{{#invoke:ISO 639 name|iso_639_name_to_code|', '}}',
		{
			{''},																-- no name param
			{'nv'},																-- 639-1 code
--language names --
			{'Navajo'},															-- 639-1 name
			{'Navajo'},															-- 639-2 name
			{'Navaho'},															-- 639-3 name
			{'Apache languages'},												-- 639-5 name

			{'Navajo|1'},														-- 639-1 name
			{'Navajo|2'},														-- 639-2 name
			{'Navaho|3'},														-- 639-3 name
			{'Apache languages|5'},												-- 639-5 name

			{'Navajo|5'},														-- 639-1 name not in 5
			{'Navajo|3'},														-- 639-2 name not in 3
			{'Navaho|2'},														-- 639-3 name not in 2
			{'Apache languages|1'},												-- 639-5 name not in 1

			{'Apache languages|6'},												-- invalid 639-part

			{'Greek'},															-- only 639-1 code in override table
			{'Old English'},													-- 639-2 code in override table
			{'Ancient Egyptian'},												-- 639-3 code in override table
--			{''},																-- 639-5 code at this writing override table is empty

-- these should not link
			{'Navajo|link=yes'},												-- 639-1 name
			{'Navajo|link=yes|label=Navajo'},									-- 639-2 name
			{'Navaho|label=Navajo'},											-- 639-3 name
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< I S O _ 6 3 9 _ C O D E _ E X I S T S >----------------------------------------
]]

function p:test_iso_639_code_exists()
    self:preprocess_equals_preprocess_many(
    	'{{#invoke:ISO 639 name/sandbox|iso_639_code_exists|', '}}', '{{#invoke:ISO 639 name|iso_639_code_exists|', '}}',	-- TODO: update function name to iso_639_code_exists
		{
			{''},																-- no code param
			{'xx'},																-- not a 639-1 code
			{'xxx'},															-- not a 639-2, 3, 5 code

			{'nv'},																-- 639-1 code
			{'apa'},															-- 639-2 code
			{'nav'},															-- 639-2 code

			{'el'},																-- override 639-1 code
			{'mga'},															-- override 639-2 code
			{'pms'},															-- override 639-3 code
		},
		{nowiki=false, templatestyles=true}
	)
end


return p