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