Skip to content

test: add dynamic component query tests #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions assets/tests/query/dynamic_component_query.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local entity_a = world.spawn()
local NewComponent = world.register_new_component("NewComponent")

world.add_default_component(entity_a, NewComponent)

local found_entities = {}
for i,result in pairs(world.query():component(NewComponent):build()) do
table.insert(found_entities, result:entity())
end

assert(#found_entities == 1, "Expected 1 entities, got " .. #found_entities)

expected_entities = {
entity_a
}

for i, entity in ipairs(found_entities) do
assert(entity:index() == expected_entities[i]:index(), "Expected entity " .. expected_entities[i]:index() .. " but got " .. entity:index())
end

17 changes: 17 additions & 0 deletions assets/tests/query/dynamic_component_query.rhai
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let entity_a = world.spawn_.call();
let NewComponent = world.register_new_component.call("NewComponent");

world.add_default_component.call(entity_a, NewComponent);

let found_entities = [];
for (result, i) in world.query.call().component.call(NewComponent).build.call() {
found_entities.push(result.entity.call());
}

assert(found_entities.len == 1, "Expected 1 entities, got " + found_entities.len);

let expected_entities = [entity_a];

for (entity, i) in found_entities {
assert(entity.index.call() == expected_entities[i].index.call(), "Expected entity " + expected_entities[i].index.call() + " but got " + entity.index.call());
}
Loading