มอดูล:Lang/testcases

local p = require('Module:UnitTests')
-- ==========================  ========================== 
--italic=no overrides every other parameter that might set the rendered text's font.
function p:test_01_lang_italic()
	self:preprocess_equals_preprocess_many('italic=', , 'italic=', ,
		{
			{'yes'},
			{'no'},
			{'invert'},
			{'italic'},
			{},
			{'whatever'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess('text=text', 'text=text',
		{nowiki=1})
end
--script=arab the module shall add
dir="rtl" to the text's enclosing  and insert the ‎ marker.
function p:test_02_lang_italic_with_script()
	self:preprocess_equals_preprocess_many('script=', , 'script=', ,
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess_many('script=', , 'script=', ,
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
end
--rtl=yes adds dir="rtl" to the text's enclosing  and inserts the ‎ marker.
function p:test_03_lang_rtl()
	self:preprocess_equals_preprocess_many('rtl=', , 'rtl=', ,
		{
			{'yes'},
			{'no'},
			{},
			{'whatever'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess('text=text', 'text=text',
		{nowiki=1})
end
--code= with values that should not produce error messages:
	'de', 'de-ch', 'de-CH-1901', 'ru-RU-petr1708', '1ca', es-419.
function p:test_04_lang_ietf()
	self:preprocess_equals_preprocess_many('code=', , 'code=', ,
		{
			{'de'},					-- code
			{'nav'},				-- code
			{'1ca'},				-- non-standard code
			{'cmn-Latn'},			-- code-script; shall italicize text
			{'he-hebr'},			-- code-script; shall insert rtl
			{'de-ch'},				-- code-region
			{'de-1901'},			-- code-numeric variant
			{'ru-petr1708'},		-- code-alnum variant
			{'ca-valencia'},		-- code-alpha variant
			{'ru-ru-petr1708'},		-- code-region-variant
			{'es-419'},				-- code-numeric region
			{'ru-Cyrl-RU'},			-- code-script-region
			{'ca-419-valencia'},	-- code-numeric reigion-variant
			{'cel-x-proto'},		-- private-use
		}, {nowiki=1})
end
--italic=invert set.
function p:test_05_lang_invert_italics()
	self:preprocess_equals_preprocess_many('code=ar', , 'code=ar', ,
		{
			{'|text=text|italic=invert'},
			{"|text=text|italic=invert"},
			{"|text=text|italic=invert"},
			{"|text=text|italic=invert"},
			{"|text=text's|italic=invert"},
			{"|text=text's|italic=invert"},
		}, {nowiki=1})
end
-- ==========================  ========================== 
--italic=no overrides every other parameter that might set the rendered text's font.
function p:test_06_lang_xx_italic()
	self:preprocess_equals_preprocess_many('italic=', , 'italic=', ,
		{
			{'yes'},
			{'no'},
			{'invert'},
			{'italic'},
			{},
			{'whatever'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess('text', 'text',
		{nowiki=1})
end
--script=arab the module shall add
dir="rtl" to the text's enclosing  and insert the ‎ marker.
function p:test_07_lang_xx_italic_with_script()
	self:preprocess_equals_preprocess_many('script=', , 'script=', ,
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess_many('script=', , 'script=', ,
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
end
--variant=
parameters - those subtags can all be added to the IETF language code in the template's first positional parameter ().
function p:test_08_lang_xx_script()
	self:preprocess_equals_preprocess_many('script=', , 'script=', ,
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess_many('script=', , 'script=', ,
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
end
--rtl=yes adds dir="rtl" to the text's enclosing  and inserts the ‎ marker.
function p:test_09_lang_xx_rtl()
	self:preprocess_equals_preprocess_many('rtl=', , 'rtl=', ,
		{
			{'yes'},
			{'no'},
			{},
			{'whatever'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess('text', 'text',
		{nowiki=1})
end
--------------------------------------------------------------------------------
Tests various supported combinations of translit formats.
function p:test_10_lang_xx_translit()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|translit-script=Arab'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|translit-std=DIN'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|translit-std=ALA'},
			{'code=ar|عربى|translit=ʿarabī'},
			{'code=ar|عربى|translit=ʿarabī|lit=Arabic'},
			{'code=ar|عربى|translit=ʿarabī|translation=Arabic'},
			{'code=ar|عربى|translit=ʿarabī|lit=Arabic|links=no'},
			{'code=ar|عربى|translation=Arabic'},
			{'code=ar|عربى|translation=Arabic|links=no'},
			{'code=ff|text=𞤁𞤢𞤲𞤣𞤢𞤴𞤯𞤫|translit=something|translit-script=Adlm'},
			{'code=ff|text=𞤁𞤢𞤲𞤣𞤢𞤴𞤯𞤫|translit=something|translit-script=Adlm|translit-std=ALA'},
			{'code=ar|text=نص العنصر النائب|translit=nasu aleunsur alnnay|translit-std=DIN|translit-script=arab'},
			{'code=gem|text=test|translit=ʿarabī|translation=Arabic'},			-- not valid translations, the test is here to see the link with a collective lagnauge
			{'code=ath|text=test|translit=ʿarabī|translation=Arabic'},			-- not valid translations, the test is here to see the link with a collective lagnauge
		}, {nowiki=1})
end
--engvar=
function p:test_11_lang_xx_engvar()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay'},			-- |engvar= omitted
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar='},	-- |engvar= empty
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=au'},	-- valid engvar language tags
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=ca'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=gb'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=ie'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=in'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=nz'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=us'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=za'},
			{'code=ar|rtl=yes|text=نص العنصر النائب|translit=nasu aleunsur alnnay|engvar=nv'},	-- invalid engvar language tag
		}, {nowiki=1})
end
--label= combinations.
function p:test_12_lang_xx_link_and_label()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'code=uk|морити голодом|lit=to kill by starvation|translit=moryty holodom|label=none'},
			{'code=uk|морити голодом|lit=to kill by starvation|translit=moryty holodom|label=none|link=no'},
			{'code=ff|text=test|translit=something|translit-script=Adlm|label=none'},
			{'code=ff|text=test|translit=something|translit-script=Adlm|label=test label'},
		}, {nowiki=1})
end
--italic=invert set.
function p:test_13_lang_xx_invert_italics()
	self:preprocess_equals_preprocess_many('code=ar', , 'code=ar', ,
		{
			{'|text=text|italic=invert'},
			{"|text=text|italic=invert"},
			{"|text=text|italic=invert"},
			{"|text=text|italic=invert"},
			{"|text=text's|italic=invert"},
			{"|text=text's|italic=invert"},
		}, {nowiki=1})
end
-- ==========================  ========================== 
-- --------------------------  --------------------------
Tests various supported combinations of translit formats.
function p:test_14_transl_formats()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			-- language with transliteration standard (std) tests:
			{'ja|iso|test'}, -- get code value:			x (y language) transliteration
			{'kana|iso|test'}, -- get script value:		x (y script) transliteration
			{'oto|iso|test'}, -- get default value:		x transliteration
			-- code or script found in "no_std" tests:
			-- TODO: no current code example {'???|test'}, -- no_std code:
			{'xsux|test'}, -- no_std script:			x transliteration (whatever the override value is)
			-- translit-script tests:
			{'Cyrl|š'}, -- script:						x-script transliteration
			-- no translit-script or std tests:
			{'ar|test'}, -- romanization:				x-language romanization
			{'oto|test'}, -- romanization collective:	x languages romanization
			
		}, {nowiki=1})
end
--italic= with values 'yes', 'no', present but not set, default, unset, and the invalid 'whatever'.
There is a separate test for the parameter not present.
function p:test_15_transl_italics()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'ar|nasu aleunsur alnnayib|italic='},
			{'ar|nasu aleunsur alnnayib|italic=yes'},
			{'ar|nasu aleunsur alnnayib|italic=no'},
			{'ar|nasu aleunsur alnnayib|italic=default'},
			{'ar|nasu aleunsur alnnayib|italic=whatever'},
			{'ar|nasu \'\'aleunsur\'\' alnnayib|italic=unset'},
			{'Arab|nasu \'\'aleunsur\'\' alnnayib|italic=unset'},
		}, {nowiki=1})
end
--engvar= with various legitimate values and translit standards and engvar spelling in the
tooltip
function p:test_16_transl_engvar()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'ja|Tōkyō tawā'},													-- generic |engvar= omitted: Japanese-language romanization
			{'ja|Tōkyō tawā|envar='},											-- generic |engvar= empty: Japanese-language romanization
			{'ja|Tōkyō tawā|engvar=ca'},										-- generic with american-english spelling: Japanese-language romanization
			{'ja|Tōkyō tawā|engvar=ie'},										-- generic with british-english spelling: Japanese-language romanisation
			{'ko|rr|seongmyeong'},												-- tooltip= Revised Romanization of Korean transliteration; default engvar spelling
			{'ko|rr|seongmyeong|engvar='},										-- tooltip= default engvar spelling
			{'ko|rr|seongmyeong|engvar=us'},									-- tooltip= default engvar spelling 
			{'ko|rr|seongmyeong|engvar=in'},									-- tooltip= Revised Romanisation of Korean transliteration
																				-- at this writing (2024-08-30) yaleko romanization not use at en.wiki
			{'ko|yaleko|seongmyeong'},											-- tooltip= Yale romanization of Korean; default engvar spelling
			{'ko|yaleko|seongmyeong|engvar='},									-- tooltip= default engvar spelling
			{'ko|yaleko|seongmyeong|engvar=us'},								-- tooltip= default engvar spelling 
			{'ko|yaleko|seongmyeong|engvar=in'},								-- tooltip= Yale romanisation of Korean
		}, {nowiki=1})
end
-- ==========================  ========================== 
-- --------------------------  --------------------------
Returns category links from IETF tags.
A complete list of valid tests can be found here:- Module:Lang/testcases/ISO 639-1 category from tag- Module:Lang/testcases/ISO 639-3-1 category from tag (A–H)- Module:Lang/testcases/ISO 639-3-2 category from tag (I–N)- Module:Lang/testcases/ISO 639-3-3 category from tag (O–Z)- Module:Lang/testcases/ISO 639 deprecated and override category from tag
function p:test_17_category_from_tag()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'fr|link=yes'},
			{'ber|link=yes'},
			{'en|link=yes'},
			{'en-gb|link=yes'},
			{'fr'},
			{'FR'},
			{'ber'},
			{'BER'},
			{'en'},
			{'EN'},
			{'en-gb'},
			{'EN-GB'},
		})
