fbpx
วิกิพีเดีย

มอดูล:Hatnote/testcases

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, ...)  self:assertFalse(success) end  function suite:assertNotEquals(expected, actual)  self:assertTrue(expected ~= actual) end  function suite:assertParentFrameCallEquals(expected, func, args)  args = args or {}  local current = mw.getCurrentFrame()  local parent = current:newChild{title = 'Parent', args = args}  local child = parent:newChild{title = 'Child'}  self:assertEquals(expected, func(child)) end  function suite:assertParentFrameCallContains(expected, func, args)  args = args or {}  local current = mw.getCurrentFrame()  local parent = current:newChild{title = 'Parent', args = args}  local child = parent:newChild{title = 'Child'}  self:assertStringContains(expected, func(child)) 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()  self:assertEquals(  '<strong class="error">Error: Foo.</strong>[[หมวดหมู่:Hatnote templates with errors]]',  mHatnote.makeWikitextError('Foo', nil, nil, mw.title.new('Example'))  ) end  function suite:testMakeWikitextErrorHelpLink()  self:assertEquals(  '<strong class="error">Error: Foo ([[Bar|help]]).</strong>[[หมวดหมู่:Hatnote templates with errors]]',  mHatnote.makeWikitextError('Foo', 'Bar', nil, mw.title.new('Example'))  ) end  function suite:testMakeWikitextErrorManualCategorySuppression()  self:assertEquals(  '<strong class="error">Error: Foo.</strong>',  mHatnote.makeWikitextError('Foo', nil, false, mw.title.new('Example'))  ) end  function suite:testMakeWikitextErrorTalkPageCategorySuppression()  self:assertEquals(  '<strong class="error">Error: Foo.</strong>',  mHatnote.makeWikitextError('Foo', nil, nil, mw.title.new('Talk:Example'))  ) end  ------------------------------------------------------------------------------- -- formatLink tests -------------------------------------------------------------------------------  function suite:testFormatLink()  self:assertEquals('[[:Foo]]', mHatnote._formatLink{link = 'Foo'}) end  function suite:testFormatLinkColonHandling()  self:assertEquals(  '[[:Category:Foo]]',  mHatnote._formatLink{link = ':Category:Foo'}  ) end  function suite:testFormatLinkSectionLinking()  self:assertEquals(  '[[:Foo#Bar|Foo §&nbsp;Bar]]',  mHatnote._formatLink{link = 'Foo#Bar'}  ) end  function suite:testFormatLinkPipeHandling()  self:assertEquals('[[:Foo|Bar]]', mHatnote._formatLink{link = 'Foo|Bar'}) end  function suite:testFormatLinkDisplay()  self:assertEquals(  '[[:Foo|Bar]]',  mHatnote._formatLink{link = 'Foo', display = 'Bar'}  ) end  function suite:testFormatLinkDisplayOverwritesManualPiping()  self:assertEquals(  '[[:Foo|Baz]]',  mHatnote._formatLink{link = 'Foo|Bar', display = 'Baz'}  ) end  function suite:testFormatLinkPageItalicization()  self:assertEquals(  "[[:Foo|<i>Foo</i>]]",  mHatnote._formatLink{link = 'Foo', italicizePage = true}  ) end  function suite:testFormatLinkPageItalicizationWithSection()  self:assertEquals(  "[[:Foo#Bar|<i>Foo</i> §&nbsp;Bar]]",  mHatnote._formatLink{link = 'Foo#Bar', italicizePage = true}  ) end  function suite:testFormatLinkSectionItalicization()  self:assertEquals(  "[[:Foo#Bar|Foo §&nbsp;<i>Bar</i>]]",  mHatnote._formatLink{link = 'Foo#Bar', italicizeSection = true}  ) end  function suite:testFormatLinkPageItalicizationIsOverwrittenByDisplay()  self:assertEquals(  "[[:Foo#Bar|Baz]]",  mHatnote._formatLink{  link = 'Foo#Bar',  display = 'Baz',  italicizePage = true,  }  ) end  function suite:testFormatLinkSectionItalicizationIsOverwrittenByDisplay()  self:assertEquals(  "[[:Foo#Bar|Baz]]",  mHatnote._formatLink{  link = 'Foo#Bar',  display = 'Baz',  italicizeSection = true,  }  ) end  function suite:testFormatLinkItalicizationIsOverwrittenByManualPiping()  self:assertEquals(  "[[:Foo#Bar|Baz]]",  mHatnote._formatLink{  link = 'Foo#Bar|Baz',  italicizePage = true,  italicizeSection = true,  }  ) end  function suite:testFormatLinkWithSectionOnlyLink()  self:assertEquals(  "[[:#Section|§&nbsp;Section]]",  mHatnote._formatLink{  link = '#Section',  }  ) end  function suite:testFormatLinkWithSectionOnlyLinkAndItalicizedSection()  self:assertEquals(  "[[:#Section|§&nbsp;<i>Section</i>]]",  mHatnote._formatLink{  link = '#Section',  italicizeSection = true,  }  ) end  function suite:testFormatLinkWithSectionOnlyLinkAndItalicizedPage()  self:assertEquals(  "[[:#Section|§&nbsp;Section]]",  mHatnote._formatLink{  link = '#Section',  italicizePage=true,  }  ) end  function suite:testFormatLinkEntryPoint()  self:assertParentFrameCallEquals('[[:Foo]]', mHatnote.formatLink, {'Foo'})  self:assertParentFrameCallEquals(  '[[:Foo|Bar]]',  mHatnote.formatLink, {'Foo', 'Bar'}  )  self:assertParentFrameCallEquals(  "[[:Foo#Bar|<i>Foo</i> §&nbsp;<i>Bar</i>]]",  mHatnote.formatLink,  {'Foo#Bar', italicizepage="yes", italicizesection="yes"}  )  self:assertParentFrameCallEquals(  "[[:Foo#Bar|Foo §&nbsp;Bar]]",  mHatnote.formatLink,  {'Foo#Bar', italicizepage="no", italicizesection="no"}  ) end  ------------------------------------------------------------------------------- -- hatnote tests -------------------------------------------------------------------------------  function suite:testHatnoteInputErrors()  self:assertError(mHatnote._hatnote, 9)  self:assertError(mHatnote._hatnote)  self:assertError(mHatnote._hatnote, 'A page', 9) end  function suite:testHatnote()  self:assertStringContains(  '<div role="note" class="hatnote navigation%-not%-searchable">Foo</div>',  mHatnote._hatnote('Foo')  ) end  function suite:testHatnoteSelfref()  self:assertStringContains(  '<div role="note" class="hatnote navigation%-not%-searchable selfref">Foo</div>',  mHatnote._hatnote('Foo', {selfref = true})  ) end  function suite:testHatnoteExtraClasses()  self:assertStringContains(  '<div role="note" class="hatnote navigation%-not%-searchable extraclass">Foo</div>',  mHatnote._hatnote('Foo', {extraclasses = 'extraclass'})  ) end  function suite:testHatnoteEntryPoint()  self:assertParentFrameCallContains(  '<div role="note" class="hatnote navigation%-not%-searchable">Foo</div>',  mHatnote.hatnote,  {'Foo'}  ) end  function suite:testHatnoteEntryPointSelfref()  self:assertParentFrameCallContains(  '<div role="note" class="hatnote navigation%-not%-searchable selfref">Foo</div>',  mHatnote.hatnote,  {'Foo', selfref = 'yes'}  ) end  function suite:testHatnoteEntryPointExtraClasses()  self:assertParentFrameCallContains(  '<div role="note" class="hatnote navigation%-not%-searchable extraclass">Foo</div>',  mHatnote.hatnote,  {'Foo', extraclasses = 'extraclass'}  ) end  return suite 

