模組討論:Lang/testcases
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('text', 'text', { {'yes'}, {'no'}, {'invert'}, {'italic'}, {}, {'whatever'}, }, {nowiki=1}) self:preprocess_equals_preprocess('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 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('[text] 错误:{{Lang}}:无效参数:|script=(帮助)', '[text] 错误:{{Lang}}:无效参数:|script=(帮助)', { {'arab'}, {'latn'}, }, {nowiki=1}) self:preprocess_equals_preprocess_many('[text] 错误:{{Lang}}:无效参数:|script=(帮助)', '[text] 错误:{{Lang}}:无效参数:|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 and inserts the marker.
]]
function p:test_03_lang_rtl() self:preprocess_equals_preprocess_many('text', 'text', { {'yes'}, {'no'}, {}, {'whatever'}, }, {nowiki=1}) self:preprocess_equals_preprocess('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('[text] 错误:{{Lang}}:無法辨識語言標籤 ', '(帮助)', '[text] 错误:{{Lang}}:無法辨識語言標籤 ', '(帮助)', { {'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('[未定义] 错误:{{Lang}}:无文本(帮助)', '[未定义] 错误:{{Lang}}:无文本(帮助)', { {'|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('阿拉伯語:text', '阿拉伯語:text', { {'yes'}, {'no'}, {'invert'}, {'italic'}, {}, {'whatever'}, }, {nowiki=1}) self:preprocess_equals_preprocess('阿拉伯語: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 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('[text] 错误:{{Lang-xx}}:無法辨識代碼 ar 所指定的書寫系統 ', '。(帮助)', '[text] 错误:{{Lang-xx}}:無法辨識代碼 ar 所指定的書寫系統 ', '。(帮助)', { {'arab'}, {'latn'}, }, {nowiki=1}) self:preprocess_equals_preprocess_many('[text] 错误:{{Lang-xx}}:無法辨識代碼 ar 所指定的書寫系統 ', '。(帮助)', '[text] 错误:{{Lang-xx}}:無法辨識代碼 ar 所指定的書寫系統 ', '。(帮助)', { {'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 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('[text] 错误:{{Lang-xx}}:無法辨識代碼 ar 所指定的書寫系統 ', '。(帮助)', '[text] 错误:{{Lang-xx}}:無法辨識代碼 ar 所指定的書寫系統 ', '。(帮助)', { {'arab'}, {'latn'}, }, {nowiki=1}) self:preprocess_equals_preprocess_many('[text] 错误:{{Lang-xx}}:無法辨識代碼 ar 所指定的書寫系統 ', '。(帮助)', '[text] 错误:{{Lang-xx}}:無法辨識代碼 ar 所指定的書寫系統 ', '。(帮助)', { {'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 and inserts the marker.
]]
function p:test_09_lang_xx_rtl() self:preprocess_equals_preprocess_many('阿拉伯語:text', '阿拉伯語:text', { {'yes'}, {'no'}, {}, {'whatever'}, }, {nowiki=1}) self:preprocess_equals_preprocess('阿拉伯語:text', '阿拉伯語: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('[', '] 错误:{{Lang-xx}}:缺少语言标签(帮助)', '[', '] 错误:{{Lang-xx}}:缺少语言标签(帮助)', { {'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('[', '] 错误:{{Lang-xx}}:缺少语言标签(帮助)', '[', '] 错误:{{Lang-xx}}:缺少语言标签(帮助)', { {'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('[未定义] 错误:{{Lang-xx}}:无文本(帮助)', '[未定义] 错误:{{Lang-xx}}:无文本(帮助)', { {'|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('[', '] 错误:{{Transl}}:缺少语言/字母代码(帮助)', '[', '] 错误:{{Transl}}:缺少语言/字母代码(帮助)', { -- 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('[', '] 错误:{{Transl}}:缺少语言/字母代码(帮助)', '[', '] 错误:{{Transl}}:缺少语言/字母代码(帮助)', { {'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('错误:無法辨識語言標籤 ', '', '错误:無法辨識語言標籤 ', '', { {'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('错误:無法辨識語言標籤 ', '', '错误:無法辨識語言標籤 ', '', { {'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('错误:语言:', ' 未找到', '错误:语言:', ' 未找到', { {'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(, , { {'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(, , { {'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('[未定义] 错误:{{Lang}}:无文本(帮助)', '[未定义] 错误:{{Lang}}:无文本(帮助)', { {}, -- 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 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('[', '] 错误:{{Lang-xx}}:缺少语言标签(帮助)', '[', '] 错误:{{Lang-xx}}:缺少语言标签(帮助)',
{
{}, -- 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|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('[', '] 错误:{{Transl}}:缺少语言/字母代码(帮助)', '[', '] 错误:{{Transl}}:缺少语言/字母代码(帮助)', { {'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('错误:無法辨識語言標籤 ', '', '错误:無法辨識語言標籤 ', '', { {'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('错误:無法辨識語言標籤 ', '', '错误:無法辨識語言標籤 ', '', { {'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('错误:语言:', ' 未找到', '错误:语言:', ' 未找到', { {'sfsfsfs'}, }, {nowiki=1}) end
return p