end
-- ==========================  ========================== 
-- --------------------------  --------------------------
Returns language names from IETF tags.
A complete list of valid tests can be found here:- Module:Lang/testcases/ISO 639-1 name from tag- Module:Lang/testcases/ISO 639-3-1 name from tag (A–H)- Module:Lang/testcases/ISO 639-3-2 name from tag (I–N)- Module:Lang/testcases/ISO 639-3-3 name from tag (O–Z)- Module:Lang/testcases/ISO 639 deprecated and override name from tag
function p:test_18_name_from_tag()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'fr|link=yes'},
			{'ber|link=yes'},
			{'en|link=yes'},
			{'en-gb|link=yes'},
			{'fr'},
			{'FR'},
			{'ber'},
			{'BER'},
			{'en'},
			{'EN'},
			{'en-gb'},
			{'EN-GB'},
		})
end
-- ==========================  ========================== 
-- --------------------------  --------------------------
Returns language IETF tags from language names.
A complete list of valid tests can be found here:- Module:Lang/testcases/ISO 639-1 tag from name- Module:Lang/testcases/ISO 639-3-1 tag from name (A–H)- Module:Lang/testcases/ISO 639-3-2 tag from name (I–N)- Module:Lang/testcases/ISO 639-3-3 tag from name (O–Z)- Module:Lang/testcases/ISO 639 deprecated and override tag from name
function p:test_19_tag_from_name()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'french'},
			{'French'},
			{'FRENCH'},
			{'Berber Languages'},
			{'Berber languages'},
			{'British English'},
			{'en'},
			{'EN'},
		})
