From Wikipedia, the free encyclopedia 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',- 'invert',- 'italic',- present but not set,- invalid 'whatever',- 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'}, {'invert'}, {'italic'}, {''}, {'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 and |italic=no when |script=arab or |script=latn is set.|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 adddir="rtl" to the text's enclosing <span> and insert the ‎ 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 ‎ 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 {'cel-x-proto'}, -- private-use }, {nowiki=1})end--[[ -------------------------- < I N V E R T _ I T A L I C S > --------------------------Tests text ouput with |italic=invert set.]]function p:test_05_lang_invert_italics() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang|code=ar', '}}', '{{#invoke:Lang|lang|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--[[ ========================== < L A N G _ X X _ T E S T S > ========================== ]]--[[ -------------------------- < I T A L I C > --------------------------- 'yes',- 'no',- 'invert',- 'italic',- present but not set,- invalid 'whatever',- parameter not present.|italic=yes or |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('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar|text=text|italic=', '}}', '{{#invoke:Lang|lang_xx_inherit|code=ar|text=text|italic=', '}}', { {'yes'}, {'no'}, {'invert'}, {'italic'}, {''}, {'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 and |italic=no when |script=arab or |script=latn is set.|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 adddir="rtl" to the text's enclosing <span> and insert the ‎ marker.]]function p:test_07_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 adddir="rtl" to the text's enclosing <span> and insert the ‎ marker.There is no {{lang}} version of this test because {{lang}} has no 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_08_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 ‎ marker.]]function p:test_09_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 >------------------------------------------------------------------------Tests various supported combinations of translit formats.]]function p:test_10_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'}, {'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--[[--------------------------< L I N K _ A N D _ L A B E L >------------------------------------------------------------------------Tests various supported combinations of |link= and |label= combinations.]]function p:test_11_lang_xx_link_and_label() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|nocat=yes|', '}}', '{{#invoke:Lang|lang_xx_inherit|nocat=yes|', '}}', { {'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--[[ -------------------------- < I N V E R T _ I T A L I C S > --------------------------Tests text ouput with |italic=invert set.]]function p:test_12_lang_xx_invert_italics() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|lang_xx_inherit|code=ar', '}}', '{{#invoke:Lang|lang_xx_inherit|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--[[ ========================== < T R A N S L _ T E S T S > ========================== ]]--[[ -------------------------- < T R A N S L _ F O R M A T S > --------------------------Tests various supported combinations of translit formats.]]function p:test_13_transl_formats() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|transl|nocat=yes|', '}}', '{{#invoke:Lang|transl|nocat=yes|', '}}', { -- 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--[[ -------------------------- < I T A L I C S > --------------------------Tests module parameter |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_14_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=whatever'}, {'ar|nasu \'\'aleunsur\'\' alnnayib|italic=unset'}, {'Arab|nasu \'\'aleunsur\'\' alnnayib|italic=unset'}, }, {nowiki=1})end--[[ ========================== < C A T E G O R Y _ F R O M _ T A G _ T E S T S > ========================== ]]--[[ -------------------------- < C A T E G O R Y _ F R O M _ T A G > --------------------------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_15_category_from_tag() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|category_from_tag|nocat=yes|', '}}', '{{#invoke:Lang|category_from_tag|nocat=yes|', '}}', { {'fr|link=yes'}, {'ber|link=yes'}, {'en|link=yes'}, {'en-gb|link=yes'}, {'fr'}, {'FR'}, {'ber'}, {'BER'}, {'en'}, {'EN'}, {'en-gb'}, {'EN-GB'}, })end--[[ ========================== < N A M E _ F R O M _ T A G _ T E S T S > ========================== ]]--[[ -------------------------- < N A M E _ F R O M _ T A G > --------------------------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_16_name_from_tag() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|name_from_tag|nocat=yes|', '}}', '{{#invoke:Lang|name_from_tag|nocat=yes|', '}}', { {'fr|link=yes'}, {'ber|link=yes'}, {'en|link=yes'}, {'en-gb|link=yes'}, {'fr'}, {'FR'}, {'ber'}, {'BER'}, {'en'}, {'EN'}, {'en-gb'}, {'EN-GB'}, })end--[[ ========================== < T A G _ F R O M _ N A M E _ T E S T S > ========================== ]]--[[ -------------------------- < T A G _ F R O M _ N A M E > --------------------------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_17_tag_from_name() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|tag_from_name|nocat=yes|', '}}', '{{#invoke:Lang|tag_from_name|nocat=yes|', '}}', { {'french'}, {'French'}, {'FRENCH'}, {'Berber Languages'}, {'Berber languages'}, {'British English'}, {'en'}, {'EN'}, })end--[[ ========================== < I S _ I E T F _ T A G _ T E S T S > ========================== ]]--[[ -------------------------- < I S _ I E T F _ T A G > --------------------------Returns true if valid IETF tag.]]function p:test_18_is_ietf_tag() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|is_ietf_tag|nocat=yes|', '}}', '{{#invoke:Lang|is_ietf_tag|nocat=yes|', '}}', { {'french'}, {'French'}, {'FRENCH'}, {'Berber Languages'}, {'Berber languages'}, {'British English'}, {'fr'}, {'FR'}, {'ber'}, {'BER'}, {'en'}, {'EN'}, {'en-gb'}, {'EN-GB'}, })end--[[ ========================== < I S _ L A N G _ N A M E _ T E S T S > ========================== ]]--[[ -------------------------- < I S _ L A N G _ N A M E > --------------------------Returns true if valid language name.]]function p:test_19_is_lang_name() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|is_lang_name|nocat=yes|', '}}', '{{#invoke:Lang|is_lang_name|nocat=yes|', '}}', { {'french'}, {'French'}, {'FRENCH'}, {'Berber Languages'}, {'Berber languages'}, {'British English'}, {'fr'}, {'FR'}, {'ber'}, {'BER'}, {'en'}, {'EN'}, {'en-gb'}, {'EN-GB'}, })end--[[ ========================== < E R R O R S > ========================== ]]--[[--------------------------< L A N G _ E R R O R S >------------------------------------------------------------------------Lang errors.]]function p:test_20_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|\'\'italics\'\''}, -- text has italic markup {'fr|text={{lang|fr|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--[[ -------------------------- < L A N G _ X X _ E R R O R S > --------------------------Lang-xx errors.]]function p:test_21_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|{{lang|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--[[ -------------------------- < T R A N S L _ E R R O R S > --------------------------Transl errors.]]function p:test_22_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--[[ -------------------------- < C A T E G O R Y _ F R O M _ T A G _ E R R O R S > --------------------------category_from_tag errors.]]function p:test_23_category_from_tag_errors() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|category_from_tag|nocat=yes|', '}}', '{{#invoke:Lang|category_from_tag|nocat=yes|', '}}', { {'sfsfsfs'}, }, {nowiki=1})end--[[ -------------------------- < N A M E _ F R O M _ T A G _ E R R O R S > --------------------------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_24_name_from_tag_errors() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|name_from_tag|nocat=yes|', '}}', '{{#invoke:Lang|name_from_tag|nocat=yes|', '}}', { {'sfsfsfs'}, }, {nowiki=1})end--[[ -------------------------- < T A G _ F R O M _ N A M E _ E R R O R S > --------------------------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_25_tag_from_name_errors() self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|tag_from_name|nocat=yes|', '}}', '{{#invoke:Lang|tag_from_name|nocat=yes|', '}}', { {'sfsfsfs'}, }, {nowiki=1})endreturn p This page was last edited on 17 November 2020, at 12:14 (UTC).