diff options
Diffstat (limited to 'test/functional')
120 files changed, 8006 insertions, 2693 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 3f9883f43f..64b28e7bf7 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -273,54 +273,72 @@ describe('autocmd api', function() eq({}, api.nvim_get_autocmds({ event = 'User', pattern = 'Test' })) end) - it('receives an args table', function() + local function test_autocmd_args(event) + local function get_amatch(pat) + return event == 'User' and pat or vim.fs.normalize(n.fn.fnamemodify(pat, ':p')) + end + local group_id = api.nvim_create_augroup('TestGroup', {}) -- Having an existing autocmd calling expand("<afile>") shouldn't change args #18964 - api.nvim_create_autocmd('User', { + api.nvim_create_autocmd(event, { group = 'TestGroup', pattern = 'Te*', command = 'call expand("<afile>")', }) - local autocmd_id = exec_lua [[ - return vim.api.nvim_create_autocmd("User", { + local autocmd_id = exec_lua(([[ + return vim.api.nvim_create_autocmd(%q, { group = "TestGroup", pattern = "Te*", callback = function(args) vim.g.autocmd_args = args end, }) - ]] + ]]):format(event)) - api.nvim_exec_autocmds('User', { pattern = 'Test pattern' }) + local exec_pat = 'Test pattern' + local amatch = get_amatch(exec_pat) + api.nvim_exec_autocmds(event, { pattern = exec_pat }) eq({ id = autocmd_id, group = group_id, - event = 'User', - match = 'Test pattern', - file = 'Test pattern', + event = event, + match = amatch, + file = exec_pat, buf = 1, }, api.nvim_get_var('autocmd_args')) -- Test without a group - autocmd_id = exec_lua [[ - return vim.api.nvim_create_autocmd("User", { + autocmd_id = exec_lua(([[ + return vim.api.nvim_create_autocmd(%q, { pattern = "*", callback = function(args) vim.g.autocmd_args = args end, }) - ]] + ]]):format(event)) - api.nvim_exec_autocmds('User', { pattern = 'some_pat' }) + exec_pat = 'some_pat' + amatch = get_amatch(exec_pat) + api.nvim_exec_autocmds(event, { pattern = exec_pat }) eq({ id = autocmd_id, group = nil, - event = 'User', - match = 'some_pat', - file = 'some_pat', + event = event, + match = amatch, + file = exec_pat, buf = 1, }, api.nvim_get_var('autocmd_args')) + end + + describe('receives correct args table', function() + it('for event that takes non-file pattern', function() + test_autocmd_args('User') + end) + + it('for event that takes file pattern', function() + test_autocmd_args('BufEnter') + end) end) it('can receive arbitrary data', function() @@ -881,6 +899,89 @@ describe('autocmd api', function() eq([[:echo "Buffer"]], normalized_aus[1].command) end) end) + + describe('id', function() + it('gets events by ID', function() + local id = api.nvim_create_autocmd('BufEnter', { + command = 'echo "hello"', + }) + eq({ + { + buflocal = false, + command = 'echo "hello"', + event = 'BufEnter', + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id })) + end) + + it('gets events by ID by other filters', function() + local group_name = 'NVIM_GET_AUTOCMDS_ID' + local group = api.nvim_create_augroup(group_name, { clear = true }) + local id = api.nvim_create_autocmd('BufEnter', { + command = 'set number', + group = group, + }) + api.nvim_create_autocmd('WinEnter', { + group = group, + command = 'set cot&', + }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'BufEnter', + group = group, + group_name = group_name, + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id, group = group })) + end) + + it('gets events by ID and a specific event', function() + local id = api.nvim_create_autocmd('InsertEnter', { command = 'set number' }) + api.nvim_create_autocmd('InsertEnter', { command = 'set wrap' }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'InsertEnter', + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id, event = 'InsertEnter' })) + end) + + it('gets events by ID and a specific pattern', function() + local id = api.nvim_create_autocmd('InsertEnter', { + pattern = '*.c', + command = 'set number', + }) + api.nvim_create_autocmd('InsertEnter', { + pattern = '*.c', + command = 'set wrap', + }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'InsertEnter', + id = id, + once = false, + pattern = '*.c', + }, + }, api.nvim_get_autocmds({ id = id, pattern = '*.c' })) + end) + + it('empty result when id does not found', function() + eq({}, api.nvim_get_autocmds({ id = 255 })) + end) + end) end) describe('nvim_exec_autocmds', function() diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 527394bfd1..489f601d31 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -879,7 +879,8 @@ describe('API: buffer events:', function() it('when :terminal lines change', function() local buffer_lines = {} local expected_lines = {} - fn.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, { + fn.jobstart({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index a16c6a88e3..fabd9be6d6 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -651,6 +651,11 @@ describe('nvim_create_user_command', function() api.nvim_set_current_buf(bufnr) command('Hello') assert_alive() + eq( + 'Invalid buffer id: 1234', + pcall_err(api.nvim_buf_create_user_command, 1234, 'Hello', '', {}) + ) + assert_alive() end) it('can use a Lua complete function', function() @@ -771,5 +776,9 @@ describe('nvim_del_user_command', function() command('Hello') api.nvim_buf_del_user_command(0, 'Hello') matches('Not an editor command: Hello', pcall_err(command, 'Hello')) + eq('Invalid command (not found): Hello', pcall_err(api.nvim_buf_del_user_command, 0, 'Hello')) + eq('Invalid command (not found): Bye', pcall_err(api.nvim_buf_del_user_command, 0, 'Bye')) + eq('Invalid buffer id: 1234', pca |