Skip to content

Commit

Permalink
Add tests for entity-child relationships and removal in world queries…
Browse files Browse the repository at this point in the history
…, fixed world_each
  • Loading branch information
CapedBojji committed Jan 15, 2025
1 parent bacf056 commit 10bbb21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions jecs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions test/tests.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 10bbb21

Please sign in to comment.