Jump to content

Module:Lang/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 15:29, 29 October 2020. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = require('Module:UnitTests')

--[[==========================<< L A N G   T E S T S=========================================================]]

--[[--------------------------< I T A L I C >------------------------------------------------------------------

Tests module parameter |italic= with values 'yes', 'no', present but not set, and the invalid 'whatever'.  There
is a separate test for the parameter not present.

|italic=yes or |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('{{#invoke:Lang/sandbox|lang|code=ar|text=text|italic=', '}}', '{{#invoke:Lang|lang|code=ar|text=text|italic=', '}}',
		{
			{'yes'},
			{'no'},
			{''},
			{'whatever'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess('{{#invoke:Lang/sandbox|lang|code=ar|text=text}}', '{{#invoke:Lang|lang|code=ar|text=text}}',
		{nowiki=1})
end;


--[[--------------------------< I T A L I C   W I T H   S C R I P T >------------------------------------------

Tests module parameter |italic=yes when |script=arab or |script=latn

|italic=yes should override whatever |script= might say

The value assigned to |script= shall be appended to the language code; for |script=arab the module shall add
dir="rtl" to the text's enclosing <span> and insert the &lrm; marker

]]

function p:test_02_lang_italic_with_script()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang|code=ar|text=text|italic=yes|script=', '}}', '{{#invoke:Lang|lang|code=ar|text=text|italic=yes|script=', '}}',
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang|code=ar|text=text|italic=no|script=', '}}', '{{#invoke:Lang|lang|code=ar|text=text|italic=no|script=', '}}',
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
end;


--[[--------------------------< R T L >------------------------------------------------------------------------

Tests module parameter |rtl= with values 'yes', 'no', present but not set, and the invalid 'whatever'.  There
is a separate test for the parameter not present.

|rtl=yes adds dir="rtl" to the text's enclosing <span> and inserts the &lrm; marker

]]

function p:test_03_lang_rtl()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang|code=ar|text=text|rtl=', '}}', '{{#invoke:Lang|lang|code=ar|text=text|rtl=', '}}',
		{
			{'yes'},
			{'no'},
			{''},
			{'whatever'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess('{{#invoke:Lang/sandbox|lang|code=ar|text=text}}', '{{#invoke:Lang|lang|code=ar|text=text}}',
		{nowiki=1})
end;


--[[--------------------------< I E T F   D E C O D I N G >----------------------------------------------------

Tests module parameter |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('{{#invoke:Lang/sandbox|lang|text=text|code=', '}}', '{{#invoke:Lang|lang|text=text|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
		}, {nowiki=1})
end;


--[[==========================<< L A N G _ X X   T E S T S===================================================]]

--[[--------------------------< I T A L I C >------------------------------------------------------------------

Tests module parameter |italic= with values 'yes', 'no', present but not set, and the invalid 'whatever'.  There
is a separate test for the parameter not present.

|italic=yes or |italic=no overrides every other parameter that might set the rendered text's font.

]]

function p:test_05_lang_xx_italic()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text=text|italic=', '}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text=text|italic=', '}}',
		{
			{'yes'},
			{'no'},
			{''},
			{'whatever'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text}}',
		{nowiki=1})
end;


--[[--------------------------< I T A L I C   W I T H   S C R I P T >------------------------------------------

Tests module parameter |italic=yes when |script=arab or |script=latn

|italic=yes should override whatever |script= might say

The value assigned to |script= shall be appended to the language code; for |script=arab the module shall add
dir="rtl" to the text's enclosing <span> and insert the &lrm; marker

]]

function p:test_06_lang_xx_italic_with_script()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text=text|italic=yes|script=', '}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text=text|italic=yes|script=', '}}',
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text=text|italic=no|script=', '}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text=text|italic=no|script=', '}}',
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
end;


--[[--------------------------< S C R I P T >------------------------------------------------------------------

Tests module parameter |script=arab and |script=latn with |italic= preset but not set and |italic= not present

|script=arab shall not italicize text
|script=latn shall italicize text

The value assigned to |script= shall be appended to the language code; for |script=arab the module shall add
dir="rtl" to the text's enclosing <span> and insert the &lrm; marker

There is no {{lang}} version of this test because {{lang}} has not need for separate |script=, |region=, and |variant=
parameters - those subtags can all be added to the IETF language code in the template's first positional parameter ({{{1}}}).

]]

function p:test_07_lang_xx_script()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text=text|italic=|script=', '}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text=text|italic=|script=', '}}',
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text=text|script=', '}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text=text|script=', '}}',
		{
			{'arab'},
			{'latn'},
		}, {nowiki=1})
end;


