Module:Check DYK hook/testcases
| 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')
local ScribuntoUnit = require('Module:ScribuntoUnit')
-- Initialise test suite
local suite = ScribuntoUnit.new()
--------------------------------------------------------------------------------
-- Sandbox run
--------------------------------------------------------------------------------
function suite.runSandbox(...)
mCheckDYKHook = require('Module:Check DYK hook/sandbox')
return suite.run(...)
end
--------------------------------------------------------------------------------
-- Helper methods
--------------------------------------------------------------------------------
local function makeFrameWithArgs(args)
local frame = mw.getCurrentFrame()
return frame:newChild{args = args}
end
--------------------------------------------------------------------------------
-- Tests for p._isValidHook
--------------------------------------------------------------------------------
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
function suite:testIsValidHook_RaisesError_WhenHookIsNotAString()
self:assertThrows(
mCheckDYKHook._isValidHook,
"bad argument #1 to '_isValidHook' (string expected, got number)",
nil,
7
)
end
--------------------------------------------------------------------------------
-- Tests for p.isValidHook
--------------------------------------------------------------------------------
local templateTestData = {
{
testName = "testTemplateIsValidHook_ReturnsYes_ForHooksStartingWithThat",
args = {"... that foo bar baz?"},
expected = "yes",
},
{
testName = "testTemplateIsValidHook_ReturnsBlank_ForHooksStartingWithOtherWords",
args = {"... foo bar baz?"},
expected = "",
},
{
testName = "testTemplateIsValidHook_ReturnsYes_ForHooksWithWhitespace",
args = {"\n ... that foo bar baz? \n"},
expected = "yes",
},
{
testName = "testTemplateIsValidHook_ReturnsBlank_ForInvalidHooksWithWhitespace",
args = {"\n ... that foo bar baz \n"},
expected = "",
},
{
testName = "testTemplateIsValidHook_ReturnsYes_ForHooksEndingWithAQuestionMarkHTMLEncodedInsideASpan",
args = {'... that foo bar [[baz|<span class="something">baz?</span>]]'},
expected = "yes",
},
{
testName = "testTemplateIsValidHook_ReturnsYes_ForHooksEndingWithAQuestionMarkHTMLEncodedInsideASpanWithWhitespace",
args = {'\n ... that foo bar [[baz|<span class="something">baz?</span>]] \n'},
expected = "yes",
},
{
testName = "testTemplateIsValidHook_ReturnsYes_WhenCalledWithValidHookWithHookKeywordArgument",
args = {hook = "... that foo bar baz?"},
expected = "yes",
},
}
for _, testData in ipairs(templateTestData) do
suite[testData.testName] = function(self)
self:assertEquals(
mCheckDYKHook.isValidHook(makeFrameWithArgs(testData.args)),
testData.expected
)
end
end
function suite:testTemplateIsValidHook_RaisesError_WhenNoHookSupplied()
self:assertThrows(
mCheckDYKHook.isValidHook,
"No hook specified",
nil, makeFrameWithArgs{nil}
)
end
return suite
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.