Skip to content

Commit e806daa

Browse files
authored
test: add dynamic component query tests (#387)
# Summary - Adds tests for queries on dynamic components
1 parent 4ceac91 commit e806daa

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local entity_a = world.spawn()
2+
local NewComponent = world.register_new_component("NewComponent")
3+
4+
world.add_default_component(entity_a, NewComponent)
5+
6+
local found_entities = {}
7+
for i,result in pairs(world.query():component(NewComponent):build()) do
8+
table.insert(found_entities, result:entity())
9+
end
10+
11+
assert(#found_entities == 1, "Expected 1 entities, got " .. #found_entities)
12+
13+
expected_entities = {
14+
entity_a
15+
}
16+
17+
for i, entity in ipairs(found_entities) do
18+
assert(entity:index() == expected_entities[i]:index(), "Expected entity " .. expected_entities[i]:index() .. " but got " .. entity:index())
19+
end
20+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let entity_a = world.spawn_.call();
2+
let NewComponent = world.register_new_component.call("NewComponent");
3+
4+
world.add_default_component.call(entity_a, NewComponent);
5+
6+
let found_entities = [];
7+
for (result, i) in world.query.call().component.call(NewComponent).build.call() {
8+
found_entities.push(result.entity.call());
9+
}
10+
11+
assert(found_entities.len == 1, "Expected 1 entities, got " + found_entities.len);
12+
13+
let expected_entities = [entity_a];
14+
15+
for (entity, i) in found_entities {
16+
assert(entity.index.call() == expected_entities[i].index.call(), "Expected entity " + expected_entities[i].index.call() + " but got " + entity.index.call());
17+
}

0 commit comments

Comments
 (0)