Modul:template parser/testcases
Penampilan
- Modul ini kekurangan sublaman pendokumenan. Sila mencipta laman pendokumenan berkaitan.
- Pautan berguna: laman akar • sublaman • pautan • transklusi • modul ujian • kotak pasir
local tests = require "Module:UnitTests"
local parse_template = require "Module:template parser".parseTemplate
local highlight = require "Module:debug".highlight { lang = "text" }
function tests:check_templates(examples)
local options = { nowiki = true }
tests:iterate(examples, function(self, wikitext, expected)
self:equals_deep(highlight(wikitext), {parse_template(wikitext)}, 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" } },
}
}
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