Module:Template test case: Difference between revisions

    (move the render methods table to the base of the TestCase class)
    (add a shared message method)
    Line 7: Line 7:
    -- Set constants
    -- Set constants
    local DATA_MODULE = 'Module:Template test case/data'
    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: Line 142:
    local TestCase = {}
    local TestCase = {}
    TestCase.__index = TestCase
    TestCase.__index = TestCase
    TestCase.message = message -- add the message method


    TestCase.renderMethods = {
    TestCase.renderMethods = {
    Line 365: Line 381:
    local NowikiInvocation = {}
    local NowikiInvocation = {}
    NowikiInvocation.__index = NowikiInvocation
    NowikiInvocation.__index = NowikiInvocation
    NowikiInvocation.message = message -- Add the message method


    function NowikiInvocation.new(invocation, cfg)
    function NowikiInvocation.new(invocation, cfg)
    Line 388: Line 405:
    )
    )
    if count < 1 then
    if count < 1 then
    error(string.format(
    error(self:message(
    "the template invocation must include '%s' in place " ..
    'nowiki-magic-word-error',
    "of the template name",
    self.cfg.templateNameMagicWord
    self.cfg.templateNameMagicWord
    ))
    ))
    Line 408: Line 424:
    local TableInvocation = {}
    local TableInvocation = {}
    TableInvocation.__index = TableInvocation
    TableInvocation.__index = TableInvocation
    TableInvocation.message = message -- Add the message method


    function TableInvocation.new(invokeArgs, nowikiCode, cfg)
    function TableInvocation.new(invokeArgs, nowikiCode, cfg)