diff options
| author | Lewis Russell <lewis6991@gmail.com> | 2024-01-12 13:11:28 +0000 |
|---|---|---|
| committer | Lewis Russell <lewis6991@gmail.com> | 2024-01-12 17:53:27 +0000 |
| commit | 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e (patch) | |
| tree | 0cbb2cf8dac8b4f43109dc6f7a4051dfbea23f12 /test/functional/api | |
| parent | c30f2e3182e3b50e7c03932027ac55edfc8ada4a (diff) | |
| download | rneovim-4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e.tar.gz rneovim-4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e.tar.bz2 rneovim-4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e.zip | |
test: normalise nvim bridge functions
- remove helpers.cur*meths
- remove helpers.nvim
Diffstat (limited to 'test/functional/api')
| -rw-r--r-- | test/functional/api/autocmd_spec.lua | 12 | ||||
| -rw-r--r-- | test/functional/api/buffer_spec.lua | 505 | ||||
| -rw-r--r-- | test/functional/api/buffer_updates_spec.lua | 68 | ||||
| -rw-r--r-- | test/functional/api/command_spec.lua | 30 | ||||
| -rw-r--r-- | test/functional/api/extmark_spec.lua | 64 | ||||
| -rw-r--r-- | test/functional/api/highlight_spec.lua | 26 | ||||
| -rw-r--r-- | test/functional/api/keymap_spec.lua | 76 | ||||
| -rw-r--r-- | test/functional/api/server_notifications_spec.lua | 22 | ||||
| -rw-r--r-- | test/functional/api/server_requests_spec.lua | 36 | ||||
| -rw-r--r-- | test/functional/api/tabpage_spec.lua | 71 | ||||
| -rw-r--r-- | test/functional/api/vim_spec.lua | 934 | ||||
| -rw-r--r-- | test/functional/api/window_spec.lua | 274 |
12 files changed, 1065 insertions, 1053 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 79a524d9eb..47cb8bfd54 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -109,12 +109,12 @@ describe('autocmd api', function() buffer = 0, }) - meths.nvim_command 'set filetype=txt' + command 'set filetype=txt' eq(1, meths.nvim_get_var('called')) -- switch to a new buffer - meths.nvim_command 'new' - meths.nvim_command 'set filetype=python' + command 'new' + command 'set filetype=python' eq(1, meths.nvim_get_var('called')) end) @@ -938,7 +938,7 @@ describe('autocmd api', function() meths.nvim_exec_autocmds('CursorHold', { buffer = 1 }) eq('none', meths.nvim_get_var('filename_executed')) - meths.nvim_command('edit __init__.py') + command('edit __init__.py') eq('__init__.py', meths.nvim_get_var('filename_executed')) end) @@ -955,8 +955,8 @@ describe('autocmd api', function() meths.nvim_set_var('filename_executed', 'none') eq('none', meths.nvim_get_var('filename_executed')) - meths.nvim_command('edit other_file.txt') - meths.nvim_command('edit __init__.py') + command('edit other_file.txt') + command('edit __init__.py') eq('none', meths.nvim_get_var('filename_executed')) meths.nvim_create_autocmd('CursorHoldI', { diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index c71853b574..b1b4c9f583 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer -local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq -local curbufmeths, ok = helpers.curbufmeths, helpers.ok +local clear = helpers.clear +local eq = helpers.eq +local ok = helpers.ok local describe_lua_and_rpc = helpers.describe_lua_and_rpc(describe) local meths = helpers.meths local funcs = helpers.funcs @@ -13,7 +13,6 @@ local feed_command = helpers.feed_command local insert = helpers.insert local NIL = vim.NIL local command = helpers.command -local bufmeths = helpers.bufmeths local feed = helpers.feed local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -51,48 +50,54 @@ describe('api/buf', function() it('cursor position is maintained after lines are inserted #9961', function() -- replace the buffer contents with these three lines. - request('nvim_buf_set_lines', 0, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) + meths.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) -- Set the current cursor to {3, 2}. - curwin('set_cursor', { 3, 2 }) + meths.nvim_win_set_cursor(0, { 3, 2 }) -- add 2 lines and delete 1 line above the current cursor position. - request('nvim_buf_set_lines', 0, 1, 2, 1, { 'line5', 'line6' }) + meths.nvim_buf_set_lines(0, 1, 2, true, { 'line5', 'line6' }) -- check the current set of lines in the buffer. - eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, buffer('get_lines', 0, 0, -1, 1)) + eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.nvim_buf_get_lines(0, 0, -1, true)) -- cursor should be moved below by 1 line. - eq({ 4, 2 }, curwin('get_cursor')) + eq({ 4, 2 }, meths.nvim_win_get_cursor(0)) -- add a line after the current cursor position. - request('nvim_buf_set_lines', 0, 5, 5, 1, { 'line7' }) + meths.nvim_buf_set_lines(0, 5, 5, true, { 'line7' }) -- check the current set of lines in the buffer. - eq({ 'line1', 'line5', 'line6', 'line3', 'line4', 'line7' }, buffer('get_lines', 0, 0, -1, 1)) + eq( + { 'line1', 'line5', 'line6', 'line3', 'line4', 'line7' }, + meths.nvim_buf_get_lines(0, 0, -1, true) + ) -- cursor position is unchanged. - eq({ 4, 2 }, curwin('get_cursor')) + eq({ 4, 2 }, meths.nvim_win_get_cursor(0)) -- overwrite current cursor line. - request('nvim_buf_set_lines', 0, 3, 5, 1, { 'line8', 'line9' }) + meths.nvim_buf_set_lines(0, 3, 5, true, { 'line8', 'line9' }) -- check the current set of lines in the buffer. - eq({ 'line1', 'line5', 'line6', 'line8', 'line9', 'line7' }, buffer('get_lines', 0, 0, -1, 1)) + eq( + { 'line1', 'line5', 'line6', 'line8', 'line9', 'line7' }, + meths.nvim_buf_get_lines(0, 0, -1, true) + ) -- cursor position is unchanged. - eq({ 4, 2 }, curwin('get_cursor')) + eq({ 4, 2 }, meths.nvim_win_get_cursor(0)) -- delete current cursor line. - request('nvim_buf_set_lines', 0, 3, 5, 1, {}) + meths.nvim_buf_set_lines(0, 3, 5, true, {}) -- check the current set of lines in the buffer. - eq({ 'line1', 'line5', 'line6', 'line7' }, buffer('get_lines', 0, 0, -1, 1)) + eq({ 'line1', 'line5', 'line6', 'line7' }, meths.nvim_buf_get_lines(0, 0, -1, true)) -- cursor position is unchanged. - eq({ 4, 2 }, curwin('get_cursor')) + eq({ 4, 2 }, meths.nvim_win_get_cursor(0)) end) it('cursor position is maintained in non-current window', function() - meths.nvim_buf_set_lines(0, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) + meths.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) meths.nvim_win_set_cursor(0, { 3, 2 }) local win = meths.nvim_get_current_win() local buf = meths.nvim_get_current_buf() command('new') - meths.nvim_buf_set_lines(buf, 1, 2, 1, { 'line5', 'line6' }) + meths.nvim_buf_set_lines(buf, 1, 2, true, { 'line5', 'line6' }) eq( { 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.nvim_buf_get_lines(buf, 0, -1, true) @@ -101,7 +106,7 @@ describe('api/buf', function() end) it('cursor position is maintained in TWO non-current windows', function() - meths.nvim_buf_set_lines(0, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) + meths.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) meths.nvim_win_set_cursor(0, { 3, 2 }) local win = meths.nvim_get_current_win() local buf = meths.nvim_get_current_buf() @@ -113,7 +118,7 @@ describe('api/buf', function() -- set current window to third one with another buffer command('new') - meths.nvim_buf_set_lines(buf, 1, 2, 1, { 'line5', 'line6' }) + meths.nvim_buf_set_lines(buf, 1, 2, true, { 'line5', 'line6' }) eq( { 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.nvim_buf_get_lines(buf, 0, -1, true) @@ -124,32 +129,32 @@ describe('api/buf', function() it('line_count has defined behaviour for unloaded buffers', function() -- we'll need to know our bufnr for when it gets unloaded - local bufnr = curbuf('get_number') + local bufnr = meths.nvim_buf_get_number(0) -- replace the buffer contents with these three lines - request('nvim_buf_set_lines', bufnr, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) + meths.nvim_buf_set_lines(bufnr, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) -- check the line count is correct - eq(4, request('nvim_buf_line_count', bufnr)) + eq(4, meths.nvim_buf_line_count(bufnr)) -- force unload the buffer (this will discard changes) command('new') command('bunload! ' .. bufnr) -- line count for an unloaded buffer should always be 0 - eq(0, request('nvim_buf_line_count', bufnr)) + eq(0, meths.nvim_buf_line_count(bufnr)) end) it('get_lines has defined behaviour for unloaded buffers', function() -- we'll need to know our bufnr for when it gets unloaded - local bufnr = curbuf('get_number') + local bufnr = meths.nvim_buf_get_number(0) -- replace the buffer contents with these three lines - buffer('set_lines', bufnr, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) + meths.nvim_buf_set_lines(bufnr, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) -- confirm that getting lines works - eq({ 'line2', 'line3' }, buffer('get_lines', bufnr, 1, 3, 1)) + eq({ 'line2', 'line3' }, meths.nvim_buf_get_lines(bufnr, 1, 3, true)) -- force unload the buffer (this will discard changes) command('new') command('bunload! ' .. bufnr) -- attempting to get lines now always gives empty list - eq({}, buffer('get_lines', bufnr, 1, 3, 1)) + eq({}, meths.nvim_buf_get_lines(bufnr, 1, 3, true)) -- it's impossible to get out-of-bounds errors for an unloaded buffer - eq({}, buffer('get_lines', bufnr, 8888, 9999, 1)) + eq({}, meths.nvim_buf_get_lines(bufnr, 8888, 9999, true)) end) describe('handles topline', function() @@ -166,7 +171,7 @@ describe('api/buf', function() 0, 0, -1, - 1, + true, { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' } ) meths.nvim_set_option_value('modified', false, {}) @@ -516,15 +521,23 @@ describe('api/buf', function() end) describe_lua_and_rpc('nvim_buf_get_lines, nvim_buf_set_lines', function(api) - local get_lines = api.curbufmeths.get_lines - local set_lines = api.curbufmeths.set_lines - local line_count = api.curbufmeths.line_count + local function get_lines(...) + return api.meths.nvim_buf_get_lines(0, ...) + end + + local function set_lines(...) + return api.meths.nvim_buf_set_lines(0, ...) + end + + local function line_count() + return api.meths.nvim_buf_line_count(0) + end it('fails correctly when input is not valid', function() - eq(1, api.curbufmeths.get_number()) + eq(1, api.meths.nvim_buf_get_number(0)) eq( [['replacement string' item contains newlines]], - pcall_err(bufmeths.set_lines, 1, 1, 2, false, { 'b\na' }) + pcall_err(api.meths.nvim_buf_set_lines, 1, 1, 2, false, { 'b\na' }) ) end) @@ -532,7 +545,7 @@ describe('api/buf', function() command('set nomodifiable') eq( [[Buffer is not 'modifiable']], - pcall_err(api.bufmeths.set_lines, 1, 1, 2, false, { 'a', 'b' }) + pcall_err(api.meths.nvim_buf_set_lines, 1, 1, 2, false, { 'a', 'b' }) ) end) @@ -726,7 +739,7 @@ describe('api/buf', function() end) it('set_lines on unloaded buffer #8659 #22670', function() - local bufnr = curbuf('get_number') + local bufnr = meths.nvim_buf_get_number(0) meths.nvim_buf_set_lines(bufnr, 0, -1, false, { 'a', 'b', 'c' }) meths.nvim_buf_set_name(bufnr, 'set_lines') finally(function() @@ -742,7 +755,13 @@ describe('api/buf', function() end) describe('nvim_buf_set_text', function() - local get_lines, set_text = curbufmeths.get_lines, curbufmeths.set_text + local function get_lines(...) + return meths.nvim_buf_get_lines(0, ...) + end + + local function set_text(...) + return meths.nvim_buf_set_text(0, ...) + end it('works', function() insert([[ @@ -821,12 +840,12 @@ describe('api/buf', function() ]]) -- position the cursor on `!` - curwin('set_cursor', { 1, 11 }) + meths.nvim_win_set_cursor(0, { 1, 11 }) -- replace 'world' with 'foo' set_text(0, 6, 0, 11, { 'foo' }) eq('hello foo!', curbuf_depr('get_line', 0)) -- cursor should be moved left by two columns (replacement is shorter by 2 chars) - eq({ 1, 9 }, curwin('get_cursor')) + eq({ 1, 9 }, meths.nvim_win_get_cursor(0)) end) it('updates the cursor position in non-current window', function() @@ -879,12 +898,12 @@ describe('api/buf', function() abcd]]) -- position the cursor on 'c' - curwin('set_cursor', { 1, 2 }) + meths.nvim_win_set_cursor(0, { 1, 2 }) -- add 'xxx' before 'c' set_text(0, 2, 0, 2, { 'xxx' }) eq({ 'abxxxcd' }, get_lines(0, -1, true)) -- cursor should be on 'c' - eq({ 1, 5 }, curwin('get_cursor')) + eq({ 1, 5 }, meths.nvim_win_get_cursor(0)) end) it('updates the cursor position only in non-current window when in INSERT mode', function() @@ -892,7 +911,7 @@ describe('api/buf', function() abcd]]) -- position the cursor on 'c' - curwin('set_cursor', { 1, 2 }) + meths.nvim_win_set_cursor(0, { 1, 2 }) -- open vertical split feed('<c-w>v') -- get into INSERT mode to treat cursor @@ -902,13 +921,13 @@ describe('api/buf', function() set_text(0, 2, 0, 2, { 'xxx' }) eq({ 'abxxxcd' }, get_lines(0, -1, true)) -- in the current window cursor should stay after 'b' - eq({ 1, 2 }, curwin('get_cursor')) + eq({ 1, 2 }, meths.nvim_win_get_cursor(0)) -- quit INSERT mode feed('<esc>') -- close current window feed('<c-w>c') -- in another window cursor should be on 'c' - eq({ 1, 5 }, curwin('get_cursor')) + eq({ 1, 5 }, meths.nvim_win_get_cursor(0)) end) end) @@ -918,12 +937,12 @@ describe('api/buf', function() abcd]]) -- position the cursor on 'b' - curwin('set_cursor', { 1, 1 }) + meths.nvim_win_set_cursor(0, { 1, 1 }) -- delete 'b' set_text(0, 1, 0, 2, {}) eq({ 'acd' }, get_lines(0, -1, true)) -- cursor is now on 'c' - eq({ 1, 1 }, curwin('get_cursor')) + eq({ 1, 1 }, meths.nvim_win_get_cursor(0)) end) it('maintains INSERT-mode cursor position current/non-current window', function() @@ -931,7 +950,7 @@ describe('api/buf', function() abcd]]) -- position the cursor on 'b' - curwin('set_cursor', { 1, 1 }) + meths.nvim_win_set_cursor(0, { 1, 1 }) -- open vertical split feed('<c-w>v') -- get into INSERT mode to treat cursor @@ -941,13 +960,13 @@ describe('api/buf', function() set_text(0, 1, 0, 2, {}) eq({ 'acd' }, get_lines(0, -1, true)) -- cursor in the current window should stay after 'a' - eq({ 1, 1 }, curwin('get_cursor')) + eq({ 1, 1 }, meths.nvim_win_get_cursor(0)) -- quit INSERT mode feed('<esc>') -- close current window feed('<c-w>c') -- cursor in non-current window should stay on 'c' - eq({ 1, 1 }, curwin('get_cursor')) + eq({ 1, 1 }, meths.nvim_win_get_cursor(0)) end) end) @@ -959,7 +978,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on ' ' before 'first' - curwin('set_cursor', { 1, 14 }) + meths.nvim_win_set_cursor(0, { 1, 14 }) set_text(0, 15, 2, 11, { 'the line we do not want', @@ -971,7 +990,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should stay at the same position - eq({ 1, 14 }, curwin('get_cursor')) + eq({ 1, 14 }, meths.nvim_win_get_cursor(0)) end) it('maintains cursor position if at start_row and column is still valid', function() @@ -981,7 +1000,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'f' in 'first' - curwin('set_cursor', { 1, 15 }) + meths.nvim_win_set_cursor(0, { 1, 15 }) set_text(0, 15, 2, 11, { 'the line we do not want', @@ -993,7 +1012,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should stay at the same position - eq({ 1, 15 }, curwin('get_cursor')) + eq({ 1, 15 }, meths.nvim_win_get_cursor(0)) end) it('adjusts cursor column to keep it valid if start_row got smaller', function() @@ -1003,7 +1022,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 't' in 'first' - curwin('set_cursor', { 1, 19 }) + meths.nvim_win_set_cursor(0, { 1, 19 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 15, 2, 24, {'last'}) @@ -1012,7 +1031,7 @@ describe('api/buf', function() eq({ 'This should be last' }, get_lines(0, -1, true)) -- cursor should end up on 't' in 'last' - eq({ 1, 18 }, curwin('get_cursor')) + eq({ 1, 18 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 18 }, cursor) end) @@ -1024,7 +1043,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 't' in 'first' - curwin('set_cursor', { 1, 19 }) + meths.nvim_win_set_cursor(0, { 1, 19 }) -- enter INSERT mode to treat cursor as being after 't' feed('a') @@ -1035,7 +1054,7 @@ describe('api/buf', function() eq({ 'This should be last' }, get_lines(0, -1, true)) -- cursor should end up after 't' in 'last' - eq({ 1, 19 }, curwin('get_cursor')) + eq({ 1, 19 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 19 }, cursor) end) @@ -1047,7 +1066,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'w' in 'want' - curwin('set_cursor', { 2, 31 }) + meths.nvim_win_set_cursor(0, { 2, 31 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { @@ -1064,7 +1083,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor column should end up at the end of a row - eq({ 2, 5 }, curwin('get_cursor')) + eq({ 2, 5 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 5 }, cursor) end) @@ -1078,7 +1097,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'w' in 'want' - curwin('set_cursor', { 2, 31 }) + meths.nvim_win_set_cursor(0, { 2, 31 }) -- enter INSERT mode feed('a') @@ -1097,7 +1116,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor column should end up at the end of a row - eq({ 2, 6 }, curwin('get_cursor')) + eq({ 2, 6 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 6 }, cursor) end @@ -1110,7 +1129,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'n' in 'finally' - curwin('set_cursor', { 3, 6 }) + meths.nvim_win_set_cursor(0, { 3, 6 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { @@ -1126,7 +1145,7 @@ describe('api/buf', function() }, get_lines(0, -1, true)) -- cursor should end up on 'y' in 'hopefully' -- to stay in the range, because it got smaller - eq({ 2, 12 }, curwin('get_cursor')) + eq({ 2, 12 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 12 }, cursor) end) @@ -1138,7 +1157,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'r' in 'there' - curwin('set_cursor', { 2, 8 }) + meths.nvim_win_set_cursor(0, { 2, 8 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 15, 2, 12, {}) @@ -1147,7 +1166,7 @@ describe('api/buf', function() eq({ 'This should be the last one' }, get_lines(0, -1, true)) -- cursor should end up on the next column after deleted range - eq({ 1, 15 }, curwin('get_cursor')) + eq({ 1, 15 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 15 }, cursor) end) @@ -1159,7 +1178,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'r' in 'there' - curwin('set_cursor', { 2, 8 }) + meths.nvim_win_set_cursor(0, { 2, 8 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 0, 2, 4, {}) @@ -1168,7 +1187,7 @@ describe('api/buf', function() eq({ 'finally the last one' }, get_lines(0, -1, true)) -- cursor should end up in column 0 - eq({ 1, 0 }, curwin('get_cursor')) + eq({ 1, 0 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 0 }, cursor) end) @@ -1180,7 +1199,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'y' in 'finally' - curwin('set_cursor', { 3, 10 }) + meths.nvim_win_set_cursor(0, { 3, 10 }) set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' }) eq({ @@ -1189,7 +1208,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor should end up on 'n' in 'then' - eq({ 3, 7 }, curwin('get_cursor')) + eq({ 3, 7 }, meths.nvim_win_get_cursor(0)) end) it( @@ -1201,7 +1220,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'y' at 'finally' - curwin('set_cursor', { 3, 10 }) + meths.nvim_win_set_cursor(0, { 3, 10 }) -- enter INSERT mode to treat cursor as being between 'l' and 'y' feed('i') set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' }) @@ -1212,7 +1231,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor should end up after 'n' in 'then' - eq({ 3, 8 }, curwin('get_cursor')) + eq({ 3, 8 }, meths.nvim_win_get_cursor(0)) end ) @@ -1223,7 +1242,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'y' in 'finally' - curwin('set_cursor', { 3, 10 }) + meths.nvim_win_set_cursor(0, { 3, 10 }) set_text(2, 4, 2, 11, { 'then' }) eq({ @@ -1232,7 +1251,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor should end up on 'n' in 'then' - eq({ 3, 7 }, curwin('get_cursor')) + eq({ 3, 7 }, meths.nvim_win_get_cursor(0)) end) it('does not move cursor column after end of a line', function() @@ -1241,7 +1260,7 @@ describe('api/buf', function() !!!]]) -- position cursor on the last '1' - curwin('set_cursor', { 2, 2 }) + meths.nvim_win_set_cursor(0, { 2, 2 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 33, 1, 3, {}) @@ -1250,7 +1269,7 @@ describe('api/buf', function() eq({ 'This should be the only line here' }, get_lines(0, -1, true)) -- cursor should end up on '!' - eq({ 1, 32 }, curwin('get_cursor')) + eq({ 1, 32 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 32 }, cursor) end) @@ -1259,7 +1278,7 @@ describe('api/buf', function() insert('\n!!!') -- position cursor on the last '1' - curwin('set_cursor', { 2, 2 }) + meths.nvim_win_set_cursor(0, { 2, 2 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 0, 1, 3, {}) @@ -1268,7 +1287,7 @@ describe('api/buf', function() eq({ '' }, get_lines(0, -1, true)) -- cursor should end up on '!' - eq({ 1, 0 }, curwin('get_cursor')) + eq({ 1, 0 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 0 }, cursor) end) @@ -1281,7 +1300,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 't' in 'want' - curwin('set_cursor', { 2, 34 }) + meths.nvim_win_set_cursor(0, { 2, 34 }) -- turn on virtualedit command('set virtualedit=all') @@ -1299,7 +1318,7 @@ describe('api/buf', function() }, get_lines(0, -1, true)) -- cursor should end up on 'y' in 'hopefully' -- to stay in the range - eq({ 2, 12 }, curwin('get_cursor')) + eq({ 2, 12 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 12 }, cursor) -- coladd should be 0 @@ -1318,7 +1337,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 't' in 'want' - curwin('set_cursor', { 2, 34 }) + meths.nvim_win_set_cursor(0, { 2, 34 }) -- turn on virtualedit command('set virtualedit=all') -- move cursor after eol @@ -1339,7 +1358,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should end up at eol of a new row - eq({ 2, 26 }, curwin('get_cursor')) + eq({ 2, 26 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 26 }, cursor) -- coladd should be increased so that cursor stays in the same screen column @@ -1360,7 +1379,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 't' in 'first' - curwin('set_cursor', { 1, 19 }) + meths.nvim_win_set_cursor(0, { 1, 19 }) -- turn on virtualedit command('set virtualedit=all') -- move cursor after eol @@ -1381,7 +1400,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should end up at eol of a new row - eq({ 1, 38 }, curwin('get_cursor')) + eq({ 1, 38 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 38 }, cursor) -- coladd should be increased so that cursor stays in the same screen column @@ -1403,7 +1422,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 't' in 'first' - curwin('set_cursor', { 1, 19 }) + meths.nvim_win_set_cursor(0, { 1, 19 }) -- turn on virtualedit command('set virtualedit=all') -- move cursor after eol just a bit @@ -1424,7 +1443,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should stay at the same screen column - eq({ 1, 22 }, curwin('get_cursor')) + eq({ 1, 22 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 22 }, cursor) -- coladd should become 0 @@ -1447,7 +1466,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 'e' in 'more' - curwin('set_cursor', { 3, 11 }) + meths.nvim_win_set_cursor(0, { 3, 11 }) -- turn on virtualedit command('set virtualedit=all') -- move cursor after eol @@ -1468,7 +1487,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should end up at eol of a new row - eq({ 2, 26 }, curwin('get_cursor')) + eq({ 2, 26 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 26 }, cursor) -- coladd should be increased so that cursor stays in the same screen column @@ -1491,17 +1510,17 @@ describe('api/buf', function() line]]) -- position the cursor on 'i' - curwin('set_cursor', { 3, 2 }) + meths.nvim_win_set_cursor(0, { 3, 2 }) set_text(1, 6, 2, 0, {}) eq({ 'first line', 'second line' }, get_lines(0, -1, true)) -- cursor should stay on 'i' - eq({ 2, 8 }, curwin('get_cursor')) + eq({ 2, 8 }, meths.nvim_win_get_cursor(0)) -- add a newline back set_text(1, 6, 1, 6, { '', '' }) eq({ 'first line', 'second', ' line' }, get_lines(0, -1, true)) -- cursor should return back to the original position - eq({ 3, 2 }, curwin('get_cursor')) + eq({ 3, 2 }, meths.nvim_win_get_cursor(0)) end) it( @@ -1513,11 +1532,11 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'h' in 'the' - curwin('set_cursor', { 3, 13 }) + meths.nvim_win_set_cursor(0, { 3, 13 }) set_text(0, 14, 2, 11, {}) eq({ 'This should be the last one' }, get_lines(0, -1, true)) -- cursor should stay on 'h' - eq({ 1, 16 }, curwin('get_cursor')) + eq({ 1, 16 }, meths.nvim_win_get_cursor(0)) -- add deleted lines back set_text(0, 14, 0, 14, { ' first', @@ -1530,7 +1549,7 @@ describe('api/buf', function() 'and finally the last one', }, get_lines(0, -1, true)) -- cursor should return back to the original position - eq({ 3, 13 }, curwin('get_cursor')) + eq({ 3, 13 }, meths.nvim_win_get_cursor(0)) end ) @@ -1543,7 +1562,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 's' in 'last' - curwin('set_cursor', { 3, 18 }) + meths.nvim_win_set_cursor(0, { 3, 18 }) set_text(0, 15, 2, 11, { 'the line we do not want', 'but hopefully', @@ -1554,7 +1573,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should stay on 's' - eq({ 2, 20 }, curwin('get_cursor')) + eq({ 2, 20 }, meths.nvim_win_get_cursor(0)) set_text(0, 15, 1, 13, { 'first', @@ -1568,7 +1587,7 @@ describe('api/buf', function() 'and finally the last one', }, get_lines(0, -1, true)) -- cursor should return back to the original position - eq({ 3, 18 }, curwin('get_cursor')) + eq({ 3, 18 }, meths.nvim_win_get_cursor(0)) end ) @@ -1578,7 +1597,7 @@ describe('api/buf', function() ]]) -- position cursor at the empty line - curwin('set_cursor', { 2, 0 }) + meths.nvim_win_set_cursor(0, { 2, 0 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 33, 1, 0, {'!'}) @@ -1587,7 +1606,7 @@ describe('api/buf', function() eq({ 'This should be the only line here!' }, get_lines(0, -1, true)) -- cursor should end up on '!' - eq({ 1, 33 }, curwin('get_cursor')) + eq({ 1, 33 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 33 }, cursor) end) @@ -1598,7 +1617,7 @@ describe('api/buf', function() eq({ '', '' }, get_lines(0, -1, true)) -- position cursor on the last '1' - curwin('set_cursor', { 2, 2 }) + meths.nvim_win_set_cursor(0, { 2, 2 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 0, 1, 0, {''}) @@ -1607,7 +1626,7 @@ describe('api/buf', function() eq({ '' }, get_lines(0, -1, true)) -- cursor should end up on '!' - eq({ 1, 0 }, curwin('get_cursor')) + eq({ 1, 0 }, meths.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 0 }, cursor) end) @@ -1619,46 +1638,46 @@ describe('api/buf', function() end) it('adjusts extmarks', function() - local ns = request('nvim_create_namespace', 'my-fancy-plugin') + local ns = meths.nvim_create_namespace('my-fancy-plugin') insert([[ foo bar baz ]]) - local id1 = curbufmeths.set_extmark(ns, 0, 1, {}) - local id2 = curbufmeths.set_extmark(ns, 0, 7, {}) - local id3 = curbufmeths.set_extmark(ns, 1, 1, {}) + local id1 = meths.nvim_buf_set_extmark(0, ns, 0, 1, {}) + local id2 = meths.nvim_buf_set_extmark(0, ns, 0, 7, {}) + local id3 = meths.nvim_buf_set_extmark(0, ns, 1, 1, {}) set_text(0, 4, 0, 7, { 'q' }) eq({ 'foo q', 'baz' }, get_lines(0, 2, true)) -- mark before replacement point is unaffected - eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {})) + eq({ 0, 1 }, meths.nvim_buf_get_extmark_by_id(0, ns, id1, {})) -- mark gets shifted back because the replacement was shorter - eq({ 0, 5 }, curbufmeths.get_extmark_by_id(ns, id2, {})) + eq({ 0, 5 }, meths.nvim_buf_get_extmark_by_id(0, ns, id2, {})) -- mark on the next line is unaffected - eq({ 1, 1 }, curbufmeths.get_extmark_by_id(ns, id3, {})) + eq({ 1, 1 }, meths.nvim_buf_get_extmark_by_id(0, ns, id3, {})) -- replacing the text spanning two lines will adjust the mark on the next line set_text(0, 3, 1, 3, { 'qux' }) eq({ 'fooqux', '' }, get_lines(0, 2, true)) - eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id3, {})) + eq({ 0, 6 }, meths.nvim_buf_get_extmark_by_id(0, ns, id3, {})) -- but mark before replacement point is still unaffected - eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {})) + eq({ 0, 1 }, meths.nvim_buf_get_extmark_by_id(0, ns, id1, {})) -- and the mark in the middle was shifted to the end of the insertion - eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id2, {})) + eq({ 0, 6 }, meths.nvim_buf_get_extmark_by_id(0, ns, id2, {})) -- marks should be put back into the same place after undoing set_text(0, 0, 0, 2, { '' }) feed('u') - eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {})) - eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id2, {})) - eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id3, {})) + eq({ 0, 1 }, meths.nvim_buf_get_extmark_by_id(0, ns, id1, {})) + eq({ 0, 6 }, meths.nvim_buf_get_extmark_by_id(0, ns, id2, {})) + eq({ 0, 6 }, meths.nvim_buf_get_extmark_by_id(0, ns, id3, {})) -- marks should be shifted over by the correct number of bytes for multibyte -- chars set_text(0, 0, 0, 0, { 'Ø' }) - eq({ 0, 3 }, curbufmeths.get_extmark_by_id(ns, id1, {})) - eq({ 0, 8 }, curbufmeths.get_extmark_by_id(ns, id2, {})) - eq({ 0, 8 }, curbufmeths.get_extmark_by_id(ns, id3, {})) + eq({ 0, 3 }, meths.nvim_buf_get_extmark_by_id(0, ns, id1, {})) + eq({ 0, 8 }, meths.nvim_buf_get_extmark_by_id(0, ns, id2, {})) + eq({ 0, 8 }, meths.nvim_buf_get_extmark_by_id(0, ns, id3, {})) end) it('correctly marks changed region for redraw #13890', function() @@ -1670,7 +1689,7 @@ describe('api/buf', function() BBB ]]) - curbufmeths.set_text(0, 0, 1, 3, { 'XXX', 'YYY' }) + meths.nvim_buf_set_text(0, 0, 0, 1, 3, { 'XXX', 'YYY' }) screen:expect([[ XXX | @@ -1727,7 +1746,7 @@ describe('api/buf', function() 0, 0, -1, - 1, + true, { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' } ) meths.nvim_set_option_value('modified', false, {}) @@ -1854,7 +1873,7 @@ describe('api/buf', function() end) describe_lua_and_rpc('nvim_buf_get_text', function(api) - local get_text = api.curbufmeths.get_text + local get_text = api.meths.nvim_buf_get_text before_each(function() insert([[ hello foo! @@ -1863,105 +1882,105 @@ describe('api/buf', function() end) it('works', function() - eq({ 'hello' }, get_text(0, 0, 0, 5, {})) - eq({ 'hello foo!' }, get_text(0, 0, 0, 42, {})) - eq({ 'foo!' }, get_text(0, 6, 0, 10, {})) - eq({ 'foo!', 'tex' }, get_text(0, 6, 1, 3, {})) - eq({ 'foo!', 'tex' }, get_text(-3, 6, -2, 3, {})) - eq({ '' }, get_text(0, 18, 0, 20, {})) - eq({ 'ext' }, get_text(-2, 1, -2, 4, {})) - eq({ 'hello foo!', 'text', 'm' }, get_text(0, 0, 2, 1, {})) + eq({ 'hello' }, get_text(0, 0, 0, 0, 5, {})) + eq({ 'hello foo!' }, get_text(0, 0, 0, 0, 42, {})) + eq({ 'foo!' }, get_text(0, 0, 6, 0, 10, {})) + eq({ 'foo!', 'tex' }, get_text(0, 0, 6, 1, 3, {})) + eq({ 'foo!', 'tex' }, get_text(0, -3, 6, -2, 3, {})) + eq({ '' }, get_text(0, 0, 18, 0, 20, {})) + eq({ 'ext' }, get_text(0, -2, 1, -2, 4, {})) + eq({ 'hello foo!', 'text', 'm' }, get_text(0, 0, 0, 2, 1, {})) end) it('errors on out-of-range', function() - eq('Index out of bounds', pcall_err(get_text, 2, 0, 4, 0, {})) - eq('Index out of bounds', pcall_err(get_text, -4, 0, 0, 0, {})) - eq('Index out of bounds', pcall_err(get_text, 0, 0, 3, 0, {})) - eq('Index out of bounds', pcall_err(get_text, 0, 0, -4, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 2, 0, 4, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, -4, 0, 0, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, 0, 3, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, 0, -4, 0, {})) -- no ml_get errors should happen #19017 eq('', meths.nvim_get_vvar('errmsg')) end) it('errors when start is greater than end', function() - eq("'start' is higher than 'end'", pcall_err(get_text, 1, 0, 0, 0, {})) - eq('start_col must be less than end_col', pcall_err(get_text, 0, 1, 0, 0, {})) + eq("'start' is higher than 'end'", pcall_err(get_text, 0, 1, 0, 0, 0, {})) + eq('start_col must be less than end_col', pcall_err(get_text, 0, 0, 1, 0, 0, {})) end) end) describe('nvim_buf_get_offset', function() - local get_offset = curbufmeths.get_offset + local get_offset = meths.nvim_buf_get_offset it('works', function() - curbufmeths.set_lines(0, -1, true, { 'Some\r', 'exa\000mple', '', 'buf\rfer', 'text' }) - eq(5, curbufmeths.line_count()) - eq(0, get_offset(0)) - eq(6, get_offset(1)) - eq(15, get_offset(2)) - eq(16, get_offset(3)) - eq(24, get_offset(4)) - eq(29, get_offset(5)) - eq('Index out of bounds', pcall_err(get_offset, 6)) - eq('Index out of bounds', pcall_err(get_offset, -1)) + meths.nvim_buf_set_lines(0, 0, -1, true, { 'Some\r', 'exa\000mple', '', 'buf\rfer', 'text' }) + eq(5, meths.nvim_buf_line_count(0)) + eq(0, get_offset(0, 0)) + eq(6, get_offset(0, 1)) + eq(15, get_offset(0, 2)) + eq(16, get_offset(0, 3)) + eq(24, get_offset(0, 4)) + eq(29, get_offset(0, 5)) + eq('Index out of bounds', pcall_err(get_offset, 0, 6)) + eq('Index out of bounds', pcall_err(get_offset, 0, -1)) meths.nvim_set_option_value('eol', false, {}) meths.nvim_set_option_value('fixeol', false, {}) - eq(28, get_offset(5)) + eq(28, get_offset(0, 5)) -- fileformat is ignored meths.nvim_set_option_value('fileformat', 'dos', {}) - eq(0, get_offset(0)) - eq(6, get_offset(1)) - eq(15, get_offset(2)) - eq(16, get_offset(3)) - eq(24, get_offset(4)) - eq(28, get_offset(5)) + eq(0, get_offset(0, 0)) + eq(6, get_offset(0, 1)) + eq(15, get_offset(0, 2)) + eq(16, get_offset(0, 3)) + eq(24, get_offset(0, 4)) + eq(28, get_offset(0, 5)) meths.nvim_set_option_value('eol', true, {}) - eq(29, get_offset(5)) + eq(29, get_offset(0, 5)) command('set hidden') command('enew') - eq(6, bufmeths.get_offset(1, 1)) + eq(6, meths.nvim_buf_get_offset(1, 1)) command('bunload! 1') - eq(-1, bufmeths.get_offset(1, 1)) - eq(-1, bufmeths.get_offset(1, 0)) + eq(-1, meths.nvim_buf_get_offset(1, 1)) + eq(-1, meths.nvim_buf_get_offset(1, 0)) end) it('works in empty buffer', function() - eq(0, get_offset(0)) - eq(1, get_offset(1)) + eq(0, get_offset(0, 0)) + eq(1, get_offset(0, 1)) eq(-1, funcs.line2byte('$')) end) it('works in buffer with one line inserted', function() feed('itext') - eq(0, get_offset(0)) - eq(5, get_offset(1)) + eq(0, get_offset(0, 0)) + eq(5, get_offset(0, 1)) end) end) describe('nvim_buf_get_var, nvim_buf_set_var, nvim_buf_del_var', function() it('works', function() - curbuf('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) - eq({ 1, 2, { ['3'] = 1 } }, curbuf('get_var', 'lua')) - eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'b:lua')) + meths.nvim_buf_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_buf_get_var(0, 'lua')) + eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('b:lua')) eq(1, funcs.exists('b:lua')) - curbufmeths.del_var('lua') + meths.nvim_buf_del_var(0, 'lua') eq(0, funcs.exists('b:lua')) - eq('Key not found: lua', pcall_err(curbufmeths.del_var, 'lua')) - curbufmeths.set_var('lua', 1) + eq('Key not found: lua', pcall_err(meths.nvim_buf_del_var, 0, 'lua')) + meths.nvim_buf_set_var(0, 'lua', 1) command('lockvar b:lua') - eq('Key is locked: lua', pcall_err(curbufmeths.del_var, 'lua')) - eq('Key is locked: lua', pcall_err(curbufmeths.set_var, 'lua', 1)) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, 'changedtick')) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.set_var, 'changedtick', 1)) + eq('Key is locked: lua', pcall_err(meths.nvim_buf_del_var, 0, 'lua')) + eq('Key is locked: lua', pcall_err(meths.nvim_buf_set_var, 0, 'lua', 1)) + eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_del_var, 0, 'changedtick')) + eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_set_var, 0, 'changedtick', 1)) end) end) describe('nvim_buf_get_changedtick', function() it('works', function() - eq(2, curbufmeths.get_changedtick()) - curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' }) - eq(3, curbufmeths.get_changedtick()) - eq(3, curbufmeths.get_var('changedtick')) + eq(2, meths.nvim_buf_get_changedtick(0)) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' }) + eq(3, meths.nvim_buf_get_changedtick(0)) + eq(3, meths.nvim_buf_get_var(0, 'changedtick')) end) it('buffer_set_var returns the old value', function() @@ -1982,32 +2001,32 @@ describe('api/buf', function() describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - eq(8, nvim('get_option_value', 'shiftwidth', {})) - nvim('set_option_value', 'shiftwidth', 4, {}) - eq(4, nvim('get_option_value', 'shiftwidth', {})) + eq(8, meths.nvim_get_option_value('shiftwidth', {})) + meths.nvim_set_option_value('shiftwidth', 4, {}) + eq(4, meths.nvim_get_option_value('shiftwidth', {})) -- global-local option - nvim('set_option_value', 'define', 'test', { buf = 0 }) - eq('test', nvim('get_option_value', 'define', { buf = 0 })) + meths.nvim_set_option_value('define', 'test', { buf = 0 }) + eq('test', meths.nvim_get_option_value('define', { buf = 0 })) -- Doesn't change the global value - eq('', nvim('get_option_value', 'define', { scope = 'global' })) + eq('', meths.nvim_get_option_value('define', { scope = 'global' })) end) it('returns values for unset local options', function() -- 'undolevels' is only set to its "unset" value when a new buffer is -- created command('enew') - eq(-123456, nvim('get_option_value', 'undolevels', { buf = 0 })) + eq(-123456, meths.nvim_get_option_value('undolevels', { buf = 0 })) end) end) describe('nvim_buf_get_name, nvim_buf_set_name', function() it('works', function() - nvim('command', 'new') - eq('', curbuf('get_name')) - local new_name = nvim('eval', 'resolve(tempname())') - curbuf('set_name', new_name) - eq(new_name, curbuf('get_name')) - nvim('command', 'w!') + command('new') + eq('', meths.nvim_buf_get_name(0)) + local new_name = meths.nvim_eval('resolve(tempname())') + meths.nvim_buf_set_name(0, new_name) + eq(new_name, meths.nvim_buf_get_name(0)) + command('w!') eq(1, funcs.filereadable(new_name)) os.remove(new_name) end) @@ -2016,83 +2035,83 @@ describe('api/buf', function() describe('nvim_buf_is_loaded', function() it('works', function() -- record our buffer number for when we unload it - local bufnr = curbuf('get_number') + local bufnr = meths.nvim_buf_get_number(0) -- api should report that the buffer is loaded - ok(buffer('is_loaded', bufnr)) + ok(meths.nvim_buf_is_loaded(bufnr)) -- hide the current buffer by switching to a new empty buffer -- Careful! we need to modify the buffer first or vim will just reuse it - buffer('set_lines', bufnr, 0, -1, 1, { 'line1' }) + meths.nvim_buf_set_lines(bufnr, 0, -1, true, { 'line1' }) command('hide enew') -- confirm the buffer is hidden, but still loaded - local infolist = nvim('eval', 'getbufinfo(' .. bufnr .. ')') + local infolist = meths.nvim_eval('getbufinfo(' .. bufnr .. ')') eq(1, #infolist) eq(1, infolist[1].hidden) eq(1, infolist[1].loaded) -- now force unload the buffer command('bunload! ' .. bufnr) -- confirm the buffer is unloaded - infolist = nvim('eval', 'getbufinfo(' .. bufnr .. ')') + infolist = meths.nvim_eval('getbufinfo(' .. bufnr .. ')') eq(0, infolist[1].loaded) -- nvim_buf_is_loaded() should also report the buffer as unloaded - eq(false, buffer('is_loaded', bufnr)) + eq(false, meths.nvim_buf_is_loaded(bufnr)) end) end) describe('nvim_buf_is_valid', function() it('works', function() - nvim('command', 'new') - local b = nvim('get_current_buf') - ok(buffer('is_valid', b)) - nvim('command', 'bw!') - ok(not buffer('is_valid', b)) + command('new') + local b = meths.nvim_get_current_buf() + ok(meths.nvim_buf_is_valid(b)) + command('bw!') + ok(not meths.nvim_buf_is_valid(b)) end) end) describe('nvim_buf_delete', function() it('allows for just deleting', function() - nvim('command', 'new') - local b = nvim('get_current_buf') - ok(buffer('is_valid', b)) - nvim('buf_delete', b, {}) - ok(not buffer('is_loaded', b)) - ok(not buffer('is_valid', b)) + command('new') + local b = meths.nvim_get_current_buf() + ok(meths.nvim_buf_is_valid(b)) + meths.nvim_buf_delete(b, {}) + ok(not meths.nvim_buf_is_loaded(b)) + ok(not meths.nvim_buf_is_valid(b)) end) it('allows for just unloading', function() - nvim('command', 'new') - local b = nvim('get_current_buf') - ok(buffer('is_valid', b)) - nvim('buf_delete', b, { unload = true }) - ok(not buffer('is_loaded', b)) - ok(buffer('is_valid', b)) + command('new') + local b = meths.nvim_get_current_buf() + ok(meths.nvim_buf_is_valid(b)) + meths.nvim_buf_delete(b, { unload = true }) + ok(not meths.nvim_buf_is_loaded(b)) + ok(meths.nvim_buf_is_valid(b)) end) end) describe('nvim_buf_get_mark', function() it('works', function() - curbuf('set_lines', -1, -1, true, { 'a', 'bit of', 'text' }) - curwin('set_cursor', { 3, 4 }) - nvim('command', 'mark v') - eq({ 3, 0 }, curbuf('get_mark', 'v')) + meths.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + meths.nvim_win_set_cursor(0, { 3, 4 }) + command('mark v') + eq({ 3, 0 }, meths.nvim_buf_get_mark(0, 'v')) end) end) describe('nvim_buf_set_mark', function() it('works with buffer local marks', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - eq(true, curbufmeths.set_mark('z', 1, 1, {})) - eq({ 1, 1 }, curbufmeths.get_mark('z')) + meths.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + eq(true, meths.nvim_buf_set_mark(0, 'z', 1, 1, {})) + eq({ 1, 1 }, meths.nvim_buf_get_mark(0, 'z')) eq({ 0, 1, 2, 0 }, funcs.getpos("'z")) end) it('works with file/uppercase marks', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - eq(true, curbufmeths.set_mark('Z', 3, 2, {})) - eq({ 3, 2 }, curbufmeths.get_mark('Z')) - eq({ curbuf().id, 3, 3, 0 }, funcs.getpos("'Z")) + meths.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + eq(true, meths.nvim_buf_set_mark(0, 'Z', 3, 2, {})) + eq({ 3, 2 }, meths.nvim_buf_get_mark(0, 'Z')) + eq({ meths.nvim_get_current_buf().id, 3, 3, 0 }, funcs.getpos("'Z")) end) it('fails when invalid marks names are used', function() - eq(false, pcall(curbufmeths.set_mark, '!', 1, 0, {})) - eq(false, pcall(curbufmeths.set_mark, 'fail', 1, 0, {})) + eq(false, pcall(meths.nvim_buf_set_mark, 0, '!', 1, 0, {})) + eq(false, pcall(meths.nvim_buf_set_mark, 0, 'fail', 1, 0, {})) end) it('fails when invalid buffer number is used', function() eq(false, pcall(meths.nvim_buf_set_mark, 99, 'a', 1, 1, {})) @@ -2101,33 +2120,33 @@ describe('api/buf', function() describe('nvim_buf_del_mark', function() it('works with buffer local marks', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - curbufmeths.set_mark('z', 3, 1, {}) - eq(true, curbufmeths.del_mark('z')) - eq({ 0, 0 }, curbufmeths.get_mark('z')) + meths.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + meths.nvim_buf_set_mark(0, 'z', 3, 1, {}) + eq(true, meths.nvim_buf_del_mark(0, 'z')) + eq({ 0, 0 }, meths.nvim_buf_get_mark(0, 'z')) end) it('works with file/uppercase marks', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - curbufmeths.set_mark('Z', 3, 3, {}) - eq(true, curbufmeths.del_mark('Z')) - eq({ 0, 0 }, curbufmeths.get_mark('Z')) + meths.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + meths.nvim_buf_set_mark(0, 'Z', 3, 3, {}) + eq(true, meths.nvim_buf_del_mark(0, 'Z')) + eq({ 0, 0 }, meths.nvim_buf_get_mark(0, 'Z')) end) it('returns false in marks not set in this buffer', function() local abuf = meths.nvim_create_buf(false, true) - bufmeths.set_lines(abuf, -1, -1, true, { 'a', 'bit of', 'text' }) - bufmeths.set_mark(abuf, 'A', 2, 2, {}) - eq(false, curbufmeths.del_mark('A')) - eq({ 2, 2 }, bufmeths.get_mark(abuf, 'A')) + meths.nvim_buf_set_lines(abuf, -1, -1, true, { 'a', 'bit of', 'text' }) + meths.nvim_buf_set_mark(abuf, 'A', 2, 2, {}) + eq(false, meths.nvim_buf_del_mark(0, 'A')) + eq({ 2, 2 }, meths.nvim_buf_get_mark(abuf, 'A')) end) it('returns false if mark was not deleted', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - curbufmeths.set_mark('z', 3, 1, {}) - eq(true, curbufmeths.del_mark('z')) - eq(false, curbufmeths.del_mark('z')) -- Mark was already deleted + meths.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + meths.nvim_buf_set_mark(0, 'z', 3, 1, {}) + eq(true, meths.nvim_buf_del_mark(0, 'z')) + eq(false, meths.nvim_buf_del_mark(0, 'z')) -- Mark was already deleted end) it('fails when invalid marks names are used', function() - eq(false, pcall(curbufmeths.del_mark, '!')) - eq(false, pcall(curbufmeths.del_mark, 'fail')) + eq(false, pcall(meths.nvim_buf_del_mark, 0, '!')) + eq(false, pcall(meths.nvim_buf_del_mark, 0, 'fail')) end) it('fails when invalid buffer number is used', function() eq(false, pcall(meths.nvim_buf_del_mark, 99, 'a')) diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index af6404fe7f..254e7d4d42 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -2,8 +2,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq, ok = helpers.eq, helpers.ok local funcs = helpers.funcs -local buffer, command, eval, nvim, next_msg = - helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg +local meths = helpers.meths +local command, eval, next_msg = helpers.command, helpers.eval, helpers.next_msg local nvim_prog = helpers.nvim_prog local pcall_err = helpers.pcall_err local sleep = vim.uv.sleep @@ -24,7 +24,7 @@ local function expectn(name, args) end local function sendkeys(keys) - nvim('input', keys) + meths.nvim_input(keys) -- give nvim some time to process msgpack requests before possibly sending -- more key presses - otherwise they all pile up in the queue and get -- processed at once @@ -37,7 +37,7 @@ local function open(activate, lines) local filename = helpers.tmpname() write_file(filename, table.concat(lines, '\n') .. '\n', true) command('edit ' .. filename) - local b = nvim('get_current_buf') + local b = meths.nvim_get_current_buf() -- what is the value of b:changedtick? local tick = eval('b:changedtick') @@ -45,7 +45,7 @@ local function open(activate, lines) -- arrive as expected if activate then local firstline = 0 - ok(buffer('attach', b, true, {})) + ok(meths.nvim_buf_attach(b, true, {})) expectn('nvim_buf_lines_event', { b, tick, firstline, -1, lines, false }) end @@ -62,12 +62,12 @@ local function editoriginal(activate, lines) end local function reopen(buf, expectedlines) - ok(buffer('detach', buf)) + ok(meths.nvim_buf_detach(buf)) expectn('nvim_buf_detach_event', { buf }) -- for some reason the :edit! increments tick by 2 command('edit!') local tick = eval('b:changedtick') - ok(buffer('attach', buf, true, {})) + ok(meths.nvim_buf_attach(buf, true, {})) local firstline = 0 expectn('nvim_buf_lines_event', { buf, tick, firstline, -1, expectedlines, false }) command('normal! gg') @@ -197,21 +197,21 @@ describe('API: buffer events:', function() -- add a line at the start of an empty file command('enew') tick = eval('b:changedtick') - local b2 = nvim('get_current_buf') - ok(buffer('attach', b2, true, {})) + local b2 = meths.nvim_get_current_buf() + ok(meths.nvim_buf_attach(b2, true, {})) expectn('nvim_buf_lines_event', { b2, tick, 0, -1, { '' }, false }) eval('append(0, ["new line 1"])') tick = tick + 1 expectn('nvim_buf_lines_event', { b2, tick, 0, 0, { 'new line 1' }, false }) -- turn off buffer events manually - buffer('detach', b2) + meths.nvim_buf_detach(b2) expectn('nvim_buf_detach_event', { b2 }) -- add multiple lines to a blank file command('enew!') - local b3 = nvim('get_current_buf') - ok(buffer('attach', b3, true, {})) + local b3 = meths.nvim_get_current_buf() + ok(meths.nvim_buf_attach(b3, true, {})) tick = eval('b:changedtick') expectn('nvim_buf_lines_event', { b3, tick, 0, -1, { '' }, false }) eval('append(0, ["new line 1", "new line 2", "new line 3"])') @@ -222,7 +222,7 @@ describe('API: buffer events:', function() ) -- use the API itself to add a line to the start of the buffer - buffer('set_lines', b3, 0, 0, true, { 'New First Line' }) + meths.nvim_buf_set_lines(b3, 0, 0, true, { 'New First Line' }) tick = tick + 1 expectn('nvim_buf_lines_event', { b3, tick, 0, 0, { 'New First Line' }, false }) end) @@ -306,8 +306,8 @@ describe('API: buffer events:', function() command('bdelete!') tick = 2 expectn('nvim_buf_detach_event', { b }) - local bnew = nvim('get_current_buf') - ok(buffer('attach', bnew, true, {})) + local bnew = meths.nvim_get_current_buf() + ok(meths.nvim_buf_attach(bnew, true, {})) expectn('nvim_buf_lines_event', { bnew, tick, 0, -1, { '' }, false }) sendkeys('i') sendkeys('h') @@ -472,25 +472,25 @@ describe('API: buffer events:', function() end) it('does not get confused if enabled/disabled many times', function() - local channel = nvim('get_api_info')[1] + local channel = meths.nvim_get_api_info()[1] local b, tick = editoriginal(false) -- Enable buffer events many times. - ok(buffer('attach', b, true, {})) - ok(buffer('attach', b, true, {})) - ok(buffer('attach', b, true, {})) - ok(buffer('attach', b, true, {})) - ok(buffer('attach', b, true, {})) + ok(meths.nvim_buf_attach(b, true, {})) + ok(meths.nvim_buf_attach(b, true, {})) + ok(meths.nvim_buf_attach(b, true, {})) + ok(meths.nvim_buf_attach(b, true, {})) + ok(meths.nvim_buf_attach(b, true, {})) expectn('nvim_buf_lines_event', { b, tick, 0, -1, origlines, false }) eval('rpcnotify(' .. channel .. ', "Hello There")') expectn('Hello There', {}) -- Disable buffer events many times. - ok(buffer('detach', b)) - ok(buffer('detach', b)) - ok(buffer('detach', b)) - ok(buffer('detach', b)) - ok(buffer('detach', b)) + ok(meths.nvim_buf_detach(b)) + ok(meths.nvim_buf_detach(b)) + ok(meths.nvim_buf_detach(b)) + ok(meths.nvim_buf_detach(b)) + ok(meths.nvim_buf_detach(b)) expectn('nvim_buf_detach_event', { b }) eval('rpcnotify(' .. channel .. ', "Hello Again")') expectn('Hello Again', {}) @@ -573,7 +573,7 @@ describe('API: buffer events:', function() it('works with :diffput and :diffget', function() local b1, tick1 = editoriginal(true, { 'AAA', 'BBB' }) - local channel = nvim('get_api_info')[1] + local channel = meths.nvim_get_api_info()[1] command('diffthis') command('rightbelow vsplit') local b2, tick2 = open(true, { 'BBB', 'CCC' }) @@ -690,7 +690,7 @@ describe('API: buffer events:', function() it('detaches if the buffer is closed', function() local b, tick = editoriginal(true, { 'AAA' }) - local channel = nvim('get_api_info')[1] + local channel = meths.nvim_get_api_info()[1] -- Test that buffer events are working. command('normal! x') @@ -729,7 +729,7 @@ describe('API: buffer events:', function() it(':enew! does not detach hidden buffer', function() local b, tick = editoriginal(true, { 'AAA', 'BBB' }) - local channel = nvim('get_api_info')[1] + local channel = meths.nvim_get_api_info()[1] command('set undoreload=1 hidden') command('normal! x') @@ -743,7 +743,7 @@ describe('API: buffer events:', function() it('stays attached if the buffer is hidden', function() local b, tick = editoriginal(true, { 'AAA' }) - local channel = nvim('get_api_info')[1] + local channel = meths.nvim_get_api_info()[1] -- Test that buffer events are working. command('normal! x') @@ -790,14 +790,14 @@ describe('API: buffer events:', function() it('does not send the buffer content if not requested', function() clear() local b, tick = editoriginal(false) - ok(buffer('attach', b, false, {})) + ok(meths.nvim_buf_attach(b, false, {})) expectn('nvim_buf_changedtick_event', { b, tick }) end) it('returns a proper error on nonempty options dict', function() clear() local b = editoriginal(false) - eq("Invalid key: 'builtin'", pcall_err(buffer, 'attach', b, false, { builtin = 'asfd' })) + eq("Invalid key: 'builtin'", pcall_err(meths.nvim_buf_attach, b, false, { builtin = 'asfd' })) end) it('nvim_buf_attach returns response after delay #8634', function() @@ -873,8 +873,8 @@ describe('API: buffer events:', function() env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) - local b = nvim('get_current_buf') - ok(buffer('attach', b, true, {})) + local b = meths.nvim_get_current_buf() + ok(meths.nvim_buf_attach(b, true, {})) for _ = 1, 22 do table.insert(expected_lines, '~') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index f1e3c5155d..dc6a68da03 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -3,10 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local NIL = vim.NIL local clear = helpers.clear local command = helpers.command -local curbufmeths = helpers.curbufmeths local eq = helpers.eq local meths = helpers.meths -local bufmeths = helpers.bufmeths local matches = helpers.matches local source = helpers.source local pcall_err = helpers.pcall_err @@ -74,16 +72,16 @@ describe('nvim_get_commands', function() 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 })) + eq({ Hello = cmd_dict }, meths.nvim_buf_get_commands(0, { 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 })) + eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.nvim_buf_get_commands(0, { builtin = false })) -- Delete a command. command('delcommand Pwd') - eq({ Hello = cmd_dict }, curbufmeths.get_commands({ builtin = false })) + eq({ Hello = cmd_dict }, meths.nvim_buf_get_commands(0, { builtin = false })) -- {builtin=true} always returns empty for buffer-local case. - eq({}, curbufmeths.get_commands({ builtin = true })) + eq({}, meths.nvim_buf_get_commands(0, { builtin = true })) end) it('gets various command attributes', function() @@ -203,7 +201,7 @@ describe('nvim_create_user_command', function() it('works with strings', function() meths.nvim_create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 }) - meths.nvim_command('SomeCommand 42') + command('SomeCommand 42') eq(42, meths.nvim_eval('g:command_fired')) end) @@ -647,10 +645,10 @@ describe('nvim_create_user_command', function() it('can define buffer-local commands', function() local bufnr = meths.nvim_create_buf(false, false) - bufmeths.create_user_command(bufnr, 'Hello', '', {}) - matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello')) + meths.nvim_buf_create_user_command(bufnr, 'Hello', '', {}) + matches('Not an editor command: Hello', pcall_err(command, 'Hello')) meths.nvim_set_current_buf(bufnr) - meths.nvim_command('Hello') + command('Hello') assert_alive() end) @@ -762,15 +760,15 @@ describe('nvim_del_user_command', function() it('can delete global commands', function() meths.nvim_create_user_command('Hello', 'echo "Hi"', {}) - meths.nvim_command('Hello') + command('Hello') meths.nvim_del_user_command('Hello') - matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello')) + matches('Not an editor command: Hello', pcall_err(command, 'Hello')) end) it('can delete buffer-local commands', function() - bufmeths.create_user_command(0, 'Hello', 'echo "Hi"', {}) - meths.nvim_command('Hello') - bufmeths.del_user_command(0, 'Hello') - matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello')) + meths.nvim_buf_create_user_command(0, 'Hello', 'echo "Hi"', {}) + command('Hello') + meths.nvim_buf_del_user_command(0, 'Hello') + matches('Not an editor command: Hello', pcall_err(command, 'Hello')) end) end) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 83fc5aa47f..668ce43588 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -4,8 +4,6 @@ local Screen = require('test.functional.ui.screen') local request = helpers.request local eq = helpers.eq local ok = helpers.ok -local curbufmeths = helpers.curbufmeths -local bufmeths = helpers.bufmeths local pcall_err = helpers.pcall_err local insert = helpers.insert local feed = helpers.feed @@ -26,21 +24,21 @@ local function set_extmark(ns_id, id, line, col, opts) if id ~= nil and id ~= 0 then opts.id = id end - return curbufmeths.set_extmark(ns_id, line, col, opts) + return meths.nvim_buf_set_extmark(0, ns_id, line, col, opts) end local function get_extmarks(ns_id, start, end_, opts) if opts == nil then opts = {} end - return curbufmeths.get_extmarks(ns_id, start, end_, opts) + return meths.nvim_buf_get_extmarks(0, ns_id, start, end_, opts) end local function get_extmark_by_id(ns_id, id, opts) if opts == nil then opts = {} end - return curbufmeths.get_extmark_by_id(ns_id, id, opts) + return meths.nvim_buf_get_extmark_by_id(0, ns_id, id, opts) end local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end @@ -198,11 +196,11 @@ describe('API/extmarks', function() eq({ row, col }, rv) -- remove the test marks - eq(true, curbufmeths.del_extmark(ns, marks[1])) - eq(false, curbufmeths.del_extmark(ns, marks[1])) - eq(true, curbufmeths.del_extmark(ns, marks[2])) - eq(false, curbufmeths.del_extmark(ns, marks[3])) - eq(false, curbufmeths.del_extmark(ns, 1000)) + eq(true, meths.nvim_buf_del_extmark(0, ns, marks[1])) + eq(false, meths.nvim_buf_del_extmark(0, ns, marks[1])) + eq(true, meths.nvim_buf_del_extmark(0, ns, marks[2])) + eq(false, meths.nvim_buf_del_extmark(0, ns, marks[3])) + eq(false, meths.nvim_buf_del_extmark(0, ns, 1000)) end) it('can clear a specific namespace range', function() @@ -210,7 +208,7 @@ describe('API/extmarks', function() set_extmark(ns2, 1, 0, 1) -- force a new undo buffer feed('o<esc>') - curbufmeths.clear_namespace(ns2, 0, -1) + meths.nvim_buf_clear_namespace(0, ns2, 0, -1) eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) feed('u') @@ -226,7 +224,7 @@ describe('API/extmarks', function() set_extmark(ns2, 1, 0, 1) -- force a new undo buffer feed('o<esc>') - curbufmeths.clear_namespace(-1, 0, -1) + meths.nvim_buf_clear_namespace(0, -1, 0, -1) eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) feed('u') @@ -244,14 +242,14 @@ describe('API/extmarks', function() eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) feed('dd') eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) - curbufmeths.clear_namespace(ns, 0, -1) + meths.nvim_buf_clear_namespace(0, ns, 0, -1) eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) set_extmark(ns, 1, 0, 0, { right_gravity = false }) set_extmark(ns, 2, 1, 0, { right_gravity = false }) eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) feed('u') eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) - curbufmeths.clear_namespace(ns, 0, -1) + meths.nvim_buf_clear_namespace(0, ns, 0, -1) end) it('querying for information and ranges', function() @@ -933,7 +931,7 @@ describe('API/extmarks', function() -- Test unset feed('o<esc>') - curbufmeths.del_extmark(ns, marks[3]) + meths.nvim_buf_del_extmark(0, ns, marks[3]) feed('u') rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) -- undo does NOT restore deleted marks @@ -989,10 +987,10 @@ describe('API/extmarks', function() rv = get_extmarks(ns2, positions[2], positions[1]) eq(2, #rv) - curbufmeths.del_extmark(ns, marks[1]) + meths.nvim_buf_del_extmark(0, ns, marks[1]) rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) eq(2, #rv) - curbufmeths.del_extmark(ns2, marks[1]) + meths.nvim_buf_del_extmark(0, ns2, marks[1]) rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 }) eq(2, #rv) end) @@ -1429,7 +1427,7 @@ describe('API/extmarks', function() "Invalid 'ns_id': 3", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]) ) - eq("Invalid 'ns_id': 3", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1])) + eq("Invalid 'ns_id': 3", pcall_err(meths.nvim_buf_del_extmark, 0, ns_invalid, marks[1])) eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2])) eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1])) end) @@ -1480,8 +1478,8 @@ describe('API/extmarks', function() it('can set a mark to other buffer', function() local buf = request('nvim_create_buf', 0, 1) request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' }) - local id = bufmeths.set_extmark(buf, ns, 1, 0, {}) - eq({ { id, 1, 0 } }, bufmeths.get_extmarks(buf, ns, 0, -1, {})) + local id = meths.nvim_buf_set_extmark(buf, ns, 1, 0, {}) + eq({ { id, 1, 0 } }, meths.nvim_buf_get_extmarks(buf, ns, 0, -1, {})) end) it('does not crash with append/delete/undo sequence', function() @@ -1497,24 +1495,24 @@ describe('API/extmarks', function() it('works with left and right gravity', function() -- right gravity should move with inserted text, while -- left gravity should stay in place. - curbufmeths.set_extmark(ns, 0, 5, { right_gravity = false }) - curbufmeths.set_extmark(ns, 0, 5, { right_gravity = true }) + meths.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = false }) + meths.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true }) feed([[Aasdfasdf]]) - eq({ { 1, 0, 5 }, { 2, 0, 13 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) + eq({ { 1, 0, 5 }, { 2, 0, 13 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) -- but both move when text is inserted before feed([[<esc>Iasdf<esc>]]) - -- eq({}, curbufmeths.get_lines(0, -1, true)) - eq({ { 1, 0, 9 }, { 2, 0, 17 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) + -- eq({}, meths.nvim_buf_get_lines(0, 0, -1, true)) + eq({ { 1, 0, 9 }, { 2, 0, 17 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) -- clear text - curbufmeths.set_text(0, 0, 0, 17, {}) + meths.nvim_buf_set_text(0, 0, 0, 0, 17, {}) -- handles set_text correctly as well eq({ { 1, 0, 0 }, { 2, 0, 0 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) - curbufmeths.set_text(0, 0, 0, 0, { 'asdfasdf' }) - eq({ { 1, 0, 0 }, { 2, 0, 8 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) + meths.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' }) + eq({ { 1, 0, 0 }, { 2, 0, 8 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) feed('u') -- handles pasting @@ -1641,7 +1639,7 @@ describe('API/extmarks', function() right_gravity = true, }, }, get_extmark_by_id(ns, marks[3], { details = true })) - curbufmeths.clear_namespace(ns, 0, -1) + meths.nvim_buf_clear_namespace(0, ns, 0, -1) -- legacy sign mark includes sign name command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine') command('sign place 1 name=sign1 line=1') @@ -1770,7 +1768,7 @@ describe('Extmarks buffer api with many marks', function() for i = 1, 30 do lines[#lines + 1] = string.rep('x ', i) end - curbufmeths.set_lines(0, -1, true, lines) + meths.nvim_buf_set_lines(0, 0, -1, true, lines) local ns = ns1 local q = 0 for i = 0, 29 do @@ -1804,16 +1802,16 @@ describe('Extmarks buffer api with many marks', function() end) it('can clear all marks in ns', function() - curbufmeths.clear_namespace(ns1, 0, -1) + meths.nvim_buf_clear_namespace(0, ns1, 0, -1) eq({}, get_marks(ns1)) eq(ns_marks[ns2], get_marks(ns2)) - curbufmeths.clear_namespace(ns2, 0, -1) + meths.nvim_buf_clear_namespace(0, ns2, 0, -1) eq({}, get_marks(ns1)) eq({}, get_marks(ns2)) end) it('can clear line range', function() - curbufmeths.clear_namespace(ns1, 10, 20) + meths.nvim_buf_clear_namespace(0, ns1, 10, 20) for id, mark in pairs(ns_marks[ns1]) do if 10 <= mark[1] and mark[1] < 20 then ns_marks[ns1][id] = nil diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 07ce9d0c54..b86fe550a1 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim = helpers.clear, helpers.nvim +local clear = helpers.clear local Screen = require('test.functional.ui.screen') local eq, eval = helpers.eq, helpers.eval local command = helpers.command @@ -52,22 +52,22 @@ describe('API: highlight', function() it('nvim_get_hl_by_id', function() local hl_id = eval("hlID('NewHighlight')") - eq(expected_cterm, nvim('get_hl_by_id', hl_id, false)) + eq(expected_cterm, meths.nvim_get_hl_by_id(hl_id, false)) hl_id = eval("hlID('NewHighlight')") -- Test valid id. - eq(expected_rgb, nvim('get_hl_by_id', hl_id, true)) + eq(expected_rgb, meths.nvim_get_hl_by_id(hl_id, true)) -- Test invalid id. eq('Invalid highlight id: 30000', pcall_err(meths.nvim_get_hl_by_id, 30000, false)) -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') - eq(expected_rgb2, nvim('get_hl_by_id', hl_id, true)) + eq(expected_rgb2, meths.nvim_get_hl_by_id(hl_id, true)) -- Test undercurl command('hi NewHighlight gui=undercurl') - eq(expected_undercurl, nvim('get_hl_by_id', hl_id, true)) + eq(expected_undercurl, meths.nvim_get_hl_by_id(hl_id, true)) -- Test nil argument. eq( @@ -102,14 +102,14 @@ describe('API: highlight', function() local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } -- Test `Normal` default values. - eq({}, nvim('get_hl_by_name', 'Normal', true)) + eq({}, meths.nvim_get_hl_by_name('Normal', true)) - eq(expected_cterm, nvim('get_hl_by_name', 'NewHighlight', false)) - eq(expected_rgb, nvim('get_hl_by_name', 'NewHighlight', true)) + eq(expected_cterm, meths.nvim_get_hl_by_name('NewHighlight', false)) + eq(expected_rgb, meths.nvim_get_hl_by_name('NewHighlight', true)) -- Test `Normal` modified values. command('hi Normal guifg=red guibg=yellow') - eq(expected_normal, nvim('get_hl_by_name', 'Normal', true)) + eq(expected_normal, meths.nvim_get_hl_by_name('Normal', true)) -- Test invalid name. eq( @@ -137,10 +137,10 @@ describe('API: highlight', function() meths.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) meths.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) -- Note colors are "cterm" values, not rgb-as-ints - eq({ foreground = 17, background = 213 }, nvim('get_hl_by_name', 'Normal', false)) + eq({ foreground = 17, background = 213 }, meths.nvim_get_hl_by_name('Normal', false)) eq( { foreground = 17, background = 213, nocombine = true }, - nvim('get_hl_by_name', 'NotNormal', false) + meths.nvim_get_hl_by_name('NotNormal', false) ) end) @@ -378,7 +378,7 @@ describe('API: set highlight', function() it("correctly sets 'Normal' internal properties", function() -- Normal has some special handling internally. #18024 meths.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) - eq({ foreground = 131, background = 243 }, nvim('get_hl_by_name', 'Normal', true)) + eq({ foreground = 131, background = 243 }, meths.nvim_get_hl_by_name('Normal', true)) end) it('does not segfault on invalid group name #20009', function() @@ -475,7 +475,7 @@ describe('API: get highlight', function() end) it('nvim_get_hl with create flag', function() - eq({}, nvim('get_hl', 0, { name = 'Foo', create = false })) + eq({}, meths.nvim_get_hl(0, { name = 'Foo', create = false })) eq(0, funcs.hlexists('Foo')) meths.nvim_get_hl(0, { name = 'Bar', create = true }) eq(1, funcs.hlexists('Bar')) diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index f633c96a7c..b7de7732e8 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -1,9 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local bufmeths = helpers.bufmeths local clear = helpers.clear local command = helpers.command -local curbufmeths = helpers.curbufmeths local eq, neq = helpers.eq, helpers.neq local exec_lua = helpers.exec_lua local exec = helpers.exec @@ -112,7 +110,7 @@ describe('nvim_get_keymap', function() -- The buffer mapping should not show up eq({ foolong_bar_map_table }, meths.nvim_get_keymap('n')) - eq({ buffer_table }, curbufmeths.get_keymap('n')) + eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n')) end) it('considers scope for overlapping maps', function() @@ -124,11 +122,11 @@ describe('nvim_get_keymap', function() command('nnoremap <buffer> foo bar') eq({ foo_bar_map_table }, meths.nvim_get_keymap('n')) - eq({ buffer_table }, curbufmeths.get_keymap('n')) + eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n')) end) it('can retrieve mapping for different buffers', function() - local original_buffer = curbufmeths.get_number() + local original_buffer = meths.nvim_buf_get_number(0) -- Place something in each of the buffers to make sure they stick around -- and set hidden so we can leave them command('set hidden') @@ -137,7 +135,7 @@ describe('nvim_get_keymap', function() command('new') command('normal! ihello 3') - local final_buffer = curbufmeths.get_number() + local final_buffer = meths.nvim_buf_get_number(0) command('nnoremap <buffer> foo bar') -- Final buffer will have buffer mappings @@ -147,10 +145,10 @@ describe('nvim_get_keymap', function() eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n')) command('buffer ' .. original_buffer) - eq(original_buffer, curbufmeths.get_number()) + eq(original_buffer, meths.nvim_buf_get_number(0)) -- Original buffer won't have any mappings eq({}, meths.nvim_get_keymap('n')) - eq({}, curbufmeths.get_keymap('n')) + eq({}, meths.nvim_buf_get_keymap(0, 'n')) eq({ buffer_table }, meths.nvim_buf_get_keymap(final_buffer, 'n')) end) @@ -209,7 +207,7 @@ describe('nvim_get_keymap', function() function() make_new_windows(new_windows) command(map .. ' <buffer> ' .. option_token .. ' foo bar') - local result = curbufmeths.get_keymap(mode)[1][option] + local result = meths.nvim_buf_get_keymap(0, mode)[1][option] eq(buffer_on_result, result) end ) @@ -246,7 +244,7 @@ describe('nvim_get_keymap', function() make_new_windows(new_windows) command(map .. ' <buffer> foo bar') - local result = curbufmeths.get_keymap(mode)[1][option] + local result = meths.nvim_buf_get_keymap(0, mode)[1][option] eq(buffer_off_result, result) end ) @@ -290,7 +288,7 @@ describe('nvim_get_keymap', function() nnoremap <buffer> fizz :call <SID>maparg_test_function()<CR> ]]) - local sid_result = curbufmeths.get_keymap('n')[1]['sid'] + local sid_result = meths.nvim_buf_get_keymap(0, 'n')[1]['sid'] eq(1, sid_result) eq('testing', meths.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {})) end) @@ -698,33 +696,33 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('can set mappings whose RHS is a <Nop>', function() meths.nvim_set_keymap('i', 'lhs', '<Nop>', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) -- imap to <Nop> does nothing + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) -- imap to <Nop> does nothing eq(generate_mapargs('i', 'lhs', '<Nop>', {}), get_mapargs('i', 'lhs')) -- also test for case insensitivity meths.nvim_set_keymap('i', 'lhs', '<nOp>', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) -- note: RHS in returned mapargs() dict reflects the original RHS -- provided by the user eq(generate_mapargs('i', 'lhs', '<nOp>', {}), get_mapargs('i', 'lhs')) meths.nvim_set_keymap('i', 'lhs', '<NOP>', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq(generate_mapargs('i', 'lhs', '<NOP>', {}), get_mapargs('i', 'lhs')) -- a single ^V in RHS is also <Nop> (see :h map-empty-rhs) meths.nvim_set_keymap('i', 'lhs', '\022', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq(generate_mapargs('i', 'lhs', '\022', {}), get_mapargs('i', 'lhs')) end) it('treats an empty RHS in a mapping like a <Nop>', function() meths.nvim_set_keymap('i', 'lhs', '', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) end) @@ -743,7 +741,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() command([[call nvim_set_keymap('i', "\<space>", "\<tab>", {})]]) eq(generate_mapargs('i', '<Space>', '\t', { sid = 0 }), get_mapargs('i', '<Space>')) feed('i ') - eq({ '\t' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '\t' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) end ) @@ -772,12 +770,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function() meths.nvim_set_keymap('i', 'lhs', 'FlipFlop()', { expr = true }) command('normal ilhs') - eq({ '1' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '1' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) command('normal! ggVGd') command('normal ilhs') - eq({ '0' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '0' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) end) it('can set mappings that do trigger other mappings', function() @@ -785,12 +783,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function() meths.nvim_set_keymap('i', 'lhs', 'mhs', {}) command('normal imhs') - eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) command('normal! ggVGd') command('normal ilhs') - eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) end) it("can set noremap mappings that don't trigger other mappings", function() @@ -798,12 +796,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function() meths.nvim_set_keymap('i', 'lhs', 'mhs', { noremap = true }) command('normal imhs') - eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) command('normal! ggVGd') command('normal ilhs') -- shouldn't trigger mhs-to-rhs mapping - eq({ 'mhs' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'mhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) end) it('can set nowait mappings that fire without waiting', function() @@ -817,7 +815,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed(c) sleep(5) end - eq({ 'shorter456' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'shorter456' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) end) -- Perform exhaustive tests of basic functionality @@ -1181,66 +1179,66 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() it('rejects negative bufnr values', function() eq( 'Wrong type for argument 1 when calling nvim_buf_set_keymap, expecting Buffer', - pcall_err(bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {}) + pcall_err(meths.nvim_buf_set_keymap, -1, '', 'lhs', 'rhs', {}) ) end) it('can set mappings active in the current buffer but not others', function() local first, second = make_two_buffers(true) - bufmeths.set_keymap(0, '', 'lhs', 'irhs<Esc>', {}) + meths.nvim_buf_set_keymap(0, '', 'lhs', 'irhs<Esc>', {}) command('normal lhs') - eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) -- mapping should have no effect in new buffer switch_to_buf(second) command('normal lhs') - eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) -- mapping should remain active in old buffer switch_to_buf(first) command('normal ^lhs') - eq({ 'rhsrhs' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhsrhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) end) it('can set local mappings in buffer other than current', function() local first = make_two_buffers(false) - bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) + meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) -- shouldn't do anything command('normal lhs') - eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) -- should take effect switch_to_buf(first) command('normal lhs') - eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) end) it('can disable mappings made in another buffer, inside that buffer', function() local first = make_two_buffers(false) - bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) - bufmeths.del_keymap(first, '', 'lhs') + meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) + meths.nvim_buf_del_keymap(first, '', 'lhs') switch_to_buf(first) -- shouldn't do anything command('normal lhs') - eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) end) it("can't disable mappings given wrong buffer handle", function() local first, second = make_two_buffers(false) - bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) - eq('E31: No such mapping', pcall_err(bufmeths.del_keymap, second, '', 'lhs')) + meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) + eq('E31: No such mapping', pcall_err(meths.nvim_buf_del_keymap, second, '', 'lhs')) -- should still work switch_to_buf(first) command('normal lhs') - eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) end) it('does not crash when setting mapping in a non-existing buffer #13541', function() - pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs<Esc>', {}) + pcall_err(meths.nvim_buf_set_keymap, 100, '', 'lsh', 'irhs<Esc>', {}) helpers.assert_alive() end) diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 3fc7b9986a..c80f7f4f7b 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log -local eq, clear, eval, command, nvim, next_msg = - helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.nvim, helpers.next_msg +local eq, clear, eval, command, next_msg = + helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.next_msg local meths = helpers.meths local exec_lua = helpers.exec_lua local retry = helpers.retry @@ -14,7 +14,7 @@ describe('notify', function() before_each(function() clear() - channel = nvim('get_api_info')[1] + channel = meths.nvim_get_api_info()[1] end) after_each(function() @@ -33,14 +33,14 @@ describe('notify', function() describe('passing 0 as the channel id', function() it('sends the notification/args to all subscribed channels', function() - nvim('subscribe', 'event2') + meths.nvim_subscribe('event2') eval('rpcnotify(0, "event1", 1, 2, 3)') eval('rpcnotify(0, "event2", 4, 5, 6)') eval('rpcnotify(0, "event2", 7, 8, 9)') eq({ 'notification', 'event2', { 4, 5, 6 } }, next_msg()) eq({ 'notification', 'event2', { 7, 8, 9 } }, next_msg()) - nvim('unsubscribe', 'event2') - nvim('subscribe', 'event1') + meths.nvim_unsubscribe('event2') + meths.nvim_subscribe('event1') eval('rpcnotify(0, "event2", 10, 11, 12)') eval('rpcnotify(0, "event1", 13, 14, 15)') eq({ 'notification', 'event1', { 13, 14, 15 } }, next_msg()) @@ -49,9 +49,7 @@ describe('notify', function() it('does not crash for deeply nested variable', function() meths.nvim_set_var('l', {}) local nest_level = 1000 - meths.nvim_command( - ('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1) - ) + command(('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1)) eval('rpcnotify(' .. channel .. ', "event", g:l)') local msg = next_msg() eq('notification', msg[1]) @@ -81,10 +79,10 @@ describe('notify', function() clear { env = { NVIM_LOG_FILE = testlog, } } - nvim('subscribe', 'event1') - nvim('unsubscribe', 'doesnotexist') + meths.nvim_subscribe('event1') + meths.nvim_unsubscribe('doesnotexist') assert_log("tried to unsubscribe unknown event 'doesnotexist'", testlog, 10) - nvim('unsubscribe', 'event1') + meths.nvim_unsubscribe('event1') assert_alive() end) diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 6878ac0218..e06d32f656 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -2,7 +2,7 @@ -- `rpcrequest` calls we need the client event loop to be running. local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval +local clear, eval = helpers.clear, helpers.eval local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs local source, next_msg = helpers.source, helpers.next_msg @@ -18,7 +18,7 @@ describe('server -> client', function() before_each(function() clear() - cid = nvim('get_api_info')[1] + cid = meths.nvim_get_api_info()[1] end) it('handles unexpected closed stream while preparing RPC response', function() @@ -47,7 +47,7 @@ describe('server -> client', function() local function on_request(method, args) eq('scall', method) eq({ 1, 2, 3 }, args) - nvim('command', 'let g:result = [4, 5, 6]') + command('let g:result = [4, 5, 6]') return eval('g:result') end run(on_request, nil, on_setup) @@ -77,15 +77,15 @@ describe('server -> client', function() describe('recursive call', function() it('works', function() local function on_setup() - nvim('set_var', 'result1', 0) - nvim('set_var', 'result2', 0) - nvim('set_var', 'result3', 0) - nvim('set_var', 'result4', 0) - nvim('command', 'let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') - eq(4, nvim('get_var', 'result1')) - eq(8, nvim('get_var', 'result2')) - eq(16, nvim('get_var', 'result3')) - eq(32, nvim('get_var', 'result4')) + meths.nvim_set_var('result1', 0) + meths.nvim_set_var('result2', 0) + meths.nvim_set_var('result3', 0) + meths.nvim_set_var('result4', 0) + command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') + eq(4, meths.nvim_get_var('result1')) + eq(8, meths.nvim_get_var('result2')) + eq(16, meths.nvim_get_var('result3')) + eq(32, meths.nvim_get_var('result4')) stop() end @@ -101,7 +101,7 @@ describe('server -> client', function() elseif n == 16 then cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' end - nvim('command', cmd) + command(cmd) end return n end @@ -195,10 +195,10 @@ describe('server -> client', function() end) it('can send/receive notifications and make requests', function() - nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") + command("call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") -- Wait for the notification to complete. - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") + command("call rpcrequest(vim, 'vim_eval', '0')") eq('SOME TEXT', eval("rpcrequest(vim, 'vim_get_current_line')")) end) @@ -212,7 +212,7 @@ describe('server -> client', function() eq(1, buf) eval("rpcnotify(vim, 'buffer_set_line', " .. buf .. ", 0, 'SOME TEXT')") - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait + command("call rpcrequest(vim, 'vim_eval', '0')") -- wait eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', " .. buf .. ', 0)')) @@ -231,8 +231,8 @@ describe('server -> client', function() describe('jobstart()', function() local jobid before_each(function() - local channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + local channel = meths.nvim_get_api_info()[1] + meths.nvim_set_var('channel', channel) source([[ function! s:OnEvent(id, data, event) call rpcnotify(g:channel, a:event, 0, a:data) diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua index f661f8e38b..830b547da5 100644 --- a/test/functional/api/tabpage_spec.lua +++ b/test/functional/api/tabpage_spec.lua @@ -1,7 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, tabpage, curtab, eq, ok = - helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq, helpers.ok -local curtabmeths = helpers.curtabmeths +local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok +local meths = helpers.meths local funcs = helpers.funcs local request = helpers.request local NIL = vim.NIL @@ -13,35 +12,35 @@ describe('api/tabpage', function() describe('list_wins and get_win', function() it('works', function() - nvim('command', 'tabnew') - nvim('command', 'vsplit') - local tab1, tab2 = unpack(nvim('list_tabpages')) - local win1, win2, win3 = unpack(nvim('list_wins')) - eq({ win1 }, tabpage('list_wins', tab1)) - eq({ win2, win3 }, tabpage('list_wins', tab2)) - eq(win2, tabpage('get_win', tab2)) - nvim('set_current_win', win3) - eq(win3, tabpage('get_win', tab2)) + helpers.command('tabnew') + helpers.command('vsplit') + local tab1, tab2 = unpack(meths.nvim_list_tabpages()) + local win1, win2, win3 = unpack(meths.nvim_list_wins()) + eq({ win1 }, meths.nvim_tabpage_list_wins(tab1)) + eq({ win2, win3 }, meths.nvim_tabpage_list_wins(tab2)) + eq(win2, meths.nvim_tabpage_get_win(tab2)) + meths.nvim_set_current_win(win3) + eq(win3, meths.nvim_tabpage_get_win(tab2)) end) it('validates args', function() - eq('Invalid tabpage id: 23', pcall_err(tabpage, 'list_wins', 23)) + eq('Invalid tabpage id: 23', pcall_err(meths.nvim_tabpage_list_wins, 23)) end) end) describe('{get,set,del}_var', function() it('works', function() - curtab('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) - eq({ 1, 2, { ['3'] = 1 } }, curtab('get_var', 'lua')) - eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 't:lua')) + meths.nvim_tabpage_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_tabpage_get_var(0, 'lua')) + eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('t:lua')) eq(1, funcs.exists('t:lua')) - curtabmeths.del_var('lua') + meths.nvim_tabpage_del_var(0, 'lua') eq(0, funcs.exists('t:lua')) - eq('Key not found: lua', pcall_err(curtabmeths.del_var, 'lua')) - curtabmeths.set_var('lua', 1) + eq('Key not found: lua', pcall_err(meths.nvim_tabpage_del_var, 0, 'lua')) + meths.nvim_tabpage_set_var(0, 'lua', 1) command('lockvar t:lua') - eq('Key is locked: lua', pcall_err(curtabmeths.del_var, 'lua')) - eq('Key is locked: lua', pcall_err(curtabmeths.set_var, 'lua', 1)) + eq('Key is locked: lua', pcall_err(meths.nvim_tabpage_del_var, 0, 'lua')) + eq('Key is locked: lua', pcall_err(meths.nvim_tabpage_set_var, 0, 'lua', 1)) end) it('tabpage_set_var returns the old value', function() @@ -62,28 +61,28 @@ describe('api/tabpage', function() describe('get_number', function() it('works', function() - local tabs = nvim('list_tabpages') - eq(1, tabpage('get_number', tabs[1])) + local tabs = meths.nvim_list_tabpages() + eq(1, meths.nvim_tabpage_get_number(tabs[1])) - nvim('command', 'tabnew') - local tab1, tab2 = unpack(nvim('list_tabpages')) - eq(1, tabpage('get_number', tab1)) - eq(2, tabpage('get_number', tab2)) + helpers.command('tabnew') + local tab1, tab2 = unpack(meths.nvim_list_tabpages()) + eq(1, meths.nvim_tabpage_get_number(tab1)) + eq(2, meths.nvim_tabpage_get_number(tab2)) - nvim('command', '-tabmove') - eq(2, tabpage('get_number', tab1)) - eq(1, tabpage('get_number', tab2)) + helpers.command('-tabmove') + eq(2, meths.nvim_tabpage_get_number(tab1)) + eq(1, meths.nvim_tabpage_get_number(tab2)) end) end) describe('is_valid', function() it('works', function() - nvim('command', 'tabnew') - local tab = nvim('list_tabpages')[2] - nvim('set_current_tabpage', tab) - ok(tabpage('is_valid', tab)) - nvim('command', 'tabclose') - ok(not tabpage('is_valid', tab)) + helpers.command('tabnew') + local tab = meths.nvim_list_tabpages()[2] + meths.nvim_set_current_tabpage(tab) + ok(meths.nvim_tabpage_is_valid(tab)) + helpers.command('tabclose') + ok(not meths.nvim_tabpage_is_valid(tab)) end) end) end) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 3fd1cdab1e..ba2042d585 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -6,8 +6,9 @@ local fmt = string.format local dedent = helpers.dedent local assert_alive = helpers.assert_alive local NIL = vim.NIL -local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq +local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq local command = helpers.command +local command_output = helpers.meths.command_output local exec = helpers.exec local exec_capture = helpers.exec_capture local eval = helpers.eval @@ -94,41 +95,40 @@ describe('API', function() end) it('does not set CA_COMMAND_BUSY #7254', function() - nvim('command', 'split') - nvim('command', 'autocmd WinEnter * startinsert') - nvim('command', 'wincmd w') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + command('split') + command('autocmd WinEnter * startinsert') + command('wincmd w') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) end) describe('nvim_exec2', function() it('always returns table', function() -- In built version this results into `vim.empty_dict()` - eq({}, nvim('exec2', 'echo "Hello"', {})) - eq({}, nvim('exec2', 'echo "Hello"', { output = false })) - eq({ output = 'Hello' }, nvim('exec2', 'echo "Hello"', { output = true })) + eq({}, meths.nvim_exec2('echo "Hello"', {})) + eq({}, meths.nvim_exec2('echo "Hello"', { output = false })) + eq({ output = 'Hello' }, meths.nvim_exec2('echo "Hello"', { output = true })) end) it('default options', function() -- Should be equivalent to { output = false } - nvim('exec2', "let x0 = 'a'", {}) - eq('a', nvim('get_var', 'x0')) + meths.nvim_exec2("let x0 = 'a'", {}) + eq('a', meths.nvim_get_var('x0')) end) it('one-line input', function() - nvim('exec2', "let x1 = 'a'", { output = false }) - eq('a', nvim('get_var', 'x1')) + meths.nvim_exec2("let x1 = 'a'", { output = false }) + eq('a', meths.nvim_get_var('x1')) end) it(':verbose set {option}?', function() - nvim('exec2', 'set nowrap', { output = false }) + meths.nvim_exec2('set nowrap', { output = false }) eq( { output = 'nowrap\n\tLast set from anonymous :source' }, - nvim('exec2', 'verbose set wrap?', { output = true }) + meths.nvim_exec2('verbose set wrap?', { output = true }) ) -- Using script var to force creation of a script item - nvim( - 'exec2', + meths.nvim_exec2( [[ let s:a = 1 set nowrap @@ -137,40 +137,39 @@ describe('API', function() ) eq( { output = 'nowrap\n\tLast set from anonymous :source (script id 1)' }, - nvim('exec2', 'verbose set wrap?', { output = true }) + meths.nvim_exec2('verbose set wrap?', { output = true }) ) end) it('multiline input', function() -- Heredoc + empty lines. - nvim('exec2', "let x2 = 'a'\n", { output = false }) - eq('a', nvim('get_var', 'x2')) - nvim('exec2', 'lua <<EOF\n\n\n\ny=3\n\n\nEOF', { output = false }) - eq(3, nvim('eval', "luaeval('y')")) + meths.nvim_exec2("let x2 = 'a'\n", { output = false }) + eq('a', meths.nvim_get_var('x2')) + meths.nvim_exec2('lua <<EOF\n\n\n\ny=3\n\n\nEOF', { output = false }) + eq(3, meths.nvim_eval("luaeval('y')")) - eq({}, nvim('exec2', 'lua <<EOF\ny=3\nEOF', { output = false })) - eq(3, nvim('eval', "luaeval('y')")) + eq({}, meths.nvim_exec2('lua <<EOF\ny=3\nEOF', { output = false })) + eq(3, meths.nvim_eval("luaeval('y')")) -- Multiple statements - nvim('exec2', 'let x1=1\nlet x2=2\nlet x3=3\n', { output = false }) - eq(1, nvim('eval', 'x1')) - eq(2, nvim('eval', 'x2')) - eq(3, nvim('eval', 'x3')) + meths.nvim_exec2('let x1=1\nlet x2=2\nlet x3=3\n', { output = false }) + eq(1, meths.nvim_eval('x1')) + eq(2, meths.nvim_eval('x2')) + eq(3, meths.nvim_eval('x3')) -- Functions - nvim('exec2', 'function Foo()\ncall setline(1,["xxx"])\nendfunction', { output = false }) - eq('', nvim('get_current_line')) - nvim('exec2', 'call Foo()', { output = false }) - eq('xxx', nvim('get_current_line')) + meths.nvim_exec2('function Foo()\ncall setline(1,["xxx"])\nendfunction', { output = false }) + eq('', meths.nvim_get_current_line()) + meths.nvim_exec2('call Foo()', { output = false }) + eq('xxx', meths.nvim_get_current_line()) -- Autocmds - nvim('exec2', 'autocmd BufAdd * :let x1 = "Hello"', { output = false }) - nvim('command', 'new foo') + meths.nvim_exec2('autocmd BufAdd * :let x1 = "Hello"', { output = false }) + command('new foo') eq('Hello', request('nvim_eval', 'g:x1')) -- Line continuations - nvim( - 'exec2', + meths.nvim_exec2( [[ let abc = #{ \ a: 1, @@ -182,14 +181,13 @@ describe('API', function() eq({ a = 1, c = 3 }, request('nvim_eval', 'g:abc')) -- try no spaces before continuations to catch off-by-one error - nvim('exec2', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', { output = false }) + meths.nvim_exec2('let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', { output = false }) eq({ a = 98 }, request('nvim_eval', 'g:ab')) -- Script scope (s:) eq( { output = 'ahoy! script-scoped varrrrr' }, - nvim( - 'exec2', + meths.nvim_exec2( [[ let s:pirate = 'script-scoped varrrrr' function! s:avast_ye_hades(s) abort @@ -203,8 +201,7 @@ describe('API', function() eq( { output = "{'output': 'ahoy! script-scoped varrrrr'}" }, - nvim( - 'exec2', + meths.nvim_exec2( [[ let s:pirate = 'script-scoped varrrrr' function! Avast_ye_hades(s) abort @@ -232,8 +229,7 @@ describe('API', function() -- Script items are created only on script var access eq( { output = '1\n0' }, - nvim( - 'exec2', + meths.nvim_exec2( [[ echo expand("<SID>")->empty() let s:a = 123 @@ -245,8 +241,7 @@ describe('API', function() eq( { output = '1\n0' }, - nvim( - 'exec2', + meths.nvim_exec2( [[ echo expand("<SID>")->empty() function s:a() abort @@ -259,8 +254,7 @@ describe('API', function() end) it('non-ASCII input', function() - nvim( - 'exec2', + meths.nvim_exec2( [=[ new exe "normal! i ax \n Ax " @@ -268,13 +262,12 @@ describe('API', function() ]=], { output = false } ) - nvim('command', '1') - eq(' --a1234-- ', nvim('get_current_line')) - nvim('command', '2') - eq(' --A1234-- ', nvim('get_current_line')) + command('1') + eq(' --a1234-- ', meths.nvim_get_current_line()) + command('2') + eq(' --A1234-- ', meths.nvim_get_current_line()) - nvim( - 'exec2', + meths.nvim_exec2( [[ new call setline(1,['xxx']) @@ -283,7 +276,7 @@ describe('API', function() ]], { output = false } ) - eq('ñxx', nvim('get_current_line')) + eq('ñxx', meths.nvim_get_current_line()) end) it('execution error', function() @@ -291,7 +284,7 @@ describe('API', function() 'nvim_exec2(): Vim:E492: Not an editor command: bogus_command', pcall_err(request, 'nvim_exec2', 'bogus_command', {}) ) - eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated. + eq('', meths.nvim_eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) eq( @@ -355,10 +348,10 @@ describe('API', function() it('returns output', function() eq( { output = 'this is spinal tap' }, - nvim('exec2', 'lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', { output = true }) + meths.nvim_exec2('lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', { output = true }) ) - eq({ output = '' }, nvim('exec2', 'echo', { output = true })) - eq({ output = 'foo 42' }, nvim('exec2', 'echo "foo" 42', { output = true })) + eq({ output = '' }, meths.nvim_exec2('echo', { output = true })) + eq({ output = 'foo 42' }, meths.nvim_exec2('echo "foo" 42', { output = true })) end) it('displays messages when opts.output=false', function() @@ -410,10 +403,10 @@ describe('API', function() describe('nvim_command', function() it('works', function() local fname = tmpname() - nvim('command', 'new') - nvim('command', 'edit ' .. fname) - nvim('command', 'normal itesting\napi') - nvim('command', 'w') + command('new') + command('edit ' .. fname) + command('normal itesting\napi') + command('w') local f = assert(io.open(fname)) if is_os('win') then eq('testing\r\napi\r\n', f:read('*a')) @@ -425,15 +418,15 @@ describe('API', function() end) it('Vimscript validation error: fails with specific error', function() - local status, rv = pcall(nvim, 'command', 'bogus_command') + local status, rv = pcall(command, 'bogus_command') eq(false, status) -- nvim_command() failed. eq('E492:', string.match(rv, 'E%d*:')) -- Vimscript error was returned. - eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated. + eq('', meths.nvim_eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) end) it('Vimscript execution error: fails with specific error', function() - local status, rv = pcall(nvim, 'command', 'buffer 23487') + local status, rv = pcall(command, 'buffer 23487') eq(false, status) -- nvim_command() failed. eq('E86: Buffer 23487 does not exist', string.match(rv, 'E%d*:.*')) eq('', eval('v:errmsg')) -- v:errmsg was not updated. @@ -451,92 +444,89 @@ describe('API', function() describe('nvim_command_output', function() it('does not induce hit-enter prompt', function() - nvim('ui_attach', 80, 20, {}) + meths.nvim_ui_attach(80, 20, {}) -- Induce a hit-enter prompt use nvim_input (non-blocking). - nvim('command', 'set cmdheight=1') - nvim('input', [[:echo "hi\nhi2"<CR>]]) + command('set cmdheight=1') + meths.nvim_input([[:echo "hi\nhi2"<CR>]]) -- Verify hit-enter prompt. - eq({ mode = 'r', blocking = true }, nvim('get_mode')) - nvim('input', [[<C-c>]]) + eq({ mode = 'r', blocking = true }, meths.nvim_get_mode()) + meths.nvim_input([[<C-c>]]) -- Verify NO hit-enter prompt. - nvim('command_output', [[echo "hi\nhi2"]]) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + command_output([[echo "hi\nhi2"]]) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('captures command output', function() - eq('this is\nspinal tap', nvim('command_output', [[echo "this is\nspinal tap"]])) - eq('no line ending!', nvim('command_output', [[echon "no line ending!"]])) + eq('this is\nspinal tap', command_output([[echo "this is\nspinal tap"]])) + eq('no line ending!', command_output([[echon "no line ending!"]])) end) it('captures empty command output', function() - eq('', nvim('command_output', 'echo')) + eq('', command_output('echo')) end) it('captures single-char command output', function() - eq('x', nvim('command_output', 'echo "x"')) + eq('x', command_output('echo "x"')) end) it('captures multiple commands', function() - eq( - 'foo\n 1 %a "[No Name]" line 1', - nvim('command_output', 'echo "foo" | ls') - ) + eq('foo\n 1 %a "[No Name]" line 1', command_output('echo "foo" | ls')) end) it('captures nested execute()', function() eq( '\nnested1\nnested2\n 1 %a "[No Name]" line 1', - nvim('command_output', [[echo execute('echo "nested1\nnested2"') | ls]]) + command_output([[echo execute('echo "nested1\nnested2"') | ls]]) ) end) it('captures nested nvim_command_output()', function() eq( 'nested1\nnested2\n 1 %a "[No Name]" line 1', - nvim('command_output', [[echo nvim_command_output('echo "nested1\nnested2"') | ls]]) + command_output([[echo nvim_command_output('echo "nested1\nnested2"') | ls]]) ) end) it('returns shell |:!| output', function() local win_lf = is_os('win') and '\r' or '' - eq(':!echo foo\r\n\nfoo' .. win_lf .. '\n', nvim('command_output', [[!echo foo]])) + eq(':!echo foo\r\n\nfoo' .. win_lf .. '\n', command_output([[!echo foo]])) end) it('Vimscript validation error: fails with specific error', function() - local status, rv = pcall(nvim, 'command_output', 'bogus commannnd') + local status, rv = pcall(command_output, 'bogus commannnd') eq(false, status) -- nvim_command_output() failed. eq('E492: Not an editor command: bogus commannnd', string.match(rv, 'E%d*:.*')) eq('', eval('v:errmsg')) -- v:errmsg was not updated. -- Verify NO hit-enter prompt. - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('Vimscript execution error: fails with specific error', function() - local status, rv = pcall(nvim, 'command_output', 'buffer 42') + local status, rv = pcall(command_output, 'buffer 42') eq(false, status) -- nvim_command_output() failed. eq('E86: Buffer 42 does not exist', string.match(rv, 'E%d*:.*')) eq('', eval('v:errmsg')) -- v:errmsg was not updated. -- Verify NO hit-enter prompt. - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('does not cause heap buffer overflow with large output', function() - eq(eval('string(range(1000000))'), nvim('command_output', 'echo range(1000000)')) + eq(eval('string(range(1000000))'), command_output('echo range(1000000)')) end) end) describe('nvim_eval', function() it('works', function() - nvim('command', 'let g:v1 = "a"') - nvim('command', 'let g:v2 = [1, 2, {"v3": 3}]') - eq({ v1 = 'a', v2 = { 1, 2, { v3 = 3 } } }, nvim('eval', 'g:')) + command('let g:v1 = "a"') + command('let g:v2 = [1, 2, {"v3": 3}]') + eq({ v1 = 'a', v2 = { 1, 2, { v3 = 3 } } }, meths.nvim_eval('g:')) end) it('handles NULL-initialized strings correctly', function() - eq(1, nvim('eval', "matcharg(1) == ['', '']")) - eq({ '', '' }, nvim('eval', 'matcharg(1)')) + eq(1, meths.nvim_eval("matcharg(1) == ['', '']")) + eq({ '', '' }, meths.nvim_eval('matcharg(1)')) end) it('works under deprecated name', function() @@ -551,10 +541,10 @@ describe('API', function() describe('nvim_call_function', function() it('works', function() - nvim('call_function', 'setqflist', { { { filename = 'something', lnum = 17 } }, 'r' }) - eq(17, nvim('call_function', 'getqflist', {})[1].lnum) - eq(17, nvim('call_function', 'eval', { 17 })) - eq('foo', nvim('call_function', 'simplify', { 'this/./is//redundant/../../../foo' })) + meths.nvim_call_function('setqflist', { { { filename = 'something', lnum = 17 } }, 'r' }) + eq(17, meths.nvim_call_function('getqflist', {})[1].lnum) + eq(17, meths.nvim_call_function('eval', { 17 })) + eq('foo', meths.nvim_call_function('simplify', { 'this/./is//redundant/../../../foo' })) end) it('Vimscript validation error: returns specific error, does NOT update v:errmsg', function() @@ -629,18 +619,18 @@ describe('API', function() ]]) -- :help Dictionary-function - eq('Hello, World!', nvim('call_dict_function', 'g:test_dict_fn', 'F', { 'World' })) + eq('Hello, World!', meths.nvim_call_dict_function('g:test_dict_fn', 'F', { 'World' })) -- Funcref is sent as NIL over RPC. - eq({ greeting = 'Hello', F = NIL }, nvim('get_var', 'test_dict_fn')) + eq({ greeting = 'Hello', F = NIL }, meths.nvim_get_var('test_dict_fn')) -- :help numbered-function - eq('Hi, Moon ...', nvim('call_dict_function', 'g:test_dict_fn2', 'F2', { 'Moon' })) + eq('Hi, Moon ...', meths.nvim_call_dict_function('g:test_dict_fn2', 'F2', { 'Moon' })) -- Funcref is sent as NIL over RPC. - eq({ greeting = 'Hi', F2 = NIL }, nvim('get_var', 'test_dict_fn2')) + eq({ greeting = 'Hi', F2 = NIL }, meths.nvim_get_var('test_dict_fn2')) -- Function specified via RPC dict. source('function! G() dict\n return "@".(self.result)."@"\nendfunction') - eq('@it works@', nvim('call_dict_function', { result = 'it works', G = 'G' }, 'G', {})) + eq('@it works@', meths.nvim_call_dict_function({ result = 'it works', G = 'G' }, 'G', {})) end) it('validation', function() @@ -758,20 +748,20 @@ describe('API', function() describe('nvim_notify', function() it('can notify a info message', function() - nvim('notify', 'hello world', 2, {}) + meths.nvim_notify('hello world', 2, {}) end) it('can be overridden', function() command('lua vim.notify = function(...) return 42 end') eq(42, meths.nvim_exec_lua("return vim.notify('Hello world')", {})) - nvim('notify', 'hello world', 4, {}) + meths.nvim_notify('hello world', 4, {}) end) end) describe('nvim_input', function() it('Vimscript error: does NOT fail, updates v:errmsg', function() - local status, _ = pcall(nvim, 'input', ':call bogus_fn()<CR>') - local v_errnum = string.match(nvim('eval', 'v:errmsg'), 'E%d*:') + local status, _ = pcall(meths.nvim_input, ':call bogus_fn()<CR>') + local v_errnum = string.match(meths.nvim_eval('v:errmsg'), 'E%d*:') eq(true, status) -- nvim_input() did not fail. eq('E117:', v_errnum) -- v:errmsg was updated. end) @@ -789,23 +779,23 @@ describe('API', function() end) local function run_streamed_paste_tests() it('stream: multiple chunks form one undo-block', function() - nvim('paste', '1/chunk 1 (start)\n', true, 1) - nvim('paste', '1/chunk 2 (end)\n', true, 3) + meths.nvim_paste('1/chunk 1 (start)\n', true, 1) + meths.nvim_paste('1/chunk 2 (end)\n', true, 3) local expected1 = [[ 1/chunk 1 (start) 1/chunk 2 (end) ]] expect(expected1) - nvim('paste', '2/chunk 1 (start)\n', true, 1) - nvim('paste', '2/chunk 2\n', true, 2) + meths.nvim_paste('2/chunk 1 (start)\n', true, 1) + meths.nvim_paste('2/chunk 2\n', true, 2) expect([[ 1/chunk 1 (start) 1/chunk 2 (end) 2/chunk 1 (start) 2/chunk 2 ]]) - nvim('paste', '2/chunk 3\n', true, 2) - nvim('paste', '2/chunk 4 (end)\n', true, 3) + meths.nvim_paste('2/chunk 3\n', true, 2) + meths.nvim_paste('2/chunk 4 (end)\n', true, 3) expect([[ 1/chunk 1 (start) 1/chunk 2 (end) @@ -821,10 +811,10 @@ describe('API', function() -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. feed('afoo<Esc>u') feed('i') - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('aaaaaabbbbbbccccccdddddd') feed('<Esc>u') expect('') @@ -840,17 +830,17 @@ describe('API', function() expect('') end) it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('aaaaaabbbbbbccccccdddddd') end) it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -870,17 +860,17 @@ describe('API', function() expect('||') end) it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('|aaaaaabbbbbbccccccdddddd|') end) it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd', false, 3) expect([[ |aaaaaa bbbbbb @@ -900,17 +890,17 @@ describe('API', function() expect('||') end) it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd', false, 3) expect([[ ||aaaaaa bbbbbb @@ -934,24 +924,24 @@ describe('API', function() xxx|]]) end) it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('|aaaaaabbbbbbccccccdddddd|') end) it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('|bbbbbbccccccdddddd|') end) it('with all chunks empty', function() - nvim('paste', '', false, 1) - nvim('paste', '', false, 2) - nvim('paste', '', false, 2) - nvim('paste', '', false, 3) + meths.nvim_paste('', false, 1) + meths.nvim_paste('', false, 2) + meths.nvim_paste('', false, 2) + meths.nvim_paste('', false, 3) expect('||') end) end) @@ -969,17 +959,17 @@ describe('API', function() xxx]]) end) it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('||bbbbbbccccccdddddd') end) end) @@ -997,17 +987,17 @@ describe('API', function() xxx]]) end) it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('', false, 1) + meths.nvim_paste('bbbbbb', false, 2) + meths.nvim_paste('cccccc', false, 2) + meths.nvim_paste('dddddd', false, 3) expect('||bbbbbbccccccdddddd') end) end) @@ -1030,10 +1020,10 @@ describe('API', function() feed('ggV') end) it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -1042,10 +1032,10 @@ describe('API', function() 123456789]]) end) it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd\n', false, 3) expect([[ aaaaaa bbbbbb @@ -1060,10 +1050,10 @@ describe('API', function() feed('2ggV') end) it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd', false, 3) expect([[ 123456789 aaaaaa @@ -1072,10 +1062,10 @@ describe('API', function() dddddd123456789]]) end) it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd\n', false, 3) expect([[ 123456789 aaaaaa @@ -1090,10 +1080,10 @@ describe('API', function() feed('3ggV') end) it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd', false, 3) expect([[ 123456789 987654321 @@ -1103,10 +1093,10 @@ describe('API', function() dddddd]]) end) it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd\n', false, 3) expect([[ 123456789 987654321 @@ -1122,10 +1112,10 @@ describe('API', function() feed('ggVG') end) it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -1133,10 +1123,10 @@ describe('API', function() dddddd]]) end) it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) + meths.nvim_paste('aaaaaa\n', false, 1) + meths.nvim_paste('bbbbbb\n', false, 2) + meths.nvim_paste('cccccc\n', false, 2) + meths.nvim_paste('dddddd\n', false, 3) expect([[ aaaaaa bbbbbb @@ -1158,17 +1148,17 @@ describe('API', function() end) it('non-streaming', function() -- With final "\n". - nvim('paste', 'line 1\nline 2\nline 3\n', true, -1) + meths.nvim_paste('line 1\nline 2\nline 3\n', true, -1) expect([[ line 1 line 2 line 3 ]]) eq({ 0, 4, 1, 0 }, funcs.getpos('.')) -- Cursor follows the paste. - eq(false, nvim('get_option_value', 'paste', {})) + eq(false, meths.nvim_get_option_value('paste', {})) command('%delete _') -- Without final "\n". - nvim('paste', 'line 1\nline 2\nline 3', true, -1) + meths.nvim_paste('line 1\nline 2\nline 3', true, -1) expect([[ line 1 line 2 @@ -1176,7 +1166,7 @@ describe('API', function() eq({ 0, 3, 6, 0 }, funcs.getpos('.')) command('%delete _') -- CRLF #10872 - nvim('paste', 'line 1\r\nline 2\r\nline 3\r\n', true, -1) + meths.nvim_paste('line 1\r\nline 2\r\nline 3\r\n', true, -1) expect([[ line 1 line 2 @@ -1185,7 +1175,7 @@ describe('API', function() eq({ 0, 4, 1, 0 }, funcs.getpos('.')) command('%delete _') -- CRLF without final "\n". - nvim('paste', 'line 1\r\nline 2\r\nline 3\r', true, -1) + meths.nvim_paste('line 1\r\nline 2\r\nline 3\r', true, -1) expect([[ line 1 line 2 @@ -1194,7 +1184,7 @@ describe('API', function() eq({ 0, 4, 1, 0 }, funcs.getpos('.')) command('%delete _') -- CRLF without final "\r\n". - nvim('paste', 'line 1\r\nline 2\r\nline 3', true, -1) + meths.nvim_paste('line 1\r\nline 2\r\nline 3', true, -1) expect([[ line 1 line 2 @@ -1202,27 +1192,27 @@ describe('API', function() eq({ 0, 3, 6, 0 }, funcs.getpos('.')) command('%delete _') -- Various other junk. - nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1) + meths.nvim_paste('line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1) expect('line 1\n\n\nline 2\nline 3\nline 4\n') eq({ 0, 7, 1, 0 }, funcs.getpos('.')) - eq(false, nvim('get_option_value', 'paste', {})) + eq(false, meths.nvim_get_option_value('paste', {})) end) it('Replace-mode', function() -- Within single line - nvim('put', { 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) + meths.nvim_put({ 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) command('normal l') command('startreplace') - nvim('paste', '123456', true, -1) + meths.nvim_paste('123456', true, -1) expect([[ a123456d eeffgghh iijjkkll]]) command('%delete _') -- Across lines - nvim('put', { 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) + meths.nvim_put({ 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) command('normal l') command('startreplace') - nvim('paste', '123\n456', true, -1) + meths.nvim_paste('123\n456', true, -1) expect([[ a123 456d @@ -1231,20 +1221,20 @@ describe('API', function() end) it('when searching in Visual mode', function() feed('v/') - nvim('paste', 'aabbccdd', true, -1) + meths.nvim_paste('aabbccdd', true, -1) eq('aabbccdd', funcs.getcmdline()) expect('') end) it('mappings are disabled in Cmdline mode', function() command('cnoremap a b') feed(':') - nvim('paste', 'a', true, -1) + meths.nvim_paste('a', true, -1) eq('a', funcs.getcmdline()) end) it('pasted text is saved in cmdline history when <CR> comes from mapping #20957', function() command('cnoremap <CR> <CR>') feed(':') - nvim('paste', 'echo', true, -1) + meths.nvim_paste('echo', true, -1) eq('', funcs.histget(':')) feed('<CR>') eq('echo', funcs.histget(':')) @@ -1253,8 +1243,8 @@ describe('API', function() local screen = Screen.new(20, 4) screen:attach() feed(':') - nvim('paste', 'Foo', true, 1) - nvim('paste', '', true, 3) + meths.nvim_paste('Foo', true, 1) + meths.nvim_paste('', true, 3) screen:expect([[ | ~ |*2 @@ -1265,7 +1255,7 @@ describe('API', function() local screen = Screen.new(20, 4) screen:attach() feed(':') - nvim('paste', 'normal! \023\022\006\027', true, -1) + meths.nvim_paste('normal! \023\022\006\027', true, -1) screen:expect([[ | ~ |*2 @@ -1273,12 +1263,12 @@ describe('API', function() ]]) end) it('crlf=false does not break lines at CR, CRLF', function() - nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) + meths.nvim_paste('line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) expect('line 1\r\n\r\rline 2\nline 3\rline 4\r') eq({ 0, 3, 14, 0 }, funcs.getpos('.')) end) it('vim.paste() failure', function() - nvim('exec_lua', 'vim.paste = (function(lines, phase) error("fake fail") end)', {}) + meths.nvim_exec_lua('vim.paste = (function(lines, phase) error("fake fail") end)', {}) eq('fake fail', pcall_err(request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1)) end) end) @@ -1300,7 +1290,7 @@ describe('API', function() end) it('inserts text', function() -- linewise - nvim('put', { 'line 1', 'line 2', 'line 3' }, 'l', true, true) + meths.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'l', true, true) expect([[ line 1 @@ -1309,14 +1299,14 @@ describe('API', function() eq({ 0, 4, 1, 0 }, funcs.getpos('.')) command('%delete _') -- charwise - nvim('put', { 'line 1', 'line 2', 'line 3' }, 'c', true, false) + meths.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'c', true, false) expect([[ line 1 line 2 line 3]]) eq({ 0, 1, 1, 0 }, funcs.getpos('.')) -- follow=false -- blockwise - nvim('put', { 'AA', 'BB' }, 'b', true, true) + meths.nvim_put({ 'AA', 'BB' }, 'b', true, true) expect([[ lAAine 1 lBBine 2 @@ -1324,35 +1314,35 @@ describe('API', function() eq({ 0, 2, 4, 0 }, funcs.getpos('.')) command('%delete _') -- Empty lines list. - nvim('put', {}, 'c', true, true) + meths.nvim_put({}, 'c', true, true) eq({ 0, 1, 1, 0 }, funcs.getpos('.')) expect([[]]) -- Single empty line. - nvim('put', { '' }, 'c', true, true) + meths.nvim_put({ '' }, 'c', true, true) eq({ 0, 1, 1, 0 }, funcs.getpos('.')) expect([[ ]]) - nvim('put', { 'AB' }, 'c', true, true) + meths.nvim_put({ 'AB' }, 'c', true, true) -- after=false, follow=true - nvim('put', { 'line 1', 'line 2' }, 'c', false, true) + meths.nvim_put({ 'line 1', 'line 2' }, 'c', false, true) expect([[ Aline 1 line 2B]]) eq({ 0, 2, 7, 0 }, funcs.getpos('.')) command('%delete _') - nvim('put', { 'AB' }, 'c', true, true) + meths.nvim_put({ 'AB' }, 'c', true, true) -- after=false, follow=false - nvim('put', { 'line 1', 'line 2' }, 'c', false, false) + meths.nvim_put({ 'line 1', 'line 2' }, 'c', false, false) expect([[ Aline 1 line 2B]]) eq({ 0, 1, 2, 0 }, funcs.getpos('.')) - eq('', nvim('eval', 'v:errmsg')) + eq('', meths.nvim_eval('v:errmsg')) end) it('detects charwise/linewise text (empty {type})', function() -- linewise (final item is empty string) - nvim('put', { 'line 1', 'line 2', 'line 3', '' }, '', true, true) + meths.nvim_put({ 'line 1', 'line 2', 'line 3', '' }, '', true, true) expect([[ line 1 @@ -1361,7 +1351,7 @@ describe('API', function() eq({ 0, 4, 1, 0 }, funcs.getpos('.')) command('%delete _') -- charwise (final item is non-empty) - nvim('put', { 'line 1', 'line 2', 'line 3' }, '', true, true) + meths.nvim_put({ 'line 1', 'line 2', 'line 3' }, '', true, true) expect([[ line 1 line 2 @@ -1399,22 +1389,22 @@ describe('API', function() describe('nvim_strwidth', function() it('works', function() - eq(3, nvim('strwidth', 'abc')) + eq(3, meths.nvim_strwidth('abc')) -- 6 + (neovim) -- 19 * 2 (each japanese character occupies two cells) - eq(44, nvim('strwidth', 'neovimのデザインかなりまともなのになってる。')) + eq(44, meths.nvim_strwidth('neovimのデザインかなりまともなのになってる。')) end) it('cannot handle NULs', function() - eq(0, nvim('strwidth', '\0abc')) + eq(0, meths.nvim_strwidth('\0abc')) end) end) describe('nvim_get_current_line, nvim_set_current_line', function() it('works', function() - eq('', nvim('get_current_line')) - nvim('set_current_line', 'abc') - eq('abc', nvim('get_current_line')) + eq('', meths.nvim_get_current_line()) + meths.nvim_set_current_line('abc') + eq('abc', meths.nvim_get_current_line()) end) end) @@ -1425,9 +1415,9 @@ describe('API', function() end) it('nvim_get_var, nvim_set_var, nvim_del_var', function() - nvim('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) - eq({ 1, 2, { ['3'] = 1 } }, nvim('get_var', 'lua')) - eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'g:lua')) + meths.nvim_set_var('lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_get_var('lua')) + eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('g:lua')) eq(1, funcs.exists('g:lua')) meths.nvim_del_var('lua') eq(0, funcs.exists('g:lua')) @@ -1435,8 +1425,8 @@ describe('API', function() meths.nvim_set_var('lua', 1) -- Empty keys are allowed in Vim dicts (and msgpack). - nvim('set_var', 'dict_empty_key', { [''] = 'empty key' }) - eq({ [''] = 'empty key' }, nvim('get_var', 'dict_empty_key')) + meths.nvim_set_var('dict_empty_key', { [''] = 'empty key' }) + eq({ [''] = 'empty key' }, meths.nvim_get_var('dict_empty_key')) -- Set locked g: var. command('lockvar lua') @@ -1549,182 +1539,182 @@ describe('API', function() end) it('truncates values with NULs in them', function() - nvim('set_var', 'xxx', 'ab\0cd') - eq('ab', nvim('get_var', 'xxx')) + meths.nvim_set_var('xxx', 'ab\0cd') + eq('ab', meths.nvim_get_var('xxx')) end) end) describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - ok(nvim('get_option_value', 'equalalways', {})) - nvim('set_option_value', 'equalalways', false, {}) - ok(not nvim('get_option_value', 'equalalways', {})) + ok(meths.nvim_get_option_value('equalalways', {})) + meths.nvim_set_option_value('equalalways', false, {}) + ok(not meths.nvim_get_option_value('equalalways', {})) end) it('works to get global value of local options', function() - eq(false, nvim('get_option_value', 'lisp', {})) - eq(8, nvim('get_option_value', 'shiftwidth', {})) + eq(false, meths.nvim_get_option_value('lisp', {})) + eq(8, meths.nvim_get_option_value('shiftwidth', {})) end) it('works to set global value of local options', function() - nvim('set_option_value', 'lisp', true, { scope = 'global' }) - eq(true, nvim('get_option_value', 'lisp', { scope = 'global' })) - eq(false, nvim('get_option_value', 'lisp', {})) - eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp')) - eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp')) - nvim('set_option_value', 'shiftwidth', 20, { scope = 'global' }) - eq('20', nvim('command_output', 'setglobal shiftwidth?'):match('%d+')) - eq('8', nvim('command_output', 'setlocal shiftwidth?'):match('%d+')) + meths.nvim_set_option_value('lisp', true, { scope = 'global' }) + eq(true, meths.nvim_get_option_value('lisp', { scope = 'global' })) + eq(false, meths.nvim_get_option_value('lisp', {})) + eq(nil, command_output('setglobal lisp?'):match('nolisp')) + eq('nolisp', command_output('setlocal lisp?'):match('nolisp')) + meths.nvim_set_option_value('shiftwidth', 20, { scope = 'global' }) + eq('20', command_output('setglobal shiftwidth?'):match('%d+')) + eq('8', command_output('setlocal shiftwidth?'):match('%d+')) end) it('updates where the option was last set from', function() - nvim('set_option_value', 'equalalways', false, {}) - local status, rv = pcall(nvim, 'command_output', 'verbose set equalalways?') + meths.nvim_set_option_value('equalalways', false, {}) + local status, rv = pcall(command_output, 'verbose set equalalways?') eq(true, status) ok( nil ~= string.find(rv, 'noequalalways\n' .. '\tLast set from API client %(channel id %d+%)') ) - nvim('exec_lua', 'vim.api.nvim_set_option_value("equalalways", true, {})', {}) - status, rv = pcall(nvim, 'command_output', 'verbose set equalalways?') + meths.nvim_exec_lua('vim.api.nvim_set_option_value("equalalways", true, {})', {}) + status, rv = pcall(command_output, 'verbose set equalalways?') eq(true, status) eq(' equalalways\n\tLast set from Lua', rv) end) it('updates whether the option has ever been set #25025', function() - eq(false, nvim('get_option_info2', 'autochdir', {}).was_set) - nvim('set_option_value', 'autochdir', true, {}) - eq(true, nvim('get_option_info2', 'autochdir', {}).was_set) + eq(false, meths.nvim_get_option_info2('autochdir', {}).was_set) + meths.nvim_set_option_value('autochdir', true, {}) + eq(true, meths.nvim_get_option_info2('autochdir', {}).was_set) - eq(false, nvim('get_option_info2', 'cmdwinheight', {}).was_set) - nvim('set_option_value', 'cmdwinheight', 10, {}) - eq(true, nvim('get_option_info2', 'cmdwinheight', {}).was_set) + eq(false, meths.nvim_get_option_info2('cmdwinheight', {}).was_set) + meths.nvim_set_option_value('cmdwinheight', 10, {}) + eq(true, meths.nvim_get_option_info2('cmdwinheight', {}).was_set) - eq(false, nvim('get_option_info2', 'debug', {}).was_set) - nvim('set_option_value', 'debug', 'beep', {}) - eq(true, nvim('get_option_info2', 'debug', {}).was_set) + eq(false, meths.nvim_get_option_info2('debug', {}).was_set) + meths.nvim_set_option_value('debug', 'beep', {}) + eq(true, meths.nvim_get_option_info2('debug', {}).was_set) end) it('validation', function() eq( "Invalid 'scope': expected 'local' or 'global'", - pcall_err(nvim, 'get_option_value', 'scrolloff', { scope = 'bogus' }) + pcall_err(meths.nvim_get_option_value, 'scrolloff', { scope = 'bogus' }) ) eq( "Invalid 'scope': expected 'local' or 'global'", - pcall_err(nvim, 'set_option_value', 'scrolloff', 1, { scope = 'bogus' }) + pcall_err(meths.nvim_set_option_value, 'scrolloff', 1, { scope = 'bogus' }) ) eq( "Invalid 'scope': expected String, got Integer", - pcall_err(nvim, 'get_option_value', 'scrolloff', { scope = 42 }) + pcall_err(meths.nvim_get_option_value, 'scrolloff', { scope = 42 }) ) eq( "Invalid 'value': expected valid option type, got Array", - pcall_err(nvim, 'set_option_value', 'scrolloff', {}, {}) + pcall_err(meths.nvim_set_option_value, 'scrolloff', {}, {}) ) eq( "Invalid value for option 'scrolloff': expected number, got boolean true", - pcall_err(nvim, 'set_option_value', 'scrolloff', true, {}) + pcall_err(meths.nvim_set_option_value, 'scrolloff', true, {}) ) eq( 'Invalid value for option \'scrolloff\': expected number, got string "wrong"', - pcall_err(nvim, 'set_option_value', 'scrolloff', 'wrong', {}) + pcall_err(meths.nvim_set_option_value, 'scrolloff', 'wrong', {}) ) end) it('can get local values when global value is set', function() - eq(0, nvim('get_option_value', 'scrolloff', {})) - eq(-1, nvim('get_option_value', 'scrolloff', { scope = 'local' })) + eq(0, meths.nvim_get_option_value('scrolloff', {})) + eq(-1, meths.nvim_get_option_value('scrolloff', { scope = 'local' })) end) it('can set global and local values', function() - nvim('set_option_value', 'makeprg', 'hello', {}) - eq('hello', nvim('get_option_value', 'makeprg', {})) - eq('', nvim('get_option_value', 'makeprg', { scope = 'local' })) - nvim('set_option_value', 'makeprg', 'world', { scope = 'local' }) - eq('world', nvim('get_option_value', 'makeprg', { scope = 'local' })) - nvim('set_option_value', 'makeprg', 'goodbye', { scope = 'global' }) - eq('goodbye', nvim('get_option_value', 'makeprg', { scope = 'global' })) - nvim('set_option_value', 'makeprg', 'hello', {}) - eq('hello', nvim('get_option_value', 'makeprg', { scope = 'global' })) - eq('hello', nvim('get_option_value', 'makeprg', {})) - eq('', nvim('get_option_value', 'makeprg', { scope = 'local' })) + meths.nvim_set_option_value('makeprg', 'hello', {}) + eq('hello', meths.nvim_get_option_value('makeprg', {})) + eq('', meths.nvim_get_option_value('makeprg', { scope = 'local' })) + meths.nvim_set_option_value('makeprg', 'world', { scope = 'local' }) + eq('world', meths.nvim_get_option_value('makeprg', { scope = 'local' })) + meths.nvim_set_option_value('makeprg', 'goodbye', { scope = 'global' }) + eq('goodbye', meths.nvim_get_option_value('makeprg', { scope = 'global' })) + meths.nvim_set_option_value('makeprg', 'hello', {}) + eq('hello', meths.nvim_get_option_value('makeprg', { scope = 'global' })) + eq('hello', meths.nvim_get_option_value('makeprg', {})) + eq('', meths.nvim_get_option_value('makeprg', { scope = 'local' })) end) it('clears the local value of an option with nil', function() -- Set global value - nvim('set_option_value', 'shiftwidth', 42, {}) - eq(42, nvim('get_option_value', 'shiftwidth', {})) + meths.nvim_set_option_value('shiftwidth', 42, {}) + eq(42, meths.nvim_get_option_value('shiftwidth', {})) -- Set local value - nvim('set_option_value', 'shiftwidth', 8, { scope = 'local' }) - eq(8, nvim('get_option_value', 'shiftwidth', {})) - eq(8, nvim('get_option_value', 'shiftwidth', { scope = 'local' })) - eq(42, nvim('get_option_value', 'shiftwidth', { scope = 'global' })) + meths.nvim_set_option_value('shiftwidth', 8, { scope = 'local' }) + eq(8, meths.nvim_get_option_value('shiftwidth', {})) + eq(8, meths.nvim_get_option_value('shiftwidth', { scope = 'local' })) + eq(42, meths.nvim_get_option_value('shiftwidth', { scope = 'global' })) -- Clear value without scope - nvim('set_option_value', 'shiftwidth', NIL, {}) - eq(42, nvim('get_option_value', 'shiftwidth', {})) - eq(42, nvim('get_option_value', 'shiftwidth', { scope = 'local' })) + meths.nvim_set_option_value('shiftwidth', NIL, {}) + eq(42, meths.nvim_get_option_value('shiftwidth', {})) + eq(42, meths.nvim_get_option_value('shiftwidth', { scope = 'local' })) -- Clear value with explicit scope - nvim('set_option_value', 'shiftwidth', 8, { scope = 'local' }) - nvim('set_option_value', 'shiftwidth', NIL, { scope = 'local' }) - eq(42, nvim('get_option_value', 'shiftwidth', {})) - eq(42, nvim('get_option_value', 'shiftwidth', { scope = 'local' })) + meths.nvim_set_option_value('shiftwidth', 8, { scope = 'local' }) + meths.nvim_set_option_value('shiftwidth', NIL, { scope = 'local' }) + eq(42, meths.nvim_get_option_value('shiftwidth', {})) + eq(42, meths.nvim_get_option_value('shiftwidth', { scope = 'local' })) -- Now try with options with a special "local is unset" value (e.g. 'undolevels') - nvim('set_option_value', 'undolevels', 1000, {}) - nvim('set_option_value', 'undolevels', 1200, { scope = 'local' }) - eq(1200, nvim('get_option_value', 'undolevels', { scope = 'local' })) - nvim('set_option_value', 'undolevels', NIL, { scope = 'local' }) - eq(-123456, nvim('get_option_value', 'undolevels', { scope = 'local' })) - eq(1000, nvim('get_option_value', 'undolevels', {})) + meths.nvim_set_option_value('undolevels', 1000, {}) + meths.nvim_set_option_value('undolevels', 1200, { scope = 'local' }) + eq(1200, meths.nvim_get_option_value('undolevels', { scope = 'local' })) + meths.nvim_set_option_value('undolevels', NIL, { scope = 'local' }) + eq(-123456, meths.nvim_get_option_value('undolevels', { scope = 'local' })) + eq(1000, meths.nvim_get_option_value('undolevels', {})) - nvim('set_option_value', 'autoread', true, {}) - nvim('set_option_value', 'autoread', false, { scope = 'local' }) - eq(false, nvim('get_option_value', 'autoread', { scope = 'local' })) - nvim('set_option_value', 'autoread', NIL, { scope = 'local' }) - eq(NIL, nvim('get_option_value', 'autoread', { scope = 'local' })) - eq(true, nvim('get_option_value', 'autoread', {})) + meths.nvim_set_option_value('autoread', true, {}) + meths.nvim_set_option_value('autoread', false, { scope = 'local' }) + eq(false, meths.nvim_get_option_value('autoread', { scope = 'local' })) + meths.nvim_set_option_value('autoread', NIL, { scope = 'local' }) + eq(NIL, meths.nvim_get_option_value('autoread', { scope = 'local' })) + eq(true, meths.nvim_get_option_value('autoread', {})) end) it('set window options', function() - nvim('set_option_value', 'colorcolumn', '4,3', {}) - eq('4,3', nvim('get_option_value', 'colorcolumn', { scope = 'local' })) + meths.nvim_set_option_value('colorcolumn', '4,3', {}) + eq('4,3', meths.nvim_get_option_value('colorcolumn', { scope = 'local' })) command('set modified hidden') command('enew') -- edit new buffer, window option is preserved - eq('4,3', nvim('get_option_value', 'colorcolumn', { scope = 'local' })) + eq('4,3', meths.nvim_get_option_value('colorcolumn', { scope = 'local' })) end) it('set local window options', function() - nvim('set_option_value', 'colorcolumn', '4,3', { win = 0, scope = 'local' }) - eq('4,3', nvim('get_option_value', 'colorcolumn', { win = 0, scope = 'local' })) + meths.nvim_set_option_value('colorcolumn', '4,3', { win = 0, scope = 'local' }) + eq('4,3', meths.nvim_get_option_value('colorcolumn', { win = 0, scope = 'local' })) command('set modified hidden') command('enew') -- edit new buffer, window option is reset - eq('', nvim('get_option_value', 'colorcolumn', { win = 0, scope = 'local' })) + eq('', meths.nvim_get_option_value('colorcolumn', { win = 0, scope = 'local' })) end) it('get buffer or window-local options', function() - nvim('command', 'new') - local buf = nvim('get_current_buf').id - nvim('set_option_value', 'tagfunc', 'foobar', { buf = buf }) - eq('foobar', nvim('get_option_value', 'tagfunc', { buf = buf })) + command('new') + local buf = meths.nvim_get_current_buf().id + meths.nvim_set_option_value('tagfunc', 'foobar', { buf = buf }) + eq('foobar', meths.nvim_get_option_value('tagfunc', { buf = buf })) - local win = nvim('get_current_win').id - nvim('set_option_value', 'number', true, { win = win }) - eq(true, nvim('get_option_value', 'number', { win = win })) + local win = meths.nvim_get_current_win().id + meths.nvim_set_option_value('number', true, { win = win }) + eq(true, meths.nvim_get_option_value('number', { win = win })) end) it('getting current buffer option does not adjust cursor #19381', function() - nvim('command', 'new') - local buf = nvim('get_current_buf').id - local win = nvim('get_current_win').id + command('new') + local buf = meths.nvim_get_current_buf().id + local win = meths.nvim_get_current_win().id insert('some text') feed('0v$') - eq({ 1, 9 }, nvim('win_get_cursor', win)) - nvim('get_option_value', 'filetype', { buf = buf }) - eq({ 1, 9 }, nvim('win_get_cursor', win)) + eq({ 1, 9 }, meths.nvim_win_get_cursor(win)) + meths.nvim_get_option_value('filetype', { buf = buf }) + eq({ 1, 9 }, meths.nvim_win_get_cursor(win)) end) it('can get default option values for filetypes', function() @@ -1736,156 +1726,156 @@ describe('API', function() xml = { formatexpr = 'xmlformat#Format()' }, } do for option, value in pairs(opts) do - eq(value, nvim('get_option_value', option, { filetype = ft })) + eq(value, meths.nvim_get_option_value(option, { filetype = ft })) end end command 'au FileType lua setlocal commentstring=NEW\\ %s' - eq('NEW %s', nvim('get_option_value', 'commentstring', { filetype = 'lua' })) + eq('NEW %s', meths.nvim_get_option_value('commentstring', { filetype = 'lua' })) end) it('errors for bad FileType autocmds', function() command 'au FileType lua setlocal commentstring=BAD' eq( [[FileType Autocommands for "lua": Vim(setlocal):E537: 'commentstring' must be empty or contain %s: commentstring=BAD]], - pcall_err(nvim, 'get_option_value', 'commentstring', { filetype = 'lua' }) + pcall_err(meths.nvim_get_option_value, 'commentstring', { filetype = 'lua' }) ) end) it("value of 'modified' is always false for scratch buffers", function() - nvim('set_current_buf', nvim('create_buf', true, true)) + meths.nvim_set_current_buf(meths.nvim_create_buf(true, true)) insert([[ foo bar baz ]]) - eq(false, nvim('get_option_value', 'modified', {})) + eq(false, meths.nvim_get_option_value('modified', {})) end) end) describe('nvim_{get,set}_current_buf, nvim_list_bufs', function() it('works', function() - eq(1, #nvim('list_bufs')) - eq(nvim('list_bufs')[1], nvim('get_current_buf')) - nvim('command', 'new') - eq(2, #nvim('list_bufs')) - eq(nvim('list_bufs')[2], nvim('get_current_buf')) - nvim('set_current_buf', nvim('list_bufs')[1]) - eq(nvim('list_bufs')[1], nvim('get_current_buf')) + eq(1, #meths.nvim_list_bufs()) + eq(meths.nvim_list_bufs()[1], meths.nvim_get_current_buf()) + command('new') + eq(2, #meths.nvim_list_bufs()) + eq(meths.nvim_list_bufs()[2], meths.nvim_get_current_buf()) + meths.nvim_set_current_buf(meths.nvim_list_bufs()[1]) + eq(meths.nvim_list_bufs()[1], meths.nvim_get_current_buf()) end) end) describe('nvim_{get,set}_current_win, nvim_list_wins', function() it('works', function() - eq(1, #nvim('list_wins')) - eq(nvim('list_wins')[1], nvim('get_current_win')) - nvim('command', 'vsplit') - nvim('command', 'split') - eq(3, #nvim('list_wins')) - eq(nvim('list_wins')[1], nvim('get_current_win')) - nvim('set_current_win', nvim('list_wins')[2]) - eq(nvim('list_wins')[2], nvim('get_current_win')) + eq(1, #meths.nvim_list_wins()) + eq(meths.nvim_list_wins()[1], meths.nvim_get_current_win()) + command('vsplit') + command('split') + eq(3, #meths.nvim_list_wins()) + eq(meths.nvim_list_wins()[1], meths.nvim_get_current_win()) + meths.nvim_set_current_win(meths.nvim_list_wins()[2]) + eq(meths.nvim_list_wins()[2], meths.nvim_get_current_win()) end) end) describe('nvim_{get,set}_current_tabpage, nvim_list_tabpages', function() it('works', function() - eq(1, #nvim('list_tabpages')) - eq(nvim('list_tabpages')[1], nvim('get_current_tabpage')) - nvim('command', 'tabnew') - eq(2, #nvim('list_tabpages')) - eq(2, #nvim('list_wins')) - eq(nvim('list_wins')[2], nvim('get_current_win')) - eq(nvim('list_tabpages')[2], nvim('get_current_tabpage')) - nvim('set_current_win', nvim('list_wins')[1]) + eq(1, #meths.nvim_list_tabpages()) + eq(meths.nvim_list_tabpages()[1], meths.nvim_get_current_tabpage()) + command('tabnew') + eq(2, #meths.nvim_list_tabpages()) + eq(2, #meths.nvim_list_wins()) + eq(meths.nvim_list_wins()[2], meths.nvim_get_current_win()) + eq(meths.nvim_list_tabpages()[2], meths.nvim_get_current_tabpage()) + meths.nvim_set_current_win(meths.nvim_list_wins()[1]) -- Switching window also switches tabpages if necessary - eq(nvim('list_tabpages')[1], nvim('get_current_tabpage')) - eq(nvim('list_wins')[1], nvim('get_current_win')) - nvim('set_current_tabpage', nvim('list_tabpages')[2]) - eq(nvim('list_tabpages')[2], nvim('get_current_tabpage')) - eq(nvim('list_wins')[2], nvim('get_current_win')) + eq(meths.nvim_list_tabpages()[1], meths.nvim_get_current_tabpage()) + eq(meths.nvim_list_wins()[1], meths.nvim_get_current_win()) + meths.nvim_set_current_tabpage(meths.nvim_list_tabpages()[2]) + eq(meths.nvim_list_tabpages()[2], meths.nvim_get_current_tabpage()) + eq(meths.nvim_list_wins()[2], meths.nvim_get_current_win()) end) end) describe('nvim_get_mode', function() it('during normal-mode `g` returns blocking=true', function() - nvim('input', 'o') -- add a line - eq({ mode = 'i', blocking = false }, nvim('get_mode')) - nvim('input', [[<C-\><C-N>]]) - eq(2, nvim('eval', "line('.')")) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') -- add a line + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + meths.nvim_input([[<C-\><C-N>]]) + eq(2, meths.nvim_eval("line('.')")) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) - nvim('input', 'g') - eq({ mode = 'n', blocking = true }, nvim('get_mode')) + meths.nvim_input('g') + eq({ mode = 'n', blocking = true }, meths.nvim_get_mode()) - nvim('input', 'k') -- complete the operator - eq(1, nvim('eval', "line('.')")) -- verify the completed operator - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('k') -- complete the operator + eq(1, meths.nvim_eval("line('.')")) -- verify the completed operator + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('returns the correct result multiple consecutive times', function() for _ = 1, 5 do - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end - nvim('input', 'g') + meths.nvim_input('g') for _ = 1, 4 do - eq({ mode = 'n', blocking = true }, nvim('get_mode')) + eq({ mode = 'n', blocking = true }, meths.nvim_get_mode()) end - nvim('input', 'g') + meths.nvim_input('g') for _ = 1, 7 do - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end end) it('during normal-mode CTRL-W, returns blocking=true', function() - nvim('input', '<C-W>') - eq({ mode = 'n', blocking = true }, nvim('get_mode')) + meths.nvim_input('<C-W>') + eq({ mode = 'n', blocking = true }, meths.nvim_get_mode()) - nvim('input', 's') -- complete the operator - eq(2, nvim('eval', "winnr('$')")) -- verify the completed operator - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('s') -- complete the operator + eq(2, meths.nvim_eval("winnr('$')")) -- verify the completed operator + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('during press-enter prompt without UI returns blocking=false', function() - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) command("echom 'msg1'") command("echom 'msg2'") command("echom 'msg3'") command("echom 'msg4'") command("echom 'msg5'") - eq({ mode = 'n', blocking = false }, nvim('get_mode')) - nvim('input', ':messages<CR>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + meths.nvim_input(':messages<CR>') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('during press-enter prompt returns blocking=true', function() - nvim('ui_attach', 80, 20, {}) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_ui_attach(80, 20, {}) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) command("echom 'msg1'") command("echom 'msg2'") command("echom 'msg3'") command("echom 'msg4'") command("echom 'msg5'") - eq({ mode = 'n', blocking = false }, nvim('get_mode')) - nvim('input', ':messages<CR>') - eq({ mode = 'r', blocking = true }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + meths.nvim_input(':messages<CR>') + eq({ mode = 'r', blocking = true }, meths.nvim_get_mode()) end) it('during getchar() returns blocking=false', function() - nvim('input', ':let g:test_input = nr2char(getchar())<CR>') + meths.nvim_input(':let g:test_input = nr2char(getchar())<CR>') -- Events are enabled during getchar(), RPC calls are *not* blocked. #5384 - eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(0, nvim('eval', "exists('g:test_input')")) - nvim('input', 'J') - eq('J', nvim('eval', 'g:test_input')) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + eq(0, meths.nvim_eval("exists('g:test_input')")) + meths.nvim_input('J') + eq('J', meths.nvim_eval('g:test_input')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) -- TODO: bug #6247#issuecomment-286403810 it('batched with input', function() - nvim('ui_attach', 80, 20, {}) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_ui_attach(80, 20, {}) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) command("echom 'msg1'") command("echom 'msg2'") command("echom 'msg3'") @@ -1907,34 +1897,34 @@ describe('API', function() }, NIL, }, meths.nvim_call_atomic(req)) - eq({ mode = 'r', blocking = true }, nvim('get_mode')) + eq({ mode = 'r', blocking = true }, meths.nvim_get_mode()) end) it('during insert-mode map-pending, returns blocking=true #6166', function() command('inoremap xx foo') - nvim('input', 'ix') - eq({ mode = 'i', blocking = true }, nvim('get_mode')) + meths.nvim_input('ix') + eq({ mode = 'i', blocking = true }, meths.nvim_get_mode()) end) it('during normal-mode gU, returns blocking=false #6166', function() - nvim('input', 'gu') - eq({ mode = 'no', blocking = false }, nvim('get_mode')) + meths.nvim_input('gu') + eq({ mode = 'no', blocking = false }, meths.nvim_get_mode()) end) it("at '-- More --' prompt returns blocking=true #11899", function() command('set more') feed(':digraphs<cr>') - eq({ mode = 'rm', blocking = true }, nvim('get_mode')) + eq({ mode = 'rm', blocking = true }, meths.nvim_get_mode()) end) it('after <Nop> mapping returns blocking=false #17257', function() command('nnoremap <F2> <Nop>') feed('<F2>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('after empty string <expr> mapping returns blocking=false #17257', function() command('nnoremap <expr> <F2> ""') feed('<F2>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) end) @@ -1943,16 +1933,16 @@ describe('API', function() helpers.insert([[ FIRST LINE SECOND LINE]]) - nvim('input', 'gg') - nvim('input', 'gu') + meths.nvim_input('gg') + meths.nvim_input('gu') -- Make any RPC request (can be non-async: op-pending does not block). - nvim('get_current_buf') + meths.nvim_get_current_buf() -- Buffer should not change. expect([[ FIRST LINE SECOND LINE]]) -- Now send input to complete the operator. - nvim('input', 'j') + meths.nvim_input('j') expect([[ first line second line]]) @@ -1966,7 +1956,7 @@ describe('API', function() feed('ia<cr>b<cr>c<cr><Esc>kkk') feed('d') -- Make any RPC request (can be non-async: op-pending does not block). - nvim('get_current_buf') + meths.nvim_get_current_buf() screen:expect([[ ^a$ | b$ | @@ -1980,12 +1970,12 @@ describe('API', function() helpers.insert([[ FIRST LINE SECOND LINE]]) - nvim('input', 'gg') - nvim('input', 'd') + meths.nvim_input('gg') + meths.nvim_input('d') -- Make any RPC request (must be async, because map-pending blocks). - nvim('get_api_info') + meths.nvim_get_api_info() -- Send input to complete the mapping. - nvim('input', 'd') + meths.nvim_input('d') expect([[ FIRST LINE SECOND LINE]]) @@ -1998,11 +1988,11 @@ describe('API', function() helpers.insert([[ FIRST LINE SECOND LINE]]) - nvim('input', 'ix') + meths.nvim_input('ix') -- Make any RPC request (must be async, because map-pending blocks). - nvim('get_api_info') + meths.nvim_get_api_info() -- Send input to complete the mapping. - nvim('input', 'x') + meths.nvim_input('x') expect([[ FIRST LINE SECOND LINfooE]]) @@ -2059,28 +2049,28 @@ describe('API', function() describe('nvim_get_context', function() it('validation', function() - eq("Invalid key: 'blah'", pcall_err(nvim, 'get_context', { blah = {} })) + eq("Invalid key: 'blah'", pcall_err(meths.nvim_get_context, { blah = {} })) eq( "Invalid 'types': expected Array, got Integer", - pcall_err(nvim, 'get_context', { types = 42 }) + pcall_err(meths.nvim_get_context, { types = 42 }) ) eq( "Invalid 'type': 'zub'", - pcall_err(nvim, 'get_context', { types = { 'jumps', 'zub', 'zam' } }) + pcall_err(meths.nvim_get_context, { types = { 'jumps', 'zub', 'zam' } }) ) end) it('returns map of current editor state', function() local opts = { types = { 'regs', 'jumps', 'bufs', 'gvars' } } - eq({}, parse_context(nvim('get_context', {}))) + eq({}, parse_context(meths.nvim_get_context({}))) feed('i1<cr>2<cr>3<c-[>ddddddqahjklquuu') feed('gg') feed('G') command('edit! BUF1') command('edit BUF2') - nvim('set_var', 'one', 1) - nvim('set_var', 'Two', 2) - nvim('set_var', 'THREE', 3) + meths.nvim_set_var('one', 1) + meths.nvim_set_var('Two', 2) + meths.nvim_set_var('THREE', 3) local expected_ctx = { ['regs'] = { @@ -2105,72 +2095,72 @@ describe('API', function() ['gvars'] = { { 'one', 1 }, { 'Two', 2 }, { 'THREE', 3 } }, } - eq(expected_ctx, parse_context(nvim('get_context', opts))) - eq(expected_ctx, parse_context(nvim('get_context', {}))) - eq(expected_ctx, parse_context(nvim('get_context', { types = {} }))) + eq(expected_ctx, parse_context(meths.nvim_get_context(opts))) + eq(expected_ctx, parse_context(meths.nvim_get_context({}))) + eq(expected_ctx, parse_context(meths.nvim_get_context({ types = {} }))) end) end) describe('nvim_load_context', function() it('sets current editor state to given context dictionary', function() local opts = { types = { 'regs', 'jumps', 'bufs', 'gvars' } } - eq({}, parse_context(nvim('get_context', opts))) - - nvim('set_var', 'one', 1) - nvim('set_var', 'Two', 2) - nvim('set_var', 'THREE', 3) - local ctx = nvim('get_context', opts) - nvim('set_var', 'one', 'a') - nvim('set_var', 'Two', 'b') - nvim('set_var', 'THREE', 'c') + eq({}, parse_context(meths.nvim_get_context(opts))) + + meths.nvim_set_var('one', 1) + meths.nvim_set_var('Two', 2) + meths.nvim_set_var('THREE', 3) + local ctx = meths.nvim_get_context(opts) + meths.nvim_set_var('one', 'a') + meths.nvim_set_var('Two', 'b') + meths.nvim_set_var('THREE', 'c') eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) - nvim('load_context', ctx) + meths.nvim_load_context(ctx) eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) end) it('errors when context dictionary is invalid', function() eq( 'E474: Failed to convert list to msgpack string buffer', - pcall_err(nvim, 'load_context', { regs = { {} }, jumps = { {} } }) + pcall_err(meths.nvim_load_context, { regs = { {} }, jumps = { {} } }) ) eq( 'E474: Failed to convert list to msgpack string buffer', - pcall_err(nvim, 'load_context', { regs = { { [''] = '' } } }) + pcall_err(meths.nvim_load_context, { regs = { { [''] = '' } } }) ) end) end) describe('nvim_replace_termcodes', function() it('escapes K_SPECIAL as K_SPECIAL KS_SPECIAL KE_FILLER', function() - eq('\128\254X', helpers.nvim('replace_termcodes', '\128', true, true, true)) + eq('\128\254X', helpers.meths.nvim_replace_termcodes('\128', true, true, true)) end) it('leaves non-K_SPECIAL string unchanged', function() - eq('abc', helpers.nvim('replace_termcodes', 'abc', true, true, true)) + eq('abc', helpers.meths.nvim_replace_termcodes('abc', true, true, true)) end) it('converts <expressions>', function() - eq('\\', helpers.nvim('replace_termcodes', '<Leader>', true, true, true)) + eq('\\', helpers.meths.nvim_replace_termcodes('<Leader>', true, true, true)) end) it('converts <LeftMouse> to K_SPECIAL KS_EXTRA KE_LEFTMOUSE', function() -- K_SPECIAL KS_EXTRA KE_LEFTMOUSE -- 0x80 0xfd 0x2c -- 128 253 44 - eq('\128\253\44', helpers.nvim('replace_termcodes', '<LeftMouse>', true, true, true)) + eq('\128\253\44', helpers.meths.nvim_replace_termcodes('<LeftMouse>', true, true, true)) end) it('converts keycodes', function() eq( '\nx\27x\rx<x', - helpers.nvim('replace_termcodes', '<NL>x<Esc>x<CR>x<lt>x', true, true, true) + helpers.meths.nvim_replace_termcodes('<NL>x<Esc>x<CR>x<lt>x', true, true, true) ) end) it('does not convert keycodes if special=false', function() eq( '<NL>x<Esc>x<CR>x<lt>x', - helpers.nvim('replace_termcodes', '<NL>x<Esc>x<CR>x<lt>x', true, true, false) + helpers.meths.nvim_replace_termcodes('<NL>x<Esc>x<CR>x<lt>x', true, true, false) ) end) @@ -2196,15 +2186,15 @@ describe('API', function() it('K_SPECIAL escaping', function() local function on_setup() -- notice the special char(…) \xe2\80\xa6 - nvim('feedkeys', ':let x1="…"\n', '', true) + meths.nvim_feedkeys(':let x1="…"\n', '', true) -- Both nvim_replace_termcodes and nvim_feedkeys escape \x80 - local inp = helpers.nvim('replace_termcodes', ':let x2="…"<CR>', true, true, true) - nvim('feedkeys', inp, '', true) -- escape_ks=true + local inp = helpers.meths.nvim_replace_termcodes(':let x2="…"<CR>', true, true, true) + meths.nvim_feedkeys(inp, '', true) -- escape_ks=true -- nvim_feedkeys with K_SPECIAL escaping disabled - inp = helpers.nvim('replace_termcodes', ':let x3="…"<CR>', true, true, true) - nvim('feedkeys', inp, '', false) -- escape_ks=false + inp = helpers.meths.nvim_replace_termcodes(':let x3="…"<CR>', true, true, true) + meths.nvim_feedkeys(inp, '', false) -- escape_ks=false helpers.stop() end @@ -2212,10 +2202,10 @@ describe('API', function() -- spin the loop a bit helpers.run(nil, nil, on_setup) - eq('…', nvim('get_var', 'x1')) + eq('…', meths.nvim_get_var('x1')) -- Because of the double escaping this is neq - neq('…', nvim('get_var', 'x2')) - eq('…', nvim('get_var', 'x3')) + neq('…', meths.nvim_get_var('x2')) + eq('…', meths.nvim_get_var('x3')) end) end) @@ -2709,20 +2699,20 @@ describe('API', function() end) it('can throw exceptions', function() - local status, err = pcall(nvim, 'get_option_value', 'invalid-option', {}) + local status, err = pcall(meths.nvim_get_option_value, 'invalid-option', {}) eq(false, status) ok(err:match("Unknown option 'invalid%-option'") ~= nil) end) it('does not truncate error message <1 MB #5984', function() local very_long_name = 'A' .. ('x'):rep(10000) .. 'Z' - local status, err = pcall(nvim, 'get_option_value', very_long_name, {}) + local status, err = pcall(meths.nvim_get_option_value, very_long_name, {}) eq(false, status) eq(very_long_name, err:match('Ax+Z?')) end) it('does not leak memory on incorrect argument types', function() - local status, err = pcall(nvim, 'set_current_dir', { 'not', 'a', 'dir' }) + local status, err = pcall(meths.nvim_set_current_dir, { 'not', 'a', 'dir' }) eq(false, status) ok( err:match(': Wrong type for argument 1 when calling nvim_set_current_dir, expecting String') @@ -2945,7 +2935,7 @@ describe('API', function() describe('nvim_list_uis', function() it('returns empty if --headless', function() -- Test runner defaults to --headless. - eq({}, nvim('list_uis')) + eq({}, meths.nvim_list_uis()) end) it('returns attached UIs', function() local screen = Screen.new(20, 4) @@ -2974,7 +2964,7 @@ describe('API', function() }, } - eq(expected, nvim('list_uis')) + eq(expected, meths.nvim_list_uis()) screen:detach() screen = Screen.new(44, 99) @@ -2983,7 +2973,7 @@ describe('API', function() expected[1].override = false expected[1].width = 44 expected[1].height = 99 - eq(expected, nvim('list_uis')) + eq(expected, meths.nvim_list_uis()) end) end) @@ -3007,7 +2997,7 @@ describe('API', function() eq( ' 1 %a "[No Name]" line 1\n' .. ' 2 h "[No Name]" line 0', - meths.nvim_command_output('ls') + command_output('ls') ) -- current buffer didn't change eq({ id = 1 }, meths.nvim_get_current_buf()) @@ -3436,13 +3426,13 @@ describe('API', function() end) it('can save message history', function() - nvim('command', 'set cmdheight=2') -- suppress Press ENTER - nvim('echo', { { 'msg\nmsg' }, { 'msg' } }, true, {}) + command('set cmdheight=2') -- suppress Press ENTER + meths.nvim_echo({ { 'msg\nmsg' }, { 'msg' } }, true, {}) eq('msg\nmsgmsg', exec_capture('messages')) end) it('can disable saving message history', function() - nvim('command', 'set cmdheight=2') -- suppress Press ENTER + command('set cmdheight=2') -- suppress Press ENTER nvim_async('echo', { { 'msg\nmsg' }, { 'msg' } }, false, {}) eq('', exec_capture('messages')) end) @@ -3630,12 +3620,12 @@ describe('API', function() it('works with deleted buffers', function() local fname = tmpname() write_file(fname, 'a\nbit of\text') - nvim('command', 'edit ' .. fname) + command('edit ' .. fname) local buf = meths.nvim_get_current_buf() meths.nvim_buf_set_mark(buf, 'F', 2, 2, {}) - nvim('command', 'new') -- Create new buf to avoid :bd failing - nvim('command', 'bd! ' .. buf.id) + command('new') -- Create new buf to avoid :bd failing + command('bd! ' .. buf.id) os.remove(fname) local mark = meths.nvim_get_mark('F', {}) diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 9542272447..87aa0ca2a8 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1,21 +1,17 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, ok, feed, insert, eval, tabpage = +local clear, curbuf, curbuf_contents, curwin, eq, neq, ok, feed, insert, eval = helpers.clear, - helpers.nvim, - helpers.curbuf, + helpers.meths.nvim_get_current_buf, helpers.curbuf_contents, - helpers.window, - helpers.curwin, + helpers.meths.nvim_get_current_win, helpers.eq, helpers.neq, helpers.ok, helpers.feed, helpers.insert, - helpers.eval, - helpers.tabpage + helpers.eval local poke_eventloop = helpers.poke_eventloop -local curwinmeths = helpers.curwinmeths local exec = helpers.exec local funcs = helpers.funcs local request = helpers.request @@ -30,26 +26,35 @@ describe('API/win', function() describe('get_buf', function() it('works', function() - eq(curbuf(), window('get_buf', nvim('list_wins')[1])) - nvim('command', 'new') - nvim('set_current_win', nvim('list_wins')[2]) - eq(curbuf(), window('get_buf', nvim('list_wins')[2])) - neq(window('get_buf', nvim('list_wins')[1]), window('get_buf', nvim('list_wins')[2])) + eq(curbuf(), meths.nvim_win_get_buf(meths.nvim_list_wins()[1])) + command('new') + meths.nvim_set_current_win(meths.nvim_list_wins()[2]) + eq(curbuf(), meths.nvim_win_get_buf(meths.nvim_list_wins()[2])) + neq( + meths.nvim_win_get_buf(meths.nvim_list_wins()[1]), + meths.nvim_win_get_buf(meths.nvim_list_wins()[2]) + ) end) end) describe('set_buf', function() it('works', function() - nvim('command', 'new') - local windows = nvim('list_wins') - neq(window('get_buf', windows[2]), window('get_buf', windows[1])) - window('set_buf', windows[2], window('get_buf', windows[1])) - eq(window('get_buf', windows[2]), window('get_buf', windows[1])) + command('new') + local windows = meths.nvim_list_wins() + neq(meths.nvim_win_get_buf(windows[2]), meths.nvim_win_get_buf(windows[1])) + meths.nvim_win_set_buf(windows[2], meths.nvim_win_get_buf(windows[1])) + eq(meths.nvim_win_get_buf(windows[2]), meths.nvim_win_get_buf(windows[1])) end) it('validates args', function() - eq('Invalid buffer id: 23', pcall_err(window, 'set_buf', nvim('get_current_win'), 23)) - eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf'))) + eq( + 'Invalid buffer id: 23', + pcall_err(meths.nvim_win_set_buf, meths.nvim_get_current_win(), 23) + ) + eq( + 'Invalid window id: 23', + pcall_err(meths.nvim_win_set_buf, 23, meths.nvim_get_current_buf()) + ) end) it('disallowed in cmdwin if win={old_}curwin or buf=curbuf', function() @@ -84,12 +89,12 @@ describe('API/win', function() describe('{get,set}_cursor', function() it('works', function() - eq({ 1, 0 }, curwin('get_cursor')) - nvim('command', 'normal ityping\027o some text') + eq({ 1, 0 }, meths.nvim_win_get_cursor(0)) + command('normal ityping\027o some text') eq('typing\n some text', curbuf_contents()) - eq({ 2, 10 }, curwin('get_cursor')) - curwin('set_cursor', { 2, 6 }) - nvim('command', 'normal i dumb') + eq({ 2, 10 }, meths.nvim_win_get_cursor(0)) + meths.nvim_win_set_cursor(0, { 2, 6 }) + command('normal i dumb') eq('typing\n some dumb text', curbuf_contents()) end) @@ -119,10 +124,10 @@ describe('API/win', function() ]], } -- cursor position is at beginning - eq({ 1, 0 }, window('get_cursor', win)) + eq({ 1, 0 }, meths.nvim_win_get_cursor(win)) -- move cursor to end - window('set_cursor', win, { 101, 0 }) + meths.nvim_win_set_cursor(win, { 101, 0 }) screen:expect { grid = [[ |*7 @@ -132,7 +137,7 @@ describe('API/win', function() } -- move cursor to the beginning again - window('set_cursor', win, { 1, 0 }) + meths.nvim_win_set_cursor(win, { 1, 0 }) screen:expect { grid = [[ ^prologue | @@ -141,11 +146,11 @@ describe('API/win', function() } -- move focus to new window - nvim('command', 'new') + command('new') neq(win, curwin()) -- sanity check, cursor position is kept - eq({ 1, 0 }, window('get_cursor', win)) + eq({ 1, 0 }, meths.nvim_win_get_cursor(win)) screen:expect { grid = [[ ^ | @@ -159,7 +164,7 @@ describe('API/win', function() } -- move cursor to end - window('set_cursor', win, { 101, 0 }) + meths.nvim_win_set_cursor(win, { 101, 0 }) screen:expect { grid = [[ ^ | @@ -173,7 +178,7 @@ describe('API/win', function() } -- move cursor to the beginning again - window('set_cursor', win, { 1, 0 }) + meths.nvim_win_set_cursor(win, { 1, 0 }) screen:expect { grid = [[ ^ | @@ -200,17 +205,17 @@ describe('API/win', function() -- cursor position is at beginning local win = curwin() - eq({ 1, 0 }, window('get_cursor', win)) + eq({ 1, 0 }, meths.nvim_win_get_cursor(win)) -- move cursor to column 5 - window('set_cursor', win, { 1, 5 }) + meths.nvim_win_set_cursor(win, { 1, 5 }) -- move down a line feed('j') poke_eventloop() -- let nvim process the 'j' command -- cursor is still in column 5 - eq({ 2, 5 }, window('get_cursor', win)) + eq({ 2, 5 }, meths.nvim_win_get_cursor(win)) end) it('updates cursorline and statusline ruler in non-current window', function() @@ -240,7 +245,7 @@ describe('API/win', function() {3:[No Name] [+] 4,3 All }{4:[No Name] [+] 4,3 All}| | ]]) - window('set_cursor', oldwin, { 1, 0 }) + meths.nvim_win_set_cursor(oldwin, { 1, 0 }) screen:expect([[ aaa │{2:aaa }| bbb │bbb | @@ -278,7 +283,7 @@ describe('API/win', function() {3:[No Name] [+] }{4:[No Name] [+] }| | ]]) - window('set_cursor', oldwin, { 2, 0 }) + meths.nvim_win_set_cursor(oldwin, { 2, 0 }) screen:expect([[ aa{2:a} │{2:a}aa | bb{2:b} │bbb | @@ -293,32 +298,35 @@ describe('API/win', function() describe('{get,set}_height', function() it('works', function() - nvim('command', 'vsplit') - eq(window('get_height', nvim('list_wins')[2]), window('get_height', nvim('list_wins')[1])) - nvim('set_current_win', nvim('list_wins')[2]) - nvim('command', 'split') + command('vsplit') + eq( + meths.nvim_win_get_height(meths.nvim_list_wins()[2]), + meths.nvim_win_get_height(meths.nvim_list_wins()[1]) + ) + meths.nvim_set_current_win(meths.nvim_list_wins()[2]) + command('split') eq( - window('get_height', nvim('list_wins')[2]), - math.floor(window('get_height', nvim('list_wins')[1]) / 2) + meths.nvim_win_get_height(meths.nvim_list_wins()[2]), + math.floor(meths.nvim_win_get_height(meths.nvim_list_wins()[1]) / 2) ) - window('set_height', nvim('list_wins')[2], 2) - eq(2, window('get_height', nvim('list_wins')[2])) + meths.nvim_win_set_height(meths.nvim_list_wins()[2], 2) + eq(2, meths.nvim_win_get_height(meths.nvim_list_wins()[2])) end) it('correctly handles height=1', function() - nvim('command', 'split') - nvim('set_current_win', nvim('list_wins')[1]) - window('set_height', nvim('list_wins')[2], 1) - eq(1, window('get_height', nvim('list_wins')[2])) + command('split') + meths.nvim_set_current_win(meths.nvim_list_wins()[1]) + meths.nvim_win_set_height(meths.nvim_list_wins()[2], 1) + eq(1, meths.nvim_win_get_height(meths.nvim_list_wins()[2])) end) it('correctly handles height=1 with a winbar', function() - nvim('command', 'set winbar=foobar') - nvim('command', 'set winminheight=0') - nvim('command', 'split') - nvim('set_current_win', nvim('list_wins')[1]) - window('set_height', nvim('list_wins')[2], 1) - eq(1, window('get_height', nvim('list_wins')[2])) + command('set winbar=foobar') + command('set winminheight=0') + command('split') + meths.nvim_set_current_win(meths.nvim_list_wins()[1]) + meths.nvim_win_set_height(meths.nvim_list_wins()[2], 1) + eq(1, meths.nvim_win_get_height(meths.nvim_list_wins()[2])) end) it('do not cause ml_get errors with foldmethod=expr #19989', function() @@ -340,16 +348,19 @@ describe('API/win', function() describe('{get,set}_width', function() it('works', function() - nvim('command', 'split') - eq(window('get_width', nvim('list_wins')[2]), window('get_width', nvim('list_wins')[1])) - nvim('set_current_win', nvim('list_wins')[2]) - nvim('command', 'vsplit') + command('split') + eq( + meths.nvim_win_get_width(meths.nvim_list_wins()[2]), + meths.nvim_win_get_width(meths.nvim_list_wins()[1]) + ) + meths.nvim_set_current_win(meths.nvim_list_wins()[2]) + command('vsplit') eq( - window('get_width', nvim('list_wins')[2]), - math.floor(window('get_width', nvim('list_wins')[1]) / 2) + meths.nvim_win_get_width(meths.nvim_list_wins()[2]), + math.floor(meths.nvim_win_get_width(meths.nvim_list_wins()[1]) / 2) ) - window('set_width', nvim('list_wins')[2], 2) - eq(2, window('get_width', nvim('list_wins')[2])) + meths.nvim_win_set_width(meths.nvim_list_wins()[2], 2) + eq(2, meths.nvim_win_get_width(meths.nvim_list_wins()[2])) end) it('do not cause ml_get errors with foldmethod=expr #19989', function() @@ -371,17 +382,17 @@ describe('API/win', function() describe('{get,set,del}_var', function() it('works', function() - curwin('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) - eq({ 1, 2, { ['3'] = 1 } }, curwin('get_var', 'lua')) - eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'w:lua')) + meths.nvim_win_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_win_get_var(0, 'lua')) + eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('w:lua')) eq(1, funcs.exists('w:lua')) - curwinmeths.del_var('lua') + meths.nvim_win_del_var(0, 'lua') eq(0, funcs.exists('w:lua')) - eq('Key not found: lua', pcall_err(curwinmeths.del_var, 'lua')) - curwinmeths.set_var('lua', 1) + eq('Key not found: lua', pcall_err(meths.nvim_win_del_var, 0, 'lua')) + meths.nvim_win_set_var(0, 'lua', 1) command('lockvar w:lua') - eq('Key is locked: lua', pcall_err(curwinmeths.del_var, 'lua')) - eq('Key is locked: lua', pcall_err(curwinmeths.set_var, 'lua', 1)) + eq('Key is locked: lua', pcall_err(meths.nvim_win_del_var, 0, 'lua')) + eq('Key is locked: lua', pcall_err(meths.nvim_win_set_var, 0, 'lua', 1)) end) it('window_set_var returns the old value', function() @@ -402,51 +413,51 @@ describe('API/win', function() describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - nvim('set_option_value', 'colorcolumn', '4,3', {}) - eq('4,3', nvim('get_option_value', 'colorcolumn', {})) + meths.nvim_set_option_value('colorcolumn', '4,3', {}) + eq('4,3', meths.nvim_get_option_value('colorcolumn', {})) command('set modified hidden') command('enew') -- edit new buffer, window option is preserved - eq('4,3', nvim('get_option_value', 'colorcolumn', {})) + eq('4,3', meths.nvim_get_option_value('colorcolumn', {})) -- global-local option - nvim('set_option_value', 'statusline', 'window-status', { win = 0 }) - eq('window-status', nvim('get_option_value', 'statusline', { win = 0 })) - eq('', nvim('get_option_value', 'statusline', { scope = 'global' })) + meths.nvim_set_option_value('statusline', 'window-status', { win = 0 }) + eq('window-status', meths.nvim_get_option_value('statusline', { win = 0 })) + eq('', meths.nvim_get_option_value('statusline', { scope = 'global' })) command('set modified') command('enew') -- global-local: not preserved in new buffer -- confirm local value was not copied - eq('', nvim('get_option_value', 'statusline', { win = 0 })) + eq('', meths.nvim_get_option_value('statusline', { win = 0 })) eq('', eval('&l:statusline')) end) it('after switching windows #15390', function() - nvim('command', 'tabnew') - local tab1 = unpack(nvim('list_tabpages')) - local win1 = unpack(tabpage('list_wins', tab1)) - nvim('set_option_value', 'statusline', 'window-status', { win = win1.id }) - nvim('command', 'split') - nvim('command', 'wincmd J') - nvim('command', 'wincmd j') - eq('window-status', nvim('get_option_value', 'statusline', { win = win1.id })) + command('tabnew') + local tab1 = unpack(meths.nvim_list_tabpages()) + local win1 = unpack(meths.nvim_tabpage_list_wins(tab1)) + meths.nvim_set_option_value('statusline', 'window-status', { win = win1.id }) + command('split') + command('wincmd J') + command('wincmd j') + eq('window-status', meths.nvim_get_option_value('statusline', { win = win1.id })) assert_alive() end) it('returns values for unset local options', function() - eq(-1, nvim('get_option_value', 'scrolloff', { win = 0, scope = 'local' })) + eq(-1, meths.nvim_get_option_value('scrolloff', { win = 0, scope = 'local' })) end) end) describe('get_position', function() it('works', function() - local height = window('get_height', nvim('list_wins')[1]) - local width = window('get_width', nvim('list_wins')[1]) - nvim('command', 'split') - nvim('command', 'vsplit') - eq({ 0, 0 }, window('get_position', nvim('list_wins')[1])) + local height = meths.nvim_win_get_height(meths.nvim_list_wins()[1]) + local width = meths.nvim_win_get_width(meths.nvim_list_wins()[1]) + command('split') + command('vsplit') + eq({ 0, 0 }, meths.nvim_win_get_position(meths.nvim_list_wins()[1])) local vsplit_pos = math.floor(width / 2) local split_pos = math.floor(height / 2) - local win2row, win2col = unpack(window('get_position', nvim('list_wins')[2])) - local win3row, win3col = unpack(window('get_position', nvim('list_wins')[3])) + local win2row, win2col = unpack(meths.nvim_win_get_position(meths.nvim_list_wins()[2])) + local win3row, win3col = unpack(meths.nvim_win_get_position(meths.nvim_list_wins()[3])) eq(0, win2row) eq(0, win3col) ok(vsplit_pos - 1 <= win2col and win2col <= vsplit_pos + 1) @@ -456,46 +467,46 @@ describe('API/win', function() describe('get_position', function() it('works', function() - nvim('command', 'tabnew') - nvim('command', 'vsplit') - eq(window('get_tabpage', nvim('list_wins')[1]), nvim('list_tabpages')[1]) - eq(window('get_tabpage', nvim('list_wins')[2]), nvim('list_tabpages')[2]) - eq(window('get_tabpage', nvim('list_wins')[3]), nvim('list_tabpages')[2]) + command('tabnew') + command('vsplit') + eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[1]), meths.nvim_list_tabpages()[1]) + eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[2]), meths.nvim_list_tabpages()[2]) + eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[3]), meths.nvim_list_tabpages()[2]) end) end) describe('get_number', function() it('works', function() - local wins = nvim('list_wins') - eq(1, window('get_number', wins[1])) + local wins = meths.nvim_list_wins() + eq(1, meths.nvim_win_get_number(wins[1])) - nvim('command', 'split') - local win1, win2 = unpack(nvim('list_wins')) - eq(1, window('get_number', win1)) - eq(2, window('get_number', win2)) + command('split') + local win1, win2 = unpack(meths.nvim_list_wins()) + eq(1, meths.nvim_win_get_number(win1)) + eq(2, meths.nvim_win_get_number(win2)) - nvim('command', 'wincmd J') - eq(2, window('get_number', win1)) - eq(1, window('get_number', win2)) + command('wincmd J') + eq(2, meths.nvim_win_get_number(win1)) + eq(1, meths.nvim_win_get_number(win2)) - nvim('command', 'tabnew') - local win3 = nvim('list_wins')[3] + command('tabnew') + local win3 = meths.nvim_list_wins()[3] -- First tab page - eq(2, window('get_number', win1)) - eq(1, window('get_number', win2)) + eq(2, meths.nvim_win_get_number(win1)) + eq(1, meths.nvim_win_get_number(win2)) -- Second tab page - eq(1, window('get_number', win3)) + eq(1, meths.nvim_win_get_number(win3)) end) end) describe('is_valid', function() it('works', function() - nvim('command', 'split') - local win = nvim('list_wins')[2] - nvim('set_current_win', win) - ok(window('is_valid', win)) - nvim('command', 'close') - ok(not window('is_valid', win)) + command('split') + local win = meths.nvim_list_wins()[2] + meths.nvim_set_current_win(win) + ok(meths.nvim_win_is_valid(win)) + command('close') + ok(not meths.nvim_win_is_valid(win)) end) end) @@ -671,42 +682,43 @@ describe('API/win', function() ddd eee]]) eq('Invalid window id: 23', pcall_err(meths.nvim_win_text_height, 23, {})) - eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { start_row = 5 })) - eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { start_row = -6 })) - eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { end_row = 5 })) - eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { end_row = -6 })) + eq('Line index out of bounds', pcall_err(meths.nvim_win_text_height, 0, { start_row = 5 })) + eq('Line index out of bounds', pcall_err(meths.nvim_win_text_height, 0, { start_row = -6 })) + eq('Line index out of bounds', pcall_err(meths.nvim_win_text_height, 0, { end_row = 5 })) + eq('Line index out of bounds', pcall_err(meths.nvim_win_text_height, 0, { end_row = -6 })) eq( "'start_row' is higher than 'end_row'", - pcall_err(curwinmeths.text_height, { start_row = 3, end_row = 1 }) + pcall_err(meths.nvim_win_text_height, 0, { start_row = 3, end_row = 1 }) ) eq( "'start_vcol' specified without 'start_row'", - pcall_err(curwinmeths.text_height, { end_row = 2, start_vcol = 0 }) + pcall_err(meths.nvim_win_text_height, 0, { end_row = 2, start_vcol = 0 }) ) eq( "'end_vcol' specified without 'end_row'", - pcall_err(curwinmeths.text_height, { start_row = 2, end_vcol = 0 }) + pcall_err(meths.nvim_win_text_height, 0, { start_row = 2, end_vcol = 0 }) ) eq( "Invalid 'start_vcol': out of range", - pcall_err(curwinmeths.text_height, { start_row = 2, start_vcol = -1 }) + pcall_err(meths.nvim_win_text_height, 0, { start_row = 2, start_vcol = -1 }) ) eq( "Invalid 'start_vcol': out of range", - pcall_err(curwinmeths.text_height, { start_row = 2, start_vcol = X + 1 }) + pcall_err(meths.nvim_win_text_height, 0, { start_row = 2, start_vcol = X + 1 }) ) eq( "Invalid 'end_vcol': out of range", - pcall_err(curwinmeths.text_height, { end_row = 2, end_vcol = -1 }) + pcall_err(meths.nvim_win_text_height, 0, { end_row = 2, end_vcol = -1 }) ) eq( "Invalid 'end_vcol': out of range", - pcall_err(curwinmeths.text_height, { end_row = 2, end_vcol = X + 1 }) + pcall_err(meths.nvim_win_text_height, 0, { end_row = 2, end_vcol = X + 1 }) ) eq( "'start_vcol' is higher than 'end_vcol'", pcall_err( - curwinmeths.text_height, + meths.nvim_win_text_height, + 0, { start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 } ) ) |