From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/api/vim_spec.lua | 1616 +++++++++++++++++++------------------- 1 file changed, 802 insertions(+), 814 deletions(-) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ba2042d585..aa3b4419cc 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -8,13 +8,13 @@ local assert_alive = helpers.assert_alive local NIL = vim.NIL local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq local command = helpers.command -local command_output = helpers.meths.command_output +local command_output = helpers.api.command_output local exec = helpers.exec local exec_capture = helpers.exec_capture local eval = helpers.eval local expect = helpers.expect -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local matches = helpers.matches local pesc = vim.pesc local mkdir_p = helpers.mkdir_p @@ -71,7 +71,7 @@ describe('API', function() end) it('handles errors in async requests', function() - local error_types = meths.nvim_get_api_info()[2].error_types + local error_types = api.nvim_get_api_info()[2].error_types nvim_async('bogus') eq({ 'notification', @@ -83,7 +83,7 @@ describe('API', function() end) it('failed async request emits nvim_error_event', function() - local error_types = meths.nvim_get_api_info()[2].error_types + local error_types = api.nvim_get_api_info()[2].error_types nvim_async('command', 'bogus') eq({ 'notification', @@ -98,37 +98,37 @@ describe('API', function() command('split') command('autocmd WinEnter * startinsert') command('wincmd w') - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) end) describe('nvim_exec2', function() it('always returns table', function() -- In built version this results into `vim.empty_dict()` - eq({}, meths.nvim_exec2('echo "Hello"', {})) - eq({}, meths.nvim_exec2('echo "Hello"', { output = false })) - eq({ output = 'Hello' }, meths.nvim_exec2('echo "Hello"', { output = true })) + eq({}, api.nvim_exec2('echo "Hello"', {})) + eq({}, api.nvim_exec2('echo "Hello"', { output = false })) + eq({ output = 'Hello' }, api.nvim_exec2('echo "Hello"', { output = true })) end) it('default options', function() -- Should be equivalent to { output = false } - meths.nvim_exec2("let x0 = 'a'", {}) - eq('a', meths.nvim_get_var('x0')) + api.nvim_exec2("let x0 = 'a'", {}) + eq('a', api.nvim_get_var('x0')) end) it('one-line input', function() - meths.nvim_exec2("let x1 = 'a'", { output = false }) - eq('a', meths.nvim_get_var('x1')) + api.nvim_exec2("let x1 = 'a'", { output = false }) + eq('a', api.nvim_get_var('x1')) end) it(':verbose set {option}?', function() - meths.nvim_exec2('set nowrap', { output = false }) + api.nvim_exec2('set nowrap', { output = false }) eq( { output = 'nowrap\n\tLast set from anonymous :source' }, - meths.nvim_exec2('verbose set wrap?', { output = true }) + api.nvim_exec2('verbose set wrap?', { output = true }) ) -- Using script var to force creation of a script item - meths.nvim_exec2( + api.nvim_exec2( [[ let s:a = 1 set nowrap @@ -137,39 +137,39 @@ describe('API', function() ) eq( { output = 'nowrap\n\tLast set from anonymous :source (script id 1)' }, - meths.nvim_exec2('verbose set wrap?', { output = true }) + api.nvim_exec2('verbose set wrap?', { output = true }) ) end) it('multiline input', function() -- Heredoc + empty lines. - meths.nvim_exec2("let x2 = 'a'\n", { output = false }) - eq('a', meths.nvim_get_var('x2')) - meths.nvim_exec2('lua <")->empty() let s:a = 123 @@ -241,7 +241,7 @@ describe('API', function() eq( { output = '1\n0' }, - meths.nvim_exec2( + api.nvim_exec2( [[ echo expand("")->empty() function s:a() abort @@ -254,7 +254,7 @@ describe('API', function() end) it('non-ASCII input', function() - meths.nvim_exec2( + api.nvim_exec2( [=[ new exe "normal! i ax \n Ax " @@ -263,11 +263,11 @@ describe('API', function() { output = false } ) command('1') - eq(' --a1234-- ', meths.nvim_get_current_line()) + eq(' --a1234-- ', api.nvim_get_current_line()) command('2') - eq(' --A1234-- ', meths.nvim_get_current_line()) + eq(' --A1234-- ', api.nvim_get_current_line()) - meths.nvim_exec2( + api.nvim_exec2( [[ new call setline(1,['xxx']) @@ -276,7 +276,7 @@ describe('API', function() ]], { output = false } ) - eq('ñxx', meths.nvim_get_current_line()) + eq('ñxx', api.nvim_get_current_line()) end) it('execution error', function() @@ -284,7 +284,7 @@ describe('API', function() 'nvim_exec2(): Vim:E492: Not an editor command: bogus_command', pcall_err(request, 'nvim_exec2', 'bogus_command', {}) ) - eq('', meths.nvim_eval('v:errmsg')) -- v:errmsg was not updated. + eq('', api.nvim_eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) eq( @@ -319,7 +319,7 @@ describe('API', function() write_file(fname, 'echo "hello"\n') local sourcing_fname = tmpname() write_file(sourcing_fname, 'call nvim_exec2("source ' .. fname .. '", {"output": v:false})\n') - meths.nvim_exec2('set verbose=2', { output = false }) + api.nvim_exec2('set verbose=2', { output = false }) local traceback_output = dedent([[ line 0: sourcing "%s" line 0: sourcing "%s" @@ -336,7 +336,7 @@ describe('API', function() ) eq( { output = traceback_output }, - meths.nvim_exec2( + api.nvim_exec2( 'call nvim_exec2("source ' .. sourcing_fname .. '", {"output": v:false})', { output = true } ) @@ -348,10 +348,10 @@ describe('API', function() it('returns output', function() eq( { output = 'this is spinal tap' }, - meths.nvim_exec2('lua <]]) + api.nvim_input([[:echo "hi\nhi2"]]) -- Verify hit-enter prompt. - eq({ mode = 'r', blocking = true }, meths.nvim_get_mode()) - meths.nvim_input([[]]) + eq({ mode = 'r', blocking = true }, api.nvim_get_mode()) + api.nvim_input([[]]) -- Verify NO hit-enter prompt. command_output([[echo "hi\nhi2"]]) - eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('captures command output', function() @@ -500,7 +500,7 @@ describe('API', function() 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 }, meths.nvim_get_mode()) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('Vimscript execution error: fails with specific error', function() @@ -509,7 +509,7 @@ describe('API', function() 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 }, meths.nvim_get_mode()) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('does not cause heap buffer overflow with large output', function() @@ -521,12 +521,12 @@ describe('API', function() it('works', function() 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:')) + eq({ v1 = 'a', v2 = { 1, 2, { v3 = 3 } } }, api.nvim_eval('g:')) end) it('handles NULL-initialized strings correctly', function() - eq(1, meths.nvim_eval("matcharg(1) == ['', '']")) - eq({ '', '' }, meths.nvim_eval('matcharg(1)')) + eq(1, api.nvim_eval("matcharg(1) == ['', '']")) + eq({ '', '' }, api.nvim_eval('matcharg(1)')) end) it('works under deprecated name', function() @@ -541,10 +541,10 @@ describe('API', function() describe('nvim_call_function', function() it('works', function() - 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' })) + api.nvim_call_function('setqflist', { { { filename = 'something', lnum = 17 } }, 'r' }) + eq(17, api.nvim_call_function('getqflist', {})[1].lnum) + eq(17, api.nvim_call_function('eval', { 17 })) + eq('foo', api.nvim_call_function('simplify', { 'this/./is//redundant/../../../foo' })) end) it('Vimscript validation error: returns specific error, does NOT update v:errmsg', function() @@ -619,18 +619,18 @@ describe('API', function() ]]) -- :help Dictionary-function - eq('Hello, World!', meths.nvim_call_dict_function('g:test_dict_fn', 'F', { 'World' })) + eq('Hello, World!', api.nvim_call_dict_function('g:test_dict_fn', 'F', { 'World' })) -- Funcref is sent as NIL over RPC. - eq({ greeting = 'Hello', F = NIL }, meths.nvim_get_var('test_dict_fn')) + eq({ greeting = 'Hello', F = NIL }, api.nvim_get_var('test_dict_fn')) -- :help numbered-function - eq('Hi, Moon ...', meths.nvim_call_dict_function('g:test_dict_fn2', 'F2', { 'Moon' })) + eq('Hi, Moon ...', api.nvim_call_dict_function('g:test_dict_fn2', 'F2', { 'Moon' })) -- Funcref is sent as NIL over RPC. - eq({ greeting = 'Hi', F2 = NIL }, meths.nvim_get_var('test_dict_fn2')) + eq({ greeting = 'Hi', F2 = NIL }, api.nvim_get_var('test_dict_fn2')) -- Function specified via RPC dict. source('function! G() dict\n return "@".(self.result)."@"\nendfunction') - eq('@it works@', meths.nvim_call_dict_function({ result = 'it works', G = 'G' }, 'G', {})) + eq('@it works@', api.nvim_call_dict_function({ result = 'it works', G = 'G' }, 'G', {})) end) it('validation', function() @@ -675,8 +675,8 @@ describe('API', function() local start_dir before_each(function() - funcs.mkdir('Xtestdir') - start_dir = funcs.getcwd() + fn.mkdir('Xtestdir') + start_dir = fn.getcwd() end) after_each(function() @@ -684,84 +684,84 @@ describe('API', function() end) it('works', function() - meths.nvim_set_current_dir('Xtestdir') - eq(funcs.getcwd(), start_dir .. helpers.get_pathsep() .. 'Xtestdir') + api.nvim_set_current_dir('Xtestdir') + eq(fn.getcwd(), start_dir .. helpers.get_pathsep() .. 'Xtestdir') end) it('sets previous directory', function() - meths.nvim_set_current_dir('Xtestdir') + api.nvim_set_current_dir('Xtestdir') command('cd -') - eq(funcs.getcwd(), start_dir) + eq(fn.getcwd(), start_dir) end) end) describe('nvim_exec_lua', function() it('works', function() - meths.nvim_exec_lua('vim.api.nvim_set_var("test", 3)', {}) - eq(3, meths.nvim_get_var('test')) + api.nvim_exec_lua('vim.api.nvim_set_var("test", 3)', {}) + eq(3, api.nvim_get_var('test')) - eq(17, meths.nvim_exec_lua('a, b = ...\nreturn a + b', { 10, 7 })) + eq(17, api.nvim_exec_lua('a, b = ...\nreturn a + b', { 10, 7 })) - eq(NIL, meths.nvim_exec_lua('function xx(a,b)\nreturn a..b\nend', {})) - eq('xy', meths.nvim_exec_lua('return xx(...)', { 'x', 'y' })) + eq(NIL, api.nvim_exec_lua('function xx(a,b)\nreturn a..b\nend', {})) + eq('xy', api.nvim_exec_lua('return xx(...)', { 'x', 'y' })) -- Deprecated name: nvim_execute_lua. - eq('xy', meths.nvim_execute_lua('return xx(...)', { 'x', 'y' })) + eq('xy', api.nvim_execute_lua('return xx(...)', { 'x', 'y' })) end) it('reports errors', function() eq( [[Error loading lua: [string ""]:0: '=' expected near '+']], - pcall_err(meths.nvim_exec_lua, 'a+*b', {}) + pcall_err(api.nvim_exec_lua, 'a+*b', {}) ) eq( [[Error loading lua: [string ""]:0: unexpected symbol near '1']], - pcall_err(meths.nvim_exec_lua, '1+2', {}) + pcall_err(api.nvim_exec_lua, '1+2', {}) ) eq( [[Error loading lua: [string ""]:0: unexpected symbol]], - pcall_err(meths.nvim_exec_lua, 'aa=bb\0', {}) + pcall_err(api.nvim_exec_lua, 'aa=bb\0', {}) ) eq( [[attempt to call global 'bork' (a nil value)]], - pcall_err(meths.nvim_exec_lua, 'bork()', {}) + pcall_err(api.nvim_exec_lua, 'bork()', {}) ) - eq('did\nthe\nfail', pcall_err(meths.nvim_exec_lua, 'error("did\\nthe\\nfail")', {})) + eq('did\nthe\nfail', pcall_err(api.nvim_exec_lua, 'error("did\\nthe\\nfail")', {})) end) it('uses native float values', function() - eq(2.5, meths.nvim_exec_lua('return select(1, ...)', { 2.5 })) - eq('2.5', meths.nvim_exec_lua('return vim.inspect(...)', { 2.5 })) + eq(2.5, api.nvim_exec_lua('return select(1, ...)', { 2.5 })) + eq('2.5', api.nvim_exec_lua('return vim.inspect(...)', { 2.5 })) -- "special" float values are still accepted as return values. - eq(2.5, meths.nvim_exec_lua("return vim.api.nvim_eval('2.5')", {})) + eq(2.5, api.nvim_exec_lua("return vim.api.nvim_eval('2.5')", {})) eq( '{\n [false] = 2.5,\n [true] = 3\n}', - meths.nvim_exec_lua("return vim.inspect(vim.api.nvim_eval('2.5'))", {}) + api.nvim_exec_lua("return vim.inspect(vim.api.nvim_eval('2.5'))", {}) ) end) end) describe('nvim_notify', function() it('can notify a info message', function() - meths.nvim_notify('hello world', 2, {}) + api.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')", {})) - meths.nvim_notify('hello world', 4, {}) + eq(42, api.nvim_exec_lua("return vim.notify('Hello world')", {})) + api.nvim_notify('hello world', 4, {}) end) end) describe('nvim_input', function() it('Vimscript error: does NOT fail, updates v:errmsg', function() - local status, _ = pcall(meths.nvim_input, ':call bogus_fn()') - local v_errnum = string.match(meths.nvim_eval('v:errmsg'), 'E%d*:') + local status, _ = pcall(api.nvim_input, ':call bogus_fn()') + local v_errnum = string.match(api.nvim_eval('v:errmsg'), 'E%d*:') eq(true, status) -- nvim_input() did not fail. eq('E117:', v_errnum) -- v:errmsg was updated. end) @@ -779,23 +779,23 @@ describe('API', function() end) local function run_streamed_paste_tests() it('stream: multiple chunks form one undo-block', function() - meths.nvim_paste('1/chunk 1 (start)\n', true, 1) - meths.nvim_paste('1/chunk 2 (end)\n', true, 3) + api.nvim_paste('1/chunk 1 (start)\n', true, 1) + api.nvim_paste('1/chunk 2 (end)\n', true, 3) local expected1 = [[ 1/chunk 1 (start) 1/chunk 2 (end) ]] expect(expected1) - meths.nvim_paste('2/chunk 1 (start)\n', true, 1) - meths.nvim_paste('2/chunk 2\n', true, 2) + api.nvim_paste('2/chunk 1 (start)\n', true, 1) + api.nvim_paste('2/chunk 2\n', true, 2) expect([[ 1/chunk 1 (start) 1/chunk 2 (end) 2/chunk 1 (start) 2/chunk 2 ]]) - meths.nvim_paste('2/chunk 3\n', true, 2) - meths.nvim_paste('2/chunk 4 (end)\n', true, 3) + api.nvim_paste('2/chunk 3\n', true, 2) + api.nvim_paste('2/chunk 4 (end)\n', true, 3) expect([[ 1/chunk 1 (start) 1/chunk 2 (end) @@ -811,10 +811,10 @@ describe('API', function() -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. feed('afoou') feed('i') - meths.nvim_paste('aaaaaa', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('aaaaaabbbbbbccccccdddddd') feed('u') expect('') @@ -830,17 +830,17 @@ describe('API', function() expect('') end) it('pasting one line', function() - meths.nvim_paste('aaaaaa', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('aaaaaabbbbbbccccccdddddd') end) it('pasting multiple lines', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -860,17 +860,17 @@ describe('API', function() expect('||') end) it('pasting one line', function() - meths.nvim_paste('aaaaaa', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('|aaaaaabbbbbbccccccdddddd|') end) it('pasting multiple lines', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ |aaaaaa bbbbbb @@ -890,17 +890,17 @@ describe('API', function() expect('||') end) it('pasting one line', function() - meths.nvim_paste('aaaaaa', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('pasting multiple lines', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ ||aaaaaa bbbbbb @@ -924,24 +924,24 @@ describe('API', function() xxx|]]) end) it('with non-empty chunks', function() - meths.nvim_paste('aaaaaa', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('|aaaaaabbbbbbccccccdddddd|') end) it('with empty first chunk', function() - meths.nvim_paste('', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('|bbbbbbccccccdddddd|') end) it('with all chunks empty', function() - meths.nvim_paste('', false, 1) - meths.nvim_paste('', false, 2) - meths.nvim_paste('', false, 2) - meths.nvim_paste('', false, 3) + api.nvim_paste('', false, 1) + api.nvim_paste('', false, 2) + api.nvim_paste('', false, 2) + api.nvim_paste('', false, 3) expect('||') end) end) @@ -959,17 +959,17 @@ describe('API', function() xxx]]) end) it('with non-empty chunks', function() - meths.nvim_paste('aaaaaa', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('with empty first chunk', function() - meths.nvim_paste('', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||bbbbbbccccccdddddd') end) end) @@ -987,17 +987,17 @@ describe('API', function() xxx]]) end) it('with non-empty chunks', function() - meths.nvim_paste('aaaaaa', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('with empty first chunk', function() - meths.nvim_paste('', false, 1) - meths.nvim_paste('bbbbbb', false, 2) - meths.nvim_paste('cccccc', false, 2) - meths.nvim_paste('dddddd', false, 3) + api.nvim_paste('', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||bbbbbbccccccdddddd') end) end) @@ -1020,10 +1020,10 @@ describe('API', function() feed('ggV') end) it('pasting text without final new line', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -1032,10 +1032,10 @@ describe('API', function() 123456789]]) end) it('pasting text with final new line', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd\n', false, 3) expect([[ aaaaaa bbbbbb @@ -1050,10 +1050,10 @@ describe('API', function() feed('2ggV') end) it('pasting text without final new line', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ 123456789 aaaaaa @@ -1062,10 +1062,10 @@ describe('API', function() dddddd123456789]]) end) it('pasting text with final new line', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd\n', false, 3) expect([[ 123456789 aaaaaa @@ -1080,10 +1080,10 @@ describe('API', function() feed('3ggV') end) it('pasting text without final new line', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ 123456789 987654321 @@ -1093,10 +1093,10 @@ describe('API', function() dddddd]]) end) it('pasting text with final new line', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd\n', false, 3) expect([[ 123456789 987654321 @@ -1112,10 +1112,10 @@ describe('API', function() feed('ggVG') end) it('pasting text without final new line', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -1123,10 +1123,10 @@ describe('API', function() dddddd]]) end) it('pasting text with final new line', function() - 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) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd\n', false, 3) expect([[ aaaaaa bbbbbb @@ -1148,71 +1148,71 @@ describe('API', function() end) it('non-streaming', function() -- With final "\n". - meths.nvim_paste('line 1\nline 2\nline 3\n', true, -1) + api.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, meths.nvim_get_option_value('paste', {})) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) -- Cursor follows the paste. + eq(false, api.nvim_get_option_value('paste', {})) command('%delete _') -- Without final "\n". - meths.nvim_paste('line 1\nline 2\nline 3', true, -1) + api.nvim_paste('line 1\nline 2\nline 3', true, -1) expect([[ line 1 line 2 line 3]]) - eq({ 0, 3, 6, 0 }, funcs.getpos('.')) + eq({ 0, 3, 6, 0 }, fn.getpos('.')) command('%delete _') -- CRLF #10872 - meths.nvim_paste('line 1\r\nline 2\r\nline 3\r\n', true, -1) + api.nvim_paste('line 1\r\nline 2\r\nline 3\r\n', true, -1) expect([[ line 1 line 2 line 3 ]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) command('%delete _') -- CRLF without final "\n". - meths.nvim_paste('line 1\r\nline 2\r\nline 3\r', true, -1) + api.nvim_paste('line 1\r\nline 2\r\nline 3\r', true, -1) expect([[ line 1 line 2 line 3 ]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) command('%delete _') -- CRLF without final "\r\n". - meths.nvim_paste('line 1\r\nline 2\r\nline 3', true, -1) + api.nvim_paste('line 1\r\nline 2\r\nline 3', true, -1) expect([[ line 1 line 2 line 3]]) - eq({ 0, 3, 6, 0 }, funcs.getpos('.')) + eq({ 0, 3, 6, 0 }, fn.getpos('.')) command('%delete _') -- Various other junk. - meths.nvim_paste('line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1) + api.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, meths.nvim_get_option_value('paste', {})) + eq({ 0, 7, 1, 0 }, fn.getpos('.')) + eq(false, api.nvim_get_option_value('paste', {})) end) it('Replace-mode', function() -- Within single line - meths.nvim_put({ 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) + api.nvim_put({ 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) command('normal l') command('startreplace') - meths.nvim_paste('123456', true, -1) + api.nvim_paste('123456', true, -1) expect([[ a123456d eeffgghh iijjkkll]]) command('%delete _') -- Across lines - meths.nvim_put({ 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) + api.nvim_put({ 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) command('normal l') command('startreplace') - meths.nvim_paste('123\n456', true, -1) + api.nvim_paste('123\n456', true, -1) expect([[ a123 456d @@ -1221,30 +1221,30 @@ describe('API', function() end) it('when searching in Visual mode', function() feed('v/') - meths.nvim_paste('aabbccdd', true, -1) - eq('aabbccdd', funcs.getcmdline()) + api.nvim_paste('aabbccdd', true, -1) + eq('aabbccdd', fn.getcmdline()) expect('') end) it('mappings are disabled in Cmdline mode', function() command('cnoremap a b') feed(':') - meths.nvim_paste('a', true, -1) - eq('a', funcs.getcmdline()) + api.nvim_paste('a', true, -1) + eq('a', fn.getcmdline()) end) it('pasted text is saved in cmdline history when comes from mapping #20957', function() command('cnoremap ') feed(':') - meths.nvim_paste('echo', true, -1) - eq('', funcs.histget(':')) + api.nvim_paste('echo', true, -1) + eq('', fn.histget(':')) feed('') - eq('echo', funcs.histget(':')) + eq('echo', fn.histget(':')) end) it('pasting with empty last chunk in Cmdline mode', function() local screen = Screen.new(20, 4) screen:attach() feed(':') - meths.nvim_paste('Foo', true, 1) - meths.nvim_paste('', true, 3) + api.nvim_paste('Foo', true, 1) + api.nvim_paste('', true, 3) screen:expect([[ | ~ |*2 @@ -1255,7 +1255,7 @@ describe('API', function() local screen = Screen.new(20, 4) screen:attach() feed(':') - meths.nvim_paste('normal! \023\022\006\027', true, -1) + api.nvim_paste('normal! \023\022\006\027', true, -1) screen:expect([[ | ~ |*2 @@ -1263,12 +1263,12 @@ describe('API', function() ]]) end) it('crlf=false does not break lines at CR, CRLF', function() - meths.nvim_paste('line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) + api.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('.')) + eq({ 0, 3, 14, 0 }, fn.getpos('.')) end) it('vim.paste() failure', function() - meths.nvim_exec_lua('vim.paste = (function(lines, phase) error("fake fail") end)', {}) + api.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) @@ -1290,78 +1290,78 @@ describe('API', function() end) it('inserts text', function() -- linewise - meths.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'l', true, true) + api.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'l', true, true) expect([[ line 1 line 2 line 3]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) command('%delete _') -- charwise - meths.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'c', true, false) + api.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 + eq({ 0, 1, 1, 0 }, fn.getpos('.')) -- follow=false -- blockwise - meths.nvim_put({ 'AA', 'BB' }, 'b', true, true) + api.nvim_put({ 'AA', 'BB' }, 'b', true, true) expect([[ lAAine 1 lBBine 2 line 3]]) - eq({ 0, 2, 4, 0 }, funcs.getpos('.')) + eq({ 0, 2, 4, 0 }, fn.getpos('.')) command('%delete _') -- Empty lines list. - meths.nvim_put({}, 'c', true, true) - eq({ 0, 1, 1, 0 }, funcs.getpos('.')) + api.nvim_put({}, 'c', true, true) + eq({ 0, 1, 1, 0 }, fn.getpos('.')) expect([[]]) -- Single empty line. - meths.nvim_put({ '' }, 'c', true, true) - eq({ 0, 1, 1, 0 }, funcs.getpos('.')) + api.nvim_put({ '' }, 'c', true, true) + eq({ 0, 1, 1, 0 }, fn.getpos('.')) expect([[ ]]) - meths.nvim_put({ 'AB' }, 'c', true, true) + api.nvim_put({ 'AB' }, 'c', true, true) -- after=false, follow=true - meths.nvim_put({ 'line 1', 'line 2' }, 'c', false, true) + api.nvim_put({ 'line 1', 'line 2' }, 'c', false, true) expect([[ Aline 1 line 2B]]) - eq({ 0, 2, 7, 0 }, funcs.getpos('.')) + eq({ 0, 2, 7, 0 }, fn.getpos('.')) command('%delete _') - meths.nvim_put({ 'AB' }, 'c', true, true) + api.nvim_put({ 'AB' }, 'c', true, true) -- after=false, follow=false - meths.nvim_put({ 'line 1', 'line 2' }, 'c', false, false) + api.nvim_put({ 'line 1', 'line 2' }, 'c', false, false) expect([[ Aline 1 line 2B]]) - eq({ 0, 1, 2, 0 }, funcs.getpos('.')) - eq('', meths.nvim_eval('v:errmsg')) + eq({ 0, 1, 2, 0 }, fn.getpos('.')) + eq('', api.nvim_eval('v:errmsg')) end) it('detects charwise/linewise text (empty {type})', function() -- linewise (final item is empty string) - meths.nvim_put({ 'line 1', 'line 2', 'line 3', '' }, '', true, true) + api.nvim_put({ 'line 1', 'line 2', 'line 3', '' }, '', true, true) expect([[ line 1 line 2 line 3]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) command('%delete _') -- charwise (final item is non-empty) - meths.nvim_put({ 'line 1', 'line 2', 'line 3' }, '', true, true) + api.nvim_put({ 'line 1', 'line 2', 'line 3' }, '', true, true) expect([[ line 1 line 2 line 3]]) - eq({ 0, 3, 6, 0 }, funcs.getpos('.')) + eq({ 0, 3, 6, 0 }, fn.getpos('.')) end) it('allows block width', function() -- behave consistently with setreg(); support "\022{NUM}" return by getregtype() - meths.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'l', false, false) + api.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'l', false, false) expect([[ line 1 line 2 @@ -1369,69 +1369,69 @@ describe('API', function() ]]) -- larger width create spaces - meths.nvim_put({ 'a', 'bc' }, 'b3', false, false) + api.nvim_put({ 'a', 'bc' }, 'b3', false, false) expect([[ a line 1 bc line 2 line 3 ]]) -- smaller width is ignored - meths.nvim_put({ 'xxx', 'yyy' }, '\0221', false, true) + api.nvim_put({ 'xxx', 'yyy' }, '\0221', false, true) expect([[ xxxa line 1 yyybc line 2 line 3 ]]) - eq("Invalid 'type': 'bx'", pcall_err(meths.nvim_put, { 'xxx', 'yyy' }, 'bx', false, true)) - eq("Invalid 'type': 'b3x'", pcall_err(meths.nvim_put, { 'xxx', 'yyy' }, 'b3x', false, true)) + eq("Invalid 'type': 'bx'", pcall_err(api.nvim_put, { 'xxx', 'yyy' }, 'bx', false, true)) + eq("Invalid 'type': 'b3x'", pcall_err(api.nvim_put, { 'xxx', 'yyy' }, 'b3x', false, true)) end) end) describe('nvim_strwidth', function() it('works', function() - eq(3, meths.nvim_strwidth('abc')) + eq(3, api.nvim_strwidth('abc')) -- 6 + (neovim) -- 19 * 2 (each japanese character occupies two cells) - eq(44, meths.nvim_strwidth('neovimのデザインかなりまともなのになってる。')) + eq(44, api.nvim_strwidth('neovimのデザインかなりまともなのになってる。')) end) it('cannot handle NULs', function() - eq(0, meths.nvim_strwidth('\0abc')) + eq(0, api.nvim_strwidth('\0abc')) end) end) describe('nvim_get_current_line, nvim_set_current_line', function() it('works', function() - eq('', meths.nvim_get_current_line()) - meths.nvim_set_current_line('abc') - eq('abc', meths.nvim_get_current_line()) + eq('', api.nvim_get_current_line()) + api.nvim_set_current_line('abc') + eq('abc', api.nvim_get_current_line()) end) end) describe('set/get/del variables', function() it('validation', function() - eq('Key not found: bogus', pcall_err(meths.nvim_get_var, 'bogus')) - eq('Key not found: bogus', pcall_err(meths.nvim_del_var, 'bogus')) + eq('Key not found: bogus', pcall_err(api.nvim_get_var, 'bogus')) + eq('Key not found: bogus', pcall_err(api.nvim_del_var, 'bogus')) end) it('nvim_get_var, nvim_set_var, nvim_del_var', function() - 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')) - eq('Key not found: lua', pcall_err(meths.nvim_del_var, 'lua')) - meths.nvim_set_var('lua', 1) + api.nvim_set_var('lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_get_var('lua')) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_eval('g:lua')) + eq(1, fn.exists('g:lua')) + api.nvim_del_var('lua') + eq(0, fn.exists('g:lua')) + eq('Key not found: lua', pcall_err(api.nvim_del_var, 'lua')) + api.nvim_set_var('lua', 1) -- Empty keys are allowed in Vim dicts (and msgpack). - meths.nvim_set_var('dict_empty_key', { [''] = 'empty key' }) - eq({ [''] = 'empty key' }, meths.nvim_get_var('dict_empty_key')) + api.nvim_set_var('dict_empty_key', { [''] = 'empty key' }) + eq({ [''] = 'empty key' }, api.nvim_get_var('dict_empty_key')) -- Set locked g: var. command('lockvar lua') - eq('Key is locked: lua', pcall_err(meths.nvim_del_var, 'lua')) - eq('Key is locked: lua', pcall_err(meths.nvim_set_var, 'lua', 1)) + eq('Key is locked: lua', pcall_err(api.nvim_del_var, 'lua')) + eq('Key is locked: lua', pcall_err(api.nvim_set_var, 'lua', 1)) exec([[ function Test() @@ -1441,8 +1441,8 @@ describe('API', function() let g:Unknown_func = function('Test') let g:Unknown_script_func = function('s:Test') ]]) - eq(NIL, meths.nvim_get_var('Unknown_func')) - eq(NIL, meths.nvim_get_var('Unknown_script_func')) + eq(NIL, api.nvim_get_var('Unknown_func')) + eq(NIL, api.nvim_get_var('Unknown_script_func')) -- Check if autoload works properly local pathsep = helpers.get_pathsep() @@ -1454,40 +1454,40 @@ describe('API', function() write_file(autoload_file, [[let testload#value = 2]]) clear { args_rm = { '-u' }, env = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } } - eq(2, meths.nvim_get_var('testload#value')) + eq(2, api.nvim_get_var('testload#value')) rmdir('Xhome') end) it('nvim_get_vvar, nvim_set_vvar', function() eq('Key is read-only: count', pcall_err(request, 'nvim_set_vvar', 'count', 42)) eq('Dictionary is locked', pcall_err(request, 'nvim_set_vvar', 'nosuchvar', 42)) - meths.nvim_set_vvar('errmsg', 'set by API') - eq('set by API', meths.nvim_get_vvar('errmsg')) - meths.nvim_set_vvar('errmsg', 42) + api.nvim_set_vvar('errmsg', 'set by API') + eq('set by API', api.nvim_get_vvar('errmsg')) + api.nvim_set_vvar('errmsg', 42) eq('42', eval('v:errmsg')) - meths.nvim_set_vvar('oldfiles', { 'one', 'two' }) + api.nvim_set_vvar('oldfiles', { 'one', 'two' }) eq({ 'one', 'two' }, eval('v:oldfiles')) - meths.nvim_set_vvar('oldfiles', {}) + api.nvim_set_vvar('oldfiles', {}) eq({}, eval('v:oldfiles')) eq( 'Setting v:oldfiles to value with wrong type', - pcall_err(meths.nvim_set_vvar, 'oldfiles', 'a') + pcall_err(api.nvim_set_vvar, 'oldfiles', 'a') ) eq({}, eval('v:oldfiles')) feed('i foo foo foo0/foo') - eq({ 1, 1 }, meths.nvim_win_get_cursor(0)) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) eq(1, eval('v:searchforward')) feed('n') - eq({ 1, 5 }, meths.nvim_win_get_cursor(0)) - meths.nvim_set_vvar('searchforward', 0) + eq({ 1, 5 }, api.nvim_win_get_cursor(0)) + api.nvim_set_vvar('searchforward', 0) eq(0, eval('v:searchforward')) feed('n') - eq({ 1, 1 }, meths.nvim_win_get_cursor(0)) - meths.nvim_set_vvar('searchforward', 1) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) + api.nvim_set_vvar('searchforward', 1) eq(1, eval('v:searchforward')) feed('n') - eq({ 1, 5 }, meths.nvim_win_get_cursor(0)) + eq({ 1, 5 }, api.nvim_win_get_cursor(0)) local screen = Screen.new(60, 3) screen:set_default_attr_ids({ @@ -1503,7 +1503,7 @@ describe('API', function() | ]], } - meths.nvim_set_vvar('hlsearch', 0) + api.nvim_set_vvar('hlsearch', 0) eq(0, eval('v:hlsearch')) screen:expect { grid = [[ @@ -1512,7 +1512,7 @@ describe('API', function() | ]], } - meths.nvim_set_vvar('hlsearch', 1) + api.nvim_set_vvar('hlsearch', 1) eq(1, eval('v:hlsearch')) screen:expect { grid = [[ @@ -1539,182 +1539,182 @@ describe('API', function() end) it('truncates values with NULs in them', function() - meths.nvim_set_var('xxx', 'ab\0cd') - eq('ab', meths.nvim_get_var('xxx')) + api.nvim_set_var('xxx', 'ab\0cd') + eq('ab', api.nvim_get_var('xxx')) end) end) describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - ok(meths.nvim_get_option_value('equalalways', {})) - meths.nvim_set_option_value('equalalways', false, {}) - ok(not meths.nvim_get_option_value('equalalways', {})) + ok(api.nvim_get_option_value('equalalways', {})) + api.nvim_set_option_value('equalalways', false, {}) + ok(not api.nvim_get_option_value('equalalways', {})) end) it('works to get global value of local options', function() - eq(false, meths.nvim_get_option_value('lisp', {})) - eq(8, meths.nvim_get_option_value('shiftwidth', {})) + eq(false, api.nvim_get_option_value('lisp', {})) + eq(8, api.nvim_get_option_value('shiftwidth', {})) end) it('works to set global value of local options', function() - 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', {})) + api.nvim_set_option_value('lisp', true, { scope = 'global' }) + eq(true, api.nvim_get_option_value('lisp', { scope = 'global' })) + eq(false, api.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' }) + api.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() - meths.nvim_set_option_value('equalalways', false, {}) + api.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+%)') ) - meths.nvim_exec_lua('vim.api.nvim_set_option_value("equalalways", true, {})', {}) + api.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, 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, api.nvim_get_option_info2('autochdir', {}).was_set) + api.nvim_set_option_value('autochdir', true, {}) + eq(true, api.nvim_get_option_info2('autochdir', {}).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, api.nvim_get_option_info2('cmdwinheight', {}).was_set) + api.nvim_set_option_value('cmdwinheight', 10, {}) + eq(true, api.nvim_get_option_info2('cmdwinheight', {}).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) + eq(false, api.nvim_get_option_info2('debug', {}).was_set) + api.nvim_set_option_value('debug', 'beep', {}) + eq(true, api.nvim_get_option_info2('debug', {}).was_set) end) it('validation', function() eq( "Invalid 'scope': expected 'local' or 'global'", - pcall_err(meths.nvim_get_option_value, 'scrolloff', { scope = 'bogus' }) + pcall_err(api.nvim_get_option_value, 'scrolloff', { scope = 'bogus' }) ) eq( "Invalid 'scope': expected 'local' or 'global'", - pcall_err(meths.nvim_set_option_value, 'scrolloff', 1, { scope = 'bogus' }) + pcall_err(api.nvim_set_option_value, 'scrolloff', 1, { scope = 'bogus' }) ) eq( "Invalid 'scope': expected String, got Integer", - pcall_err(meths.nvim_get_option_value, 'scrolloff', { scope = 42 }) + pcall_err(api.nvim_get_option_value, 'scrolloff', { scope = 42 }) ) eq( "Invalid 'value': expected valid option type, got Array", - pcall_err(meths.nvim_set_option_value, 'scrolloff', {}, {}) + pcall_err(api.nvim_set_option_value, 'scrolloff', {}, {}) ) eq( "Invalid value for option 'scrolloff': expected number, got boolean true", - pcall_err(meths.nvim_set_option_value, 'scrolloff', true, {}) + pcall_err(api.nvim_set_option_value, 'scrolloff', true, {}) ) eq( 'Invalid value for option \'scrolloff\': expected number, got string "wrong"', - pcall_err(meths.nvim_set_option_value, 'scrolloff', 'wrong', {}) + pcall_err(api.nvim_set_option_value, 'scrolloff', 'wrong', {}) ) end) it('can get local values when global value is set', function() - eq(0, meths.nvim_get_option_value('scrolloff', {})) - eq(-1, meths.nvim_get_option_value('scrolloff', { scope = 'local' })) + eq(0, api.nvim_get_option_value('scrolloff', {})) + eq(-1, api.nvim_get_option_value('scrolloff', { scope = 'local' })) end) it('can set global and local values', function() - 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' })) + api.nvim_set_option_value('makeprg', 'hello', {}) + eq('hello', api.nvim_get_option_value('makeprg', {})) + eq('', api.nvim_get_option_value('makeprg', { scope = 'local' })) + api.nvim_set_option_value('makeprg', 'world', { scope = 'local' }) + eq('world', api.nvim_get_option_value('makeprg', { scope = 'local' })) + api.nvim_set_option_value('makeprg', 'goodbye', { scope = 'global' }) + eq('goodbye', api.nvim_get_option_value('makeprg', { scope = 'global' })) + api.nvim_set_option_value('makeprg', 'hello', {}) + eq('hello', api.nvim_get_option_value('makeprg', { scope = 'global' })) + eq('hello', api.nvim_get_option_value('makeprg', {})) + eq('', api.nvim_get_option_value('makeprg', { scope = 'local' })) end) it('clears the local value of an option with nil', function() -- Set global value - meths.nvim_set_option_value('shiftwidth', 42, {}) - eq(42, meths.nvim_get_option_value('shiftwidth', {})) + api.nvim_set_option_value('shiftwidth', 42, {}) + eq(42, api.nvim_get_option_value('shiftwidth', {})) -- Set local value - 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' })) + api.nvim_set_option_value('shiftwidth', 8, { scope = 'local' }) + eq(8, api.nvim_get_option_value('shiftwidth', {})) + eq(8, api.nvim_get_option_value('shiftwidth', { scope = 'local' })) + eq(42, api.nvim_get_option_value('shiftwidth', { scope = 'global' })) -- Clear value without scope - 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' })) + api.nvim_set_option_value('shiftwidth', NIL, {}) + eq(42, api.nvim_get_option_value('shiftwidth', {})) + eq(42, api.nvim_get_option_value('shiftwidth', { scope = 'local' })) -- Clear value with explicit scope - 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' })) + api.nvim_set_option_value('shiftwidth', 8, { scope = 'local' }) + api.nvim_set_option_value('shiftwidth', NIL, { scope = 'local' }) + eq(42, api.nvim_get_option_value('shiftwidth', {})) + eq(42, api.nvim_get_option_value('shiftwidth', { scope = 'local' })) -- Now try with options with a special "local is unset" value (e.g. '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', {})) + api.nvim_set_option_value('undolevels', 1000, {}) + api.nvim_set_option_value('undolevels', 1200, { scope = 'local' }) + eq(1200, api.nvim_get_option_value('undolevels', { scope = 'local' })) + api.nvim_set_option_value('undolevels', NIL, { scope = 'local' }) + eq(-123456, api.nvim_get_option_value('undolevels', { scope = 'local' })) + eq(1000, api.nvim_get_option_value('undolevels', {})) - 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', {})) + api.nvim_set_option_value('autoread', true, {}) + api.nvim_set_option_value('autoread', false, { scope = 'local' }) + eq(false, api.nvim_get_option_value('autoread', { scope = 'local' })) + api.nvim_set_option_value('autoread', NIL, { scope = 'local' }) + eq(NIL, api.nvim_get_option_value('autoread', { scope = 'local' })) + eq(true, api.nvim_get_option_value('autoread', {})) end) it('set window options', function() - meths.nvim_set_option_value('colorcolumn', '4,3', {}) - eq('4,3', meths.nvim_get_option_value('colorcolumn', { scope = 'local' })) + api.nvim_set_option_value('colorcolumn', '4,3', {}) + eq('4,3', api.nvim_get_option_value('colorcolumn', { scope = 'local' })) command('set modified hidden') command('enew') -- edit new buffer, window option is preserved - eq('4,3', meths.nvim_get_option_value('colorcolumn', { scope = 'local' })) + eq('4,3', api.nvim_get_option_value('colorcolumn', { scope = 'local' })) end) it('set local window options', function() - 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' })) + api.nvim_set_option_value('colorcolumn', '4,3', { win = 0, scope = 'local' }) + eq('4,3', api.nvim_get_option_value('colorcolumn', { win = 0, scope = 'local' })) command('set modified hidden') command('enew') -- edit new buffer, window option is reset - eq('', meths.nvim_get_option_value('colorcolumn', { win = 0, scope = 'local' })) + eq('', api.nvim_get_option_value('colorcolumn', { win = 0, scope = 'local' })) end) it('get buffer or window-local options', function() 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 buf = api.nvim_get_current_buf().id + api.nvim_set_option_value('tagfunc', 'foobar', { buf = buf }) + eq('foobar', api.nvim_get_option_value('tagfunc', { buf = buf })) - 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 })) + local win = api.nvim_get_current_win().id + api.nvim_set_option_value('number', true, { win = win }) + eq(true, api.nvim_get_option_value('number', { win = win })) end) it('getting current buffer option does not adjust cursor #19381', function() command('new') - local buf = meths.nvim_get_current_buf().id - local win = meths.nvim_get_current_win().id + local buf = api.nvim_get_current_buf().id + local win = api.nvim_get_current_win().id insert('some text') feed('0v$') - 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)) + eq({ 1, 9 }, api.nvim_win_get_cursor(win)) + api.nvim_get_option_value('filetype', { buf