请输入您要查询的百科知识:

 

词条 Module:Reply to/testcases
释义

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 = '^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()

end

function suite:testInvalidUsernameError()

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{'Example'}

)

end

function suite:testTwoUsernames()

self:assertContentEquals(

'@Example and Example2:',

replyTo{'Example', 'Example2'}

)

end

function suite:testThreeUsernames()

self:assertContentEquals(

'@Example, Example2, and Example3:',

replyTo{'Example', 'Example2', 'Example3'}

)

end

function suite:testFourUsernames()

self:assertContentEquals(

'@Example, Example2, Example3, and Example4:',

replyTo{'Example', 'Example2', 'Example3', 'Example4'}

)

end


-- Test labels

function suite:testLabel()

self:assertContentEquals(

'@Foo:',

replyTo{[1] = 'Example', label = 'Foo'}

)

end

function suite:testLabel1()

self:assertContentEquals(

'@Foo:',

replyTo{[1] = 'Example', label1 = 'Foo'}

)

end

function suite:testTwoLabels()

self:assertContentEquals(

'@Foo and Bar:',

replyTo{[1] = 'Example', label1 = 'Foo', [2] = 'Example2', label2 = 'Bar'}

)

end

function suite:testThreeLabels()

self:assertContentEquals(

'@Foo, Bar, and Baz:',

replyTo{[1] = 'Example', label1 = 'Foo', [2] = 'Example2', label2 = 'Bar', [3] = 'Example3', label3 = 'Baz'}

)

end


-- Test special formatting

function suite:testPrefix()

self:assertContentEquals(

'fooExample:',

replyTo{'Example', prefix = 'foo'}

)

end

function suite:testBlankPrefix()

self:assertContentEquals(

'Example:',

replyTo{'Example', prefix = }

)

end

function suite:testConjunction()

self:assertContentEquals(

'@Example, Example2, foo Example3:',

replyTo{'Example', 'Example2', 'Example3', c = 'foo'}

)

end

function suite:testBlankConjunction()

self:assertContentEquals(

'@Example, Example2, Example3:',

replyTo{'Example', 'Example2', 'Example3', c = }

)

end

function suite:testPunctuation()

self:assertContentEquals(

'@Examplefoo',

replyTo{'Example', p = 'foo'}

)

end

function suite:testBlankPunctuation()

self:assertContentEquals(

'@Example',

replyTo{'Example', p = }

)

end


-- Test non-standard parameter orders

function suite:testNoFirstParam()

self:assertContentEquals(

'@Example:',

replyTo{[2] = 'Example'}

)

end

function suite:testNoFirstParamWithLabel()

self:assertContentEquals(

'@Example:',

replyTo{[2] = 'Example', label = 'Foo'}

)

end

function suite:testNoFirstParamWithLabel2()

self:assertContentEquals(

'@Foo:',

replyTo{[2] = 'Example', label2 = 'Foo'}

)

end

return suite

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/30 12:32:56