end
-- ==========================  ========================== 
-- --------------------------  --------------------------
Returns true if valid IETF tag.
function p:test_20_is_ietf_tag()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'french'},
			{'French'},
			{'FRENCH'},
			{'Berber Languages'},
			{'Berber languages'},
			{'British English'},
			{'fr'},
			{'FR'},
			{'ber'},
			{'BER'},
			{'en'},
			{'EN'},
			{'en-gb'},
			{'EN-GB'},
		})
end
-- ==========================  ========================== 
-- --------------------------  --------------------------
Returns true if valid language name.
function p:test_21_is_lang_name()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'french'},
			{'French'},
			{'FRENCH'},
			{'Berber Languages'},
			{'Berber languages'},
			{'British English'},
			{'fr'},
			{'FR'},
			{'ber'},
			{'BER'},
			{'en'},
			{'EN'},
			{'en-gb'},
			{'EN-GB'},
		})
end
-- ==========================  ========================== 
----------------------------------------------------------------------------------------------------
Lang errors.
function p:test_22_lang_errors()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{},								-- no text
			{'fr'},								-- no text
			{'text=text'},						-- missing language tag
			{'fr|code=fr|text'},				-- conflicting |1= and |code=			
			{'fr|text|text=text'},				-- conflicting |2= and |text=
			{'proto=proto-y-bad|text=text'},	-- invalid |proto=
			{'fr|\'\'italics\'\},				-- text has italic markup
			{'fr|text=text=text'},	-- text already uses lang attribute
			{'fr|malformed\'\'\'\'\'\},		-- text has malformed markup
			{'1ca|text'},						-- unrecognized language tag: 1ca
			{'zz|text'},						-- unrecognized language code
			{'glg|text'},						-- code: glg promoted to code: gl
			{'iw|text'},						-- code: iw is deprecated
		}, {nowiki=1})
