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 | |
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
79 files changed, 1701 insertions, 1754 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 } ) ) diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 5088ef8031..9ed3c5fbad 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -17,7 +17,6 @@ local expect = helpers.expect local command = helpers.command local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua -local curbufmeths = helpers.curbufmeths local retry = helpers.retry local source = helpers.source @@ -144,7 +143,7 @@ describe('autocmd', function() describe('BufLeave autocommand', function() it('can wipe out the buffer created by :edit which triggered autocmd', function() meths.nvim_set_option_value('hidden', true, {}) - curbufmeths.set_lines(0, 1, false, { + meths.nvim_buf_set_lines(0, 0, 1, false, { 'start of test file xx', 'end of test file xx', }) diff --git a/test/functional/autocmd/searchwrapped_spec.lua b/test/functional/autocmd/searchwrapped_spec.lua index 83600f6689..8d25106680 100644 --- a/test/functional/autocmd/searchwrapped_spec.lua +++ b/test/functional/autocmd/searchwrapped_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command -local curbufmeths = helpers.curbufmeths +local meths = helpers.meths local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed @@ -13,7 +13,7 @@ describe('autocmd SearchWrapped', function() command('set ignorecase') command('let g:test = 0') command('autocmd! SearchWrapped * let g:test += 1') - curbufmeths.set_lines(0, 1, false, { + meths.nvim_buf_set_lines(0, 0, 1, false, { 'The quick brown fox', 'jumps over the lazy dog', }) diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua index c5a2b42273..34f5178158 100644 --- a/test/functional/autocmd/tabclose_spec.lua +++ b/test/functional/autocmd/tabclose_spec.lua @@ -1,5 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq +local clear, eq = helpers.clear, helpers.eq +local meths = helpers.meths +local command = helpers.command describe('TabClosed', function() before_each(clear) @@ -7,75 +9,70 @@ describe('TabClosed', function() describe('au TabClosed', function() describe('with * as <afile>', function() it('matches when closing any tab', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) repeat - nvim('command', 'tabnew') - until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6 - eq('tabclosed:6:6:5', nvim('exec', 'tabclose', true)) -- close last 6, current tab is now 5 - eq('tabclosed:5:5:4', nvim('exec', 'close', true)) -- close last window on tab, closes tab - eq('tabclosed:2:2:3', nvim('exec', '2tabclose', true)) -- close tab 2, current tab is now 3 - eq('tabclosed:1:1:2\ntabclosed:1:1:1', nvim('exec', 'tabonly', true)) -- close tabs 1 and 2 + command('tabnew') + until meths.nvim_eval('tabpagenr()') == 6 -- current tab is now 6 + eq('tabclosed:6:6:5', meths.nvim_exec('tabclose', true)) -- close last 6, current tab is now 5 + eq('tabclosed:5:5:4', meths.nvim_exec('close', true)) -- close last window on tab, closes tab + eq('tabclosed:2:2:3', meths.nvim_exec('2tabclose', true)) -- close tab 2, current tab is now 3 + eq('tabclosed:1:1:2\ntabclosed:1:1:1', meths.nvim_exec('tabonly', true)) -- close tabs 1 and 2 end) it('is triggered when closing a window via bdelete from another tab', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) - nvim('command', '1tabedit Xtestfile') - nvim('command', '1tabedit Xtestfile') - nvim('command', 'normal! 1gt') - eq({ 1, 3 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq('tabclosed:2:2:1\ntabclosed:2:2:1', nvim('exec', 'bdelete Xtestfile', true)) - eq({ 1, 1 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + command('1tabedit Xtestfile') + command('1tabedit Xtestfile') + command('normal! 1gt') + eq({ 1, 3 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:1\ntabclosed:2:2:1', meths.nvim_exec('bdelete Xtestfile', true)) + eq({ 1, 1 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) end) it('is triggered when closing a window via bdelete from current tab', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) - nvim('command', 'file Xtestfile1') - nvim('command', '1tabedit Xtestfile2') - nvim('command', '1tabedit Xtestfile2') + command('file Xtestfile1') + command('1tabedit Xtestfile2') + command('1tabedit Xtestfile2') -- Only one tab is closed, and the alternate file is used for the other. - eq({ 2, 3 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq('tabclosed:2:2:2', nvim('exec', 'bdelete Xtestfile2', true)) - eq('Xtestfile1', nvim('eval', 'bufname("")')) + eq({ 2, 3 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:2', meths.nvim_exec('bdelete Xtestfile2', true)) + eq('Xtestfile1', meths.nvim_eval('bufname("")')) end) end) describe('with NR as <afile>', function() it('matches when closing a tab whose index is NR', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) - nvim('command', 'au! TabClosed 2 echom "tabclosed:match"') + command('au! TabClosed 2 echom "tabclosed:match"') repeat - nvim('command', 'tabnew') - until nvim('eval', 'tabpagenr()') == 7 -- current tab is now 7 + command('tabnew') + until meths.nvim_eval('tabpagenr()') == 7 -- current tab is now 7 -- sanity check, we shouldn't match on tabs with numbers other than 2 - eq('tabclosed:7:7:6', nvim('exec', 'tabclose', true)) + eq('tabclosed:7:7:6', meths.nvim_exec('tabclose', true)) -- close tab page 2, current tab is now 5 - eq('tabclosed:2:2:5\ntabclosed:match', nvim('exec', '2tabclose', true)) + eq('tabclosed:2:2:5\ntabclosed:match', meths.nvim_exec('2tabclose', true)) end) end) describe('with close', function() it('is triggered', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) - nvim('command', 'tabedit Xtestfile') - eq({ 2, 2 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq('tabclosed:2:2:1', nvim('exec', 'close', true)) - eq({ 1, 1 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + command('tabedit Xtestfile') + eq({ 2, 2 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:1', meths.nvim_exec('close', true)) + eq({ 1, 1 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) end) end) end) diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua index fd4a16a298..cdde9ad247 100644 --- a/test/functional/autocmd/tabnewentered_spec.lua +++ b/test/functional/autocmd/tabnewentered_spec.lua @@ -6,7 +6,7 @@ local dedent = helpers.dedent local eval = helpers.eval local eq = helpers.eq local feed = helpers.feed -local nvim = helpers.nvim +local meths = helpers.meths local exec_capture = helpers.exec_capture describe('TabNewEntered', function() @@ -14,33 +14,33 @@ describe('TabNewEntered', function() describe('with * as <afile>', function() it('matches when entering any new tab', function() clear() - nvim('command', 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")') - eq('tabnewentered:2:2', nvim('exec', 'tabnew', true)) - eq('tabnewentered:3:3', nvim('exec', 'tabnew test.x2', true)) + command('au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")') + eq('tabnewentered:2:2', meths.nvim_exec('tabnew', true)) + eq('tabnewentered:3:3', meths.nvim_exec('tabnew test.x2', true)) end) end) describe('with FILE as <afile>', function() it('matches when opening a new tab for FILE', function() clear() - nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"') - eq('tabnewentered:match', nvim('exec', 'tabnew Xtest-tabnewentered', true)) + command('au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"') + eq('tabnewentered:match', meths.nvim_exec('tabnew Xtest-tabnewentered', true)) end) end) describe('with CTRL-W T', function() it('works when opening a new tab with CTRL-W T', function() clear() - nvim('command', 'au! TabNewEntered * echom "entered"') - nvim('command', 'tabnew test.x2') - nvim('command', 'split') - eq('entered', nvim('exec', 'execute "normal \\<C-W>T"', true)) + command('au! TabNewEntered * echom "entered"') + command('tabnew test.x2') + command('split') + eq('entered', meths.nvim_exec('execute "normal \\<C-W>T"', true)) end) end) describe('with tab split #4334', function() it('works when create a tab by using tab split command', function() clear() - nvim('command', 'au! TabNewEntered * let b:entered = "entered"') - nvim('command', 'tab split') - eq('entered', nvim('exec', 'echo b:entered', true)) + command('au! TabNewEntered * let b:entered = "entered"') + command('tab split') + eq('entered', meths.nvim_exec('echo b:entered', true)) end) end) end) @@ -50,20 +50,20 @@ describe('TabEnter', function() before_each(clear) it('has correct previous tab when entering any new tab', function() command('augroup TEMP') - nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') + command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') command('augroup END') - eq('tabenter:2:1', nvim('exec', 'tabnew', true)) - eq('tabenter:3:2', nvim('exec', 'tabnew test.x2', true)) + eq('tabenter:2:1', meths.nvim_exec('tabnew', true)) + eq('tabenter:3:2', meths.nvim_exec('tabnew test.x2', true)) command('augroup! TEMP') end) it('has correct previous tab when entering any preexisting tab', function() command('tabnew') command('tabnew') command('augroup TEMP') - nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') + command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') command('augroup END') - eq('tabenter:1:3', nvim('exec', 'tabnext', true)) - eq('tabenter:2:1', nvim('exec', 'tabnext', true)) + eq('tabenter:1:3', meths.nvim_exec('tabnext', true)) + eq('tabenter:2:1', meths.nvim_exec('tabnext', true)) command('augroup! TEMP') end) end) diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index caa7209de1..0243fdf600 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -2,7 +2,7 @@ local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, command, nvim, testprg = helpers.clear, helpers.command, helpers.nvim, helpers.testprg +local clear, command, testprg = helpers.clear, helpers.command, helpers.testprg local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry local matches = helpers.matches local ok = helpers.ok @@ -16,13 +16,13 @@ local is_os = helpers.is_os describe('autocmd TermClose', function() before_each(function() clear() - nvim('set_option_value', 'shell', testprg('shell-test'), {}) + meths.nvim_set_option_value('shell', testprg('shell-test'), {}) command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') end) local function test_termclose_delete_own_buf() -- The terminal process needs to keep running so that TermClose isn't triggered immediately. - nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) + meths.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) command('autocmd TermClose * bdelete!') command('terminal') matches( @@ -56,7 +56,7 @@ describe('autocmd TermClose', function() it('triggers when long-running terminal job gets stopped', function() skip(is_os('win')) - nvim('set_option_value', 'shell', is_os('win') and 'cmd.exe' or 'sh', {}) + meths.nvim_set_option_value('shell', is_os('win') and 'cmd.exe' or 'sh', {}) command('autocmd TermClose * let g:test_termclose = 23') command('terminal') command('call jobstop(b:terminal_job_id)') @@ -67,8 +67,8 @@ describe('autocmd TermClose', function() it('kills job trapping SIGTERM', function() skip(is_os('win')) - nvim('set_option_value', 'shell', 'sh', {}) - nvim('set_option_value', 'shellcmdflag', '-c', {}) + meths.nvim_set_option_value('shell', 'sh', {}) + meths.nvim_set_option_value('shellcmdflag', '-c', {}) command( [[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] @@ -93,8 +93,8 @@ describe('autocmd TermClose', function() it('kills PTY job trapping SIGHUP and SIGTERM', function() skip(is_os('win')) - nvim('set_option_value', 'shell', 'sh', {}) - nvim('set_option_value', 'shellcmdflag', '-c', {}) + meths.nvim_set_option_value('shell', 'sh', {}) + meths.nvim_set_option_value('shellcmdflag', '-c', {}) command( [[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] .. [[ 'pty': 1,]] diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua index 4250c54834..964b5c0be4 100644 --- a/test/functional/autocmd/textyankpost_spec.lua +++ b/test/functional/autocmd/textyankpost_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq local feed, command, expect = helpers.feed, helpers.command, helpers.expect -local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq +local meths, funcs, neq = helpers.meths, helpers.funcs, helpers.neq describe('TextYankPost', function() before_each(function() @@ -14,7 +14,7 @@ describe('TextYankPost', function() command('autocmd TextYankPost * let g:event = copy(v:event)') command('autocmd TextYankPost * let g:count += 1') - curbufmeths.set_lines(0, -1, true, { + meths.nvim_buf_set_lines(0, 0, -1, true, { 'foo\0bar', 'baz text', }) diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index 2c3ebf62aa..9ae2150f84 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -18,7 +18,7 @@ describe('v:exiting', function() before_each(function() helpers.clear() - cid = helpers.nvim('get_api_info')[1] + cid = helpers.meths.nvim_get_api_info()[1] end) it('defaults to v:null', function() diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 5d5be2851b..c0a838ed92 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -10,7 +10,6 @@ local feed = helpers.feed local insert = helpers.insert local neq = helpers.neq local next_msg = helpers.next_msg -local nvim = helpers.nvim local testprg = helpers.testprg local ok = helpers.ok local source = helpers.source @@ -43,8 +42,8 @@ describe('jobs', function() before_each(function() clear() - channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + channel = meths.nvim_get_api_info()[1] + meths.nvim_set_var('channel', channel) source([[ function! Normalize(data) abort " Windows: remove ^M and term escape sequences @@ -69,22 +68,22 @@ describe('jobs', function() command('let g:job_opts.env = v:true') local _, err = pcall(function() if is_os('win') then - nvim('command', "let j = jobstart('set', g:job_opts)") + command("let j = jobstart('set', g:job_opts)") else - nvim('command', "let j = jobstart('env', g:job_opts)") + command("let j = jobstart('env', g:job_opts)") end end) ok(string.find(err, 'E475: Invalid argument: env') ~= nil) end) it('append environment #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command("let g:job_opts.env = {'TOTO': 'hello world'}") if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) end expect_msg_seq({ @@ -97,14 +96,14 @@ describe('jobs', function() end) it('append environment with pty #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', 'let g:job_opts.pty = v:true') - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command('let g:job_opts.pty = v:true') + command("let g:job_opts.env = {'TOTO': 'hello world'}") if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) end expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world abc' } } }, @@ -116,10 +115,10 @@ describe('jobs', function() end) it('replace environment #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") - nvim('command', 'let g:job_opts.clear_env = 1') + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command("let g:job_opts.env = {'TOTO': 'hello world'}") + command('let g:job_opts.clear_env = 1') -- libuv ensures that certain "required" environment variables are -- preserved if the user doesn't provide them in a custom environment @@ -129,13 +128,13 @@ describe('jobs', function() -- Rather than expecting a completely empty environment, ensure that $VAR -- is *not* in the environment but $TOTO is. if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world %VAR%', '' } } }, }) else - nvim('command', 'set shell=/bin/sh') - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command('set shell=/bin/sh') + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world', '' } } }, }) @@ -143,17 +142,17 @@ describe('jobs', function() end) it('handles case-insensitively matching #env vars', function() - nvim('command', "let $TOTO = 'abc'") + command("let $TOTO = 'abc'") -- Since $Toto is being set in the job, it should take precedence over the -- global $TOTO on Windows - nvim('command', "let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") + command("let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") if is_os('win') then - nvim('command', [[let j = jobstart('set | find /I "toto="', g:job_opts)]]) + command([[let j = jobstart('set | find /I "toto="', g:job_opts)]]) else - nvim('command', [[let j = jobstart('env | grep -i toto=', g:job_opts)]]) + command([[let j = jobstart('env | grep -i toto=', g:job_opts)]]) end - nvim('command', 'call jobwait([j])') - nvim('command', 'let g:output = Normalize(g:job_opts.stdout)') + command('call jobwait([j])') + command('let g:output = Normalize(g:job_opts.stdout)') local actual = eval('g:output') local expected if is_os('win') then @@ -169,11 +168,11 @@ describe('jobs', function() end) it('uses &shell and &shellcmdflag if passed a string', function() - nvim('command', "let $VAR = 'abc'") + command("let $VAR = 'abc'") if is_os('win') then - nvim('command', "let j = jobstart('echo %VAR%', g:job_opts)") + command("let j = jobstart('echo %VAR%', g:job_opts)") else - nvim('command', "let j = jobstart('echo $VAR', g:job_opts)") + command("let j = jobstart('echo $VAR', g:job_opts)") end eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) @@ -181,11 +180,11 @@ describe('jobs', function() end) it('changes to given / directory', function() - nvim('command', "let g:job_opts.cwd = '/'") + command("let g:job_opts.cwd = '/'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end eq({ 'notification', 'stdout', { 0, { pathroot(), '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) @@ -195,11 +194,11 @@ describe('jobs', function() it('changes to given `cwd` directory', function() local dir = eval('resolve(tempname())'):gsub('/', get_pathsep()) mkdir(dir) - nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") + command("let g:job_opts.cwd = '" .. dir .. "'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end expect_msg_seq( { @@ -221,11 +220,11 @@ describe('jobs', function() it('fails to change to invalid `cwd`', function() local dir = eval('resolve(tempname())."-bogus"') local _, err = pcall(function() - nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") + command("let g:job_opts.cwd = '" .. dir .. "'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end end) ok(string.find(err, 'E475: Invalid argument: expected valid directory$') ~= nil) @@ -239,7 +238,7 @@ describe('jobs', function() funcs.setfperm(dir, 'rw-------') matches( '^Vim%(call%):E903: Process failed to start: permission denied: .*', - pcall_err(nvim, 'command', "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") + pcall_err(command, "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") ) rmdir(dir) end) @@ -269,8 +268,8 @@ describe('jobs', function() end) it('invokes callbacks when the job writes and exits', function() - nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") - nvim('command', [[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]]) + command("let g:job_opts.on_stderr = function('OnEvent')") + command([[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]]) expect_twostreams({ { 'notification', 'stdout', { 0, { '', '' } } }, { 'notification', 'stdout', { 0, { '' } } }, @@ -279,11 +278,11 @@ describe('jobs', function() end) it('interactive commands', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) - nvim('command', 'call jobsend(j, "abc\\n")') + command('call jobsend(j, "abc\\n")') eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) - nvim('command', 'call jobsend(j, "123\\nxyz\\n")') + command('call jobsend(j, "123\\nxyz\\n")') expect_msg_seq( { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, -- Alternative sequence: @@ -292,7 +291,7 @@ describe('jobs', function() { 'notification', 'stdout', { 0, { 'xyz', '' } } }, } ) - nvim('command', 'call jobsend(j, [123, "xyz", ""])') + command('call jobsend(j, [123, "xyz", ""])') expect_msg_seq( { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, -- Alternative sequence: @@ -301,7 +300,7 @@ describe('jobs', function() { 'notification', 'stdout', { 0, { 'xyz', '' } } }, } ) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) @@ -311,75 +310,75 @@ describe('jobs', function() local filename = helpers.tmpname() write_file(filename, 'abc\0def\n') - nvim('command', "let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") + command("let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") eq({ 'notification', 'stdout', { 0, { 'abc\ndef', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) os.remove(filename) -- jobsend() preserves NULs. - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', [[call jobsend(j, ["123\n456",""])]]) + command("let j = jobstart(['cat', '-'], g:job_opts)") + command([[call jobsend(j, ["123\n456",""])]]) eq({ 'notification', 'stdout', { 0, { '123\n456', '' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') end) it('emits partial lines (does NOT buffer data lacking newlines)', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, "abc\\nxyz")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, "abc\\nxyz")') eq({ 'notification', 'stdout', { 0, { 'abc', 'xyz' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('preserves newlines', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') eq({ 'notification', 'stdout', { 0, { 'a', '', 'c', '', '', '', 'b', '', '' } } }, next_msg()) end) it('preserves NULs', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') eq({ 'notification', 'stdout', { 0, { '\n123\n', 'abc\nxyz\n', '' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('avoids sending final newline', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, ["some data", "without\nfinal nl"])') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, ["some data", "without\nfinal nl"])') eq({ 'notification', 'stdout', { 0, { 'some data', 'without\nfinal nl' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('closes the job streams with jobclose', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobclose(j, "stdin")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobclose(j, "stdin")') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) it('disallows jobsend on a job that closed stdin', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobclose(j, "stdin")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobclose(j, "stdin")') eq( false, pcall(function() - nvim('command', 'call jobsend(j, ["some data"])') + command('call jobsend(j, ["some data"])') end) ) command("let g:job_opts.stdin = 'null'") - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") eq( false, pcall(function() - nvim('command', 'call jobsend(j, ["some data"])') + command('call jobsend(j, ["some data"])') end) ) end) @@ -390,21 +389,21 @@ describe('jobs', function() end) it('jobstop twice on the stopped or exited job return 0', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) eq(1, eval('jobstop(j)')) eq(0, eval('jobstop(j)')) end) it('will not leak memory if we leave a job running', function() - nvim('command', "call jobstart(['cat', '-'], g:job_opts)") + command("call jobstart(['cat', '-'], g:job_opts)") end) it('can get the pid value using getpid', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") local pid = eval('jobpid(j)') neq(NIL, meths.nvim_get_proc(pid)) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq(NIL, meths.nvim_get_proc(pid)) @@ -412,8 +411,7 @@ describe('jobs', function() it('disposed on Nvim exit', function() -- use sleep, which doesn't die on stdin close - nvim( - 'command', + command( "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" ) local pid = eval('jobpid(g:j)') @@ -423,9 +421,8 @@ describe('jobs', function() end) it('can survive the exit of nvim with "detach"', function() - nvim('command', 'let g:job_opts.detach = 1') - nvim( - 'command', + command('let g:job_opts.detach = 1') + command( "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" ) local pid = eval('jobpid(g:j)') @@ -437,8 +434,8 @@ describe('jobs', function() end) it('can pass user data to the callback', function() - nvim('command', 'let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') + command([[call jobstart('echo foo', g:job_opts)]]) local data = { n = 5, s = 'str', l = { 1 } } expect_msg_seq( { @@ -456,16 +453,16 @@ describe('jobs', function() end) it('can omit data callbacks', function() - nvim('command', 'unlet g:job_opts.on_stdout') - nvim('command', 'let g:job_opts.user = 5') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('unlet g:job_opts.on_stdout') + command('let g:job_opts.user = 5') + command([[call jobstart('echo foo', g:job_opts)]]) eq({ 'notification', 'exit', { 5, 0 } }, next_msg()) end) it('can omit exit callback', function() - nvim('command', 'unlet g:job_opts.on_exit') - nvim('command', 'let g:job_opts.user = 5') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('unlet g:job_opts.on_exit') + command('let g:job_opts.user = 5') + command([[call jobstart('echo foo', g:job_opts)]]) expect_msg_seq( { { 'notification', 'stdout', { 5, { 'foo', '' } } }, @@ -481,8 +478,8 @@ describe('jobs', function() end) it('will pass return code with the exit event', function() - nvim('command', 'let g:job_opts.user = 5') - nvim('command', "call jobstart('exit 55', g:job_opts)") + command('let g:job_opts.user = 5') + command("call jobstart('exit 55', g:job_opts)") eq({ 'notification', 'stdout', { 5, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 5, 55 } }, next_msg()) end) @@ -883,7 +880,7 @@ describe('jobs', function() r = next_msg() eq('job ' .. i .. ' exited', r[3][1]) end - eq(10, nvim('eval', 'g:counter')) + eq(10, meths.nvim_eval('g:counter')) end) describe('with timeout argument', function() @@ -953,10 +950,10 @@ describe('jobs', function() end) pending('exit event follows stdout, stderr', function() - nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('eval', 'jobsend(j, "abcdef")') - nvim('eval', 'jobstop(j)') + command("let g:job_opts.on_stderr = function('OnEvent')") + command("let j = jobstart(['cat', '-'], g:job_opts)") + meths.nvim_eval('jobsend(j, "abcdef")') + meths.nvim_eval('jobstop(j)') expect_msg_seq( { { 'notification', 'stdout', { 0, { 'abcdef' } } }, @@ -1099,7 +1096,7 @@ describe('jobs', function() end) it('jobstop on same id before stopped', function() - nvim('command', 'let j = jobstart(["cat", "-"], g:job_opts)') + command('let j = jobstart(["cat", "-"], g:job_opts)') neq(0, eval('j')) eq({ 1, 0 }, eval('[jobstop(j), jobstop(j)]')) @@ -1140,9 +1137,9 @@ describe('jobs', function() endfunction ]]) insert(testprg('tty-test')) - nvim('command', 'let g:job_opts.pty = 1') - nvim('command', 'let exec = [expand("<cfile>:p")]') - nvim('command', 'let j = jobstart(exec, g:job_opts)') + command('let g:job_opts.pty = 1') + command('let exec = [expand("<cfile>:p")]') + command('let j = jobstart(exec, g:job_opts)') j = eval 'j' eq('tty ready', next_chunk()) end) @@ -1153,14 +1150,14 @@ describe('jobs', function() end) it('resizing window', function() - nvim('command', 'call jobresize(j, 40, 10)') + command('call jobresize(j, 40, 10)') eq('rows: 10, cols: 40', next_chunk()) - nvim('command', 'call jobresize(j, 10, 40)') + command('call jobresize(j, 10, 40)') eq('rows: 40, cols: 10', next_chunk()) end) it('jobclose() sends SIGHUP', function() - nvim('command', 'call jobclose(j)') + command('call jobclose(j)') local msg = next_msg() msg = (msg[2] == 'stdout') and next_msg() or msg -- Skip stdout, if any. eq({ 'notification', 'exit', { 0, 42 } }, msg) diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 2e1d36202d..f683884292 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -5,7 +5,6 @@ local clear, feed = helpers.clear, helpers.feed local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq local feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect local funcs = helpers.funcs -local curbufmeths = helpers.curbufmeths local command = helpers.command local meths = helpers.meths local poke_eventloop = helpers.poke_eventloop @@ -928,7 +927,7 @@ describe('completion', function() end) it('CompleteChanged autocommand', function() - curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar', '' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'foobar', '' }) source([[ set complete=. completeopt=noinsert,noselect,menuone function! OnPumChange() diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua index e063924018..8787fd60f1 100644 --- a/test/functional/editor/jump_spec.lua +++ b/test/functional/editor/jump_spec.lua @@ -8,7 +8,7 @@ local funcs = helpers.funcs local feed = helpers.feed local exec_capture = helpers.exec_capture local write_file = helpers.write_file -local curbufmeths = helpers.curbufmeths +local meths = helpers.meths describe('jumplist', function() local fname1 = 'Xtest-functional-normal-jump' @@ -284,7 +284,7 @@ describe('jumpoptions=view', function() screen:attach() command('edit ' .. file1) feed('7GzbG') - curbufmeths.set_lines(0, 2, true, {}) + meths.nvim_buf_set_lines(0, 0, 2, true, {}) -- Move to line 7, and set it as the last line visible on the view with zb, meaning to recover -- the view it needs to put the cursor 7 lines from the top line. Then go to the end of the -- file, delete 2 lines before line 7, meaning the jump/mark is moved 2 lines up to line 5. diff --git a/test/functional/editor/langmap_spec.lua b/test/functional/editor/langmap_spec.lua index e697140889..5ad81ce5c2 100644 --- a/test/functional/editor/langmap_spec.lua +++ b/test/functional/editor/langmap_spec.lua @@ -4,7 +4,7 @@ local eq, neq, call = helpers.eq, helpers.neq, helpers.call local eval, feed, clear = helpers.eval, helpers.feed, helpers.clear local command, insert, expect = helpers.command, helpers.insert, helpers.expect local feed_command = helpers.feed_command -local curwin = helpers.curwin +local curwin = helpers.meths.nvim_get_current_win describe("'langmap'", function() before_each(function() diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua index ceaa01344c..1d2df8ce70 100644 --- a/test/functional/editor/macro_spec.lua +++ b/test/functional/editor/macro_spec.lua @@ -9,7 +9,6 @@ local command = helpers.command local funcs = helpers.funcs local meths = helpers.meths local insert = helpers.insert -local curbufmeths = helpers.curbufmeths describe('macros', function() before_each(function() @@ -41,16 +40,19 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>q]] - eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[Q]] - eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOOFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[G3Q]] - eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[ggV3jQ]] - eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) + eq( + { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, + meths.nvim_buf_get_lines(0, 0, -1, false) + ) end) it('can be replayed with @', function() @@ -60,16 +62,19 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>q]] - eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[Q]] - eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOOFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[G3@@]] - eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[ggV2j@@]] - eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) + eq( + { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, + meths.nvim_buf_get_lines(0, 0, -1, false) + ) end) it('can be replayed with @q and @w', function() @@ -79,17 +84,17 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[qwA123<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[V3j@q]] - eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[gg]] feed [[Vj@w]] - eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) end) it('can be replayed with @q and @w visual-block', function() @@ -99,17 +104,17 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[qwA123<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[<C-v>3j@q]] - eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) feed [[gg]] feed [[<C-v>j@w]] - eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) end) end) diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 266b5194ee..67234b9b90 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -1,7 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local meths = helpers.meths -local curbufmeths = helpers.curbufmeths local clear = helpers.clear local command = helpers.command local funcs = helpers.funcs @@ -29,13 +28,13 @@ describe('named marks', function() it('can be set', function() command('edit ' .. file1) command('mark a') - eq({ 1, 0 }, curbufmeths.get_mark('a')) + eq({ 1, 0 }, meths.nvim_buf_get_mark(0, 'a')) feed('jmb') - eq({ 2, 0 }, curbufmeths.get_mark('b')) + eq({ 2, 0 }, meths.nvim_buf_get_mark(0, 'b')) feed('jmB') - eq({ 3, 0 }, curbufmeths.get_mark('B')) + eq({ 3, 0 }, meths.nvim_buf_get_mark(0, 'B')) command('4kc') - eq({ 4, 0 }, curbufmeths.get_mark('c')) + eq({ 4, 0 }, meths.nvim_buf_get_mark(0, 'c')) end) it('errors when set out of range with :mark', function() diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua index 102de5d0c1..da9ba49aa5 100644 --- a/test/functional/editor/put_spec.lua +++ b/test/functional/editor/put_spec.lua @@ -184,11 +184,11 @@ describe('put command', function() return function(exception_table, after_redo) expect(expect_string) - -- Have to use getcurpos() instead of curwinmeths.get_cursor() in + -- Have to use getcurpos() instead of meths.nvim_win_get_cursor(0) in -- order to account for virtualedit. -- We always want the curswant element in getcurpos(), which is -- sometimes different to the column element in - -- curwinmeths.get_cursor(). + -- meths.nvim_win_get_cursor(0). -- NOTE: The ".gp command leaves the cursor after the pasted text -- when running, but does not when the command is redone with the -- '.' command. diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index 790340193f..2087695465 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -10,7 +10,7 @@ local eval = helpers.eval local exec = helpers.exec local funcs = helpers.funcs local meths = helpers.meths -local curwin = helpers.curwin +local curwin = helpers.meths.nvim_get_current_win local assert_alive = helpers.assert_alive describe('tabpage', function() diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua index 4bd323a763..27e56de54e 100644 --- a/test/functional/ex_cmds/append_spec.lua +++ b/test/functional/ex_cmds/append_spec.lua @@ -7,7 +7,6 @@ local feed = helpers.feed local clear = helpers.clear local funcs = helpers.funcs local command = helpers.command -local curbufmeths = helpers.curbufmeths local meths = helpers.meths local Screen = require('test.functional.ui.screen') @@ -15,11 +14,11 @@ local cmdtest = function(cmd, prep, ret1) describe(':' .. cmd, function() before_each(function() clear() - curbufmeths.set_lines(0, 1, true, { 'foo', 'bar', 'baz' }) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' }) end) local buffer_contents = function() - return curbufmeths.get_lines(0, -1, false) + return meths.nvim_buf_get_lines(0, 0, -1, false) end it(cmd .. 's' .. prep .. ' the current line by default', function() diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 821c8cf593..439d28d59a 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local assert_alive = helpers.assert_alive -local clear, nvim, source = helpers.clear, helpers.nvim, helpers.source +local clear, source = helpers.clear, helpers.source +local meths = helpers.meths local insert = helpers.insert local eq, next_msg = helpers.eq, helpers.next_msg local exc_exec = helpers.exc_exec @@ -13,8 +14,8 @@ describe('Vimscript dictionary notifications', function() before_each(function() clear() - channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + channel = meths.nvim_get_api_info()[1] + meths.nvim_set_var('channel', channel) end) -- the same set of tests are applied to top-level dictionaries(g:, b:, w: and @@ -59,7 +60,7 @@ describe('Vimscript dictionary notifications', function() local function verify_echo() -- helper to verify that no notifications are sent after certain change -- to a dict - nvim('command', "call rpcnotify(g:channel, 'echo')") + command("call rpcnotify(g:channel, 'echo')") eq({ 'notification', 'echo', {} }, next_msg()) end @@ -134,7 +135,7 @@ describe('Vimscript dictionary notifications', function() it('is triggered by remove()', function() update('= "test"') verify_value({ new = 'test' }) - nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + command('call remove(' .. dict_expr .. ', "watched")') verify_value({ old = 'test' }) end) @@ -142,14 +143,14 @@ describe('Vimscript dictionary notifications', function() it('is triggered by remove() when updated with nvim_*_var', function() update_with_api('"test"') verify_value({ new = 'test' }) - nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + command('call remove(' .. dict_expr .. ', "watched")') verify_value({ old = 'test' }) end) it('is triggered by remove() when updated with vim.g', function() update_with_vim_g('= "test"') verify_value({ new = 'test' }) - nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + command('call remove(' .. dict_expr .. ', "watched")') verify_value({ old = 'test' }) end) end @@ -157,7 +158,7 @@ describe('Vimscript dictionary notifications', function() it('is triggered by extend()', function() update('= "xtend"') verify_value({ new = 'xtend' }) - nvim('command', [[ + command([[ call extend(]] .. dict_expr .. [[, {'watched': 'xtend2', 'watched2': 5, 'watched3': 'a'}) ]]) verify_value({ old = 'xtend', new = 'xtend2' }) @@ -293,17 +294,17 @@ describe('Vimscript dictionary notifications', function() end) it('invokes all callbacks when the key is changed', function() - nvim('command', 'let g:key = "value"') + command('let g:key = "value"') eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) end) it('only removes watchers that fully match dict, key and callback', function() - nvim('command', 'let g:key = "value"') + command('let g:key = "value"') eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) - nvim('command', 'call dictwatcherdel(g:, "key", "g:Watcher1")') - nvim('command', 'let g:key = "v2"') + command('call dictwatcherdel(g:, "key", "g:Watcher1")') + command('let g:key = "v2"') eq({ 'notification', '2', { 'key', { old = 'value', new = 'v2' } } }, next_msg()) end) end) diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua index a2a95fbf3f..0dac810ef7 100644 --- a/test/functional/ex_cmds/ls_spec.lua +++ b/test/functional/ex_cmds/ls_spec.lua @@ -4,7 +4,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local nvim = helpers.nvim +local meths = helpers.meths local testprg = helpers.testprg local retry = helpers.retry @@ -14,7 +14,7 @@ describe(':ls', function() end) it('R, F for :terminal buffers', function() - nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) + meths.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) command('edit foo') command('set hidden') diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua index 88fd0e14e1..a91ee23bb8 100644 --- a/test/functional/ex_cmds/make_spec.lua +++ b/test/functional/ex_cmds/make_spec.lua @@ -3,7 +3,7 @@ local clear = helpers.clear local eval = helpers.eval local has_powershell = helpers.has_powershell local matches = helpers.matches -local nvim = helpers.nvim +local meths = helpers.meths local testprg = helpers.testprg describe(':make', function() @@ -22,7 +22,7 @@ describe(':make', function() end) it('captures stderr & non zero exit code #14349', function() - nvim('set_option_value', 'makeprg', testprg('shell-test') .. ' foo', {}) + meths.nvim_set_option_value('makeprg', testprg('shell-test') .. ' foo', {}) local out = eval('execute("make")') -- Error message is captured in the file and printed in the footer matches( @@ -32,7 +32,7 @@ describe(':make', function() end) it('captures stderr & zero exit code #14349', function() - nvim('set_option_value', 'makeprg', testprg('shell-test'), {}) + meths.nvim_set_option_value('makeprg', testprg('shell-test'), {}) local out = eval('execute("make")') -- Ensure there are no "shell returned X" messages between -- command and last line (indicating zero exit) diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index d6d8cce161..cd5f4d870c 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, command, nvim = helpers.clear, helpers.command, helpers.nvim +local clear, command = helpers.clear, helpers.command local expect, feed = helpers.expect, helpers.feed local eq, eval = helpers.eq, helpers.eval local funcs = helpers.funcs @@ -42,12 +42,12 @@ describe(':emenu', function() feed('ithis is a sentence<esc>^yiwo<esc>') -- Invoke "Edit.Paste" in normal-mode. - nvim('command', 'emenu Edit.Paste') + command('emenu Edit.Paste') -- Invoke "Edit.Paste" and "Test.Test" in command-mode. feed(':') - nvim('command', 'emenu Edit.Paste') - nvim('command', 'emenu Test.Test') + command('emenu Edit.Paste') + command('emenu Test.Test') expect([[ this is a sentence diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 8330395ed1..ee2bbdc4e7 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local expect_exit = helpers.expect_exit -local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command +local meths, eq, feed_command = helpers.meths, helpers.eq, helpers.feed_command local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop local ok = helpers.ok local eval = helpers.eval @@ -42,7 +42,7 @@ describe(':oldfiles', function() feed_command('edit testfile2') feed_command('wshada') feed_command('rshada!') - local oldfiles = helpers.meths.nvim_get_vvar('oldfiles') + local oldfiles = meths.nvim_get_vvar('oldfiles') feed_command('oldfiles') screen:expect([[ | @@ -56,11 +56,11 @@ describe(':oldfiles', function() it('can be filtered with :filter', function() feed_command('edit file_one.txt') - local file1 = buf.get_name() + local file1 = meths.nvim_buf_get_name(0) feed_command('edit file_two.txt') - local file2 = buf.get_name() + local file2 = meths.nvim_buf_get_name(0) feed_command('edit another.txt') - local another = buf.get_name() + local another = meths.nvim_buf_get_name(0) feed_command('wshada') feed_command('rshada!') @@ -95,9 +95,9 @@ describe(':browse oldfiles', function() before_each(function() _clear() feed_command('edit testfile1') - filename = buf.get_name() + filename = meths.nvim_buf_get_name(0) feed_command('edit testfile2') - filename2 = buf.get_name() + filename2 = meths.nvim_buf_get_name(0) feed_command('wshada') poke_eventloop() _clear() @@ -123,16 +123,16 @@ describe(':browse oldfiles', function() it('provides a prompt and edits the chosen file', function() feed('2<cr>') - eq(oldfiles[2], buf.get_name()) + eq(oldfiles[2], meths.nvim_buf_get_name(0)) end) it('provides a prompt and does nothing on <cr>', function() feed('<cr>') - eq('', buf.get_name()) + eq('', meths.nvim_buf_get_name(0)) end) it('provides a prompt and does nothing if choice is out-of-bounds', function() feed('3<cr>') - eq('', buf.get_name()) + eq('', meths.nvim_buf_get_name(0)) end) end) diff --git a/test/functional/ex_cmds/quickfix_commands_spec.lua b/test/functional/ex_cmds/quickfix_commands_spec.lua index e694f5d1da..74283fcb4e 100644 --- a/test/functional/ex_cmds/quickfix_commands_spec.lua +++ b/test/functional/ex_cmds/quickfix_commands_spec.lua @@ -8,7 +8,7 @@ local funcs = helpers.funcs local command = helpers.command local exc_exec = helpers.exc_exec local write_file = helpers.write_file -local curbufmeths = helpers.curbufmeths +local meths = helpers.meths local source = helpers.source local file_base = 'Xtest-functional-ex_cmds-quickfix_commands' @@ -79,7 +79,7 @@ for _, c in ipairs({ 'l', 'c' }) do -- Run cfile/lfile from a modified buffer command('set nohidden') command('enew!') - curbufmeths.set_lines(1, 1, true, { 'Quickfix' }) + meths.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' }) eq( ('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd), exc_exec(('%s %s'):format(filecmd, file)) diff --git a/test/functional/ex_cmds/sign_spec.lua b/test/functional/ex_cmds/sign_spec.lua index 30c6f9ac47..a0783264a7 100644 --- a/test/functional/ex_cmds/sign_spec.lua +++ b/test/functional/ex_cmds/sign_spec.lua @@ -1,5 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eq, assert_alive = helpers.clear, helpers.nvim, helpers.eq, helpers.assert_alive +local clear, eq, assert_alive = helpers.clear, helpers.eq, helpers.assert_alive +local command = helpers.command +local meths = helpers.meths describe('sign', function() before_each(clear) @@ -7,24 +9,24 @@ describe('sign', function() describe('without specifying buffer', function() it('deletes the sign from all buffers', function() -- place a sign with id 34 to first buffer - nvim('command', 'sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') - local buf1 = nvim('eval', 'bufnr("%")') - nvim('command', 'sign place 34 line=3 name=Foo buffer=' .. buf1) + command('sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') + local buf1 = meths.nvim_eval('bufnr("%")') + command('sign place 34 line=3 name=Foo buffer=' .. buf1) -- create a second buffer and place the sign on it as well - nvim('command', 'new') - local buf2 = nvim('eval', 'bufnr("%")') - nvim('command', 'sign place 34 line=3 name=Foo buffer=' .. buf2) + command('new') + local buf2 = meths.nvim_eval('bufnr("%")') + command('sign place 34 line=3 name=Foo buffer=' .. buf2) -- now unplace without specifying a buffer - nvim('command', 'sign unplace 34') - eq('--- Signs ---\n', nvim('exec', 'sign place buffer=' .. buf1, true)) - eq('--- Signs ---\n', nvim('exec', 'sign place buffer=' .. buf2, true)) + command('sign unplace 34') + eq('--- Signs ---\n', meths.nvim_exec('sign place buffer=' .. buf1, true)) + eq('--- Signs ---\n', meths.nvim_exec('sign place buffer=' .. buf2, true)) end) end) end) describe('define {id}', function() it('does not leak memory when specifying multiple times the same argument', function() - nvim('command', 'sign define Foo culhl=Normal culhl=Normal') + command('sign define Foo culhl=Normal culhl=Normal') assert_alive() end) end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index dff4a7f13c..5c66c50648 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -290,12 +290,6 @@ function module.nvim_prog_abs() end end --- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but --- v:errmsg will not be updated. -function module.command(cmd) - module.request('nvim_command', cmd) -end - -- Use for commands which expect nvim to quit. -- The first argument can also be a timeout. function module.expect_exit(fn_or_timeout, ...) @@ -629,57 +623,17 @@ module.async_meths = module.create_callindex(module.nvim_async) module.uimeths = module.create_callindex(ui) local function create_api(request, call) - local m = {} - function m.nvim(method, ...) + local function nvim(method, ...) if vim.startswith(method, 'nvim_') then return request(method, ...) end return request('nvim_' .. method, ...) end - function m.buffer(method, ...) - return request('nvim_buf_' .. method, ...) - end - - function m.window(method, ...) - return request('nvim_win_' .. method, ...) - end - - function m.tabpage(method, ...) - return request('nvim_tabpage_' .. method, ...) - end - - function m.curbuf(method, ...) - if not method then - return m.nvim('get_current_buf') - end - return m.buffer(method, 0, ...) - end - - function m.curwin(method, ...) - if not method then - return m.nvim('get_current_win') - end - return m.window(method, 0, ...) - end - - function m.curtab(method, ...) - if not method then - return m.nvim('get_current_tabpage') - end - return m.tabpage(method, 0, ...) - end - - m.funcs = module.create_callindex(call) - m.meths = module.create_callindex(m.nvim) - m.bufmeths = module.create_callindex(m.buffer) - m.winmeths = module.create_callindex(m.window) - m.tabmeths = module.create_callindex(m.tabpage) - m.curbufmeths = module.create_callindex(m.curbuf) - m.curwinmeths = module.create_callindex(m.curwin) - m.curtabmeths = module.create_callindex(m.curtab) - - return m + return { + funcs = module.create_callindex(call), + meths = module.create_callindex(nvim), + } end module.rpc = { @@ -705,11 +659,16 @@ end --- add for typing. The for loop after will overwrite this module.meths = vim.api +module.funcs = vim.fn for name, fn in pairs(module.rpc.api) do module[name] = fn end +-- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but +-- v:errmsg will not be updated. +module.command = module.meths.nvim_command + function module.poke_eventloop() -- Execute 'nvim_eval' (a deferred function) to -- force at least one main_loop iteration @@ -723,7 +682,7 @@ end ---@see buf_lines() function module.curbuf_contents() module.poke_eventloop() -- Before inspecting the buffer, do whatever. - return table.concat(module.curbuf('get_lines', 0, -1, true), '\n') + return table.concat(module.meths.nvim_buf_get_lines(0, 0, -1, true), '\n') end function module.expect(contents) @@ -760,7 +719,7 @@ end -- Asserts that buffer is loaded and visible in the current tabpage. function module.assert_visible(bufnr, visible) assert(type(visible) == 'boolean') - eq(visible, module.bufmeths.is_loaded(bufnr)) + eq(visible, module.meths.nvim_buf_is_loaded(bufnr)) if visible then assert( -1 ~= module.funcs.bufwinnr(bufnr), diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua index 4143a3159b..d2c41043ac 100644 --- a/test/functional/legacy/autocmd_option_spec.lua +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -1,8 +1,9 @@ local helpers = require('test.functional.helpers')(after_each) local nvim = helpers.meths local clear, eq, neq, eval = helpers.clear, helpers.eq, helpers.neq, helpers.eval -local curbuf, buf = helpers.curbuf, helpers.bufmeths -local curwin = helpers.curwin +local meths = helpers.meths +local curbuf = helpers.meths.nvim_get_current_buf +local curwin = helpers.meths.nvim_get_current_win local exec_capture = helpers.exec_capture local source, command = helpers.source, helpers.command @@ -210,7 +211,7 @@ describe('au OptionSet', function() it('should trigger if the current buffer is different from the targeted buffer', function() local new_buffer = make_buffer() - local new_bufnr = buf.get_number(new_buffer) + local new_bufnr = meths.nvim_buf_get_number(new_buffer) command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")') expected_combination({ @@ -647,7 +648,7 @@ describe('au OptionSet', function() set_hook('buftype') local new_buffer = make_buffer() - local new_bufnr = buf.get_number(new_buffer) + local new_bufnr = meths.nvim_buf_get_number(new_buffer) command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")') expected_combination({ diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index 7a4299c480..2efb57828d 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -18,7 +18,6 @@ local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err local write_file = helpers.write_file -local curbufmeths = helpers.curbufmeths local remove_trace = helpers.remove_trace before_each(clear) @@ -26,23 +25,23 @@ before_each(clear) describe(':lua command', function() it('works', function() eq('', exec_capture('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})')) - eq({ '', 'TEST' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'TEST' }, meths.nvim_buf_get_lines(0, 0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"}) EOF]]) - eq({ '', 'TSET' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'TSET' }, meths.nvim_buf_get_lines(0, 0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]]) - eq({ '', 'SETT' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'SETT' }, meths.nvim_buf_get_lines(0, 0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) EOF]]) - eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'ETTS', 'TTSE', 'STTE' }, meths.nvim_buf_get_lines(0, 0, 100, false)) matches( '.*Vim%(lua%):E15: Invalid expression: .*', pcall_err( @@ -68,7 +67,7 @@ describe(':lua command', function() [[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]], remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})')) ) - eq({ '' }, curbufmeths.get_lines(0, 100, false)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, 100, false)) end) it('works with NULL errors', function() eq([=[Vim(lua):E5108: Error executing lua [NULL]]=], exc_exec('lua error(nil)')) @@ -76,13 +75,13 @@ describe(':lua command', function() it('accepts embedded NLs without heredoc', function() -- Such code is usually used for `:execute 'lua' {generated_string}`: -- heredocs do not work in this case. - meths.nvim_command([[ + command([[ lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) ]]) - eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'ETTS', 'TTSE', 'STTE' }, meths.nvim_buf_get_lines(0, 0, 100, false)) end) it('preserves global and not preserves local variables', function() eq('', exec_capture('lua gvar = 42')) @@ -97,10 +96,10 @@ describe(':lua command', function() 'Vim(lua):E5107: Error loading lua [string ":lua"]:0: unfinished string near \'<eof>\'', pcall_err(command, ('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s)) ) - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq('', exec_capture(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s))) - eq({ '', s }, curbufmeths.get_lines(0, -1, false)) + eq({ '', s }, meths.nvim_buf_get_lines(0, 0, -1, false)) end) it('can show multiline error messages', function() @@ -197,31 +196,31 @@ end) describe(':luado command', function() it('works', function() - curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' }) eq('', exec_capture('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}')) - eq({ 'ABC', 'def', 'gHi' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'ABC', 'def', 'gHi' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, funcs.luaeval('lines')) -- Automatic transformation of numbers eq('', exec_capture('luado return linenr')) - eq({ '1', '2', '3' }, curbufmeths.get_lines(0, -1, false)) + eq({ '1', '2', '3' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq('', exec_capture('luado return ("<%02x>"):format(line:byte())')) - eq({ '<31>', '<32>', '<33>' }, curbufmeths.get_lines(0, -1, false)) + eq({ '<31>', '<32>', '<33>' }, meths.nvim_buf_get_lines(0, 0, -1, false)) end) it('stops processing lines when suddenly out of lines', function() - curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' }) eq('', exec_capture('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")')) - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq(1, funcs.luaeval('runs')) end) it('works correctly when changing lines out of range', function() - curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' }) eq( 'Vim(luado):E322: Line number out of range: 1 past the end', pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr') ) - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false)) end) it('fails on errors', function() eq( @@ -237,7 +236,7 @@ describe(':luado command', function() eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=], exc_exec('luado error(nil)')) end) it('fails in sandbox when needed', function() - curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' }) eq( 'Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1', pcall_err(command, 'sandbox luado runs = (runs or 0) + 1') @@ -251,10 +250,10 @@ describe(':luado command', function() 'Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'', pcall_err(command, ('luado return "%s'):format(s)) ) - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq('', exec_capture(('luado return "%s"'):format(s))) - eq({ s }, curbufmeths.get_lines(0, -1, false)) + eq({ s }, meths.nvim_buf_get_lines(0, 0, -1, false)) end) end) @@ -275,7 +274,7 @@ describe(':luafile', function() ]] ) eq('', exec_capture('luafile ' .. fname)) - eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'ETTS', 'TTSE', 'STTE' }, meths.nvim_buf_get_lines(0, 0, 100, false)) end) it('correctly errors out', function() diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index de1c139344..523e771266 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -5,8 +5,8 @@ local command = helpers.command local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq -local nvim = helpers.nvim local matches = helpers.matches +local meths = helpers.meths local pcall_err = helpers.pcall_err describe('vim.diagnostic', function() @@ -1563,8 +1563,8 @@ describe('vim.diagnostic', function() it('can perform updates after insert_leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1577,15 +1577,15 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq( 1, @@ -1596,8 +1596,8 @@ describe('vim.diagnostic', function() it('does not perform updates when not needed', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1619,7 +1619,7 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] @@ -1627,8 +1627,8 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq( 1, @@ -1638,11 +1638,11 @@ describe('vim.diagnostic', function() eq(1, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) -- Should not have set the virtual text again. eq(1, exec_lua [[return DisplayCount]]) @@ -1650,8 +1650,8 @@ describe('vim.diagnostic', function() it('never sets virtual text, in combination with insert leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1674,7 +1674,7 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] @@ -1682,8 +1682,8 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq( 1, @@ -1693,11 +1693,11 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) -- Should not have set the virtual text still. eq(0, exec_lua [[return DisplayCount]]) @@ -1705,8 +1705,8 @@ describe('vim.diagnostic', function() it('can perform updates while in insert mode, if desired', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1720,15 +1720,15 @@ describe('vim.diagnostic', function() ]] -- Diagnostics are displayed, because the user wanted them that way! - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq( 1, diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 1600616724..12110a86c9 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -341,7 +341,7 @@ describe('os.getenv', function() end) it('returns env var set by let', function() local value = 'foo' - meths.nvim_command('let $XTEST_1 = "' .. value .. '"') + command('let $XTEST_1 = "' .. value .. '"') eq(value, funcs.luaeval('os.getenv("XTEST_1")')) end) end) diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 6bc74b3540..234dc47f20 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -221,9 +221,9 @@ describe('startup defaults', function() eq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {})) -- Does not follow modifications to runtimepath. - meths.nvim_command('set runtimepath+=foo') + command('set runtimepath+=foo') neq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {})) - meths.nvim_command('set packpath+=foo') + command('set packpath+=foo') eq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {})) end) @@ -430,11 +430,11 @@ describe('XDG defaults', function() ), (meths.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') ) - meths.nvim_command('set runtimepath&') - meths.nvim_command('set backupdir&') - meths.nvim_command('set directory&') - meths.nvim_command('set undodir&') - meths.nvim_command('set viewdir&') + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') eq( ( ( @@ -573,11 +573,11 @@ describe('XDG defaults', function() ), (meths.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') ) - meths.nvim_command('set runtimepath&') - meths.nvim_command('set backupdir&') - meths.nvim_command('set directory&') - meths.nvim_command('set undodir&') - meths.nvim_command('set viewdir&') + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') eq( ( ( @@ -617,7 +617,7 @@ describe('XDG defaults', function() ('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), meths.nvim_get_option_value('viewdir', {}):gsub('\\', '/') ) - meths.nvim_command('set all&') + command('set all&') eq( ( '$XDG_DATA_HOME/nvim' @@ -745,11 +745,11 @@ describe('XDG defaults', function() ), meths.nvim_get_option_value('runtimepath', {}) ) - meths.nvim_command('set runtimepath&') - meths.nvim_command('set backupdir&') - meths.nvim_command('set directory&') - meths.nvim_command('set undodir&') - meths.nvim_command('set viewdir&') + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') eq( ( '\\, \\, \\,' diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 628ff968d7..c037636025 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,16 +1,14 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear -local eq, meths, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf = +local eq, meths, nvim_eval, nvim_command, exc_exec, funcs, nvim_feed = helpers.eq, helpers.meths, helpers.eval, helpers.command, - helpers.nvim, helpers.exc_exec, helpers.funcs, - helpers.feed, - helpers.curbuf + helpers.feed local neq = helpers.neq local read_file = helpers.read_file @@ -1581,7 +1579,7 @@ describe('autoload/shada.vim', function() describe('function shada#strings_to_sd', function() local strings2sd_eq = function(expected, input) - nvim('set_var', '__input', input) + meths.nvim_set_var('__input', input) nvim_command( 'let g:__actual = map(shada#strings_to_sd(g:__input), ' .. '"filter(v:val, \\"v:key[0] isnot# \'_\' ' @@ -1589,7 +1587,7 @@ describe('autoload/shada.vim', function() ) -- print() if type(expected) == 'table' then - nvim('set_var', '__expected', expected) + meths.nvim_set_var('__expected', expected) nvim_command('let g:__expected = ModifyVal(g:__expected)') expected = 'g:__expected' -- print(nvim_eval('msgpack#string(g:__expected)')) @@ -2534,7 +2532,7 @@ describe('autoload/shada.vim', function() end it('works', function() - local version = nvim('get_vvar', 'version') + local version = meths.nvim_get_vvar('version') getbstrings_eq({ { timestamp = 'current', @@ -2560,7 +2558,7 @@ describe('autoload/shada.vim', function() ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#add_own_header', 1) + meths.nvim_set_var('shada#add_own_header', 1) getbstrings_eq({ { timestamp = 'current', @@ -2586,14 +2584,14 @@ describe('autoload/shada.vim', function() ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#add_own_header', 0) + meths.nvim_set_var('shada#add_own_header', 0) getbstrings_eq({}, {}) getbstrings_eq({ { timestamp = 0, type = 1, value = { generator = 'test' } } }, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#keep_old_header', 0) + meths.nvim_set_var('shada#keep_old_header', 0) getbstrings_eq({}, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', @@ -2661,8 +2659,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - eq(false, nvim('get_option_value', 'modified', {})) - eq('shada', nvim('get_option_value', 'filetype', {})) + eq(false, meths.nvim_get_option_value('modified', {})) + eq('shada', meths.nvim_get_option_value('filetype', {})) nvim_command('edit ' .. fname_tmp) eq({ 'History entry with timestamp ' .. epoch .. ':', @@ -2671,8 +2669,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - eq(false, nvim('get_option_value', 'modified', {})) - eq('shada', nvim('get_option_value', 'filetype', {})) + eq(false, meths.nvim_get_option_value('modified', {})) + eq('shada', meths.nvim_get_option_value('filetype', {})) eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname)) neq({ 'History entry with timestamp ' .. epoch .. ':', @@ -2681,7 +2679,7 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - neq(true, nvim('get_option_value', 'modified', {})) + neq(true, meths.nvim_get_option_value('modified', {})) end) it('event FileReadCmd', function() @@ -2697,8 +2695,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - eq(true, nvim('get_option_value', 'modified', {})) - neq('shada', nvim('get_option_value', 'filetype', {})) + eq(true, meths.nvim_get_option_value('modified', {})) + neq('shada', meths.nvim_get_option_value('filetype', {})) nvim_command('1,$read ' .. fname_tmp) eq({ '', @@ -2713,9 +2711,9 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - eq(true, nvim('get_option_value', 'modified', {})) - neq('shada', nvim('get_option_value', 'filetype', {})) - nvim('set_option_value', 'modified', false, {}) + eq(true, meths.nvim_get_option_value('modified', {})) + neq('shada', meths.nvim_get_option_value('filetype', {})) + meths.nvim_set_option_value('modified', false, {}) eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname)) eq({ '', @@ -2730,13 +2728,13 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - neq(true, nvim('get_option_value', 'modified', {})) + neq(true, meths.nvim_get_option_value('modified', {})) end) it('event BufWriteCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + meths.nvim_set_var('shada#add_own_header', 0) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2796,8 +2794,8 @@ describe('plugin/shada.vim', function() it('event FileWriteCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + meths.nvim_set_var('shada#add_own_header', 0) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2840,8 +2838,8 @@ describe('plugin/shada.vim', function() it('event FileAppendCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + meths.nvim_set_var('shada#add_own_header', 0) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -3017,10 +3015,10 @@ describe('ftplugin/shada.vim', function() it('sets options correctly', function() nvim_command('filetype plugin indent on') nvim_command('setlocal filetype=shada') - eq(true, nvim('get_option_value', 'expandtab', {})) - eq(2, nvim('get_option_value', 'tabstop', {})) - eq(2, nvim('get_option_value', 'softtabstop', {})) - eq(2, nvim('get_option_value', 'shiftwidth', {})) + eq(true, meths.nvim_get_option_value('expandtab', {})) + eq(2, meths.nvim_get_option_value('tabstop', {})) + eq(2, meths.nvim_get_option_value('softtabstop', {})) + eq(2, meths.nvim_get_option_value('shiftwidth', {})) end) it('sets indentkeys correctly', function() @@ -3028,17 +3026,17 @@ describe('ftplugin/shada.vim', function() nvim_command('setlocal filetype=shada') funcs.setline(1, ' Replacement with timestamp ' .. epoch) nvim_feed('ggA:\027') - eq('Replacement with timestamp ' .. epoch .. ':', curbuf('get_lines', 0, 1, true)[1]) + eq('Replacement with timestamp ' .. epoch .. ':', meths.nvim_buf_get_lines(0, 0, 1, true)[1]) nvim_feed('o-\027') - eq({ ' -' }, curbuf('get_lines', 1, 2, true)) + eq({ ' -' }, meths.nvim_buf_get_lines(0, 1, 2, true)) nvim_feed('ggO+\027') - eq({ '+' }, curbuf('get_lines', 0, 1, true)) + eq({ '+' }, meths.nvim_buf_get_lines(0, 0, 1, true)) nvim_feed('GO*\027') - eq({ ' *' }, curbuf('get_lines', 2, 3, true)) + eq({ ' *' }, meths.nvim_buf_get_lines(0, 2, 3, true)) nvim_feed('ggO /\027') - eq({ ' /' }, curbuf('get_lines', 0, 1, true)) + eq({ ' /' }, meths.nvim_buf_get_lines(0, 0, 1, true)) nvim_feed('ggOx\027') - eq({ 'x' }, curbuf('get_lines', 0, 1, true)) + eq({ 'x' }, meths.nvim_buf_get_lines(0, 0, 1, true)) end) end) @@ -3063,7 +3061,7 @@ describe('syntax/shada.vim', function() } screen:attach() - curbuf('set_lines', 0, 1, true, { + meths.nvim_buf_set_lines(0, 0, 1, true, { 'Header with timestamp ' .. epoch .. ':', ' % Key Value', ' + t "test"', diff --git a/test/functional/provider/define_spec.lua b/test/functional/provider/define_spec.lua index 59422d8224..5f51ad76e6 100644 --- a/test/functional/provider/define_spec.lua +++ b/test/functional/provider/define_spec.lua @@ -1,7 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) -local eval, command, nvim = helpers.eval, helpers.command, helpers.nvim +local eval, command = helpers.eval, helpers.command local eq, run, stop = helpers.eq, helpers.run, helpers.stop local clear = helpers.clear +local meths = helpers.meths local function get_prefix(sync) if sync then @@ -361,7 +362,7 @@ local function function_specs_for(fn, sync, first_arg_factory, init) end local function channel() - return nvim('get_api_info')[1] + return meths.nvim_get_api_info()[1] end local function host() diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua index c0fb3815b6..06b7167525 100644 --- a/test/functional/shada/buffers_spec.lua +++ b/test/functional/shada/buffers_spec.lua @@ -1,7 +1,6 @@ -- shada buffer list saving/reading support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, eq, curbufmeths, meths = - helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths, helpers.meths +local nvim_command, funcs, eq, meths = helpers.command, helpers.funcs, helpers.eq, helpers.meths local expect_exit = helpers.expect_exit local shada_helpers = require('test.functional.shada.helpers') @@ -70,9 +69,9 @@ describe('shada support code', function() it('does not dump unnamed buffers', function() reset('set shada+=% hidden') - curbufmeths.set_lines(0, 1, true, { 'foo' }) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'foo' }) nvim_command('enew') - curbufmeths.set_lines(0, 1, true, { 'bar' }) + meths.nvim_buf_set_lines(0, 0, 1, true, { 'bar' }) eq(2, funcs.bufnr('$')) expect_exit(nvim_command, 'qall!') reset('set shada+=% hidden') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index b50df23be4..0850084d98 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -1,12 +1,6 @@ -- ShaDa marks saving/reading support local helpers = require('test.functional.helpers')(after_each) -local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq = - helpers.meths, - helpers.curwinmeths, - helpers.curbufmeths, - helpers.command, - helpers.funcs, - helpers.eq +local meths, nvim_command, funcs, eq = helpers.meths, helpers.command, helpers.funcs, helpers.eq local feed = helpers.feed local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture local expect_exit = helpers.expect_exit @@ -15,7 +9,7 @@ local shada_helpers = require('test.functional.shada.helpers') local reset, clear = shada_helpers.reset, shada_helpers.clear local nvim_current_line = function() - return curwinmeths.get_cursor()[1] + return meths.nvim_win_get_cursor(0)[1] end describe('ShaDa support code', function() @@ -49,7 +43,7 @@ describe('ShaDa support code', function() reset() nvim_command('rshada') nvim_command('normal! `A') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) nvim_command('normal! `B') eq(2, nvim_current_line()) @@ -76,7 +70,7 @@ describe('ShaDa support code', function() reset("set shada='0,f0") nvim_command('language C') nvim_command('normal! `A') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) end) @@ -89,7 +83,7 @@ describe('ShaDa support code', function() reset() nvim_command('edit ' .. testfilename) nvim_command('normal! `a') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) nvim_command('normal! `b') eq(2, nvim_current_line()) @@ -119,9 +113,9 @@ describe('ShaDa support code', function() it('is able to populate v:oldfiles', function() nvim_command('edit ' .. testfilename) - local tf_full = curbufmeths.get_name() + local tf_full = meths.nvim_buf_get_name(0) nvim_command('edit ' .. testfilename_2) - local tf_full_2 = curbufmeths.get_name() + local tf_full_2 = meths.nvim_buf_get_name(0) expect_exit(nvim_command, 'qall') reset() local oldfiles = meths.nvim_get_vvar('oldfiles') @@ -166,7 +160,7 @@ describe('ShaDa support code', function() nvim_command('rshada') nvim_command('normal! \15') -- <C-o> eq(testfilename_2, funcs.bufname('%')) - eq({ 2, 0 }, curwinmeths.get_cursor()) + eq({ 2, 0 }, meths.nvim_win_get_cursor(0)) end) it('is able to dump and restore jump list with different times (slow!)', function() diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index 7ca261eb11..fd6bf9d7af 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -1,8 +1,8 @@ -- ShaDa merging data support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, curbufmeths, eq = - helpers.command, helpers.funcs, helpers.curbufmeths, helpers.eq +local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture +local meths = helpers.meths local shada_helpers = require('test.functional.shada.helpers') local reset, clear, get_shada_rw = @@ -492,14 +492,14 @@ describe('ShaDa marks support code', function() wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) end) it('can merge with file with mark 9 as the only numeric mark', function() wshada('\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `9oabc') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -632,7 +632,7 @@ describe('ShaDa marks support code', function() wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd(true))) nvim_command('normal! `A') - eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('?', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) end) it('uses last A mark with eq timestamp from instance when reading', function() @@ -641,7 +641,7 @@ describe('ShaDa marks support code', function() wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) end) it('uses last A mark with gt timestamp from file when reading', function() @@ -650,7 +650,7 @@ describe('ShaDa marks support code', function() wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('?', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) end) it('uses last A mark with gt timestamp from instance when writing', function() @@ -658,7 +658,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -675,7 +675,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -692,7 +692,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -803,7 +803,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') nvim_command('normal! `a') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -940,7 +940,7 @@ describe('ShaDa jumps support code', function() .. 'f\161l\002' ) eq(0, exc_exec(sdrcmd())) - eq('', curbufmeths.get_name()) + eq('', meths.nvim_buf_get_name(0)) eq( ' jump line col file/text\n' .. ' 5 2 0 ' diff --git a/test/functional/terminal/altscreen_spec.lua b/test/functional/terminal/altscreen_spec.lua index f626a463c5..3c41a68eda 100644 --- a/test/functional/terminal/altscreen_spec.lua +++ b/test/functional/terminal/altscreen_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf +local clear, eq, meths = helpers.clear, helpers.eq, helpers.meths local feed = helpers.feed local feed_data = thelpers.feed_data local enter_altscreen = thelpers.enter_altscreen @@ -42,7 +42,7 @@ describe(':terminal altscreen', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(10, curbuf('line_count')) + eq(10, meths.nvim_buf_line_count(0)) end) it('wont clear lines already in the scrollback', function() @@ -107,7 +107,7 @@ describe(':terminal altscreen', function() end) it('wont modify line count', function() - eq(10, curbuf('line_count')) + eq(10, meths.nvim_buf_line_count(0)) end) it('wont modify lines in the scrollback', function() @@ -144,7 +144,7 @@ describe(':terminal altscreen', function() rows: 4, cols: 50 | | ]]) - eq(9, curbuf('line_count')) + eq(9, meths.nvim_buf_line_count(0)) end) describe('and after exit', function() diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 541812b4be..7029b81de0 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') local assert_alive = helpers.assert_alive -local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim +local feed, clear = helpers.feed, helpers.clear local poke_eventloop = helpers.poke_eventloop local nvim_prog = helpers.nvim_prog local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source @@ -92,12 +92,12 @@ describe(':terminal buffer', function() end) it('does not create swap files', function() - local swapfile = nvim('exec', 'swapname', true):gsub('\n', '') + local swapfile = meths.nvim_exec('swapname', true):gsub('\n', '') eq(nil, io.open(swapfile)) end) it('does not create undofiles files', function() - local undofile = nvim('eval', 'undofile(bufname("%"))') + local undofile = meths.nvim_eval('undofile(bufname("%"))') eq(nil, io.open(undofile)) end) end) @@ -172,7 +172,7 @@ describe(':terminal buffer', function() it('handles loss of focus gracefully', function() -- Change the statusline to avoid printing the file name, which varies. - nvim('set_option_value', 'statusline', '==========', {}) + meths.nvim_set_option_value('statusline', '==========', {}) -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index a818f8139c..73fd97203e 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') -local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim +local feed, clear = helpers.feed, helpers.clear local testprg, command = helpers.testprg, helpers.command local eq, eval = helpers.eq, helpers.eval local matches = helpers.matches @@ -118,8 +118,8 @@ describe('cursor with customized highlighting', function() before_each(function() clear() - nvim('command', 'highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE') - nvim('command', 'highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE') + command('highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE') + command('highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE') screen = Screen.new(50, 7) screen:set_default_attr_ids({ [1] = { foreground = 45, background = 46 }, diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index 4f462b9e5b..754a681cff 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -1,8 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local screen = require('test.functional.ui.screen') -local curbufmeths = helpers.curbufmeths -local curwinmeths = helpers.curwinmeths local testprg = helpers.testprg local command = helpers.command local funcs = helpers.funcs @@ -48,7 +46,7 @@ describe(':edit term://*', function() command('edit term://foobar') local bufcontents = {} - local winheight = curwinmeths.get_height() + local winheight = meths.nvim_win_get_height(0) local buf_cont_start = rep - sb - winheight + 2 for i = buf_cont_start, (rep - 1) do bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i) @@ -65,6 +63,6 @@ describe(':edit term://*', function() exp_screen = exp_screen .. (' '):rep(columns) .. '|\n' scr:expect(exp_screen) - eq(bufcontents, curbufmeths.get_lines(0, -1, true)) + eq(bufcontents, meths.nvim_buf_get_lines(0, 0, -1, true)) end) end) diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 68d206c177..266a34feea 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -1,11 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local assert_alive = helpers.assert_alive -local clear, poke_eventloop, nvim = helpers.clear, helpers.poke_eventloop, helpers.nvim +local clear, poke_eventloop = helpers.clear, helpers.poke_eventloop local testprg, source, eq = helpers.testprg, helpers.source, helpers.eq local feed = helpers.feed local feed_command, eval = helpers.feed_command, helpers.eval local funcs = helpers.funcs +local meths = helpers.meths local retry = helpers.retry local ok = helpers.ok local command = helpers.command @@ -104,30 +105,30 @@ describe(':terminal', function() it('nvim_get_mode() in :terminal', function() command('terminal') - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode()) feed('i') - eq({ blocking = false, mode = 't' }, nvim('get_mode')) + eq({ blocking = false, mode = 't' }, meths.nvim_get_mode()) feed([[<C-\><C-N>]]) - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode()) end) it(':stopinsert RPC request exits terminal-mode #7807', function() command('terminal') feed('i[tui] insert-mode') - eq({ blocking = false, mode = 't' }, nvim('get_mode')) + eq({ blocking = false, mode = 't' }, meths.nvim_get_mode()) command('stopinsert') feed('<Ignore>') -- Add input to separate two RPC requests - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode()) end) it(":stopinsert in normal mode doesn't break insert mode #9889", function() command('terminal') - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode()) command('stopinsert') feed('<Ignore>') -- Add input to separate two RPC requests - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode()) feed('a') - eq({ blocking = false, mode = 't' }, nvim('get_mode')) + eq({ blocking = false, mode = 't' }, meths.nvim_get_mode()) end) it('switching to terminal buffer in Insert mode goes to Terminal mode #7164', function() @@ -138,9 +139,9 @@ describe(':terminal', function() command('autocmd InsertLeave * let g:events += ["InsertLeave"]') command('autocmd TermEnter * let g:events += ["TermEnter"]') command('inoremap <F2> <Cmd>wincmd p<CR>') - eq({ blocking = false, mode = 'i' }, nvim('get_mode')) + eq({ blocking = false, mode = 'i' }, meths.nvim_get_mode()) feed('<F2>') - eq({ blocking = false, mode = 't' }, nvim('get_mode')) + eq({ blocking = false, mode = 't' }, meths.nvim_get_mode()) eq({ 'InsertLeave', 'TermEnter' }, eval('g:events')) end) end) @@ -158,9 +159,9 @@ local function test_terminal_with_fake_shell(backslash) clear() screen = Screen.new(50, 4) screen:attach({ rgb = false }) - nvim('set_option_value', 'shell', shell_path, {}) - nvim('set_option_value', 'shellcmdflag', 'EXE', {}) - nvim('set_option_value', 'shellxquote', '', {}) + meths.nvim_set_option_value('shell', shell_path, {}) + meths.nvim_set_option_value('shellcmdflag', 'EXE', {}) + meths.nvim_set_option_value('shellxquote', '', {}) end) it('with no argument, acts like termopen()', function() @@ -177,7 +178,7 @@ local function test_terminal_with_fake_shell(backslash) end) it("with no argument, and 'shell' is set to empty string", function() - nvim('set_option_value', 'shell', '', {}) + meths.nvim_set_option_value('shell', '', {}) feed_command('terminal') screen:expect([[ ^ | @@ -187,7 +188,7 @@ local function test_terminal_with_fake_shell(backslash) end) it("with no argument, but 'shell' has arguments, acts like termopen()", function() - nvim('set_option_value', 'shell', shell_path .. ' INTERACT', {}) + meths.nvim_set_option_value('shell', shell_path .. ' INTERACT', {}) feed_command('terminal') screen:expect([[ ^interact $ | @@ -208,7 +209,7 @@ local function test_terminal_with_fake_shell(backslash) end) it("executes a given command through the shell, when 'shell' has arguments", function() - nvim('set_option_value', 'shell', shell_path .. ' -t jeff', {}) + meths.nvim_set_option_value('shell', shell_path .. ' -t jeff', {}) command('set shellxquote=') -- win: avoid extra quotes feed_command('terminal echo hi') screen:expect([[ diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index babc2337fa..59af0ab167 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(nil) local Screen = require('test.functional.ui.screen') local testprg = helpers.testprg local exec_lua = helpers.exec_lua -local nvim = helpers.nvim +local meths = helpers.meths local nvim_prog = helpers.nvim_prog local function feed_data(data) @@ -89,8 +89,8 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts) command = command and command or default_command cols = cols and cols or 50 - nvim('command', 'highlight TermCursor cterm=reverse') - nvim('command', 'highlight TermCursorNC ctermbg=11') + meths.nvim_command('highlight TermCursor cterm=reverse') + meths.nvim_command('highlight TermCursorNC ctermbg=11') local screen = Screen.new(cols, 7 + extra_rows) screen:set_default_attr_ids({ @@ -113,17 +113,17 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts) screen:attach(screen_opts or { rgb = false }) - nvim('command', 'enew') - nvim('call_function', 'termopen', { command, env and { env = env } or nil }) - nvim('input', '<CR>') - local vim_errmsg = nvim('eval', 'v:errmsg') + meths.nvim_command('enew') + meths.nvim_call_function('termopen', { command, env and { env = env } or nil }) + meths.nvim_input('<CR>') + local vim_errmsg = meths.nvim_eval('v:errmsg') if vim_errmsg and '' ~= vim_errmsg then error(vim_errmsg) end - nvim('command', 'setlocal scrollback=10') - nvim('command', 'startinsert') - nvim('input', '<Ignore>') -- Add input to separate two RPC requests + meths.nvim_command('setlocal scrollback=10') + meths.nvim_command('startinsert') + meths.nvim_input('<Ignore>') -- Add input to separate two RPC requests -- tty-test puts the terminal into raw mode and echoes input. Tests work by -- feeding termcodes to control the display and asserting by screen:expect. @@ -147,7 +147,7 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts) screen:expect(table.concat(expected, '|\n') .. '|') else -- This eval also acts as a poke_eventloop(). - if 0 == nvim('eval', "exists('b:terminal_job_id')") then + if 0 == meths.nvim_eval("exists('b:terminal_job_id')") then error('terminal job failed to start') end end diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index 951a0f6c65..a8e0f1ac27 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -1,7 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') -local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim +local feed, clear = helpers.feed, helpers.clear +local meths = helpers.meths local testprg, command = helpers.testprg, helpers.command local nvim_prog_abs = helpers.nvim_prog_abs local eq, eval = helpers.eq, helpers.eval @@ -250,7 +251,7 @@ describe(':terminal highlight with custom palette', function() [9] = { bold = true }, }) screen:attach({ rgb = true }) - nvim('set_var', 'terminal_color_3', '#123456') + meths.nvim_set_var('terminal_color_3', '#123456') command(("enew | call termopen(['%s'])"):format(testprg('tty-test'))) feed('i') screen:expect([[ diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 65d0c8f854..e98b04090c 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval -local feed, nvim, command = helpers.feed, helpers.nvim, helpers.command +local feed, meths, command = helpers.feed, helpers.meths, helpers.command local feed_data = thelpers.feed_data local is_os = helpers.is_os local skip = helpers.skip @@ -11,7 +11,7 @@ describe(':terminal mouse', function() before_each(function() clear() - nvim('set_option_value', 'statusline', '==========', {}) + meths.nvim_set_option_value('statusline', '==========', {}) command('highlight StatusLine cterm=NONE') command('highlight StatusLineNC cterm=NONE') command('highlight VertSplit cterm=NONE') @@ -514,7 +514,7 @@ describe(':terminal mouse', function() end) it('handles terminal size when switching buffers', function() - nvim('set_option_value', 'hidden', true, {}) + meths.nvim_set_option_value('hidden', true, {}) feed('<c-\\><c-n><c-w><c-w>') screen:expect([[ {7: 27 }line │line30 | diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 7c1da6b32b..bd58ef0b0a 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -1,14 +1,13 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf +local clear, eq = helpers.clear, helpers.eq local feed, testprg = helpers.feed, helpers.testprg local eval = helpers.eval local command = helpers.command local poke_eventloop = helpers.poke_eventloop local retry = helpers.retry local meths = helpers.meths -local nvim = helpers.nvim local feed_data = thelpers.feed_data local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua @@ -86,7 +85,7 @@ describe(':terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(7, curbuf('line_count')) + eq(7, meths.nvim_buf_line_count(0)) end) describe('and then 3 more lines are printed', function() @@ -170,7 +169,7 @@ describe(':terminal scrollback', function() {2:^ } | | ]]) - eq(8, curbuf('line_count')) + eq(8, meths.nvim_buf_line_count(0)) feed([[3k]]) screen:expect([[ ^line4 | @@ -204,7 +203,7 @@ describe(':terminal scrollback', function() | {3:-- TERMINAL --} | ]]) - eq(4, curbuf('line_count')) + eq(4, meths.nvim_buf_line_count(0)) end it('will delete the last two empty lines', will_delete_last_two_lines) @@ -222,7 +221,7 @@ describe(':terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(4, curbuf('line_count')) + eq(4, meths.nvim_buf_line_count(0)) feed('<c-\\><c-n>gg') screen:expect([[ ^tty ready | @@ -261,7 +260,7 @@ describe(':terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(7, curbuf('line_count')) + eq(7, meths.nvim_buf_line_count(0)) end) describe('and the height is increased by 1', function() @@ -287,7 +286,7 @@ describe(':terminal scrollback', function() describe('and then by 3', function() before_each(function() pop_then_push() - eq(8, curbuf('line_count')) + eq(8, meths.nvim_buf_line_count(0)) screen:try_resize(screen._width, screen._height + 3) end) @@ -302,7 +301,7 @@ describe(':terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(9, curbuf('line_count')) + eq(9, meths.nvim_buf_line_count(0)) feed('<c-\\><c-n>gg') screen:expect([[ ^tty ready | @@ -342,7 +341,7 @@ describe(':terminal scrollback', function() ]]) -- since there's an empty line after the cursor, the buffer line -- count equals the terminal screen height - eq(11, curbuf('line_count')) + eq(11, meths.nvim_buf_line_count(0)) end) end) end) @@ -381,7 +380,7 @@ describe("'scrollback' option", function() end) local function set_fake_shell() - nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) + meths.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) end local function expect_lines(expected, epsilon) diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index a5dfd460c0..d91dff096c 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -772,7 +772,7 @@ describe('treesitter highlighting (help)', function() ]], } - helpers.curbufmeths.set_text(0, 1, 0, 5, { 'lua' }) + helpers.meths.nvim_buf_set_text(0, 0, 1, 0, 5, { 'lua' }) screen:expect { grid = [[ @@ -785,7 +785,7 @@ describe('treesitter highlighting (help)', function() ]], } - helpers.curbufmeths.set_text(0, 1, 0, 4, { 'ruby' }) + helpers.meths.nvim_buf_set_text(0, 0, 1, 0, 4, { 'ruby' }) screen:expect { grid = [[ diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua index 13fea71fec..2cde0a8688 100644 --- a/test/functional/ui/bufhl_spec.lua +++ b/test/functional/ui/bufhl_spec.lua @@ -4,8 +4,9 @@ local Screen = require('test.functional.ui.screen') local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, neq = helpers.command, helpers.neq local meths = helpers.meths -local curbufmeths, eq = helpers.curbufmeths, helpers.eq +local eq = helpers.eq local pcall_err = helpers.pcall_err +local set_virtual_text = meths.nvim_buf_set_virtual_text describe('Buffer highlighting', function() local screen @@ -39,8 +40,8 @@ describe('Buffer highlighting', function() }) end) - local add_highlight = curbufmeths.add_highlight - local clear_namespace = curbufmeths.clear_namespace + local add_highlight = meths.nvim_buf_add_highlight + local clear_namespace = meths.nvim_buf_clear_namespace it('works', function() insert([[ @@ -55,8 +56,8 @@ describe('Buffer highlighting', function() | ]]) - add_highlight(-1, 'String', 0, 10, 14) - add_highlight(-1, 'Statement', 1, 5, -1) + add_highlight(0, -1, 'String', 0, 10, 14) + add_highlight(0, -1, 'Statement', 1, 5, -1) screen:expect([[ these are {2:some} lines | @@ -74,7 +75,7 @@ describe('Buffer highlighting', function() | ]]) - clear_namespace(-1, 0, -1) + clear_namespace(0, -1, 0, -1) screen:expect([[ these are some lines | ^ | @@ -94,21 +95,21 @@ describe('Buffer highlighting', function() from different sources]]) command('hi ImportantWord gui=bold cterm=bold') - id1 = add_highlight(0, 'ImportantWord', 0, 2, 8) - add_highlight(id1, 'ImportantWord', 1, 12, -1) - add_highlight(id1, 'ImportantWord', 2, 0, 9) - add_highlight(id1, 'ImportantWord', 3, 5, 14) + id1 = add_highlight(0, 0, 'ImportantWord', 0, 2, 8) + add_highlight(0, id1, 'ImportantWord', 1, 12, -1) + add_highlight(0, id1, 'ImportantWord', 2, 0, 9) + add_highlight(0, id1, 'ImportantWord', 3, 5, 14) -- add_highlight can be called like this to get a new source -- without adding any highlight - id2 = add_highlight(0, '', 0, 0, 0) + id2 = add_highlight(0, 0, '', 0, 0, 0) neq(id1, id2) - add_highlight(id2, 'Special', 0, 2, 8) - add_highlight(id2, 'Identifier', 1, 3, 8) - add_highlight(id2, 'Special', 1, 14, 20) - add_highlight(id2, 'Underlined', 2, 6, 12) - add_highlight(id2, 'Underlined', 3, 0, 9) + add_highlight(0, id2, 'Special', 0, 2, 8) + add_highlight(0, id2, 'Identifier', 1, 3, 8) + add_highlight(0, id2, 'Special', 1, 14, 20) + add_highlight(0, id2, 'Underlined', 2, 6, 12) + add_highlight(0, id2, 'Underlined', 3, 0, 9) screen:expect([[ a {5:longer} example | @@ -121,7 +122,7 @@ describe('Buffer highlighting', function() end) it('and clearing the first added', function() - clear_namespace(id1, 0, -1) + clear_namespace(0, id1, 0, -1) screen:expect([[ a {4:longer} example | in {6:order} to de{4:monstr}ate | @@ -133,7 +134,7 @@ describe('Buffer highlighting', function() end) it('and clearing using deprecated name', function() - curbufmeths.clear_highlight(id1, 0, -1) + meths.nvim_buf_clear_highlight(0, id1, 0, -1) screen:expect([[ a {4:longer} example | in {6:order} to de{4:monstr}ate | @@ -145,7 +146,7 @@ describe('Buffer highlighting', function() end) it('and clearing the second added', function() - clear_namespace(id2, 0, -1) + clear_namespace(0, id2, 0, -1) screen:expect([[ a {7:longer} example | in order to {7:demonstrate} | @@ -157,9 +158,9 @@ describe('Buffer highlighting', function() end) it('and clearing line ranges', function() - clear_namespace(-1, 0, 1) - clear_namespace(id1, 1, 2) - clear_namespace(id2, 2, -1) + clear_namespace(0, -1, 0, 1) + clear_namespace(0, id1, 1, 2) + clear_namespace(0, id2, 2, -1) screen:expect([[ a longer example | in {6:order} to de{4:monstr}ate | @@ -449,9 +450,9 @@ describe('Buffer highlighting', function() pending('prioritizes latest added highlight', function() insert([[ three overlapping colors]]) - add_highlight(0, 'Identifier', 0, 6, 17) - add_highlight(0, 'String', 0, 14, 23) - local id = add_highlight(0, 'Special', 0, 0, 9) + add_highlight(0, 0, 'Identifier', 0, 6, 17) + add_highlight(0, 0, 'String', 0, 14, 23) + local id = add_highlight(0, 0, 'Special', 0, 0, 9) screen:expect([[ {4:three ove}{6:rlapp}{2:ing color}^s | @@ -459,7 +460,7 @@ describe('Buffer highlighting', function() | ]]) - clear_namespace(id, 0, 1) + clear_namespace(0, id, 0, 1) screen:expect([[ three {6:overlapp}{2:ing color}^s | {1:~ }|*6 @@ -470,9 +471,9 @@ describe('Buffer highlighting', function() it('prioritizes earlier highlight groups (TEMP)', function() insert([[ three overlapping colors]]) - add_highlight(0, 'Identifier', 0, 6, 17) - add_highlight(0, 'String', 0, 14, 23) - local id = add_highlight(0, 'Special', 0, 0, 9) + add_highlight(0, 0, 'Identifier', 0, 6, 17) + add_highlight(0, 0, 'String', 0, 14, 23) + local id = add_highlight(0, 0, 'Special', 0, 0, 9) screen:expect { grid = [[ @@ -482,7 +483,7 @@ describe('Buffer highlighting', function() ]], } - clear_namespace(id, 0, 1) + clear_namespace(0, id, 0, 1) screen:expect { grid = [[ three {6:overlapp}{2:ing color}^s | @@ -493,17 +494,16 @@ describe('Buffer highlighting', function() end) it('respects priority', function() - local set_extmark = curbufmeths.set_extmark local id = meths.nvim_create_namespace('') insert [[foobar]] - set_extmark(id, 0, 0, { + meths.nvim_buf_set_extmark(0, id, 0, 0, { end_line = 0, end_col = 5, hl_group = 'Statement', priority = 100, }) - set_extmark(id, 0, 0, { + meths.nvim_buf_set_extmark(0, id, 0, 0, { end_line = 0, end_col = 6, hl_group = 'String', @@ -516,7 +516,7 @@ describe('Buffer highlighting', function() | ]] - clear_namespace(id, 0, -1) + clear_namespace(0, id, 0, -1) screen:expect { grid = [[ fooba^r | @@ -525,13 +525,13 @@ describe('Buffer highlighting', function() ]], } - set_extmark(id, 0, 0, { + meths.nvim_buf_set_extmark(0, id, 0, 0, { end_line = 0, end_col = 6, hl_group = 'String', priority = 1, }) - set_extmark(id, 0, 0, { + meths.nvim_buf_set_extmark(0, id, 0, 0, { end_line = 0, end_col = 5, hl_group = 'Statement', @@ -548,8 +548,8 @@ describe('Buffer highlighting', function() it('works with multibyte text', function() insert([[ Ta båten över sjön!]]) - add_highlight(-1, 'Identifier', 0, 3, 9) - add_highlight(-1, 'String', 0, 16, 21) + add_highlight(0, -1, 'Identifier', 0, 3, 9) + add_highlight(0, -1, 'String', 0, 16, 21) screen:expect([[ Ta {6:båten} över {2:sjön}^! | @@ -561,7 +561,7 @@ describe('Buffer highlighting', function() it('works with new syntax groups', function() insert([[ fancy code in a new fancy language]]) - add_highlight(-1, 'FancyLangItem', 0, 0, 5) + add_highlight(0, -1, 'FancyLangItem', 0, 0, 5) screen:expect([[ fancy code in a new fancy languag^e | {1:~ }|*6 @@ -577,7 +577,6 @@ describe('Buffer highlighting', function() end) describe('virtual text decorations', function() - local set_virtual_text = curbufmeths.set_virtual_text local id1, id2 before_each(function() insert([[ @@ -595,9 +594,9 @@ describe('Buffer highlighting', function() | ]]) - id1 = set_virtual_text(0, 0, { { '=', 'Statement' }, { ' 3', 'Number' } }, {}) - set_virtual_text(id1, 1, { { 'ERROR:', 'ErrorMsg' }, { ' invalid syntax' } }, {}) - id2 = set_virtual_text(0, 2, { + id1 = set_virtual_text(0, 0, 0, { { '=', 'Statement' }, { ' 3', 'Number' } }, {}) + set_virtual_text(0, id1, 1, { { 'ERROR:', 'ErrorMsg' }, { ' invalid syntax' } }, {}) + id2 = set_virtual_text(0, 0, 2, { { 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', }, @@ -616,7 +615,7 @@ describe('Buffer highlighting', function() | ]]) - clear_namespace(id1, 0, -1) + clear_namespace(0, id1, 0, -1) screen:expect([[ ^1 + 2 | 3 + | @@ -632,6 +631,7 @@ describe('Buffer highlighting', function() eq( -1, set_virtual_text( + 0, -1, 1, { { '暗x事zz速野谷質結育副住新覚丸活解終事', 'Comment' } }, @@ -687,22 +687,22 @@ describe('Buffer highlighting', function() -- this used to leak memory eq( "Invalid 'chunk': expected Array, got String", - pcall_err(set_virtual_text, id1, 0, { 'texty' }, {}) + pcall_err(set_virtual_text, 0, id1, 0, { 'texty' }, {}) ) eq( "Invalid 'chunk': expected Array, got String", - pcall_err(set_virtual_text, id1, 0, { { 'very' }, 'texty' }, {}) + pcall_err(set_virtual_text, 0, id1, 0, { { 'very' }, 'texty' }, {}) ) end) it('can be retrieved', function() - local get_extmarks = curbufmeths.get_extmarks - local line_count = curbufmeths.line_count + local get_extmarks = meths.nvim_buf_get_extmarks + local line_count = meths.nvim_buf_line_count local s1 = { { 'Köttbullar', 'Comment' }, { 'Kräuterbutter' } } local s2 = { { 'こんにちは', 'Comment' } } - set_virtual_text(id1, 0, s1, {}) + set_virtual_text(0, id1, 0, s1, {}) eq({ { 1, @@ -719,10 +719,10 @@ describe('Buffer highlighting', function() virt_text_hide = false, }, }, - }, get_extmarks(id1, { 0, 0 }, { 0, -1 }, { details = true })) + }, get_extmarks(0, id1, { 0, 0 }, { 0, -1 }, { details = true })) - local lastline = line_count() - set_virtual_text(id1, line_count(), s2, {}) + local lastline = line_count(0) + set_virtual_text(0, id1, line_count(0), s2, {}) eq({ { 3, @@ -739,9 +739,9 @@ describe('Buffer highlighting', function() virt_text_hide = false, }, }, - }, get_extmarks(id1, { lastline, 0 }, { lastline, -1 }, { details = true })) + }, get_extmarks(0, id1, { lastline, 0 }, { lastline, -1 }, { details = true })) - eq({}, get_extmarks(id1, { lastline + 9000, 0 }, { lastline + 9000, -1 }, {})) + eq({}, get_extmarks(0, id1, { lastline + 9000, 0 }, { lastline + 9000, -1 }, {})) end) it('is not highlighted by visual selection', function() @@ -814,7 +814,7 @@ describe('Buffer highlighting', function() | ]]) - clear_namespace(-1, 0, -1) + clear_namespace(0, -1, 0, -1) screen:expect([[ ^1 + 2{1:$} | 3 +{1:$} | @@ -869,7 +869,7 @@ describe('Buffer highlighting', function() end) it('works with color column', function() - eq(-1, set_virtual_text(-1, 3, { { '暗x事', 'Comment' } }, {})) + eq(-1, set_virtual_text(0, -1, 3, { { '暗x事', 'Comment' } }, {})) screen:expect { grid = [[ ^1 + 2 {3:=}{2: 3} | @@ -898,12 +898,11 @@ describe('Buffer highlighting', function() end) it('and virtual text use the same namespace counter', function() - local set_virtual_text = curbufmeths.set_virtual_text - eq(1, add_highlight(0, 'String', 0, 0, -1)) - eq(2, set_virtual_text(0, 0, { { '= text', 'Comment' } }, {})) + eq(1, add_highlight(0, 0, 'String', 0, 0, -1)) + eq(2, set_virtual_text(0, 0, 0, { { '= text', 'Comment' } }, {})) eq(3, meths.nvim_create_namespace('my-ns')) - eq(4, add_highlight(0, 'String', 0, 0, -1)) - eq(5, set_virtual_text(0, 0, { { '= text', 'Comment' } }, {})) + eq(4, add_highlight(0, 0, 'String', 0, 0, -1)) + eq(5, set_virtual_text(0, 0, 0, { { '= text', 'Comment' } }, {})) eq(6, meths.nvim_create_namespace('other-ns')) end) end) diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 99f6e2eed8..a26c529396 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -10,7 +10,6 @@ local source = helpers.source local exec_capture = helpers.exec_capture local dedent = helpers.dedent local command = helpers.command -local curbufmeths = helpers.curbufmeths local screen @@ -503,7 +502,7 @@ describe('Command-line coloring', function() ]])) eq( { '', ':', 'E888 detected for \\ze*', ':', 'E888 detected for \\zs*' }, - curbufmeths.get_lines(0, -1, false) + meths.nvim_buf_get_lines(0, 0, -1, false) ) eq('', funcs.execute('messages')) end) @@ -646,7 +645,7 @@ describe('Ex commands coloring', function() ]])) eq( { '', 'E888 detected for \\ze*', 'E888 detected for \\zs*' }, - curbufmeths.get_lines(0, -1, false) + meths.nvim_buf_get_lines(0, 0, -1, false) ) eq('', funcs.execute('messages')) end) @@ -725,10 +724,10 @@ describe('Ex commands coloring', function() end) describe('Expressions coloring support', function() it('works', function() - meths.nvim_command('hi clear NvimNumber') - meths.nvim_command('hi clear NvimNestingParenthesis') - meths.nvim_command('hi NvimNumber guifg=Blue2') - meths.nvim_command('hi NvimNestingParenthesis guifg=Yellow') + command('hi clear NvimNumber') + command('hi clear NvimNestingParenthesis') + command('hi NvimNumber guifg=Blue2') + command('hi NvimNestingParenthesis guifg=Yellow') feed(':echo <C-r>=(((1)))') screen:expect([[ | @@ -739,8 +738,8 @@ describe('Expressions coloring support', function() it('does not use Nvim_color_expr', function() meths.nvim_set_var('Nvim_color_expr', 42) -- Used to error out due to failing to get callback. - meths.nvim_command('hi clear NvimNumber') - meths.nvim_command('hi NvimNumber guifg=Blue2') + command('hi clear NvimNumber') + command('hi NvimNumber guifg=Blue2') feed(':<C-r>=1') screen:expect([[ | @@ -749,12 +748,12 @@ describe('Expressions coloring support', function() ]]) end) it('works correctly with non-ASCII and control characters', function() - meths.nvim_command('hi clear NvimStringBody') - meths.nvim_command('hi clear NvimStringQuote') - meths.nvim_command('hi clear NvimInvalid') - meths.nvim_command('hi NvimStringQuote guifg=Blue3') - meths.nvim_command('hi NvimStringBody guifg=Blue4') - meths.nvim_command('hi NvimInvalid guifg=Red guibg=Blue') + command('hi clear NvimStringBody') + command('hi clear NvimStringQuote') + command('hi clear NvimInvalid') + command('hi NvimStringQuote guifg=Blue3') + command('hi NvimStringBody guifg=Blue4') + command('hi NvimInvalid guifg=Red guibg=Blue') feed('i<C-r>="«»"«»') screen:expect([[ | diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 91a5f10c84..42c9c706d1 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -9,7 +9,6 @@ local exec = helpers.exec local expect_events = helpers.expect_events local meths = helpers.meths local funcs = helpers.funcs -local curbufmeths = helpers.curbufmeths local command = helpers.command local eq = helpers.eq local assert_alive = helpers.assert_alive @@ -244,7 +243,7 @@ describe('decorations providers', function() -- spell=false with higher priority does disable spell local ns = meths.nvim_create_namespace "spell" - local id = curbufmeths.set_extmark(ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false }) + local id = meths.nvim_buf_set_extmark(0, ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false }) screen:expect{grid=[[ I am well written text. | @@ -267,7 +266,7 @@ describe('decorations providers', function() command('echo ""') -- spell=false with lower priority doesn't disable spell - curbufmeths.set_extmark(ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false }) + meths.nvim_buf_set_extmark(0, ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false }) screen:expect{grid=[[ I am well written text. | diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 645cce25aa..944e40876f 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -12,12 +12,13 @@ local exec = helpers.exec local exec_lua = helpers.exec_lua local insert = helpers.insert local meths = helpers.meths -local curbufmeths = helpers.curbufmeths local funcs = helpers.funcs local run = helpers.run local pcall_err = helpers.pcall_err local tbl_contains = vim.tbl_contains -local curbuf, curwin, curtab = helpers.curbuf, helpers.curwin, helpers.curtab +local curbuf = helpers.meths.nvim_get_current_buf +local curwin = helpers.meths.nvim_get_current_win +local curtab = helpers.meths.nvim_get_current_tabpage local NIL = vim.NIL describe('float window', function() @@ -6624,7 +6625,7 @@ describe('float window', function() for i = 1,5 do feed(i.."<c-w>w") feed_command("enew") - curbufmeths.set_lines(0,-1,true,{tostring(i)}) + meths.nvim_buf_set_lines(0, 0,-1,true,{tostring(i)}) end if multigrid then diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 857fd29f19..c2a7317da0 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -5,7 +5,6 @@ local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, exec = helpers.command, helpers.exec local eval = helpers.eval local feed_command, eq = helpers.feed_command, helpers.eq -local curbufmeths = helpers.curbufmeths local funcs = helpers.funcs local meths = helpers.meths local exec_lua = helpers.exec_lua @@ -2088,7 +2087,7 @@ describe("'winhighlight' highlight", function() end) it('can override NonText, Conceal and EndOfBuffer', function() - curbufmeths.set_lines(0, -1, true, { 'raa\000' }) + meths.nvim_buf_set_lines(0, 0, -1, true, { 'raa\000' }) command('call matchaddpos("Conceal", [[1,2]], 0, -1, {"conceal": "#"})') command('set cole=2 cocu=nvic') command('split') diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index c97fd02562..e82f889553 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -14,7 +14,6 @@ local ok = helpers.ok local retry = helpers.retry local source = helpers.source local poke_eventloop = helpers.poke_eventloop -local nvim = helpers.nvim local sleep = vim.uv.sleep local testprg = helpers.testprg local assert_alive = helpers.assert_alive @@ -1898,20 +1897,20 @@ describe("'inccommand' with 'gdefault'", function() common_setup(nil, 'nosplit', '{') command('set gdefault') feed(':s/{\\n') - eq({ mode = 'c', blocking = false }, nvim('get_mode')) + eq({ mode = 'c', blocking = false }, meths.nvim_get_mode()) feed('/A<Enter>') expect('A') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('with multiline text and range, does not lock up #7244', function() common_setup(nil, 'nosplit', '{\n\n{') command('set gdefault') feed(':%s/{\\n') - eq({ mode = 'c', blocking = false }, nvim('get_mode')) + eq({ mode = 'c', blocking = false }, meths.nvim_get_mode()) feed('/A<Enter>') expect('A\nA') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('does not crash on zero-width matches #7485', function() @@ -1920,9 +1919,9 @@ describe("'inccommand' with 'gdefault'", function() feed('gg') feed('Vj') feed(':s/\\%V') - eq({ mode = 'c', blocking = false }, nvim('get_mode')) + eq({ mode = 'c', blocking = false }, meths.nvim_get_mode()) feed('<Esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) end) it('removes highlights after abort for a zero-width match', function() diff --git a/test/functional/ui/linematch_spec.lua b/test/functional/ui/linematch_spec.lua index ca02fa6403..98ada8f6c4 100644 --- a/test/functional/ui/linematch_spec.lua +++ b/test/functional/ui/linematch_spec.lua @@ -1118,9 +1118,9 @@ describe('regressions', function() screen = Screen.new(100, 20) screen:attach() -- line must be greater than MATCH_CHAR_MAX_LEN - helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1000) .. 'hello' }) + helpers.meths.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1000) .. 'hello' }) helpers.exec 'vnew' - helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1010) .. 'world' }) + helpers.meths.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1010) .. 'world' }) helpers.exec 'windo diffthis' end) @@ -1133,9 +1133,9 @@ describe('regressions', function() for i = 0, 29 do lines[#lines + 1] = tostring(i) end - helpers.curbufmeths.set_lines(0, -1, false, lines) + helpers.meths.nvim_buf_set_lines(0, 0, -1, false, lines) helpers.exec 'vnew' - helpers.curbufmeths.set_lines(0, -1, false, { '00', '29' }) + helpers.meths.nvim_buf_set_lines(0, 0, -1, false, { '00', '29' }) helpers.exec 'windo diffthis' feed('<C-e>') screen:expect { diff --git a/test/functional/ui/multigrid_spec.lua b/test/functional/ui/multigrid_spec.lua index 094e27e69a..600b08744f 100644 --- a/test/functional/ui/multigrid_spec.lua +++ b/test/functional/ui/multigrid_spec.lua @@ -5,7 +5,7 @@ local feed, command, insert = helpers.feed, helpers.command, helpers.insert local eq = helpers.eq local funcs = helpers.funcs local meths = helpers.meths -local curwin = helpers.curwin +local curwin = helpers.meths.nvim_get_current_win local poke_eventloop = helpers.poke_eventloop diff --git a/test/functional/ui/spell_spec.lua b/test/functional/ui/spell_spec.lua index c9730cee97..f52ae29562 100644 --- a/test/functional/ui/spell_spec.lua +++ b/test/functional/ui/spell_spec.lua @@ -7,7 +7,6 @@ local exec = helpers.exec local feed = helpers.feed local insert = helpers.insert local meths = helpers.meths -local curbufmeths = helpers.curbufmeths local is_os = helpers.is_os describe("'spell'", function() @@ -262,7 +261,7 @@ describe("'spell'", function() exec('echo ""') local ns = meths.nvim_create_namespace('spell') -- extmark with spell=true enables spell - local id = curbufmeths.set_extmark(ns, 1, 4, { end_row = 1, end_col = 10, spell = true }) + local id = meths.nvim_buf_set_extmark(0, ns, 1, 4, { end_row = 1, end_col = 10, spell = true }) screen:expect([[ {3:#include }{4:<stdbool.h>} | {5:bool} {1:func}({5:void}); | @@ -278,9 +277,9 @@ describe("'spell'", function() {0:~ }|*4 | ]]) - curbufmeths.del_extmark(ns, id) + meths.nvim_buf_del_extmark(0, ns, id) -- extmark with spell=false disables spell - id = curbufmeths.set_extmark(ns, 2, 18, { end_row = 2, end_col = 26, spell = false }) + id = meths.nvim_buf_set_extmark(0, ns, 2, 18, { end_row = 2, end_col = 26, spell = false }) screen:expect([[ {3:#include }{4:<stdbool.h>} | {5:bool} ^func({5:void}); | @@ -297,7 +296,7 @@ describe("'spell'", function() {6:search hit TOP, continuing at BOTTOM} | ]]) exec('echo ""') - curbufmeths.del_extmark(ns, id) + meths.nvim_buf_del_extmark(0, ns, id) screen:expect([[ {3:#include }{4:<stdbool.h>} | {5:bool} func({5:void}); | @@ -369,7 +368,7 @@ describe("'spell'", function() call setline(1, "This is some text without any spell errors.") ]]) local ns = meths.nvim_create_namespace('spell') - curbufmeths.set_extmark(ns, 0, 0, { hl_group = 'WarningMsg', end_col = 43 }) + meths.nvim_buf_set_extmark(0, ns, 0, 0, { hl_group = 'WarningMsg', end_col = 43 }) screen:expect([[ {6:^This is some text without any spell errors.}| {0:~ }| diff --git a/test/functional/ui/title_spec.lua b/test/functional/ui/title_spec.lua index 222850ee42..598952404d 100644 --- a/test/functional/ui/title_spec.lua +++ b/test/functional/ui/title_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command -local curwin = helpers.curwin +local curwin = helpers.meths.nvim_get_current_win local eq = helpers.eq local exec_lua = helpers.exec_lua local feed = helpers.feed diff --git a/test/functional/ui/winbar_spec.lua b/test/functional/ui/winbar_spec.lua index 6a09d3a555..5e914952e3 100644 --- a/test/functional/ui/winbar_spec.lua +++ b/test/functional/ui/winbar_spec.lua @@ -8,7 +8,6 @@ local eq = helpers.eq local poke_eventloop = helpers.poke_eventloop local feed = helpers.feed local funcs = helpers.funcs -local curwin = helpers.curwin local pcall_err = helpers.pcall_err describe('winbar', function() @@ -52,7 +51,7 @@ describe('winbar', function() ]]) -- winbar is excluded from the heights returned by winheight() and getwininfo() eq(11, funcs.winheight(0)) - local win_info = funcs.getwininfo(curwin().id)[1] + local win_info = funcs.getwininfo(meths.nvim_get_current_win().id)[1] eq(11, win_info.height) eq(1, win_info.winbar) end) diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 6249dcc363..29841d052a 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local neq, eq, command = helpers.neq, helpers.eq, helpers.command -local clear, curbufmeths = helpers.clear, helpers.curbufmeths +local clear = helpers.clear local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval local insert, pcall_err = helpers.insert, helpers.pcall_err local matches = helpers.matches @@ -97,8 +97,8 @@ describe('eval-API', function() ) -- But others, like nvim_buf_set_lines(), which just changes text, is OK. - curbufmeths.set_lines(0, -1, 1, { 'wow!' }) - eq({ 'wow!' }, curbufmeths.get_lines(0, -1, 1)) + meths.nvim_buf_set_lines(0, 0, -1, 1, { 'wow!' }) + eq({ 'wow!' }, meths.nvim_buf_get_lines(0, 0, -1, 1)) -- Turning the cmdwin buffer into a terminal buffer would be pretty weird. eq( @@ -143,11 +143,11 @@ describe('eval-API', function() end) it('get_lines and set_lines use NL to represent NUL', function() - curbufmeths.set_lines(0, -1, true, { 'aa\0', 'b\0b' }) + meths.nvim_buf_set_lines(0, 0, -1, true, { 'aa\0', 'b\0b' }) eq({ 'aa\n', 'b\nb' }, eval('nvim_buf_get_lines(0, 0, -1, 1)')) command('call nvim_buf_set_lines(0, 1, 2, v:true, ["xx", "\\nyy"])') - eq({ 'aa\0', 'xx', '\0yy' }, curbufmeths.get_lines(0, -1, 1)) + eq({ 'aa\0', 'xx', '\0yy' }, meths.nvim_buf_get_lines(0, 0, -1, 1)) end) it('that are FUNC_ATTR_NOEVAL cannot be called', function() diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua index c93e55df5f..34206b15ae 100644 --- a/test/functional/vimscript/buf_functions_spec.lua +++ b/test/functional/vimscript/buf_functions_spec.lua @@ -6,10 +6,6 @@ local funcs = helpers.funcs local meths = helpers.meths local command = helpers.command local exc_exec = helpers.exc_exec -local bufmeths = helpers.bufmeths -local curbufmeths = helpers.curbufmeths -local curwinmeths = helpers.curwinmeths -local curtabmeths = helpers.curtabmeths local get_pathsep = helpers.get_pathsep local rmdir = helpers.rmdir local pcall_err = helpers.pcall_err @@ -196,7 +192,7 @@ describe('getbufline() function', function() end) it('returns empty list when range is invalid', function() eq({}, funcs.getbufline(1, 0)) - curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'baz' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'baz' }) eq({}, funcs.getbufline(1, 2, 1)) eq({}, funcs.getbufline(1, -10, -20)) eq({}, funcs.getbufline(1, -2, -1)) @@ -205,9 +201,9 @@ describe('getbufline() function', function() it('returns expected lines', function() meths.nvim_set_option_value('hidden', true, {}) command('file ' .. fname) - curbufmeths.set_lines(0, 1, false, { 'foo\0', '\0bar', 'baz' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'foo\0', '\0bar', 'baz' }) command('edit ' .. fname2) - curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' }) eq({ 'foo\n', '\nbar', 'baz' }, funcs.getbufline(1, 1, 9999)) eq({ 'abc\n', '\ndef', 'ghi' }, funcs.getbufline(2, 1, 9999)) eq({ 'foo\n', '\nbar', 'baz' }, funcs.getbufline(1, 1, '$')) @@ -247,7 +243,7 @@ describe('getbufvar() function', function() -- But with window-local options it probably does not what you expect command('setl number') -- (note that current window’s buffer is 2, but getbufvar() receives 1) - eq({ id = 2 }, curwinmeths.get_buf()) + eq({ id = 2 }, meths.nvim_win_get_buf(0)) eq(1, funcs.getbufvar(1, '&number')) eq(1, funcs.getbufvar(1, '&l:number')) -- You can get global value though, if you find this useful. @@ -255,9 +251,9 @@ describe('getbufvar() function', function() end) it('returns expected variable value', function() eq(2, funcs.getbufvar(1, 'changedtick')) - curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' }) + meths.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' }) eq(3, funcs.getbufvar(1, 'changedtick')) - curbufmeths.set_var('test', true) + meths.nvim_buf_set_var(0, 'test', true) eq(true, funcs.getbufvar(1, 'test')) eq({ test = true, changedtick = 3 }, funcs.getbufvar(1, '')) command('new') @@ -288,9 +284,9 @@ describe('setbufvar() function', function() eq(false, meths.nvim_get_option_value('number', {})) command('split') command('new') - eq(2, bufmeths.get_number(curwinmeths.get_buf())) + eq(2, meths.nvim_buf_get_number(meths.nvim_win_get_buf(0))) funcs.setbufvar(1, '&number', true) - local windows = curtabmeths.list_wins() + local windows = meths.nvim_tabpage_list_wins(0) eq(false, meths.nvim_get_option_value('number', { win = windows[1].id })) eq(true, meths.nvim_get_option_value('number', { win = windows[2].id })) eq(false, meths.nvim_get_option_value('number', { win = windows[3].id })) @@ -309,11 +305,11 @@ describe('setbufvar() function', function() local buf1 = meths.nvim_get_current_buf() command('split') command('new') - eq(2, curbufmeths.get_number()) + eq(2, meths.nvim_buf_get_number(0)) funcs.setbufvar(1, 'number', true) - eq(true, bufmeths.get_var(buf1, 'number')) + eq(true, meths.nvim_buf_get_var(buf1, 'number')) eq('Vim(call):E461: Illegal variable name: b:', exc_exec('call setbufvar(1, "", 0)')) - eq(true, bufmeths.get_var(buf1, 'number')) + eq(true, meths.nvim_buf_get_var(buf1, 'number')) eq( 'Vim:E46: Cannot change read-only variable "b:changedtick"', pcall_err(funcs.setbufvar, 1, 'changedtick', true) diff --git a/test/functional/vimscript/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua index 04ebc9cdc9..203c9a22e5 100644 --- a/test/functional/vimscript/changedtick_spec.lua +++ b/test/functional/vimscript/changedtick_spec.lua @@ -10,14 +10,13 @@ local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err local exec_capture = helpers.exec_capture -local curbufmeths = helpers.curbufmeths before_each(clear) local function changedtick() - local ct = curbufmeths.get_changedtick() - eq(ct, curbufmeths.get_var('changedtick')) - eq(ct, curbufmeths.get_var('changedtick')) + local ct = meths.nvim_buf_get_changedtick(0) + eq(ct, meths.nvim_buf_get_var(0, 'changedtick')) + eq(ct, meths.nvim_buf_get_var(0, 'changedtick')) eq(ct, eval('b:changedtick')) eq(ct, eval('b:["changedtick"]')) eq(ct, eval('b:.changedtick')) @@ -46,11 +45,11 @@ describe('b:changedtick', function() it('increments at bdel', function() command('new') eq(2, changedtick()) - local bnr = curbufmeths.get_number() + local bnr = meths.nvim_buf_get_number(0) eq(2, bnr) command('bdel') eq(3, funcs.getbufvar(bnr, 'changedtick')) - eq(1, curbufmeths.get_number()) + eq(1, meths.nvim_buf_get_number(0)) end) it('fails to be changed by user', function() local ct = changedtick() @@ -72,7 +71,7 @@ describe('b:changedtick', function() 'Vim(let):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'let d.changedtick = ' .. ctn) ) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.set_var, 'changedtick', ctn)) + eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_set_var, 0, 'changedtick', ctn)) eq( 'Vim(unlet):E795: Cannot delete variable b:changedtick', @@ -90,7 +89,7 @@ describe('b:changedtick', function() 'Vim(unlet):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'unlet d.changedtick') ) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, 'changedtick')) + eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_del_var, 0, 'changedtick')) eq(ct, changedtick()) eq( diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua index c336f3cb2d..ced29a6b76 100644 --- a/test/functional/vimscript/ctx_functions_spec.lua +++ b/test/functional/vimscript/ctx_functions_spec.lua @@ -7,7 +7,7 @@ local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed local map = vim.tbl_map -local nvim = helpers.nvim +local meths = helpers.meths local parse_context = helpers.parse_context local exec_capture = helpers.exec_capture local source = helpers.source @@ -126,16 +126,16 @@ describe('context functions', function() end) it('saves and restores global variables properly', function() - 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) eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) call('ctxpush') call('ctxpush', { 'gvars' }) - nvim('del_var', 'one') - nvim('del_var', 'Two') - nvim('del_var', 'THREE') + meths.nvim_del_var('one') + meths.nvim_del_var('Two') + meths.nvim_del_var('THREE') eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one')) eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two')) eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE')) @@ -143,9 +143,9 @@ describe('context functions', function() call('ctxpop') eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) - nvim('del_var', 'one') - nvim('del_var', 'Two') - nvim('del_var', 'THREE') + meths.nvim_del_var('one') + meths.nvim_del_var('Two') + meths.nvim_del_var('THREE') eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one')) eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two')) eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE')) @@ -300,9 +300,9 @@ describe('context functions', function() feed('G') feed('gg') command('edit ' .. fname2) - 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 with_regs = { ['regs'] = { @@ -412,14 +412,14 @@ describe('context functions', function() end) it('sets context dictionary at index in context stack', function() - 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) call('ctxpush') local ctx1 = call('ctxget') - nvim('set_var', 'one', 'a') - nvim('set_var', 'Two', 'b') - nvim('set_var', 'THREE', 'c') + meths.nvim_set_var('one', 'a') + meths.nvim_set_var('Two', 'b') + meths.nvim_set_var('THREE', 'c') call('ctxpush') call('ctxpush') local ctx2 = call('ctxget') @@ -431,7 +431,7 @@ describe('context functions', function() eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) call('ctxpop') eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) - nvim('set_var', 'one', 1.5) + meths.nvim_set_var('one', 1.5) eq({ 1.5, 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) call('ctxpop') eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) diff --git a/test/functional/vimscript/errorlist_spec.lua b/test/functional/vimscript/errorlist_spec.lua index b2afafe08c..2977612247 100644 --- a/test/functional/vimscript/errorlist_spec.lua +++ b/test/functional/vimscript/errorlist_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local command = helpers.command local eq = helpers.eq local exc_exec = helpers.exc_exec -local get_cur_win_var = helpers.curwinmeths.get_var +local get_win_var = helpers.meths.nvim_win_get_var describe('setqflist()', function() local setqflist = helpers.funcs.setqflist @@ -26,15 +26,15 @@ describe('setqflist()', function() it('sets w:quickfix_title', function() setqflist({ '' }, 'r', 'foo') command('copen') - eq('foo', get_cur_win_var('quickfix_title')) + eq('foo', get_win_var(0, 'quickfix_title')) setqflist({}, 'r', { ['title'] = 'qf_title' }) - eq('qf_title', get_cur_win_var('quickfix_title')) + eq('qf_title', get_win_var(0, 'quickfix_title')) end) it('allows string {what} for backwards compatibility', function() setqflist({}, 'r', '5') command('copen') - eq('5', get_cur_win_var('quickfix_title')) + eq('5', get_win_var(0, 'quickfix_title')) end) it('requires a dict for {what}', function() @@ -67,9 +67,9 @@ describe('setloclist()', function() setloclist(1, {}, 'r', 'foo') setloclist(2, {}, 'r', 'bar') command('lopen') - eq('bar', get_cur_win_var('quickfix_title')) + eq('bar', get_win_var(0, 'quickfix_title')) command('lclose | wincmd w | lopen') - eq('foo', get_cur_win_var('quickfix_title')) + eq('foo', get_win_var(0, 'quickfix_title')) end) it("doesn't crash when when window is closed in the middle #13721", function() diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index e11c8af157..9edf54898b 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -9,7 +9,6 @@ local expect = helpers.expect local feed = helpers.feed local funcs = helpers.funcs local meths = helpers.meths -local nvim = helpers.nvim local source = helpers.source local command = helpers.command local exec_capture = helpers.exec_capture @@ -37,16 +36,16 @@ describe('maparg()', function() } it('returns a dictionary', function() - nvim('command', 'nnoremap foo bar') + command('nnoremap foo bar') eq('bar', funcs.maparg('foo')) eq(foo_bar_map_table, funcs.maparg('foo', 'n', false, true)) end) it('returns 1 for silent when <silent> is used', function() - nvim('command', 'nnoremap <silent> foo bar') + command('nnoremap <silent> foo bar') eq(1, funcs.maparg('foo', 'n', false, true)['silent']) - nvim('command', 'nnoremap baz bat') + command('nnoremap baz bat') eq(0, funcs.maparg('baz', 'n', false, true)['silent']) end) @@ -59,8 +58,8 @@ describe('maparg()', function() end) it('returns the same value for noremap and <script>', function() - nvim('command', 'inoremap <script> hello world') - nvim('command', 'inoremap this that') + command('inoremap <script> hello world') + command('inoremap this that') eq( funcs.maparg('hello', 'i', false, true)['noremap'], funcs.maparg('this', 'i', false, true)['noremap'] @@ -69,14 +68,14 @@ describe('maparg()', function() it('returns a boolean for buffer', function() -- Open enough windows to know we aren't on buffer number 1 - nvim('command', 'new') - nvim('command', 'new') - nvim('command', 'new') - nvim('command', 'cnoremap <buffer> this that') + command('new') + command('new') + command('new') + command('cnoremap <buffer> this that') eq(1, funcs.maparg('this', 'c', false, true)['buffer']) -- Global will return 0 always - nvim('command', 'nnoremap other another') + command('nnoremap other another') eq(0, funcs.maparg('other', 'n', false, true)['buffer']) end) @@ -89,7 +88,7 @@ describe('maparg()', function() nnoremap fizz :call <SID>maparg_test_function()<CR> ]]) eq(1, funcs.maparg('fizz', 'n', false, true)['sid']) - eq('testing', nvim('call_function', '<SNR>1_maparg_test_function', {})) + eq('testing', meths.nvim_call_function('<SNR>1_maparg_test_function', {})) end) it('works with <F12> and others', function() diff --git a/test/functional/vimscript/msgpack_functions_spec.lua b/test/functional/vimscript/msgpack_functions_spec.lua index 824c1e8751..b6980befd9 100644 --- a/test/functional/vimscript/msgpack_functions_spec.lua +++ b/test/functional/vimscript/msgpack_functions_spec.lua @@ -3,7 +3,7 @@ local clear = helpers.clear local funcs = helpers.funcs local eval, eq = helpers.eval, helpers.eq local command = helpers.command -local nvim = helpers.nvim +local meths = helpers.meths local exc_exec = helpers.exc_exec local is_os = helpers.is_os @@ -12,7 +12,7 @@ describe('msgpack*() functions', function() local obj_test = function(msg, obj) it(msg, function() - nvim('set_var', 'obj', obj) + meths.nvim_set_var('obj', obj) eq(obj, eval('msgpackparse(msgpackdump(g:obj))')) eq(obj, eval('msgpackparse(msgpackdump(g:obj, "B"))')) end) diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua index efc3c451f8..2e96ccfead 100644 --- a/test/functional/vimscript/null_spec.lua +++ b/test/functional/vimscript/null_spec.lua @@ -1,6 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local curbufmeths = helpers.curbufmeths local exc_exec = helpers.exc_exec local command = helpers.command local clear = helpers.clear @@ -72,10 +71,10 @@ describe('NULL', function() null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) null_expr_test('does not crash append()', 'append(0, L)', 0, 0, function() - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false)) end) null_expr_test('does not crash setline()', 'setline(1, L)', 0, 0, function() - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false)) end) null_expr_test('is identical to itself', 'L is L', 0, 1) null_expr_test('can be sliced', 'L[:]', 0, {}) @@ -184,7 +183,7 @@ describe('NULL', function() 0, '', function() - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false)) end ) null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, 0) diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index e1faf1e464..19a5d4c806 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -4,14 +4,14 @@ local helpers = require('test.functional.helpers')(after_each) local assert_alive = helpers.assert_alive local testprg = helpers.testprg -local eq, call, clear, eval, feed_command, feed, nvim = +local eq, call, clear, eval, feed_command, feed, meths = helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command, helpers.feed, - helpers.nvim + helpers.meths local command = helpers.command local insert = helpers.insert local expect = helpers.expect @@ -220,8 +220,8 @@ describe('system()', function() end) it('prints verbose information', function() - nvim('set_option_value', 'shell', 'fake_shell', {}) - nvim('set_option_value', 'shellcmdflag', 'cmdflag', {}) + meths.nvim_set_option_value('shell', 'fake_shell', {}) + meths.nvim_set_option_value('shellcmdflag', 'cmdflag', {}) screen:try_resize(72, 14) feed(':4verbose echo system("echo hi")<cr>') @@ -346,7 +346,7 @@ describe('system()', function() input[#input + 1] = '01234567890ABCDEFabcdef' end input = table.concat(input, '\n') - nvim('set_var', 'input', input) + meths.nvim_set_var('input', input) eq(input, eval('system("cat -", g:input)')) end) end) @@ -480,7 +480,7 @@ describe('systemlist()', function() for _ = 1, 0xffff do input[#input + 1] = '01234567890ABCDEFabcdef' end - nvim('set_var', 'input', input) + meths.nvim_set_var('input', input) eq(input, eval('systemlist("cat -", g:input)')) end) end) diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 0293d30380..02a5880949 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -4,7 +4,7 @@ local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs local exc_exec = helpers.exc_exec -local curbufmeths = helpers.curbufmeths +local meths = helpers.meths local load_adjust = helpers.load_adjust local retry = helpers.retry @@ -111,7 +111,7 @@ describe('timers', function() [1] = { bold = true, foreground = Screen.colors.Blue }, }) - curbufmeths.set_lines(0, -1, true, { 'ITEM 1', 'ITEM 2' }) + meths.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' }) source([[ let g:cont = 0 func! AddItem(timer) diff --git a/test/functional/vimscript/wait_spec.lua b/test/functional/vimscript/wait_spec.lua index 03cdbc12fa..e6b244538d 100644 --- a/test/functional/vimscript/wait_spec.lua +++ b/test/functional/vimscript/wait_spec.lua @@ -7,14 +7,14 @@ local eq = helpers.eq local feed = helpers.feed local feed_command = helpers.feed_command local next_msg = helpers.next_msg -local nvim = helpers.nvim +local meths = helpers.meths local source = helpers.source local pcall_err = helpers.pcall_err before_each(function() clear() - 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) end) describe('wait()', function() @@ -61,13 +61,13 @@ describe('wait()', function() -- XXX: flaky (#11137) helpers.retry(nil, nil, function() - nvim('set_var', 'counter', 0) + meths.nvim_set_var('counter', 0) eq(-1, call('wait', 20, 'Count() >= 5', 99999)) end) - nvim('set_var', 'counter', 0) + meths.nvim_set_var('counter', 0) eq(0, call('wait', 10000, 'Count() >= 5', 5)) - eq(5, nvim('get_var', 'counter')) + eq(5, meths.nvim_get_var('counter')) end) it('validates args', function() diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim index 88a29968fe..d277ff72df 100644 --- a/test/old/testdir/test_functions.vim +++ b/test/old/testdir/test_functions.vim @@ -2104,7 +2104,7 @@ func Test_trim() call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx")) call assert_equal("RESERVE", trim("你RESERVE好", "你好")) call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好")) - call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", )) + call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses")) |