Difference between revisions of "Module:List/testcases"
Jump to navigation
Jump to search
blackwiki>Edokter (start=3) |
blackwiki>Mr. Stradivarius (start rewriting the test cases) |
||
| Line 1: | Line 1: | ||
-- Unit tests for [[Module:List]]. Click talk page to run tests. | -- Unit tests for [[Module:List]]. Click talk page to run tests. | ||
| − | |||
| − | + | local mList = require('Module:List/sandbox') | |
| − | + | local ScribuntoUnit = require('Module:ScribuntoUnit') | |
| − | + | local suite = ScribuntoUnit:new() | |
| − | + | ||
| − | + | -------------------------------------------------------------------------------- | |
| − | + | -- Default values | |
| − | + | -------------------------------------------------------------------------------- | |
| − | + | ||
| − | + | local d = {} | |
| − | + | ||
| − | + | -- Function names | |
| − | + | d.bulletedFunc = 'bulleted' | |
| − | + | d.unbulletedFunc = 'unbulleted' | |
| − | + | d.horizontalFunc = 'horizontal' | |
| − | + | d.orderedFunc = 'ordered' | |
| − | + | d.horizontalOrderedFunc = 'horizontal_ordered' | |
| − | + | ||
| − | + | -- List items | |
| − | + | d.item1 = 'Foo' | |
| − | + | d.item2 = 'Bar' | |
| − | + | ||
| − | + | -- Styles | |
| − | + | d.arbitraryStyle = 'text-align: right' | |
| + | |||
| + | -- Parameter names | ||
| + | d.itemStyleParam1 = 'item_style1' | ||
| − | + | -------------------------------------------------------------------------------- | |
| − | + | -- Test makeListData | |
| − | + | -------------------------------------------------------------------------------- | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | function | + | function suite:testDataBlank() |
| − | + | local data = mList.makeListData(d.bulletedFunc, {}) | |
| − | + | self:assertEquals('table', type(data)) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | function | + | function suite:testDataOneItem() |
| − | + | local data = mList.makeListData(d.bulletedFunc, {d.item1}) | |
| − | + | self:assertEquals(d.item1, data.items[1].content) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | function | + | function suite:testDataTwoItems() |
| − | + | local data = mList.makeListData(d.bulletedFunc, {d.item1, d.item2}) | |
| − | + | self:assertEquals(d.item1, data.items[1].content) | |
| − | + | self:assertEquals(d.item2, data.items[2].content) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | function | + | function suite:testDataItemStyle() |
| − | + | local data = mList.makeListData(d.bulletedFunc, {d.item1, [d.itemStyleParam1] = d.arbitraryStyle}) | |
| − | + | self:assertEquals(d.arbitraryStyle, data.items[1].style) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | return | + | return suite |
Revision as of 02:33, 23 May 2014
Documentation for this module may be created at Module:List/testcases/doc
-- Unit tests for [[Module:List]]. Click talk page to run tests.
local mList = require('Module:List/sandbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
--------------------------------------------------------------------------------
-- Default values
--------------------------------------------------------------------------------
local d = {}
-- Function names
d.bulletedFunc = 'bulleted'
d.unbulletedFunc = 'unbulleted'
d.horizontalFunc = 'horizontal'
d.orderedFunc = 'ordered'
d.horizontalOrderedFunc = 'horizontal_ordered'
-- List items
d.item1 = 'Foo'
d.item2 = 'Bar'
-- Styles
d.arbitraryStyle = 'text-align: right'
-- Parameter names
d.itemStyleParam1 = 'item_style1'
--------------------------------------------------------------------------------
-- Test makeListData
--------------------------------------------------------------------------------
function suite:testDataBlank()
local data = mList.makeListData(d.bulletedFunc, {})
self:assertEquals('table', type(data))
end
function suite:testDataOneItem()
local data = mList.makeListData(d.bulletedFunc, {d.item1})
self:assertEquals(d.item1, data.items[1].content)
end
function suite:testDataTwoItems()
local data = mList.makeListData(d.bulletedFunc, {d.item1, d.item2})
self:assertEquals(d.item1, data.items[1].content)
self:assertEquals(d.item2, data.items[2].content)
end
function suite:testDataItemStyle()
local data = mList.makeListData(d.bulletedFunc, {d.item1, [d.itemStyleParam1] = d.arbitraryStyle})
self:assertEquals(d.arbitraryStyle, data.items[1].style)
end
return suite