Module:TNT/testcases
外观
4 tests failed.
Name | Expected | Actual | |
---|---|---|---|
test_doc / doc02 | {"paramOrder":["param1","param2"],"description":"DO NOT EDIT OR TRANSLATE unless you are changing unit tests","params":{"param2":{"suggested":true,"type":"string","required":false,"label":"fr_label_2","example":"pl_example_2","description":"en_desc_2"},"param1":{"suggested":false,"type":"string","required":true,"label":"en_label_1","example":"en_example_1","description":"en_desc_1"}}} | {"paramOrder":["param1","param2"],"description":"DO NOT EDIT OR TRANSLATE unless you are changing unit tests","params":{"param1":{"suggested":false,"type":"string","required":true,"label":"en_label_1","example":"en_example_1","description":"en_desc_1"},"param2":{"suggested":true,"type":"string","required":false,"label":"fr_label_2","example":"pl_example_2","description":"en_desc_2"}}} | |
test_link | |||
test_msg | |||
test_msg_errors | Module:TNT/testcases:90: msgerr01
Failed to find plain string "<strong class="error"><span class="scribunto-error" id="mw-scribunto-error-" in string "<strong class="error"><span class="scribunto-error mw-scribunto-error-bb7de043">Module:TNT第167行Lua错误:第一个参数必须是共享资源数据集名称</span></strong>" | ||
test_msg_format / format13 | Dataset [[c:Data:_bad_name_.tab]] is not valid | 数据集[[c:Data:_bad_name_.tab]]无效 | |
test_msg_format_in_language / formatInLanguage13 | Dataset [[c:Data:_bad_name_.tab]] is not valid | 数据集[[c:Data:_bad_name_.tab]]无效 |
3 tests failed.
Name | Expected | Actual | |
---|---|---|---|
test_doc | |||
test_link | |||
test_msg | |||
test_msg_errors | Module:TNT/testcases:90: msgerr01
Failed to find plain string "<strong class="error"><span class="scribunto-error" id="mw-scribunto-error-" in string "<strong class="error"><span class="scribunto-error mw-scribunto-error-1586f55f">Module:TNT/sandbox第154行Lua错误:第一个参数必须是共享资源数据集名称</span></strong>" | ||
test_msg_format / format13 | Dataset [[c:Data:_bad_name_.tab]] is not valid | 数据集[[c:Data:_bad_name_.tab]]无效 | |
test_msg_format_in_language / formatInLanguage13 | Dataset [[c:Data:_bad_name_.tab]] is not valid | 数据集[[c:Data:_bad_name_.tab]]无效 |
上述文档嵌入自Module:TNT/testcases/doc。 (编辑 | 历史) 编者可以在本模块的沙盒 (编辑 | 差异)和测试样例 (编辑 | 运行)页面进行实验。 本模块的子页面。 |
local ScribuntoUnit = require('Module:ScribuntoUnit')
local p = ScribuntoUnit:new()
local libName = 'TNT'
-- Helper to run all tests using sandbox version of the library from the debug console. To run against main lib, use =p.run()
function p.runSandbox()
local frame = mw.getCurrentFrame():newChild{title='testcases', args={module=libName .. '/sandbox', displayMode='log'}}
return p.run(frame)
end
-- Allow test runner to use both the main library and the sandbox of the library with the same testcases
function p:module()
return self.frame and self.frame.args.module or libName
end
function p:invokeLib(wikicode)
return '{{#invoke:' .. p:module() .. '|' .. wikicode .. '}}'
end
--[[
Library-specific tests
]]
function p:test_msg()
-- dataset resolution
self:assertResultEquals('text message', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text'), 'msg01')
self:assertResultEquals('text message', p:invokeLib('msg|I18n/Module:TNT/testcases|text'), 'msg02')
self:assertResultEquals('text message', p:invokeLib('msg| I18n/Module:TNT/testcases.tab |text'), 'msg03')
self:assertResultEquals('text message', p:invokeLib('msg| I18n/Module:TNT/testcases |text'), 'msg04')
-- spacing
self:assertResultEquals('text message', p:invokeLib(' msg | I18n/Module:TNT/testcases.tab | text '), 'msg11')
self:assertResultEquals('text message', p:invokeLib(' \n msg \n | \n I18n/Module:TNT/testcases.tab \n | \n text \n '), 'msg12')
self:assertResultEquals('текст', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text|lang=ru'), 'msg13')
self:assertResultEquals('text message', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text|lang=fr'), 'msg14')
-- 1 parameter
self:assertResultEquals('text message a', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_1|a'), 'msg21')
self:assertResultEquals('text message a', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_1| a '), 'msg22')
self:assertResultEquals('text message a', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_1| \na \n '), 'msg23')
self:assertResultEquals('текст абв', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_1|абв|lang=ru'), 'msg24')
-- multiple parameters
self:assertResultEquals('text message a and b', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_2|a|b'), 'msg31')
self:assertResultEquals('text message a and b', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_2| a | b '), 'msg32')
self:assertResultEquals('text message a and b', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_2| \na \n | \nb \n '), 'msg33')
self:assertResultEquals('текст абв и где', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_2|абв|где|lang=ru'), 'msg34')
-- parameters as part of wiki text
self:assertResultEquals('text message [[a|b]]', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_link|a|b'), 'msg41')
self:assertResultEquals('text message [[a|b]]', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_link| a | b '), 'msg42')
self:assertResultEquals('текст [[абв|где]]', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_link|абв|где|lang=ru'), 'msg43')
-- fallbacks
self:assertResultEquals('текст', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_no_en'), 'msg51')
self:assertResultEquals('текст', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_no_en|lang=ru'), 'msg52')
self:assertResultEquals('текст', p:invokeLib('msg|I18n/Module:TNT/testcases.tab|text_no_en|lang=fr'), 'msg53')
end
function p:test_msg_format()
local tnt = require('Module:' .. p:module())
self:assertEquals('text message', tnt.format('I18n/Module:TNT/testcases', 'text'), 'format01')
self:assertEquals('text message a', tnt.format('I18n/Module:TNT/testcases', 'text_1', 'a'), 'format02')
self:assertEquals('text message foo and bar', tnt.format('I18n/Module:TNT/testcases', 'text_2', 'foo', 'bar'), 'format03')
self:assertEquals('text message foo and bar', tnt.format('I18n/Module:TNT/testcases', 'text_2', {'foo', 'bar'}), 'format04')
self:assertThrows(function() tnt.format() end, "bad argument #1 to 'format' (string expected, got nil)", 'format11')
self:assertThrows(function() tnt.format('Module:TNT/testcases') end, "bad argument #2 to 'format' (string expected, got nil)", 'format12')
self:assertThrows(function() tnt.format('_bad_name_', 'foo') end, 'Dataset [[c:Data:_bad_name_.tab]] is not valid', 'format13')
self:assertThrows(function() tnt.format('I18n/Module:TNT/testcases', '_bad_msg') end, 'Message “_bad_msg” does not exist in dataset [[c:Data:I18n/Module:TNT/testcases]]', 'format14')
end
function p:test_msg_format_in_language()
local tnt = require('Module:' .. p:module())
self:assertEquals('text message', tnt.formatInLanguage('en', 'I18n/Module:TNT/testcases', 'text'), 'formatInLanguage01')
self:assertEquals('text message a', tnt.formatInLanguage('en', 'I18n/Module:TNT/testcases', 'text_1', 'a'), 'formatInLanguage02')
self:assertEquals('text message foo and bar', tnt.formatInLanguage('en', 'I18n/Module:TNT/testcases', 'text_2', 'foo', 'bar'), 'formatInLanguage03')
self:assertEquals('text message foo and bar', tnt.formatInLanguage('en', 'I18n/Module:TNT/testcases', 'text_2', {'foo', 'bar'}), 'formatInLanguage04')
self:assertEquals('текст абв', tnt.formatInLanguage('ru', 'I18n/Module:TNT/testcases', 'text_1', 'абв'), 'formatInLanguage03')
self:assertThrows(function() tnt.formatInLanguage() end, "bad argument #1 to 'formatInLanguage' (string expected, got nil)", 'formatInLanguage11')
self:assertThrows(function() tnt.formatInLanguage('en') end, "bad argument #2 to 'formatInLanguage' (string expected, got nil)", 'formatInLanguage12')
self:assertThrows(function() tnt.formatInLanguage('en', 'Module:TNT/testcases') end, "bad argument #3 to 'formatInLanguage' (string expected, got nil)", 'formatInLanguage12')
self:assertThrows(function() tnt.formatInLanguage('en', '_bad_name_', 'foo') end, 'Dataset [[c:Data:_bad_name_.tab]] is not valid', 'formatInLanguage13')
self:assertThrows(function() tnt.formatInLanguage('en', 'I18n/Module:TNT/testcases', '_bad_msg') end, 'Message “_bad_msg” does not exist in dataset [[c:Data:I18n/Module:TNT/testcases]]', 'formatInLanguage14')
end
function p:assertResultError(errorText, text, message)
local actual = self.frame:preprocess(text)
self:assertStringContains('<strong class="error"><span class="scribunto-error" id="mw-scribunto-error-', actual, true, message)
self:assertStringContains(errorText .. '.</span></strong>', actual, true, message)
end
function p:test_msg_errors()
-- The error messages might change if https://commons.wikimedia.org/wiki/Data:I18n/Module:TNT.tab changes for English
self:assertResultError('第一个参数必须是共享资源数据集', p:invokeLib('msg'), 'msgerr01')
self:assertResultError('第一个参数必须是共享资源数据集', p:invokeLib('msg|lang=pl'), 'msgerr02')
self:assertResultError('数据集[[c:Data:_bad_name_.tab]]', p:invokeLib('msg|_bad_name_'), 'msgerr03')
self:assertResultError('消息「_bad_msg_」不存在于数据集[[c:Data:I18n/Module:TNT]]之中', p:invokeLib('msg|I18n/Module:TNT|_bad_msg_'), 'msgerr04')
end
function p:test_link()
self:assertResultEquals('c:Data:abc.tab', p:invokeLib('link|abc.tab'), 'link01')
self:assertResultEquals('c:Data:abc.tab', p:invokeLib(' link | abc.tab '), 'link02')
self:assertResultEquals('c:Data:abc.tab', p:invokeLib(' link |\n abc.tab\n '), 'link03')
end
function p:test_doc()
local tnt = require('Module:' .. p:module())
self:assertEquals(
'{"paramOrder":["1","2"],"description":"DO NOT EDIT OR TRANSLATE unless you are changing unit tests","params":{"1":{"suggested":false,"type":"string","required":true,"label":"en_label_1","example":"en_example_1","description":"en_desc_1"},"2":{"suggested":true,"type":"string","required":false,"label":"fr_label_2","example":"pl_example_2","description":"en_desc_2"}}}',
tnt.getTemplateData('Templatedata/Module:TNT/testcases templatedata 1'),
'doc01')
self:assertEquals(
'{"paramOrder":["param1","param2"],"description":"DO NOT EDIT OR TRANSLATE unless you are changing unit tests","params":{"param2":{"suggested":true,"type":"string","required":false,"label":"fr_label_2","example":"pl_example_2","description":"en_desc_2"},"param1":{"suggested":false,"type":"string","required":true,"label":"en_label_1","example":"en_example_1","description":"en_desc_1"}}}',
tnt.getTemplateData('Templatedata/Module:TNT/testcases templatedata 2'),
'doc02')
end
return p