Add tests for entity-child relationships and removal in world queries, fixed world_each

This commit is contained in:
CapedBojji 2025-01-14 20:30:56 -05:00
parent bacf056851
commit 10bbb21024
2 changed files with 33 additions and 0 deletions

View file

@ -1995,6 +1995,7 @@ local function world_each(world: World, id): () -> ()
archetype = archetypes[archetype_id]
entities = archetype.entities
row = #entities
entity = entities[row]
end
row -= 1
return entity

View file

@ -914,6 +914,38 @@ TEST("world:children", function()
end
CHECK(false)
end
-- Check query, with tags and children being added inside the query
local parent = world:entity()
local c1 = world:component()
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
for entity in world:children(parent) do
count += 1
end
CHECK(count == 0)
-- Check removing child
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)
TEST("world:clear()", function()