VOOZH about

URL: https://en.wikipedia.org/wiki/Module:File_link/testcases

⇱ Module:File link/testcases - Wikipedia


Jump to content
From Wikipedia, the free encyclopedia
👁 Image
This is the test cases page for the module Module:File link. Results of the test cases.
-- Unit tests for [[Module:File link]]. Click on the talk page to run the tests.
localmFileLink=require('Module:File link/sandbox')
localmain=mFileLink.main
local_main=mFileLink._main
localScribuntoUnit=require('Module:ScribuntoUnit')
localsuite=ScribuntoUnit:new()
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
functionsuite:assertPositionalParamExists(key)
self:assertEquals(
_main{file='Example.png',[key]='some value'},
'[[File:Example.png|some value]]'
)
end
functionsuite:assertNamedParamExists(key)
self:assertEquals(
_main{file='Example.png',[key]='some value'},
'[[File:Example.png|'..key..'=some value]]'
)
end
--------------------------------------------------------------------------------
-- Basic tests
--------------------------------------------------------------------------------
functionsuite:testBadInput()
self:assertThrows(_main,"bad argument #1 to '_main' (table expected, got nil)",nil)
self:assertThrows(_main,"bad argument #1 to '_main' (table expected, got string)",nil,'foo')
self:assertThrows(_main,"bad argument #1 to '_main' (table expected, got boolean)",nil,false)
self:assertThrows(_main,"bad argument #1 to '_main' (table expected, got number)",nil,9)
end
functionsuite:testBadFile()
self:assertThrows(_main,"type error in 'file' parameter of '_main' (expected string, got nil)",nil,{})
self:assertThrows(_main,"type error in 'file' parameter of '_main' (expected string, got boolean)",nil,{file=true})
self:assertThrows(_main,"type error in 'file' parameter of '_main' (expected string, got number)",nil,{file=123})
self:assertThrows(_main,"type error in 'file' parameter of '_main' (expected string, got table)",nil,{file={}})
end
functionsuite:testFile()
self:assertEquals(_main{file='Example.png'},'[[File:Example.png]]')
end
--------------------------------------------------------------------------------
-- Positional parameters
--------------------------------------------------------------------------------
functionsuite:testFormat()
self:assertPositionalParamExists('format')
end
functionsuite:testLocation()
self:assertPositionalParamExists('location')
end
functionsuite:testAlignment()
self:assertPositionalParamExists('alignment')
end
functionsuite:testSize()
self:assertPositionalParamExists('size')
end
functionsuite:testCaption()
self:assertPositionalParamExists('caption')
end
--------------------------------------------------------------------------------
-- Named parameters
--------------------------------------------------------------------------------
functionsuite:testUpright()
self:assertNamedParamExists('upright')
end
functionsuite:testLink()
self:assertNamedParamExists('link')
end
functionsuite:testAlt()
self:assertNamedParamExists('alt')
end
functionsuite:testPage()
self:assertNamedParamExists('page')
end
functionsuite:testClass()
self:assertNamedParamExists('class')
end
functionsuite:testLang()
self:assertNamedParamExists('lang')
end
functionsuite:testStart()
self:assertNamedParamExists('start')
end
functionsuite:testEnd()
self:assertNamedParamExists('end')
end
functionsuite:testThumbtime()
self:assertNamedParamExists('thumbtime')
end
--------------------------------------------------------------------------------
-- Special parameters
--------------------------------------------------------------------------------
functionsuite:testBorder()
self:assertEquals(
_main{file='Example.png',border=true},
'[[File:Example.png|border]]'
)
self:assertEquals(
_main{file='Example.png',border='yes'},
'[[File:Example.png|border]]'
)
self:assertEquals(
_main{file='Example.png',border='y'},
'[[File:Example.png|border]]'
)
self:assertEquals(
_main{file='Example.png',border='YES'},
'[[File:Example.png|border]]'
)
end
functionsuite:testFormatfileWithFormat()
self:assertEquals(
_main{file='Example.png',format='a format',formatfile='foo'},
'[[File:Example.png|a format=foo]]'
)
end
functionsuite:testFormatfileWithoutFormat()
self:assertEquals(
_main{file='Example.png',formatfile='foo'},
'[[File:Example.png]]'
)
end
--------------------------------------------------------------------------------
-- Order
--------------------------------------------------------------------------------
functionsuite:testOrder()
localparams={
'file',
'format',
'formatfile',
'border',
'location',
'alignment',
'size',
'upright',
'link',
'alt',
'page',
'class',
'lang',
'start',
'end',
'thumbtime',
'caption'
}
localargs={}
fori,paraminipairs(params)do
args[param]='param '..i
end
args.border=true-- border is a special case
localresult=_main(args)
-- Ugly hack to make border work whatever position it's in.
localborderNum
fori,vinipairs(params)do
ifv=='border'then
borderNum=i
end
end
result=result:gsub('border','param '..borderNum,1)
locali=0
forsinstring.gmatch(result,'param %d+')do
i=i+1
suite:assertEquals(s,'param '..i)
end
end
returnsuite