Module:Sandbox/Johnuniq/message

-- Adapt message from Module:Documentation/sandbox to test -- Anomie's advice at WT:Lua: --  mw.message.newRawMessage("text"):params("$1", "$2", "etc"):plain -- To see output, preview following in a sandbox: --

local cfg = { invalid = 'Input "$1" is not a number', too_big = 'Input $1 should be less than $2', }

local function message(cfgKey, valArray) local msg = cfg[cfgKey] if valArray then return mw.message.newRawMessage(msg):params(valArray):plain end return msg end

local tests = { { 'invalid', { 'xyz' } }, { 'too_big', { '42', '12' } }, { 'too_big', { 42, 12 } }, }

local function main local result = {} for _, t in ipairs(tests) do result[#result + 1] = '*' .. message(t[1], t[2]) .. '\n' end return table.concat(result) end

return { main = main }