--[[--------------------------< R T L >------------------------------------------------------------------------

Tests module parameter |rtl= with values 'yes', 'no', present but not set, and the invalid 'whatever'.  There
is a separate test for the parameter not present.

|rtl=yes adds dir="rtl" to the text's enclosing <span> and inserts the &lrm; marker

]]

function p:test_08_lang_xx_rtl()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text=text|rtl=', '}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text=text|rtl=', '}}',
		{
			{'yes'},
			{'no'},
			{''},
			{'whatever'},
		}, {nowiki=1})
	self:preprocess_equals_preprocess('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text}}',
		{nowiki=1})
end;


--[[--------------------------< L A N G _ T R A N S L I T >------------------------------------------------------------------------


]]

function p:test_09_lang_xx_translit()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|nocat=yes|', '}}', '{{#invoke:Lang|lang_xx_inherit|nocat=yes|', '}}',
		{
			{'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'},
		}, {nowiki=1})
end;


--[[--------------------------< L A N G _ A N D _ L A N G X X _ E R R O R S >------------------------------------------------------------------------

Lang and Lang-xx errors.

]]

function p:test_10_lang_errors()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang|nocat=yes|', '}}', '{{#invoke:Lang|lang|nocat=yes|', '}}',
		{
			{''},								-- 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|malformed\'\'\'\'\'\''},		-- text has malformed markup
			{'fr|\'\'italics\'\''},				-- text has italic 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;

function p:test_11_lang_xx_errors()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|nocat=yes|', '}}', '{{#invoke:Lang|lang_xx_inherit|nocat=yes|', '}}',
		{
			{''},													-- no text
			{'code=fr'},											-- no text
			{'text=text'},											-- missing language tag
			{'code=fr|text|text=text'},								-- conflicting {{{1}}} and |text=
			{'code=fr|text|translit|translit=translit'},			-- conflicting {{{2}}} and |translit=
			{'code=fr|text||lit|lit=lit'},							-- conflicting {{{3}}} and |lit= or |translation=
			{'code=fr|text||translation|translation=translation'},	-- conflicting {{{3}}} and |lit= or |translation=
			{'code=fr|text|||lit=lit|translation=translation'}, 	-- conflicting |lit= and |translation=
			{'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'},
		}, {nowiki=1})
end;


--[[--------------------------< T R A N S L >------------------------------------------------------------------------

Lang and Lang-xx errors.

]]

function p:test_12_transl()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|transl|nocat=yes|', '}}', '{{#invoke:Lang|transl|nocat=yes|', '}}',
		{
			{'ar|al-Khwarizmi'},
			{'Ogam|MAQI'},
			{'Cyrl|š'},
			{'cu|š'},
			{'ru|š'},
			{'ar|DIN|al-Ḫawārizmī'},
			{'ar|ALA|al-Khawārizmī'},
			{'Arab|DIN|Ḫ'},
			{'Arab|ALA|Kh'},
		}, {nowiki=1})
end;

function p:test_13_transl_italics()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|transl|nocat=yes|', '}}', '{{#invoke:Lang|transl|nocat=yes|', '}}',
		{
			{'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=unset'},
			{'Arab|nasu \'\'aleunsur\'\' alnnayib|italic=unset'},
		}, {nowiki=1})
end;

function p:test_14_transl_errors()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|transl|nocat=yes|', '}}', '{{#invoke:Lang|transl|nocat=yes|', '}}',
		{
			{'al-Khwarizmi'},
			{'ar'},
			{'at|al-Khwarizmi'},
			{'ar|AL|al-Khwarizmi'},
			{'Arab|nasu \'\'aleunsur\'\' alnnayib|italic=yes|italics=no'},
		}, {nowiki=1})
end;

function p:test_15_lang_xx_transl_compare()
	self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|nocat=yes|', '}}', '{{#invoke:Lang|transl|nocat=yes|', '}}',
		{
			{'code=ar|rtl=yes|نص العنصر النائب|nasu aleunsur alnnayib', 'ar|nasu aleunsur alnnayib'},
			{'code=ar|rtl=yes|نص العنصر النائب|nasu aleunsur alnnayib|translit-std=DIN', 'ar|DIN|nasu aleunsur alnnayib'},
			{'code=ar|rtl=yes|نص العنصر النائب|nasu aleunsur alnnayib|translit-std=ALA', 'ar|ALA|nasu aleunsur alnnayib'},
			{'code=ar|rtl=yes|نص العنصر النائب|nasu aleunsur alnnayib|translit-std=DIN|translit-script=arab', 'Arab|DIN|nasu aleunsur alnnayib'},
		}, {nowiki=1})
end;

return p