Jump to content

Module:Check DYK hook/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 13:25, 25 October 2020 (add an underscore to the function name). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Load necessary modules
local mCheckDYKHook = require('Module:Check DYK hook/sandbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')

-- Initialise test suite
local suite = ScribuntoUnit:new()

local testData = {
	{
		testName = "testCheckHook_ReturnsTrue_ForHooksStartingWithThat",
		dykText = "... that foo bar baz?",
		shouldBeValid = true,
	},
	{
		testName = "testCheckHook_ReturnsTrue_ForHooksStartingWithAbout",
		dykText = "... about the foo bar baz?",
		shouldBeValid = true,
	},
	{
		testName = "testCheckHook_ReturnsFalse_ForHooksStartingWithOtherWords",
		dykText = "... foo bar baz?",
		shouldBeValid = false,
	},
	{
		testName = "testCheckHook_ReturnsTrue_ForHooksEndingWithAQuestionMark",
		dykText = "... that foo bar baz?",
		shouldBeValid = true,
	},
	{
		testName = "testCheckHook_ReturnsTrue_ForHooksEndingWithAQuestionMarkHTMLEncodedInsideALink",
		dykText = '... that foo bar [[baz|<span class="something">baz&#63;</span>]]',
		shouldBeValid = true,
	},
	{
		testName = "testCheckHook_ReturnsTrue_ForHooksEndingWithYouProbablyDid",
		dykText = '... that foo bar baz? You probably did...',
		shouldBeValid = true,
	},
	{
		testName = "testCheckHook_ReturnsFalse_ForHooksNotEndingInAQuestionMark",
		dykText = '... that foo bar baz',
		shouldBeValid = false,
	},
}

for _, individualTestData in ipairs(testData) do
	suite[individualTestData.testName] = function(self)
		local result = mCheckDYKHook._isValidHook(individualTestData.dykText)
		if individualTestData.shouldBeValid then
			self:assertTrue(result)
		else
			self:assertFalse(result)
		end
	end
end

return suite