diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-05-11 07:50:00 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-05-11 13:50:00 +0200 |
commit | 738bffea2cbb810ad1d3a3aa5bfeb88392260a8a (patch) | |
tree | 1cf06c01744acf33df2c1db67398c897a5af962b /test/functional/api/command_spec.lua | |
parent | 9fa7727ce047e8e2e13f9fbf60d5defe9cf45060 (diff) | |
download | rneovim-738bffea2cbb810ad1d3a3aa5bfeb88392260a8a.tar.gz rneovim-738bffea2cbb810ad1d3a3aa5bfeb88392260a8a.tar.bz2 rneovim-738bffea2cbb810ad1d3a3aa5bfeb88392260a8a.zip |
API: nvim_get_commands(): more attributes
Support more :command attributes:
-bang
-bar
-register
Diffstat (limited to 'test/functional/api/command_spec.lua')
-rw-r--r-- | test/functional/api/command_spec.lua | 72 |
1 files changed, 26 insertions, 46 deletions
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index d24cdc0493..149a5dd111 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -10,38 +10,21 @@ local meths = helpers.meths local source = helpers.source describe('nvim_get_commands', function() - local cmd_dict = { - addr=NIL, - complete=NIL, - complete_arg=NIL, - count=NIL, - definition='echo "Hello World"', - name='Hello', - nargs='1', - range=NIL, - script_id=0, - } - local cmd_dict2 = { - addr=NIL, - complete=NIL, - complete_arg=NIL, - count=NIL, - definition='pwd', - name='Pwd', - nargs='?', - range=NIL, - script_id=0, - } + 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 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"') @@ -53,6 +36,7 @@ describe('nvim_get_commands', function() command('delcommand Pwd') eq({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"') @@ -64,34 +48,30 @@ describe('nvim_get_commands', function() command('delcommand Pwd') eq({cmd_dict}, curbufmeths.get_commands({builtin=false})) end) - it('gets different attributes of different commands', function() - local cmd1 = { - addr=NIL, - complete='custom', - complete_arg='ListUsers', - count=NIL, - definition='!finger <args>', - name='Finger', - nargs='+', - range=NIL, - script_id=1, - } - local cmd2 = { - addr='arguments', - complete='dir', - complete_arg=NIL, - count='10', - definition='pwd <args>', - name='TestCmd', - nargs='0', - range='10', - script_id=0, - } + + 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({cmd1}, meths.get_commands({builtin=false})) command('command -complete=dir -addr=arguments -count=10 TestCmd pwd <args>') - eq({cmd1, cmd2}, meths.get_commands({builtin=false})) + eq({cmd1, 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, cmd3, cmd4, cmd1, cmd0}, meths.get_commands({builtin=false})) end) end) |