Module:Icon/testcases: Difference between revisions

Content deleted Content added
move declarations to the top
simplify file link pattern check
Line 11:
end
 
function suite:assertFileLinkassertIsFileLink(s)
local fileLinkPattern
self:assertStringContains('^%[%[File:[^%]]+%]%]$', s)
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:assertFileLinkassertIsFileLink(icon{})
self:assertFileLinkassertIsFileLink(icon{'fa'})
self:assertFileLinkassertIsFileLink(icon{'qwertyuiop'})
end