From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/vimscript/api_functions_spec.lua | 10 +++--- test/functional/vimscript/buf_functions_spec.lua | 26 ++++++-------- test/functional/vimscript/changedtick_spec.lua | 15 ++++---- test/functional/vimscript/ctx_functions_spec.lua | 40 +++++++++++----------- test/functional/vimscript/errorlist_spec.lua | 12 +++---- test/functional/vimscript/map_functions_spec.lua | 23 ++++++------- .../vimscript/msgpack_functions_spec.lua | 4 +-- test/functional/vimscript/null_spec.lua | 7 ++-- test/functional/vimscript/system_spec.lua | 12 +++---- test/functional/vimscript/timer_spec.lua | 4 +-- test/functional/vimscript/wait_spec.lua | 12 +++---- 11 files changed, 79 insertions(+), 86 deletions(-) (limited to 'test/functional/vimscript') 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 is used', function() - nvim('command', 'nnoremap foo bar') + command('nnoremap 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