Jump to content

Module:Disambiguation/testcases

From Wikipedia, the free encyclopedia
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 "{{disambiguation}}"',
		page = 'New',
		content = "'''New''' may refer to:\n...\n{{disambiguation}}\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{{Disambiguation|ship}}\n",
		expectedBool = true,
		expectedText = 'yes',
	},
	{
		description = 'content containing hndis templates with named parameters',
		page = 'Frederick II',
		content = "''Frederick II''' may refer to:\n...\n{{hndis|name=Frederick 02}}\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{{Mountainindex|Signal}}\n",
		expectedBool = false,
		expectedText = '',
	},
	{
		description = 'content containing "{{italic disambiguation}}"',
		page = 'Abby (The Last of Us)',
		content = "{{italic disambiguation}}\n'''Abigail''' \"'''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 = {
	'{{disambiguation}}',
	'{{ disambiguation }}',
	'{{Disambiguation}}',
	'{{ Disambiguation }}',
	'{{ disambiguation | foo }}',
	'{{ disambiguation | foo=bar }}',
	'{{ disambiguation | foo = bar }}',
	'{{DAB}}',
	'{{dab}}',
	'{{dabpage}}',
	'{{dbig}}',
	'{{dis}}',
	'{{disam}}',
	'{{disamb}}',
	'{{disambig}}',
	'{{disambig misspelling}}',
	'{{disambig-plants}}',
	'{{disambiguation page}}',
	'{{begriffsklärung}}',
	'{{meta disambig}}',
	'{{project disambiguation}}',
	'{{shortcut disambig}}',
	'{{WP disambig}}',
	'{{WP-disambig}}',
	'{{Wikipedia disambiguation}}',
	'{{Airport disambiguation}}',
	'{{Biology disambiguation}}',
	'{{Call sign disambiguation}}',
	'{{Caselaw disambiguation}}',
	'{{Chinese title disambiguation}}',
	'{{Disambiguation cleanup}}',
	'{{Genus disambiguation}}',
	'{{Hospital disambiguation}}',
	'{{Human name disambiguation}}',
	'{{Human name disambiguation cleanup}}',
	'{{Letter–number combination disambiguation}}',
	'{{Mathematical disambiguation}}',
	'{{Military unit disambiguation}}',
	'{{Music disambiguation}}',
	'{{Number disambiguation}}',
	'{{Opus number disambiguation}}',
	'{{Phonetics disambiguation}}',
	'{{Place name disambiguation}}',
	'{{Portal disambiguation}}',
	'{{Road disambiguation}}',
	'{{School disambiguation}}',
	'{{Species Latin name abbreviation disambiguation}}',
	'{{Species Latin name disambiguation}}',
	'{{Station disambiguation}}',
	'{{Synagogue disambiguation}}',
	'{{Taxonomic authority disambiguation}}',
	'{{Taxonomy disambiguation}}',
	'{{Template disambiguation}}',
	'{{WoO number disambiguation}}',
	'{{Airport disambig}}',
	'{{Callsigndis}}',
	'{{Case law disambiguation}}',
	'{{CJKVdab}}',
	'{{Disambig-Chinese-char-title}}',
	'{{Chinese title disambig}}',
	'{{Disamb-cleanup}}',
	'{{Cleanup disambig}}',
	'{{CleanupDisambig}}',
	'{{Dabclean}}',
	'{{Dab-cleanup}}',
	'{{Disambig-CU}}',
	'{{Disambig-cu}}',
	'{{Disambig cleanup}}',
	'{{Geodis-cleanup}}',
	'{{Disambig-cleanup}}',
	'{{Disambiguation-cleanup}}',
	'{{Disambcleanup}}',
	'{{Disambigcleanup}}',
	'{{Disambiguate-cleanup}}',
	'{{Dab cleanup}}',
	'{{Cleanup disambiguation}}',
	'{{Genus disambig}}',
	'{{Hospitaldis}}',
	'{{Bio-dab}}',
	'{{Hndisambig}}',
	'{{Hndab}}',
	'{{HnDis}}',
	'{{Personal name disambiguation}}',
	'{{HNDIS}}',
	'{{Hndis}}',
	'{{Personal name}}',
	'{{Human name dab}}',
	'{{Personal name disambiguation cleanup}}',
	'{{Hndis-cleanup}}',
	'{{Letter-NumberCombdisambig}}',
	'{{Letter-NumberCombinationDisambiguation}}',
	'{{LNCD}}',
	'{{Letter-Number combination disambiguation}}',
	'{{Letter-NumberCombDisambig}}',
	'{{Letter-Number Combination Disambiguation}}',
	'{{Letter-number combination disambiguation}}',
	'{{Mathematics disambiguation}}',
	'{{Mathdab}}',
	'{{Math dab}}',
	'{{Math disambiguation}}',
	'{{Maths disambiguation}}',
	'{{Mil-unit-disambig}}',
	'{{Mil-unit-dis}}',
	'{{Music disambig}}',
	'{{Numdisambig}}',
	'{{Numdab}}',
	'{{Numberdis}}',
	'{{Geodab}}',
	'{{Geo-dis}}',
	'{{Geodisambig}}',
	'{{Geodis}}',
	'{{DisambigG}}',
	'{{DisambigGeo}}',
	'{{Disambiggeo}}',
	'{{Geographic disambiguation}}',
	'{{Portal disambig}}',
	'{{Roaddis}}',
	'{{Schooldis}}',
	'{{Schooldab}}',
	'{{School disambig}}',
	'{{LatinNameDisambig}}',
	'{{SpeciesLatinNameDisambig}}',
	'{{Station dab}}',
	'{{Taxonomic authorities disambiguation}}',
	'{{Species disambiguation}}',
	'{{Template disambig}}',
	'{{Template dab}}',
	'{{Template ambiguous}}',
	'__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__',
	'{{}}',
	'{{ }}',
	'{{italic disambiguation}}',
	'{{Italic disambiguation}}',
	'{{ italic disambiguation }}',
	'{{ Italic disambiguation }}',
	'{{italic disambiguation|foo}}',
	'{{ italic disambiguation | 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