summaryrefslogtreecommitdiff
path: root/honey/ecs.test.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-03-28 11:50:23 -0500
committersanine-a <sanine.not@pm.me>2023-03-28 11:50:23 -0500
commitbb019b6aad81f3dc80900f8bd6bad9ce046cf11a (patch)
tree44b738b202791af0b619175071b83c3d52f8ac1e /honey/ecs.test.lua
parentcd3d4706da048076375f5899b9f893e108fed7fa (diff)
begin rdb-style refactor
Diffstat (limited to 'honey/ecs.test.lua')
-rw-r--r--honey/ecs.test.lua73
1 files changed, 43 insertions, 30 deletions
diff --git a/honey/ecs.test.lua b/honey/ecs.test.lua
index 7814097..9f7519b 100644
--- a/honey/ecs.test.lua
+++ b/honey/ecs.test.lua
@@ -10,42 +10,55 @@ end
local ecs = require 'ecs'
-local Filter = ecs.Filter
-test("Filter.AND correctly matches basic keys", function()
- local filter = Filter.AND{"hello", "world"}
+local Component = ecs.Component
- assert(filter{hello=true} == false)
- assert(filter{world=true} == false)
- assert(filter{hello=true, world=true} == true)
- assert(filter{asm=true, hello=true, world=true} == true)
+
+test("factories work as expected", function()
+ local factory = Component.newFactory("health", { percent=100 })
+ local comp1 = factory()
+ assert(comp1.__type == "health", "bad component type for comp1")
+ assert(comp1.percent == 100, "bat percent for comp1")
+
+ local comp2 = factory{ percent=50 }
+ assert(comp2.__type == "health", "bad component type for comp2")
+ assert(comp2.percent == 50, "bad percent for comp2")
+
+ local success = pcall(function()
+ comp2.dne = 5
+ end)
+ assert(not success, "incorrectly succeeded in setting comp2.dne")
+
+ local success = pcall(function()
+ local comp3 = factory{ percent = 44, something = 2 }
+ end)
+ assert(not success, "incorrectly succeeded in creating comp3")
end)
-test("Filter.AND correctly matches subfilters", function()
- local subfilter = Filter.AND{"hello"}
- local filter = Filter.AND{subfilter, "world"}
-
- assert(filter{hello=true} == false)
- assert(filter{world=true} == false)
- assert(filter{hello=true, world=true} == true)
- assert(filter{asm=true, hello=true, world=true} == true)
+
+
+test("components serialize as expected", function()
+ local position = Component.newFactory("position", { x=0, y=0, z=0 })
+ local comp = position{x=10, y=15, z=10}
+ local str = tostring(comp)
+ local tbl = (loadstring("return " .. str))()
+ assert(tbl.__type == "position", "bad type")
+ assert(tbl.x == 10, "bad x")
+ assert(tbl.y == 15, "bad y")
+ assert(tbl.z == 10, "bad z")
end)
-test("Filter.OR correctly matches basic keys", function()
- local filter = Filter.OR{"hello", "world"}
+test("components serialize successfully with subcomponents", function()
+ local position = Component.newFactory("position", { x=0, y=0, z=0 })
+ local player = Component.newFactory("player", { name="", position={} })
- assert(filter{hello=true} == true)
- assert(filter{world=true} == true)
- assert(filter{hello=true, world=true} == true)
- assert(filter{asm=true} == false)
-end)
-test("Filter.OR correctly matches subfilters", function()
- local subfilter = Filter.OR{"hello"}
- local filter = Filter.OR{subfilter, "world"}
-
- assert(filter{hello=true} == true)
- assert(filter{world=true} == true)
- assert(filter{hello=true, world=true} == true)
- assert(filter{asm=true} == false)
+ local p = player{ name="hannah", position=position{x=10, y=9, z=8} }
+ local tbl = (loadstring("return " .. tostring(p)))()
+ assert(tbl.__type == "player")
+ assert(tbl.name == "hannah")
+ assert(tbl.position.__type == "position")
+ assert(tbl.position.x == 10)
+ assert(tbl.position.y == 9)
+ assert(tbl.position.z == 8)
end)