Jump to content

Module:Hatnote/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 02:06, 29 January 2016 (start making test cases for Module:Hatnote). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
local mHatnote = require('Module:Hatnote') -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:assertError(func, ...)
	local success, result = pcall(func, ...)
	suite:assertFalse(success)
end

function suite:assertNotEquals(expected, actual)
	suite:assertTrue(expected ~= actual)
end

-------------------------------------------------------------------------------
-- findNamespaceId tests
-------------------------------------------------------------------------------

function suite:testFindNamespaceIdInputErrors()
    self:assertError(mHatnote.findNamespaceId, 9)
    self:assertError(mHatnote.findNamespaceId)
    self:assertError(mHatnote.findNamespaceId, 'A page', 9)
end

function suite:testFindNamespaceIdNamespaces()
	self:assertEquals(0, mHatnote.findNamespaceId('Foo'))
	self:assertEquals(2, mHatnote.findNamespaceId('User:Example'))
	self:assertEquals(14, mHatnote.findNamespaceId('Category:Example'))
end

function suite:testFindNamespaceIdColonRemoval()
	self:assertEquals(14, mHatnote.findNamespaceId(':Category:Example'))
end

function suite:testFindNamespaceIdSkipColonRemoval()
	self:assertNotEquals(14, mHatnote.findNamespaceId(':Category:Example', false))
end

return suite