Module:template parser/testcases
Appearance
- පහත දැක්වෙන උපදෙස්, Module:template parser/testcases/documentation හි පිහිටා ඇත. Module:template parser/testcases/documentation]]. [සංස්කරණය]
- ප්රයෝජනවත් සබැඳි: root page • root page’s subpages • සබැඳි • transclusions • tested module • sandbox
All tests passed. (refresh)
Text | Expected | Actual | |
---|---|---|---|
{{l|en|word}}
| {"link", {"en", "word"}} | {"link", {"en", "word"}} | |
{{t|cmn|大老二|tr={{m|cmn|dà lǎo èr}}}}
| {"t", {"cmn", "大老二", tr='<i class="Latn mention" lang="cmn">[[dà lǎo èr#මැන්ඩරීන්|dà lǎo èr]]</i>'}} | {"t", {"cmn", "大老二", tr='<i class="Latn mention" lang="cmn">[[dà lǎo èr#මැන්ඩරීන්|dà lǎo èr]]</i>'}} | |
{{t|akk|𒁀|tr=[[Image:B014ellst.png|30px]] qiāšu, BA}}
| {"t", {"akk", "𒁀", tr="[[Image:B014ellst.png|30px]] qiāšu, BA"}} | {"t", {"akk", "𒁀", tr="[[Image:B014ellst.png|30px]] qiāšu, BA"}} |
Text | Expected | Actual | |
---|---|---|---|
{{l| en | word
}}
| {"link", {" en ", " word\n"}} | {"link", {" en ", " word\n"}} | |
{{l| en | 2 = word
}}
| {"link", {" en ", "word"}} | {"link", {" en ", "word"}} | |
{{l| 1 = en | word
}}
| {"link", {" word\n"}} | {"link", {" word\n"}} |
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=[[Image:B014ellst.png|30px]] qiāšu, BA}}",
{ "t", { "akk", "𒁀", tr = "[[Image:B014ellst.png|30px]] qiāšu, BA" } },
}
}
local frame = mw.getCurrentFrame()
for i, example in ipairs(examples) do
local args, new = example[2][2], {}
for k, v in pairs(args) do
k = type(k) == "string" and frame:preprocess(k) or k
new[k] = frame:preprocess(v)
end
example[2][2] = 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