local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local clear = n.clear
local command = n.command
local eq, neq = t.eq, t.neq
local exec_lua = n.exec_lua
local exec = n.exec
local feed = n.feed
local fn = n.fn
local api = n.api
local matches = t.matches
local source = n.source
local pcall_err = t.pcall_err
local shallowcopy = t.shallowcopy
local sleep = vim.uv.sleep
local sid_api_client = -9
local sid_lua = -8
local mode_bits_map = {
['n'] = 0x01,
['x'] = 0x02,
['o'] = 0x04,
['c'] = 0x08,
['i'] = 0x10,
['l'] = 0x20,
['s'] = 0x40,
['t'] = 0x80,
[' '] = 0x47,
['v'] = 0x42,
['!'] = 0x18,
}
describe('nvim_get_keymap', function()
local function keymap_info(overrides)
return vim.tbl_extend('force', {
script = 0,
silent = 0,
expr = 0,
replace_keycodes = 0,
sid = 0,
scriptversion = 1,
buf = 0,
buffer = 0, -- deprecated
nowait = 0,
abbr = 0,
noremap = 1,
lnum = 0,
}, overrides)
end
before_each(clear)
-- Basic mapping and table to be used to describe results
local foo_bar_string = 'nnoremap foo bar'
local foo_bar_map_table = keymap_info({
lhs = 'foo',
lhsraw = 'foo',
rhs = 'bar',
mode = 'n',
mode_bits = 0x01,
})
it('returns empty list when no map', function()
eq({}, api.nvim_get_keymap('n'))
end)
it('returns list of all applicable mappings', function()
command(foo_bar_string)
-- Only one mapping available. Should be the same as `foo_bar_map_table`, and maparg() result
-- (plus "buf"), since this is a global map.
eq({ foo_bar_map_table }, api.nvim_get_keymap('n'))
-- Add "buf" key to maparg() result.
local maparg_rv = vim.tbl_deep_extend('force', fn.maparg('foo', 'n
|