feat: add unit tests
This commit is contained in:
parent
44686975f4
commit
dcee9d9553
|
@ -0,0 +1,13 @@
|
|||
name: test
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
busted:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Run Busted
|
||||
uses: lunarmodules/busted@v2.2.0
|
|
@ -3,6 +3,7 @@ std = "min"
|
|||
cache = true
|
||||
|
||||
include_files = {
|
||||
".busted",
|
||||
".luacheckrc",
|
||||
"*.rockspec",
|
||||
"src/",
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
},
|
||||
"stylua.targetReleaseVersion": "latest",
|
||||
"files.associations": {
|
||||
".busted": "lua",
|
||||
".luacheckrc": "lua",
|
||||
"*.rockspec": "lua",
|
||||
"config.ld": "lua"
|
||||
|
|
3
Makefile
3
Makefile
|
@ -22,3 +22,6 @@ lint: luacheck stylua ldoc-dryrun cspell lint-rockspec
|
|||
|
||||
ldoc:
|
||||
ldoc .
|
||||
|
||||
test:
|
||||
luarocks test
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
rockspec_format = "3.0"
|
||||
|
||||
package = "awesome-slot"
|
||||
version = "dev-1"
|
||||
|
||||
source = {
|
||||
url = "git+https://github.com/Aire-One/awesome-slot.git",
|
||||
}
|
||||
|
||||
description = {
|
||||
summary = "A declarative API to connect signals for the AwesomeWM.",
|
||||
detailed = "A declarative API to connect signals for the AwesomeWM.",
|
||||
|
@ -15,6 +18,7 @@ description = {
|
|||
"declarative",
|
||||
},
|
||||
}
|
||||
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
|
@ -29,3 +33,7 @@ build = {
|
|||
"doc",
|
||||
},
|
||||
}
|
||||
|
||||
test = {
|
||||
type = "busted",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
-- Fake awesome modules
|
||||
package.loaded["gears.table"] = {
|
||||
hasitem = function(t, item)
|
||||
for k, v in pairs(t) do
|
||||
if v == item then
|
||||
return k
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
package.loaded["ruled.client"] = {}
|
||||
|
||||
package.loaded["ruled.notification"] = {}
|
||||
|
||||
package.loaded["awful.keyboard"] = {
|
||||
append_client_keybindings = function() end,
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
local slot = require "awesome-slot"
|
||||
|
||||
local function new_target()
|
||||
return {
|
||||
connect_signal = spy.new(function() end),
|
||||
disconnect_signal = spy.new(function() end),
|
||||
}
|
||||
end
|
||||
|
||||
describe("Awesome-slot", function()
|
||||
it("should create slot", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
}
|
||||
|
||||
assert.is_not_nil(s)
|
||||
end)
|
||||
|
||||
it("should remove slot", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
}
|
||||
|
||||
slot.remove(s)
|
||||
|
||||
assert.is_nil(slot.get_slot(s))
|
||||
end)
|
||||
|
||||
it("should connect slot (from constructor parameters)", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
connect = true,
|
||||
}
|
||||
|
||||
assert.is_true(s.connected)
|
||||
end)
|
||||
|
||||
it("should connect signal", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
}
|
||||
|
||||
slot.connect(s)
|
||||
|
||||
assert.is_true(s.connected)
|
||||
end)
|
||||
|
||||
it("should disconnect slot", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
connect = true,
|
||||
}
|
||||
|
||||
slot.disconnect(s)
|
||||
|
||||
assert.is_false(s.connected)
|
||||
end)
|
||||
|
||||
it("should get slot", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
}
|
||||
|
||||
assert.is_not_nil(slot.get_slot(s))
|
||||
end)
|
||||
|
||||
it("should get slot by id", function()
|
||||
local target = new_target()
|
||||
local id = "SOME_ID"
|
||||
|
||||
slot {
|
||||
id = id,
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
}
|
||||
|
||||
assert.is_not_nil(slot.get_slot(id))
|
||||
end)
|
||||
|
||||
it("should generate id", function()
|
||||
local target = new_target()
|
||||
|
||||
local s = slot {
|
||||
target = target,
|
||||
signal = "signal",
|
||||
slot = function() end,
|
||||
slot_params = { key = "value" },
|
||||
}
|
||||
|
||||
assert.is_not_nil(s.id)
|
||||
end)
|
||||
end)
|
|
@ -186,9 +186,9 @@ function awesome_slot.disconnect(slot)
|
|||
|
||||
-- Please check the `:connect_slot` method to understand why we do this.
|
||||
if gtable.hasitem(awesome_slot.static_connect, s.target) then
|
||||
s.target.disconnect_slot(s.signal, s.callback)
|
||||
s.target.disconnect_signal(s.signal, s.callback)
|
||||
else
|
||||
s.target:disconnect_slot(s.signal, s.callback)
|
||||
s.target:disconnect_signal(s.signal, s.callback)
|
||||
end
|
||||
|
||||
s.connected = false
|
||||
|
|
Loading…
Reference in New Issue