fix: action replace/enhance if the replaced/enhanced action as combined (#1814)

This commit is contained in:
Simon Hauser
2022-03-31 18:42:38 +02:00
committed by GitHub
parent b83d6d4711
commit d38ad438f3
2 changed files with 93 additions and 11 deletions

View File

@@ -282,6 +282,70 @@ describe("actions", function()
eq(3, called_count)
end)
it(
"can call replace fn even when combined before replace registered the fn (because that happens with mappings)",
function()
local a = transform_mod {
x = function()
return "x"
end,
y = function()
return "y"
end,
}
local called_count = 0
local count_inc = function()
called_count = called_count + 1
end
local x_plus_y = a.x + a.y
a.x:replace(function()
count_inc()
end)
a.y:replace(function()
count_inc()
end)
x_plus_y()
eq(2, called_count)
end
)
it(
"can call enhance fn even when combined before enhance registed fns (because that happens with mappings)",
function()
local a = transform_mod {
x = function()
return "x"
end,
y = function()
return "y"
end,
}
local called_count = 0
local count_inc = function()
called_count = called_count + 1
end
local x_plus_y = a.x + a.y
a.y:enhance {
pre = count_inc,
post = count_inc,
}
a.x:enhance {
post = count_inc,
}
x_plus_y()
eq(3, called_count)
end
)
it("clears enhance", function()
local a = transform_mod {
x = function()