Skip to content

Commit

Permalink
Merge pull request #146 from pietrovismara/sliced-query-results
Browse files Browse the repository at this point in the history
✅ classic: test query results to not be altered
  • Loading branch information
krispya authored Jun 24, 2024
2 parents 61f23b0 + a55d336 commit 54ae505
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/classic/test/integration/Query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,58 @@ describe('Query Integration Tests', () => {
expect(ents.length).toBe(1);
expect(ents).toBeInstanceOf(Uint32Array);
});

it('should not alter query results when removing entities', () => {
const world = createWorld();
const TestComponent = defineComponent({ value: Types.f32 });

for (let i = 0; i < 10; i += 1) {
const eid = addEntity(world);
addComponent(world, TestComponent, eid);
}

const results = query(world, [TestComponent]);
const length = results.length;
for (const eid of results) {
removeEntity(world, eid);
}

expect(length).toBe(results.length);
});

it('should not alter query results when removing a query component', () => {
const world = createWorld();
const TestComponent = defineComponent({ value: Types.f32 });

for (let i = 0; i < 10; i += 1) {
const eid = addEntity(world);
addComponent(world, TestComponent, eid);
}

const results = query(world, [TestComponent]);
const length = results.length;
for (const eid of results) {
removeComponent(world, TestComponent, eid);
}

expect(length).toBe(results.length);
});

it('should not alter query results when buffered', () => {
const world = enableBufferedQueries(createWorld());
const TestComponent = defineComponent({ value: Types.f32 });

for (let i = 0; i < 10; i += 1) {
const eid = addEntity(world);
addComponent(world, TestComponent, eid);
}

const results = query(world, [TestComponent]);
const length = results.length;
for (const eid of results) {
removeEntity(world, eid);
}

expect(length).toBe(results.length);
});
});

0 comments on commit 54ae505

Please sign in to comment.