end
-- --------------------------  --------------------------
Lang-xx errors.
function p:test_23_lang_xx_errors()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{},													-- no text
			{'code=fr'},											-- no text
			{'text=text'},											-- missing language tag
			{'code=fr|text|text=text'},								-- conflicting  and |text=
			{'code=fr|text|translit|translit=translit'},			-- conflicting  and |translit=
			{'code=fr|text|lit|lit=lit'},							-- conflicting  and |lit= or |translation=
			{'code=fr|text|translation|translation=translation'},	-- conflicting  and |lit= or |translation=
			{'code=fr|text|lit=lit|translation=translation'},		-- conflicting |lit= and |translation=
			{'code=fr|text'},							-- text already uses lang attribute
			{'code=fr-Latn|script=Latn|text'},						-- redundant script tag
			{'code=fr|script=nonsense|text'},						-- unrecognized script: nonsense for code fr
			{'code=ar|script=Arab|text'},							-- script: script: arab not supported for code: ar
			{'code=en-US|region=US|text'},							-- redundant region tag
			{'code=de-XL|text'},									-- unrecognized region: xl for code de
			{'code=de-1901|variant=1901|text'},						-- redundant variant tag
			{'code=de-19022|text'},									-- unrecognized variant: 19022
			{'code=de|script=Armn|variant=1901|text'},				-- unrecognized variant: 1901 for code-script pair: de-armn
			{'code=en|variant=1901|text'},							-- unrecognized variant: 1901 for code: en
			{'code=es-x-419|text'},									-- unrecognized private tag: 419
			{'code=ar|rtl=yes|نص العنصر النائب|nasu aleunsur alnnayib|translit-std=bob'}, --invalid |translit-std=: bob
			{'code=ar|text=نص العنصر النائب|translit=nasu aleunsur alnnay|translit-std=DIN|translit-script=ar'}, -- invalid |translit-script= value
		}, {nowiki=1})
end
-- --------------------------  --------------------------
Transl errors.
function p:test_24_transl_errors()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'al-Khwarizmi'},
			{'ar'},
			{'at|al-Khwarizmi'},
			{'ar|AL|al-Khwarizmi'},
			{'Arab|nasu \'\'aleunsur\'\' alnnayib|italic=yes|italics=no'},
		}, {nowiki=1})
end
-- --------------------------  --------------------------
category_from_tag errors.
function p:test_25_category_from_tag_errors()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'sfsfsfs'},
		}, {nowiki=1})
end
-- --------------------------  --------------------------
name_from_tag errors.
A complete list of valid tests can be found here:- Module:Lang/testcases/ISO 639-1 name from tag- Module:Lang/testcases/ISO 639-3-1 name from tag (A–H)- Module:Lang/testcases/ISO 639-3-2 name from tag (I–N)- Module:Lang/testcases/ISO 639-3-3 name from tag (O–Z)- Module:Lang/testcases/ISO 639 deprecated and override name from tag
function p:test_26_name_from_tag_errors()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'sfsfsfs'},
		}, {nowiki=1})
end
-- --------------------------  --------------------------
tag_from_name errors.
A complete list of valid tests can be found here:- Module:Lang/testcases/ISO 639-1 tag from name- Module:Lang/testcases/ISO 639-3-1 tag from name (A–H)- Module:Lang/testcases/ISO 639-3-2 tag from name (I–N)- Module:Lang/testcases/ISO 639-3-3 tag from name (O–Z)- Module:Lang/testcases/ISO 639 deprecated and override tag from name
function p:test_27_tag_from_name_errors()
	self:preprocess_equals_preprocess_many(, , , ,
		{
			{'sfsfsfs'},
		}, {nowiki=1})
end
-- --------------------------  --------------------------
html_tag_select errors.
function p:test_28_html_tag_select()
	implied_para_content = 
Text with...
implied paragraph breaks.
	self:preprocess_equals_preprocess_many(
		, ,
		, ,
		{
			{'code=ar|نص العنصر النائب'},
			{'code=ar|rtl=yes|نص العنصر النائب'},
			{'code=ar|نص العنصر النائب'},
			{'code=ar|rtl=yes|نص العنصر النائب'},
			{'code=en|a test failsLua'},
			{'code=en|' .. implied_para_content},
		}, {nowiki=1, stripmarker=1})
end
return p