Fix tests for matrix.eventable
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
local eventable = require "matrix.eventable"
|
local eventable = require "matrix.eventable"
|
||||||
|
|
||||||
do -- Simple event
|
do -- Simple event
|
||||||
local fire, hook = assert(eventable())
|
local fire, hook = assert(eventable.functions())
|
||||||
local flag = false
|
local flag = false
|
||||||
hook("foo", function () flag = true end)
|
hook("foo", function () flag = true end)
|
||||||
fire("foo")
|
fire("foo")
|
||||||
@@ -16,7 +16,7 @@ do -- Simple event
|
|||||||
end
|
end
|
||||||
|
|
||||||
do -- Stop at first handler that returns some value
|
do -- Stop at first handler that returns some value
|
||||||
local fire, hook = assert(eventable())
|
local fire, hook = assert(eventable.functions())
|
||||||
local flag1, flag2, flag3 = false, false, false
|
local flag1, flag2, flag3 = false, false, false
|
||||||
hook("foo", function () flag1 = true end)
|
hook("foo", function () flag1 = true end)
|
||||||
hook("foo", function () flag2 = true ; return 42 end)
|
hook("foo", function () flag2 = true ; return 42 end)
|
||||||
@@ -29,7 +29,7 @@ end
|
|||||||
|
|
||||||
do -- Arguments to eventable() are passed to handlers
|
do -- Arguments to eventable() are passed to handlers
|
||||||
local obj = { answer = 42 }
|
local obj = { answer = 42 }
|
||||||
local fire, hook = assert(eventable(obj))
|
local fire, hook = assert(eventable.functions(obj))
|
||||||
hook("foo", function (o)
|
hook("foo", function (o)
|
||||||
assert(o == obj)
|
assert(o == obj)
|
||||||
assert(o.answer == 42)
|
assert(o.answer == 42)
|
||||||
@@ -40,7 +40,7 @@ do -- Arguments to eventable() are passed to handlers
|
|||||||
end
|
end
|
||||||
|
|
||||||
do -- Multiple arguments passed to eventable
|
do -- Multiple arguments passed to eventable
|
||||||
local fire, hook = assert(eventable(42, "bar", nil, { v=10 }))
|
local fire, hook = assert(eventable.functions(42, "bar", nil, { v=10 }))
|
||||||
hook("foo", function (a, s, n, o)
|
hook("foo", function (a, s, n, o)
|
||||||
assert(a == 42)
|
assert(a == 42)
|
||||||
assert(s == "bar")
|
assert(s == "bar")
|
||||||
@@ -55,7 +55,7 @@ do -- Unhooking should work
|
|||||||
local h1 = function () flag1 = true end
|
local h1 = function () flag1 = true end
|
||||||
local h2 = function () flag2 = true end
|
local h2 = function () flag2 = true end
|
||||||
|
|
||||||
local fire, hook, unhook = assert(eventable())
|
local fire, hook, unhook = assert(eventable.functions())
|
||||||
hook("foo", h1)
|
hook("foo", h1)
|
||||||
hook("foo", h2)
|
hook("foo", h2)
|
||||||
fire("foo")
|
fire("foo")
|
||||||
|
|||||||
Reference in New Issue
Block a user