diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 7d6445f49c..b7858888c4 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -17,16 +17,16 @@ describe('get_keymap', function() -- Basic mapping and table to be used to describe results local foo_bar_string = 'nnoremap foo bar' local foo_bar_map_table = { - lhs='foo', - silent=0, - rhs='bar', - expr=0, - sid=0, - buffer=0, - nowait=0, - mode='n', - noremap=1, - } + lhs='foo', + silent=0, + rhs='bar', + expr=0, + sid=0, + buffer=0, + nowait=0, + mode='n', + noremap=1, + } it('returns empty list when no map', function() eq({}, meths.get_keymap('n')) @@ -238,4 +238,56 @@ describe('get_keymap', function() eq('', meths.get_keymap('n')[1]['lhs']) eq(':let g:maparg_test_var = 1', meths.get_keymap('n')[1]['rhs']) end) + + it('works correctly despite various &cpo settings', function() + local cpo_table = { + silent=0, + expr=0, + sid=0, + buffer=0, + nowait=0, + noremap=1, + } + local function cpomap(lhs, rhs, mode) + local ret = shallowcopy(cpo_table) + ret.lhs = lhs + ret.rhs = rhs + ret.mode = mode + return ret + end + + command('set cpo-=< cpo+=B') + command('nnoremap \\ \\') + command('nnoremap \\ \\') + + command('set cpo+=B<') + command('xnoremap \\ \\') + command('xnoremap \\ \\') + + command('set cpo-=B<') + command('snoremap \\ \\') + command('snoremap \\ \\') + + command('set cpo-=B cpo+=<') + command('onoremap \\ \\') + command('onoremap \\ \\') + + for _, cmd in ipairs({ + 'set cpo-=B cpo+=<', + 'set cpo-=B<', + 'set cpo+=B<', + 'set cpo-=< cpo+=B', + }) do + command(cmd) + eq({cpomap('\\', '\\', 'n'), cpomap('\\', '\\', 'n')}, + meths.get_keymap('n')) + -- FIXME + -- eq({cpomap('\\', '\\', 'x'), cpomap('\\C-A>', '\\C-B>', 'x')}, + -- meths.get_keymap('x')) + -- eq({cpomap('C-C>', 'C-D>', 's'), cpomap('C-A>', 'C-B>', 's')}, + -- meths.get_keymap('x')) + -- eq({cpomap('C-C>', 'C-D>', 'o'), cpomap('C-A>', 'C-B>', 'o')}, + -- meths.get_keymap('x')) + end + end) end)