Module:Arguments/testcases

From blackwiki
< Module:Arguments
Revision as of 01:34, 10 December 2013 by blackwiki>Mr. Stradivarius (try putting the function directly in the suite table)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Arguments/testcases/doc

local getArgs = require('Module:Arguments').getArgs
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

------------------ Template invocations used by the module --------------------
-- Module talk:Arguments/testInvoke:
-- {{#invoke:arguments/testcases|{{{function|}}}|firstInvokeArg}}
-- Module talk:Arguments/testTemplate:
-- {{Module talk:Arguments/testInvoke|{{{1|}}}|{{{2|}}}|blank=|function={{{function|}}}}}

function suite.expandTestTemplate(funcName, para1, para2)
	local frame = mw.getCurrentFrame()
	local val = frame:preprocess('{{Module talk:Arguments/testTemplate|' .. para1 .. '|' .. para2 .. '|function=' .. funcName .. '}}')
	return val
end

function suite.createInvokeFunction(key, options)
	return function (frame)
		options = options or {}
		local args = getArgs(frame, options)
		return args[key]
	end
end

suite.defaultPrecedenceFirst = suite.createInvokeFunction(1)

function suite:testDefaultPrecedence()
	local first = suite.expandTestTemplate('defaultPrecedenceFirst', 'firstTemplateArg', 'secondTemplateArg')
	self:assertEquals('firstInvokeArg', first)
end

function suite.main(frame)
	local args = getArgs(frame)
	return args[1]
end

function suite.test()
	local frame = mw.getCurrentFrame()
	local mainVal = frame:preprocess('{{Module talk:Arguments/testInvoke|function=main}}')
	return mainVal
end

return suite