mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	test: more tests for nvim_{set,del}_keymap with abbreviation (#23970)
This commit is contained in:
		| @@ -1487,7 +1487,7 @@ nvim_set_keymap({mode}, {lhs}, {rhs}, {*opts})             *nvim_set_keymap()* | |||||||
|     Parameters: ~ |     Parameters: ~ | ||||||
|       • {mode}  Mode short-name (map command prefix: "n", "i", "v", "x", …) or |       • {mode}  Mode short-name (map command prefix: "n", "i", "v", "x", …) or | ||||||
|                 "!" for |:map!|, or empty string for |:map|. "ia", "ca" 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 |                 respectively | ||||||
|       • {lhs}   Left-hand-side |{lhs}| of the mapping. |       • {lhs}   Left-hand-side |{lhs}| of the mapping. | ||||||
|       • {rhs}   Right-hand-side |{rhs}| of the mapping. |       • {rhs}   Right-hand-side |{rhs}| of the mapping. | ||||||
|   | |||||||
| @@ -82,7 +82,7 @@ The following new APIs or features were added. | |||||||
|  |  | ||||||
| • |vim.system()| for running system commands. | • |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* | CHANGED FEATURES                                                 *news-changed* | ||||||
|   | |||||||
| @@ -1420,7 +1420,7 @@ ArrayOf(Dictionary) nvim_get_keymap(String mode) | |||||||
| /// @param channel_id | /// @param channel_id | ||||||
| /// @param  mode  Mode short-name (map command prefix: "n", "i", "v", "x", …) | /// @param  mode  Mode short-name (map command prefix: "n", "i", "v", "x", …) | ||||||
| ///               or "!" for |:map!|, or empty string for |:map|. | ///               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  lhs   Left-hand-side |{lhs}| of the mapping. | ||||||
| /// @param  rhs   Right-hand-side |{rhs}| 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>|, | /// @param  opts  Optional parameters map: Accepts all |:map-arguments| as keys except |<buffer>|, | ||||||
|   | |||||||
| @@ -400,6 +400,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() | |||||||
|   -- maparg(), which does not accept "!" (though it returns "!" in its output |   -- maparg(), which does not accept "!" (though it returns "!" in its output | ||||||
|   -- if getting a mapping set with |:map!|). |   -- if getting a mapping set with |:map!|). | ||||||
|   local function normalize_mapmode(mode, generate_expected) |   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 |     if not generate_expected and mode == '!' then | ||||||
|       -- Cannot retrieve mapmode-ic mappings with "!", but can with "i" or "c". |       -- Cannot retrieve mapmode-ic mappings with "!", but can with "i" or "c". | ||||||
|       mode = 'i' |       mode = 'i' | ||||||
| @@ -435,7 +438,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() | |||||||
|  |  | ||||||
|   -- Gets a maparg() dict from Nvim, if one exists. |   -- Gets a maparg() dict from Nvim, if one exists. | ||||||
|   local function get_mapargs(mode, lhs) |   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 |     -- drop "lhsraw" and "lhsrawalt" which are hard to check | ||||||
|     mapargs.lhsraw = nil |     mapargs.lhsraw = nil | ||||||
|     mapargs.lhsrawalt = nil |     mapargs.lhsrawalt = nil | ||||||
| @@ -744,7 +747,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() | |||||||
|   end) |   end) | ||||||
|  |  | ||||||
|   -- Perform exhaustive tests of basic functionality |   -- 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 |   for _, mapmode in ipairs(mapmodes) do | ||||||
|     it('can set/unset normal mappings in mapmode '..mapmode, function() |     it('can set/unset normal mappings in mapmode '..mapmode, function() | ||||||
|       meths.set_keymap(mapmode, 'lhs', 'rhs', {}) |       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 |   -- remove some map arguments that are harder to test, or were already tested | ||||||
|   optnames = {'nowait', 'silent', 'expr', 'noremap'} |   optnames = {'nowait', 'silent', 'expr', 'noremap'} | ||||||
|   for _, mapmode in ipairs(mapmodes) do |   for _, mapmode in ipairs(mapmodes) do | ||||||
|     local printable_mode = normalize_mapmode(mapmode) |  | ||||||
|  |  | ||||||
|     -- Test with single mappings |     -- Test with single mappings | ||||||
|     for _, maparg in ipairs(optnames) do |     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() |           function() | ||||||
|         meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = true}) |         meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = true}) | ||||||
|         eq(generate_mapargs(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') |         meths.del_keymap(mapmode, 'lhs') | ||||||
|         eq({}, get_mapargs(mapmode, 'lhs')) |         eq({}, get_mapargs(mapmode, 'lhs')) | ||||||
|       end) |       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() |           maparg..', whose value is false', function() | ||||||
|         meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = false}) |         meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = false}) | ||||||
|         eq(generate_mapargs(mapmode, 'lhs', 'rhs'), |         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 |     -- Test with triplets of mappings, one of which is false | ||||||
|     for i = 1, (#optnames - 2) do |     for i = 1, (#optnames - 2) do | ||||||
|       local opt1, opt2, opt3 = optnames[i], optnames[i + 1], optnames[i + 2] |       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() |           opt1..', '..opt2..', '..opt3, function() | ||||||
|         local opts = {[opt1] = true, [opt2] = false, [opt3] = true} |         local opts = {[opt1] = true, [opt2] = false, [opt3] = true} | ||||||
|         meths.set_keymap(mapmode, 'lhs', 'rhs', opts) |         meths.set_keymap(mapmode, 'lhs', 'rhs', opts) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zeertzjq
					zeertzjq