aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/command_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-05-12 08:17:21 +0200
committerGitHub <noreply@github.com>2018-05-12 08:17:21 +0200
commit36b2e3f743aaeb27531e67079d1a20bb4ac75e35 (patch)
tree75063f22b1a90605b6f2aee0233729eaf06306b4 /test/functional/api/command_spec.lua
parent273d2cd5d5cfc7616c76d3531e9938750abcc05e (diff)
parent137eedb4edab1643b47282cce4ca07dd2ee42a63 (diff)
downloadrneovim-36b2e3f743aaeb27531e67079d1a20bb4ac75e35.tar.gz
rneovim-36b2e3f743aaeb27531e67079d1a20bb4ac75e35.tar.bz2
rneovim-36b2e3f743aaeb27531e67079d1a20bb4ac75e35.zip
Merge #8375 'API: nvim_get_commands'
closes #7833 ref #8029
Diffstat (limited to 'test/functional/api/command_spec.lua')
-rw-r--r--test/functional/api/command_spec.lua80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
new file mode 100644
index 0000000000..f3f9f93649
--- /dev/null
+++ b/test/functional/api/command_spec.lua
@@ -0,0 +1,80 @@
+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 cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', range=NIL, register=false, script_id=0, }
+ local cmd_dict2 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='pwd', name='Pwd', nargs='?', range=NIL, register=false, script_id=0, }
+ before_each(clear)
+
+ it('gets empty list if no commands were defined', function()
+ eq({}, meths.get_commands({builtin=false}))
+ end)
+
+ it('validates input', function()
+ expect_err('builtin=true not implemented', 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({Hello=cmd_dict}, meths.get_commands({builtin=false}))
+ -- Define another command.
+ command('command -nargs=? Pwd pwd');
+ eq({Hello=cmd_dict, Pwd=cmd_dict2}, meths.get_commands({builtin=false}))
+ -- Delete a command.
+ command('delcommand Pwd')
+ eq({Hello=cmd_dict}, meths.get_commands({builtin=false}))
+ end)
+
+ it('gets buffer-local user-defined commands', function()
+ -- Define a buffer-local command.
+ command('command -buffer -nargs=1 Hello echo "Hello World"')
+ eq({Hello=cmd_dict}, curbufmeths.get_commands({builtin=false}))
+ -- Define another buffer-local command.
+ command('command -buffer -nargs=? Pwd pwd')
+ eq({Hello=cmd_dict, Pwd=cmd_dict2}, curbufmeths.get_commands({builtin=false}))
+ -- Delete a command.
+ command('delcommand Pwd')
+ eq({Hello=cmd_dict}, curbufmeths.get_commands({builtin=false}))
+
+ -- {builtin=true} always returns empty for buffer-local case.
+ eq({}, curbufmeths.get_commands({builtin=true}))
+ end)
+
+ it('gets various command attributes', function()
+ local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd <args>', name='TestCmd', nargs='0', range='10', register=false, script_id=0, }
+ local cmd1 = { addr=NIL, bang=false, bar=false, complete='custom', complete_arg='ListUsers', count=NIL, definition='!finger <args>', name='Finger', nargs='+', range=NIL, register=false, script_id=1, }
+ local cmd2 = { addr=NIL, bang=true, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253Q2_foo(<q-args>)', name='Cmd2', nargs='*', range=NIL, register=false, script_id=2, }
+ local cmd3 = { addr=NIL, bang=false, bar=true, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253Q3_ohyeah()', name='Cmd3', nargs='0', range=NIL, register=false, script_id=3, }
+ local cmd4 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253Q4_just_great()', name='Cmd4', nargs='0', range=NIL, register=true, script_id=4, }
+ source([[
+ command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
+ ]])
+ eq({Finger=cmd1}, meths.get_commands({builtin=false}))
+ command('command -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
+ eq({Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false}))
+
+ source([[
+ command -bang -nargs=* Cmd2 call <SID>foo(<q-args>)
+ ]])
+ source([[
+ command -bar -nargs=0 Cmd3 call <SID>ohyeah()
+ ]])
+ source([[
+ command -register Cmd4 call <SID>just_great()
+ ]])
+ -- TODO(justinmk): Order is stable but undefined. Sort before return?
+ eq({Cmd2=cmd2, Cmd3=cmd3, Cmd4=cmd4, Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false}))
+ end)
+end)