มอด, hatnote, testcases, อหน, าช, ดทดสอบของมอด, มอด, hatnote, ผลล, พธ, ของช, ดทดสอบlocal, mhatnote, require, module, hatnote, sandbox, module, tested, local, scribuntounit, require, module, scribuntounit, local, suite, scribuntounit, function, suite, asserterr. nikhuxhnachudthdsxbkhxngmxdul mxdul Hatnote phllphthkhxngchudthdsxblocal 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 self assertFalse success end function suite assertNotEquals expected actual self assertTrue expected actual end function suite assertParentFrameCallEquals expected func args args args or local current mw getCurrentFrame local parent current newChild title Parent args args local child parent newChild title Child self assertEquals expected func child end function suite assertParentFrameCallContains expected func args args args or local current mw getCurrentFrame local parent current newChild title Parent args args local child parent newChild title Child self assertStringContains expected func child 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 self assertEquals lt strong class error gt Error Foo lt strong gt hmwdhmu Hatnote templates with errors mHatnote makeWikitextError Foo nil nil mw title new Example end function suite testMakeWikitextErrorHelpLink self assertEquals lt strong class error gt Error Foo Bar help lt strong gt hmwdhmu Hatnote templates with errors mHatnote makeWikitextError Foo Bar nil mw title new Example end function suite testMakeWikitextErrorManualCategorySuppression self assertEquals lt strong class error gt Error Foo lt strong gt mHatnote makeWikitextError Foo nil false mw title new Example end function suite testMakeWikitextErrorTalkPageCategorySuppression self assertEquals lt strong class error gt Error Foo lt strong gt mHatnote makeWikitextError Foo nil nil mw title new Talk Example end formatLink tests function suite testFormatLink self assertEquals Foo mHatnote formatLink link Foo end function suite testFormatLinkColonHandling self assertEquals Category Foo mHatnote formatLink link Category Foo end function suite testFormatLinkSectionLinking self assertEquals Foo Bar Foo amp nbsp Bar mHatnote formatLink link Foo Bar end function suite testFormatLinkPipeHandling self assertEquals Foo Bar mHatnote formatLink link Foo Bar end function suite testFormatLinkDisplay self assertEquals Foo Bar mHatnote formatLink link Foo display Bar end function suite testFormatLinkDisplayOverwritesManualPiping self assertEquals Foo Baz mHatnote formatLink link Foo Bar display Baz end function suite testFormatLinkPageItalicization self assertEquals Foo lt i gt Foo lt i gt mHatnote formatLink link Foo italicizePage true end function suite testFormatLinkPageItalicizationWithSection self assertEquals Foo Bar lt i gt Foo lt i gt amp nbsp Bar mHatnote formatLink link Foo Bar italicizePage true end function suite testFormatLinkSectionItalicization self assertEquals Foo Bar Foo amp nbsp lt i gt Bar lt i gt mHatnote formatLink link Foo Bar italicizeSection true end function suite testFormatLinkPageItalicizationIsOverwrittenByDisplay self assertEquals Foo Bar Baz mHatnote formatLink link Foo Bar display Baz italicizePage true end function suite testFormatLinkSectionItalicizationIsOverwrittenByDisplay self assertEquals Foo Bar Baz mHatnote formatLink link Foo Bar display Baz italicizeSection true end function suite testFormatLinkItalicizationIsOverwrittenByManualPiping self assertEquals Foo Bar Baz mHatnote formatLink link Foo Bar Baz italicizePage true italicizeSection true end function suite testFormatLinkWithSectionOnlyLink self assertEquals Section amp nbsp Section mHatnote formatLink link Section end function suite testFormatLinkWithSectionOnlyLinkAndItalicizedSection self assertEquals Section amp nbsp lt i gt Section lt i gt mHatnote formatLink link Section italicizeSection true end function suite testFormatLinkWithSectionOnlyLinkAndItalicizedPage self assertEquals Section amp nbsp Section mHatnote formatLink link Section italicizePage true end function suite testFormatLinkEntryPoint self assertParentFrameCallEquals Foo mHatnote formatLink Foo self assertParentFrameCallEquals Foo Bar mHatnote formatLink Foo Bar self assertParentFrameCallEquals Foo Bar lt i gt Foo lt i gt amp nbsp lt i gt Bar lt i gt mHatnote formatLink Foo Bar italicizepage yes italicizesection yes self assertParentFrameCallEquals Foo Bar Foo amp nbsp Bar mHatnote formatLink Foo Bar italicizepage no italicizesection no end hatnote tests function suite testHatnoteInputErrors self assertError mHatnote hatnote 9 self assertError mHatnote hatnote self assertError mHatnote hatnote A page 9 end function suite testHatnote self assertStringContains lt div role note class hatnote navigation not searchable gt Foo lt div gt mHatnote hatnote Foo end function suite testHatnoteSelfref self assertStringContains lt div role note class hatnote navigation not searchable selfref gt Foo lt div gt mHatnote hatnote Foo selfref true end function suite testHatnoteExtraClasses self assertStringContains lt div role note class hatnote navigation not searchable extraclass gt Foo lt div gt mHatnote hatnote Foo extraclasses extraclass end function suite testHatnoteEntryPoint self assertParentFrameCallContains lt div role note class hatnote navigation not searchable gt Foo lt div gt mHatnote hatnote Foo end function suite testHatnoteEntryPointSelfref self assertParentFrameCallContains lt div role note class hatnote navigation not searchable selfref gt Foo lt div gt mHatnote hatnote Foo selfref yes end function suite testHatnoteEntryPointExtraClasses self assertParentFrameCallContains lt div role note class hatnote navigation not searchable extraclass gt Foo lt div gt mHatnote hatnote Foo extraclasses extraclass end return suite ekhathungcak https th wikipedia org w index php title mxdul Hatnote testcases amp oldid 9751865, wikipedia, วิกิ หนังสือ, หนังสือ, ห้องสมุด,

บทความ

, อ่าน, ดาวน์โหลด, ฟรี, ดาวน์โหลดฟรี, mp3, วิดีโอ, mp4, 3gp, jpg, jpeg, gif, png, รูปภาพ, เพลง, เพลง, หนัง, หนังสือ, เกม, เกม