--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"

function p:_internal_test(module, name)
	module.test = function(...)
		local s,r = module.getValue(...)
		if not s then
			return "<Fail> " .. r
		else
			return r
		end
	end

	--Basic errors tests
	self:equals(name.."error test 1", module.test(), "<Fail> Missing required parameters 'templates' and 'parameter'")
	self:equals(name.."error test 2", module.test("", "", ""), "<Fail> Requested title doesn't exist")
	self:equals(name.."error test 3", module.test(TestPage, "", ""), "<Fail> No valid template found")

	--Test _id grabbing for the TemplateN series
	self:equals(name.."basic grabbing 1", module.test(TestPage, "X13", "_id"), "1")
	self:equals(name.."basic grabbing 2", module.test(TestPage, "X11", "_id"), "2")
	self:equals(name.."basic grabbing 3", module.test(TestPage, "X11", "_id", {template_index=1}), "2")
	self:equals(name.."basic grabbing 4", module.test(TestPage, "X12", "_id"), "3")
	self:equals(name.."basic grabbing 5", module.test(TestPage, "X11", "_id", {template_index=2}), "4")
	self:equals(name.."basic grabbing 6", module.test(TestPage, "X11", "_id", {template_index=3}), "5")
	self:equals(name.."basic grabbing 7", module.test(TestPage, "X11", "_id", {template_index=4}), "subtemplate")
	self:equals(name.."basic grabbing 8", module.test(TestPage, "X11", "_id", {template_index=4, parameter_index=2}), "6")
	self:equals(name.."basic grabbing 9", module.test(TestPage, "X11", "_id", {template_index=4, ignore_subtemplates=true}), "6")
	
	--Test grabbing for the other tests (NumericalParameters, HeavyNesting)
	self:equals(name.."numerical parameters 1", module.test(TestPage, "X21", "1"), "X")
	self:equals(name.."numerical parameters 2", module.test(TestPage, "X21", "2"), "Y")
	self:equals(name.."numerical parameters 3", module.test(TestPage, "X21", "3"), "Z")
	self:equals(name.."numerical parameters 4", module.test(TestPage, "X21", "4"), "W")
	self:equals(name.."numerical parameters 5", module.test(TestPage, "X21", "5"), "")
	self:equals(name.."numerical parameters 6", module.test(TestPage, "X21", "6"), "P")
	
	self:equals(name.."nesting templates 1", module.test(TestPage, "X22", "1"), "2")
	self:equals(name.."nesting templates 2", module.test(TestPage, "X22", "1", {ignore_subtemplates=true}), "")
	self:equals(name.."nesting templates 3", module.test(TestPage, "X22", "A1"), "Nest1")
	self:equals(name.."nesting templates 4", module.test(TestPage, "X22", "A2"), "Nest2{{X20 |x=y|1=2|_id=9}} Content", {nowiki=1})
	self:equals(name.."nesting templates 5", module.test(TestPage, "X22", "A3a"), "{{Text|A|4|A4=A5}}", {nowiki=1})
	self:equals(name.."nesting templates 6", module.test(TestPage, "X22", "A3b"), "1{{Text|A|4|A4=A5}}2", {nowiki=1})
	self:equals(name.."nesting templates 7", module.test(TestPage, "X22", "A4", {parameter_index=2}), "A5")
	self:equals(name.."nesting templates 8", module.test(TestPage, "X22", "A4", {parameter_index=3}), "[[Help:Example|{{X20|[[Help:Example]]|_id=%10}}]]", {nowiki=1})
	self:equals(name.."nesting templates 9", module.test(TestPage, "X22", "A5"), "")
	self:equals(name.."nesting templates 10", module.test(TestPage, "X22", "A6"), "")
	self:equals(name.."nesting templates 11", module.test(TestPage, "X22", "A7"), "{{X22 |_id=11}}", {nowiki=1})
end

function p:test_live()
	p:_internal_test(require("Module:Template parameter value"), "Live ")
end

function p:test_sandbox()
	p:_internal_test(require("Module:Template parameter value/sandbox"), "Sandbox ")
end

return p
"https://si.wikipedia.org/w/index.php?title=Module:Template_parameter_value/testcases&oldid=704250" වෙතින් සම්ප්‍රවේශනය කෙරිණි