Module:Template test case: Difference between revisions
(add a Template.outputEquals function) |
(allow Template.outputEquals to compare more than two template objects) |
||
Line 24: | Line 24: | ||
} | } | ||
function Template.outputEquals( | function Template.outputEquals(...) | ||
-- This function accepts 2 or more template objects and compares their | |||
-- output. If all the outputs are equal, it returns true, and if any of them | |||
-- are different, it returns false. | |||
local n = select('#', ...) | |||
if n < 2 then | |||
error('Template.outputEquals requires at least two arguments', 2) | |||
end | |||
local function normaliseOutput(obj) | local function normaliseOutput(obj) | ||
local out = obj:getOutput() | local out = obj:getOutput() | ||
Line 31: | Line 38: | ||
return out | return out | ||
end | end | ||
local prevOutput = normaliseOutput(select(1, ...)) | |||
for i = 2, n do | |||
local output = normaliseOutput(select(i, ...)) | |||
if output ~= prevOutput then | |||
return false | |||
end | |||
prevOutput = output | |||
end | |||
return true | |||
end | end | ||