Module:Icon/testcases: Difference between revisions
Appearance
Content deleted Content added
test leaving link data out of the data table |
use descriptive sentences for test cases, and generate the test data table every time, just in case the main module does something funny with it |
||
Line 3: | Line 3: | ||
local suite = ScribuntoUnit:new() |
local suite = ScribuntoUnit:new() |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
_DEFAULT = { |
|||
⚫ | |||
⚫ | |||
_DEFAULT = { |
|||
⚫ | |||
link = false, |
|||
} |
|||
} |
} |
||
⚫ | |||
} |
|||
⚫ | |||
-- above. |
|||
⚫ | |||
⚫ | |||
end |
end |
||
Line 35: | Line 33: | ||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
function suite:assertLinkIsNotSuppressed(s) |
|||
⚫ | |||
end |
|||
suite["test _main: when no icon code is specified, a file link is output"] = function(self) |
|||
self:assertIsFileLink(icon{}) |
self:assertIsFileLink(icon{}) |
||
end |
|||
suite["test _main: when an existing icon code is specified, a file link is output"] = function(self) |
|||
self:assertIsFileLink(icon{'fa'}) |
self:assertIsFileLink(icon{'fa'}) |
||
⚫ | |||
end |
end |
||
suite["test _main: when an nonexistent icon code is specified, a file link is output"] = function(self) |
|||
function suite:testGA() |
|||
⚫ | |||
end |
|||
suite["test _main: when an existing code is specified, the relevant image is displayed"] = function(self) |
|||
self:assertStringContains('Symbol support vote.svg', icon{'ga'}, true) |
self:assertStringContains('Symbol support vote.svg', icon{'ga'}, true) |
||
end |
|||
suite["test _main: when an existing code is specified, the relevant tooltip is displayed"] = function(self) |
|||
self:assertStringContains('Good article', icon{'ga'}, true) |
self:assertStringContains('Good article', icon{'ga'}, true) |
||
end |
end |
||
suite["test _main: when no dimensions are specified, the image is output as 16x16 pixels"] = function(self) |
|||
function suite:testDefaultSize() |
|||
self:assertStringContains('16x16px', icon{}) |
self:assertStringContains('16x16px', icon{}) |
||
end |
end |
||
suite["test _main: when custom dimensions are specified, the image is output with those dimensions"] = function(self) |
|||
function suite:testCustomSize() |
|||
self:assertStringContains('320px', icon{size = '320px'}) |
self:assertStringContains('320px', icon{size = '320px'}) |
||
end |
end |
||
suite["test _main: codes can have surrounding whitespace"] = function(self) |
|||
function suite:testCodeWhitespace() |
|||
self:assertStringContains('Featured article', icon{' fa '}) |
self:assertStringContains('Featured article', icon{' fa '}) |
||
end |
end |
||
suite["test _main: codes can be upper case"] = function(self) |
|||
function suite:testCodeCapitalization() |
|||
self:assertStringContains('Featured article', icon{'FA'}) |
self:assertStringContains('Featured article', icon{'FA'}) |
||
end |
end |
||
suite["test _main: codes can be specified with the 'class' parameter"] = function(self) |
|||
function suite:testClassParameter() |
|||
self:assertStringContains('Featured article', icon{class = 'fa'}) |
self:assertStringContains('Featured article', icon{class = 'fa'}) |
||
end |
end |
||
suite["test _main: the class parameter has precedence over the first positional parameter"] = function(self) |
|||
function suite:testClassParameterOverride() |
|||
self:assertNotStringContains('Featured article', icon{'fa', class = 'ga'}) |
self:assertNotStringContains('Featured article', icon{'fa', class = 'ga'}) |
||
end |
|||
suite["test _main: the class parameter has precedence over the first positional parameter, even if the class parameter is the empty string"] = function(self) |
|||
self:assertNotStringContains('Featured article', icon{'fa', class = ''}) |
self:assertNotStringContains('Featured article', icon{'fa', class = ''}) |
||
end |
end |
||
suite["test _main: links are suppressed when the entry in the data table has 'link' set to false"] = function(self) |
|||
function suite:testLinkSuppression() |
|||
self:assertLinkIsSuppressed(icon{'ga'}) |
|||
⚫ | |||
end |
|||
⚫ | |||
suite["test _main: links are not suppressed when the entry in the data table has 'link' set to true"] = function(self) |
|||
self:assertNotStringContains(linkPattern, icon{'fa'}) |
self:assertNotStringContains(linkPattern, icon{'fa'}) |
||
⚫ | |||
end |
end |
||
suite["test _main: links are not suppressed when the entry in the data table has no value for 'link'"] = function(self) |
|||
-- Functions that test the original data |
|||
self:assertNotStringContains(linkPattern, icon{'wikipedia'}) |
|||
end |
|||
suite["test Module:Icon/data: codes can be specified as aliases"] = function(self) |
|||
function suite:testAlias() |
|||
self:assertStringContains('Former featured article', mIcon._main{'dfa'}) |
self:assertStringContains('Former featured article', mIcon._main{'dfa'}) |
||
end |
end |
Latest revision as of 06:12, 29 August 2021
![]() | This is the test cases page for the module Module:Icon. Results of the test cases. |
local mIcon = require('Module:Icon/sandbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
-- Use a shortcut function to call mIcon._main using custom icon data.
local function icon(args)
local data = {
fa = {
image = "Featured article star.svg",
tooltip = "Featured article",
link = true,
},
ga = {
image = "Symbol support vote.svg",
tooltip = "Good article",
link = false,
},
wikipedia = {
image = "Wikipedia-logo.svg",
tooltip = "Wikipedia page",
},
_DEFAULT = {
image = "Symbol question.svg",
link = false,
}
}
return mIcon._main(args, data)
end
function suite:assertIsFileLink(s)
self:assertStringContains('^%[%[File:[^%]]+%]%]$', s)
self:assertStringContains('|class=noviewer', s, true)
end
local linkPattern = '|link=[|%]]'
function suite:assertLinkIsSuppressed(s)
self:assertStringContains(linkPattern, s)
end
function suite:assertLinkIsNotSuppressed(s)
self:assertNotStringContains(linkPattern, s)
end
suite["test _main: when no icon code is specified, a file link is output"] = function(self)
self:assertIsFileLink(icon{})
end
suite["test _main: when an existing icon code is specified, a file link is output"] = function(self)
self:assertIsFileLink(icon{'fa'})
end
suite["test _main: when an nonexistent icon code is specified, a file link is output"] = function(self)
self:assertIsFileLink(icon{'nonexistentcode'})
end
suite["test _main: when an existing code is specified, the relevant image is displayed"] = function(self)
self:assertStringContains('Symbol support vote.svg', icon{'ga'}, true)
end
suite["test _main: when an existing code is specified, the relevant tooltip is displayed"] = function(self)
self:assertStringContains('Good article', icon{'ga'}, true)
end
suite["test _main: when no dimensions are specified, the image is output as 16x16 pixels"] = function(self)
self:assertStringContains('16x16px', icon{})
end
suite["test _main: when custom dimensions are specified, the image is output with those dimensions"] = function(self)
self:assertStringContains('320px', icon{size = '320px'})
end
suite["test _main: codes can have surrounding whitespace"] = function(self)
self:assertStringContains('Featured article', icon{' fa '})
end
suite["test _main: codes can be upper case"] = function(self)
self:assertStringContains('Featured article', icon{'FA'})
end
suite["test _main: codes can be specified with the 'class' parameter"] = function(self)
self:assertStringContains('Featured article', icon{class = 'fa'})
end
suite["test _main: the class parameter has precedence over the first positional parameter"] = function(self)
self:assertNotStringContains('Featured article', icon{'fa', class = 'ga'})
end
suite["test _main: the class parameter has precedence over the first positional parameter, even if the class parameter is the empty string"] = function(self)
self:assertNotStringContains('Featured article', icon{'fa', class = ''})
end
suite["test _main: links are suppressed when the entry in the data table has 'link' set to false"] = function(self)
self:assertLinkIsSuppressed(icon{'ga'})
end
suite["test _main: links are not suppressed when the entry in the data table has 'link' set to true"] = function(self)
self:assertNotStringContains(linkPattern, icon{'fa'})
end
suite["test _main: links are not suppressed when the entry in the data table has no value for 'link'"] = function(self)
self:assertNotStringContains(linkPattern, icon{'wikipedia'})
end
suite["test Module:Icon/data: codes can be specified as aliases"] = function(self)
self:assertStringContains('Former featured article', mIcon._main{'dfa'})
end
return suite