Module:Template test case: Difference between revisions

add a shared message method
(move the render methods table to the base of the TestCase class)
(add a shared message method)
Line 7:
-- Set constants
local DATA_MODULE = 'Module:Template test case/data'
 
-------------------------------------------------------------------------------
-- Shared methods
-------------------------------------------------------------------------------
 
local function message(self, key, ...)
-- This method is added to classes that need to deal with messages from the
-- config module.
local msg = self.cfg.msg[key]
if select(1, ...) then
return mw.message.newRawMessage(msg, ...):plain()
else
return msg
end
end
 
-------------------------------------------------------------------------------
Line 127 ⟶ 142:
local TestCase = {}
TestCase.__index = TestCase
TestCase.message = message -- add the message method
 
TestCase.renderMethods = {
Line 365 ⟶ 381:
local NowikiInvocation = {}
NowikiInvocation.__index = NowikiInvocation
NowikiInvocation.message = message -- Add the message method
 
function NowikiInvocation.new(invocation, cfg)
Line 388 ⟶ 405:
)
if count < 1 then
error(string.formatself:message(
'nowiki-magic-word-error',
"the template invocation must include '%s' in place " ..
"of the template name",
self.cfg.templateNameMagicWord
))
Line 408 ⟶ 424:
local TableInvocation = {}
TableInvocation.__index = TableInvocation
TableInvocation.message = message -- Add the message method
 
function TableInvocation.new(invokeArgs, nowikiCode, cfg)