diff options
| author | Lewis Russell <lewis6991@gmail.com> | 2024-01-12 13:11:28 +0000 |
|---|---|---|
| committer | Lewis Russell <lewis6991@gmail.com> | 2024-01-12 17:53:27 +0000 |
| commit | 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e (patch) | |
| tree | 0cbb2cf8dac8b4f43109dc6f7a4051dfbea23f12 /test/functional | |
| parent | c30f2e3182e3b50e7c03932027ac55edfc8ada4a (diff) | |
| download | rneovim-4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e.tar.gz rneovim-4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e.tar.bz2 rneovim-4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e.zip | |
test: normalise nvim bridge functions
- remove helpers.cur*meths
- remove helpers.nvim
Diffstat (limited to 'test/functional')
78 files changed, 1700 insertions, 1753 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 }) |