Jump to content

Module:List/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 02:33, 23 May 2014 (start rewriting the test cases). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- 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