-- Example Unit tests for [[Module:UnitTests]]. Click talk page to run tests.
require[[strict]]
local p = require('Module:UnitTests')

local frame0 = mw.getCurrentFrame()
local frame0_getTitle = frame0:getTitle()
local getCurrentFrame_getTitle = mw.getCurrentFrame():getTitle()
local arg = ...

function p._test(frame)
	return
		"# " .. frame:getTitle() .. "\n" ..
		"# " .. frame0:getTitle() .. "\n" ..
		"# " .. frame0_getTitle .. "\n" ..
		"# " .. getCurrentFrame_getTitle .. "\n" ..
		"# " .. mw.dumpObject(arg) .. "\n" ..
		""
end

function p._test0(frame)
	return
		"# Module:UnitTests/testcases\n" ..
		"# Module:UnitTests/testcases\n" ..
		"# Module:UnitTests/testcases\n" ..
		"# Module:UnitTests/testcases\n" ..
		"# nil\n" ..
	""
end

function p.preprocess(frame)
	--return frame.args[1]
	return frame:preprocess(frame.args[1])
end

function p.p1(frame)
	return frame:preprocess('{{#invoke:UnitTests/testcases | _test}}')
end

function p.p2(frame)
	return frame:preprocess('{{#invoke:UnitTests/testcases/frame | _test}}')
end

function p:test()
	local testcases_expected_result = "" ..
		"# Module:UnitTests/testcases\n" ..
		"# Module:UnitTests/testcases\n" ..
		"# Module:UnitTests/testcases\n" ..
		"# Module:UnitTests/testcases\n" ..
		""
	self:preprocess_equals('{{#invoke:UnitTests/testcases | _test}}', "\n" ..
		testcases_expected_result ..
		"# nil\n" ..
	"")
	self:preprocess_equals('{{#invoke:UnitTests/testcases | _test}}', "\n" ..
		testcases_expected_result ..
		"# nil\n" ..
	"", {nowiki=true})
	self:preprocess_equals('{{#invoke:UnitTests/testcases | _test}}', "\n" ..
		testcases_expected_result ..
		"# nil\n" ..
	"", {combined=true})
	local testcases_frame_expected_result = "" ..
		"# Module:UnitTests/testcases/frame\n" ..
		"# Module:UnitTests/testcases/frame\n" ..
		"# Module:UnitTests/testcases/frame\n" ..
		"# Module:UnitTests/testcases/frame\n" ..
		""
	self:preprocess_equals('{{#invoke:UnitTests/testcases/frame | _test}}', "\n" ..
		testcases_frame_expected_result ..
		"# nil\n" ..
	"")
	self:equals("<nowiki>mw.getCurrentFrame():preprocess( '{{#invoke:UnitTests/testcases/frame | _test}}' )</nowiki>",
		mw.getCurrentFrame():preprocess( '{{#invoke:UnitTests/testcases/frame | _test}}' ),
		"\n" ..
		testcases_frame_expected_result ..
		"# nil\n" ..
	"")
	self:equals("<nowiki>frame0:preprocess( '{{#invoke:UnitTests/testcases/frame | _test}}' )</nowiki>",
		frame0:preprocess( '{{#invoke:UnitTests/testcases/frame | _test}}' ),
		"\n" ..
		testcases_frame_expected_result ..
		"# nil\n" ..
	"")
	--[[self:equals("<nowiki>frame0:expandTemplate{ title = '#invoke:UnitTests/testcases/frame', args = { '_test' } }</nowiki>",
		frame0:expandTemplate{ title = '#invoke:UnitTests/testcases/frame', args = { '_test' } },
		"\n" ..
		testcases_frame_expected_result ..
		"# nil\n" ..
	"")]]
	self:equals("require('Module:UnitTests/testcases/frame')._test(mw.getCurrentFrame())",
		"\n"..require('Module:UnitTests/testcases/frame')._test(mw.getCurrentFrame()),
		"\n" ..
		testcases_expected_result ..
		'# "Module:UnitTests/testcases/frame"\n' ..
	"")
	self:equals("p._test(frame0)",
		"\n"..p._test(frame0),
		"\n" ..
		testcases_expected_result ..
		"# nil\n" ..
	"")
	self:equals("p._test(mw.getCurrentFrame())",
		"\n"..p._test(mw.getCurrentFrame()),
		"\n" ..
		testcases_expected_result ..
		"# nil\n" ..
	"")
	--[[self:preprocess_equals('{{#invoke:UnitTests/testcases | _test0}}', "\n" ..
		testcases_expected_result ..
		"# nil\n" ..
	"")
	self:preprocess_equals('{{#invoke:UnitTests/testcases | _test0}}', "\n" .. p._test0())
	]]
	self:equals("Blatant fail", "<span>String 1</span>", "<span>String 2</span>")
end

--[=[
function p:error1()
	error("p:error1")
end

function p.error2()
	error("p.error2")
end

function p:error3()
	error("p:error3")
end

function p.error3()
	error("p.error3")
end

function p.error4()
	error("p.error4")
end

function p:error4()
	error("p:error4")
end

function p:test_error5()
	error("p:test_error5")
end

function p:_test6()
	error("p:_test6")
end

function p.ttest_error7()
	error("p.test_error7")
end

function p._test8()
	error("p.test8")
end
--]=]

return p