Modul:template parser/testcases

All tests passed. (refresh)

TextExpectedActual
test_basic:
Passed
{{l|en|word}}
{"link", {"en", "word"}}{"link", {"en", "word"}}
Passed
{{t|cmn|大老二|tr={{m|cmn|dà lǎo èr}}}}
{"t", {"cmn", "大老二", tr="{{m|cmn|dà lǎo èr}}"}}{"t", {"cmn", "大老二", tr="{{m|cmn|dà lǎo èr}}"}}
Passed
{{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"}}
TextExpectedActual
test_whitespace:
Passed
{{l| en | word
}}
{"link", {" en ", " word\n"}}{"link", {" en ", " word\n"}}
Passed
{{l| en | 2 = word
}}
{"link", {" en ", "word"}}{"link", {" en ", "word"}}
Passed
{{l| 1 = en | word
}}
{"link", {" word\n"}}{"link", {" word\n"}}

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