Module:Hatnote/testcases
Appearance
From Wikipedia, the free encyclopedia
localmHatnote=require('Module:Hatnote/sandbox')-- the module to be tested localScribuntoUnit=require('Module:ScribuntoUnit') localsuite=ScribuntoUnit:new() functionsuite:assertError(func,...) localsuccess,result=pcall(func,...) self:assertFalse(success) end functionsuite:assertNotEquals(expected,actual) self:assertTrue(expected~=actual) end functionsuite:assertParentFrameCallEquals(expected,func,args) args=argsor{} localcurrent=mw.getCurrentFrame() localparent=current:newChild{title='Parent',args=args} localchild=parent:newChild{title='Child'} self:assertEquals(expected,func(child)) end functionsuite:assertParentFrameCallContains(expected,func,args) args=argsor{} localcurrent=mw.getCurrentFrame() localparent=current:newChild{title='Parent',args=args} localchild=parent:newChild{title='Child'} self:assertStringContains(expected,func(child)) end ------------------------------------------------------------------------------- -- findNamespaceId tests ------------------------------------------------------------------------------- functionsuite:testFindNamespaceIdInputErrors() self:assertError(mHatnote.findNamespaceId,9) self:assertError(mHatnote.findNamespaceId) self:assertError(mHatnote.findNamespaceId,'A page',9) end functionsuite:testFindNamespaceIdNamespaces() self:assertEquals(0,mHatnote.findNamespaceId('Foo')) self:assertEquals(2,mHatnote.findNamespaceId('User:Example')) self:assertEquals(14,mHatnote.findNamespaceId('Category:Example')) end functionsuite:testFindNamespaceIdColonRemoval() self:assertEquals(14,mHatnote.findNamespaceId(':Category:Example')) end functionsuite:testFindNamespaceIdSkipColonRemoval() self:assertNotEquals(14,mHatnote.findNamespaceId(':Category:Example',false)) end ------------------------------------------------------------------------------- -- makeWikitextError tests ------------------------------------------------------------------------------- functionsuite:testMakeWikitextError() self:assertEquals( '<strong class="error">Error: Foo.</strong>[[Category:Hatnote templates with errors]]', mHatnote.makeWikitextError('Foo',nil,nil,mw.title.new('Example')) ) end functionsuite:testMakeWikitextErrorHelpLink() self:assertEquals( '<strong class="error">Error: Foo ([[Bar|help]]).</strong>[[Category:Hatnote templates with errors]]', mHatnote.makeWikitextError('Foo','Bar',nil,mw.title.new('Example')) ) end functionsuite:testMakeWikitextErrorManualCategorySuppression() self:assertEquals( '<strong class="error">Error: Foo.</strong>', mHatnote.makeWikitextError('Foo',nil,false,mw.title.new('Example')) ) end functionsuite:testMakeWikitextErrorTalkPageCategorySuppression() self:assertEquals( '<strong class="error">Error: Foo.</strong>', mHatnote.makeWikitextError('Foo',nil,nil,mw.title.new('Talk:Example')) ) end ------------------------------------------------------------------------------- -- hatnote tests ------------------------------------------------------------------------------- functionsuite:testHatnoteInputErrors() self:assertError(mHatnote._hatnote,9) self:assertError(mHatnote._hatnote) self:assertError(mHatnote._hatnote,'A page',9) end functionsuite:testHatnote() self:assertStringContains( '<div role="note" class="hatnote navigation%-not%-searchable">Foo</div>', mHatnote._hatnote('Foo') ) end functionsuite:testHatnoteSelfref() self:assertStringContains( '<div role="note" class="hatnote navigation%-not%-searchable selfref">Foo</div>', mHatnote._hatnote('Foo',{selfref=true}) ) end functionsuite:testHatnoteExtraClasses() self:assertStringContains( '<div role="note" class="hatnote navigation%-not%-searchable extraclass">Foo</div>', mHatnote._hatnote('Foo',{extraclasses='extraclass'}) ) end functionsuite:testHatnoteEntryPoint() self:assertParentFrameCallContains( '<div role="note" class="hatnote navigation%-not%-searchable">Foo</div>', mHatnote.hatnote, {'Foo'} ) end functionsuite:testHatnoteEntryPointSelfref() self:assertParentFrameCallContains( '<div role="note" class="hatnote navigation%-not%-searchable selfref">Foo</div>', mHatnote.hatnote, {'Foo',selfref='yes'} ) end functionsuite:testHatnoteEntryPointExtraClasses() self:assertParentFrameCallContains( '<div role="note" class="hatnote navigation%-not%-searchable extraclass">Foo</div>', mHatnote.hatnote, {'Foo',extraclasses='extraclass'} ) end returnsuite