aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/keymap_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-01-25 18:31:31 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-01-25 18:31:31 +0000
commit9243becbedbb6a1592208051f8fa2b090dcc5e7d (patch)
tree607c2a862ec3f4399b8766383f6f8e04c4aa43b4 /test/functional/api/keymap_spec.lua
parent9e40b6e9e1bc67f2d856adb837ee64dd0e25b717 (diff)
parent3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff)
downloadrneovim-usermarks.tar.gz
rneovim-usermarks.tar.bz2
rneovim-usermarks.zip
Merge remote-tracking branch 'upstream/master' into usermarksusermarks
Diffstat (limited to 'test/functional/api/keymap_spec.lua')
-rw-r--r--test/functional/api/keymap_spec.lua46
1 files changed, 32 insertions, 14 deletions
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index a93a4544ff..5be4425162 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -6,6 +6,7 @@ local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq, neq = helpers.eq, helpers.neq
local exec_lua = helpers.exec_lua
+local exec = helpers.exec
local feed = helpers.feed
local funcs = helpers.funcs
local meths = helpers.meths
@@ -336,21 +337,26 @@ describe('nvim_get_keymap', function()
end)
it('can handle lua mappings', function()
- eq(0, exec_lua [[
+ eq(0, exec_lua([[
GlobalCount = 0
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
return GlobalCount
- ]])
+ ]]))
feed('asdf\n')
- eq(1, exec_lua[[return GlobalCount]])
+ eq(1, exec_lua([[return GlobalCount]]))
- eq(2, exec_lua[[
+ eq(2, exec_lua([[
vim.api.nvim_get_keymap('n')[1].callback()
return GlobalCount
+ ]]))
+
+ exec([[
+ call nvim_get_keymap('n')[0].callback()
]])
+ eq(3, exec_lua([[return GlobalCount]]))
+
local mapargs = meths.get_keymap('n')
- assert(type(mapargs[1].callback) == 'number', 'callback is not luaref number')
mapargs[1].callback = nil
eq({
lhs='asdf',
@@ -834,17 +840,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)
it ('maparg() returns lua mapping correctly', function()
- exec_lua [[
- vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end })
- ]]
- assert.truthy(string.match(funcs.maparg('asdf', 'n'),
- "^<Lua %d+>"))
+ eq(0, exec_lua([[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ return GlobalCount
+ ]]))
+
+ assert.truthy(string.match(funcs.maparg('asdf', 'n'), "^<Lua %d+>"))
+
local mapargs = funcs.maparg('asdf', 'n', false, true)
- assert(type(mapargs.callback) == 'number', 'callback is not luaref number')
mapargs.callback = nil
mapargs.lhsraw = nil
mapargs.lhsrawalt = nil
eq(generate_mapargs('n', 'asdf', nil, {sid=sid_lua}), mapargs)
+
+ eq(1, exec_lua([[
+ vim.fn.maparg('asdf', 'n', false, true).callback()
+ return GlobalCount
+ ]]))
+
+ exec([[
+ call maparg('asdf', 'n', v:false, v:true).callback()
+ ]])
+ eq(2, exec_lua([[return GlobalCount]]))
end)
it('can make lua expr mappings replacing keycodes', function()
@@ -867,7 +885,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
eq({'<space>'}, meths.buf_get_lines(0, 0, -1, false))
end)
- it('lua expr mapping returning nil is equivalent to returnig an empty string', function()
+ it('lua expr mapping returning nil is equivalent to returning an empty string', function()
exec_lua [[
vim.api.nvim_set_keymap ('i', 'aa', '', {callback = function() return nil end, expr = true })
]]
@@ -1048,7 +1066,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
eq({'rhs'}, bufmeths.get_lines(0, 0, 1, 1))
end)
- it("does not crash when setting keymap in a non-existing buffer #13541", function()
+ it("does not crash when setting mapping in a non-existing buffer #13541", function()
pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs<Esc>', {})
helpers.assert_alive()
end)