Module:Template test case: Difference between revisions
move Template.outputEquals to the TestCase class
(pass the config through to NowikiInvocation from TableInvocation:getInvocation) |
(move Template.outputEquals to the TestCase class) |
||
Line 22: | Line 22: | ||
getOutput = true | getOutput = true | ||
} | } | ||
function Template.new(invocationObj, options) | function Template.new(invocationObj, options) | ||
Line 216: | Line 191: | ||
end | end | ||
return output | return output | ||
end | |||
function TestCase:templateOutputIsEqual() | |||
-- Returns a boolean showing whether all of the template outputs are equal. | |||
-- The random parts of strip markers (see [[Help:Strip markers]]) are | |||
-- removed before comparison. This means a strip marker can contain anything | |||
-- and still be treated as equal, but it solves the problem of otherwise | |||
-- identical wikitext not returning as exactly equal. | |||
local function normaliseOutput(obj) | |||
local out = obj:getOutput() | |||
-- Remove the random parts from strip markers. | |||
out = out:gsub('(%cUNIQ).-(QINU%c)', '%1%2') | |||
return out | |||
end | |||
local firstOutput = normaliseOutput(self.templates[1]) | |||
for i = 2, #self.templates do | |||
local output = normaliseOutput(self.templates[i]) | |||
if output ~= firstOutput then | |||
return false | |||
end | |||
end | |||
return true | |||
end | end | ||
function TestCase:makeCollapsible(s) | function TestCase:makeCollapsible(s) | ||
local isEqual = | local isEqual = self:templateOutputIsEqual() | ||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
root | root |