Difference between revisions of "Module:Userbox/testcases"
Jump to navigation
Jump to search
blackwiki>Mr. Stradivarius (make more accurate tests and create some pattern-generating helper functions) |
blackwiki>Mr. Stradivarius (add some more tests) |
||
| Line 27: | Line 27: | ||
-- and a given html attribute. | -- and a given html attribute. | ||
return inTag(inAttr(s, attr), tag) | return inTag(inAttr(s, attr), tag) | ||
| + | end | ||
| + | |||
| + | local function renderId(data) | ||
| + | data.showId = true | ||
| + | return render(data) | ||
end | end | ||
| Line 34: | Line 39: | ||
function suite:testRenderFloat() | function suite:testRenderFloat() | ||
| − | self:assertStringContains(inTagAttr('float:right;', 'div', 'style'), render{float= | + | self:assertStringContains(inTagAttr('float:right;', 'div', 'style'), render{float = 'right'}) |
end | end | ||
function suite:testRenderBorder() | function suite:testRenderBorder() | ||
| − | self:assertStringContains(inTagAttr('border:5px', 'div', 'style'), render{borderWidth= | + | self:assertStringContains(inTagAttr('border:5px', 'div', 'style'), render{borderWidth = '5px'}) |
| − | self:assertStringContains('solid red', render{borderColor= | + | self:assertStringContains('solid red', render{borderColor='red'}) |
end | end | ||
| Line 47: | Line 52: | ||
function suite:testRenderWidth() | function suite:testRenderWidth() | ||
| − | self:assertStringContains(inTagAttr('width:120px;', 'div', 'style'), render{width= | + | self:assertStringContains(inTagAttr('width:120px;', 'div', 'style'), render{width = '120px'}) |
end | end | ||
| Line 55: | Line 60: | ||
function suite:testRenderBodyClass() | function suite:testRenderBodyClass() | ||
| − | self:assertStringContains(inTagAttr('foobar', 'div', 'class'), render{bodyClass= | + | self:assertStringContains(inTagAttr('foobar', 'div', 'class'), render{bodyClass = 'foobar'}) |
| + | end | ||
| + | |||
| + | function suite:testRenderBorderCollapse() | ||
| + | self:assertStringContains(inTagAttr('border-collapse:collapse;', 'table', 'style'), render{}) | ||
| + | end | ||
| + | |||
| + | function suite:testRenderBorderCollapse() | ||
| + | self:assertStringContains(inTagAttr('width:120px;', 'table', 'style'), render{width = '120px'}) | ||
| + | end | ||
| + | |||
| + | function suite:testRenderTableWidth() | ||
| + | self:assertStringContains(inTagAttr('width:120px;', 'table', 'style'), render{width = '120px'}) | ||
| + | end | ||
| + | |||
| + | function suite:testRenderMarginBottom() | ||
| + | self:assertStringContains(inTagAttr('margin%-bottom:0;', 'table', 'style'), render{}) | ||
| + | end | ||
| + | |||
| + | function suite:testRenderBackgroundColor() | ||
| + | self:assertStringContains(inTagAttr('background:red;', 'table', 'style'), render{backgroundColor = 'red'}) | ||
| + | end | ||
| + | |||
| + | function suite:testRenderIdBorder() | ||
| + | self:assertStringContains(inTagAttr('border:0;', 'th', 'style'), renderId{}) | ||
| + | end | ||
| + | |||
| + | function suite:testRenderIdWidth() | ||
| + | self:assertStringContains(inTagAttr('width:50px;', 'th', 'style'), renderId{idWidth = '50px'}) | ||
| + | end | ||
| + | |||
| + | function suite:testRenderIdHeight() | ||
| + | self:assertStringContains(inTagAttr('height:50px;', 'th', 'style'), renderId{idHeight = '50px'}) | ||
end | end | ||
return suite | return suite | ||
Revision as of 19:32, 8 January 2014
Documentation for this module may be created at Module:Userbox/testcases/doc
-- Unit tests for [[Module:Userbox]]. Click talk page to run tests.
local ubx = require('Module:Userbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local userbox = ubx.userbox
local userbox2 = ubx['userbox-2']
local userboxr = ubx['userbox-r']
local render = ubx.render
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
local function inTag(s, tag)
-- Makes a pattern that tests whether s is inside a given html tag.
return '<' .. tag .. ' [^>]-' .. s
end
local function inAttr(s, attr)
-- Makes a pattern that tests whether s is inside a given html attribute.
return attr .. '="[^"]-' .. s
end
local function inTagAttr(s, tag, attr)
-- Makes a pattern that tests whether s is inside a given html tag
-- and a given html attribute.
return inTag(inAttr(s, attr), tag)
end
local function renderId(data)
data.showId = true
return render(data)
end
--------------------------------------------------------------------------------
-- Render tests
--------------------------------------------------------------------------------
function suite:testRenderFloat()
self:assertStringContains(inTagAttr('float:right;', 'div', 'style'), render{float = 'right'})
end
function suite:testRenderBorder()
self:assertStringContains(inTagAttr('border:5px', 'div', 'style'), render{borderWidth = '5px'})
self:assertStringContains('solid red', render{borderColor='red'})
end
function suite:testRenderMargin()
self:assertStringContains(inTagAttr('margin:1px;', 'div', 'style'), render{})
end
function suite:testRenderWidth()
self:assertStringContains(inTagAttr('width:120px;', 'div', 'style'), render{width = '120px'})
end
function suite:testRenderUserboxClass()
self:assertStringContains(inTagAttr('wikipediauserbox', 'div', 'class'), render{})
end
function suite:testRenderBodyClass()
self:assertStringContains(inTagAttr('foobar', 'div', 'class'), render{bodyClass = 'foobar'})
end
function suite:testRenderBorderCollapse()
self:assertStringContains(inTagAttr('border-collapse:collapse;', 'table', 'style'), render{})
end
function suite:testRenderBorderCollapse()
self:assertStringContains(inTagAttr('width:120px;', 'table', 'style'), render{width = '120px'})
end
function suite:testRenderTableWidth()
self:assertStringContains(inTagAttr('width:120px;', 'table', 'style'), render{width = '120px'})
end
function suite:testRenderMarginBottom()
self:assertStringContains(inTagAttr('margin%-bottom:0;', 'table', 'style'), render{})
end
function suite:testRenderBackgroundColor()
self:assertStringContains(inTagAttr('background:red;', 'table', 'style'), render{backgroundColor = 'red'})
end
function suite:testRenderIdBorder()
self:assertStringContains(inTagAttr('border:0;', 'th', 'style'), renderId{})
end
function suite:testRenderIdWidth()
self:assertStringContains(inTagAttr('width:50px;', 'th', 'style'), renderId{idWidth = '50px'})
end
function suite:testRenderIdHeight()
self:assertStringContains(inTagAttr('height:50px;', 'th', 'style'), renderId{idHeight = '50px'})
end
return suite