Files
neovim/test/functional/api/command_spec.lua
Jan Edmund Lazo 292148b08b vim-patch:8.2.3141: no error when using :complete for :command without -nargs
Problem:    No error when using :complete for :command without -nargs.
Solution:   Give an error. (Martin Tournoij, closes vim/vim#8544, closes vim/vim#8541)
de69a7353e

N/A patches for version.c:

vim-patch:8.1.1801: cannot build without the +eval feature

Problem:    Cannot build without the +eval feature.
Solution:   Always define funcexe_T.
505e43a20e

vim-patch:8.1.1818: unused variable

Problem:    Unused variable.
Solution:   Remove the variable. (Mike Williams)
b4a88a0441

vim-patch:8.2.1464: Vim9: build warning for unused variable

Problem:    Vim9: build warning for unused variable.
Solution:   Delete the variable declaration.
829ac868b7

vim-patch:8.2.2639: build failure when fsync() is not available

Problem:    Build failure when fsync() is not available.
Solution:   Add #ifdef.
5ea79a2599

vim-patch:8.2.2814: Vim9: unused variable

Problem:    Vim9: unused variable. (John Marriott)
Solution:   Adjust #ifdef.
b06b50dfa0

vim-patch:8.2.2947: build failure without the channel feature

Problem:    Build failure without the channel feature.
Solution:   Add back #ifdef. (John Marriott)
f5bfa8faa7

vim-patch:8.2.2976: build failure without the +eval feature

Problem:    Build failure without the +eval feature.
Solution:   Add #ifdefs.
8de901e1f1

vim-patch:8.2.2986: build failure without the profile feature

Problem:    Build failure without the profile feature.
Solution:   Add #ifdef.
d9f31c13d2

vim-patch:8.2.3114: Amiga-like systems: build error using stat()

Problem:    Amiga-like systems: build error using stat().
Solution:   Only build swapfile_process_running() on systems where it is
            actually used. (Ola Söder, closes vim/vim#8519)
599a6e5b36
2021-08-08 22:29:55 -04:00

81 lines
4.1 KiB
Lua

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 meths = helpers.meths
local source = helpers.source
local pcall_err = helpers.pcall_err
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()
eq('builtin=true not implemented', pcall_err(meths.get_commands,
{builtin=true}))
eq('unexpected key: foo', pcall_err(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='1', 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\253R2_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\253R3_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\253R4_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 -nargs=1 -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)