mirror of
https://github.com/Ukendio/jecs.git
synced 2025-09-16 21:39:17 +00:00
Add granular testing
Some checks are pending
Some checks are pending
This commit is contained in:
parent
23bf021f01
commit
8ed8c2a0e0
2 changed files with 62 additions and 10 deletions
|
@ -80,13 +80,13 @@ local function observers_new<T...>(
|
|||
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<T...>(query: Query<T...>): Observer<T...>
|
|||
if callback_removed == nil 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 r = jecs.record(world, entity)
|
||||
local archetype = r.archetype
|
||||
if archetype then
|
||||
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<T...>(query: Query<T...>): Observer<T...>
|
|||
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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue