aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/command_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2022-02-15 13:08:40 -0700
committerGitHub <noreply@github.com>2022-02-15 13:08:40 -0700
commit238b944e58d12a28245be996e69bf36a2a452a90 (patch)
tree363c9b25822888223c4b5f703c615a0a99b9b419 /test/functional/api/command_spec.lua
parent3449405f38961ac297638ced6377d75cfcb610ca (diff)
downloadrneovim-238b944e58d12a28245be996e69bf36a2a452a90.tar.gz
rneovim-238b944e58d12a28245be996e69bf36a2a452a90.tar.bz2
rneovim-238b944e58d12a28245be996e69bf36a2a452a90.zip
fix(api): validate command names in nvim_add_user_command (#17406)
This uses the same validation used when defining commands with `:command`.
Diffstat (limited to 'test/functional/api/command_spec.lua')
-rw-r--r--test/functional/api/command_spec.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
index d64d324a88..de22c9078c 100644
--- a/test/functional/api/command_spec.lua
+++ b/test/functional/api/command_spec.lua
@@ -180,6 +180,28 @@ describe('nvim_add_user_command', function()
feed('<C-U>Test b<Tab>')
eq('Test bbb', funcs.getcmdline())
end)
+
+ it('does not allow invalid command names', function()
+ matches("'name' must begin with an uppercase letter", pcall_err(exec_lua, [[
+ vim.api.nvim_add_user_command('test', 'echo "hi"', {})
+ ]]))
+
+ matches('Invalid command name', pcall_err(exec_lua, [[
+ vim.api.nvim_add_user_command('t@', 'echo "hi"', {})
+ ]]))
+
+ matches('Invalid command name', pcall_err(exec_lua, [[
+ vim.api.nvim_add_user_command('T@st', 'echo "hi"', {})
+ ]]))
+
+ matches('Invalid command name', pcall_err(exec_lua, [[
+ vim.api.nvim_add_user_command('Test!', 'echo "hi"', {})
+ ]]))
+
+ matches('Invalid command name', pcall_err(exec_lua, [[
+ vim.api.nvim_add_user_command('💩', 'echo "hi"', {})
+ ]]))
+ end)
end)
describe('nvim_del_user_command', function()