aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/vim_spec.lua
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2026-03-13 18:06:39 +0800
committerGitHub <noreply@github.com>2026-03-13 06:06:39 -0400
commitf3ec657ebc02e8fb68e7cf46213333932325fe2f (patch)
tree2fdc4e675d0c3391969a9540e1fe25e6c5c37d08 /test/functional/api/vim_spec.lua
parentb027de3a87d0b7f615646943cac5b19d21143acf (diff)
downloadrneovim-f3ec657ebc02e8fb68e7cf46213333932325fe2f.tar.gz
rneovim-f3ec657ebc02e8fb68e7cf46213333932325fe2f.tar.bz2
rneovim-f3ec657ebc02e8fb68e7cf46213333932325fe2f.zip
fix(api): nvim_parse_cmd on range-only, modifier-only commands #36665
Problem: nvim_parse_cmd rejects valid commands like `:1` (range-only) or `aboveleft` (modifier-only). Solution: allow empty command when range or modifiers exist, and handle execution using existing range command logic.
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r--test/functional/api/vim_spec.lua63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 196165ea90..d69c99b61b 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -4979,6 +4979,66 @@ describe('API', function()
result = api.nvim_parse_cmd('copen 5', {})
eq(5, result.count)
end)
+ it('parses range-only command', function()
+ insert [[
+ line1
+ line2
+ line3
+ line4
+ ]]
+ api.nvim_win_set_cursor(0, { 4, 4 })
+ local res = api.nvim_parse_cmd('1', {})
+ eq({
+ addr = 'line',
+ args = {},
+ bang = false,
+ cmd = '',
+ magic = {
+ bar = false,
+ file = false,
+ },
+ mods = {
+ browse = false,
+ confirm = false,
+ emsg_silent = false,
+ filter = {
+ force = false,
+ pattern = '',
+ },
+ hide = false,
+ horizontal = false,
+ keepalt = false,
+ keepjumps = false,
+ keepmarks = false,
+ keeppatterns = false,
+ lockmarks = false,
+ noautocmd = false,
+ noswapfile = false,
+ sandbox = false,
+ silent = false,
+ split = '',
+ tab = -1,
+ unsilent = false,
+ verbose = -1,
+ vertical = false,
+ },
+ nargs = '0',
+ nextcmd = '',
+ range = { 1 },
+ }, res)
+ api.nvim_cmd(res, {})
+ eq(1, api.nvim_win_get_cursor(0)[1])
+ feed('VG:')
+ n.poke_eventloop()
+ res = api.nvim_parse_cmd("'<,'>", {})
+ eq({ 1, 5 }, res.range)
+ end)
+ it('parses modifier-only command', function()
+ local res = api.nvim_parse_cmd('aboveleft', {})
+ eq('', res.cmd)
+ eq('aboveleft', res.mods.split)
+ eq('none', res.addr)
+ end)
end)
describe('nvim_cmd', function()
@@ -5209,6 +5269,9 @@ describe('API', function()
-- error from the next command typed is not suppressed #21420
feed(':call<CR><CR>')
eq('E471: Argument required', api.nvim_cmd({ cmd = 'messages' }, { output = true }))
+
+ -- modifier only
+ eq('', api.nvim_cmd({ cmd = '', mods = { noautocmd = true } }, {}))
end)
it('works with magic.file', function()