模組:Lang/testcases
外观
![]() | 這是Module:Lang的測試樣例頁,測試結果請見討論頁。 |
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 add
dir="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 add
dir="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
--[[ -------------------------- < 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})
end
return p