Module:Disambiguation/testcases

local mDab = require('Module:Disambiguation/sandbox') local ScribuntoUnit = require('Module:ScribuntoUnit') local mMockTitle = require('Module:Mock title') local suite = ScribuntoUnit:new

local dabPageTestData = { {		description = 'content containing ""', page = 'New', content = "New may refer to:\n...\n\n", expectedBool = true, expectedText = 'yes', },	{		description = 'content not containing a dab template', page = 'Paris', content = "Paris is the capital and most populous city of France.\n", expectedBool = false, expectedText = '', },	{		description = 'content containing disambiguation templates with parameters', page = 'Black Swan (disambiguation)', content = "Black swan is the common name for an Australasian waterfowl.\n...\n\n", expectedBool = true, expectedText = 'yes', },	{		description = 'content containing hndis templates with named parameters', page = 'Frederick II', content = "Frederick II' may refer to:\n...\n\n", expectedBool = true, expectedText = 'yes', },	{		description = 'content containing mountainindex set index templates with parameters', page = 'List of peaks named Signal', content = "A signal mountain is a mountain suited to sending and receiving visual signals\n...\n\n", expectedBool = false, expectedText = '', },	{		description = 'content containing ""', page = 'Abby (The Last of Us)', content = "\nAbigail \"Abby\" Anderson is a character in the video game The Last of Us Part II.\n", expectedBool = false, expectedText = '', }, }

for _, data in ipairs(dabPageTestData) do	mMockTitle.registerMockTitle{title = data.page, content = data.content}

suite[string.format(		"test isDisambiguation: %s returns %s",		data.description,		tostring(data.expectedBool)	)] = function (suite) suite:assertEquals(data.expectedBool, mDab.isDisambiguation(data.content)) end

suite[string.format(		"test _isDisambiguationPage: %s returns %s",		data.description,		tostring(data.expectedBool)	)] = function (suite) local actual = mMockTitle.patchTitleConstructors(			mDab._isDisambiguationPage,			data.page		) suite:assertEquals(data.expectedBool, actual) end

suite[string.format(		'test isDisambiguationPage: %s returns "%s"',		data.description,		data.expectedText	)] = function (suite) local frame = mw.getCurrentFrame:newChild{ title = 'Module talk:Disambiguation', args = {data.page}, }		local actual = mMockTitle.patchTitleConstructors(			mDab.isDisambiguationPage,			frame		) suite:assertEquals(data.expectedText, actual) end end

local dabContent = { ,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	,	'__DISAMBIG__' }

for _, content in ipairs(dabContent) do	suite[string.format(		'test isDisambiguation: content containing "%s" returns true',		content	)] = function (suite) suite:assertTrue(mDab.isDisambiguation(content)) end end

local nonDabContent = { 'just some text', '__FOO__', ' – ',	,	,	,	,	,	,	'', }

for _, content in ipairs(nonDabContent) do	suite[string.format(		'test isDisambiguation: content containing "%s" returns false',		content	)] = function (suite) suite:assertFalse(mDab.isDisambiguation(content)) end end

return suite