Pergi ke kandungan

Modul:template parser/testcases

Daripada Wikikamus

2 of 0 tests failed. (refresh)

TextExpectedActual
test_basic:
Script error during testing: Modul:template_parser/testcases:9: attempt to call upvalue 'parse_template' (a nil value)
stack traceback:
	[C]: in function 'parse_template'
	Modul:template_parser/testcases:9: in function 'func'
	Modul:UnitTests:313: in function 'iterate'
	Modul:template_parser/testcases:8: in function 'check_templates'
	Modul:template_parser/testcases:28: in function <Modul:template_parser/testcases:13>
	(tail call): ?
	(tail call): ?
	[C]: in function 'xpcall'
	Modul:fun/xpcall:37: in function 'xpcall'
	Modul:UnitTests:389: in function <Modul:UnitTests:350>
	(tail call): ?
	mw.lua:678: in function <mw.lua:652>
	[C]: ?
	[C]: in function 'expandTemplate'
	mw.lua:388: in function <mw.lua:362>
	(tail call): ?
	(tail call): ?
	Modul:pendokumenan:1043: in function 'chunk'
	mw.lua:678: in function <mw.lua:652>
	[C]: ?
TextExpectedActual
test_whitespace:
Script error during testing: Modul:template_parser/testcases:9: attempt to call upvalue 'parse_template' (a nil value)
stack traceback:
	[C]: in function 'parse_template'
	Modul:template_parser/testcases:9: in function 'func'
	Modul:UnitTests:313: in function 'iterate'
	Modul:template_parser/testcases:8: in function 'check_templates'
	Modul:template_parser/testcases:32: in function <Modul:template_parser/testcases:31>
	(tail call): ?
	(tail call): ?
	[C]: in function 'xpcall'
	Modul:fun/xpcall:37: in function 'xpcall'
	Modul:UnitTests:389: in function <Modul:UnitTests:350>
	(tail call): ?
	mw.lua:678: in function <mw.lua:652>
	[C]: ?
	[C]: in function 'expandTemplate'
	mw.lua:388: in function <mw.lua:362>
	(tail call): ?
	(tail call): ?
	Modul:pendokumenan:1043: in function 'chunk'
	mw.lua:678: in function <mw.lua:652>
	[C]: ?
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