Skip to content

Commit

Permalink
tests(handlers/keys): ensure plugins are only loaded once
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jun 6, 2024
1 parent 4e118be commit 0303315
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lua/lz/n/handler/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,11 @@ function M.add(plugin)
end
end

---@param plugin LzPlugin
function M.del(plugin)
for _, plugins in pairs(M.pending) do
plugins[plugin.name] = nil
end
end

return M
20 changes: 20 additions & 0 deletions spec/keys_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,24 @@ describe("keys", function()
assert.spy(spy_load).called(1)
--
end)
it("Multiple keys only load plugin once", function()
---@param lzkeys LzKeys[]
local function itt(lzkeys)
---@type LzPlugin
local plugin = {
name = "foo",
keys = lzkeys,
}
local spy_load = spy.on(loader, "_load")
state.plugins[plugin.name] = plugin
keys.add(plugin)
local feed1 = vim.api.nvim_replace_termcodes("<Ignore>" .. lzkeys[1].lhs, true, true, true)
vim.api.nvim_feedkeys(feed1, "ix", false)
local feed2 = vim.api.nvim_replace_termcodes("<Ignore>" .. lzkeys[2].lhs, true, true, true)
vim.api.nvim_feedkeys(feed2, "ix", false)
assert.spy(spy_load).called(1)
end
itt({ keys.parse("<leader>tt"), keys.parse("<leader>ff") })
itt({ keys.parse("<leader>ff"), keys.parse("<leader>tt") })
end)
end)

0 comments on commit 0303315

Please sign in to comment.