Fix test case

This commit is contained in:
Ukendio 2025-01-15 12:58:23 +01:00
parent 10bbb21024
commit a5e7af7102

View file

@ -900,52 +900,39 @@ end)
TEST("world:children", function() TEST("world:children", function()
local world = world_new() local world = world_new()
local e1 = world:entity() local C = world:component()
local e2 = world:entity() local T = world:entity()
local e3 = world:entity()
local e1 = world:entity()
world:set(e1, C, true)
local e2 = world:entity()
world:add(e2, T)
world:add(e2, pair(ChildOf, e1)) world:add(e2, pair(ChildOf, e1))
local e3 = world:entity()
world:add(e3, pair(ChildOf, e1)) world:add(e3, pair(ChildOf, e1))
for entity in world:children(pair(ChildOf, e1)) do local count = 0
for entity in world:children(e1) do
count += 1
if entity == e2 or entity == e3 then if entity == e2 or entity == e3 then
CHECK(true) CHECK(true)
continue continue
end end
CHECK(false) CHECK(false)
end end
-- Check query, with tags and children being added inside the query CHECK(count == 2)
local parent = world:entity()
local c1 = world:component() world:remove(e2, pair(ChildOf, e1))
local t1 = world:entity()
local t2 = world:entity()
world:set(parent, c1, true)
local count = 0
for entity in world:query(c1) do
world:add(entity, t1)
local child = world:entity()
world:add(child, pair(ChildOf, entity))
world:add(child, t2)
for child in world:children(entity) do
count += 1
end
end
CHECK(count == 0)
-- Check child still exists outside of query
count = 0 count = 0
for entity in world:children(parent) do for entity in world:children(e1) do
count += 1 count += 1
end end
CHECK(count == 0)
-- Check removing child CHECK(count == 1)
local child = world:entity()
world:add(child, pair(ChildOf, parent))
world:remove(child, pair(ChildOf, parent))
count = 0
for entity in world:children(parent) do
count += 1
end
CHECK(count == 0)
end) end)
TEST("world:clear()", function() TEST("world:clear()", function()
@ -1594,9 +1581,9 @@ TEST("repro", function()
local world = world_new() local world = world_new()
local component1 = world:component() local component1 = world:component()
local tag1 = world:entity() local tag1 = world:entity()
local query = world:query(component1):with(tag1):cached() local query = world:query(component1):with(tag1):cached()
local entity = world:entity() local entity = world:entity()
world:set(entity, component1, "some data") world:set(entity, component1, "some data")