2018-02-24 03:14:51 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
2018-05-10 14:37:56 -07:00
|
|
|
local NIL = helpers.NIL
|
2018-02-24 03:14:51 -07:00
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
|
|
|
local curbufmeths = helpers.curbufmeths
|
|
|
|
local eq = helpers.eq
|
|
|
|
local meths = helpers.meths
|
2021-12-22 11:40:21 -07:00
|
|
|
local bufmeths = helpers.bufmeths
|
|
|
|
local matches = helpers.matches
|
2018-05-10 14:37:56 -07:00
|
|
|
local source = helpers.source
|
2019-09-06 17:17:37 -07:00
|
|
|
local pcall_err = helpers.pcall_err
|
2021-12-22 11:40:21 -07:00
|
|
|
local exec_lua = helpers.exec_lua
|
|
|
|
local assert_alive = helpers.assert_alive
|
|
|
|
local feed = helpers.feed
|
|
|
|
local funcs = helpers.funcs
|
2018-02-24 03:14:51 -07:00
|
|
|
|
|
|
|
describe('nvim_get_commands', function()
|
2022-04-20 04:02:18 -07:00
|
|
|
local cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', preview=false, range=NIL, register=false, keepscript=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='?', preview=false, range=NIL, register=false, keepscript=false, script_id=0, }
|
2018-02-24 03:14:51 -07:00
|
|
|
before_each(clear)
|
2018-05-10 22:50:00 -07:00
|
|
|
|
2018-02-24 03:14:51 -07:00
|
|
|
it('gets empty list if no commands were defined', function()
|
2018-05-10 14:37:56 -07:00
|
|
|
eq({}, meths.get_commands({builtin=false}))
|
2018-02-24 03:14:51 -07:00
|
|
|
end)
|
2018-05-10 22:50:00 -07:00
|
|
|
|
2018-05-10 14:37:56 -07:00
|
|
|
it('validates input', function()
|
2019-09-06 17:17:37 -07:00
|
|
|
eq('builtin=true not implemented', pcall_err(meths.get_commands,
|
|
|
|
{builtin=true}))
|
2021-08-21 04:55:12 -07:00
|
|
|
eq("Invalid key: 'foo'", pcall_err(meths.get_commands,
|
2019-09-06 17:17:37 -07:00
|
|
|
{foo='blah'}))
|
2018-05-10 14:37:56 -07:00
|
|
|
end)
|
2018-05-10 22:50:00 -07:00
|
|
|
|
2018-05-10 14:37:56 -07:00
|
|
|
it('gets global user-defined commands', function()
|
|
|
|
-- Define a command.
|
|
|
|
command('command -nargs=1 Hello echo "Hello World"')
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Hello=cmd_dict}, meths.get_commands({builtin=false}))
|
2018-05-10 14:37:56 -07:00
|
|
|
-- Define another command.
|
|
|
|
command('command -nargs=? Pwd pwd');
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Hello=cmd_dict, Pwd=cmd_dict2}, meths.get_commands({builtin=false}))
|
2018-05-10 14:37:56 -07:00
|
|
|
-- Delete a command.
|
2018-02-24 03:14:51 -07:00
|
|
|
command('delcommand Pwd')
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Hello=cmd_dict}, meths.get_commands({builtin=false}))
|
2018-02-24 03:14:51 -07:00
|
|
|
end)
|
2018-05-10 22:50:00 -07:00
|
|
|
|
2018-05-10 14:37:56 -07:00
|
|
|
it('gets buffer-local user-defined commands', function()
|
|
|
|
-- Define a buffer-local command.
|
|
|
|
command('command -buffer -nargs=1 Hello echo "Hello World"')
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Hello=cmd_dict}, curbufmeths.get_commands({builtin=false}))
|
2018-05-10 14:37:56 -07:00
|
|
|
-- Define another buffer-local command.
|
|
|
|
command('command -buffer -nargs=? Pwd pwd')
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Hello=cmd_dict, Pwd=cmd_dict2}, curbufmeths.get_commands({builtin=false}))
|
2018-05-10 14:37:56 -07:00
|
|
|
-- Delete a command.
|
2018-02-24 03:14:51 -07:00
|
|
|
command('delcommand Pwd')
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Hello=cmd_dict}, curbufmeths.get_commands({builtin=false}))
|
2018-05-11 11:59:53 -07:00
|
|
|
|
|
|
|
-- {builtin=true} always returns empty for buffer-local case.
|
|
|
|
eq({}, curbufmeths.get_commands({builtin=true}))
|
2018-02-24 03:14:51 -07:00
|
|
|
end)
|
2018-05-10 22:50:00 -07:00
|
|
|
|
|
|
|
it('gets various command attributes', function()
|
2022-04-20 04:02:18 -07:00
|
|
|
local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd <args>', name='TestCmd', nargs='1', preview=false, range='10', register=false, keepscript=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='+', preview=false, range=NIL, register=false, keepscript=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='*', preview=false, range=NIL, register=false, keepscript=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', preview=false, range=NIL, register=false, keepscript=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', preview=false, range=NIL, register=true, keepscript=false, script_id=4, }
|
2018-05-10 14:37:56 -07:00
|
|
|
source([[
|
2022-03-27 10:25:55 -07:00
|
|
|
let s:foo = 1
|
2018-05-10 14:37:56 -07:00
|
|
|
command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
|
|
|
|
]])
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Finger=cmd1}, meths.get_commands({builtin=false}))
|
2021-08-02 21:57:38 -07:00
|
|
|
command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false}))
|
2018-05-10 22:50:00 -07:00
|
|
|
|
|
|
|
source([[
|
2022-03-27 10:25:55 -07:00
|
|
|
function! s:foo() abort
|
|
|
|
endfunction
|
2018-05-10 22:50:00 -07:00
|
|
|
command -bang -nargs=* Cmd2 call <SID>foo(<q-args>)
|
|
|
|
]])
|
|
|
|
source([[
|
2022-03-27 10:25:55 -07:00
|
|
|
function! s:ohyeah() abort
|
|
|
|
endfunction
|
2018-05-10 22:50:00 -07:00
|
|
|
command -bar -nargs=0 Cmd3 call <SID>ohyeah()
|
|
|
|
]])
|
|
|
|
source([[
|
2022-03-27 10:25:55 -07:00
|
|
|
function! s:just_great() abort
|
|
|
|
endfunction
|
2018-05-10 22:50:00 -07:00
|
|
|
command -register Cmd4 call <SID>just_great()
|
|
|
|
]])
|
|
|
|
-- TODO(justinmk): Order is stable but undefined. Sort before return?
|
2018-05-11 12:26:05 -07:00
|
|
|
eq({Cmd2=cmd2, Cmd3=cmd3, Cmd4=cmd4, Finger=cmd1, TestCmd=cmd0}, meths.get_commands({builtin=false}))
|
2018-02-24 03:14:51 -07:00
|
|
|
end)
|
|
|
|
end)
|
2021-12-22 11:40:21 -07:00
|
|
|
|
2022-04-10 18:12:41 -07:00
|
|
|
describe('nvim_create_user_command', function()
|
2021-12-22 11:40:21 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('works with strings', function()
|
2022-04-10 18:12:41 -07:00
|
|
|
meths.create_user_command('SomeCommand', 'let g:command_fired = <args>', {nargs = 1})
|
2021-12-22 11:40:21 -07:00
|
|
|
meths.command('SomeCommand 42')
|
|
|
|
eq(42, meths.eval('g:command_fired'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works with Lua functions', function()
|
|
|
|
exec_lua [[
|
|
|
|
result = {}
|
2022-04-10 18:12:41 -07:00
|
|
|
vim.api.nvim_create_user_command('CommandWithLuaCallback', function(opts)
|
2021-12-22 11:40:21 -07:00
|
|
|
result = opts
|
|
|
|
end, {
|
|
|
|
nargs = "*",
|
|
|
|
bang = true,
|
|
|
|
count = 2,
|
|
|
|
})
|
|
|
|
]]
|
|
|
|
|
|
|
|
eq({
|
2022-08-25 02:57:32 -07:00
|
|
|
args = [[this\ is a\ test]],
|
|
|
|
fargs = {"this ", "is", "a test"},
|
2021-12-22 11:40:21 -07:00
|
|
|
bang = false,
|
|
|
|
line1 = 1,
|
|
|
|
line2 = 1,
|
|
|
|
mods = "",
|
2022-05-28 21:42:00 -07:00
|
|
|
smods = {
|
|
|
|
browse = false,
|
|
|
|
confirm = false,
|
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = false,
|
2022-05-28 21:42:00 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "",
|
|
|
|
tab = 0,
|
2022-07-02 04:35:11 -07:00
|
|
|
unsilent = false,
|
2022-06-07 20:06:36 -07:00
|
|
|
verbose = -1,
|
2022-05-28 21:42:00 -07:00
|
|
|
vertical = false,
|
|
|
|
},
|
2021-12-22 11:40:21 -07:00
|
|
|
range = 0,
|
|
|
|
count = 2,
|
|
|
|
reg = "",
|
2022-02-27 12:35:06 -07:00
|
|
|
}, exec_lua [=[
|
2022-08-25 02:57:32 -07:00
|
|
|
vim.api.nvim_command([[CommandWithLuaCallback this\ is a\ test]])
|
2021-12-22 11:40:21 -07:00
|
|
|
return result
|
2022-02-27 12:35:06 -07:00
|
|
|
]=])
|
2021-12-22 11:40:21 -07:00
|
|
|
|
|
|
|
eq({
|
2022-04-13 07:04:56 -07:00
|
|
|
args = [[this includes\ a backslash: \\]],
|
|
|
|
fargs = {"this", "includes a", "backslash:", "\\"},
|
|
|
|
bang = false,
|
|
|
|
line1 = 1,
|
|
|
|
line2 = 1,
|
|
|
|
mods = "",
|
2022-05-28 21:42:00 -07:00
|
|
|
smods = {
|
|
|
|
browse = false,
|
|
|
|
confirm = false,
|
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = false,
|
2022-05-28 21:42:00 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "",
|
|
|
|
tab = 0,
|
2022-07-02 04:35:11 -07:00
|
|
|
unsilent = false,
|
2022-06-07 20:06:36 -07:00
|
|
|
verbose = -1,
|
2022-05-28 21:42:00 -07:00
|
|
|
vertical = false,
|
|
|
|
},
|
2022-04-13 07:04:56 -07:00
|
|
|
range = 0,
|
|
|
|
count = 2,
|
|
|
|
reg = "",
|
|
|
|
}, exec_lua [=[
|
|
|
|
vim.api.nvim_command([[CommandWithLuaCallback this includes\ a backslash: \\]])
|
|
|
|
return result
|
|
|
|
]=])
|
|
|
|
|
|
|
|
eq({
|
|
|
|
args = "a\\b",
|
|
|
|
fargs = {"a\\b"},
|
|
|
|
bang = false,
|
|
|
|
line1 = 1,
|
|
|
|
line2 = 1,
|
|
|
|
mods = "",
|
2022-05-28 21:42:00 -07:00
|
|
|
smods = {
|
|
|
|
browse = false,
|
|
|
|
confirm = false,
|
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = false,
|
2022-05-28 21:42:00 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "",
|
|
|
|
tab = 0,
|
2022-07-02 04:35:11 -07:00
|
|
|
unsilent = false,
|
2022-06-07 20:06:36 -07:00
|
|
|
verbose = -1,
|
2022-05-28 21:42:00 -07:00
|
|
|
vertical = false,
|
|
|
|
},
|
2022-04-13 07:04:56 -07:00
|
|
|
range = 0,
|
|
|
|
count = 2,
|
|
|
|
reg = "",
|
|
|
|
}, exec_lua [=[
|
|
|
|
vim.api.nvim_command('CommandWithLuaCallback a\\b')
|
|
|
|
return result
|
|
|
|
]=])
|
|
|
|
|
|
|
|
eq({
|
|
|
|
args = 'h\tey ',
|
2022-02-27 12:35:06 -07:00
|
|
|
fargs = {[[h]], [[ey]]},
|
2021-12-22 11:40:21 -07:00
|
|
|
bang = true,
|
|
|
|
line1 = 10,
|
|
|
|
line2 = 10,
|
2022-09-01 05:32:59 -07:00
|
|
|
mods = "confirm unsilent botright horizontal",
|
2022-05-28 21:42:00 -07:00
|
|
|
smods = {
|
|
|
|
browse = false,
|
2022-07-02 04:35:11 -07:00
|
|
|
confirm = true,
|
2022-05-28 21:42:00 -07:00
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = true,
|
2022-05-28 21:42:00 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "botright",
|
|
|
|
tab = 0,
|
2022-07-02 04:35:11 -07:00
|
|
|
unsilent = true,
|
2022-06-07 20:06:36 -07:00
|
|
|
verbose = -1,
|
2022-05-28 21:42:00 -07:00
|
|
|
vertical = false,
|
|
|
|
},
|
2021-12-22 11:40:21 -07:00
|
|
|
range = 1,
|
|
|
|
count = 10,
|
|
|
|
reg = "",
|
2022-02-27 12:35:06 -07:00
|
|
|
}, exec_lua [=[
|
2022-09-01 05:32:59 -07:00
|
|
|
vim.api.nvim_command('unsilent horizontal botright confirm 10CommandWithLuaCallback! h\tey ')
|
2021-12-22 11:40:21 -07:00
|
|
|
return result
|
2022-02-27 12:35:06 -07:00
|
|
|
]=])
|
2021-12-22 11:40:21 -07:00
|
|
|
|
|
|
|
eq({
|
2022-02-27 12:35:06 -07:00
|
|
|
args = "h",
|
|
|
|
fargs = {"h"},
|
2021-12-22 11:40:21 -07:00
|
|
|
bang = false,
|
|
|
|
line1 = 1,
|
|
|
|
line2 = 42,
|
|
|
|
mods = "",
|
2022-05-28 21:42:00 -07:00
|
|
|
smods = {
|
|
|
|
browse = false,
|
|
|
|
confirm = false,
|
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = false,
|
2022-05-28 21:42:00 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "",
|
|
|
|
tab = 0,
|
2022-07-02 04:35:11 -07:00
|
|
|
unsilent = false,
|
2022-06-07 20:06:36 -07:00
|
|
|
verbose = -1,
|
2022-05-28 21:42:00 -07:00
|
|
|
vertical = false,
|
|
|
|
},
|
2021-12-22 11:40:21 -07:00
|
|
|
range = 1,
|
|
|
|
count = 42,
|
|
|
|
reg = "",
|
|
|
|
}, exec_lua [[
|
2022-02-27 12:35:06 -07:00
|
|
|
vim.api.nvim_command('CommandWithLuaCallback 42 h')
|
2021-12-22 11:40:21 -07:00
|
|
|
return result
|
|
|
|
]])
|
2022-02-27 12:35:06 -07:00
|
|
|
|
|
|
|
eq({
|
|
|
|
args = "",
|
2022-04-13 07:04:56 -07:00
|
|
|
fargs = {}, -- fargs works without args
|
2022-02-27 12:35:06 -07:00
|
|
|
bang = false,
|
|
|
|
line1 = 1,
|
|
|
|
line2 = 1,
|
|
|
|
mods = "",
|
2022-05-28 21:42:00 -07:00
|
|
|
smods = {
|
|
|
|
browse = false,
|
|
|
|
confirm = false,
|
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = false,
|
2022-05-28 21:42:00 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "",
|
|
|
|
tab = 0,
|
2022-07-02 04:35:11 -07:00
|
|
|
unsilent = false,
|
2022-06-07 20:06:36 -07:00
|
|
|
verbose = -1,
|
2022-05-28 21:42:00 -07:00
|
|
|
vertical = false,
|
|
|
|
},
|
2022-02-27 12:35:06 -07:00
|
|
|
range = 0,
|
|
|
|
count = 2,
|
|
|
|
reg = "",
|
|
|
|
}, exec_lua [[
|
|
|
|
vim.api.nvim_command('CommandWithLuaCallback')
|
|
|
|
return result
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- f-args doesn't split when command nargs is 1 or "?"
|
|
|
|
exec_lua [[
|
|
|
|
result = {}
|
2022-08-21 06:19:29 -07:00
|
|
|
vim.api.nvim_create_user_command('CommandWithOneOrNoArg', function(opts)
|
2022-02-27 12:35:06 -07:00
|
|
|
result = opts
|
|
|
|
end, {
|
|
|
|
nargs = "?",
|
|
|
|
bang = true,
|
|
|
|
count = 2,
|
|
|
|
})
|
|
|
|
]]
|
|
|
|
|
|
|
|
eq({
|
2022-04-13 07:04:56 -07:00
|
|
|
args = "hello I'm one argument",
|
|
|
|
fargs = {"hello I'm one argument"}, -- Doesn't split args
|
2022-02-27 12:35:06 -07:00
|
|
|
bang = false,
|
|
|
|
line1 = 1,
|
|
|
|
line2 = 1,
|
|
|
|
mods = "",
|
2022-05-28 21:42:00 -07:00
|
|
|
smods = {
|
|
|
|
browse = false,
|
|
|
|
confirm = false,
|
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = false,
|
2022-05-28 21:42:00 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "",
|
|
|
|
tab = 0,
|
2022-07-02 04:35:11 -07:00
|
|
|
unsilent = false,
|
2022-06-07 20:06:36 -07:00
|
|
|
verbose = -1,
|
2022-05-28 21:42:00 -07:00
|
|
|
vertical = false,
|
|
|
|
},
|
2022-02-27 12:35:06 -07:00
|
|
|
range = 0,
|
|
|
|
count = 2,
|
|
|
|
reg = "",
|
|
|
|
}, exec_lua [[
|
2022-08-21 06:19:29 -07:00
|
|
|
vim.api.nvim_command('CommandWithOneOrNoArg hello I\'m one argument')
|
|
|
|
return result
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- f-args is an empty table if no args were passed
|
|
|
|
eq({
|
|
|
|
args = "",
|
|
|
|
fargs = {},
|
|
|
|
bang = false,
|
|
|
|
line1 = 1,
|
|
|
|
line2 = 1,
|
|
|
|
mods = "",
|
|
|
|
smods = {
|
|
|
|
browse = false,
|
|
|
|
confirm = false,
|
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = false,
|
2022-08-21 06:19:29 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "",
|
|
|
|
tab = 0,
|
|
|
|
unsilent = false,
|
|
|
|
verbose = -1,
|
|
|
|
vertical = false,
|
|
|
|
},
|
|
|
|
range = 0,
|
|
|
|
count = 2,
|
|
|
|
reg = "",
|
|
|
|
}, exec_lua [[
|
|
|
|
vim.api.nvim_command('CommandWithOneOrNoArg')
|
|
|
|
return result
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- f-args is an empty table when the command nargs=0
|
|
|
|
exec_lua [[
|
|
|
|
result = {}
|
|
|
|
vim.api.nvim_create_user_command('CommandWithNoArgs', function(opts)
|
|
|
|
result = opts
|
|
|
|
end, {
|
|
|
|
nargs = 0,
|
|
|
|
bang = true,
|
|
|
|
count = 2,
|
|
|
|
})
|
|
|
|
]]
|
|
|
|
eq({
|
|
|
|
args = "",
|
|
|
|
fargs = {},
|
|
|
|
bang = false,
|
|
|
|
line1 = 1,
|
|
|
|
line2 = 1,
|
|
|
|
mods = "",
|
|
|
|
smods = {
|
|
|
|
browse = false,
|
|
|
|
confirm = false,
|
|
|
|
emsg_silent = false,
|
|
|
|
hide = false,
|
2022-09-01 05:32:59 -07:00
|
|
|
horizontal = false,
|
2022-08-21 06:19:29 -07:00
|
|
|
keepalt = false,
|
|
|
|
keepjumps = false,
|
|
|
|
keepmarks = false,
|
|
|
|
keeppatterns = false,
|
|
|
|
lockmarks = false,
|
|
|
|
noautocmd = false,
|
|
|
|
noswapfile = false,
|
|
|
|
sandbox = false,
|
|
|
|
silent = false,
|
|
|
|
split = "",
|
|
|
|
tab = 0,
|
|
|
|
unsilent = false,
|
|
|
|
verbose = -1,
|
|
|
|
vertical = false,
|
|
|
|
},
|
|
|
|
range = 0,
|
|
|
|
count = 2,
|
|
|
|
reg = "",
|
|
|
|
}, exec_lua [[
|
|
|
|
vim.cmd('CommandWithNoArgs')
|
2022-02-27 12:35:06 -07:00
|
|
|
return result
|
|
|
|
]])
|
|
|
|
|
2021-12-22 11:40:21 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('can define buffer-local commands', function()
|
|
|
|
local bufnr = meths.create_buf(false, false)
|
2022-04-10 18:12:41 -07:00
|
|
|
bufmeths.create_user_command(bufnr, "Hello", "", {})
|
2021-12-22 11:40:21 -07:00
|
|
|
matches("Not an editor command: Hello", pcall_err(meths.command, "Hello"))
|
|
|
|
meths.set_current_buf(bufnr)
|
|
|
|
meths.command("Hello")
|
|
|
|
assert_alive()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('can use a Lua complete function', function()
|
|
|
|
exec_lua [[
|
2022-04-10 18:12:41 -07:00
|
|
|
vim.api.nvim_create_user_command('Test', '', {
|
2021-12-22 11:40:21 -07:00
|
|
|
nargs = "*",
|
|
|
|
complete = function(arg, cmdline, pos)
|
|
|
|
local options = {"aaa", "bbb", "ccc"}
|
|
|
|
local t = {}
|
|
|
|
for _, v in ipairs(options) do
|
|
|
|
if string.find(v, "^" .. arg) then
|
|
|
|
table.insert(t, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
]]
|
|
|
|
|
|
|
|
feed(':Test a<Tab>')
|
|
|
|
eq('Test aaa', funcs.getcmdline())
|
|
|
|
feed('<C-U>Test b<Tab>')
|
|
|
|
eq('Test bbb', funcs.getcmdline())
|
|
|
|
end)
|
2022-02-15 13:08:40 -07:00
|
|
|
|
|
|
|
it('does not allow invalid command names', function()
|
|
|
|
matches("'name' must begin with an uppercase letter", pcall_err(exec_lua, [[
|
2022-04-10 18:12:41 -07:00
|
|
|
vim.api.nvim_create_user_command('test', 'echo "hi"', {})
|
2022-02-15 13:08:40 -07:00
|
|
|
]]))
|
|
|
|
|
|
|
|
matches('Invalid command name', pcall_err(exec_lua, [[
|
2022-04-10 18:12:41 -07:00
|
|
|
vim.api.nvim_create_user_command('t@', 'echo "hi"', {})
|
2022-02-15 13:08:40 -07:00
|
|
|
]]))
|
|
|
|
|
|
|
|
matches('Invalid command name', pcall_err(exec_lua, [[
|
2022-04-10 18:12:41 -07:00
|
|
|
vim.api.nvim_create_user_command('T@st', 'echo "hi"', {})
|
2022-02-15 13:08:40 -07:00
|
|
|
]]))
|
|
|
|
|
|
|
|
matches('Invalid command name', pcall_err(exec_lua, [[
|
2022-04-10 18:12:41 -07:00
|
|
|
vim.api.nvim_create_user_command('Test!', 'echo "hi"', {})
|
2022-02-15 13:08:40 -07:00
|
|
|
]]))
|
|
|
|
|
|
|
|
matches('Invalid command name', pcall_err(exec_lua, [[
|
2022-04-10 18:12:41 -07:00
|
|
|
vim.api.nvim_create_user_command('💩', 'echo "hi"', {})
|
2022-02-15 13:08:40 -07:00
|
|
|
]]))
|
|
|
|
end)
|
2022-06-07 20:06:36 -07:00
|
|
|
|
|
|
|
it('smods can be used with nvim_cmd', function()
|
|
|
|
exec_lua[[
|
|
|
|
vim.api.nvim_create_user_command('MyEcho', function(opts)
|
|
|
|
vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {})
|
|
|
|
end, {})
|
|
|
|
]]
|
|
|
|
|
|
|
|
eq("3", meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true }))
|
|
|
|
end)
|
2021-12-22 11:40:21 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('nvim_del_user_command', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('can delete global commands', function()
|
2022-04-10 18:12:41 -07:00
|
|
|
meths.create_user_command('Hello', 'echo "Hi"', {})
|
2021-12-22 11:40:21 -07:00
|
|
|
meths.command('Hello')
|
|
|
|
meths.del_user_command('Hello')
|
|
|
|
matches("Not an editor command: Hello", pcall_err(meths.command, "Hello"))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('can delete buffer-local commands', function()
|
2022-04-10 18:12:41 -07:00
|
|
|
bufmeths.create_user_command(0, 'Hello', 'echo "Hi"', {})
|
2021-12-22 11:40:21 -07:00
|
|
|
meths.command('Hello')
|
|
|
|
bufmeths.del_user_command(0, 'Hello')
|
|
|
|
matches("Not an editor command: Hello", pcall_err(meths.command, "Hello"))
|
|
|
|
end)
|
|
|
|
end)
|