From afdda32c85dc4442f2eb30d8a0771d689c1adffc Mon Sep 17 00:00:00 2001 From: Ukendio Date: Sun, 12 May 2024 16:54:43 +0200 Subject: [PATCH] Add tests for wildcards --- tests/world.lua | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/tests/world.lua b/tests/world.lua index 0d3a76a..7c8f5f5 100644 --- a/tests/world.lua +++ b/tests/world.lua @@ -18,7 +18,6 @@ TEST("world", function() local world = jecs.World.new() local A = world:component() local B = world:component() - local eA = world:entity() world:set(eA, A, true) local eB = world:entity() @@ -206,7 +205,7 @@ TEST("world", function() CHECK(e == bob) end end - + do CASE "should allow wildcards in queries" local world = jecs.World.new() local Eats = world:entity() @@ -214,16 +213,41 @@ TEST("world", function() local bob = world:entity() world:add(bob, ECS_PAIR(Eats, Apples)) - --testkit.print(world.componentIndex) local w = jecs.Wildcard - for e, bool in world:query(ECS_PAIR(Eats, w)) do + for e in world:query(ECS_PAIR(Eats, w)) do CHECK(e == bob) end - for e, bool in world:query(ECS_PAIR(w, Apples)) do + for e in world:query(ECS_PAIR(w, Apples)) do CHECK(e == bob) end end + + do CASE "should match against multiple pairs" + local world = jecs.World.new() + local Eats = world:entity() + local Apples = world:entity() + local Oranges =world:entity() + local bob = world:entity() + local alice = world:entity() + + world:add(bob, ECS_PAIR(Eats, Apples)) + world:add(alice, ECS_PAIR(Eats, Oranges)) + + local w = jecs.Wildcard + local count = 0 + for e in world:query(ECS_PAIR(Eats, w)) do + count += 1 + end + + CHECK(count == 2) + count = 0 + + for e in world:query(ECS_PAIR(w, Apples)) do + count += 1 + end + CHECK(count == 1) + end end) FINISH() \ No newline at end of file