Difference between revisions of "Module:Icon/testcases"
Jump to navigation
Jump to search
blackwiki>Mr. Stradivarius (only make the file link pattern once) |
m (4 revisions imported) |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 3: | Line 3: | ||
local suite = ScribuntoUnit:new() | local suite = ScribuntoUnit:new() | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
| + | |||
| + | -- This function is used to run all the instances of Icon, so that we can easily | ||
| + | -- switch between the module and the template. | ||
| + | local function icon(args) | ||
| + | -- return frame:expandTemplate{title = 'icon/sandbox', args = args} | ||
| + | return mIcon._main(args) | ||
| + | end | ||
local fileLinkPattern | local fileLinkPattern | ||
| Line 12: | Line 19: | ||
titleChar .. '-' .. titleCharOrPipe .. '-|' .. titleChar .. '-|' .. | titleChar .. '-' .. titleCharOrPipe .. '-|' .. titleChar .. '-|' .. | ||
spaces .. 'link=' .. spaces .. '%]%]$' | spaces .. 'link=' .. spaces .. '%]%]$' | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
Latest revision as of 14:59, 22 September 2020
Documentation for this module may be created at Module:Icon/testcases/doc
local mIcon = require('Module:Icon')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local frame = mw.getCurrentFrame()
-- This function is used to run all the instances of Icon, so that we can easily
-- switch between the module and the template.
local function icon(args)
-- return frame:expandTemplate{title = 'icon/sandbox', args = args}
return mIcon._main(args)
end
local fileLinkPattern
do
local spaces = '[_ \t]*'
local titleChar = '[^|<>%[%]{}]'
local titleCharOrPipe = '[^<>%[%]{}]'
fileLinkPattern = '^%[%[' .. spaces .. '(.-)' .. spaces .. ':' .. spaces ..
titleChar .. '-' .. titleCharOrPipe .. '-|' .. titleChar .. '-|' ..
spaces .. 'link=' .. spaces .. '%]%]$'
end
function suite:assertFileLink(s)
local nsText = s:match(fileLinkPattern)
nsText = nsText and nsText:lower()
self:assertTrue(nsText == 'file' or nsText == 'image')
end
function suite:testIsFileLink()
self:assertFileLink(icon{})
self:assertFileLink(icon{'fa'})
self:assertFileLink(icon{'qwertyuiop'})
end
function suite:testGA()
self:assertStringContains('Symbol support vote.svg', icon{'ga'}, true)
self:assertStringContains('Good article', icon{'ga'}, true)
end
function suite:testDefaultSize()
self:assertStringContains('16x16px', icon{})
end
function suite:testCustomSize()
self:assertStringContains('320px', icon{size = '320px'})
end
function suite:testAlias()
self:assertStringContains('Former featured article', icon{'dfa'})
end
function suite:testCodeWhitespace()
self:assertStringContains('Featured article', icon{' fa '})
end
function suite:testCodeCapitalization()
self:assertStringContains('Featured article', icon{'FA'})
end
function suite:testClassParameter()
self:assertStringContains('Featured article', icon{class = 'fa'})
end
function suite:testClassParameterOverride()
self:assertNotStringContains('Featured article', icon{'fa', class = 'ga'})
self:assertNotStringContains('Featured article', icon{'fa', class = ''})
end
return suite