Difference between revisions of "Module:Reply to/testcases"
Jump to navigation
Jump to search
blackwiki>Mr. Stradivarius (add label tests) |
blackwiki>Mr. Stradivarius (update tests with new link syntax and error messages) |
||
| Line 1: | Line 1: | ||
| − | local mReplyTo = require('Module:Reply to') -- the module to be tested | + | local mReplyTo = require('Module:Reply to/sandbox') -- the module to be tested |
local ScribuntoUnit = require('Module:ScribuntoUnit') | local ScribuntoUnit = require('Module:ScribuntoUnit') | ||
local suite = ScribuntoUnit:new() | local suite = ScribuntoUnit:new() | ||
| Line 42: | Line 42: | ||
function suite:testNoUsernamesError() | function suite:testNoUsernamesError() | ||
| − | self:assertHtmlError(' | + | self:assertHtmlError('No usernames given', replyTo{}) |
end | end | ||
function suite:testInvalidUsernameError() | function suite:testInvalidUsernameError() | ||
| − | self:assertHtmlError(' | + | self:assertHtmlError("'%S+' is not a valid username or user page", replyTo{'Examp|le'}) |
end | end | ||
| Line 62: | Line 62: | ||
function suite:testOneUsername() | function suite:testOneUsername() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Example]]:', |
replyTo{'Example'} | replyTo{'Example'} | ||
) | ) | ||
| Line 69: | Line 69: | ||
function suite:testTwoUsernames() | function suite:testTwoUsernames() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Example]] and [[User:Example2|Example2]]:', |
replyTo{'Example', 'Example2'} | replyTo{'Example', 'Example2'} | ||
) | ) | ||
| Line 76: | Line 76: | ||
function suite:testThreeUsernames() | function suite:testThreeUsernames() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Example]], [[User:Example2|Example2]], and [[User:Example3|Example3]]:', |
replyTo{'Example', 'Example2', 'Example3'} | replyTo{'Example', 'Example2', 'Example3'} | ||
) | ) | ||
| Line 83: | Line 83: | ||
function suite:testFourUsernames() | function suite:testFourUsernames() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Example]], [[User:Example2|Example2]], [[User:Example3|Example3]], and [[User:Example4|Example4]]:', |
replyTo{'Example', 'Example2', 'Example3', 'Example4'} | replyTo{'Example', 'Example2', 'Example3', 'Example4'} | ||
) | ) | ||
| Line 94: | Line 94: | ||
function suite:testLabel() | function suite:testLabel() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Foo]]:', |
replyTo{[1] = 'Example', label = 'Foo'} | replyTo{[1] = 'Example', label = 'Foo'} | ||
) | ) | ||
| Line 101: | Line 101: | ||
function suite:testLabel1() | function suite:testLabel1() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Foo]]:', |
replyTo{[1] = 'Example', label1 = 'Foo'} | replyTo{[1] = 'Example', label1 = 'Foo'} | ||
) | ) | ||
| Line 108: | Line 108: | ||
function suite:testTwoLabels() | function suite:testTwoLabels() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Foo]] and [[User:Example2|Bar]]:', |
replyTo{[1] = 'Example', label1 = 'Foo', [2] = 'Example2', label2 = 'Bar'} | replyTo{[1] = 'Example', label1 = 'Foo', [2] = 'Example2', label2 = 'Bar'} | ||
) | ) | ||
| Line 115: | Line 115: | ||
function suite:testThreeLabels() | function suite:testThreeLabels() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Foo]], [[User:Example2|Bar]], and [[User:Example3|Baz]]:', |
replyTo{[1] = 'Example', label1 = 'Foo', [2] = 'Example2', label2 = 'Bar', [3] = 'Example3', label3 = 'Baz'} | replyTo{[1] = 'Example', label1 = 'Foo', [2] = 'Example2', label2 = 'Bar', [3] = 'Example3', label3 = 'Baz'} | ||
) | ) | ||
| Line 126: | Line 126: | ||
function suite:testPrefix() | function suite:testPrefix() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | 'foo[[ | + | 'foo[[User:Example|Example]]:', |
replyTo{'Example', prefix = 'foo'} | replyTo{'Example', prefix = 'foo'} | ||
) | ) | ||
| Line 133: | Line 133: | ||
function suite:testBlankPrefix() | function suite:testBlankPrefix() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '[[ | + | '[[User:Example|Example]]:', |
replyTo{'Example', prefix = ''} | replyTo{'Example', prefix = ''} | ||
) | ) | ||
| Line 140: | Line 140: | ||
function suite:testConjunction() | function suite:testConjunction() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Example]], [[User:Example2|Example2]], foo [[User:Example3|Example3]]:', |
replyTo{'Example', 'Example2', 'Example3', c = 'foo'} | replyTo{'Example', 'Example2', 'Example3', c = 'foo'} | ||
) | ) | ||
| Line 147: | Line 147: | ||
function suite:testBlankConjunction() | function suite:testBlankConjunction() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Example]], [[User:Example2|Example2]], [[User:Example3|Example3]]:', |
replyTo{'Example', 'Example2', 'Example3', c = ''} | replyTo{'Example', 'Example2', 'Example3', c = ''} | ||
) | ) | ||
| Line 154: | Line 154: | ||
function suite:testPunctuation() | function suite:testPunctuation() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Example]]foo', |
replyTo{'Example', p = 'foo'} | replyTo{'Example', p = 'foo'} | ||
) | ) | ||
| Line 161: | Line 161: | ||
function suite:testBlankPunctuation() | function suite:testBlankPunctuation() | ||
self:assertContentEquals( | self:assertContentEquals( | ||
| − | '@[[ | + | '@[[User:Example|Example]]', |
replyTo{'Example', p = ''} | replyTo{'Example', p = ''} | ||
) | ) | ||
Revision as of 07:13, 29 November 2016
Documentation for this module may be created at Module:Reply to/testcases/doc
local mReplyTo = require('Module:Reply to/sandbox') -- 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
function suite:assertContentEquals(expected, actual)
expected = '<span class="template-ping">' .. expected .. '</span>'
self:assertEquals(expected, actual)
end
--------------------------------------------------------------------------------
-- Error tests
--------------------------------------------------------------------------------
function suite:testNoUsernamesError()
self:assertHtmlError('No usernames given', replyTo{})
end
function suite:testInvalidUsernameError()
self:assertHtmlError("'%S+' is not a valid username or user page", 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:assertContentEquals(
'@[[User:Example|Example]]:',
replyTo{'Example'}
)
end
function suite:testTwoUsernames()
self:assertContentEquals(
'@[[User:Example|Example]] and [[User:Example2|Example2]]:',
replyTo{'Example', 'Example2'}
)
end
function suite:testThreeUsernames()
self:assertContentEquals(
'@[[User:Example|Example]], [[User:Example2|Example2]], and [[User:Example3|Example3]]:',
replyTo{'Example', 'Example2', 'Example3'}
)
end
function suite:testFourUsernames()
self:assertContentEquals(
'@[[User:Example|Example]], [[User:Example2|Example2]], [[User:Example3|Example3]], and [[User:Example4|Example4]]:',
replyTo{'Example', 'Example2', 'Example3', 'Example4'}
)
end
--------------------------------------------------------------------------------
-- Test labels
--------------------------------------------------------------------------------
function suite:testLabel()
self:assertContentEquals(
'@[[User:Example|Foo]]:',
replyTo{[1] = 'Example', label = 'Foo'}
)
end
function suite:testLabel1()
self:assertContentEquals(
'@[[User:Example|Foo]]:',
replyTo{[1] = 'Example', label1 = 'Foo'}
)
end
function suite:testTwoLabels()
self:assertContentEquals(
'@[[User:Example|Foo]] and [[User:Example2|Bar]]:',
replyTo{[1] = 'Example', label1 = 'Foo', [2] = 'Example2', label2 = 'Bar'}
)
end
function suite:testThreeLabels()
self:assertContentEquals(
'@[[User:Example|Foo]], [[User:Example2|Bar]], and [[User:Example3|Baz]]:',
replyTo{[1] = 'Example', label1 = 'Foo', [2] = 'Example2', label2 = 'Bar', [3] = 'Example3', label3 = 'Baz'}
)
end
--------------------------------------------------------------------------------
-- Test special formatting
--------------------------------------------------------------------------------
function suite:testPrefix()
self:assertContentEquals(
'foo[[User:Example|Example]]:',
replyTo{'Example', prefix = 'foo'}
)
end
function suite:testBlankPrefix()
self:assertContentEquals(
'[[User:Example|Example]]:',
replyTo{'Example', prefix = ''}
)
end
function suite:testConjunction()
self:assertContentEquals(
'@[[User:Example|Example]], [[User:Example2|Example2]], foo [[User:Example3|Example3]]:',
replyTo{'Example', 'Example2', 'Example3', c = 'foo'}
)
end
function suite:testBlankConjunction()
self:assertContentEquals(
'@[[User:Example|Example]], [[User:Example2|Example2]], [[User:Example3|Example3]]:',
replyTo{'Example', 'Example2', 'Example3', c = ''}
)
end
function suite:testPunctuation()
self:assertContentEquals(
'@[[User:Example|Example]]foo',
replyTo{'Example', p = 'foo'}
)
end
function suite:testBlankPunctuation()
self:assertContentEquals(
'@[[User:Example|Example]]',
replyTo{'Example', p = ''}
)
end
return suite