aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/command_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api/command_spec.lua')
-rw-r--r--test/functional/api/command_spec.lua95
1 files changed, 59 insertions, 36 deletions
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
index db03edf6d2..d24cdc0493 100644
--- a/test/functional/api/command_spec.lua
+++ b/test/functional/api/command_spec.lua
@@ -1,74 +1,97 @@
local helpers = require('test.functional.helpers')(after_each)
+local NIL = helpers.NIL
local clear = helpers.clear
local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq
+local expect_err = helpers.expect_err
local meths = helpers.meths
+local source = helpers.source
describe('nvim_get_commands', function()
- local dummy_dict = {dummy=''}
- local cmd_string = 'command Hello echo "Hello World"'
- local cmd_string2 = 'command Pwd pwd'
local cmd_dict = {
+ addr=NIL,
+ complete=NIL,
+ complete_arg=NIL,
+ count=NIL,
+ definition='echo "Hello World"',
name='Hello',
- nargs='0',
+ nargs='1',
+ range=NIL,
script_id=0,
- definition='echo "Hello World"',
}
local cmd_dict2 = {
+ addr=NIL,
+ complete=NIL,
+ complete_arg=NIL,
+ count=NIL,
+ definition='pwd',
name='Pwd',
- nargs='0',
+ nargs='?',
+ range=NIL,
script_id=0,
- definition='pwd',
}
before_each(clear)
it('gets empty list if no commands were defined', function()
- eq({}, meths.get_commands(dummy_dict))
+ eq({}, meths.get_commands({builtin=false}))
end)
- it('gets user-def commands', function()
- -- Insert a command
- command(cmd_string)
- eq({cmd_dict}, meths.get_commands(dummy_dict))
- -- Insert a another command
- command(cmd_string2);
- eq({cmd_dict, cmd_dict2}, meths.get_commands(dummy_dict))
- -- Delete a command
+ it('validates input', function()
+ expect_err('builtin commands not supported yet', meths.get_commands,
+ {builtin=true})
+ expect_err('unexpected key: foo', meths.get_commands,
+ {foo='blah'})
+ end)
+ it('gets global user-defined commands', function()
+ -- Define a command.
+ command('command -nargs=1 Hello echo "Hello World"')
+ eq({cmd_dict}, meths.get_commands({builtin=false}))
+ -- Define another command.
+ command('command -nargs=? Pwd pwd');
+ eq({cmd_dict, cmd_dict2}, meths.get_commands({builtin=false}))
+ -- Delete a command.
command('delcommand Pwd')
- eq({cmd_dict}, meths.get_commands(dummy_dict))
+ eq({cmd_dict}, meths.get_commands({builtin=false}))
end)
- it('considers different buffers', function()
- -- Insert a command
- command('command -buffer Hello echo "Hello World"')
- eq({cmd_dict}, curbufmeths.get_commands(dummy_dict))
- -- Insert a another command
- command('command -buffer Pwd pwd')
- eq({cmd_dict, cmd_dict2}, curbufmeths.get_commands(dummy_dict))
- -- Delete a command
+ it('gets buffer-local user-defined commands', function()
+ -- Define a buffer-local command.
+ command('command -buffer -nargs=1 Hello echo "Hello World"')
+ eq({cmd_dict}, curbufmeths.get_commands({builtin=false}))
+ -- Define another buffer-local command.
+ command('command -buffer -nargs=? Pwd pwd')
+ eq({cmd_dict, cmd_dict2}, curbufmeths.get_commands({builtin=false}))
+ -- Delete a command.
command('delcommand Pwd')
- eq({cmd_dict}, curbufmeths.get_commands(dummy_dict))
+ eq({cmd_dict}, curbufmeths.get_commands({builtin=false}))
end)
it('gets different attributes of different commands', function()
local cmd1 = {
+ addr=NIL,
complete='custom',
- nargs='1',
- name='Finger',
- script_id=0,
complete_arg='ListUsers',
+ count=NIL,
definition='!finger <args>',
+ name='Finger',
+ nargs='+',
+ range=NIL,
+ script_id=1,
}
local cmd2 = {
+ addr='arguments',
complete='dir',
- nargs='0',
+ complete_arg=NIL,
+ count='10',
+ definition='pwd <args>',
name='TestCmd',
- range='10c',
- addr='arguments',
+ nargs='0',
+ range='10',
script_id=0,
- definition='pwd <args>',
}
- command('command -complete=custom,ListUsers -nargs=1 Finger !finger <args>')
- eq({cmd1}, meths.get_commands(dummy_dict))
+ source([[
+ command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
+ ]])
+ eq({cmd1}, meths.get_commands({builtin=false}))
command('command -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
- eq({cmd1, cmd2}, meths.get_commands(dummy_dict))
+ eq({cmd1, cmd2}, meths.get_commands({builtin=false}))
end)
end)