mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
75 lines
2.2 KiB
Lua
75 lines
2.2 KiB
Lua
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 <args>',
|
|
}
|
|
local cmd2 = {
|
|
complete='dir',
|
|
nargs='0',
|
|
name='TestCmd',
|
|
range='10c',
|
|
addr='arguments',
|
|
script_id=0,
|
|
definition='pwd <args>',
|
|
}
|
|
command('command -complete=custom,ListUsers -nargs=1 Finger !finger <args>')
|
|
eq({cmd1}, meths.get_commands(dummy_dict))
|
|
command('command -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
|
|
eq({cmd1, cmd2}, meths.get_commands(dummy_dict))
|
|
end)
|
|
end)
|