Module:Reply to/testcases: Difference between revisions
Appearance
Content deleted Content added
start test cases |
expand the test cases |
||
Line 4: | Line 4: | ||
local frame = mw.getCurrentFrame() |
local frame = mw.getCurrentFrame() |
||
-------------------------------------------------------------------------------- |
|||
-- Helper functions |
|||
-------------------------------------------------------------------------------- |
|||
local function makeFrameWithParentArgs(args) |
local function makeFrameWithParentArgs(args) |
||
Line 13: | Line 17: | ||
local function replyTo(args) |
local function replyTo(args) |
||
return mReplyTo.replyto(makeFrameWithParentArgs(args)) |
return mReplyTo.replyto(makeFrameWithParentArgs(args)) |
||
end |
|||
-- Returns an array of n unique strings. |
|||
local function makeNUniqueStrings(n) |
|||
local ret = {} |
|||
for i = 1, n do |
|||
ret[i] = tostring(i) |
|||
end |
|||
return ret |
|||
end |
|||
function suite:assertHtmlError(pattern, output) |
|||
pattern = '^<strong class="error">Error in %[%[Template:Reply to%]%]: ' .. pattern .. '.</strong>$' |
|||
self:assertStringContains(pattern, output) |
|||
end |
end |
||
Line 20: | Line 38: | ||
function suite:testNoUsernamesError() |
function suite:testNoUsernamesError() |
||
self: |
self:assertHtmlError('Username not given', replyTo{}) |
||
end |
|||
function suite:testInvalidUsernameError() |
|||
self:assertHtmlError('Input contains forbidden characters', replyTo{'Examp|le'}) |
|||
end |
|||
function suite:testTooManyUsernamesError() |
|||
self:assertHtmlError( |
|||
'More than %d+ names specified', |
|||
replyTo(makeNUniqueStrings(1000)) -- The limit is probably always going to be lower than 1000 |
|||
) |
|||
end |
|||
-------------------------------------------------------------------------------- |
|||
-- Test defaults |
|||
-------------------------------------------------------------------------------- |
|||
function suite:testOneUsername() |
|||
self:assertEquals( |
|||
'<span class="template-ping">@[[:User:Example|Example]]:</span>', |
|||
replyTo{'Example'} |
|||
) |
|||
end |
|||
function suite:testTwoUsernames() |
|||
self:assertEquals( |
|||
'<span class="template-ping">@[[:User:Example|Example]] and [[:User:Example2|Example2]]:</span>', |
|||
replyTo{'Example', 'Example2'} |
|||
) |
|||
end |
|||
function suite:testThreeUsernames() |
|||
self:assertEquals( |
|||
'<span class="template-ping">@[[:User:Example|Example]], [[:User:Example2|Example2]], and [[:User:Example3|Example3]]:</span>', |
|||
replyTo{'Example', 'Example2', 'Example3'} |
|||
) |
|||
end |
|||
function suite:testFourUsernames() |
|||
self:assertEquals( |
|||
'<span class="template-ping">@[[:User:Example|Example]], [[:User:Example2|Example2]], [[:User:Example3|Example3]], and [[:User:Example4|Example4]]:</span>', |
|||
replyTo{'Example', 'Example2', 'Example3', 'Example4'} |
|||
) |
|||
end |
end |
||
Revision as of 02:25, 29 November 2016
![]() | This is the test cases page for the module Module:Reply to. Results of the test cases. |
local mReplyTo = require('Module:Reply to') -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local frame = mw.getCurrentFrame()
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
local function makeFrameWithParentArgs(args)
local parent = frame:newChild{title = 'Template:Reply to', args = args}
local child = parent:newChild{title = 'Module:Reply to'}
return child
end
local function replyTo(args)
return mReplyTo.replyto(makeFrameWithParentArgs(args))
end
-- Returns an array of n unique strings.
local function makeNUniqueStrings(n)
local ret = {}
for i = 1, n do
ret[i] = tostring(i)
end
return ret
end
function suite:assertHtmlError(pattern, output)
pattern = '^<strong class="error">Error in %[%[Template:Reply to%]%]: ' .. pattern .. '.</strong>$'
self:assertStringContains(pattern, output)
end
--------------------------------------------------------------------------------
-- Error tests
--------------------------------------------------------------------------------
function suite:testNoUsernamesError()
self:assertHtmlError('Username not given', replyTo{})
end
function suite:testInvalidUsernameError()
self:assertHtmlError('Input contains forbidden characters', replyTo{'Examp|le'})
end
function suite:testTooManyUsernamesError()
self:assertHtmlError(
'More than %d+ names specified',
replyTo(makeNUniqueStrings(1000)) -- The limit is probably always going to be lower than 1000
)
end
--------------------------------------------------------------------------------
-- Test defaults
--------------------------------------------------------------------------------
function suite:testOneUsername()
self:assertEquals(
'<span class="template-ping">@[[:User:Example|Example]]:</span>',
replyTo{'Example'}
)
end
function suite:testTwoUsernames()
self:assertEquals(
'<span class="template-ping">@[[:User:Example|Example]] and [[:User:Example2|Example2]]:</span>',
replyTo{'Example', 'Example2'}
)
end
function suite:testThreeUsernames()
self:assertEquals(
'<span class="template-ping">@[[:User:Example|Example]], [[:User:Example2|Example2]], and [[:User:Example3|Example3]]:</span>',
replyTo{'Example', 'Example2', 'Example3'}
)
end
function suite:testFourUsernames()
self:assertEquals(
'<span class="template-ping">@[[:User:Example|Example]], [[:User:Example2|Example2]], [[:User:Example3|Example3]], and [[:User:Example4|Example4]]:</span>',
replyTo{'Example', 'Example2', 'Example3', 'Example4'}
)
end
return suite