diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-11-09 21:53:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-09 21:53:34 +0800 |
commit | 267c346e2cd10081bfebe86be59f137a1b7470e5 (patch) | |
tree | 8a17cad14b298c4f62c793da95c6d59924e82b84 /test/functional/api/keymap_spec.lua | |
parent | 610f50ddaff260e2e2f7236f6a3982ee7554c2a6 (diff) | |
parent | 04d299c17014b0802c79613252e4de26da84a7c9 (diff) | |
download | rneovim-267c346e2cd10081bfebe86be59f137a1b7470e5.tar.gz rneovim-267c346e2cd10081bfebe86be59f137a1b7470e5.tar.bz2 rneovim-267c346e2cd10081bfebe86be59f137a1b7470e5.zip |
Merge pull request #25951 from zeertzjq/vim-8.2.4140
vim-patch:8.2.{4140,4820,4825,4861,4932}
Diffstat (limited to 'test/functional/api/keymap_spec.lua')
-rw-r--r-- | test/functional/api/keymap_spec.lua | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 811c4210fa..3af1faaece 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -19,6 +19,20 @@ local sleep = helpers.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() before_each(clear) @@ -32,9 +46,12 @@ describe('nvim_get_keymap', function() rhs='bar', expr=0, sid=0, + scriptversion=1, buffer=0, nowait=0, mode='n', + mode_bits=0x01, + abbr=0, noremap=1, lnum=0, } @@ -81,6 +98,7 @@ describe('nvim_get_keymap', function() -- The table will be the same except for the mode local insert_table = shallowcopy(foo_bar_map_table) insert_table['mode'] = 'i' + insert_table['mode_bits'] = 0x10 eq({insert_table}, meths.get_keymap('i')) end) @@ -258,8 +276,10 @@ describe('nvim_get_keymap', function() silent=0, expr=0, sid=0, + scriptversion=1, buffer=0, nowait=0, + abbr=0, noremap=1, lnum=0, } @@ -268,6 +288,7 @@ describe('nvim_get_keymap', function() ret.lhs = lhs ret.rhs = rhs ret.mode = mode + ret.mode_bits = mode_bits_map[mode] return ret end @@ -323,10 +344,13 @@ describe('nvim_get_keymap', function() lhsraw='| |', rhs='| |', mode='n', + mode_bits=0x01, + abbr=0, script=0, silent=0, expr=0, sid=0, + scriptversion=1, buffer=0, nowait=0, noremap=1, @@ -365,15 +389,18 @@ describe('nvim_get_keymap', function() silent=0, expr=0, sid=sid_lua, + scriptversion=1, buffer=0, nowait=0, mode='n', + mode_bits=0x01, + abbr=0, noremap=0, lnum=0, }, mapargs[1]) end) - it ('can handle map descriptions', function() + it('can handle map descriptions', function() meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"}) eq({ lhs='lhs', @@ -383,9 +410,12 @@ describe('nvim_get_keymap', function() silent=0, expr=0, sid=sid_api_client, + scriptversion=1, buffer=0, nowait=0, mode='n', + mode_bits=0x01, + abbr=0, noremap=0, lnum=0, desc='map description' @@ -420,7 +450,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end local to_return = {} - to_return.mode = normalize_mapmode(mode, true) + local expected_mode = normalize_mapmode(mode, true) + to_return.mode = expected_mode + to_return.mode_bits = mode_bits_map[expected_mode] + to_return.abbr = mode:sub(-1) == 'a' and 1 or 0 to_return.noremap = not opts.noremap and 0 or 1 to_return.lhs = lhs to_return.rhs = rhs @@ -429,6 +462,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() to_return.nowait = not opts.nowait and 0 or 1 to_return.expr = not opts.expr and 0 or 1 to_return.sid = not opts.sid and sid_api_client or opts.sid + to_return.scriptversion = 1 to_return.buffer = not opts.buffer and 0 or opts.buffer to_return.lnum = not opts.lnum and 0 or opts.lnum to_return.desc = opts.desc @@ -487,7 +521,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function() get_mapargs('', 'lhs')) end) - it('throws errors when given too-long mode shortnames', function() + it('error on invalid mode shortname', function() + eq('Invalid mode shortname: " "', pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "m"', pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "?"', pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "y"', pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "p"', pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "a"', pcall_err(meths.set_keymap, 'a', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "oa"', pcall_err(meths.set_keymap, 'oa', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "!o"', pcall_err(meths.set_keymap, '!o', 'lhs', 'rhs', {})) @@ -496,6 +535,11 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('Invalid mode shortname: "map"', pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "vmap"', pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: " "', pcall_err(meths.del_keymap, ' ', 'lhs')) + eq('Invalid mode shortname: "m"', pcall_err(meths.del_keymap, 'm', 'lhs')) + eq('Invalid mode shortname: "?"', pcall_err(meths.del_keymap, '?', 'lhs')) + eq('Invalid mode shortname: "y"', pcall_err(meths.del_keymap, 'y', 'lhs')) + eq('Invalid mode shortname: "p"', pcall_err(meths.del_keymap, 'p', 'lhs')) eq('Invalid mode shortname: "a"', pcall_err(meths.del_keymap, 'a', 'lhs')) eq('Invalid mode shortname: "oa"', pcall_err(meths.del_keymap, 'oa', 'lhs')) eq('Invalid mode shortname: "!o"', pcall_err(meths.del_keymap, '!o', 'lhs')) @@ -506,22 +550,6 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.del_keymap, 'xnoremap', 'lhs')) end) - it('error on invalid mode shortname', function() - eq('Invalid mode shortname: " "', - pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "m"', - pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "?"', - pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "y"', - pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "p"', - pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "?"', pcall_err(meths.del_keymap, '?', 'lhs')) - eq('Invalid mode shortname: "y"', pcall_err(meths.del_keymap, 'y', 'lhs')) - eq('Invalid mode shortname: "p"', pcall_err(meths.del_keymap, 'p', 'lhs')) - end) - it('error on invalid optnames', function() eq("Invalid key: 'silentt'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {silentt = true})) @@ -827,7 +855,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq(1, exec_lua[[return GlobalCount]]) end) - it (':map command shows lua mapping correctly', function() + it(':map command shows lua mapping correctly', function() exec_lua [[ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] @@ -839,7 +867,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() ) end) - it ('mapcheck() returns lua mapping correctly', function() + it('mapcheck() returns lua mapping correctly', function() exec_lua [[ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] @@ -847,7 +875,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() "^<Lua %d+>")) end) - it ('maparg() returns lua mapping correctly', function() + it('maparg() returns lua mapping correctly', function() eq(0, exec_lua([[ GlobalCount = 0 vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) |