Module:Check DYK hook/testcases
Appearance
![]() | This is the test cases page for the module Module:Check DYK hook. Results of the test cases. |
-- Load necessary modules
local mCheckDYKHook = require('Module:Check DYK hook/sandbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')
-- Initialise test suite
local suite = ScribuntoUnit:new()
local moduleTestData = {
{
testName = "testIsValidHook_ReturnsTrue_ForHooksStartingWithThat",
hook = "... that foo bar baz?",
expected = true,
},
{
testName = "testIsValidHook_ReturnsTrue_ForHooksStartingWithAbout",
hook = "... about the foo bar baz?",
expected = true,
},
{
testName = "testIsValidHook_ReturnsFalse_ForHooksStartingWithOtherWords",
hook = "... foo bar baz?",
expected = false,
},
{
testName = "testIsValidHook_ReturnsTrue_ForHooksEndingWithAQuestionMark",
hook = "... that foo bar baz?",
expected = true,
},
{
testName = "testIsValidHook_ReturnsTrue_ForHooksEndingWithAQuestionMarkHTMLEncodedInsideASpan",
hook = '... that foo bar [[baz|<span class="something">baz?</span>]]',
expected = true,
},
{
testName = "testIsValidHook_ReturnsTrue_ForHooksEndingWithYouProbablyDid",
hook = '... that foo bar baz? You probably did...',
expected = true,
},
{
testName = "testIsValidHook_ReturnsFalse_ForHooksNotEndingInAQuestionMark",
hook = '... that foo bar baz',
expected = false,
},
}
for _, testData in ipairs(moduleTestData) do
suite[testData.testName] = function(self)
local result = mCheckDYKHook._isValidHook(testData.hook)
if testData.expected then
self:assertTrue(result)
else
self:assertFalse(result)
end
end
end
local templateTestData = {
{
testName = "testTemplateIsValidHook_ReturnsYes_ForHooksStartingWithThat",
hook = "... that foo bar baz?",
expected = "yes",
},
{
testName = "testTemplateIsValidHook_ReturnsBlank_ForHooksStartingWithOtherWords",
hook = "... foo bar baz?",
expected = "",
},
{
testName = "testTemplateIsValidHook_ReturnsYes_ForHooksWithWhitespace",
hook = " ... that foo bar baz? \n",
expected = "yes",
},
{
testName = "testTemplateIsValidHook_ReturnsBlank_ForInvalidHooksWithWhitespace",
hook = "\n ... that foo bar baz \n",
expected = "",
},
{
testName = "testTemplateIsValidHook_ReturnsYes_ForHooksEndingWithAQuestionMarkHTMLEncodedInsideASpan",
hook = '... that foo bar [[baz|<span class="something">baz?</span>]]',
expected = "yes",
},
{
testName = "testTemplateIsValidHook_ReturnsYes_ForHooksEndingWithAQuestionMarkHTMLEncodedInsideASpanWithWhitespace",
hook = '\n ... that foo bar [[baz|<span class="something">baz?</span>]] \n',
expected = "yes",
},
}
for _, testData in ipairs(templateTestData) do
suite[testData.testName] = function(self)
local frame = mw.getCurrentFrame()
local child = frame:newChild{args = {testData.hook}}
self:assertEquals(mCheckDYKHook.isValidHook(child), testData.expected)
end
end
return suite