From 8ed8c2a0e045a8da96ee40da4e32f1dea5b97488 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Tue, 16 Sep 2025 11:02:52 +0200 Subject: [PATCH] Add granular testing --- addons/ob.luau | 17 ++++++++------ test/addons/ob.luau | 55 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/addons/ob.luau b/addons/ob.luau index 14777aa..6b20c58 100755 --- a/addons/ob.luau +++ b/addons/ob.luau @@ -80,13 +80,13 @@ local function observers_new( local rel = jecs.ECS_PAIR_SECOND(term) local tgt = jecs.ECS_PAIR_SECOND(term) local wc = tgt == jecs.w - local onremoved = world:removed(term, function(entity, id) + local onremoved = world:removed(rel, function(entity, id) + if not wc and term ~= tgt then + return + end local r = jecs.record(world, entity) local archetype = r.archetype if archetype then - if not wc and id ~= tgt then - return - end local dst = jecs.archetype_traverse_remove(world, id, archetype) if archetypes[dst.id] then callback(entity) @@ -218,12 +218,12 @@ local function monitors_new(query: Query): Observer if callback_removed == nil then return end + if not wc and id ~= term then + return + end local r = jecs.record(world, entity) local archetype = r.archetype if archetype then - if not wc and id ~= term then - return - end local dst = jecs.archetype_traverse_remove(world, id, archetype) if archetypes[dst.id] then callback_removed(entity) @@ -234,6 +234,9 @@ local function monitors_new(query: Query): Observer if callback_added == nil then return end + if not wc and id ~= term then + return + end local r = jecs.record(world, entity) local archetype = r.archetype if archetype then diff --git a/test/addons/ob.luau b/test/addons/ob.luau index e877202..00d2e1d 100755 --- a/test/addons/ob.luau +++ b/test/addons/ob.luau @@ -24,12 +24,16 @@ TEST("addons/ob", function() CHECK(c==2) end - do CASE "Should support query:without(pair(R, t1)) when adding pair(R, t2)" + do CASE "Should enter monitor at query:without(pair(R, t1)) when adding pair(R, t2)" local A = world:component() local B = world:component() local C = world:component() local D = world:component() + local e = world:entity() + world:add(e, A) + world:add(e, jecs.pair(B, D)) + local c = 1 local r = 1 local monitor = ob.monitor(world:query(A):without(jecs.pair(B, C))) @@ -51,7 +55,52 @@ TEST("addons/ob", function() CHECK(r==2) end - do CASE "Should support query:without(pair(R, *)) when adding pair(R, t1)" + do CASE "Should enter monitor at query:without(pair(R, t1)) when removing pair(R, t1)" + local A = world:component() + local B = world:component() + local C = world:component() + local D = world:component() + + print("B", B) + + local e = world:entity() + world:add(e, A) + world:add(e, jecs.pair(B, D)) + + local c = 1 + local r = 1 + local monitor = ob.monitor(world:query(A):without(jecs.pair(B, D))) + monitor.added(function() + c += 1 + end) + monitor.removed(function() + r += 1 + end) + + local child = world:entity() + world:add(child, jecs.pair(B, C)) + world:add(child, jecs.pair(B, D)) + CHECK(c==1) + world:add(child, A) + CHECK(c==1) + world:remove(child, jecs.pair(B, C)) + CHECK(c==1) + world:add(child, jecs.pair(B, C)) + CHECK(c==1) + world:remove(child, jecs.pair(B, D)) + CHECK(c==2) + world:add(child, jecs.pair(B, D)) + CHECK(c==2) + CHECK(r==2) + world:remove(child, jecs.pair(B, C)) + CHECK(c==2) + CHECK(r==2) + world:remove(child, jecs.pair(B, D)) + CHECK(c==3) + CHECK(r==2) + end + + do CASE "Should enter monitor at query:without(pair(R, *)) when adding pair(R, t1)" local A = world:component() local B = world:component() local C = world:component() @@ -78,7 +127,7 @@ TEST("addons/ob", function() CHECK(r==2) end - do CASE "Should support query:without()" + do CASE "Should enter monitor at query:without(t1) when removing t1" local A = world:component() local B = world:component()