aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/keymap_spec.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-04-29 17:30:45 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-04-29 17:39:24 +0800
commitc8e45366b9d0914eb17f759e0bfa7829fd419857 (patch)
treecb6cf2164c8ea900d188c6499c34ff6ab5d75a2c /test/functional/api/keymap_spec.lua
parent35a7b0f9b991e884eae81aa7393f9701b7b7b85e (diff)
downloadrneovim-c8e45366b9d0914eb17f759e0bfa7829fd419857.tar.gz
rneovim-c8e45366b9d0914eb17f759e0bfa7829fd419857.tar.bz2
rneovim-c8e45366b9d0914eb17f759e0bfa7829fd419857.zip
fix(mappings): fix double-free when unmapping simplifiable Lua mapping
Diffstat (limited to 'test/functional/api/keymap_spec.lua')
-rw-r--r--test/functional/api/keymap_spec.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index a11b5306f4..4fb2d55a76 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -874,6 +874,27 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
eq('\nNo mapping found', helpers.exec_capture('nmap asdf'))
end)
+ it('no double-free when unmapping simplifiable lua mappings', function()
+ eq(0, exec_lua [[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('n', '<C-I>', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ return GlobalCount
+ ]])
+
+ feed('<C-I>\n')
+
+ eq(1, exec_lua[[return GlobalCount]])
+
+ exec_lua [[
+ vim.api.nvim_del_keymap('n', '<C-I>')
+ ]]
+
+ feed('<C-I>\n')
+
+ eq(1, exec_lua[[return GlobalCount]])
+ eq('\nNo mapping found', helpers.exec_capture('nmap <C-I>'))
+ end)
+
it('can set descriptions on keymaps', function()
meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"})
eq(generate_mapargs('n', 'lhs', 'rhs', {desc="map description"}), get_mapargs('n', 'lhs'))
@@ -1040,4 +1061,25 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
eq(1, exec_lua[[return GlobalCount]])
eq('\nNo mapping found', helpers.exec_capture('nmap asdf'))
end)
+
+ it('no double-free when unmapping simplifiable lua mappings', function()
+ eq(0, exec_lua [[
+ GlobalCount = 0
+ vim.api.nvim_buf_set_keymap(0, 'n', '<C-I>', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ return GlobalCount
+ ]])
+
+ feed('<C-I>\n')
+
+ eq(1, exec_lua[[return GlobalCount]])
+
+ exec_lua [[
+ vim.api.nvim_buf_del_keymap(0, 'n', '<C-I>')
+ ]]
+
+ feed('<C-I>\n')
+
+ eq(1, exec_lua[[return GlobalCount]])
+ eq('\nNo mapping found', helpers.exec_capture('nmap <C-I>'))
+ end)
end)