Files
love/testing/tests/event.lua
T
ell 19df8040df 0.1
Initial commit of a basic test framework, see readme.md for more

Most modules are covered with basic unit tests, and there's an example test for a graphics draw (rectangle) and object (File) - for object tests doing more scenario based so we can check multiple things together
2023-10-04 14:43:44 +01:00

73 lines
1.7 KiB
Lua

-- love.event
-- love.event.clear
love.test.event.clear = function(test)
-- setup
love.event.push('test', 1, 2, 3)
love.event.push('test', 1, 2, 3)
love.event.push('test', 1, 2, 3)
-- tests
love.event.clear()
local count = 0
for n, a, b, c, d, e, f in love.event.poll() do
count = count + 1
end
test:assertEquals(0, count, 'check no events')
end
-- love.event.poll
love.test.event.poll = function(test)
-- setup
love.event.push('test', 1, 2, 3)
love.event.push('test', 1, 2, 3)
love.event.push('test', 1, 2, 3)
-- tests
local count = 0
for n, a, b, c, d, e, f in love.event.poll() do
count = count + 1
end
test:assertEquals(3, count, 'check 3 events')
end
-- love.event.pump
-- @NOTE dont think can really test as internal?
love.test.event.pump = function(test)
test:skipTest('not sure we can test when its internal?')
end
-- love.event.push
love.test.event.push = function(test)
-- test
love.event.push('add', 1, 2, 3)
love.event.push('ignore', 1, 2, 3)
love.event.push('add', 1, 2, 3)
love.event.push('ignore', 1, 2, 3)
local count = 0
for n, a, b, c, d, e, f in love.event.poll() do
if n == 'add' then
count = count + a + b + c
end
end
test:assertEquals(12, count, 'check total events')
end
-- love.event.quit
love.test.event.quit = function(test)
love.test.module.fakequit = true
-- this should call love.quit, which will prevent the quit
-- if this fails then the test would just abort here
love.event.quit(0)
test:assertEquals(true, true, 'check quit hook called')
end
-- love.event.wait
-- @NOTE not sure best way to test this one
love.test.event.wait = function(test)
test:skipTest('not sure on best way to test this')
end