-- @runtimes lua54 --- 演示:注册 keymap 的 stub 断言。 local M = {} local function setup(vim) vim.keymap.set("n", "h", function() vim.api.nvim_out_write("hi") end, { desc = "say hi" }) end --- @return table { registered = boolean, mode = string, lhs = string } function M.run(log) log = log or print local registered = false local mode, lhs local vim = { keymap = { set = function(m, key) registered = true mode, lhs = m, key end, }, api = { nvim_out_write = function() end }, } setup(vim) log(("registered=%s mode=%s lhs=%s"):format(tostring(registered), mode, lhs)) return { registered = registered, mode = mode, lhs = lhs } end if not ... then M.run() end return M