mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2026-09-18 09:34:36 +07:00
hold fragments with insert/remove/explicit hooks separately
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user