Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Check DYK hook/testcases
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- Load necessary modules local mCheckDYKHook = require('Module:Check DYK hook/sandbox') local ScribuntoUnit = require('Module:ScribuntoUnit') -- Initialise test suite local suite = ScribuntoUnit:new() -------------------------------------------------------------------------------- -- Helper methods -------------------------------------------------------------------------------- local function makeFrameWithArgs(args) local frame = mw.getCurrentFrame() return frame:newChild{args = args} end function suite:assertErrorMessageContains(func, expectedMessage) local success, actualMessage = pcall(func) self:assertFalse(success) self:assertStringContains(expectedMessage, actualMessage, true) 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:assertErrorMessageContains( function () mCheckDYKHook._isValidHook(7) end, "bad argument #1 to '_isValidHook' (string expected, got number)" ) 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:assertErrorMessageContains( function () mCheckDYKHook.isValidHook(makeFrameWithArgs{nil}) end, "No hook specified" ) end return suite
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Check DYK hook/testcases/doc
(
edit
)