summaryrefslogtreecommitdiff
path: root/honey/ecs.test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'honey/ecs.test.lua')
-rw-r--r--honey/ecs.test.lua48
1 files changed, 48 insertions, 0 deletions
diff --git a/honey/ecs.test.lua b/honey/ecs.test.lua
index 0577dcd..74e27dc 100644
--- a/honey/ecs.test.lua
+++ b/honey/ecs.test.lua
@@ -229,4 +229,52 @@ test("EntityDb.deleteEntity() correctly removes an entity", function()
end)
+--===== SystemDb tests =====--
+
+local SystemDb = ecs.SystemDb
+
+test("addSystem() correctly sorts systems", function()
+ local sdb = SystemDb(nil)
+ local str = ""
+ sdb:addSystem(function () return {
+ update=function(self, dt) str = str .. "c" end,
+ priority = 3,
+ } end)
+ sdb:addSystem{
+ update=function(self, dt) str = "a" end,
+ priority = 1,
+ }
+ sdb:addSystem{
+ update=function(self, dt) str = str .. "b" end,
+ priority = 2,
+ }
+ sdb:update(0)
+ assert(str == "abc")
+end)
+
+
+test("removeSystem() correctly handles things", function()
+ local sdb = SystemDb(nil)
+ local str = ""
+ sdb:addSystem(function () return {
+ update=function(self, dt) str = str .. "c" end,
+ priority = 3,
+ } end)
+ sdb:addSystem{
+ update=function(self, dt) str = "a" end,
+ priority = 1,
+ }
+ local id = sdb:addSystem{
+ update=function(self, dt) str = str .. "b" end,
+ priority = 2,
+ }
+ sdb:update(0)
+ assert(str == "abc")
+
+ sdb:removeSystem(id)
+ sdb:update(1)
+ assert(str == "ac")
+end)
+
+
print(string.format("ran %d tests, %d failed", testCount, failCount))