Jump to content

Module:ScribuntoUnit/testcases

From Simple English Wikipedia, the free encyclopedia
Revision as of 01:42, 4 November 2021 by MeritedElm63160 (talk | changes) (Created page with "local ScribuntoUnit = require('Module:ScribuntoUnit') local p = {} -------------------------------------------------------------------------------- -- Test assertEquals local function testAssertEquals(msg, expected, actual, shouldFail) local out = msg .. ' ' local errmsg = '' local success, details = pcall(function () local suite = ScribuntoUnit:new() suite:assertEquals(expected, actual) end) if not success and (type(details) ~= 'table' or not details.Scri...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:ScribuntoUnit/testcases/doc

local ScribuntoUnit = require('Module:ScribuntoUnit')

local p = {}

--------------------------------------------------------------------------------
-- Test assertEquals

local function testAssertEquals(msg, expected, actual, shouldFail)
	local out = msg .. ' '
	local errmsg = ''

	local success, details = pcall(function ()
		local suite = ScribuntoUnit:new()
		suite:assertEquals(expected, actual)
	end)
	
	if not success and (type(details) ~= 'table' or not details.ScribuntoUnit) then -- a real error, not a failed assertion
		local errmsg = 'Lua error: ' .. tostring(details)
	end
	
	if success == not shouldFail then
		out = out .. 'OK'
	else
		out = out .. 'FAIL'	.. (errmsg and ' -- ' .. errmsg or '')			
	end

	return out
end
	
function p.testAssertEqualsWithEqualStrings()
	
	return testAssertEquals(
		'Testing that assertEquals does not throw error for equal strings...',
		'abc',
		'abc',
		false
	)

end

function p.testAssertEqualsWithUnequalStrings()
	
	return testAssertEquals(
		'Testing that assertEquals throws error for unequal strings...',
		'abc',
		'def',
		true
	)

end

--------------------------------------------------------------------------------
-- TODO: Test more methods
--

return p