Module:LC zh/testcases

From mediawiki.org
Module documentation

All tests passed.

test_main:

Text Expected Actual
Yes {{#invoke:LC zh|main}}
Yes {{#invoke:LC zh|main|type=N}}
Yes {{#invoke:LC zh|main|type=N|ns=User}} User User
Yes {{#invoke:LC zh|main|type=N|ns=Help}} Help Help
Yes {{#invoke:LC zh|main|type=T}}
Yes {{#invoke:LC zh|main|type=T|ns=User}} User: User:
Yes {{#invoke:LC zh|main|type=T|ns=Help}} Help: Help:
Yes {{#invoke:LC zh|main|type=T|ns=User|zh=Example}} User:Example User:Example
Yes {{#invoke:LC zh|main|type=T|ns=Help|zh=Example|zh-hans=示例|zh-hant=範例}} Help:Example Help:Example
Yes {{#invoke:LC zh|main|type=T|hide_ns=1|ns=Help}}
Yes {{#invoke:LC zh|main|type=T|hide_ns=1|ns=Help|zh=Example|zh-hans=示例|zh-hant=範例}} Example Example
Yes {{#invoke:LC zh|main|type=H}}
Yes {{#invoke:LC zh|main|type=C}}
Yes {{#invoke:LC zh|main|type=C|zh=Example|zh-hans=示例|zh-hant=範例}} Example Example

test_template:

Text Expected Actual
Yes {{LC zh}}
Yes {{LC zh|type=N}}
Yes {{LC zh|type=N|ns=User}} User User
Yes {{LC zh|type=N|ns=Help}} Help Help
Yes {{LC zh|type=T}}
Yes {{LC zh|type=T|ns=User}} User: User:
Yes {{LC zh|type=T|ns=Help}} Help: Help:
Yes {{LC zh|type=T|ns=User|zh=Example}} User:Example User:Example
Yes {{LC zh|type=T|ns=Help|zh=Example|zh-hans=示例|zh-hant=範例}} Help:Example Help:Example
Yes {{LC zh|type=T|hide_ns=1|ns=Help}}
Yes {{LC zh|type=T|hide_ns=1|ns=Help|zh=Example|zh-hans=示例|zh-hant=範例}} Example Example
Yes {{LC zh|type=H}}
Yes {{LC zh|type=C}}
Yes {{LC zh|type=C|zh=Example|zh-hans=示例|zh-hant=範例}} Example Example

--- Unit tests for [[Module:LC zh]]. Click talk page to run tests.
--
-- self:preprocess_equals( "{{#invoke:LC zh|main}}", "" )
--
-- self:preprocess_equals_many(
-- "{{#invoke:LC zh|main|", "}}",
-- {
-- { "", "" },
-- }
-- )
--
-- @var table
local p = require( [[Module:UnitTests]] )

local current_frame = mw.getCurrentFrame()

-- Title.pageLang.code is an expensive function in Scribunto, thus not using
--  pageLang.code here
--
-- @var string
local page_lang_code = current_frame:preprocess( "{{PAGELANGUAGE}}" )

-- @var string
local ui_lang_code = current_frame:callParserFunction{
	name = "int", args = { "lang" }
}

-- @var string
local function lang_code_type( lang_code )
	if lang_code == "zh" then
		return "zh"
	elseif (
			lang_code == "zh-hans" or
			lang_code == "zh-cn" or
			lang_code == "zh-my" or
			lang_code == "zh-sg"
	) then
		return "zh-hans"
	elseif (
			lang_code == "zh-hant" or
			lang_code == "zh-tw"
	) then
		return "zh-hant"
	elseif (
			lang_code == "zh-hk" or
			lang_code == "zh-mo"
	) then
		return "zh-hk"
	else
		return nil
	end
end

-- @var string
local function ui_lang_code_type()
	return lang_code_type( ui_lang_code )
end

-- @return table
local function provide_test_main()
	return {
		{ "type=N", "" },
		{
			"type=N|ns=User",
			page_lang_code == "zh" and
				"-{zh:User; zh-hans:用户; zh-hant:使用者; zh-hk:用戶;}-" or
				ui_lang_code_type() == "zh" and "User" or
				ui_lang_code_type() == "zh-hans" and "用户" or
				ui_lang_code_type() == "zh-hant" and "使用者" or
				ui_lang_code_type() == "zh-hk" and "用戶" or
				"User"
		},
		{
			"type=N|ns=Help",
			page_lang_code == "zh" and
				"-{zh:Help; zh-hans:帮助; zh-hant:說明;}-" or
				ui_lang_code_type() == "zh" and "Help" or
				ui_lang_code_type() == "zh-hans" and "帮助" or
				ui_lang_code_type() == "zh-hant" and "說明" or
				ui_lang_code_type() == "zh-hk" and "說明" or
				"Help"
		},
		{ "type=T", "" },
		{
			"type=T|ns=User",
			page_lang_code == "zh" and
				"-{zh:User; zh-hans:用户; zh-hant:使用者; zh-hk:用戶;}-:" or
				ui_lang_code_type() == "zh" and "User:" or
				ui_lang_code_type() == "zh-hans" and "用户:" or
				ui_lang_code_type() == "zh-hant" and "使用者:" or
				ui_lang_code_type() == "zh-hk" and "用戶:" or
				"User:"
		},
		{
			"type=T|ns=Help",
			page_lang_code == "zh" and
				"-{zh:Help; zh-hans:帮助; zh-hant:說明;}-:" or
				ui_lang_code_type() == "zh" and "Help:" or
				ui_lang_code_type() == "zh-hans" and "帮助:" or
				ui_lang_code_type() == "zh-hant" and "說明:" or
				ui_lang_code_type() == "zh-hk" and "說明:" or
				"Help:"
		},
		{
			"type=T|ns=User|zh=Example",
			page_lang_code == "zh" and
				"-{zh:User; zh-hans:用户; zh-hant:使用者; zh-hk:用戶;}-:" ..
					"Example" or
				ui_lang_code_type() == "zh" and "User:Example" or
				ui_lang_code_type() == "zh-hans" and "用户:Example" or
				ui_lang_code_type() == "zh-hant" and "使用者:Example" or
				ui_lang_code_type() == "zh-hk" and "用戶:Example" or
				"User:Example"
		},
		{
			"type=T|ns=Help|zh=Example|zh-hans=示例|zh-hant=範例",
			page_lang_code == "zh" and
				"-{zh:Help; zh-hans:帮助; zh-hant:說明;}-:" ..
					"-{zh:Example; zh-hans:示例; zh-hant:範例;}-" or
				ui_lang_code_type() == "zh" and "Help:Example" or
				ui_lang_code_type() == "zh-hans" and "帮助:示例" or
				ui_lang_code_type() == "zh-hant" and "說明:範例" or
				ui_lang_code_type() == "zh-hk" and "說明:範例" or
				"Help:Example"
		},
		{ "type=T|hide_ns=1|ns=Help", "" },
		{
			"type=T|hide_ns=1|ns=Help|zh=Example|zh-hans=示例|zh-hant=範例",
			page_lang_code == "zh" and
				"-{zh:Example; zh-hans:示例; zh-hant:範例;}-" or
				ui_lang_code_type() == "zh" and "Example" or
				ui_lang_code_type() == "zh-hans" and "示例" or
				ui_lang_code_type() == "zh-hant" and "範例" or
				ui_lang_code_type() == "zh-hk" and "範例" or
				"Example"
		},
		{ "type=H", "" },
		{ "type=C", "" },
		{
			"type=C|zh=Example|zh-hans=示例|zh-hant=範例",
			page_lang_code == "zh" and
				"-{zh:Example; zh-hans:示例; zh-hant:範例;}-" or
				ui_lang_code_type() == "zh" and "Example" or
				ui_lang_code_type() == "zh-hans" and "示例" or
				ui_lang_code_type() == "zh-hant" and "範例" or
				ui_lang_code_type() == "zh-hk" and "範例" or
				"Example"
		},
	}
end

function p:test_main()
	self:preprocess_equals( "{{#invoke:LC zh|main}}", "" )
	self:preprocess_equals_many(
		"{{#invoke:LC zh|main|", "}}", provide_test_main()
	)
end

function p:test_template()
	self:preprocess_equals( "{{LC zh}}", "" )
	self:preprocess_equals_many( "{{LC zh|", "}}", provide_test_main() )
end

return p