Jump to content

Module:Template parameter value/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Aidan9382 (talk | contribs) at 06:29, 24 February 2023 (try without preprocessing). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
--Go to the talk page to see the results of the tests. See [[Template:Template parameter value/testpage]] for the content used in testing
local p = require('Module:UnitTests')
local TestPage = "Template:Template parameter value/testpage"

local function process(x)
	return x--return mw.getCurrentFrame():preprocess(x)
end

function p:test_TemplateEntry()
	--Test _id grabbing for the TemplateN series
	self:preprocess_equals_sandbox_many('{{#invoke:Template parameter value', 'main', {
		{TestPage.."|Template3||_id", "1"},
		{TestPage.."|Template1||_id", "2"},
		{TestPage.."|Template1|1|_id", "2"},
		{TestPage.."|Template2||_id", "3"},
		{TestPage.."|Template1|2|_id", "4"},
		{TestPage.."|Template1|3|_id", "5"},
		{TestPage.."|Template1|4|_id", "subtemplate"},
		{TestPage.."|Template1|4|_id|2", "6"},
		{TestPage.."|Template1|4|_id|ignore_subtemplates=y", "6"},
	}, {nowiki=1})

	--Test grabbing for the other tests (NumericalParameters, HeavyNesting)
	self:preprocess_equals_sandbox_many('{{#invoke:Template parameter value', 'main', {
		{TestPage.."|NumericalParameters||1", "X"},
		{TestPage.."|NumericalParameters||2", "Y"},
		{TestPage.."|NumericalParameters||3", "Z"},
		{TestPage.."|NumericalParameters||4", "W"},
		{TestPage.."|NumericalParameters||5", ""},
		{TestPage.."|NumericalParameters||6", "P"},
	}, {nowiki=1})
	self:preprocess_equals_sandbox_many('{{#invoke:Template parameter value', 'main', {
		{TestPage.."|HeavyNesting||1", "2"},
		{TestPage.."|HeavyNesting||1|ignore_subtemplates=y", ""},
		{TestPage.."|HeavyNesting||A1", "Nest1"},
		{TestPage.."|HeavyNesting||A2", process("Nest2{{Inline template|x=y|1=2|_id=9}} Content")},
		{TestPage.."|HeavyNesting||A3", process("{{Text|A|4|A4=A5}}")},
		{TestPage.."|HeavyNesting||A3v2", process("1{{Text|A|4|A4=A5}}2")},
		{TestPage.."|HeavyNesting||A4|2", "A5"},
		{TestPage.."|HeavyNesting||A4|3", process("[[Help:Example|{{%1|[[Help:Example]]|_id=10}}]]")},
		{TestPage.."|HeavyNesting||A5", ""},
		{TestPage.."|HeavyNesting||A6", ""},
		{TestPage.."|HeavyNesting||A7", process("{{HeavyNesting|_id=11}}")},
	}, {nowiki=1})
end

return p