diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-31 21:14:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 21:14:14 +0800 |
commit | 933c80e8f9d7ff4ab634c14d370440702c7c8ed7 (patch) | |
tree | e58d3a701628ad71a2b4139c4125f3f4670d0002 /test/functional/api/keymap_spec.lua | |
parent | fa747d004a1e91b30066020f2f592e4dc5d94084 (diff) | |
download | rneovim-933c80e8f9d7ff4ab634c14d370440702c7c8ed7.tar.gz rneovim-933c80e8f9d7ff4ab634c14d370440702c7c8ed7.tar.bz2 rneovim-933c80e8f9d7ff4ab634c14d370440702c7c8ed7.zip |
refactor(mappings)!: mapblock_fill_dict() use API Dictionary (#20020)
This introduces the following breaking changes:
- nvim_get_keymap now always returns a LuaRef object as "callback" for a
Lua mapping regardless of how it is called. The LuaRef object can be
called from Lua and Vim script, but is lost over RPC.
- maparg() now returns a Funcref instead of a ref number as "callback"
for a Lua mapping. The Funcref can be called from Lua and Vim script,
but is lost over RPC.
This may also make nvim_get_keymap faster, but make maparg() slower.
Diffstat (limited to 'test/functional/api/keymap_spec.lua')
-rw-r--r-- | test/functional/api/keymap_spec.lua | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index a93a4544ff..fedcbfa76a 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -6,6 +6,7 @@ local command = helpers.command local curbufmeths = helpers.curbufmeths local eq, neq = helpers.eq, helpers.neq local exec_lua = helpers.exec_lua +local exec = helpers.exec local feed = helpers.feed local funcs = helpers.funcs local meths = helpers.meths @@ -336,21 +337,26 @@ describe('nvim_get_keymap', function() end) it('can handle lua mappings', function() - eq(0, exec_lua [[ + eq(0, exec_lua([[ GlobalCount = 0 - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount - ]]) + ]])) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua([[return GlobalCount]])) - eq(2, exec_lua[[ + eq(2, exec_lua([[ vim.api.nvim_get_keymap('n')[1].callback() return GlobalCount + ]])) + + exec([[ + call nvim_get_keymap('n')[0].callback() ]]) + eq(3, exec_lua([[return GlobalCount]])) + local mapargs = meths.get_keymap('n') - assert(type(mapargs[1].callback) == 'number', 'callback is not luaref number') mapargs[1].callback = nil eq({ lhs='asdf', @@ -834,17 +840,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it ('maparg() returns lua mapping correctly', function() - exec_lua [[ - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end }) - ]] - assert.truthy(string.match(funcs.maparg('asdf', 'n'), - "^<Lua %d+>")) + eq(0, exec_lua([[ + GlobalCount = 0 + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + return GlobalCount + ]])) + + assert.truthy(string.match(funcs.maparg('asdf', 'n'), "^<Lua %d+>")) + local mapargs = funcs.maparg('asdf', 'n', false, true) - assert(type(mapargs.callback) == 'number', 'callback is not luaref number') mapargs.callback = nil mapargs.lhsraw = nil mapargs.lhsrawalt = nil eq(generate_mapargs('n', 'asdf', nil, {sid=sid_lua}), mapargs) + + eq(1, exec_lua([[ + vim.fn.maparg('asdf', 'n', false, true).callback() + return GlobalCount + ]])) + + exec([[ + call maparg('asdf', 'n', v:false, v:true).callback() + ]]) + eq(2, exec_lua([[return GlobalCount]])) end) it('can make lua expr mappings replacing keycodes', function() |