local libName = 'Module:Reply to'local ScribuntoUnit = require('Module:ScribuntoUnit')local suite = ScribuntoUnit:newlocal frame = mw.getCurrentFrame
-- Helper to run all tests using sandbox version of the library from the debug console. To run against main lib, use =p.runfunction suite.runSandbox return suite.run(frame:newChild)end
-- Allow test runner to use both the main library and the sandbox of the library with the same testcasesfunction suite:module return self.frame and self.frame.args.module or libNameend
---------------------------------------------------------------------------------- Helper functions--------------------------------------------------------------------------------
local function makeFrameWithParentArgs(args) local parent = frame:newChild local child = parent:newChild return childend
local function replyTo(args) return require(suite:module).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 retend
function suite:assertHtmlError(pattern, output) pattern = '^Error in %[%[Template:Reply to%]%]: ' .. pattern .. '.$' self:assertStringContains(pattern, output)end
function suite:assertContentEquals(expected, actual) expected = '
' .. expected .. '' self:assertEquals(mw.text.trim(expected), mw.text.trim(actual))end---------------------------------------------------------------------------------- Error tests--------------------------------------------------------------------------------
function suite:testNoUsernamesError self:assertHtmlError('Username not given', replyTo)end
function suite:testInvalidUsernameError self:assertHtmlError("Input contains forbidden characters", replyTo)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('@Example:', replyTo )end
function suite:testTwoUsernames self:assertContentEquals('@Example and Example2:', replyTo )end
function suite:testThreeUsernames self:assertContentEquals('@Example, Example2, and Example3:', replyTo )end
function suite:testFourUsernames self:assertContentEquals('@Example, Example2, Example3, and Example4:', replyTo )end
---------------------------------------------------------------------------------- Test labels--------------------------------------------------------------------------------
function suite:testLabel self:assertContentEquals('@Foo:', replyTo )end
function suite:testLabel1 self:assertContentEquals('@Foo:', replyTo )end
function suite:testTwoLabels self:assertContentEquals('@Foo and Bar:', replyTo )end
function suite:testThreeLabels self:assertContentEquals('@Foo, Bar, and Baz:', replyTo )end
---------------------------------------------------------------------------------- Test special formatting--------------------------------------------------------------------------------
function suite:testPrefix self:assertContentEquals('fooExample:', replyTo )end
function suite:testBlankPrefix self:assertContentEquals('Example:', replyTo )end
function suite:testConjunction self:assertContentEquals('@Example, Example2, foo Example3:', replyTo )end
function suite:testBlankConjunction self:assertContentEquals('@Example, Example2, Example3:', replyTo )end
function suite:testPunctuation self:assertContentEquals('@Examplefoo', replyTo )end
function suite:testBlankPunctuation self:assertContentEquals('@Example', replyTo )end
---------------------------------------------------------------------------------- Test non-standard parameter orders--------------------------------------------------------------------------------
function suite:testNoFirstParam self:assertContentEquals('@Example:', replyTo )end
function suite:testNoFirstParamWithLabel self:assertContentEquals('@Example:', replyTo )end
function suite:testNoFirstParamWithLabel2 self:assertContentEquals('@Foo:', replyTo )end
return suite