Compare commits
2 Commits
dcee9d9553
...
d0dda9399e
Author | SHA1 | Date |
---|---|---|
Aire-One | d0dda9399e | |
Aire-One | d4add4fb8a |
|
@ -6,6 +6,7 @@ include_files = {
|
|||
".busted",
|
||||
".luacheckrc",
|
||||
"*.rockspec",
|
||||
"spec/",
|
||||
"src/",
|
||||
"config.ld",
|
||||
}
|
||||
|
|
|
@ -2,8 +2,16 @@ local slot = require "awesome-slot"
|
|||
|
||||
local function new_target()
|
||||
return {
|
||||
connect_signal = spy.new(function() end),
|
||||
disconnect_signal = spy.new(function() end),
|
||||
signal = nil, -- Only need to bind 1 signal in the tests
|
||||
connect_signal = function(self, _signal_name, signal_callback)
|
||||
self.signal = signal_callback
|
||||
end,
|
||||
disconnect_signal = function()
|
||||
-- Unimplemented
|
||||
end,
|
||||
emit_signal = function(self, _signal_name, ...)
|
||||
self.signal(...)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -121,4 +129,47 @@ describe("Awesome-slot", function()
|
|||
|
||||
assert.is_not_nil(s.id)
|
||||
end)
|
||||
|
||||
it("should manage slot parameters", function()
|
||||
local target = new_target()
|
||||
local signal_name = "signal"
|
||||
local params = { key = "value" }
|
||||
local callback = spy.new(function(p)
|
||||
return function()
|
||||
assert.same(params, p)
|
||||
end
|
||||
end)
|
||||
|
||||
slot {
|
||||
target = target,
|
||||
signal = signal_name,
|
||||
slot = callback,
|
||||
slot_params = params,
|
||||
connect = true,
|
||||
}
|
||||
|
||||
target:emit_signal(signal_name)
|
||||
assert.spy(callback).called()
|
||||
end)
|
||||
|
||||
it("should retrieve signal parameters", function()
|
||||
local target = new_target()
|
||||
local signal_name = "signal"
|
||||
local callback = spy.new(function()
|
||||
return function(a, b, c)
|
||||
assert.equal(a, 1)
|
||||
assert.equal(b, 2)
|
||||
assert.equal(c, 3)
|
||||
end
|
||||
end)
|
||||
|
||||
slot {
|
||||
target = target,
|
||||
signal = signal_name,
|
||||
slot = callback,
|
||||
connect = true,
|
||||
}
|
||||
|
||||
target:emit_signal(signal_name, 1, 2, 3)
|
||||
end)
|
||||
end)
|
||||
|
|
|
@ -120,14 +120,8 @@ function awesome_slot.create(params)
|
|||
slot.target = params.target
|
||||
slot.signal = params.signal
|
||||
slot.connected = false
|
||||
|
||||
if params.slot_params then
|
||||
slot.params = params.slot_params
|
||||
slot.callback = function()
|
||||
params.slot(slot.params)
|
||||
end
|
||||
else
|
||||
slot.callback = params.slot
|
||||
slot.callback = function(...)
|
||||
params.slot(params.slot_params)(...)
|
||||
end
|
||||
|
||||
-- Insert the new slot into the slots list
|
||||
|
|
Loading…
Reference in New Issue