From 3c667d3e0fe41a900cee9477e190ae02d7ec0c23 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 23 Dec 2023 15:30:44 +0800 Subject: fix(mappings): fix mapset() not replacing map with backslash (#26719) --- test/functional/vimscript/map_functions_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/functional/vimscript/map_functions_spec.lua') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index acba5e9708..e3cc653e12 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -180,6 +180,16 @@ end) describe('mapset()', function() before_each(clear) + it('can restore mapping with backslash in lhs', function() + meths.set_keymap('n', '\\ab', 'a', {}) + eq('\nn \\ab a', exec_capture("nmap \\ab")) + local mapargs = funcs.maparg('\\ab', 'n', false, true) + meths.set_keymap('n', '\\ab', 'b', {}) + eq('\nn \\ab b', exec_capture("nmap \\ab")) + funcs.mapset('n', false, mapargs) + eq('\nn \\ab a', exec_capture("nmap \\ab")) + end) + it('can restore mapping description from the dict returned by maparg()', function() meths.set_keymap('n', 'lhs', 'rhs', {desc = 'map description'}) eq('\nn lhs rhs\n map description', exec_capture("nmap lhs")) -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/vimscript/map_functions_spec.lua | 85 +++++++++++++----------- 1 file changed, 46 insertions(+), 39 deletions(-) (limited to 'test/functional/vimscript/map_functions_spec.lua') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index e3cc653e12..b0c4a9747a 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -19,22 +19,22 @@ describe('maparg()', function() before_each(clear) local foo_bar_map_table = { - lhs='foo', - lhsraw='foo', - script=0, - silent=0, - rhs='bar', - expr=0, - sid=0, - scriptversion=1, - buffer=0, - nowait=0, - mode='n', - mode_bits=0x01, - abbr=0, - noremap=1, - lnum=0, - } + lhs = 'foo', + lhsraw = 'foo', + script = 0, + silent = 0, + rhs = 'bar', + expr = 0, + sid = 0, + scriptversion = 1, + buffer = 0, + nowait = 0, + mode = 'n', + mode_bits = 0x01, + abbr = 0, + noremap = 1, + lnum = 0, + } it('returns a dictionary', function() nvim('command', 'nnoremap foo bar') @@ -64,7 +64,7 @@ describe('maparg()', function() eq( funcs.maparg('hello', 'i', false, true)['noremap'], funcs.maparg('this', 'i', false, true)['noremap'] - ) + ) end) it('returns a boolean for buffer', function() @@ -135,7 +135,7 @@ describe('maparg()', function() it('works with combining characters', function() -- Using addacutes to make combining character better visible local function ac(s) - local acute = '\204\129' -- U+0301 COMBINING ACUTE ACCENT + local acute = '\204\129' -- U+0301 COMBINING ACUTE ACCENT local ret = s:gsub('`', acute) return ret end @@ -145,8 +145,8 @@ describe('maparg()', function() nnoremap e` f` ]])) eq(ac('b`'), funcs.maparg(ac('a'))) - eq(ac(''), funcs.maparg(ac('c'))) - eq(ac('d'), funcs.maparg(ac('c`'))) + eq(ac(''), funcs.maparg(ac('c'))) + eq(ac('d'), funcs.maparg(ac('c`'))) eq(ac('f`'), funcs.maparg(ac('e`'))) local function acmap(lhs, rhs) @@ -170,9 +170,9 @@ describe('maparg()', function() } end - eq({}, funcs.maparg(ac('c'), 'n', 0, 1)) - eq(acmap('a', 'b`'), funcs.maparg(ac('a'), 'n', 0, 1)) - eq(acmap('c`', 'd'), funcs.maparg(ac('c`'), 'n', 0, 1)) + eq({}, funcs.maparg(ac('c'), 'n', 0, 1)) + eq(acmap('a', 'b`'), funcs.maparg(ac('a'), 'n', 0, 1)) + eq(acmap('c`', 'd'), funcs.maparg(ac('c`'), 'n', 0, 1)) eq(acmap('e`', 'f`'), funcs.maparg(ac('e`'), 'n', 0, 1)) end) end) @@ -182,30 +182,30 @@ describe('mapset()', function() it('can restore mapping with backslash in lhs', function() meths.set_keymap('n', '\\ab', 'a', {}) - eq('\nn \\ab a', exec_capture("nmap \\ab")) + eq('\nn \\ab a', exec_capture('nmap \\ab')) local mapargs = funcs.maparg('\\ab', 'n', false, true) meths.set_keymap('n', '\\ab', 'b', {}) - eq('\nn \\ab b', exec_capture("nmap \\ab")) + eq('\nn \\ab b', exec_capture('nmap \\ab')) funcs.mapset('n', false, mapargs) - eq('\nn \\ab a', exec_capture("nmap \\ab")) + eq('\nn \\ab a', exec_capture('nmap \\ab')) end) it('can restore mapping description from the dict returned by maparg()', function() - meths.set_keymap('n', 'lhs', 'rhs', {desc = 'map description'}) - eq('\nn lhs rhs\n map description', exec_capture("nmap lhs")) + meths.set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) + eq('\nn lhs rhs\n map description', exec_capture('nmap lhs')) local mapargs = funcs.maparg('lhs', 'n', false, true) - meths.set_keymap('n', 'lhs', 'rhs', {desc = 'MAP DESCRIPTION'}) - eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture("nmap lhs")) + meths.set_keymap('n', 'lhs', 'rhs', { desc = 'MAP DESCRIPTION' }) + eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture('nmap lhs')) funcs.mapset('n', false, mapargs) - eq('\nn lhs rhs\n map description', exec_capture("nmap lhs")) + eq('\nn lhs rhs\n map description', exec_capture('nmap lhs')) end) it('can restore "replace_keycodes" from the dict returned by maparg()', function() - meths.set_keymap('i', 'foo', [['']], {expr = true, replace_keycodes = true}) + meths.set_keymap('i', 'foo', [['']], { expr = true, replace_keycodes = true }) feed('Afoo') expect('<') local mapargs = funcs.maparg('foo', 'i', false, true) - meths.set_keymap('i', 'foo', [['']], {expr = true}) + meths.set_keymap('i', 'foo', [['']], { expr = true }) feed('foo') expect('<') funcs.mapset('i', false, mapargs) @@ -230,11 +230,14 @@ describe('mapset()', function() end) it('can restore Lua callback from the dict returned by maparg()', function() - eq(0, exec_lua([[ + eq( + 0, + exec_lua([[ GlobalCount = 0 vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]])) + ]]) + ) feed('asdf') eq(1, exec_lua([[return GlobalCount]])) @@ -262,9 +265,13 @@ describe('mapset()', function() end) it('does not leak memory if lhs is missing', function() - eq('Vim:E460: Entries missing in mapset() dict argument', - pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]])) - eq('Vim:E460: Entries missing in mapset() dict argument', - pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]])) + eq( + 'Vim:E460: Entries missing in mapset() dict argument', + pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]]) + ) + eq( + 'Vim:E460: Entries missing in mapset() dict argument', + pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]]) + ) end) end) -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/vimscript/map_functions_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/functional/vimscript/map_functions_spec.lua') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index b0c4a9747a..e11c8af157 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -181,31 +181,31 @@ describe('mapset()', function() before_each(clear) it('can restore mapping with backslash in lhs', function() - meths.set_keymap('n', '\\ab', 'a', {}) + meths.nvim_set_keymap('n', '\\ab', 'a', {}) eq('\nn \\ab a', exec_capture('nmap \\ab')) local mapargs = funcs.maparg('\\ab', 'n', false, true) - meths.set_keymap('n', '\\ab', 'b', {}) + meths.nvim_set_keymap('n', '\\ab', 'b', {}) eq('\nn \\ab b', exec_capture('nmap \\ab')) funcs.mapset('n', false, mapargs) eq('\nn \\ab a', exec_capture('nmap \\ab')) end) it('can restore mapping description from the dict returned by maparg()', function() - meths.set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) + meths.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) eq('\nn lhs rhs\n map description', exec_capture('nmap lhs')) local mapargs = funcs.maparg('lhs', 'n', false, true) - meths.set_keymap('n', 'lhs', 'rhs', { desc = 'MAP DESCRIPTION' }) + meths.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'MAP DESCRIPTION' }) eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture('nmap lhs')) funcs.mapset('n', false, mapargs) eq('\nn lhs rhs\n map description', exec_capture('nmap lhs')) end) it('can restore "replace_keycodes" from the dict returned by maparg()', function() - meths.set_keymap('i', 'foo', [['']], { expr = true, replace_keycodes = true }) + meths.nvim_set_keymap('i', 'foo', [['']], { expr = true, replace_keycodes = true }) feed('Afoo') expect('<') local mapargs = funcs.maparg('foo', 'i', false, true) - meths.set_keymap('i', 'foo', [['']], { expr = true }) + meths.nvim_set_keymap('i', 'foo', [['']], { expr = true }) feed('foo') expect('<') funcs.mapset('i', false, mapargs) -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/vimscript/map_functions_spec.lua | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'test/functional/vimscript/map_functions_spec.lua') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index e11c8af157..9edf54898b 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -9,7 +9,6 @@ local expect = helpers.expect local feed = helpers.feed local funcs = helpers.funcs local meths = helpers.meths -local nvim = helpers.nvim local source = helpers.source local command = helpers.command local exec_capture = helpers.exec_capture @@ -37,16 +36,16 @@ describe('maparg()', function() } it('returns a dictionary', function() - nvim('command', 'nnoremap foo bar') + command('nnoremap foo bar') eq('bar', funcs.maparg('foo')) eq(foo_bar_map_table, funcs.maparg('foo', 'n', false, true)) end) it('returns 1 for silent when is used', function() - nvim('command', 'nnoremap foo bar') + command('nnoremap foo bar') eq(1, funcs.maparg('foo', 'n', false, true)['silent']) - nvim('command', 'nnoremap baz bat') + command('nnoremap baz bat') eq(0, funcs.maparg('baz', 'n', false, true)['silent']) end) @@ -59,8 +58,8 @@ describe('maparg()', function() end) it('returns the same value for noremap and