aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-06-10 10:44:31 +0800
committerGitHub <noreply@github.com>2023-06-10 10:44:31 +0800
commitb6d2f49b4536f89cf2428d1f214468aa5fb21788 (patch)
tree3cbe7946047482cdd0506dbaa31d5fe91a5311b2
parent7154f0c98619d0789618f370a6c7f81ee1775469 (diff)
downloadrneovim-b6d2f49b4536f89cf2428d1f214468aa5fb21788.tar.gz
rneovim-b6d2f49b4536f89cf2428d1f214468aa5fb21788.tar.bz2
rneovim-b6d2f49b4536f89cf2428d1f214468aa5fb21788.zip
test: more tests for nvim_{set,del}_keymap with abbreviation (#23970)
-rw-r--r--runtime/doc/api.txt2
-rw-r--r--runtime/doc/news.txt2
-rw-r--r--src/nvim/api/vim.c2
-rw-r--r--test/functional/api/keymap_spec.lua15
4 files changed, 11 insertions, 10 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index 8c44db1867..748a8ba3bb 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -1487,7 +1487,7 @@ nvim_set_keymap({mode}, {lhs}, {rhs}, {*opts}) *nvim_set_keymap()*
Parameters: ~
• {mode} Mode short-name (map command prefix: "n", "i", "v", "x", …) or
"!" for |:map!|, or empty string for |:map|. "ia", "ca" or
- "!a" for abbreviation in insert mode, cmdline mode, or both,
+ "!a" for abbreviation in Insert mode, Cmdline mode, or both,
respectively
• {lhs} Left-hand-side |{lhs}| of the mapping.
• {rhs} Right-hand-side |{rhs}| of the mapping.
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index a901c4f13c..20d20d9a90 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -82,7 +82,7 @@ The following new APIs or features were added.
• |vim.system()| for running system commands.
-• |nvim_set_keymap()| now supports abbreviations.
+• |nvim_set_keymap()| and |nvim_del_keymap()| now support abbreviations.
==============================================================================
CHANGED FEATURES *news-changed*
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 4bbbf644a8..62b4fd9764 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -1420,7 +1420,7 @@ ArrayOf(Dictionary) nvim_get_keymap(String mode)
/// @param channel_id
/// @param mode Mode short-name (map command prefix: "n", "i", "v", "x", …)
/// or "!" for |:map!|, or empty string for |:map|.
-/// "ia", "ca" or "!a" for abbreviation in insert mode, cmdline mode, or both, respectively
+/// "ia", "ca" or "!a" for abbreviation in Insert mode, Cmdline mode, or both, respectively
/// @param lhs Left-hand-side |{lhs}| of the mapping.
/// @param rhs Right-hand-side |{rhs}| of the mapping.
/// @param opts Optional parameters map: Accepts all |:map-arguments| as keys except |<buffer>|,
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index e56dfd483a..953402ada3 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -400,6 +400,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- maparg(), which does not accept "!" (though it returns "!" in its output
-- if getting a mapping set with |:map!|).
local function normalize_mapmode(mode, generate_expected)
+ if mode:sub(-1) == 'a' then
+ mode = mode:sub(1, -2)
+ end
if not generate_expected and mode == '!' then
-- Cannot retrieve mapmode-ic mappings with "!", but can with "i" or "c".
mode = 'i'
@@ -435,7 +438,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Gets a maparg() dict from Nvim, if one exists.
local function get_mapargs(mode, lhs)
- local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), false, true)
+ local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), mode:sub(-1) == 'a', true)
-- drop "lhsraw" and "lhsrawalt" which are hard to check
mapargs.lhsraw = nil
mapargs.lhsrawalt = nil
@@ -744,7 +747,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)
-- Perform exhaustive tests of basic functionality
- local mapmodes = {'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', ''}
+ local mapmodes = {'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', '', 'ia', 'ca', '!a'}
for _, mapmode in ipairs(mapmodes) do
it('can set/unset normal mappings in mapmode '..mapmode, function()
meths.set_keymap(mapmode, 'lhs', 'rhs', {})
@@ -773,11 +776,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- remove some map arguments that are harder to test, or were already tested
optnames = {'nowait', 'silent', 'expr', 'noremap'}
for _, mapmode in ipairs(mapmodes) do
- local printable_mode = normalize_mapmode(mapmode)
-
-- Test with single mappings
for _, maparg in ipairs(optnames) do
- it('can set/unset '..printable_mode..'-mappings with maparg: '..maparg,
+ it('can set/unset '..mapmode..'-mappings with maparg: '..maparg,
function()
meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = true})
eq(generate_mapargs(mapmode, 'lhs', 'rhs', {[maparg] = true}),
@@ -785,7 +786,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
meths.del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs'))
end)
- it ('can set/unset '..printable_mode..'-mode mappings with maparg '..
+ it ('can set/unset '..mapmode..'-mode mappings with maparg '..
maparg..', whose value is false', function()
meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = false})
eq(generate_mapargs(mapmode, 'lhs', 'rhs'),
@@ -798,7 +799,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Test with triplets of mappings, one of which is false
for i = 1, (#optnames - 2) do
local opt1, opt2, opt3 = optnames[i], optnames[i + 1], optnames[i + 2]
- it('can set/unset '..printable_mode..'-mode mappings with mapargs '..
+ it('can set/unset '..mapmode..'-mode mappings with mapargs '..
opt1..', '..opt2..', '..opt3, function()
local opts = {[opt1] = true, [opt2] = false, [opt3] = true}
meths.set_keymap(mapmode, 'lhs', 'rhs', opts)