-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added 100% coverage for existing tests (#125)
* test: Added 100% coverage for existing tests * test: changed collision test in Lua 5.1 * test: added is_ok and is_redirect tests --------- Co-authored-by: Vicente Pereira <[email protected]> Co-authored-by: Nicolas Pires <[email protected]>
- Loading branch information
1 parent
af6d266
commit 30ea79c
Showing
11 changed files
with
613 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
local old_require = require | ||
|
||
local function mock_require(decorators) | ||
return function(src) | ||
if decorators[src] then | ||
return decorators[src]() | ||
end | ||
return old_require(src) | ||
end | ||
end | ||
|
||
local P = { | ||
require=mock_require | ||
} | ||
|
||
return P |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
local luaunit = require('luaunit') | ||
local engine_game = require('src/lib/engine/api/app') | ||
|
||
|
||
function test_app_reset() | ||
local index = 1 | ||
local buses = {} | ||
local std = { | ||
node = {}, | ||
bus = { | ||
listen = function() end, | ||
emit = function(key) | ||
buses[key] = index | ||
index = index + 1 | ||
end | ||
} | ||
} | ||
|
||
local config = { | ||
quit = function() | ||
print("Config quit foi chamado!") | ||
end | ||
} | ||
|
||
zeebo_game = engine_game.install(std, {}, {}) | ||
zeebo_game.reset() | ||
|
||
luaunit.assertEquals(buses.exit, 1) | ||
luaunit.assertEquals(buses.init, 2) | ||
luaunit.assertEquals(index, 3) | ||
std.bus:emit('post_quit') | ||
end | ||
|
||
function test_app_reset_no_node() | ||
local exit_called = false | ||
local init_called = false | ||
|
||
local std = { | ||
bus = { | ||
listen = function() end, | ||
emit = function() end | ||
} | ||
} | ||
|
||
|
||
local engine = { | ||
root = { | ||
data = {}, | ||
callbacks = {} | ||
} | ||
} | ||
|
||
engine.root.callbacks.exit = function(std_param, data_param) | ||
luaunit.assertEquals(std_param, std) | ||
luaunit.assertEquals(data_param, engine.root.data) | ||
exit_called = true | ||
end | ||
|
||
engine.root.callbacks.init = function(std_param, data_param) | ||
luaunit.assertEquals(std_param, std) | ||
luaunit.assertEquals(data_param, engine.root.data) | ||
init_called = true | ||
end | ||
zeebo_game = engine_game.install(std, engine, {}) | ||
zeebo_game.reset() | ||
|
||
luaunit.assertTrue(exit_called) | ||
luaunit.assertTrue(init_called) | ||
end | ||
|
||
function test_app_exit() | ||
local index = 1 | ||
local buses = {} | ||
local std = { | ||
bus = { | ||
listen = function() end, | ||
emit = function(key) | ||
buses[key] = index | ||
index = index + 1 | ||
end | ||
} | ||
} | ||
|
||
zeebo_game = engine_game.install(std, {}, {}) | ||
zeebo_game.exit() | ||
|
||
luaunit.assertEquals(buses.exit, 1) | ||
luaunit.assertEquals(buses.quit, 2) | ||
luaunit.assertEquals(index, 3) | ||
end | ||
|
||
function test_app_title() | ||
|
||
local function mock_set_title(window_name) | ||
luaunit.assertEquals(window_name, "Teste") | ||
end | ||
|
||
local std = { | ||
bus = { | ||
listen = function() end, | ||
emit = function() end | ||
}, | ||
app ={ | ||
title = nil | ||
} | ||
} | ||
local config = { | ||
set_title = mock_set_title | ||
} | ||
|
||
local zeebo_game = engine_game.install(std, {}, config) | ||
|
||
zeebo_game.title("Teste") | ||
|
||
end | ||
|
||
function test_app_install() | ||
local exit_called = false | ||
local init_called = false | ||
local quit_called = false | ||
|
||
local std = { | ||
bus = { | ||
listen = function(event, callback) | ||
if event == 'post_quit' then | ||
callback() | ||
end | ||
end, | ||
emit = function() end | ||
} | ||
} | ||
|
||
local engine = { | ||
root = { | ||
data = {}, | ||
callbacks = {} | ||
} | ||
} | ||
|
||
engine.root.callbacks.exit = function(std_param, data_param) | ||
luaunit.assertEquals(std_param, std) | ||
luaunit.assertEquals(data_param, engine.root.data) | ||
exit_called = true | ||
end | ||
|
||
engine.root.callbacks.init = function(std_param, data_param) | ||
luaunit.assertEquals(std_param, std) | ||
luaunit.assertEquals(data_param, engine.root.data) | ||
init_called = true | ||
end | ||
|
||
local config = { | ||
set_title = function(window_name) | ||
luaunit.assertEquals(window_name, "Test Window") | ||
end, | ||
fps = 60, | ||
quit = function() | ||
quit_called = true | ||
end | ||
} | ||
|
||
local zeebo_game = engine_game.install(std, engine, config) | ||
|
||
luaunit.assertNotNil(zeebo_game.title) | ||
luaunit.assertNotNil(zeebo_game.exit) | ||
luaunit.assertNotNil(zeebo_game.reset) | ||
luaunit.assertEquals(zeebo_game.get_fps, 60) | ||
|
||
zeebo_game.title("Test Window") | ||
|
||
zeebo_game.reset() | ||
|
||
luaunit.assertTrue(exit_called) | ||
luaunit.assertTrue(init_called) | ||
luaunit.assertTrue(quit_called) | ||
end | ||
os.exit(luaunit.LuaUnit.run()) |
Oops, something went wrong.