From 25b630484023716977c3fe2790c13b41f9db9f30 Mon Sep 17 00:00:00 2001 From: Nimit Bhardwaj Date: Sat, 24 Feb 2018 15:44:51 +0530 Subject: API: nvim_get_commands() --- test/functional/api/command_spec.lua | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/functional/api/command_spec.lua (limited to 'test/functional/api/command_spec.lua') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua new file mode 100644 index 0000000000..db03edf6d2 --- /dev/null +++ b/test/functional/api/command_spec.lua @@ -0,0 +1,74 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local command = helpers.command +local curbufmeths = helpers.curbufmeths +local eq = helpers.eq +local meths = helpers.meths + +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 = { + name='Hello', + nargs='0', + script_id=0, + definition='echo "Hello World"', + } + local cmd_dict2 = { + name='Pwd', + nargs='0', + script_id=0, + definition='pwd', + } + before_each(clear) + it('gets empty list if no commands were defined', function() + eq({}, meths.get_commands(dummy_dict)) + 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 + command('delcommand Pwd') + eq({cmd_dict}, meths.get_commands(dummy_dict)) + 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 + command('delcommand Pwd') + eq({cmd_dict}, curbufmeths.get_commands(dummy_dict)) + end) + it('gets different attributes of different commands', function() + local cmd1 = { + complete='custom', + nargs='1', + name='Finger', + script_id=0, + complete_arg='ListUsers', + definition='!finger ', + } + local cmd2 = { + complete='dir', + nargs='0', + name='TestCmd', + range='10c', + addr='arguments', + script_id=0, + definition='pwd ', + } + command('command -complete=custom,ListUsers -nargs=1 Finger !finger ') + eq({cmd1}, meths.get_commands(dummy_dict)) + command('command -complete=dir -addr=arguments -count=10 TestCmd pwd ') + eq({cmd1, cmd2}, meths.get_commands(dummy_dict)) + end) +end) -- cgit From 9fa7727ce047e8e2e13f9fbf60d5defe9cf45060 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 10 May 2018 23:37:56 +0200 Subject: API: nvim_get_commands(): always return keys - Always return all keys, with at least NIL value. - Require `opts` param to be {"builtin":false} - Validate `opts` param --- test/functional/api/command_spec.lua | 95 ++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 36 deletions(-) (limited to 'test/functional/api/command_spec.lua') 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 ', + name='Finger', + nargs='+', + range=NIL, + script_id=1, } local cmd2 = { + addr='arguments', complete='dir', - nargs='0', + complete_arg=NIL, + count='10', + definition='pwd ', name='TestCmd', - range='10c', - addr='arguments', + nargs='0', + range='10', script_id=0, - definition='pwd ', } - command('command -complete=custom,ListUsers -nargs=1 Finger !finger ') - eq({cmd1}, meths.get_commands(dummy_dict)) + source([[ + command -complete=custom,ListUsers -nargs=+ Finger !finger + ]]) + eq({cmd1}, meths.get_commands({builtin=false})) command('command -complete=dir -addr=arguments -count=10 TestCmd pwd ') - eq({cmd1, cmd2}, meths.get_commands(dummy_dict)) + eq({cmd1, cmd2}, meths.get_commands({builtin=false})) end) end) -- cgit From 738bffea2cbb810ad1d3a3aa5bfeb88392260a8a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 11 May 2018 07:50:00 +0200 Subject: API: nvim_get_commands(): more attributes Support more :command attributes: -bang -bar -register --- test/functional/api/command_spec.lua | 72 +++++++++++++----------------------- 1 file changed, 26 insertions(+), 46 deletions(-) (limited to 'test/functional/api/command_spec.lua') 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 ', - name='Finger', - nargs='+', - range=NIL, - script_id=1, - } - local cmd2 = { - addr='arguments', - complete='dir', - complete_arg=NIL, - count='10', - definition='pwd ', - 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 ', 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 ', 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()', 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 ]]) eq({cmd1}, meths.get_commands({builtin=false})) command('command -complete=dir -addr=arguments -count=10 TestCmd pwd ') - eq({cmd1, cmd2}, meths.get_commands({builtin=false})) + eq({cmd1, cmd0}, meths.get_commands({builtin=false})) + + source([[ + command -bang -nargs=* Cmd2 call foo() + ]]) + source([[ + command -bar -nargs=0 Cmd3 call ohyeah() + ]]) + source([[ + command -register Cmd4 call 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) -- cgit From cb6672853a0df3dbe5202621d818ef1c2da7432c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 11 May 2018 20:59:53 +0200 Subject: API: nvim_get_commands(): builtin is irrelevant for buffer-local builtin commands are never buffer-local, so we can return empty for that case. --- test/functional/api/command_spec.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/functional/api/command_spec.lua') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 149a5dd111..c7cf081355 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -19,7 +19,7 @@ describe('nvim_get_commands', function() end) it('validates input', function() - expect_err('builtin commands not supported yet', meths.get_commands, + expect_err('builtin=true not implemented', meths.get_commands, {builtin=true}) expect_err('unexpected key: foo', meths.get_commands, {foo='blah'}) @@ -47,6 +47,9 @@ describe('nvim_get_commands', function() -- Delete a command. command('delcommand Pwd') eq({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() -- cgit From 137eedb4edab1643b47282cce4ca07dd2ee42a63 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 11 May 2018 21:26:05 +0200 Subject: API: nvim_get_commands(): return Dictionary --- test/functional/api/command_spec.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test/functional/api/command_spec.lua') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index c7cf081355..f3f9f93649 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -28,25 +28,25 @@ describe('nvim_get_commands', function() 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})) + eq({Hello=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})) + eq({Hello=cmd_dict, Pwd=cmd_dict2}, meths.get_commands({builtin=false})) -- Delete a command. command('delcommand Pwd') - eq({cmd_dict}, meths.get_commands({builtin=false})) + 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({cmd_dict}, curbufmeths.get_commands({builtin=false})) + eq({Hello=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})) + eq({Hello=cmd_dict, Pwd=cmd_dict2}, curbufmeths.get_commands({builtin=false})) -- Delete a command. command('delcommand Pwd') - eq({cmd_dict}, curbufmeths.get_commands({builtin=false})) + eq({Hello=cmd_dict}, curbufmeths.get_commands({builtin=false})) -- {builtin=true} always returns empty for buffer-local case. eq({}, curbufmeths.get_commands({builtin=true})) @@ -61,9 +61,9 @@ describe('nvim_get_commands', function() source([[ command -complete=custom,ListUsers -nargs=+ Finger !finger ]]) - eq({cmd1}, meths.get_commands({builtin=false})) + eq({Finger=cmd1}, meths.get_commands({builtin=false})) command('command -complete=dir -addr=arguments -count=10 TestCmd pwd ') - eq({cmd1, cmd0}, meths.get_commands({builtin=false})) + eq({Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false})) source([[ command -bang -nargs=* Cmd2 call foo() @@ -75,6 +75,6 @@ describe('nvim_get_commands', function() command -register Cmd4 call just_great() ]]) -- TODO(justinmk): Order is stable but undefined. Sort before return? - eq({cmd2, cmd3, cmd4, cmd1, cmd0}, meths.get_commands({builtin=false})) + eq({Cmd2=cmd2, Cmd3=cmd3, Cmd4=cmd4, Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false})) end) end) -- cgit