hold fragments with insert/remove/explicit hooks separately

This commit is contained in:
BlackMATov
2026-03-06 05:59:26 +07:00
parent 39c0b988b5
commit a9fecee874
4 changed files with 380 additions and 91 deletions
+203
View File
@@ -0,0 +1,203 @@
local evo = require 'evolved'
evo.debug_mode(true)
do
local f1, f2 = evo.id(2)
local insert_hook_calls = 0
if f1 < f2 then
evo.set(f1, evo.ON_INSERT, function()
insert_hook_calls = insert_hook_calls + 1
end)
else
evo.set(f2, evo.ON_INSERT, function()
insert_hook_calls = insert_hook_calls + 1
end)
end
do
insert_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
assert(insert_hook_calls == 1)
evo.destroy(e)
end
evo.remove(f1, evo.ON_INSERT)
evo.remove(f2, evo.ON_INSERT)
do
insert_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
assert(insert_hook_calls == 0)
evo.destroy(e)
end
if f1 < f2 then
evo.set(f1, evo.ON_INSERT, function()
insert_hook_calls = insert_hook_calls + 2
end)
else
evo.set(f2, evo.ON_INSERT, function()
insert_hook_calls = insert_hook_calls + 2
end)
end
do
insert_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
assert(insert_hook_calls == 2)
evo.destroy(e)
end
end
do
local f1, f2 = evo.id(2)
local insert_hook_calls = 0
if f1 > f2 then
evo.set(f1, evo.ON_INSERT, function()
insert_hook_calls = insert_hook_calls + 1
end)
else
evo.set(f2, evo.ON_INSERT, function()
insert_hook_calls = insert_hook_calls + 1
end)
end
do
insert_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
assert(insert_hook_calls == 1)
evo.destroy(e)
end
evo.remove(f1, evo.ON_INSERT)
evo.remove(f2, evo.ON_INSERT)
do
insert_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
assert(insert_hook_calls == 0)
evo.destroy(e)
end
if f1 > f2 then
evo.set(f1, evo.ON_INSERT, function()
insert_hook_calls = insert_hook_calls + 2
end)
else
evo.set(f2, evo.ON_INSERT, function()
insert_hook_calls = insert_hook_calls + 2
end)
end
do
insert_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
assert(insert_hook_calls == 2)
evo.destroy(e)
end
end
do
local f1, f2 = evo.id(2)
local remove_hook_calls = 0
if f1 < f2 then
evo.set(f1, evo.ON_REMOVE, function()
remove_hook_calls = remove_hook_calls + 1
end)
else
evo.set(f2, evo.ON_REMOVE, function()
remove_hook_calls = remove_hook_calls + 1
end)
end
do
remove_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
evo.destroy(e)
assert(remove_hook_calls == 1)
end
evo.remove(f1, evo.ON_REMOVE)
evo.remove(f2, evo.ON_REMOVE)
do
remove_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
evo.destroy(e)
assert(remove_hook_calls == 0)
end
if f1 < f2 then
evo.set(f1, evo.ON_REMOVE, function()
remove_hook_calls = remove_hook_calls + 2
end)
else
evo.set(f2, evo.ON_REMOVE, function()
remove_hook_calls = remove_hook_calls + 2
end)
end
do
remove_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
evo.destroy(e)
assert(remove_hook_calls == 2)
end
end
do
local f1, f2 = evo.id(2)
local remove_hook_calls = 0
if f1 > f2 then
evo.set(f1, evo.ON_REMOVE, function()
remove_hook_calls = remove_hook_calls + 1
end)
else
evo.set(f2, evo.ON_REMOVE, function()
remove_hook_calls = remove_hook_calls + 1
end)
end
do
remove_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
evo.destroy(e)
assert(remove_hook_calls == 1)
end
evo.remove(f1, evo.ON_REMOVE)
evo.remove(f2, evo.ON_REMOVE)
do
remove_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
evo.destroy(e)
assert(remove_hook_calls == 0)
end
if f1 > f2 then
evo.set(f1, evo.ON_REMOVE, function()
remove_hook_calls = remove_hook_calls + 2
end)
else
evo.set(f2, evo.ON_REMOVE, function()
remove_hook_calls = remove_hook_calls + 2
end)
end
do
remove_hook_calls = 0
local e = evo.spawn { [f1] = 42, [f2] = 'hello' }
evo.destroy(e)
assert(remove_hook_calls == 2)
end
end
+4 -4
View File
@@ -2928,8 +2928,8 @@ do
last_insert_entity, last_insert_component = 0, 0
local e = evo.spawn({ [f2] = 21, [f1] = true })
assert(set_count == 2 and insert_count == 2)
assert(last_set_entity == e and last_set_component == 21)
assert(last_insert_entity == e and last_insert_component == 21)
assert(last_set_entity == e and (last_set_component == 21 or last_set_component == true))
assert(last_insert_entity == e and (last_insert_component == 21 or last_insert_component == true))
end
do
@@ -2948,8 +2948,8 @@ do
last_insert_entity, last_insert_component = 0, 0
local e = evo.spawn({ [f3] = 33, [f2] = 22 })
assert(set_count == 2 and insert_count == 2)
assert(last_set_entity == e and last_set_component == nil)
assert(last_insert_entity == e and last_insert_component == nil)
assert(last_set_entity == e and (last_set_component == nil or last_set_component == 22))
assert(last_insert_entity == e and (last_insert_component == nil or last_insert_component == 22))
end
end