Jump to content

Module:Anchor/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 15:43, 15 December 2013 (test against template). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:Anchor]]. Click talk page to run tests.

local anchor = require('Module:Anchor') -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:testmain()
	self:assertResultEquals('<span id="foo"></span>', '{{#invoke:Anchor|main|foo}}')
	self:assertResultEquals('<span id="foo"></span><span id="bar"></span>', '{{#invoke:Anchor|main|foo|bar}}')
	self:assertResultEquals('<span id="foo"></span>', '{{#invoke:Anchor|main|3=foo}}')
	self:assertResultEquals('<span id="foo"></span>', '{{#invoke:Anchor|main|  foo  }}')
	self:assertResultEquals('<span id="foo"></span>', '{{#invoke:Anchor|main|25=foo}}')
end

function suite:test_main()
	self:assertResultEquals('<span id="foo"></span>', anchor._main('foo'))
	self:assertResultEquals('<span id="foo"></span><span id="bar"></span>', anchor._main('foo', 'bar'))
end

function suite:testAgainstTemplate()
	self:assertSameResult('{{anchor|foo}}', '{{#invoke:Anchor|main|foo}}')
	self:assertSameResult('{{anchor|foo|bar}}', '{{#invoke:Anchor|main|foo|bar}}')
	self:assertSameResult('{{anchor|3=foo}}', '{{#invoke:Anchor|main|3=foo}}')
	-- The below are not equal as the template only accepts up to 10 anchors.
	self:assertFalse(self.frame:preprocess('{{anchor|25=foo}}') == self.frame:preprocess('{{#invoke:Anchor|main|25=foo}}'))
	-- The below are not equal as the template doesn't trim whitespace from the anchor.
	self:assertFalse(self.frame:preprocess('{{anchor|  foo  }}') == self.frame:preprocess('{{#invoke:Anchor|main|  foo  }}'))
end

return suite