Jump to content

Module:Disambiguation/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 11:46, 7 September 2023 (Use Module talk:Disambiguation instead of Template:Disambiguation for the frame object; the latter doesn't have any relation to Module:Disambiguation). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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

return suite