Module:Hatnote/testcases
Appearance
![]() | This is the test cases page for the module Module:Hatnote. Results of the test cases. |
local mHatnote = require('Module:Hatnote/sandbox') -- 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
-------------------------------------------------------------------------------
-- formatPages tests
-------------------------------------------------------------------------------
function suite:testFormatPages()
self:assertDeepEquals({'[[:Foo]]', '[[:Bar]]'}, mHatnote.formatPages('Foo', 'Bar'))
end
-------------------------------------------------------------------------------
-- formatPageTables tests
-------------------------------------------------------------------------------
function suite:testFormatPageTables()
self:assertDeepEquals(
{'[[:Foo|foo]]', '[[:Bar|bar]]'},
mHatnote.formatPageTables({'Foo', 'foo'}, {'Bar', 'bar'})
)
end
-------------------------------------------------------------------------------
-- makeWikitextError tests
-------------------------------------------------------------------------------
function suite:testMakeWikitextError()
suite:assertEquals(
'<strong class="error">Error: Foo.</strong>[[Category:Hatnote templates with errors]]',
mHatnote.makeWikitextError('Foo', nil, nil, mw.title.new('Example'))
)
end
function suite:testMakeWikitextErrorHelpLink()
suite:assertEquals(
'<strong class="error">Error: Foo ([[Bar|help]]).</strong>[[Category:Hatnote templates with errors]]',
mHatnote.makeWikitextError('Foo', 'Bar', nil, mw.title.new('Example'))
)
end
function suite:testMakeWikitextErrorCategorySuppression()
suite:assertEquals(
'<strong class="error">Error: Foo.</strong>',
mHatnote.makeWikitextError('Foo', nil, false, mw.title.new('Example'))
)
end
-------------------------------------------------------------------------------
-- formatLink tests
-------------------------------------------------------------------------------
function suite:testFormatLink()
suite:assertEquals('[[:Foo]]', mHatnote._formatLink('Foo'))
end
function suite:testFormatLinkColonHandling()
suite:assertEquals('[[:Category:Foo]]', mHatnote._formatLink(':Category:Foo'))
end
function suite:testFormatLinkSectionLinking()
suite:assertEquals('[[:Foo#Bar|Foo § Bar]]', mHatnote._formatLink('Foo#Bar'))
end
function suite:testFormatLinkPipeHandling()
suite:assertEquals('[[:Foo|Bar]]', mHatnote._formatLink('Foo|Bar'))
end
function suite:testFormatLinkDisplay()
suite:assertEquals('[[:Foo|Bar]]', mHatnote._formatLink('Foo', 'Bar'))
end
function suite:testFormatLinkEntryPoint()
local current = mw.getCurrentFrame()
local parent = current:newChild{title = 'Parent', args = {'Foo'}}
local child = parent:newChild{title = 'Child'}
suite:assertEquals('[[:Foo]]', mHatnote.formatLink(child))
parent = current:newChild{title = 'Parent', args = {'Foo', 'Bar'}}
child = parent:newChild{title = 'Child'}
suite:assertEquals('[[:Foo|Bar]]', mHatnote.formatLink(child))
end
return suite