test: make mapping tests more consistent (#28368)

- Test maparg() and maplist() in the same test.
- Use matches() instead of string.match().
- Avoid overlong lines and strange spacing in exec_lua().
- Revert code change from last PR as the variable may be needed.
This commit is contained in:
zeertzjq
2024-04-16 14:05:09 +08:00
committed by GitHub
parent 47ba96a6b3
commit 7fa24948a9
3 changed files with 119 additions and 57 deletions

View File

@@ -233,7 +233,9 @@ describe('mapset()', function()
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
]])
)
@@ -242,7 +244,9 @@ describe('mapset()', function()
exec_lua([[
_G.saved_asdf_map = vim.fn.maparg('asdf', 'n', false, true)
vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 10 end })
vim.api.nvim_set_keymap('n', 'asdf', '', {
callback = function() GlobalCount = GlobalCount + 10 end,
})
]])
feed('asdf')
eq(11, exec_lua([[return GlobalCount]]))
@@ -253,7 +257,10 @@ describe('mapset()', function()
exec([[
let g:saved_asdf_map = maparg('asdf', 'n', v:false, v:true)
lua vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 10 end })
lua <<
vim.api.nvim_set_keymap('n', 'asdf', '', {
callback = function() GlobalCount = GlobalCount + 10 end,
})
]])
feed('asdf')
eq(22, exec_lua([[return GlobalCount]]))