repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
hypr/tests/commands_test.lua
Rawpackage.path = "./?.lua;./?/init.lua;" .. package.path
local calls = {}
hl = {
dsp = {
exec_cmd = function(command)
table.insert(calls, { "exec_cmd", command })
return { kind = "exec", command = command }
end,
focus = function(opts)
table.insert(calls, { "focus", opts.workspace })
return { kind = "focus", workspace = opts.workspace }
end,
window = {
move = function(opts)
table.insert(calls, { "move", opts.workspace })
return { kind = "move", workspace = opts.workspace }
end,
},
},
dispatch = function(dispatcher)
table.insert(calls, { "dispatch", dispatcher.kind, dispatcher.command or dispatcher.workspace })
return "dispatched"
end,
}
local commands = require("modules.commands")
assert(commands.to_dispatcher("firefox").command == "firefox")
assert(commands.to_dispatcher("firefox").kind == "exec")
local dispatcher = { kind = "raw" }
assert(commands.to_dispatcher(dispatcher) == dispatcher)
assert(commands.app("wifi") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "exec")
assert(calls[#calls][3] == "wezterm start --class impala -- impala")
assert(commands.app("battery") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "exec")
assert(calls[#calls][3]:find("wezterm start --class battery -- nu -c", 1, true))
assert(calls[#calls][3]:find("upower -i /org/freedesktop/UPower/devices/battery_BAT0", 1, true))
assert(commands.workspace("3") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "focus")
assert(calls[#calls][3] == "3")
assert(commands.move_to_workspace("4") == "dispatched")
assert(calls[#calls][1] == "dispatch")
assert(calls[#calls][2] == "move")
assert(calls[#calls][3] == "4")
local ok, err = pcall(commands.app, "missing")
assert(not ok)
assert(tostring(err):find("missing", 1, true))
print("commands ok")