2 of 0 tests failed. (refresh)
Text | Expected | Actual | |
---|---|---|---|
Script error during testing: Module:template_parser/testcases:10: attempt to call method 'get_name' (a nil value)stack traceback: : in function 'get_name' Module:template_parser/testcases:10: in function 'func' Module:UnitTests:313: in function 'iterate' Module:template_parser/testcases:8: in function 'check_templates' Module:template_parser/testcases:38: in function <Module:template_parser/testcases:14> (tail call): ? (tail call): ? : in function 'xpcall' Module:fun/xpcall:37: in function 'xpcall' Module:UnitTests:389: in function <Module:UnitTests:350> (tail call): ? mw.lua:527: in function <mw.lua:507> : ? : in function 'expandTemplate' mw.lua:333: in function <mw.lua:307> (tail call): ? (tail call): ? Module:documentation:1026: in function 'chunk' mw.lua:527: in function <mw.lua:507> : ? |
Text | Expected | Actual | |
---|---|---|---|
Script error during testing: Module:template_parser/testcases:10: attempt to call method 'get_name' (a nil value)stack traceback: : in function 'get_name' Module:template_parser/testcases:10: in function 'func' Module:UnitTests:313: in function 'iterate' Module:template_parser/testcases:8: in function 'check_templates' Module:template_parser/testcases:42: in function <Module:template_parser/testcases:41> (tail call): ? (tail call): ? : in function 'xpcall' Module:fun/xpcall:37: in function 'xpcall' Module:UnitTests:389: in function <Module:UnitTests:350> (tail call): ? mw.lua:527: in function <mw.lua:507> : ? : in function 'expandTemplate' mw.lua:333: in function <mw.lua:307> (tail call): ? (tail call): ? Module:documentation:1026: in function 'chunk' mw.lua:527: in function <mw.lua:507> : ? |
local tests = require "Module:UnitTests"
local highlight = require("Module:debug").highlight{ lang = "text"}
local parse = require("Module:template parser").parse
function tests:check_templates(examples)
local options = { nowiki = true }
tests:iterate(examples, function(self, wikitext, expected)
local template = parse(wikitext)
self:equals_deep(highlight(wikitext), {template:get_name(), template:get_arguments()}, expected, options)
end)
end
function tests:test_basic()
local examples = {
{
"{{l|en|word}}",
{ "link", { "en", "word" } },
},
{
"{{t|cmn|大老二|tr={{m|cmn|dà lǎo èr}}}}",
{ "t", { "cmn", "大老二", tr = "{{m|cmn|dà lǎo èr}}" } },
},
{
"{{t|akk|𒁀|tr=] qiāšu, BA}}",
{ "t", { "akk", "𒁀", tr = "] qiāšu, BA" } },
}
}
local frame = mw.getCurrentFrame()
for i, example in ipairs(examples) do
local args, new = example, {}
for k, v in pairs(args) do
k = type(k) == "string" and frame:preprocess(k) or k
new = frame:preprocess(v)
end
example = new
end
self:check_templates(examples)
end
function tests:test_whitespace()
self:check_templates {
{ "{{l| en | word\n}}", { "link", { " en ", " word\n" } } },
{ "{{l| en | 2 = word\n}}", { "link", { " en ", "word" } } },
{ "{{l| 1 = en | word\n}}", { "link", { " word\n" } } },
}
end
return tests