Add tests for relation data

This commit is contained in:
Ukendio 2024-05-12 17:13:09 +02:00
parent 18381ff5e6
commit 3d6e7cb067

View file

@ -201,8 +201,9 @@ TEST("world", function()
local bob = world:entity() local bob = world:entity()
world:set(bob, ECS_PAIR(Eats, Apples), true) world:set(bob, ECS_PAIR(Eats, Apples), true)
for e in world:query(ECS_PAIR(Eats, Apples)) do for e, bool in world:query(ECS_PAIR(Eats, Apples)) do
CHECK(e == bob) CHECK(e == bob)
CHECK(bool)
end end
end end
@ -212,14 +213,16 @@ TEST("world", function()
local Apples = world:entity() local Apples = world:entity()
local bob = world:entity() local bob = world:entity()
world:add(bob, ECS_PAIR(Eats, Apples)) world:set(bob, ECS_PAIR(Eats, Apples), "bob eats apples")
local w = jecs.Wildcard local w = jecs.Wildcard
for e in world:query(ECS_PAIR(Eats, w)) do for e, data in world:query(ECS_PAIR(Eats, w)) do
CHECK(e == bob) CHECK(e == bob)
CHECK(data == "bob eats apples")
end end
for e in world:query(ECS_PAIR(w, Apples)) do for e, data in world:query(ECS_PAIR(w, Apples)) do
CHECK(e == bob) CHECK(e == bob)
CHECK(data == "bob eats apples")
end end
end end
@ -231,20 +234,26 @@ TEST("world", function()
local bob = world:entity() local bob = world:entity()
local alice = world:entity() local alice = world:entity()
world:add(bob, ECS_PAIR(Eats, Apples)) world:set(bob, ECS_PAIR(Eats, Apples), "bob eats apples")
world:add(alice, ECS_PAIR(Eats, Oranges)) world:set(alice, ECS_PAIR(Eats, Oranges), "alice eats oranges")
local w = jecs.Wildcard local w = jecs.Wildcard
local count = 0 local count = 0
for e in world:query(ECS_PAIR(Eats, w)) do for e, data in world:query(ECS_PAIR(Eats, w)) do
count += 1 count += 1
if e == bob then
CHECK(data == "bob eats apples")
else
CHECK(data == "alice eats oranges")
end
end end
CHECK(count == 2) CHECK(count == 2)
count = 0 count = 0
for e in world:query(ECS_PAIR(w, Apples)) do for e, data in world:query(ECS_PAIR(w, Apples)) do
count += 1 count += 1
CHECK(data == "bob eats apples")
end end
CHECK(count == 1) CHECK(count == 1)
end end