Module:Template test case: Difference between revisions
(make a template class and add code to set template objects in the test case class) |
(implement a default test case format) |
||
Line 126: | Line 126: | ||
-- Separate general options from options for specific templates | -- Separate general options from options for specific templates | ||
local templateOptions = mTableTools.numData(options, true) | local templateOptions = mTableTools.numData(options, true) | ||
options = templateOptions.other | obj.options = templateOptions.other | ||
-- Make the template objects | -- Make the template objects | ||
Line 141: | Line 140: | ||
obj.templates[2] = Template.new( | obj.templates[2] = Template.new( | ||
invocationObj, | invocationObj, | ||
templateOptions[2], | |||
function () | function () | ||
return templateTitleCallback():subPageTitle('sandbox') | return templateTitleCallback():subPageTitle('sandbox') | ||
Line 154: | Line 153: | ||
return obj | return obj | ||
end | |||
function TestCase:renderDefault() | |||
local ret = {} | |||
ret[#ret + 1] = self.templates[1]:getInvocation('code') | |||
for i, obj in ipairs(self.templates) do | |||
ret[#ret + 1] = '<div style="clear: both;"></div>' | |||
ret[#ret + 1] = obj:makeBraceLink() | |||
ret[#ret + 1] = obj:getOutput() | |||
end | |||
return table.concat(ret, '\n\n') | |||
end | |||
function TestCase:tostring() | |||
local methods = { | |||
columns = 'renderColumns', | |||
rows = 'renderRows' | |||
} | |||
local format = self.options.format | |||
local method = format and methods[format] or 'renderDefault' | |||
return self[method](self) | |||
end | end | ||
Line 248: | Line 268: | ||
end | end | ||
end | end | ||
local | local invocationObj = TableInvocation.new(invokeArgs) | ||
return | local testCaseObj = TestCase.new(invocationObj, options) | ||
return tostring(testCaseObj) | |||
end | end | ||
Line 271: | Line 292: | ||
function p._nowiki(args) | function p._nowiki(args) | ||
local | local invocationObj = NowikiInvocation.new(args.invocation) | ||
args.invocation = nil | args.invocation = nil | ||
local options = args | local options = args | ||
return | local testCaseObj = TestCase.new(invocationObj, options) | ||
return tostring(testCaseObj) | |||
end | end | ||