mode: enter/exit debug mode with keybinding lifecycle

This commit is contained in:
swaits committed 2026-04-11 16:36:55 -06:00
1 parent 628b7b7737
commit 78a43da5d1
5 files changed
+219

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
-- tests for keybinding stash/restore
local td = require("tiny-debugger")
local function assert_eq(a, b, msg)
if a ~= b then
error(string.format("FAIL: %s — expected %s, got %s", msg, vim.inspect(b), vim.inspect(a)))
end
end
-- set a custom mapping for 'c'
local custom_called = false
vim.keymap.set("n", "c", function() custom_called = true end, { buffer = 0, desc = "custom c" })
-- verify custom mapping exists
local maparg = vim.fn.maparg("c", "n", false, true)
assert_eq(maparg.desc, "custom c", "custom mapping exists before enter")
-- enter debug mode — should override 'c'
td.toggle()
maparg = vim.fn.maparg("c", "n", false, true)
assert_eq(maparg.desc, "tiny-debugger: continue", "c overridden in debug mode")
-- exit debug mode — should restore custom 'c'
td.toggle()
maparg = vim.fn.maparg("c", "n", false, true)
assert_eq(maparg.desc, "custom c", "custom mapping restored after exit")
print("ALL KEY STASH/RESTORE TESTS PASSED")
+42
View File
@@ -0,0 +1,42 @@
-- tests for debug mode enter/exit
local td = require("tiny-debugger")
local mode = require("tiny-debugger.mode")
local function assert_eq(a, b, msg)
if a ~= b then
error(string.format("FAIL: %s — expected %s, got %s", msg, vim.inspect(b), vim.inspect(a)))
end
end
local function has_buf_map(key)
local maps = vim.api.nvim_buf_get_keymap(0, "n")
for _, m in ipairs(maps) do
if m.lhs == key then return true end
end
return false
end
-- test 1: starts inactive
assert_eq(td.active(), false, "starts inactive")
-- test 2: toggle enters debug mode
td.toggle()
assert_eq(td.active(), true, "active after toggle")
-- test 3: keymaps are set
assert_eq(has_buf_map("c"), true, "continue key mapped")
assert_eq(has_buf_map("s"), true, "step_over key mapped")
assert_eq(has_buf_map("d"), true, "step_into key mapped")
assert_eq(has_buf_map("r"), true, "step_out key mapped")
assert_eq(has_buf_map("q"), true, "terminate key mapped")
-- test 4: toggle exits debug mode
td.toggle()
assert_eq(td.active(), false, "inactive after second toggle")
-- test 5: keymaps are removed
assert_eq(has_buf_map("c"), false, "continue key removed")
assert_eq(has_buf_map("s"), false, "step_over key removed")
assert_eq(has_buf_map("q"), false, "terminate key removed")
print("ALL MODE TESTS PASSED")