Module:Template test case: Difference between revisions
allow users to pass in nowiki invocations when using table-based templates
(add an option to make things collapsible, and remove dead code) |
(allow users to pass in nowiki invocations when using table-based templates) |
||
Line 406: | Line 406: | ||
TableInvocation.__index = TableInvocation | TableInvocation.__index = TableInvocation | ||
function TableInvocation.new(invokeArgs) | function TableInvocation.new(invokeArgs, nowikiCode) | ||
local obj = setmetatable({}, TableInvocation) | local obj = setmetatable({}, TableInvocation) | ||
obj.invokeArgs = invokeArgs | obj.invokeArgs = invokeArgs | ||
obj.code = nowikiCode | |||
return obj | return obj | ||
end | end | ||
function TableInvocation:getInvocation(template) | function TableInvocation:getInvocation(template) | ||
return require('Module:Template invocation').invocation( | if self.code then | ||
local nowikiObj = NowikiInvocation(self.code) | |||
return nowikiObj:getInvocation(template) | |||
else | |||
return require('Module:Template invocation').invocation( | |||
template, | |||
self.invokeArgs | |||
) | |||
end | |||
end | end | ||
Line 457: | Line 463: | ||
end | end | ||
end | end | ||
local invocationObj = TableInvocation.new(invokeArgs) | |||
-- Allow passing a nowiki invocation as an option. While this means users | |||
-- have to pass in the code twice, whitespace is preserved and < etc. | |||
-- will work as intended. | |||
local nowikiCode = options.code | |||
options.code = nil | |||
local invocationObj = TableInvocation.new(invokeArgs, nowikiCode) | |||
local testCaseObj = TestCase.new(invocationObj, options) | local testCaseObj = TestCase.new(invocationObj, options) | ||
return tostring(testCaseObj) | return tostring(testCaseObj) |