fix(api): make nvim_parse_cmd propagate errors

Makes `nvim_parse_cmd` propagate any errors that occur while parsing to
give the user a better idea of what's wrong with the command.
This commit is contained in:
Famiu Haque
2022-05-05 23:11:57 +06:00
parent 1eecea8449
commit 511f06a56e
3 changed files with 37 additions and 13 deletions

View File

@@ -3426,10 +3426,15 @@ describe('API', function()
}, meths.parse_cmd('MyCommand test it', {}))
end)
it('errors for invalid command', function()
eq('Error while parsing command line', pcall_err(meths.parse_cmd, 'Fubar', {}))
eq('Error while parsing command line', pcall_err(meths.parse_cmd, '', {}))
eq('Error while parsing command line', pcall_err(meths.parse_cmd, '" foo', {}))
eq('Error while parsing command line: E492: Not an editor command: Fubar',
pcall_err(meths.parse_cmd, 'Fubar', {}))
command('command! Fubar echo foo')
eq('Error while parsing command line', pcall_err(meths.parse_cmd, 'Fubar!', {}))
eq('Error while parsing command line', pcall_err(meths.parse_cmd, '4,6Fubar', {}))
eq('Error while parsing command line: E477: No ! allowed',
pcall_err(meths.parse_cmd, 'Fubar!', {}))
eq('Error while parsing command line: E481: No range allowed',
pcall_err(meths.parse_cmd, '4,6Fubar', {}))
end)
end)
end)