From da70c394053e2110aedf5a8ea72cbaba0ccf06d9 Mon Sep 17 00:00:00 2001 From: Liad Oz Date: Wed, 7 Dec 2022 19:07:56 +0200 Subject: fix(extmarks): adjust extmarks when inserting prompt prefix --- test/functional/api/extmark_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 00f5b25b8a..9902826c72 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1454,6 +1454,14 @@ describe('API/extmarks', function() }} }, get_extmarks(ns, 0, -1, {details=true})) end) + it('in prompt buffer', function() + feed('dd') + local id = set_extmark(ns, marks[1], 0, 0, {}) + curbufmeths.set_option('buftype', 'prompt') + feed('i') + eq({{id, 0, 2}}, get_extmarks(ns, 0, -1)) + end) + it('can get details', function() set_extmark(ns, marks[1], 0, 0, { end_col = 0, -- cgit From 860fea1a3f880c2da0ac351a9523156bcfc67361 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 31 Jan 2023 07:08:23 +0800 Subject: fix(highlight): properly deal with underline mask when listing (#22057) --- test/functional/api/highlight_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 5941d4c68b..7f044977cb 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -214,7 +214,7 @@ describe("API: set highlight", function() bold = true, italic = true, reverse = true, - underline = true, + underdashed = true, strikethrough = true, altfont = true, cterm = { @@ -231,7 +231,7 @@ describe("API: set highlight", function() bold = true, italic = true, reverse = true, - underline = true, + underdashed = true, strikethrough = true, altfont = true, } @@ -297,7 +297,7 @@ describe("API: set highlight", function() exec_capture('highlight Test_hl')) meths.set_hl(0, 'Test_hl2', highlight3_config) - eq('Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underline,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', + eq('Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', exec_capture('highlight Test_hl2')) -- Colors are stored with the name they are defined, but -- cgit From ecc40660d1577835245d99f95e14762a30d36054 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Feb 2023 10:53:47 +0800 Subject: fix(rpc): ignore redraw events when not in UI client (#21892) Otherwise it will crash. --- test/functional/api/server_requests_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index ceff390dc5..e6bfc6b64f 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -337,6 +337,21 @@ describe('server -> client', function() eq('localhost:', string.sub(address,1,10)) connect_test(server, 'tcp', address) end) + + it('does not crash on receiving UI events', function() + local server = spawn(nvim_argv) + set_session(server) + local address = funcs.serverlist()[1] + local client = spawn(nvim_argv, false, nil, true) + set_session(client) + + local id = funcs.sockconnect('pipe', address, {rpc=true}) + funcs.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) + assert_alive() + + server:close() + client:close() + end) end) describe('connecting to its own pipe address', function() -- cgit From f8f82901cdd0ccd5308e05c73af6deb7d083720f Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 1 Feb 2023 12:54:22 +0100 Subject: fix(tests): fixes for using vim.mpack and more ASAN --- test/functional/api/rpc_fixture.lua | 7 +++---- test/functional/api/server_requests_spec.lua | 2 +- test/functional/api/vim_spec.lua | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/rpc_fixture.lua b/test/functional/api/rpc_fixture.lua index 94df751363..c860a6da59 100644 --- a/test/functional/api/rpc_fixture.lua +++ b/test/functional/api/rpc_fixture.lua @@ -4,9 +4,8 @@ package.path = arg[1] package.cpath = arg[2] -local mpack = require('mpack') -local StdioStream = require('nvim.stdio_stream') -local Session = require('nvim.session') +local StdioStream = require'test.client.uv_stream'.StdioStream +local Session = require'test.client.session' local stdio_stream = StdioStream.open() local session = Session.new(stdio_stream) @@ -19,7 +18,7 @@ local function on_request(method, args) return "done!" elseif method == "exit" then session:stop() - return mpack.NIL + return vim.NIL end end diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index e6bfc6b64f..cb273aedba 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -237,7 +237,7 @@ describe('server -> client', function() \ } ]]) meths.set_var("args", { - helpers.test_lua_prg, + nvim_prog, '-ll', 'test/functional/api/rpc_fixture.lua', package.path, package.cpath, diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 8fcdd9620b..fc550f5861 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -59,7 +59,7 @@ describe('API', function() -- XXX: This must be the last one, else next one will fail: -- "Packer instance already working. Use another Packer ..." - matches("can't serialize object$", + matches("can't serialize object of type .$", pcall_err(request, nil)) end) -- cgit From c5b34fa55483d84d1de32937ffff0b7cf1aeba78 Mon Sep 17 00:00:00 2001 From: glacambre Date: Sat, 11 Feb 2023 09:45:11 +0100 Subject: refactor: move init_default_autocmds to lua The original motivation for this change came from developping https://github.com/neovim/neovim/pull/22159, which will require adding more autocommand creation to Neovim's startup sequence. This change requires lightly editing a test that expected no autocommand to have been created from lua. --- test/functional/api/autocmd_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 22a1311ee9..af13736aa9 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -209,7 +209,7 @@ describe('autocmd api', function() local aus = meths.get_autocmds({ event = 'User', pattern = 'Test' }) local first = aus[1] - eq(first.id, 1) + eq(true, first.id > 0) meths.set_var("some_condition", true) meths.exec_autocmds("User", {pattern = "Test"}) -- cgit From 46a87a5d2bac598fed0870f0d3c926087f95d30f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 05:19:04 -0500 Subject: refactor(api): VALIDATE macros #22187 Problem: - API validation involves too much boilerplate. - API validation errors are not consistently worded. Solution: Introduce some macros. Currently these are clumsy, but they at least help with consistency and avoid some nesting. --- test/functional/api/autocmd_spec.lua | 18 +++++----- test/functional/api/buffer_updates_spec.lua | 2 +- test/functional/api/command_spec.lua | 2 +- test/functional/api/extmark_spec.lua | 14 ++++---- test/functional/api/vim_spec.lua | 56 ++++++++++++++++------------- 5 files changed, 49 insertions(+), 43 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 22a1311ee9..56b0a4d9b2 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -21,7 +21,7 @@ describe('autocmd api', function() callback = "NotAllowed", }) - eq("specify either 'callback' or 'command', not both", rv) + eq("Cannot use both 'callback' and 'command'", rv) end) it('doesnt leak when you use ++once', function() @@ -66,7 +66,7 @@ describe('autocmd api', function() pattern = "*.py", }) - eq("cannot pass both: 'pattern' and 'buffer' for the same autocmd", rv) + eq("Cannot use both 'pattern' and 'buffer' for the same autocmd", rv) end) it('does not allow passing invalid buffers', function() @@ -407,8 +407,8 @@ describe('autocmd api', function() pattern = "", }}, aus) - eq("Invalid value for 'buffer': must be an integer or array of integers", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) - eq("Invalid value for 'buffer': must be an integer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) + eq("Invalid buffer: expected Integer or Array, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) + eq("Invalid buffer: expected Integer, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) eq("Invalid buffer id: 42", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { 42 } })) local bufs = {} @@ -416,7 +416,7 @@ describe('autocmd api', function() table.insert(bufs, meths.create_buf(true, false)) end - eq("Too many buffers. Please limit yourself to 256 or fewer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs })) + eq("Too many buffers (maximum of 256)", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs })) end) it('should return autocmds when group is specified by id', function() @@ -578,7 +578,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches('invalid augroup: NotDefined', code) + matches("Invalid group: 'NotDefined'", code) end) it('raises error for undefined augroup id', function() @@ -596,7 +596,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches('invalid augroup: 1', code) + matches('Invalid group: 1', code) end) it('raises error for invalid group type', function() @@ -611,7 +611,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("'group' must be a string or an integer", code) + matches("Invalid group: expected String or Integer, got Boolean", code) end) it('raises error for invalid pattern array', function() @@ -625,7 +625,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("All entries in 'pattern' must be strings", code) + matches("Invalid 'pattern' item type: expected String, got Array", code) end) end) diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index d5f06c8f1f..1510d31945 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -762,7 +762,7 @@ describe('API: buffer events:', function() it('returns a proper error on nonempty options dict', function() clear() local b = editoriginal(false) - eq("unexpected key: builtin", pcall_err(buffer, 'attach', b, false, {builtin="asfd"})) + eq("Invalid key: 'builtin'", pcall_err(buffer, 'attach', b, false, {builtin="asfd"})) end) it('nvim_buf_attach returns response after delay #8634', function() diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index d0fb26edc7..189f9d4f98 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -543,7 +543,7 @@ describe('nvim_create_user_command', function() end) it('does not allow invalid command names', function() - matches("'name' must begin with an uppercase letter", pcall_err(exec_lua, [[ + matches("Invalid command name %(must begin with an uppercase letter%): 'test'", pcall_err(exec_lua, [[ vim.api.nvim_create_user_command('test', 'echo "hi"', {}) ]])) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 9902826c72..fc68f11a67 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -106,7 +106,7 @@ describe('API/extmarks', function() end_col = 0, end_row = 1 }) - eq("end_col value outside range", + eq("Invalid end_col: '(out of range)'", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 })) end) @@ -1344,10 +1344,10 @@ describe('API/extmarks', function() it('throws consistent error codes', function() local ns_invalid = ns2 + 1 - eq("Invalid ns_id", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2])) - eq("Invalid ns_id", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1])) - eq("Invalid ns_id", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2])) - eq("Invalid ns_id", pcall_err(get_extmark_by_id, ns_invalid, marks[1])) + eq("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(get_extmarks, ns_invalid, positions[1], positions[2])) + eq("Invalid ns_id: 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1])) end) it('when col = line-length, set the mark on eol', function() @@ -1362,13 +1362,13 @@ describe('API/extmarks', function() it('when col = line-length, set the mark on eol', function() local invalid_col = init_text:len() + 1 - eq("col value outside range", pcall_err(set_extmark, ns, marks[1], 0, invalid_col)) + eq("Invalid col: '(out of range)'", pcall_err(set_extmark, ns, marks[1], 0, invalid_col)) end) it('fails when line > line_count', function() local invalid_col = init_text:len() + 1 local invalid_lnum = 3 - eq('line value outside range', pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col)) + eq("Invalid line: '(out of range)'", pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col)) eq({}, get_extmark_by_id(ns, marks[1])) end) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index fc550f5861..5c56c90952 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1155,7 +1155,7 @@ describe('API', function() describe('nvim_put', function() it('validates args', function() - eq('Invalid lines (expected array of strings)', + eq("Invalid line: expected String, got Integer", pcall_err(request, 'nvim_put', {42}, 'l', false, false)) eq("Invalid type: 'x'", pcall_err(request, 'nvim_put', {'foo'}, 'x', false, false)) @@ -1410,6 +1410,15 @@ describe('API', function() ok(not nvim('get_option_value', 'equalalways', {})) end) + it('validation', function() + eq("Invalid scope (expected 'local' or 'global')", + pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 'bogus'})) + eq("Invalid scope (expected 'local' or 'global')", + pcall_err(nvim, 'set_option_value', 'scrolloff', 1, {scope = 'bogus'})) + eq("Invalid scope: expected String, got Integer", + pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 42})) + 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'})) @@ -1780,9 +1789,9 @@ describe('API', function() it('validates args', function() eq("Invalid key: 'blah'", pcall_err(nvim, 'get_context', {blah={}})) - eq('invalid value for key: types', + eq("Invalid types: expected Array, got Integer", pcall_err(nvim, 'get_context', {types=42})) - eq('unexpected type: zub', + eq("Invalid type: 'zub'", pcall_err(nvim, 'get_context', {types={'jumps', 'zub', 'zam',}})) end) it('returns map of current editor state', function() @@ -2223,15 +2232,14 @@ describe('API', function() eq(5, meths.get_var('avar')) end) - it('throws error on malformed arguments', function() + it('validation', function() local req = { {'nvim_set_var', {'avar', 1}}, {'nvim_set_var'}, {'nvim_set_var', {'avar', 2}}, } - local status, err = pcall(meths.call_atomic, req) - eq(false, status) - ok(err:match('Items in calls array must be arrays of size 2') ~= nil) + eq('Items in calls array must be arrays of size 2', + pcall_err(meths.call_atomic, req)) -- call before was done, but not after eq(1, meths.get_var('avar')) @@ -2239,18 +2247,16 @@ describe('API', function() { 'nvim_set_var', { 'bvar', { 2, 3 } } }, 12, } - status, err = pcall(meths.call_atomic, req) - eq(false, status) - ok(err:match('Items in calls array must be arrays') ~= nil) + eq("Invalid calls item: expected Array, got Integer", + pcall_err(meths.call_atomic, req)) eq({2,3}, meths.get_var('bvar')) req = { {'nvim_set_current_line', 'little line'}, {'nvim_set_var', {'avar', 3}}, } - status, err = pcall(meths.call_atomic, req) - eq(false, status) - ok(err:match('Args must be Array') ~= nil) + eq("Invalid args: expected Array, got String", + pcall_err(meths.call_atomic, req)) -- call before was done, but not after eq(1, meths.get_var('avar')) eq({''}, meths.buf_get_lines(0, 0, -1, true)) @@ -2750,7 +2756,7 @@ describe('API', function() describe('nvim_get_option_info', function() it('should error for unknown options', function() - eq("no such option: 'bogus'", pcall_err(meths.get_option_info, 'bogus')) + eq("Invalid option (not found): 'bogus'", pcall_err(meths.get_option_info, 'bogus')) end) it('should return the same options for short and long name', function() @@ -3031,10 +3037,10 @@ describe('API', function() eq(true, meths.del_mark('F')) eq({0, 0}, meths.buf_get_mark(buf, 'F')) end) - it('fails when invalid marks are used', function() - eq(false, pcall(meths.del_mark, 'f')) - eq(false, pcall(meths.del_mark, '!')) - eq(false, pcall(meths.del_mark, 'fail')) + it('validation', function() + eq("Invalid mark name (must be file/uppercase): 'f'", pcall_err(meths.del_mark, 'f')) + eq("Invalid mark name (must be file/uppercase): '!'", pcall_err(meths.del_mark, '!')) + eq("Invalid mark name (must be a single char): 'fail'", pcall_err(meths.del_mark, 'fail')) end) end) describe('nvim_get_mark', function() @@ -3048,10 +3054,10 @@ describe('API', function() assert(string.find(mark[4], "mybuf$")) eq({2, 2, buf.id, mark[4]}, mark) end) - it('fails when invalid marks are used', function() - eq(false, pcall(meths.del_mark, 'f')) - eq(false, pcall(meths.del_mark, '!')) - eq(false, pcall(meths.del_mark, 'fail')) + it('validation', function() + eq("Invalid mark name (must be file/uppercase): 'f'", pcall_err(meths.get_mark, 'f', {})) + eq("Invalid mark name (must be file/uppercase): '!'", pcall_err(meths.get_mark, '!', {})) + eq("Invalid mark name (must be a single char): 'fail'", pcall_err(meths.get_mark, 'fail', {})) end) it('returns the expected when mark is not set', function() eq(true, meths.del_mark('A')) @@ -3113,15 +3119,15 @@ describe('API', function() meths.eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 })) end) it('rejects multiple-character fillchar', function() - eq('fillchar must be a single character', + eq('Invalid fillchar (not a single character)', pcall_err(meths.eval_statusline, '', { fillchar = 'aa' })) end) it('rejects empty string fillchar', function() - eq('fillchar must be a single character', + eq('Invalid fillchar (not a single character)', pcall_err(meths.eval_statusline, '', { fillchar = '' })) end) it('rejects non-string fillchar', function() - eq('fillchar must be a single character', + eq("Invalid fillchar: expected String, got Integer", pcall_err(meths.eval_statusline, '', { fillchar = 1 })) end) it('rejects invalid string', function() -- cgit From ff3d04b75b4a9314815c37d53ebc4d035a043335 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 08:07:38 -0500 Subject: refactor(api): VALIDATE macros #22256 - VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args --- test/functional/api/autocmd_spec.lua | 104 ++++++++++++++++++++++----------- test/functional/api/buffer_spec.lua | 20 +++---- test/functional/api/extmark_spec.lua | 6 +- test/functional/api/highlight_spec.lua | 67 +++++++++------------ test/functional/api/proc_spec.lua | 4 +- test/functional/api/ui_spec.lua | 26 ++++++++- test/functional/api/vim_spec.lua | 10 ++-- 7 files changed, 141 insertions(+), 96 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 56b0a4d9b2..f10f18174e 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -14,14 +14,31 @@ before_each(clear) describe('autocmd api', function() describe('nvim_create_autocmd', function() - it('"command" and "callback" are mutually exclusive', function() - local rv = pcall_err(meths.create_autocmd, "BufReadPost", { - pattern = "*.py,*.pyi", + it('validation', function() + eq("Cannot use both 'callback' and 'command'", pcall_err(meths.create_autocmd, 'BufReadPost', { + pattern = '*.py,*.pyi', command = "echo 'Should Have Errored", - callback = "NotAllowed", - }) - - eq("Cannot use both 'callback' and 'command'", rv) + callback = 'NotAllowed', + })) + eq("Cannot use both 'pattern' and 'buffer' for the same autocmd", pcall_err(meths.create_autocmd, 'FileType', { + command = 'let g:called = g:called + 1', + buffer = 0, + pattern = '*.py', + })) + eq("Required: 'event'", pcall_err(meths.create_autocmd, {}, { + command = 'ls', + })) + eq("Required: 'command' or 'callback'", pcall_err(meths.create_autocmd, 'FileType', { + })) + eq('Invalid desc: expected String, got Integer', pcall_err(meths.create_autocmd, 'FileType', { + command = 'ls', + desc = 42, + })) + eq('Invalid callback: expected Lua function or Vim function name, got Integer', pcall_err(meths.create_autocmd, 'FileType', { + callback = 0, + })) + eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd, + {'FileType', {}}, {})) end) it('doesnt leak when you use ++once', function() @@ -59,18 +76,8 @@ describe('autocmd api', function() eq(1, meths.get_var('called')) end) - it('does not allow passing buffer and patterns', function() - local rv = pcall_err(meths.create_autocmd, "Filetype", { - command = "let g:called = g:called + 1", - buffer = 0, - pattern = "*.py", - }) - - eq("Cannot use both 'pattern' and 'buffer' for the same autocmd", rv) - end) - it('does not allow passing invalid buffers', function() - local ok, msg = pcall(meths.create_autocmd, "Filetype", { + local ok, msg = pcall(meths.create_autocmd, 'FileType', { command = "let g:called = g:called + 1", buffer = -1, }) @@ -295,7 +302,7 @@ describe('autocmd api', function() describe('nvim_get_autocmds', function() describe('events', function() - it('should return one autocmd when there is only one for an event', function() + it('returns one autocmd when there is only one for an event', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] @@ -303,7 +310,7 @@ describe('autocmd api', function() eq(1, #aus) end) - it('should return two autocmds when there are two for an event', function() + it('returns two autocmds when there are two for an event', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] @@ -312,7 +319,7 @@ describe('autocmd api', function() eq(2, #aus) end) - it('should return the same thing if you use string or list', function() + it('returns the same thing if you use string or list', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] @@ -322,7 +329,7 @@ describe('autocmd api', function() eq(string_aus, array_aus) end) - it('should return two autocmds when there are two for an event', function() + it('returns two autocmds when there are two for an event', function() command [[au! InsertEnter]] command [[au! InsertLeave]] command [[au InsertEnter * :echo "1"]] @@ -332,7 +339,7 @@ describe('autocmd api', function() eq(2, #aus) end) - it('should return different IDs for different autocmds', function() + it('returns different IDs for different autocmds', function() command [[au! InsertEnter]] command [[au! InsertLeave]] command [[au InsertEnter * :echo "1"]] @@ -356,7 +363,7 @@ describe('autocmd api', function() eq(first, new_aus[1]) end) - it('should return event name', function() + it('returns event name', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] @@ -364,7 +371,7 @@ describe('autocmd api', function() eq({ { buflocal = false, command = ':echo "1"', event = "InsertEnter", once = false, pattern = "*" } }, aus) end) - it('should work with buffer numbers', function() + it('works with buffer numbers', function() command [[new]] command [[au! InsertEnter]] command [[au InsertEnter :echo "1"]] @@ -419,7 +426,7 @@ describe('autocmd api', function() eq("Too many buffers (maximum of 256)", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs })) end) - it('should return autocmds when group is specified by id', function() + it('returns autocmds when group is specified by id', function() local auid = meths.create_augroup("nvim_test_augroup", { clear = true }) meths.create_autocmd("FileType", { group = auid, command = 'echo "1"' }) meths.create_autocmd("FileType", { group = auid, command = 'echo "2"' }) @@ -431,7 +438,7 @@ describe('autocmd api', function() eq(0, #aus2) end) - it('should return autocmds when group is specified by name', function() + it('returns autocmds when group is specified by name', function() local auname = "nvim_test_augroup" meths.create_augroup(auname, { clear = true }) meths.create_autocmd("FileType", { group = auname, command = 'echo "1"' }) @@ -531,7 +538,7 @@ describe('autocmd api', function() command [[augroup END]] end) - it('should return all groups if no group is specified', function() + it('returns all groups if no group is specified', function() local aus = meths.get_autocmds { event = "InsertEnter" } if #aus ~= 4 then eq({}, aus) @@ -540,7 +547,7 @@ describe('autocmd api', function() eq(4, #aus) end) - it('should return only the group specified', function() + it('returns only the group specified', function() local aus = meths.get_autocmds { event = "InsertEnter", group = "GroupOne", @@ -551,7 +558,7 @@ describe('autocmd api', function() eq("GroupOne", aus[1].group_name) end) - it('should return only the group specified, multiple values', function() + it('returns only the group specified, multiple values', function() local aus = meths.get_autocmds { event = "InsertEnter", group = "GroupTwo", @@ -625,7 +632,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("Invalid 'pattern' item type: expected String, got Array", code) + matches("Invalid 'pattern' item: expected String, got Array", code) end) end) @@ -640,7 +647,7 @@ describe('autocmd api', function() command [[au InsertEnter :echo "Buffer"]] end) - it('should should return for literal match', function() + it('returns for literal match', function() local aus = meths.get_autocmds { event = "InsertEnter", pattern = "*" @@ -650,7 +657,7 @@ describe('autocmd api', function() eq([[:echo "No Group"]], aus[1].command) end) - it('should return for multiple matches', function() + it('returns for multiple matches', function() -- vim.api.nvim_get_autocmds local aus = meths.get_autocmds { event = "InsertEnter", @@ -687,6 +694,23 @@ describe('autocmd api', function() end) describe('nvim_exec_autocmds', function() + it('validation', function() + eq('Invalid group: 9997999', pcall_err(meths.exec_autocmds, 'FileType', { + group = 9997999, + })) + eq("Invalid group: 'bogus'", pcall_err(meths.exec_autocmds, 'FileType', { + group = 'bogus', + })) + eq('Invalid group: expected String or Integer, got Array', pcall_err(meths.exec_autocmds, 'FileType', { + group = {}, + })) + eq('Invalid buffer: expected Integer, got Array', pcall_err(meths.exec_autocmds, 'FileType', { + buffer = {}, + })) + eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.exec_autocmds, + {'FileType', {}}, {})) + end) + it("can trigger builtin autocmds", function() meths.set_var("autocmd_executed", false) @@ -1036,7 +1060,7 @@ describe('autocmd api', function() local augroup = "WillBeDeleted" meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd({"Filetype"}, { + meths.create_autocmd({"FileType"}, { pattern = "*", command = "echo 'does not matter'", }) @@ -1055,7 +1079,7 @@ describe('autocmd api', function() meths.set_var("value_set", false) meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd("Filetype", { + meths.create_autocmd("FileType", { pattern = "", command = "let g:value_set = v:true", }) @@ -1171,6 +1195,16 @@ describe('autocmd api', function() end) describe('nvim_clear_autocmds', function() + it('validation', function() + eq("Cannot use both 'pattern' and 'buffer'", pcall_err(meths.clear_autocmds, { + pattern = '*', + buffer = 42, + })) + eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.clear_autocmds, { + event = {'FileType', {}} + })) + end) + it('should clear based on event + pattern', function() command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"') command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 6b13729994..d454765edb 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -193,7 +193,7 @@ describe('api/buf', function() it('fails correctly when input is not valid', function() eq(1, api.curbufmeths.get_number()) - eq([[String cannot contain newlines]], + eq([['replacement string' item contains newlines]], pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'b\na'})) end) @@ -553,20 +553,20 @@ describe('api/buf', function() insert([[ hello foo! text]]) - eq('start_row out of bounds', pcall_err(set_text, 2, 0, 3, 0, {})) - eq('start_row out of bounds', pcall_err(set_text, -3, 0, 0, 0, {})) - eq('end_row out of bounds', pcall_err(set_text, 0, 0, 2, 0, {})) - eq('end_row out of bounds', pcall_err(set_text, 0, 0, -3, 0, {})) - eq('start_col out of bounds', pcall_err(set_text, 1, 5, 1, 5, {})) - eq('end_col out of bounds', pcall_err(set_text, 1, 0, 1, 5, {})) + eq("Invalid 'start_row': out of range", pcall_err(set_text, 2, 0, 3, 0, {})) + eq("Invalid 'start_row': out of range", pcall_err(set_text, -3, 0, 0, 0, {})) + eq("Invalid 'end_row': out of range", pcall_err(set_text, 0, 0, 2, 0, {})) + eq("Invalid 'end_row': out of range", pcall_err(set_text, 0, 0, -3, 0, {})) + eq("Invalid 'start_col': out of range", pcall_err(set_text, 1, 5, 1, 5, {})) + eq("Invalid 'end_col': out of range", pcall_err(set_text, 1, 0, 1, 5, {})) end) it('errors when start is greater than end', function() insert([[ hello foo! text]]) - eq('start is higher than end', pcall_err(set_text, 1, 0, 0, 0, {})) - eq('start is higher than end', pcall_err(set_text, 0, 1, 0, 0, {})) + eq("'start' is higher than 'end'", pcall_err(set_text, 1, 0, 0, 0, {})) + eq("'start' is higher than 'end'", pcall_err(set_text, 0, 1, 0, 0, {})) end) it('no heap-use-after-free when called consecutively #19643', function() @@ -611,7 +611,7 @@ describe('api/buf', function() 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' 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, {})) end) end) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index fc68f11a67..fab1557204 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -106,7 +106,7 @@ describe('API/extmarks', function() end_col = 0, end_row = 1 }) - eq("Invalid end_col: '(out of range)'", + eq("Invalid 'end_col': out of range", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 })) end) @@ -1362,13 +1362,13 @@ describe('API/extmarks', function() it('when col = line-length, set the mark on eol', function() local invalid_col = init_text:len() + 1 - eq("Invalid col: '(out of range)'", pcall_err(set_extmark, ns, marks[1], 0, invalid_col)) + eq("Invalid 'col': out of range", pcall_err(set_extmark, ns, marks[1], 0, invalid_col)) end) it('fails when line > line_count', function() local invalid_col = init_text:len() + 1 local invalid_lnum = 3 - eq("Invalid line: '(out of range)'", pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col)) + eq("Invalid 'line': out of range", pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col)) eq({}, get_extmark_by_id(ns, marks[1])) end) diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 7f044977cb..73551de42e 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -57,9 +57,7 @@ describe('API: highlight',function() eq(expected_rgb, nvim("get_hl_by_id", hl_id, true)) -- Test invalid id. - local err, emsg = pcall(meths.get_hl_by_id, 30000, false) - eq(false, err) - eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*')) + eq('Invalid highlight id: 30000', pcall_err(meths.get_hl_by_id, 30000, false)) -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') @@ -70,22 +68,14 @@ describe('API: highlight',function() eq(expected_undercurl, nvim("get_hl_by_id", hl_id, true)) -- Test nil argument. - err, emsg = pcall(meths.get_hl_by_id, { nil }, false) - eq(false, err) eq('Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', - string.match(emsg, 'Wrong.*')) + pcall_err(meths.get_hl_by_id, { nil }, false)) -- Test 0 argument. - err, emsg = pcall(meths.get_hl_by_id, 0, false) - eq(false, err) - eq('Invalid highlight id: 0', - string.match(emsg, 'Invalid.*')) + eq('Invalid highlight id: 0', pcall_err(meths.get_hl_by_id, 0, false)) -- Test -1 argument. - err, emsg = pcall(meths.get_hl_by_id, -1, false) - eq(false, err) - eq('Invalid highlight id: -1', - string.match(emsg, 'Invalid.*')) + eq('Invalid highlight id: -1', pcall_err(meths.get_hl_by_id, -1, false)) -- Test highlight group without ctermbg value. command('hi Normal ctermfg=red ctermbg=yellow') @@ -119,22 +109,16 @@ describe('API: highlight',function() eq(expected_normal, nvim("get_hl_by_name", 'Normal', true)) -- Test invalid name. - local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight', false) - eq(false, err) - eq('Invalid highlight name: unknown_highlight', - string.match(emsg, 'Invalid.*')) + eq("Invalid highlight name: 'unknown_highlight'", + pcall_err(meths.get_hl_by_name , 'unknown_highlight', false)) -- Test nil argument. - err, emsg = pcall(meths.get_hl_by_name , { nil }, false) - eq(false, err) eq('Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', - string.match(emsg, 'Wrong.*')) + pcall_err(meths.get_hl_by_name , { nil }, false)) -- Test empty string argument. - err, emsg = pcall(meths.get_hl_by_name , '', false) - eq(false, err) - eq('Invalid highlight name: ', - string.match(emsg, 'Invalid.*')) + eq('Invalid highlight name', + pcall_err(meths.get_hl_by_name , '', false)) -- Test "standout" attribute. #8054 eq({ underline = true, }, @@ -155,7 +139,7 @@ describe('API: highlight',function() it('nvim_get_hl_id_by_name', function() -- precondition: use a hl group that does not yet exist - eq('Invalid highlight name: Shrubbery', pcall_err(meths.get_hl_by_name, "Shrubbery", true)) + eq("Invalid highlight name: 'Shrubbery'", pcall_err(meths.get_hl_by_name, "Shrubbery", true)) eq(0, funcs.hlID("Shrubbery")) local hl_id = meths.get_hl_id_by_name("Shrubbery") @@ -253,25 +237,32 @@ describe("API: set highlight", function() before_each(clear) - it ("can set gui highlight", function() + it('validation', function() + eq("Invalid 'blend': out of range", + pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend=999})) + eq("Invalid blend: expected Integer, got Array", + pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend={}})) + end) + + it("can set gui highlight", function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', highlight1) eq(highlight1, meths.get_hl_by_name('Test_hl', true)) end) - it ("can set cterm highlight", function() + it("can set cterm highlight", function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', highlight2_config) eq(highlight2_result, meths.get_hl_by_name('Test_hl', false)) end) - it ("can set empty cterm attr", function() + it("can set empty cterm attr", function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', { cterm = {} }) eq({}, meths.get_hl_by_name('Test_hl', false)) end) - it ("cterm attr defaults to gui attr", function() + it("cterm attr defaults to gui attr", function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', highlight1) eq({ @@ -280,14 +271,14 @@ describe("API: set highlight", function() }, meths.get_hl_by_name('Test_hl', false)) end) - it ("can overwrite attr for cterm", function() + it("can overwrite attr for cterm", function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', highlight3_config) eq(highlight3_result_gui, meths.get_hl_by_name('Test_hl', true)) eq(highlight3_result_cterm, meths.get_hl_by_name('Test_hl', false)) end) - it ("can set a highlight in the global namespace", function() + it("can set a highlight in the global namespace", function() meths.set_hl(0, 'Test_hl', highlight2_config) eq('Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse', exec_capture('highlight Test_hl')) @@ -307,7 +298,7 @@ describe("API: set highlight", function() exec_capture('highlight Test_hl3')) end) - it ("can modify a highlight in the global namespace", function() + it("can modify a highlight in the global namespace", function() meths.set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue'}) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) @@ -328,17 +319,17 @@ describe("API: set highlight", function() eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) - eq("'redd' is not a valid color", + eq("Invalid highlight color: 'redd'", pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='redd'})) - eq("'bleu' is not a valid color", + eq("Invalid highlight color: 'bleu'", pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='bleu'})) meths.set_hl(0, 'Test_hl3', {fg='#FF00FF'}) eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3')) - eq("'#FF00FF' is not a valid color", + eq("Invalid highlight color: '#FF00FF'", pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='#FF00FF'})) for _, fg_val in ipairs{ nil, 'NONE', 'nOnE', '', -1 } do @@ -353,14 +344,14 @@ describe("API: set highlight", function() end) - it ("correctly sets 'Normal' internal properties", function() + it("correctly sets 'Normal' internal properties", function() -- Normal has some special handling internally. #18024 meths.set_hl(0, 'Normal', {fg='#000083', bg='#0000F3'}) eq({foreground = 131, background = 243}, nvim("get_hl_by_name", 'Normal', true)) end) it('does not segfault on invalid group name #20009', function() - eq('Invalid highlight name: foo bar', pcall_err(meths.set_hl, 0, 'foo bar', {bold = true})) + eq("Invalid highlight name: 'foo bar'", pcall_err(meths.set_hl, 0, 'foo bar', {bold = true})) assert_alive() end) end) diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua index 2028a8fba5..315653af14 100644 --- a/test/functional/api/proc_spec.lua +++ b/test/functional/api/proc_spec.lua @@ -42,7 +42,7 @@ describe('API', function() end) end) - it('validates input', function() + it('validation', function() local status, rv = pcall(request, "nvim_get_proc_children", -1) eq(false, status) eq("Invalid pid: -1", string.match(rv, "Invalid.*")) @@ -68,7 +68,7 @@ describe('API', function() neq(pid, pinfo.ppid) end) - it('validates input', function() + it('validation', function() local status, rv = pcall(request, "nvim_get_proc", -1) eq(false, status) eq("Invalid pid: -1", string.match(rv, "Invalid.*")) diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua index 279cd1856d..5654ef31ef 100644 --- a/test/functional/api/ui_spec.lua +++ b/test/functional/api/ui_spec.lua @@ -11,17 +11,37 @@ describe('nvim_ui_attach()', function() before_each(function() clear() end) + it('handles very large width/height #2180', function() local screen = Screen.new(999, 999) screen:attach() eq(999, eval('&lines')) eq(999, eval('&columns')) end) - it('invalid option returns error', function() + + it('validation', function() eq('No such UI option: foo', pcall_err(meths.ui_attach, 80, 24, { foo={'foo'} })) - end) - it('validates channel arg', function() + + eq('Invalid ext_linegrid: expected Boolean, got Array', + pcall_err(meths.ui_attach, 80, 24, { ext_linegrid={} })) + eq('Invalid override: expected Boolean, got Array', + pcall_err(meths.ui_attach, 80, 24, { override={} })) + eq('Invalid rgb: expected Boolean, got Array', + pcall_err(meths.ui_attach, 80, 24, { rgb={} })) + eq('Invalid term_name: expected String, got Boolean', + pcall_err(meths.ui_attach, 80, 24, { term_name=true })) + eq('Invalid term_colors: expected Integer, got Boolean', + pcall_err(meths.ui_attach, 80, 24, { term_colors=true })) + eq('Invalid term_background: expected String, got Boolean', + pcall_err(meths.ui_attach, 80, 24, { term_background=true })) + eq('Invalid stdin_fd: expected Integer, got String', + pcall_err(meths.ui_attach, 80, 24, { stdin_fd='foo' })) + eq('Invalid stdin_tty: expected Boolean, got String', + pcall_err(meths.ui_attach, 80, 24, { stdin_tty='foo' })) + eq('Invalid stdout_tty: expected Boolean, got String', + pcall_err(meths.ui_attach, 80, 24, { stdout_tty='foo' })) + eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_try_resize', 40, 10)) eq('UI not attached to channel: 1', diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 5c56c90952..469d8e8b6a 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1411,9 +1411,9 @@ describe('API', function() end) it('validation', function() - eq("Invalid scope (expected 'local' or 'global')", + eq("Invalid scope: expected 'local' or 'global'", pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 'bogus'})) - eq("Invalid scope (expected 'local' or 'global')", + eq("Invalid scope: expected 'local' or 'global'", pcall_err(nvim, 'set_option_value', 'scrolloff', 1, {scope = 'bogus'})) eq("Invalid scope: expected String, got Integer", pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 42})) @@ -2238,7 +2238,7 @@ describe('API', function() {'nvim_set_var'}, {'nvim_set_var', {'avar', 2}}, } - eq('Items in calls array must be arrays of size 2', + eq('calls item must be a 2-item Array', pcall_err(meths.call_atomic, req)) -- call before was done, but not after eq(1, meths.get_var('avar')) @@ -3119,11 +3119,11 @@ describe('API', function() meths.eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 })) end) it('rejects multiple-character fillchar', function() - eq('Invalid fillchar (not a single character)', + eq('Invalid fillchar: expected single character', pcall_err(meths.eval_statusline, '', { fillchar = 'aa' })) end) it('rejects empty string fillchar', function() - eq('Invalid fillchar (not a single character)', + eq('Invalid fillchar: expected single character', pcall_err(meths.eval_statusline, '', { fillchar = '' })) end) it('rejects non-string fillchar', function() -- cgit From 556f8646c01d1751cf39fe4df9c622899dceab9d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 14:19:28 -0500 Subject: refactor(api): consistent VALIDATE messages #22262 Problem: Validation messages are not consistently formatted. - Parameter names sometimes are NOT quoted. - Descriptive names (non-parameters) sometimes ARE quoted. Solution: Always quote the `name` value passed to a VALIDATE macro _unless_ the value has whitespace. --- test/functional/api/autocmd_spec.lua | 43 +++++++++++++++++------- test/functional/api/buffer_updates_spec.lua | 2 +- test/functional/api/command_spec.lua | 14 +++----- test/functional/api/extmark_spec.lua | 16 ++++++--- test/functional/api/highlight_spec.lua | 2 +- test/functional/api/proc_spec.lua | 8 ++--- test/functional/api/ui_spec.lua | 18 +++++----- test/functional/api/vim_spec.lua | 51 ++++++++++++++++------------- 8 files changed, 93 insertions(+), 61 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index f10f18174e..d1a93b5a86 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -30,11 +30,11 @@ describe('autocmd api', function() })) eq("Required: 'command' or 'callback'", pcall_err(meths.create_autocmd, 'FileType', { })) - eq('Invalid desc: expected String, got Integer', pcall_err(meths.create_autocmd, 'FileType', { + eq("Invalid 'desc': expected String, got Integer", pcall_err(meths.create_autocmd, 'FileType', { command = 'ls', desc = 42, })) - eq('Invalid callback: expected Lua function or Vim function name, got Integer', pcall_err(meths.create_autocmd, 'FileType', { + eq("Invalid 'callback': expected Lua function or Vim function name, got Integer", pcall_err(meths.create_autocmd, 'FileType', { callback = 0, })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd, @@ -301,6 +301,27 @@ describe('autocmd api', function() end) describe('nvim_get_autocmds', function() + it('validation', function() + eq("Invalid 'group': 9997999", pcall_err(meths.get_autocmds, { + group = 9997999, + })) + eq("Invalid 'group': 'bogus'", pcall_err(meths.get_autocmds, { + group = 'bogus', + })) + eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.get_autocmds, { + group = {}, + })) + eq("Invalid 'buffer': expected Integer or Array, got Boolean", pcall_err(meths.get_autocmds, { + buffer = true, + })) + eq("Invalid 'event': expected String or Array", pcall_err(meths.get_autocmds, { + event = true, + })) + eq("Invalid 'pattern': expected String or Array, got Boolean", pcall_err(meths.get_autocmds, { + pattern = true, + })) + end) + describe('events', function() it('returns one autocmd when there is only one for an event', function() command [[au! InsertEnter]] @@ -414,8 +435,8 @@ describe('autocmd api', function() pattern = "", }}, aus) - eq("Invalid buffer: expected Integer or Array, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) - eq("Invalid buffer: expected Integer, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) + eq("Invalid 'buffer': expected Integer or Array, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) + eq("Invalid 'buffer': expected Integer, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) eq("Invalid buffer id: 42", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { 42 } })) local bufs = {} @@ -585,7 +606,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("Invalid group: 'NotDefined'", code) + matches("Invalid 'group': 'NotDefined'", code) end) it('raises error for undefined augroup id', function() @@ -603,7 +624,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches('Invalid group: 1', code) + matches("Invalid 'group': 1", code) end) it('raises error for invalid group type', function() @@ -618,7 +639,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("Invalid group: expected String or Integer, got Boolean", code) + matches("Invalid 'group': expected String or Integer, got Boolean", code) end) it('raises error for invalid pattern array', function() @@ -695,16 +716,16 @@ describe('autocmd api', function() describe('nvim_exec_autocmds', function() it('validation', function() - eq('Invalid group: 9997999', pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'group': 9997999", pcall_err(meths.exec_autocmds, 'FileType', { group = 9997999, })) - eq("Invalid group: 'bogus'", pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'group': 'bogus'", pcall_err(meths.exec_autocmds, 'FileType', { group = 'bogus', })) - eq('Invalid group: expected String or Integer, got Array', pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { group = {}, })) - eq('Invalid buffer: expected Integer, got Array', pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'buffer': expected Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { buffer = {}, })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.exec_autocmds, diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 1510d31945..25b838a4af 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -762,7 +762,7 @@ describe('API: buffer events:', function() 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 'opts' key: 'builtin'", pcall_err(buffer, 'attach', b, false, {builtin="asfd"})) end) it('nvim_buf_attach returns response after delay #8634', function() diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 189f9d4f98..9db687cc37 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -543,23 +543,19 @@ describe('nvim_create_user_command', function() end) it('does not allow invalid command names', function() - matches("Invalid command name %(must begin with an uppercase letter%): 'test'", pcall_err(exec_lua, [[ + eq("Invalid command name (must start with uppercase): 'test'", pcall_err(exec_lua, [[ vim.api.nvim_create_user_command('test', 'echo "hi"', {}) ]])) - - matches('Invalid command name', pcall_err(exec_lua, [[ + eq("Invalid command name: 't@'", pcall_err(exec_lua, [[ vim.api.nvim_create_user_command('t@', 'echo "hi"', {}) ]])) - - matches('Invalid command name', pcall_err(exec_lua, [[ + eq("Invalid command name: 'T@st'", pcall_err(exec_lua, [[ vim.api.nvim_create_user_command('T@st', 'echo "hi"', {}) ]])) - - matches('Invalid command name', pcall_err(exec_lua, [[ + eq("Invalid command name: 'Test!'", pcall_err(exec_lua, [[ vim.api.nvim_create_user_command('Test!', 'echo "hi"', {}) ]])) - - matches('Invalid command name', pcall_err(exec_lua, [[ + eq("Invalid command name: '💩'", pcall_err(exec_lua, [[ vim.api.nvim_create_user_command('💩', 'echo "hi"', {}) ]])) end) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index fab1557204..3f9cb94260 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -101,6 +101,14 @@ describe('API/extmarks', function() ns2 = request('nvim_create_namespace', "my-fancy-plugin2") end) + it('validation', function() + eq("Invalid 'end_col': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = {}, end_row = 1 })) + eq("Invalid 'end_row': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = {} })) + eq("Invalid 'id': expected positive Integer", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })) + eq("Invalid mark position: expected 2 Integer items", pcall_err(get_extmarks, ns, {}, {-1, -1})) + eq("Invalid mark position: expected mark id Integer or 2-item Array", pcall_err(get_extmarks, ns, true, {-1, -1})) + end) + it("can end extranges past final newline using end_col = 0", function() set_extmark(ns, marks[1], 0, 0, { end_col = 0, @@ -1344,10 +1352,10 @@ describe('API/extmarks', function() it('throws consistent error codes', function() local ns_invalid = ns2 + 1 - eq("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(get_extmarks, ns_invalid, positions[1], positions[2])) - eq("Invalid ns_id: 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1])) + eq("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(get_extmarks, ns_invalid, positions[1], positions[2])) + eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1])) end) it('when col = line-length, set the mark on eol', function() diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 73551de42e..e1b3562329 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -240,7 +240,7 @@ describe("API: set highlight", function() it('validation', function() eq("Invalid 'blend': out of range", pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend=999})) - eq("Invalid blend: expected Integer, got Array", + eq("Invalid 'blend': expected Integer, got Array", pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend={}})) end) diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua index 315653af14..20edea3feb 100644 --- a/test/functional/api/proc_spec.lua +++ b/test/functional/api/proc_spec.lua @@ -45,11 +45,11 @@ describe('API', function() it('validation', function() local status, rv = pcall(request, "nvim_get_proc_children", -1) eq(false, status) - eq("Invalid pid: -1", string.match(rv, "Invalid.*")) + eq("Invalid 'pid': -1", string.match(rv, "Invalid.*")) status, rv = pcall(request, "nvim_get_proc_children", 0) eq(false, status) - eq("Invalid pid: 0", string.match(rv, "Invalid.*")) + eq("Invalid 'pid': 0", string.match(rv, "Invalid.*")) -- Assume PID 99999 does not exist. status, rv = pcall(request, "nvim_get_proc_children", 99999) @@ -71,11 +71,11 @@ describe('API', function() it('validation', function() local status, rv = pcall(request, "nvim_get_proc", -1) eq(false, status) - eq("Invalid pid: -1", string.match(rv, "Invalid.*")) + eq("Invalid 'pid': -1", string.match(rv, "Invalid.*")) status, rv = pcall(request, "nvim_get_proc", 0) eq(false, status) - eq("Invalid pid: 0", string.match(rv, "Invalid.*")) + eq("Invalid 'pid': 0", string.match(rv, "Invalid.*")) -- Assume PID 99999 does not exist. status, rv = pcall(request, "nvim_get_proc", 99999) diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua index 5654ef31ef..b616f51d10 100644 --- a/test/functional/api/ui_spec.lua +++ b/test/functional/api/ui_spec.lua @@ -23,23 +23,23 @@ describe('nvim_ui_attach()', function() eq('No such UI option: foo', pcall_err(meths.ui_attach, 80, 24, { foo={'foo'} })) - eq('Invalid ext_linegrid: expected Boolean, got Array', + eq("Invalid 'ext_linegrid': expected Boolean, got Array", pcall_err(meths.ui_attach, 80, 24, { ext_linegrid={} })) - eq('Invalid override: expected Boolean, got Array', + eq("Invalid 'override': expected Boolean, got Array", pcall_err(meths.ui_attach, 80, 24, { override={} })) - eq('Invalid rgb: expected Boolean, got Array', + eq("Invalid 'rgb': expected Boolean, got Array", pcall_err(meths.ui_attach, 80, 24, { rgb={} })) - eq('Invalid term_name: expected String, got Boolean', + eq("Invalid 'term_name': expected String, got Boolean", pcall_err(meths.ui_attach, 80, 24, { term_name=true })) - eq('Invalid term_colors: expected Integer, got Boolean', + eq("Invalid 'term_colors': expected Integer, got Boolean", pcall_err(meths.ui_attach, 80, 24, { term_colors=true })) - eq('Invalid term_background: expected String, got Boolean', + eq("Invalid 'term_background': expected String, got Boolean", pcall_err(meths.ui_attach, 80, 24, { term_background=true })) - eq('Invalid stdin_fd: expected Integer, got String', + eq("Invalid 'stdin_fd': expected Integer, got String", pcall_err(meths.ui_attach, 80, 24, { stdin_fd='foo' })) - eq('Invalid stdin_tty: expected Boolean, got String', + eq("Invalid 'stdin_tty': expected Boolean, got String", pcall_err(meths.ui_attach, 80, 24, { stdin_tty='foo' })) - eq('Invalid stdout_tty: expected Boolean, got String', + eq("Invalid 'stdout_tty': expected Boolean, got String", pcall_err(meths.ui_attach, 80, 24, { stdout_tty='foo' })) eq('UI not attached to channel: 1', diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 469d8e8b6a..981fc19b36 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -490,7 +490,7 @@ describe('API', function() eq('', eval('v:errmsg')) -- v:errmsg was not updated. end) - it('validates args', function() + it('validation', function() local too_many_args = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' } source([[ function! Foo(...) abort @@ -532,7 +532,7 @@ describe('API', function() eq('@it works@', nvim('call_dict_function', { result = 'it works', G = 'G'}, 'G', {})) end) - it('validates args', function() + it('validation', function() command('let g:d={"baz":"zub","meep":[]}') eq('Not found: bogus', pcall_err(request, 'nvim_call_dict_function', 'g:d', 'bogus', {1,2})) @@ -648,10 +648,10 @@ describe('API', function() end) describe('nvim_paste', function() - it('validates args', function() - eq('Invalid phase: -2', + it('validation', function() + eq("Invalid 'phase': -2", pcall_err(request, 'nvim_paste', 'foo', true, -2)) - eq('Invalid phase: 4', + eq("Invalid 'phase': 4", pcall_err(request, 'nvim_paste', 'foo', true, 4)) end) local function run_streamed_paste_tests() @@ -1154,10 +1154,10 @@ describe('API', function() end) describe('nvim_put', function() - it('validates args', function() - eq("Invalid line: expected String, got Integer", + it('validation', function() + eq("Invalid 'line': expected String, got Integer", pcall_err(request, 'nvim_put', {42}, 'l', false, false)) - eq("Invalid type: 'x'", + eq("Invalid 'type': 'x'", pcall_err(request, 'nvim_put', {'foo'}, 'x', false, false)) end) it("fails if 'nomodifiable'", function() @@ -1259,9 +1259,9 @@ describe('API', function() yyybc line 2 line 3 ]]) - eq("Invalid type: 'bx'", + eq("Invalid 'type': 'bx'", pcall_err(meths.put, {'xxx', 'yyy'}, 'bx', false, true)) - eq("Invalid type: 'b3x'", + eq("Invalid 'type': 'b3x'", pcall_err(meths.put, {'xxx', 'yyy'}, 'b3x', false, true)) end) end) @@ -1288,6 +1288,11 @@ describe('API', function() end) describe('set/get/del variables', function() + it('validation', function() + eq('Key not found: bogus', pcall_err(meths.get_var, 'bogus')) + eq('Key not found: bogus', pcall_err(meths.del_var, 'bogus')) + 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')) @@ -1411,12 +1416,14 @@ describe('API', function() end) it('validation', function() - eq("Invalid scope: expected 'local' or 'global'", + eq("Invalid 'scope': expected 'local' or 'global'", pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 'bogus'})) - eq("Invalid scope: expected 'local' or 'global'", + eq("Invalid 'scope': expected 'local' or 'global'", pcall_err(nvim, 'set_option_value', 'scrolloff', 1, {scope = 'bogus'})) - eq("Invalid scope: expected String, got Integer", + eq("Invalid 'scope': expected String, got Integer", pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 42})) + eq("Invalid 'scrolloff': expected Integer/Boolean/String, got Array", + pcall_err(nvim, 'set_option_value', 'scrolloff', {}, {})) end) it('can get local values when global value is set', function() @@ -1786,12 +1793,12 @@ describe('API', function() end) describe('nvim_get_context', function() - it('validates args', function() + it('validation', function() eq("Invalid key: 'blah'", pcall_err(nvim, 'get_context', {blah={}})) - eq("Invalid types: expected Array, got Integer", + eq("Invalid 'types': expected Array, got Integer", pcall_err(nvim, 'get_context', {types=42})) - eq("Invalid type: 'zub'", + eq("Invalid 'type': 'zub'", pcall_err(nvim, 'get_context', {types={'jumps', 'zub', 'zam',}})) end) it('returns map of current editor state', function() @@ -2238,7 +2245,7 @@ describe('API', function() {'nvim_set_var'}, {'nvim_set_var', {'avar', 2}}, } - eq('calls item must be a 2-item Array', + eq("Invalid 'calls' item: expected 2-item Array", pcall_err(meths.call_atomic, req)) -- call before was done, but not after eq(1, meths.get_var('avar')) @@ -2247,7 +2254,7 @@ describe('API', function() { 'nvim_set_var', { 'bvar', { 2, 3 } } }, 12, } - eq("Invalid calls item: expected Array, got Integer", + eq("Invalid 'calls' item: expected Array, got Integer", pcall_err(meths.call_atomic, req)) eq({2,3}, meths.get_var('bvar')) @@ -2255,7 +2262,7 @@ describe('API', function() {'nvim_set_current_line', 'little line'}, {'nvim_set_var', {'avar', 3}}, } - eq("Invalid args: expected Array, got String", + eq("Invalid call args: expected Array, got String", pcall_err(meths.call_atomic, req)) -- call before was done, but not after eq(1, meths.get_var('avar')) @@ -3119,15 +3126,15 @@ describe('API', function() meths.eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 })) end) it('rejects multiple-character fillchar', function() - eq('Invalid fillchar: expected single character', + eq("Invalid 'fillchar': expected single character", pcall_err(meths.eval_statusline, '', { fillchar = 'aa' })) end) it('rejects empty string fillchar', function() - eq('Invalid fillchar: expected single character', + eq("Invalid 'fillchar': expected single character", pcall_err(meths.eval_statusline, '', { fillchar = '' })) end) it('rejects non-string fillchar', function() - eq("Invalid fillchar: expected String, got Integer", + eq("Invalid 'fillchar': expected String, got Integer", pcall_err(meths.eval_statusline, '', { fillchar = 1 })) end) it('rejects invalid string', function() -- cgit From 09b3432eaff3abcadb56d61b6f247f992b80b63f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 16 Feb 2023 10:07:18 -0500 Subject: fix(api): allow empty Lua table for nested dicts #22268 Problem: The Lua-API bridge allows Dict params to be empty Lua (list) tables at the function-signature level. But not for _nested_ Dicts, because they are not modeled: https://github.com/neovim/neovim/blob/fae754073289566051433fae74ec65783f9e7a6a/src/nvim/api/keysets.lua#L184 Some API functions like nvim_cmd check for kObjectTypeDictionary and don't handle the case of empty Lua tables (treated as "Array"). Solution: Introduce VALIDATE_T_DICT and use it in places where kObjectTypeDictionary was being checked directly. fixes #21005 --- test/functional/api/command_spec.lua | 2 +- test/functional/api/vim_spec.lua | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 9db687cc37..1ddb289ded 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -24,7 +24,7 @@ describe('nvim_get_commands', function() eq({}, meths.get_commands({builtin=false})) end) - it('validates input', function() + it('validation', function() eq('builtin=true not implemented', pcall_err(meths.get_commands, {builtin=true})) eq("Invalid key: 'foo'", pcall_err(meths.get_commands, diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 981fc19b36..3e40967dd5 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3826,14 +3826,71 @@ describe('API', function() meths.cmd({ cmd = "set", args = { "cursorline" } }, {}) eq(true, meths.get_option_value("cursorline", {})) end) + + it('validation', function() + eq("Invalid 'cmd': expected non-empty String", + pcall_err(meths.cmd, { cmd = ""}, {})) + eq("Invalid 'cmd': expected non-empty String", + pcall_err(meths.cmd, { cmd = {}}, {})) + eq("Invalid 'args': expected Array, got Boolean", + pcall_err(meths.cmd, { cmd = "set", args = true }, {})) + eq("Invalid 'magic': expected Dict, got Array", + pcall_err(meths.cmd, { cmd = "set", args = {}, magic = {} }, {})) + eq("Invalid command arg: expected non-whitespace", + pcall_err(meths.cmd, { cmd = "set", args = {' '}, }, {})) + eq("Invalid command arg: expected valid type, got Array", + pcall_err(meths.cmd, { cmd = "set", args = {{}}, }, {})) + eq("Wrong number of arguments", + pcall_err(meths.cmd, { cmd = "aboveleft", args = {}, }, {})) + eq("Command cannot accept bang: print", + pcall_err(meths.cmd, { cmd = "print", args = {}, bang = true }, {})) + + eq("Command cannot accept range: set", + pcall_err(meths.cmd, { cmd = "set", args = {}, range = {1} }, {})) + eq("Invalid 'range': expected Array, got Boolean", + pcall_err(meths.cmd, { cmd = "print", args = {}, range = true }, {})) + eq("Invalid 'range': expected <=2 elements", + pcall_err(meths.cmd, { cmd = "print", args = {}, range = {1,2,3,4} }, {})) + eq("Invalid range element: expected non-negative Integer", + pcall_err(meths.cmd, { cmd = "print", args = {}, range = {-1} }, {})) + + eq("Command cannot accept count: set", + pcall_err(meths.cmd, { cmd = "set", args = {}, count = 1 }, {})) + eq("Invalid 'count': expected non-negative Integer", + pcall_err(meths.cmd, { cmd = "print", args = {}, count = true }, {})) + eq("Invalid 'count': expected non-negative Integer", + pcall_err(meths.cmd, { cmd = "print", args = {}, count = -1 }, {})) + + eq("Command cannot accept register: set", + pcall_err(meths.cmd, { cmd = "set", args = {}, reg = 'x' }, {})) + eq('Cannot use register "=', + pcall_err(meths.cmd, { cmd = "put", args = {}, reg = '=' }, {})) + eq("Invalid 'reg': expected single character, got xx", + pcall_err(meths.cmd, { cmd = "put", args = {}, reg = 'xx' }, {})) + + -- Lua call allows empty {} for dict item. + eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, magic = {} }]])) + eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, mods = {} }]])) + + -- Lua call does not allow non-empty list-like {} for dict item. + eq("Invalid 'magic': expected Dict, got Array", + pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, magic = { 'a' } }]])) + eq("Invalid key: 'bogus'", + pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, magic = { bogus = true } }]])) + eq("Invalid key: 'bogus'", + pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, mods = { bogus = true } }]])) + end) + it('captures output', function() eq("foo", meths.cmd({ cmd = "echo", args = { '"foo"' } }, { output = true })) end) + it('sets correct script context', function() meths.cmd({ cmd = "set", args = { "cursorline" } }, {}) local str = meths.exec([[verbose set cursorline?]], true) neq(nil, str:find("cursorline\n\tLast set from API client %(channel id %d+%)")) end) + it('works with range', function() insert [[ line1 -- cgit From 524e1a06432ed7a88c1e183d81812dd48dc18cfb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Feb 2023 16:15:04 +0800 Subject: fix(highlight): avoid ORing underline flags (#22372) When combining attributes use the one that takes priority. For :highlight command use the last one specified. For API use a hard-coded order same as the order in docs. --- test/functional/api/highlight_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index e1b3562329..eb7d0f7b47 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -278,6 +278,20 @@ describe("API: set highlight", function() eq(highlight3_result_cterm, meths.get_hl_by_name('Test_hl', false)) end) + it("only allows one underline attribute #22371", function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { + underdouble = true, + underdotted = true, + cterm = { + underline = true, + undercurl = true, + }, + }) + eq({ undercurl = true }, meths.get_hl_by_name('Test_hl', false)) + eq({ underdotted = true }, meths.get_hl_by_name('Test_hl', true)) + end) + it("can set a highlight in the global namespace", function() meths.set_hl(0, 'Test_hl', highlight2_config) eq('Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse', -- cgit From 7f424e2b65779c59fc0cac3cc7508ba2ec07f200 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 23 Feb 2023 18:29:36 +0100 Subject: feat(api): more fields in nvim_list_uis Problem: nvim_list_uis does not report all ":help ui-option" fields. Solution: Store ":help ui-option" fields on the `UI` object and update ui_array. --- test/functional/api/vim_spec.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 3e40967dd5..08abf82f47 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2549,20 +2549,26 @@ describe('API', function() { chan = 1, ext_cmdline = false, - ext_popupmenu = false, - ext_tabline = false, - ext_wildmenu = false, + ext_hlstate = false, ext_linegrid = screen._options.ext_linegrid or false, + ext_messages = false, ext_multigrid = false, - ext_hlstate = false, + ext_popupmenu = false, + ext_tabline = false, ext_termcolors = false, - ext_messages = false, + ext_wildmenu = false, height = 4, - rgb = true, override = true, + rgb = true, + stdin_tty = false, + stdout_tty = false, + term_background = '', + term_colors = 0, + term_name = '', width = 20, } } + eq(expected, nvim("list_uis")) screen:detach() -- cgit From 39842be8cd8808c7da2638a6cc84d7c3fe40b996 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Mar 2023 07:09:28 +0800 Subject: fix(extmarks): don't leak memory on error (#22507) --- test/functional/api/extmark_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 3f9cb94260..30e75b8061 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -107,6 +107,13 @@ describe('API/extmarks', function() eq("Invalid 'id': expected positive Integer", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })) eq("Invalid mark position: expected 2 Integer items", pcall_err(get_extmarks, ns, {}, {-1, -1})) eq("Invalid mark position: expected mark id Integer or 2-item Array", pcall_err(get_extmarks, ns, true, {-1, -1})) + -- No memory leak with virt_text, virt_lines, sign_text + eq("right_gravity is not a boolean", pcall_err(set_extmark, ns, marks[2], 0, 0, { + virt_text = {{'foo', 'Normal'}}, + virt_lines = {{{'bar', 'Normal'}}}, + sign_text = 'a', + right_gravity = 'baz', + })) end) it("can end extranges past final newline using end_col = 0", function() -- cgit From 6d0c61d90d316473eee0729363e20bf06825b09b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Mar 2023 21:09:11 +0800 Subject: fix(api): set script context when setting usercmd or option (#22624) --- test/functional/api/vim_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 08abf82f47..48ac491ade 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2832,6 +2832,24 @@ describe('API', function() type = "boolean", was_set = true }, meths.get_option_info'showcmd') + + meths.set_option_value('showcmd', true, {}) + + eq({ + allows_duplicates = true, + commalist = false, + default = true, + flaglist = false, + global_local = false, + last_set_chan = 1, + last_set_linenr = 0, + last_set_sid = -9, + name = "showcmd", + scope = "global", + shortname = "sc", + type = "boolean", + was_set = true + }, meths.get_option_info'showcmd') end) end) -- cgit From 673d2b52fa4335aa083c52e6686f0728e25b8ebd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 7 Mar 2023 16:04:57 +0100 Subject: refactor!: rename vim.pretty_print => vim.print Problem: The function name `vim.pretty_print`: 1. is verbose, which partially defeats its purpose as sugar 2. does not draw from existing precedent or any sort of convention (except external projects like penlight or python?), which reduces discoverability, and degrades signaling about best practices. Solution: - Rename to `vim.print`. - Change the behavior so that 1. strings are printed without quotes 2. each arg is printed on its own line 3. tables are indented with 2 instead of 4 spaces - Example: :lua ='a', 'b', 42, {a=3} a b 42 { a = 3 } Comparison of alternatives: - `vim.print`: - pro: consistent with Lua's `print()` - pro: aligns with potential `nvim_print` API function which will replace nvim_echo, nvim_notify, etc. - con: behaves differently than Lua's `print()`, slightly misleading? - `vim.echo`: - pro: `:echo` has similar "pretty print" behavior. - con: inconsistent with Lua idioms. - `vim.p`: - pro: very short, fits with `vim.o`, etc. - con: not as discoverable as "echo" - con: less opportunity for `local p = vim.p` because of potential shadowing. --- test/functional/api/vim_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 48ac491ade..2af041c706 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -4042,7 +4042,7 @@ describe('API', function() it('splits arguments correctly for Lua callback', function() meths.exec_lua([[ local function FooFunc(opts) - vim.pretty_print(opts.fargs) + vim.print(opts.fargs) end vim.api.nvim_create_user_command("Foo", FooFunc, { nargs = '+' }) -- cgit From e5641df6d3fc3bb6c3c55593b6152082bfc561b6 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 11 Mar 2023 17:11:02 +0000 Subject: feat: add `vim.filetype.get_option()` --- test/functional/api/vim_spec.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 2af041c706..ff1bfef591 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1518,6 +1518,31 @@ describe('API', function() nvim('get_option_value', 'filetype', {buf = buf}) eq({1, 9}, nvim('win_get_cursor', win)) end) + + it('can get default option values for filetypes', function() + command('filetype plugin on') + for ft, opts in pairs { + lua = { commentstring = '-- %s' }, + vim = { commentstring = '"%s' }, + man = { tagfunc = 'v:lua.require\'man\'.goto_tag' }, + xml = { formatexpr = 'xmlformat#Format()' } + } do + for option, value in pairs(opts) do + eq(value, 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' })) + 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' })) + end) + end) describe('nvim_{get,set}_current_buf, nvim_list_bufs', function() -- cgit From c0fe6c040e19ef9102a8507ffcbd88b83186326a Mon Sep 17 00:00:00 2001 From: Null Chilly <56817415+nullchilly@users.noreply.github.com> Date: Thu, 23 Mar 2023 16:31:39 +0700 Subject: feat(api): add nvim_get_hl (#22693) Problem: no way of getting all highlight group definitions in a namespace. Solution: add `nvim_get_hl()`, deprecate `nvim_get_hl_by_name()` and `nvim_get_hl_by_id()`. --- test/functional/api/highlight_spec.lua | 219 +++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index eb7d0f7b47..de3eb4e798 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -369,3 +369,222 @@ describe("API: set highlight", function() assert_alive() end) end) + +describe('API: get highlight', function() + local highlight_color = { + fg = tonumber('0xff0000'), + bg = tonumber('0x0032aa'), + ctermfg = 8, + ctermbg = 15, + } + local highlight1 = { + bg = highlight_color.bg, + fg = highlight_color.fg, + bold = true, + italic = true, + } + local highlight2 = { + ctermbg = highlight_color.ctermbg, + ctermfg = highlight_color.ctermfg, + underline = true, + reverse = true, + } + local highlight3_config = { + bg = highlight_color.bg, + fg = highlight_color.fg, + ctermbg = highlight_color.ctermbg, + ctermfg = highlight_color.ctermfg, + bold = true, + italic = true, + reverse = true, + underdashed = true, + strikethrough = true, + altfont = true, + cterm = { + italic = true, + reverse = true, + strikethrough = true, + altfont = true, + nocombine = true, + }, + } + local highlight3_result = { + bg = highlight_color.bg, + fg = highlight_color.fg, + ctermbg = highlight_color.ctermbg, + ctermfg = highlight_color.ctermfg, + bold = true, + italic = true, + nocombine = true, + reverse = true, + underdashed = true, + strikethrough = true, + altfont = true, + } + + local function get_ns() + -- Test namespace filtering behavior + local ns2 = meths.create_namespace('Another_namespace') + meths.set_hl(ns2, 'Test_hl', { ctermfg = 23 }) + meths.set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' }) + meths.set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' }) + meths.set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' }) + + local ns = meths.create_namespace('Test_set_hl') + meths.set_hl_ns(ns) + + return ns + end + + before_each(clear) + + it('validation', function() + eq( + 'Invalid highlight name: expected String, got Integer', + pcall_err(meths.get_hl, 0, { name = 177 }) + ) + eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' })) + end) + + it('can get all highlights in current namespace', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) + meths.set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) + eq({ + Test_hl = { + bg = 11845374 + }, + Test_hl_link = { + link = 'Test_hl' + } + }, meths.get_hl(ns, {})) + end) + + it('can get gui highlight', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('can get cterm highlight', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', highlight2) + eq(highlight2, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('can get empty cterm attr', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('cterm attr defaults to gui attr', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('can overwrite attr for cterm', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', highlight3_config) + eq(highlight3_result, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('only allows one underline attribute #22371', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { + underdouble = true, + underdotted = true, + cterm = { + underline = true, + undercurl = true, + }, + }) + eq({ undercurl = true, underdotted = true }, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('can get a highlight in the global namespace', function() + meths.set_hl(0, 'Test_hl', highlight2) + eq(highlight2, meths.get_hl(0, { name = 'Test_hl' })) + + meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) + eq({ + bg = 12970, + }, meths.get_hl(0, { name = 'Test_hl' })) + + meths.set_hl(0, 'Test_hl2', highlight3_config) + eq(highlight3_result, meths.get_hl(0, { name = 'Test_hl2' })) + + -- Colors are stored with the name they are defined, but + -- with canonical casing + meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + eq({ + bg = 16711680, + fg = 255, + }, meths.get_hl(0, { name = 'Test_hl3' })) + end) + + local expected_rgb = { + altfont = true, + bg = 16776960, + bold = true, + ctermbg = 10, + fg = 16711680, + italic = true, + nocombine = true, + reverse = true, + sp = 255, + strikethrough = true, + underline = true, + } + local expected = { + bg = 16776960, + bold = true, + ctermbg = 10, + fg = 16711680, + sp = 255, + underline = true, + } + local expected_undercurl = { + bg = 16776960, + ctermbg = 10, + fg = 16711680, + sp = 255, + undercurl = true, + underline = true, + } + + it('nvim_get_hl by id', function() + local hl_id = meths.get_hl_id_by_name('NewHighlight') + + command( + 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' + ) + eq(expected, meths.get_hl(0, { id = hl_id })) + + -- Test 0 argument + eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 })) + + eq( + 'Invalid highlight id: expected Integer, got String', + pcall_err(meths.get_hl, 0, { id = 'Test_set_hl' }) + ) + + -- Test all highlight properties. + command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') + eq(expected_rgb, meths.get_hl(0, { id = hl_id })) + + -- Test undercurl + command('hi NewHighlight gui=undercurl') + eq(expected_undercurl, meths.get_hl(0, { id = hl_id })) + end) + + it('can correctly detect links', function() + command('hi String guifg=#a6e3a1') + command('hi link @string string') + command('hi link @string.cpp @string') + eq({ fg = 10937249 }, meths.get_hl(0, { name = 'String' })) + eq({ link = 'String' }, meths.get_hl(0, { name = '@string' })) + eq({ fg = 10937249 }, meths.get_hl(0, { name = '@string.cpp', link = false })) + end) +end) -- cgit From 6d267ad30cf539f520b46e3c92939f7031ce116f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 23 Mar 2023 12:44:05 +0100 Subject: fix(api): make nvim_get_hl return 'cterm' attrs properly --- test/functional/api/highlight_spec.lua | 64 ++++++++++------------------------ 1 file changed, 19 insertions(+), 45 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index de3eb4e798..65b13bebf7 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -380,14 +380,14 @@ describe('API: get highlight', function() local highlight1 = { bg = highlight_color.bg, fg = highlight_color.fg, - bold = true, - italic = true, + bold = true, italic = true, + cterm = {bold = true, italic = true}, } local highlight2 = { ctermbg = highlight_color.ctermbg, ctermfg = highlight_color.ctermfg, - underline = true, - reverse = true, + underline = true, reverse = true, + cterm = {underline = true, reverse = true}, } local highlight3_config = { bg = highlight_color.bg, @@ -413,13 +413,8 @@ describe('API: get highlight', function() fg = highlight_color.fg, ctermbg = highlight_color.ctermbg, ctermfg = highlight_color.ctermfg, - bold = true, - italic = true, - nocombine = true, - reverse = true, - underdashed = true, - strikethrough = true, - altfont = true, + bold = true, italic = true, reverse = true, underdashed = true, strikethrough = true, altfont = true, + cterm = {italic = true, nocombine = true, reverse = true, strikethrough = true, altfont = true} } local function get_ns() @@ -500,7 +495,8 @@ describe('API: get highlight', function() undercurl = true, }, }) - eq({ undercurl = true, underdotted = true }, meths.get_hl(ns, { name = 'Test_hl' })) + eq({ underdotted = true, cterm = { undercurl = true} }, + meths.get_hl(ns, { name = 'Test_hl' })) end) it('can get a highlight in the global namespace', function() @@ -524,43 +520,15 @@ describe('API: get highlight', function() }, meths.get_hl(0, { name = 'Test_hl3' })) end) - local expected_rgb = { - altfont = true, - bg = 16776960, - bold = true, - ctermbg = 10, - fg = 16711680, - italic = true, - nocombine = true, - reverse = true, - sp = 255, - strikethrough = true, - underline = true, - } - local expected = { - bg = 16776960, - bold = true, - ctermbg = 10, - fg = 16711680, - sp = 255, - underline = true, - } - local expected_undercurl = { - bg = 16776960, - ctermbg = 10, - fg = 16711680, - sp = 255, - undercurl = true, - underline = true, - } - it('nvim_get_hl by id', function() local hl_id = meths.get_hl_id_by_name('NewHighlight') command( 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' ) - eq(expected, meths.get_hl(0, { id = hl_id })) + eq({ fg = 16711680, bg = 16776960, sp = 255, bold = true, + ctermbg = 10, cterm = { underline = true }, + }, meths.get_hl(0, { id = hl_id })) -- Test 0 argument eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 })) @@ -572,11 +540,17 @@ describe('API: get highlight', function() -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') - eq(expected_rgb, meths.get_hl(0, { id = hl_id })) + eq({ fg = 16711680, bg = 16776960, sp = 255, + altfont = true, bold = true, italic = true, nocombine = true, reverse = true, strikethrough = true, underline = true, + ctermbg = 10, cterm = {underline = true}, + }, meths.get_hl(0, { id = hl_id })) -- Test undercurl command('hi NewHighlight gui=undercurl') - eq(expected_undercurl, meths.get_hl(0, { id = hl_id })) + eq({ fg = 16711680, bg = 16776960, sp = 255, undercurl = true, + ctermbg = 10, + cterm = {underline = true}, + }, meths.get_hl(0, { id = hl_id })) end) it('can correctly detect links', function() -- cgit From fe9cbcb3a5c82932ecfb8f49d07e98a1fc2b31e5 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sat, 25 Mar 2023 18:58:48 +0200 Subject: feat(api): nvim_exec2(), deprecate nvim_exec() #19032 Problem: The signature of nvim_exec() is not extensible per ":help api-contract". Solution: Introduce nvim_exec2() and deprecate nvim_exec(). --- test/functional/api/extmark_spec.lua | 6 +- test/functional/api/keymap_spec.lua | 12 ++- test/functional/api/vim_spec.lua | 149 +++++++++++++++++++---------------- 3 files changed, 92 insertions(+), 75 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 30e75b8061..e9a175625b 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1413,12 +1413,12 @@ describe('API/extmarks', function() end) it('does not crash with append/delete/undo sequence', function() - meths.exec([[ + meths.exec2([[ let ns = nvim_create_namespace('myplugin') call nvim_buf_set_extmark(0, ns, 0, 0, {}) call append(0, '') %delete - undo]],false) + undo]], { output = false }) assert_alive() end) @@ -1450,7 +1450,7 @@ describe('API/extmarks', function() feed('u') -- handles pasting - meths.exec([[let @a='asdfasdf']], false) + meths.exec2([[let @a='asdfasdf']], { output = false }) feed([["ap]]) eq({ {1, 0, 0}, {2, 0, 8} }, meths.buf_get_extmarks(0, ns, 0, -1, {})) diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 5be4425162..78281be195 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -681,13 +681,13 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it('can set mappings whose RHS change dynamically', function() - meths.exec([[ + meths.exec2([[ function! FlipFlop() abort if !exists('g:flip') | let g:flip = 0 | endif let g:flip = !g:flip return g:flip endfunction - ]], true) + ]], { output = false }) eq(1, meths.call_function('FlipFlop', {})) eq(0, meths.call_function('FlipFlop', {})) eq(1, meths.call_function('FlipFlop', {})) @@ -827,8 +827,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function() exec_lua [[ vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] - assert.truthy(string.match(exec_lua[[return vim.api.nvim_exec(':nmap asdf', true)]], - "^\nn asdf ")) + assert.truthy( + string.match( + exec_lua[[return vim.api.nvim_exec2(':nmap asdf', { output = true }).output]], + "^\nn asdf " + ) + ) end) it ('mapcheck() returns lua mapping correctly', function() diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ff1bfef591..162735dbd7 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -89,132 +89,145 @@ describe('API', function() eq({mode='i', blocking=false}, nvim("get_mode")) end) - describe('nvim_exec', function() + 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 })) + end) + + it('default options', function() + -- Should be equivalent to { output = false } + nvim('exec2', "let x0 = 'a'", {}) + eq('a', nvim('get_var', 'x0')) + end) + it('one-line input', function() - nvim('exec', "let x1 = 'a'", false) + nvim('exec2', "let x1 = 'a'", { output = false }) eq('a', nvim('get_var', 'x1')) end) it(':verbose set {option}?', function() - nvim('exec', 'set nowrap', false) - eq('nowrap\n\tLast set from anonymous :source', - nvim('exec', 'verbose set wrap?', true)) + nvim('exec2', 'set nowrap', { output = false }) + eq({ output = 'nowrap\n\tLast set from anonymous :source' }, + nvim('exec2', 'verbose set wrap?', { output = true })) -- Using script var to force creation of a script item - nvim('exec', [[ + nvim('exec2', [[ let s:a = 1 set nowrap - ]], false) - eq('nowrap\n\tLast set from anonymous :source (script id 1)', - nvim('exec', 'verbose set wrap?', true)) + ]], { output = false }) + eq({ output = 'nowrap\n\tLast set from anonymous :source (script id 1)' }, + nvim('exec2', 'verbose set wrap?', { output = true })) end) it('multiline input', function() -- Heredoc + empty lines. - nvim('exec', "let x2 = 'a'\n", false) + nvim('exec2', "let x2 = 'a'\n", { output = false }) eq('a', nvim('get_var', 'x2')) - nvim('exec','lua <avast_ye_hades('ahoy!') - ]], true)) + ]], { output = true })) - eq('ahoy! script-scoped varrrrr', nvim('exec', [[ + eq({ output = "{'output': 'ahoy! script-scoped varrrrr'}" }, nvim('exec2', [[ let s:pirate = 'script-scoped varrrrr' function! Avast_ye_hades(s) abort return a:s .. ' ' .. s:pirate endfunction - echo nvim_exec('echo Avast_ye_hades(''ahoy!'')', 1) - ]], true)) + echo nvim_exec2('echo Avast_ye_hades(''ahoy!'')', {'output': v:true}) + ]], { output = true })) matches('Vim%(echo%):E121: Undefined variable: s:pirate$', - pcall_err(request, 'nvim_exec', [[ + pcall_err(request, 'nvim_exec2', [[ let s:pirate = 'script-scoped varrrrr' - call nvim_exec('echo s:pirate', 1) - ]], false)) + call nvim_exec2('echo s:pirate', {'output': v:true}) + ]], { output = false })) -- Script items are created only on script var access - eq('1\n0', nvim('exec', [[ + eq({ output = '1\n0' }, nvim('exec2', [[ echo expand("")->empty() let s:a = 123 echo expand("")->empty() - ]], true)) + ]], { output = true })) - eq('1\n0', nvim('exec', [[ + eq({ output = '1\n0' }, nvim('exec2', [[ echo expand("")->empty() function s:a() abort endfunction echo expand("")->empty() - ]], true)) + ]], { output = true })) end) it('non-ASCII input', function() - nvim('exec', [=[ + nvim('exec2', [=[ new exe "normal! i ax \n Ax " :%s/ax/--a1234--/g | :%s/Ax/--A1234--/g - ]=], false) + ]=], { output = false }) nvim('command', '1') eq(' --a1234-- ', nvim('get_current_line')) nvim('command', '2') eq(' --A1234-- ', nvim('get_current_line')) - nvim('exec', [[ + nvim('exec2', [[ new call setline(1,['xxx']) call feedkeys('r') call feedkeys('ñ', 'xt') - ]], false) + ]], { output = false }) eq('ñxx', nvim('get_current_line')) end) it('execution error', function() - eq('nvim_exec(): Vim:E492: Not an editor command: bogus_command', - pcall_err(request, 'nvim_exec', 'bogus_command', false)) + eq('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('', eval('v:exception')) - eq('nvim_exec(): Vim(buffer):E86: Buffer 23487 does not exist', - pcall_err(request, 'nvim_exec', 'buffer 23487', false)) + eq('nvim_exec2(): Vim(buffer):E86: Buffer 23487 does not exist', + pcall_err(request, 'nvim_exec2', 'buffer 23487', {})) eq('', eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) end) @@ -222,17 +235,17 @@ describe('API', function() it('recursion', function() local fname = tmpname() write_file(fname, 'let x1 = "set from :source file"\n') - -- nvim_exec + -- nvim_exec2 -- :source - -- nvim_exec - request('nvim_exec', [[ + -- nvim_exec2 + request('nvim_exec2', [[ let x2 = substitute('foo','o','X','g') let x4 = 'should be overwritten' - call nvim_exec("source ]]..fname..[[\nlet x3 = substitute('foo','foo','set by recursive nvim_exec','g')\nlet x5='overwritten'\nlet x4=x5\n", v:false) - ]], false) + call nvim_exec2("source ]]..fname..[[\nlet x3 = substitute('foo','foo','set by recursive nvim_exec2','g')\nlet x5='overwritten'\nlet x4=x5\n", {'output': v:false}) + ]], { output = false }) eq('set from :source file', request('nvim_get_var', 'x1')) eq('fXX', request('nvim_get_var', 'x2')) - eq('set by recursive nvim_exec', request('nvim_get_var', 'x3')) + eq('set by recursive nvim_exec2', request('nvim_get_var', 'x3')) eq('overwritten', request('nvim_get_var', 'x4')) eq('overwritten', request('nvim_get_var', 'x5')) os.remove(fname) @@ -242,35 +255,35 @@ describe('API', function() local fname = tmpname() write_file(fname, 'echo "hello"\n') local sourcing_fname = tmpname() - write_file(sourcing_fname, 'call nvim_exec("source '..fname..'", v:false)\n') - meths.exec('set verbose=2', false) + write_file(sourcing_fname, 'call nvim_exec2("source '..fname..'", {"output": v:false})\n') + meths.exec2('set verbose=2', { output = false }) local traceback_output = 'line 0: sourcing "'..sourcing_fname..'"\n'.. 'line 0: sourcing "'..fname..'"\n'.. 'hello\n'.. 'finished sourcing '..fname..'\n'.. - 'continuing in nvim_exec() called at '..sourcing_fname..':1\n'.. + 'continuing in nvim_exec2() called at '..sourcing_fname..':1\n'.. 'finished sourcing '..sourcing_fname..'\n'.. - 'continuing in nvim_exec() called at nvim_exec():0' - eq(traceback_output, - meths.exec('call nvim_exec("source '..sourcing_fname..'", v:false)', true)) + 'continuing in nvim_exec2() called at nvim_exec2():0' + eq({ output = traceback_output }, + meths.exec2('call nvim_exec2("source '..sourcing_fname..'", {"output": v:false})', { output = true })) os.remove(fname) os.remove(sourcing_fname) end) it('returns output', function() - eq('this is spinal tap', - nvim('exec', 'lua <]]) @@ -575,7 +588,7 @@ describe('API', function() it('sets previous directory', function() meths.set_current_dir("Xtestdir") - meths.exec('cd -', false) + meths.exec2('cd -', { output = false }) eq(funcs.getcwd(), start_dir) end) end) @@ -2674,7 +2687,7 @@ describe('API', function() eq(' 1 %a "[No Name]" line 1\n'.. ' 3 h "[Scratch]" line 0\n'.. ' 4 h "[Scratch]" line 0', - meths.exec('ls', true)) + meths.exec2('ls', { output = true }).output) -- current buffer didn't change eq({id=1}, meths.get_current_buf()) @@ -2788,7 +2801,7 @@ describe('API', function() end) it('should not crash when echoed', function() - meths.exec("echo nvim_get_all_options_info()", true) + meths.exec2("echo nvim_get_all_options_info()", { output = true }) end) end) @@ -2941,13 +2954,13 @@ describe('API', function() it('can save message history', function() nvim('command', 'set cmdheight=2') -- suppress Press ENTER nvim("echo", {{"msg\nmsg"}, {"msg"}}, true, {}) - eq("msg\nmsgmsg", meths.exec('messages', true)) + eq("msg\nmsgmsg", meths.exec2('messages', { output = true }).output) end) it('can disable saving message history', function() nvim('command', 'set cmdheight=2') -- suppress Press ENTER nvim_async("echo", {{"msg\nmsg"}, {"msg"}}, false, {}) - eq("", meths.exec("messages", true)) + eq("", meths.exec2("messages", { output = true }).output) end) end) @@ -3936,7 +3949,7 @@ describe('API', function() it('sets correct script context', function() meths.cmd({ cmd = "set", args = { "cursorline" } }, {}) - local str = meths.exec([[verbose set cursorline?]], true) + local str = meths.exec2([[verbose set cursorline?]], { output = true }).output neq(nil, str:find("cursorline\n\tLast set from API client %(channel id %d+%)")) end) @@ -3986,7 +3999,7 @@ describe('API', function() line6 ]] meths.cmd({ cmd = "del", range = { 2, 4 }, reg = 'a' }, {}) - meths.exec("1put a", false) + meths.exec2("1put a", { output = false }) expect [[ line1 line2 @@ -4051,11 +4064,11 @@ describe('API', function() { output = true })) end) it('splits arguments correctly', function() - meths.exec([[ + meths.exec2([[ function! FooFunc(...) echo a:000 endfunction - ]], false) + ]], { output = false }) meths.create_user_command("Foo", "call FooFunc()", { nargs = '+' }) eq([=[['a quick', 'brown fox', 'jumps over the', 'lazy dog']]=], meths.cmd({ cmd = "Foo", args = { "a quick", "brown fox", "jumps over the", "lazy dog"}}, -- cgit From 4863ca6b8902c5b0aab95f2af640118cd417d379 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Mar 2023 10:49:32 +0800 Subject: test: use exec_capture() in more places (#22787) Problem: Using `meths.exec2("code", { output = true })` is too verbose. Solution: Use exec_capture() in more places. --- test/functional/api/extmark_spec.lua | 7 ++++--- test/functional/api/keymap_spec.lua | 4 ++-- test/functional/api/vim_spec.lua | 17 +++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index e9a175625b..3882fc90ca 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -11,6 +11,7 @@ local insert = helpers.insert local feed = helpers.feed local clear = helpers.clear local command = helpers.command +local exec = helpers.exec local meths = helpers.meths local assert_alive = helpers.assert_alive @@ -1413,12 +1414,12 @@ describe('API/extmarks', function() end) it('does not crash with append/delete/undo sequence', function() - meths.exec2([[ + exec([[ let ns = nvim_create_namespace('myplugin') call nvim_buf_set_extmark(0, ns, 0, 0, {}) call append(0, '') %delete - undo]], { output = false }) + undo]]) assert_alive() end) @@ -1450,7 +1451,7 @@ describe('API/extmarks', function() feed('u') -- handles pasting - meths.exec2([[let @a='asdfasdf']], { output = false }) + exec([[let @a='asdfasdf']]) feed([["ap]]) eq({ {1, 0, 0}, {2, 0, 8} }, meths.buf_get_extmarks(0, ns, 0, -1, {})) diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 78281be195..f2817ff627 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -681,13 +681,13 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it('can set mappings whose RHS change dynamically', function() - meths.exec2([[ + exec([[ function! FlipFlop() abort if !exists('g:flip') | let g:flip = 0 | endif let g:flip = !g:flip return g:flip endfunction - ]], { output = false }) + ]]) eq(1, meths.call_function('FlipFlop', {})) eq(0, meths.call_function('FlipFlop', {})) eq(1, meths.call_function('FlipFlop', {})) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 162735dbd7..d8fb1bc623 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -9,6 +9,7 @@ local NIL = helpers.NIL local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq local command = helpers.command local exec = helpers.exec +local exec_capture = helpers.exec_capture local eval = helpers.eval local expect = helpers.expect local funcs = helpers.funcs @@ -588,7 +589,7 @@ describe('API', function() it('sets previous directory', function() meths.set_current_dir("Xtestdir") - meths.exec2('cd -', { output = false }) + command('cd -') eq(funcs.getcwd(), start_dir) end) end) @@ -2687,7 +2688,7 @@ describe('API', function() eq(' 1 %a "[No Name]" line 1\n'.. ' 3 h "[Scratch]" line 0\n'.. ' 4 h "[Scratch]" line 0', - meths.exec2('ls', { output = true }).output) + exec_capture('ls')) -- current buffer didn't change eq({id=1}, meths.get_current_buf()) @@ -2954,13 +2955,13 @@ describe('API', function() it('can save message history', function() nvim('command', 'set cmdheight=2') -- suppress Press ENTER nvim("echo", {{"msg\nmsg"}, {"msg"}}, true, {}) - eq("msg\nmsgmsg", meths.exec2('messages', { output = true }).output) + eq("msg\nmsgmsg", exec_capture('messages')) end) it('can disable saving message history', function() nvim('command', 'set cmdheight=2') -- suppress Press ENTER nvim_async("echo", {{"msg\nmsg"}, {"msg"}}, false, {}) - eq("", meths.exec2("messages", { output = true }).output) + eq("", exec_capture('messages')) end) end) @@ -3949,7 +3950,7 @@ describe('API', function() it('sets correct script context', function() meths.cmd({ cmd = "set", args = { "cursorline" } }, {}) - local str = meths.exec2([[verbose set cursorline?]], { output = true }).output + local str = exec_capture([[verbose set cursorline?]]) neq(nil, str:find("cursorline\n\tLast set from API client %(channel id %d+%)")) end) @@ -3999,7 +4000,7 @@ describe('API', function() line6 ]] meths.cmd({ cmd = "del", range = { 2, 4 }, reg = 'a' }, {}) - meths.exec2("1put a", { output = false }) + command('1put a') expect [[ line1 line2 @@ -4064,11 +4065,11 @@ describe('API', function() { output = true })) end) it('splits arguments correctly', function() - meths.exec2([[ + exec([[ function! FooFunc(...) echo a:000 endfunction - ]], { output = false }) + ]]) meths.create_user_command("Foo", "call FooFunc()", { nargs = '+' }) eq([=[['a quick', 'brown fox', 'jumps over the', 'lazy dog']]=], meths.cmd({ cmd = "Foo", args = { "a quick", "brown fox", "jumps over the", "lazy dog"}}, -- cgit From b7748662ed5b06c12a74560690b728fdf770666f Mon Sep 17 00:00:00 2001 From: Michal Liszcz Date: Wed, 29 Mar 2023 09:59:01 +0200 Subject: fix(api): Use local LastSet structure in nvim_get_option_info (#22741) fix(api): use local LastSet structure in nvim_get_option_info * nvim_get_option_info is deprecated. It is always using the global LastSet information as reported in #15232. * nvim_get_option_info2 is added. The new function additionally accepts an 'opts' table {scope, buf, win} allowing to specify the option scope and query local options from another buffer or window. --- test/functional/api/vim_spec.lua | 93 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index d8fb1bc623..9d5a0c4b4e 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2892,6 +2892,99 @@ describe('API', function() end) end) + describe('nvim_get_option_info2', function() + local fname + local bufs + local wins + + before_each(function() + fname = tmpname() + write_file(fname, [[ + setglobal dictionary=mydict " 1, global-local (buffer) + setlocal formatprg=myprg " 2, global-local (buffer) + setglobal equalprg=prg1 " 3, global-local (buffer) + setlocal equalprg=prg2 " 4, global-local (buffer) + setglobal fillchars=stl:x " 5, global-local (window) + setlocal listchars=eol:c " 6, global-local (window) + setglobal showbreak=aaa " 7, global-local (window) + setlocal showbreak=bbb " 8, global-local (window) + setglobal completeopt=menu " 9, global + ]]) + + exec_lua 'vim.cmd.vsplit()' + meths.create_buf(false, false) + + bufs = meths.list_bufs() + wins = meths.list_wins() + + meths.win_set_buf(wins[1].id, bufs[1].id) + meths.win_set_buf(wins[2].id, bufs[2].id) + + meths.set_current_win(wins[2].id) + meths.exec('source ' .. fname, false) + + meths.set_current_win(wins[1].id) + end) + + after_each(function() + os.remove(fname) + end) + + it('should return option information', function() + eq(meths.get_option_info('dictionary'), meths.get_option_info2('dictionary', {})) -- buffer + eq(meths.get_option_info('fillchars'), meths.get_option_info2('fillchars', {})) -- window + eq(meths.get_option_info('completeopt'), meths.get_option_info2('completeopt', {})) -- global + end) + + describe('last set', function() + local tests = { + {desc="(buf option, global requested, global set) points to global", linenr=1, sid=1, args={'dictionary', {scope='global'}}}, + {desc="(buf option, global requested, local set) is not set", linenr=0, sid=0, args={'formatprg', {scope='global'}}}, + {desc="(buf option, global requested, both set) points to global", linenr=3, sid=1, args={'equalprg', {scope='global'}}}, + {desc="(buf option, local requested, global set) is not set", linenr=0, sid=0, args={'dictionary', {scope='local'}}}, + {desc="(buf option, local requested, local set) points to local", linenr=2, sid=1, args={'formatprg', {scope='local'}}}, + {desc="(buf option, local requested, both set) points to local", linenr=4, sid=1, args={'equalprg', {scope='local'}}}, + {desc="(buf option, fallback requested, global set) points to global", linenr=1, sid=1, args={'dictionary', {}}}, + {desc="(buf option, fallback requested, local set) points to local", linenr=2, sid=1, args={'formatprg', {}}}, + {desc="(buf option, fallback requested, both set) points to local", linenr=4, sid=1, args={'equalprg', {}}}, + {desc="(win option, global requested, global set) points to global", linenr=5, sid=1, args={'fillchars', {scope='global'}}}, + {desc="(win option, global requested, local set) is not set", linenr=0, sid=0, args={'listchars', {scope='global'}}}, + {desc="(win option, global requested, both set) points to global", linenr=7, sid=1, args={'showbreak', {scope='global'}}}, + {desc="(win option, local requested, global set) is not set", linenr=0, sid=0, args={'fillchars', {scope='local'}}}, + {desc="(win option, local requested, local set) points to local", linenr=6, sid=1, args={'listchars', {scope='local'}}}, + {desc="(win option, local requested, both set) points to local", linenr=8, sid=1, args={'showbreak', {scope='local'}}}, + {desc="(win option, fallback requested, global set) points to global", linenr=5, sid=1, args={'fillchars', {}}}, + {desc="(win option, fallback requested, local set) points to local", linenr=6, sid=1, args={'listchars', {}}}, + {desc="(win option, fallback requested, both set) points to local", linenr=8, sid=1, args={'showbreak', {}}}, + {desc="(global option, global requested) points to global", linenr=9, sid=1, args={'completeopt', {scope='global'}}}, + {desc="(global option, local requested) is not set", linenr=0, sid=0, args={'completeopt', {scope='local'}}}, + {desc="(global option, fallback requested) points to global", linenr=9, sid=1, args={'completeopt', {}}}, + } + + for _, t in pairs(tests) do + it(t.desc, function() + -- Switch to the target buffer/window so that curbuf/curwin are used. + meths.set_current_win(wins[2].id) + local info = meths.get_option_info2(unpack(t.args)) + eq(t.linenr, info.last_set_linenr) + eq(t.sid, info.last_set_sid) + end) + end + + it('is provided for cross-buffer requests', function() + local info = meths.get_option_info2('formatprg', {buf=bufs[2].id}) + eq(2, info.last_set_linenr) + eq(1, info.last_set_sid) + end) + + it('is provided for cross-window requests', function() + local info = meths.get_option_info2('listchars', {win=wins[2].id}) + eq(6, info.last_set_linenr) + eq(1, info.last_set_sid) + end) + end) + end) + describe('nvim_echo', function() local screen -- cgit From b34097fe6d2ea5c84bcec65a834a430d9f58eb64 Mon Sep 17 00:00:00 2001 From: "Sindre T. Strøm" Date: Fri, 31 Mar 2023 12:52:53 +0200 Subject: fix(api): return both link and attributes with nvim_get_hl (#22824) Problem: No way to get the actual highlight attributes for a linked group through |nvim_get_hl()| (not the attributes from the link target). Solution: Return the actual attributes as well as the link target name. --- test/functional/api/highlight_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 65b13bebf7..a4bd574a56 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -561,4 +561,18 @@ describe('API: get highlight', function() eq({ link = 'String' }, meths.get_hl(0, { name = '@string' })) eq({ fg = 10937249 }, meths.get_hl(0, { name = '@string.cpp', link = false })) end) + + it('can get all attributes for a linked group', function() + command('hi Bar guifg=red') + command('hi Foo guifg=#00ff00 gui=bold,underline') + command('hi! link Foo Bar') + eq({ link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true }, meths.get_hl(0, { name = 'Foo', link = true })) + end) + + it('can set link as well as other attributes', function() + command('hi Bar guifg=red') + local hl = { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, cterm = { bold = true } } + meths.set_hl(0, 'Foo', hl) + eq(hl, meths.get_hl(0, { name = 'Foo', link = true })) + end) end) -- cgit From 2a10f64e254375e77e1c5a6aeae3cd65cd122afb Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sat, 25 Mar 2023 02:24:24 +0100 Subject: feat(extmarks): extend nvim_buf_get_extmarks() Problem: Can not get all extmarks in a buffer. Properties are missing from the details array. Solution: Allow getting all extmarks in a buffer by supplying a -1 "ns_id". Add missing properties to the details array. --- test/functional/api/extmark_spec.lua | 68 ++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 14 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 3882fc90ca..4bd8f51904 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1463,6 +1463,7 @@ describe('API/extmarks', function() end_line = 1 }) eq({ {1, 0, 0, { + ns_id = 1, end_col = 0, end_row = 1, right_gravity = true, @@ -1480,20 +1481,27 @@ describe('API/extmarks', function() it('can get details', function() set_extmark(ns, marks[1], 0, 0, { + conceal = "c", + cursorline_hl_group = "Statement", end_col = 0, - end_row = 1, - right_gravity = false, end_right_gravity = true, - priority = 0, + end_row = 1, hl_eol = true, - hl_mode = "blend", hl_group = "String", - virt_text = { { "text", "Statement" } }, - virt_text_pos = "right_align", - virt_text_hide = true, + hl_mode = "blend", + line_hl_group = "Statement", + number_hl_group = "Statement", + priority = 0, + right_gravity = false, + sign_hl_group = "Statement", + sign_text = ">>", + spell = true, virt_lines = { { { "lines", "Statement" } }}, virt_lines_above = true, virt_lines_leftcol = true, + virt_text = { { "text", "Statement" } }, + virt_text_hide = true, + virt_text_pos = "right_align", }) set_extmark(ns, marks[2], 0, 0, { priority = 0, @@ -1501,22 +1509,31 @@ describe('API/extmarks', function() virt_text_win_col = 1, }) eq({0, 0, { + conceal = "c", + cursorline_hl_group = "Statement", end_col = 0, - end_row = 1, - right_gravity = false, end_right_gravity = true, - priority = 0, + end_row = 1, hl_eol = true, - hl_mode = "blend", hl_group = "String", - virt_text = { { "text", "Statement" } }, - virt_text_pos = "right_align", - virt_text_hide = true, + hl_mode = "blend", + line_hl_group = "Statement", + ns_id = 1, + number_hl_group = "Statement", + priority = 0, + right_gravity = false, + sign_hl_group = "Statement", + sign_text = ">>", + spell = true, virt_lines = { { { "lines", "Statement" } }}, virt_lines_above = true, virt_lines_leftcol = true, + virt_text = { { "text", "Statement" } }, + virt_text_hide = true, + virt_text_pos = "right_align", } }, get_extmark_by_id(ns, marks[1], { details = true })) eq({0, 0, { + ns_id = 1, right_gravity = true, priority = 0, virt_text = { { "text", "Statement" } }, @@ -1525,6 +1542,29 @@ describe('API/extmarks', function() virt_text_win_col = 1, } }, get_extmark_by_id(ns, marks[2], { details = true })) end) + + it('can get marks from anonymous namespaces', function() + ns = request('nvim_create_namespace', "") + ns2 = request('nvim_create_namespace', "") + set_extmark(ns, 1, 0, 0, {}) + set_extmark(ns2, 2, 1, 0, {}) + eq({{ 1, 0, 0, { ns_id = ns, right_gravity = true }}, + { 2, 1, 0, { ns_id = ns2, right_gravity = true }}}, + get_extmarks(-1, 0, -1, { details = true })) + end) + + it('can filter by extmark properties', function() + set_extmark(ns, 1, 0, 0, {}) + set_extmark(ns, 2, 0, 0, { hl_group = 'Normal' }) + set_extmark(ns, 3, 0, 0, { sign_text = '>>' }) + set_extmark(ns, 4, 0, 0, { virt_text = {{'text', 'Normal'}}}) + set_extmark(ns, 5, 0, 0, { virt_lines = {{{ 'line', 'Normal' }}}}) + eq(5, #get_extmarks(-1, 0, -1, { details = true })) + eq({{ 2, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'highlight' })) + eq({{ 3, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'sign' })) + eq({{ 4, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'virt_text' })) + eq({{ 5, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'virt_lines' })) + end) end) describe('Extmarks buffer api with many marks', function() -- cgit From 269dd747b6e61842856031ca14ac26ee884ede4c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 2 Apr 2023 23:01:48 +0800 Subject: refactor(defaults)!: change default 'commentstring' value to empty (#22862) --- test/functional/api/buffer_updates_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 25b838a4af..80e29c1ff2 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -75,7 +75,7 @@ local function reopenwithfolds(b) local tick = reopen(b, origlines) -- use markers for folds, make all folds open by default - command('setlocal foldmethod=marker foldlevel=20') + command('setlocal foldmethod=marker foldlevel=20 commentstring=/*%s*/') -- add a fold command('2,4fold') -- cgit From 7c8c1550737b34fabb3e4cecbc6b6bf3581b2235 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 4 Apr 2023 08:59:11 +0800 Subject: fix(api): avoid double hit-enter prompt with nvim_err_writeln (#22879) --- test/functional/api/vim_spec.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 9d5a0c4b4e..83347a499b 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2080,6 +2080,46 @@ describe('API', function() end) end) + describe('nvim_err_writeln', function() + local screen + + before_each(function() + screen = Screen.new(40, 8) + screen:attach() + screen:set_default_attr_ids({ + [0] = {bold=true, foreground=Screen.colors.Blue}, + [1] = {foreground = Screen.colors.White, background = Screen.colors.Red}, + [2] = {bold = true, foreground = Screen.colors.SeaGreen}, + [3] = {bold = true, reverse = true}, + }) + end) + + it('shows only one return prompt after all lines are shown', function() + nvim_async('err_writeln', 'FAILURE\nERROR\nEXCEPTION\nTRACEBACK') + screen:expect([[ + | + {0:~ }| + {3: }| + {1:FAILURE} | + {1:ERROR} | + {1:EXCEPTION} | + {1:TRACEBACK} | + {2:Press ENTER or type command to continue}^ | + ]]) + feed('') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end) + end) + describe('nvim_list_chans, nvim_get_chan_info', function() before_each(function() command('autocmd ChanOpen * let g:opened_event = deepcopy(v:event)') -- cgit From a5c572bd446a89be2dccb2f7479ff1b017074640 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 4 Apr 2023 19:07:33 +0200 Subject: docs: fix typos Co-authored-by: Gregory Anders Co-authored-by: Raphael Co-authored-by: C.D. MacEachern Co-authored-by: himanoa --- test/functional/api/vim_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 83347a499b..de0d82119c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -4180,7 +4180,7 @@ describe('API', function() meths.cmd({ cmd = "buffers", mods = { filter = { pattern = "foo", force = true } } }, { output = true })) - -- with emsg_silent = true error is suppresed + -- with emsg_silent = true error is suppressed feed([[:lua vim.api.nvim_cmd({ cmd = 'call', mods = { emsg_silent = true } }, {})]]) eq('', meths.cmd({ cmd = 'messages' }, { output = true })) -- error from the next command typed is not suppressed #21420 -- cgit From 743860de40502227b3f0ed64317eb937d24d4a36 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 4 Apr 2023 21:59:06 +0200 Subject: test: replace lfs with luv and vim.fs test: replace lfs with luv luv already pretty much does everything lfs does, so this duplication of dependencies isn't needed. --- test/functional/api/vim_spec.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index de0d82119c..ab26425425 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1,6 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local lfs = require('lfs') local luv = require('luv') local fmt = string.format @@ -4193,7 +4192,7 @@ describe('API', function() vim.api.nvim_echo({{ opts.fargs[1] }}, false, {}) end, { nargs = 1 }) ]]) - eq(lfs.currentdir(), + eq(luv.cwd(), meths.cmd({ cmd = "Foo", args = { '%:p:h' }, magic = { file = true } }, { output = true })) end) -- cgit From f0ac91c58b42ed4f38dea7352d89fd39a88142f4 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sat, 1 Apr 2023 14:58:52 +0200 Subject: feat(api): evaluate 'statuscolumn' with nvim_eval_statusline() --- test/functional/api/vim_spec.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ab26425425..cddea48a76 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3421,6 +3421,40 @@ describe('API', function() 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', { use_winbar = true, highlights = true })) end) + it('works with statuscolumn', function() + command([[ + let &stc='%C%s%=%l ' + set cul nu nuw=3 scl=yes:2 fdc=2 + call setline(1, repeat(['aaaaa'], 5)) + let g:ns = nvim_create_namespace('') + call sign_define('a', {'text':'aa', 'texthl':'IncSearch', 'numhl':'Normal'}) + call sign_place(2, 1, 'a', bufnr(), {'lnum':4}) + call nvim_buf_set_extmark(0, g:ns, 3, 1, { 'sign_text':'bb', 'sign_hl_group':'ErrorMsg' }) + 1,5fold | 1,5 fold | foldopen! + ]]) + command('norm 4G') + command('let v:lnum=4') + eq({ + str = '││aabb 4 ', + width = 9, + highlights = { + { group = 'CursorLineFold', start = 0 }, + { group = 'Normal', start = 6 }, + { group = 'IncSearch', start = 6 }, + { group = 'ErrorMsg', start = 8 }, + { group = 'Normal', start = 10 } + } + }, meths.eval_statusline('%C%s%=%l ', { use_statuscol = true, highlights = true })) + command('let v:lnum=3') + eq({ + str = '3 ' , + width = 2, + highlights = { + { group = 'LineNr', start = 0 }, + { group = 'ErrorMsg', start = 1 } + } + }, meths.eval_statusline('%l%#ErrorMsg# ', { use_statuscol = true, highlights = true })) + end) it('no memory leak with click functions', function() meths.eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {}) eq({ -- cgit From 25dfed6e0148771cdb659df8c616df3860583c47 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 6 Apr 2023 03:33:57 +0200 Subject: feat(api): set statuscolumn line number in nvim_eval_statusline() Having the user set `v:lnum` before calling `nvim_eval_statusline()` is unnecesarily fragile. Redraws inbetween setting `v:lnum` and the `nvim_eval_statusline()` call will overwrite `v:lnum`. --- test/functional/api/vim_spec.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index cddea48a76..af6fbf092a 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3422,7 +3422,7 @@ describe('API', function() { use_winbar = true, highlights = true })) end) it('works with statuscolumn', function() - command([[ + exec([[ let &stc='%C%s%=%l ' set cul nu nuw=3 scl=yes:2 fdc=2 call setline(1, repeat(['aaaaa'], 5)) @@ -3431,9 +3431,8 @@ describe('API', function() call sign_place(2, 1, 'a', bufnr(), {'lnum':4}) call nvim_buf_set_extmark(0, g:ns, 3, 1, { 'sign_text':'bb', 'sign_hl_group':'ErrorMsg' }) 1,5fold | 1,5 fold | foldopen! + norm 4G ]]) - command('norm 4G') - command('let v:lnum=4') eq({ str = '││aabb 4 ', width = 9, @@ -3444,8 +3443,7 @@ describe('API', function() { group = 'ErrorMsg', start = 8 }, { group = 'Normal', start = 10 } } - }, meths.eval_statusline('%C%s%=%l ', { use_statuscol = true, highlights = true })) - command('let v:lnum=3') + }, meths.eval_statusline('%C%s%=%l ', { use_statuscol_lnum = 4, highlights = true })) eq({ str = '3 ' , width = 2, @@ -3453,7 +3451,7 @@ describe('API', function() { group = 'LineNr', start = 0 }, { group = 'ErrorMsg', start = 1 } } - }, meths.eval_statusline('%l%#ErrorMsg# ', { use_statuscol = true, highlights = true })) + }, meths.eval_statusline('%l%#ErrorMsg# ', { use_statuscol_lnum = 3, highlights = true })) end) it('no memory leak with click functions', function() meths.eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {}) -- cgit From d05d63a18ff8394b31b3f3b85bfaebe2af358437 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 13 Apr 2023 14:08:36 +0200 Subject: fix(api): make nvim_get_hl not return non-existing groups fixes #23063 --- test/functional/api/highlight_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a4bd574a56..a6e9f9a42b 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -575,4 +575,25 @@ describe('API: get highlight', function() meths.set_hl(0, 'Foo', hl) eq(hl, meths.get_hl(0, { name = 'Foo', link = true })) end) + + it("doesn't contain unset groups", function() + local id = meths.get_hl_id_by_name "@foobar.hubbabubba" + ok(id > 0) + + local data = meths.get_hl(0, {}) + eq(nil, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + + command 'hi @foobar.hubbabubba gui=bold' + data = meths.get_hl(0, {}) + eq({bold = true}, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + + -- @foobar.hubbabubba was explicitly cleared and thus shows up + -- but @foobar was never touched, and thus doesn't + command 'hi clear @foobar.hubbabubba' + data = meths.get_hl(0, {}) + eq({}, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + end) end) -- cgit From 59fed8bb6457eb6c5204dc39a49d7ea0e1781482 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Tue, 18 Apr 2023 15:07:37 +0200 Subject: fix(api): extmark highlight groups not always included in details (#23179) Problem: Erroneous for loop condition. Solution: Remove for loop condition. --- test/functional/api/extmark_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 4bd8f51904..e30ffc92b6 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1541,6 +1541,12 @@ describe('API/extmarks', function() virt_text_pos = "win_col", virt_text_win_col = 1, } }, get_extmark_by_id(ns, marks[2], { details = true })) + set_extmark(ns, marks[3], 0, 0, { cursorline_hl_group = "Statement" }) + eq({0, 0, { + ns_id = 1, + cursorline_hl_group = "Statement", + right_gravity = true, + } }, get_extmark_by_id(ns, marks[3], { details = true })) end) it('can get marks from anonymous namespaces', function() -- cgit From 3ac952d4e27f4e2454332a730310316fe13fd4a3 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sun, 23 Apr 2023 06:53:25 +0530 Subject: fix(api): avoid assertion when autocmd group id is 0 (#23210) --- test/functional/api/autocmd_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index b1e38e77a1..57390519de 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -39,6 +39,10 @@ describe('autocmd api', function() })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd, {'FileType', {}}, {})) + eq("Invalid 'group': 0", pcall_err(meths.create_autocmd, 'FileType', { + group = 0, + command = 'ls', + })) end) it('doesnt leak when you use ++once', function() @@ -308,6 +312,9 @@ describe('autocmd api', function() eq("Invalid 'group': 'bogus'", pcall_err(meths.get_autocmds, { group = 'bogus', })) + eq("Invalid 'group': 0", pcall_err(meths.get_autocmds, { + group = 0, + })) eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.get_autocmds, { group = {}, })) @@ -725,6 +732,9 @@ describe('autocmd api', function() eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { group = {}, })) + eq("Invalid 'group': 0", pcall_err(meths.exec_autocmds, 'FileType', { + group = 0, + })) eq("Invalid 'buffer': expected Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { buffer = {}, })) @@ -1049,6 +1059,12 @@ describe('autocmd api', function() eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]]) eq('Vim:E367: No such group: "--Deleted--"', pcall_err(meths.del_augroup_by_id, -12312)) + + eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, 0)]]) + eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 0)) + + eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, 12342)]]) + eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 12312)) end) it('groups work with once', function() @@ -1224,6 +1240,7 @@ describe('autocmd api', function() eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.clear_autocmds, { event = {'FileType', {}} })) + eq("Invalid 'group': 0", pcall_err(meths.clear_autocmds, {group = 0})) end) it('should clear based on event + pattern', function() -- cgit From 3a1e17e3a1767b4ff8a082150f7f9d6bda50cc8f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 19:03:08 +0800 Subject: test: add tests for executing commands with backwards range --- test/functional/api/vim_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index af6fbf092a..c81b6e90cc 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -361,6 +361,12 @@ describe('API', function() eq('', eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) end) + + it('gives E493 instead of prompting on backwards range', function() + command('split') + eq('Vim(windo):E493: Backwards range given: 2,1windo echo', + pcall_err(command, '2,1windo echo')) + end) end) describe('nvim_command_output', function() -- cgit From 5ac2e47acc999472042df4f10f8f7b5ffa72ba3e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 10 May 2023 17:42:14 +0800 Subject: fix(redo): make redo of Lua mappings in op-pending mode work (#23566) --- test/functional/api/keymap_spec.lua | 45 +++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index f2817ff627..e239717d3a 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -813,19 +813,18 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('can make lua mappings', function() eq(0, exec_lua [[ GlobalCount = 0 - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount ]]) feed('asdf\n') eq(1, exec_lua[[return GlobalCount]]) - end) it (':map command shows lua mapping correctly', function() exec_lua [[ - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end }) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] assert.truthy( string.match( @@ -837,7 +836,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it ('mapcheck() returns lua mapping correctly', function() exec_lua [[ - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end }) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] assert.truthy(string.match(funcs.mapcheck('asdf', 'n'), "^")) @@ -871,7 +870,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('can make lua expr mappings replacing keycodes', function() exec_lua [[ - vim.api.nvim_set_keymap ('n', 'aa', '', {callback = function() return 'πfoo' end, expr = true, replace_keycodes = true }) + vim.api.nvim_set_keymap('n', 'aa', '', {callback = function() return 'πfoo' end, expr = true, replace_keycodes = true }) ]] feed('aa') @@ -881,7 +880,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('can make lua expr mappings without replacing keycodes', function() exec_lua [[ - vim.api.nvim_set_keymap ('i', 'aa', '', {callback = function() return '' end, expr = true }) + vim.api.nvim_set_keymap('i', 'aa', '', {callback = function() return '' end, expr = true }) ]] feed('iaa') @@ -891,7 +890,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('lua expr mapping returning nil is equivalent to returning an empty string', function() exec_lua [[ - vim.api.nvim_set_keymap ('i', 'aa', '', {callback = function() return nil end, expr = true }) + vim.api.nvim_set_keymap('i', 'aa', '', {callback = function() return nil end, expr = true }) ]] feed('iaa') @@ -902,17 +901,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('does not reset pum in lua mapping', function() eq(0, exec_lua [[ VisibleCount = 0 - vim.api.nvim_set_keymap ('i', '', '', {callback = function() VisibleCount = VisibleCount + vim.fn.pumvisible() end}) + vim.api.nvim_set_keymap('i', '', '', {callback = function() VisibleCount = VisibleCount + vim.fn.pumvisible() end}) return VisibleCount ]]) feed('i') eq(2, exec_lua[[return VisibleCount]]) end) + it('redo of lua mappings in op-pending mode work', function() + eq(0, exec_lua [[ + OpCount = 0 + vim.api.nvim_set_keymap('o', '', '', {callback = function() OpCount = OpCount + 1 end}) + return OpCount + ]]) + feed('d') + eq(1, exec_lua[[return OpCount]]) + feed('.') + eq(2, exec_lua[[return OpCount]]) + end) + it('can overwrite lua mappings', function() eq(0, exec_lua [[ GlobalCount = 0 - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount ]]) @@ -921,7 +932,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq(1, exec_lua[[return GlobalCount]]) exec_lua [[ - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end }) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end }) ]] feed('asdf\n') @@ -932,7 +943,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('can unmap lua mappings', function() eq(0, exec_lua [[ GlobalCount = 0 - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount ]]) @@ -1078,7 +1089,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() it('can make lua mappings', function() eq(0, exec_lua [[ GlobalCount = 0 - vim.api.nvim_buf_set_keymap (0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount ]]) @@ -1089,7 +1100,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() it('can make lua expr mappings replacing keycodes', function() exec_lua [[ - vim.api.nvim_buf_set_keymap (0, 'n', 'aa', '', {callback = function() return 'πfoo' end, expr = true, replace_keycodes = true }) + vim.api.nvim_buf_set_keymap(0, 'n', 'aa', '', {callback = function() return 'πfoo' end, expr = true, replace_keycodes = true }) ]] feed('aa') @@ -1099,7 +1110,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() it('can make lua expr mappings without replacing keycodes', function() exec_lua [[ - vim.api.nvim_buf_set_keymap (0, 'i', 'aa', '', {callback = function() return '' end, expr = true }) + vim.api.nvim_buf_set_keymap(0, 'i', 'aa', '', {callback = function() return '' end, expr = true }) ]] feed('iaa') @@ -1111,7 +1122,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() it('can overwrite lua mappings', function() eq(0, exec_lua [[ GlobalCount = 0 - vim.api.nvim_buf_set_keymap (0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount ]]) @@ -1120,7 +1131,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() eq(1, exec_lua[[return GlobalCount]]) exec_lua [[ - vim.api.nvim_buf_set_keymap (0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end }) + vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount - 1 end }) ]] feed('asdf\n') @@ -1131,7 +1142,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() it('can unmap lua mappings', function() eq(0, exec_lua [[ GlobalCount = 0 - vim.api.nvim_buf_set_keymap (0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + vim.api.nvim_buf_set_keymap(0, 'n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) return GlobalCount ]]) -- cgit From 1fe1bb084d0099fc4f9bfdc11189485d0f74b75a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 19 Dec 2022 16:37:45 +0000 Subject: refactor(options): deprecate nvim[_buf|_win]_[gs]et_option Co-authored-by: zeertzjq Co-authored-by: famiu --- test/functional/api/buffer_spec.lua | 24 +++++----- test/functional/api/extmark_spec.lua | 4 +- test/functional/api/highlight_spec.lua | 4 +- test/functional/api/vim_spec.lua | 88 ++++++++++++++++------------------ test/functional/api/window_spec.lua | 26 +++++----- 5 files changed, 69 insertions(+), 77 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index d454765edb..df9092fa14 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -630,19 +630,19 @@ describe('api/buf', function() eq('Index out of bounds', pcall_err(get_offset, 6)) eq('Index out of bounds', pcall_err(get_offset, -1)) - curbufmeths.set_option('eol', false) - curbufmeths.set_option('fixeol', false) + meths.set_option_value('eol', false, {buf=0}) + meths.set_option_value('fixeol', false, {buf=0}) eq(28, get_offset(5)) -- fileformat is ignored - curbufmeths.set_option('fileformat', 'dos') + meths.set_option_value('fileformat', 'dos', {buf=0}) 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)) - curbufmeths.set_option('eol', true) + meths.set_option_value('eol', true, {buf=0}) eq(29, get_offset(5)) command("set hidden") @@ -697,23 +697,23 @@ describe('api/buf', function() end) end) - describe('nvim_buf_get_option, nvim_buf_set_option', function() + describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - eq(8, curbuf('get_option', 'shiftwidth')) - curbuf('set_option', 'shiftwidth', 4) - eq(4, curbuf('get_option', 'shiftwidth')) + eq(8, nvim('get_option_value', 'shiftwidth', {buf = 0})) + nvim('set_option_value', 'shiftwidth', 4, {buf=0}) + eq(4, nvim('get_option_value', 'shiftwidth', {buf = 0})) -- global-local option - curbuf('set_option', 'define', 'test') - eq('test', curbuf('get_option', 'define')) + nvim('set_option_value', 'define', 'test', {buf = 0}) + eq('test', nvim('get_option_value', 'define', {buf = 0})) -- Doesn't change the global value - eq([[^\s*#\s*define]], nvim('get_option', 'define')) + eq([[^\s*#\s*define]], 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, curbuf('get_option', 'undolevels')) + eq(-123456, nvim('get_option_value', 'undolevels', {buf=0})) end) end) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index e30ffc92b6..0960e910f1 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1401,7 +1401,7 @@ describe('API/extmarks', function() it('in read-only buffer', function() command("view! runtime/doc/help.txt") - eq(true, curbufmeths.get_option('ro')) + eq(true, meths.get_option_value('ro', {buf=0})) local id = set_extmark(ns, 0, 0, 2) eq({{id, 0, 2}}, get_extmarks(ns,0, -1)) end) @@ -1474,7 +1474,7 @@ describe('API/extmarks', function() it('in prompt buffer', function() feed('dd') local id = set_extmark(ns, marks[1], 0, 0, {}) - curbufmeths.set_option('buftype', 'prompt') + meths.set_option_value('buftype', 'prompt', {buf = 0}) feed('i') eq({{id, 0, 2}}, get_extmarks(ns, 0, -1)) end) diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a6e9f9a42b..1601184e1b 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -155,9 +155,9 @@ describe('API: highlight',function() it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() command('vsplit file') - local err, _ = pcall(meths.buf_set_option, 1, 'undofile', false) + local err, _ = pcall(meths.set_option_value, 'undofile', false, { buf = 1 }) eq(true, err) - err, _ = pcall(meths.buf_set_option, 1, 'undolevels', -1) + err, _ = pcall(meths.set_option_value, 'undolevels', -1, { buf = 1 }) eq(true, err) err, _ = pcall(meths.buf_add_highlight, 1, -1, 'Question', 0, 0, -1) eq(true, err) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c81b6e90cc..5b8b52a559 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1051,7 +1051,7 @@ describe('API', function() line 3 ]]) eq({0,4,1,0}, funcs.getpos('.')) -- Cursor follows the paste. - eq(false, nvim('get_option', 'paste')) + eq(false, nvim('get_option_value', 'paste', {})) command('%delete _') -- Without final "\n". nvim('paste', 'line 1\nline 2\nline 3', true, -1) @@ -1091,7 +1091,7 @@ describe('API', function() 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', 'paste')) + eq(false, nvim('get_option_value', 'paste', {})) end) it('Replace-mode', function() -- Within single line @@ -1382,44 +1382,38 @@ describe('API', function() end) end) - describe('nvim_get_option, nvim_set_option', function() + describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - ok(nvim('get_option', 'equalalways')) - nvim('set_option', 'equalalways', false) - ok(not nvim('get_option', 'equalalways')) + ok(nvim('get_option_value', 'equalalways', {})) + nvim('set_option_value', 'equalalways', false, {}) + ok(not nvim('get_option_value', 'equalalways', {})) end) it('works to get global value of local options', function() - eq(false, nvim('get_option', 'lisp')) - eq(8, nvim('get_option', 'shiftwidth')) + eq(false, nvim('get_option_value', 'lisp', {})) + eq(8, nvim('get_option_value', 'shiftwidth', {})) end) it('works to set global value of local options', function() - nvim('set_option', 'lisp', true) - eq(true, nvim('get_option', 'lisp')) - eq(false, helpers.curbuf('get_option', 'lisp')) + nvim('set_option_value', 'lisp', true, {scope='global'}) + eq(true, nvim('get_option_value', 'lisp', {scope='global'})) + eq(false, nvim('get_option_value', 'lisp', {buf=0})) eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp')) eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp')) - nvim('set_option', 'shiftwidth', 20) + 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+')) end) - it('most window-local options have no global value', function() - local status, err = pcall(nvim, 'get_option', 'foldcolumn') - eq(false, status) - ok(err:match('Invalid option name') ~= nil) - end) - it('updates where the option was last set from', function() - nvim('set_option', 'equalalways', false) + nvim('set_option_value', 'equalalways', false, {}) local status, rv = pcall(nvim, '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("equalalways", true)', {}) + nvim('exec_lua', 'vim.api.nvim_set_option_value("equalalways", true, {})', {}) status, rv = pcall(nvim, 'command_output', 'verbose set equalalways?') eq(true, status) @@ -1499,7 +1493,6 @@ describe('API', function() end) it('set window options', function() - -- Same as to nvim_win_set_option nvim('set_option_value', 'colorcolumn', '4,3', {win=0}) eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) command("set modified hidden") @@ -1508,7 +1501,6 @@ describe('API', function() end) it('set local window options', function() - -- Different to nvim_win_set_option nvim('set_option_value', 'colorcolumn', '4,3', {win=0, scope='local'}) eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0, scope = 'local'})) command("set modified hidden") @@ -1519,11 +1511,11 @@ describe('API', function() it('get buffer or window-local options', function() nvim('command', 'new') local buf = nvim('get_current_buf').id - nvim('buf_set_option', buf, 'tagfunc', 'foobar') + nvim('set_option_value', 'tagfunc', 'foobar', {buf=buf}) eq('foobar', nvim('get_option_value', 'tagfunc', {buf = buf})) local win = nvim('get_current_win').id - nvim('win_set_option', win, 'number', true) + nvim('set_option_value', 'number', true, {win=win}) eq(true, nvim('get_option_value', 'number', {win = win})) end) @@ -2215,7 +2207,7 @@ describe('API', function() it('stream=job :terminal channel', function() command(':terminal') eq({id=1}, meths.get_current_buf()) - eq(3, meths.buf_get_option(1, 'channel')) + eq(3, meths.get_option_value('channel', {buf=1})) local info = { stream='job', @@ -2368,45 +2360,45 @@ describe('API', function() end) it('returns nothing with empty &runtimepath', function() - meths.set_option('runtimepath', '') + meths.set_option_value('runtimepath', '', {}) eq({}, meths.list_runtime_paths()) end) it('returns single runtimepath', function() - meths.set_option('runtimepath', 'a') + meths.set_option_value('runtimepath', 'a', {}) eq({'a'}, meths.list_runtime_paths()) end) it('returns two runtimepaths', function() - meths.set_option('runtimepath', 'a,b') + meths.set_option_value('runtimepath', 'a,b', {}) eq({'a', 'b'}, meths.list_runtime_paths()) end) it('returns empty strings when appropriate', function() - meths.set_option('runtimepath', 'a,,b') + meths.set_option_value('runtimepath', 'a,,b', {}) eq({'a', '', 'b'}, meths.list_runtime_paths()) - meths.set_option('runtimepath', ',a,b') + meths.set_option_value('runtimepath', ',a,b', {}) eq({'', 'a', 'b'}, meths.list_runtime_paths()) -- Trailing "," is ignored. Use ",," if you really really want CWD. - meths.set_option('runtimepath', 'a,b,') + meths.set_option_value('runtimepath', 'a,b,', {}) eq({'a', 'b'}, meths.list_runtime_paths()) - meths.set_option('runtimepath', 'a,b,,') + meths.set_option_value('runtimepath', 'a,b,,', {}) eq({'a', 'b', ''}, meths.list_runtime_paths()) end) it('truncates too long paths', function() local long_path = ('/a'):rep(8192) - meths.set_option('runtimepath', long_path) + meths.set_option_value('runtimepath', long_path, {}) local paths_list = meths.list_runtime_paths() eq({}, paths_list) end) end) it('can throw exceptions', function() - local status, err = pcall(nvim, 'get_option', 'invalid-option') + local status, err = pcall(nvim, 'get_option_value', 'invalid-option', {}) eq(false, status) - ok(err:match('Invalid option name') ~= nil) + ok(err:match("Invalid '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', very_long_name) + local status, err = pcall(nvim, 'get_option_value', very_long_name, {}) eq(false, status) eq(very_long_name, err:match('Ax+Z?')) end) @@ -2419,7 +2411,7 @@ describe('API', function() describe('nvim_parse_expression', function() before_each(function() - meths.set_option('isident', '') + meths.set_option_value('isident', '', {}) end) local function simplify_east_api_node(line, east_api_node) @@ -2704,9 +2696,9 @@ describe('API', function() end) it('can change buftype before visiting', function() - meths.set_option("hidden", false) + meths.set_option_value("hidden", false, {}) eq({id=2}, meths.create_buf(true, false)) - meths.buf_set_option(2, "buftype", "nofile") + meths.set_option_value("buftype", "nofile", {buf=2}) meths.buf_set_lines(2, 0, -1, true, {"test text"}) command("split | buffer 2") eq({id=2}, meths.get_current_buf()) @@ -2749,10 +2741,10 @@ describe('API', function() local edited_buf = 2 meths.buf_set_lines(edited_buf, 0, -1, true, {"some text"}) for _,b in ipairs(scratch_bufs) do - eq('nofile', meths.buf_get_option(b, 'buftype')) - eq('hide', meths.buf_get_option(b, 'bufhidden')) - eq(false, meths.buf_get_option(b, 'swapfile')) - eq(false, meths.buf_get_option(b, 'modeline')) + eq('nofile', meths.get_option_value('buftype', {buf=b})) + eq('hide', meths.get_option_value('bufhidden', {buf=b})) + eq(false, meths.get_option_value('swapfile', {buf=b})) + eq(false, meths.get_option_value('modeline', {buf=b})) end -- @@ -2765,10 +2757,10 @@ describe('API', function() {1:~ }| | ]]) - eq('nofile', meths.buf_get_option(edited_buf, 'buftype')) - eq('hide', meths.buf_get_option(edited_buf, 'bufhidden')) - eq(false, meths.buf_get_option(edited_buf, 'swapfile')) - eq(false, meths.buf_get_option(edited_buf, 'modeline')) + eq('nofile', meths.get_option_value('buftype', {buf=edited_buf})) + eq('hide', meths.get_option_value('bufhidden', {buf=edited_buf})) + eq(false, meths.get_option_value('swapfile', {buf=edited_buf})) + eq(false, meths.get_option_value('modeline', {buf=edited_buf})) -- Scratch buffer can be wiped without error. command('bwipe') @@ -2899,7 +2891,7 @@ describe('API', function() it('should have information about global options', function() -- precondition: the option was changed from its default -- in test setup. - eq(false, meths.get_option'showcmd') + eq(false, meths.get_option_value('showcmd', {})) eq({ allows_duplicates = true, diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index ecab6a4713..660fa4731e 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -363,22 +363,22 @@ describe('API/win', function() end) end) - describe('nvim_win_get_option, nvim_win_set_option', function() + describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - curwin('set_option', 'colorcolumn', '4,3') - eq('4,3', curwin('get_option', 'colorcolumn')) + nvim('set_option_value', 'colorcolumn', '4,3', {win=0}) + eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0})) command("set modified hidden") command("enew") -- edit new buffer, window option is preserved - eq('4,3', curwin('get_option', 'colorcolumn')) + eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0})) -- global-local option - curwin('set_option', 'statusline', 'window-status') - eq('window-status', curwin('get_option', 'statusline')) - eq('', nvim('get_option', 'statusline')) + 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'})) command("set modified") command("enew") -- global-local: not preserved in new buffer -- confirm local value was not copied - eq('', curwin('get_option', 'statusline')) + eq('', nvim('get_option_value', 'statusline', {win = 0})) eq('', eval('&l:statusline')) end) @@ -386,16 +386,16 @@ describe('API/win', function() nvim('command', 'tabnew') local tab1 = unpack(nvim('list_tabpages')) local win1 = unpack(tabpage('list_wins', tab1)) - window('set_option', win1, 'statusline', 'window-status') + nvim('set_option_value', 'statusline', 'window-status', {win=win1.id}) nvim('command', 'split') nvim('command', 'wincmd J') nvim('command', 'wincmd j') - eq('window-status', window('get_option', win1, 'statusline')) + eq('window-status', nvim('get_option_value', 'statusline', {win = win1.id})) assert_alive() end) it('returns values for unset local options', function() - eq(-1, curwin('get_option', 'scrolloff')) + eq(-1, nvim('get_option_value', 'scrolloff', {win=0, scope='local'})) end) end) @@ -568,11 +568,11 @@ describe('API/win', function() it('deletes the buffer when bufhidden=wipe', function() local oldwin = meths.get_current_win() local oldbuf = meths.get_current_buf() - local buf = meths.create_buf(true, false) + local buf = meths.create_buf(true, false).id local newwin = meths.open_win(buf, true, { relative='win', row=3, col=3, width=12, height=3 }) - meths.buf_set_option(buf, 'bufhidden', 'wipe') + meths.set_option_value('bufhidden', 'wipe', {buf=buf}) meths.win_hide(newwin) eq({oldwin}, meths.list_wins()) eq({oldbuf}, meths.list_bufs()) -- cgit From 576dddb46168e81aa0f78c28816082c662dedea1 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 22 May 2023 12:47:10 +0600 Subject: test: don't unnecessarily specify win/buf for `nvim_(get|set)_option_value` `nvim_(get|set)_option_value` pick the current buffer / window by default for buffer-local/window-local (but not global-local) options. So specifying `buf = 0` or `win = 0` in opts is unnecessary for those options. This PR removes those to reduce code clutter. --- test/functional/api/buffer_spec.lua | 14 +++++++------- test/functional/api/extmark_spec.lua | 4 ++-- test/functional/api/vim_spec.lua | 4 ++-- test/functional/api/window_spec.lua | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index df9092fa14..bf9e952319 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -630,19 +630,19 @@ describe('api/buf', function() eq('Index out of bounds', pcall_err(get_offset, 6)) eq('Index out of bounds', pcall_err(get_offset, -1)) - meths.set_option_value('eol', false, {buf=0}) - meths.set_option_value('fixeol', false, {buf=0}) + meths.set_option_value('eol', false, {}) + meths.set_option_value('fixeol', false, {}) eq(28, get_offset(5)) -- fileformat is ignored - meths.set_option_value('fileformat', 'dos', {buf=0}) + meths.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)) - meths.set_option_value('eol', true, {buf=0}) + meths.set_option_value('eol', true, {}) eq(29, get_offset(5)) command("set hidden") @@ -699,9 +699,9 @@ describe('api/buf', function() describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - eq(8, nvim('get_option_value', 'shiftwidth', {buf = 0})) - nvim('set_option_value', 'shiftwidth', 4, {buf=0}) - eq(4, nvim('get_option_value', 'shiftwidth', {buf = 0})) + eq(8, nvim('get_option_value', 'shiftwidth', {})) + nvim('set_option_value', 'shiftwidth', 4, {}) + eq(4, 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})) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 0960e910f1..675c8332de 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1401,7 +1401,7 @@ describe('API/extmarks', function() it('in read-only buffer', function() command("view! runtime/doc/help.txt") - eq(true, meths.get_option_value('ro', {buf=0})) + eq(true, meths.get_option_value('ro', {})) local id = set_extmark(ns, 0, 0, 2) eq({{id, 0, 2}}, get_extmarks(ns,0, -1)) end) @@ -1474,7 +1474,7 @@ describe('API/extmarks', function() it('in prompt buffer', function() feed('dd') local id = set_extmark(ns, marks[1], 0, 0, {}) - meths.set_option_value('buftype', 'prompt', {buf = 0}) + meths.set_option_value('buftype', 'prompt', {}) feed('i') eq({{id, 0, 2}}, get_extmarks(ns, 0, -1)) end) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 5b8b52a559..040c26e058 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1397,7 +1397,7 @@ describe('API', function() 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', {buf=0})) + 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'}) @@ -1493,7 +1493,7 @@ describe('API', function() end) it('set window options', function() - nvim('set_option_value', 'colorcolumn', '4,3', {win=0}) + nvim('set_option_value', 'colorcolumn', '4,3', {}) eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) command("set modified hidden") command("enew") -- edit new buffer, window option is preserved diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 660fa4731e..a6d1807961 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -365,11 +365,11 @@ describe('API/win', function() describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - nvim('set_option_value', 'colorcolumn', '4,3', {win=0}) - eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0})) + nvim('set_option_value', 'colorcolumn', '4,3', {}) + eq('4,3', 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', {win = 0})) + eq('4,3', nvim('get_option_value', 'colorcolumn', {})) -- global-local option nvim('set_option_value', 'statusline', 'window-status', {win=0}) -- cgit From b7708eac24c22a96676176c68569d6859a9f793f Mon Sep 17 00:00:00 2001 From: Null Chilly <56817415+nullchilly@users.noreply.github.com> Date: Mon, 22 May 2023 15:49:01 +0700 Subject: fix(api): nvim_get_hl should return default flag --- test/functional/api/highlight_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 1601184e1b..d3a79327ae 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -596,4 +596,9 @@ describe('API: get highlight', function() eq({}, data["@foobar.hubbabubba"]) eq(nil, data["@foobar"]) end) + + it('should return default flag', function() + meths.set_hl(0, 'Tried', { fg = "#00ff00", default = true }) + eq({ fg = tonumber('00ff00', 16), default = true }, meths.get_hl(0, { name = 'Tried' })) + end) end) -- cgit From 68e7a6a6dccff344f880e85e4e9f87104904c8a8 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 1 Jun 2023 12:23:42 +0200 Subject: test: added tests for set_height with winminheight=0 and a winbar --- test/functional/api/window_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index a6d1807961..55d4ff6b2e 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -285,6 +285,22 @@ describe('API/win', function() eq(2, window('get_height', 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])) + 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])) + end) + it('do not cause ml_get errors with foldmethod=expr #19989', function() insert([[ aaaaa -- cgit From fcfe535e9877cfdc824dc78f2d19e590400d34cd Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:26:29 -0500 Subject: refactor(defaults): do not use C specific default values for options (#22500) The options 'path', 'include', and 'define' all use C-specific default values. This may have made sense a long time ago when Vim was mostly used just for writing C, but this is no longer the case, and we have ample support for filetype specific configuration. Make the default values of these options empty and move the C-specific values into a filetype plugin where they belong. Co-authored-by: zeertzjq --- test/functional/api/buffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index bf9e952319..d9d4539fe8 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -706,7 +706,7 @@ describe('api/buf', function() nvim('set_option_value', 'define', 'test', {buf = 0}) eq('test', nvim('get_option_value', 'define', {buf = 0})) -- Doesn't change the global value - eq([[^\s*#\s*define]], nvim('get_option_value', 'define', {scope='global'})) + eq("", nvim('get_option_value', 'define', {scope='global'})) end) it('returns values for unset local options', function() -- cgit From 0e0a166a0cc5a2dc199136e313e58c27bfb91977 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Jun 2023 09:00:55 +0800 Subject: refactor(api): adjust errors for setting options (#23942) --- test/functional/api/vim_spec.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 040c26e058..98e5482218 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1435,8 +1435,12 @@ describe('API', function() pcall_err(nvim, 'set_option_value', 'scrolloff', 1, {scope = 'bogus'})) eq("Invalid 'scope': expected String, got Integer", pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 42})) - eq("Invalid 'scrolloff': expected Integer/Boolean/String, got Array", + eq("Invalid 'value': expected Integer/Boolean/String, got Array", pcall_err(nvim, 'set_option_value', 'scrolloff', {}, {})) + eq("Invalid value for option 'scrolloff': expected Number, got Boolean true", + pcall_err(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', {})) end) it('can get local values when global value is set', function() -- cgit From dd24ea819507e3a5da04df55df7dda5240e5b57f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Jun 2023 09:29:12 +0800 Subject: fix(events): don't expand non-file as file name --- test/functional/api/autocmd_spec.lua | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 57390519de..4cfe8672b1 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -228,23 +228,28 @@ describe('autocmd api', function() end) it('receives an args table', function() - local res = exec_lua [[ - local group_id = vim.api.nvim_create_augroup("TestGroup", {}) - local autocmd_id = vim.api.nvim_create_autocmd("User", { + local group_id = meths.create_augroup("TestGroup", {}) + -- Having an existing autocmd calling expand("") shouldn't change args #18964 + meths.create_autocmd('User', { + group = 'TestGroup', + pattern = 'Te*', + command = 'call expand("")', + }) + + local autocmd_id = exec_lua [[ + return vim.api.nvim_create_autocmd("User", { group = "TestGroup", pattern = "Te*", callback = function(args) vim.g.autocmd_args = args end, }) - - return {group_id, autocmd_id} ]] meths.exec_autocmds("User", {pattern = "Test pattern"}) eq({ - id = res[2], - group = res[1], + id = autocmd_id, + group = group_id, event = "User", match = "Test pattern", file = "Test pattern", @@ -252,27 +257,24 @@ describe('autocmd api', function() }, meths.get_var("autocmd_args")) -- Test without a group - res = exec_lua [[ - local autocmd_id = vim.api.nvim_create_autocmd("User", { + autocmd_id = exec_lua [[ + return vim.api.nvim_create_autocmd("User", { pattern = "*", callback = function(args) vim.g.autocmd_args = args end, }) - - return {autocmd_id} ]] meths.exec_autocmds("User", {pattern = "some_pat"}) eq({ - id = res[1], + id = autocmd_id, group = nil, event = "User", match = "some_pat", file = "some_pat", buf = 1, }, meths.get_var("autocmd_args")) - end) it('can receive arbitrary data', function() -- cgit From 42bbc4fabcf948ac6b8798b8992bcba1fc1d3e59 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 28 May 2023 12:09:52 +0200 Subject: feat(api): support abbreviations in nvim_set_keymap closes #19198 --- test/functional/api/keymap_spec.lua | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index e239717d3a..e56dfd483a 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -988,6 +988,54 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq("\nn lhs rhs\n map description", helpers.exec_capture("nmap lhs")) end) + + it('can define !-mode abbreviations with lua callbacks', function() + exec_lua [[ + GlobalCount = 0 + vim.api.nvim_set_keymap('!a', 'foo', '', {expr = true, callback = function() + GlobalCount = GlobalCount + 1 + return tostring(GlobalCount) + end}) + ]] + + feed 'iThe foo and the bar and the foo again' + eq('The 1 and the bar and the 2 again', meths.get_current_line()) + + feed ':let x = "The foo is the one"' + eq('The 3 is the one', meths.eval'x') + end) + + it('can define insert mode abbreviations with lua callbacks', function() + exec_lua [[ + GlobalCount = 0 + vim.api.nvim_set_keymap('ia', 'foo', '', {expr = true, callback = function() + GlobalCount = GlobalCount + 1 + return tostring(GlobalCount) + end}) + ]] + + feed 'iThe foo and the bar and the foo again' + eq('The 1 and the bar and the 2 again', meths.get_current_line()) + + feed ':let x = "The foo is the one"' + eq('The foo is the one', meths.eval'x') + end) + + it('can define cmdline mode abbreviations with lua callbacks', function() + exec_lua [[ + GlobalCount = 0 + vim.api.nvim_set_keymap('ca', 'foo', '', {expr = true, callback = function() + GlobalCount = GlobalCount + 1 + return tostring(GlobalCount) + end}) + ]] + + feed 'iThe foo and the bar and the foo again' + eq('The foo and the bar and the foo again', meths.get_current_line()) + + feed ':let x = "The foo is the one"' + eq('The 1 is the one', meths.eval'x') + end) end) describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() -- cgit From b6d2f49b4536f89cf2428d1f214468aa5fb21788 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 10 Jun 2023 10:44:31 +0800 Subject: test: more tests for nvim_{set,del}_keymap with abbreviation (#23970) --- test/functional/api/keymap_spec.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index e56dfd483a..953402ada3 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -400,6 +400,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- maparg(), which does not accept "!" (though it returns "!" in its output -- if getting a mapping set with |:map!|). local function normalize_mapmode(mode, generate_expected) + if mode:sub(-1) == 'a' then + mode = mode:sub(1, -2) + end if not generate_expected and mode == '!' then -- Cannot retrieve mapmode-ic mappings with "!", but can with "i" or "c". mode = 'i' @@ -435,7 +438,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- Gets a maparg() dict from Nvim, if one exists. local function get_mapargs(mode, lhs) - local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), false, true) + local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), mode:sub(-1) == 'a', true) -- drop "lhsraw" and "lhsrawalt" which are hard to check mapargs.lhsraw = nil mapargs.lhsrawalt = nil @@ -744,7 +747,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) -- Perform exhaustive tests of basic functionality - local mapmodes = {'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', ''} + local mapmodes = {'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', '', 'ia', 'ca', '!a'} for _, mapmode in ipairs(mapmodes) do it('can set/unset normal mappings in mapmode '..mapmode, function() meths.set_keymap(mapmode, 'lhs', 'rhs', {}) @@ -773,11 +776,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- remove some map arguments that are harder to test, or were already tested optnames = {'nowait', 'silent', 'expr', 'noremap'} for _, mapmode in ipairs(mapmodes) do - local printable_mode = normalize_mapmode(mapmode) - -- Test with single mappings for _, maparg in ipairs(optnames) do - it('can set/unset '..printable_mode..'-mappings with maparg: '..maparg, + it('can set/unset '..mapmode..'-mappings with maparg: '..maparg, function() meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = true}) eq(generate_mapargs(mapmode, 'lhs', 'rhs', {[maparg] = true}), @@ -785,7 +786,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() meths.del_keymap(mapmode, 'lhs') eq({}, get_mapargs(mapmode, 'lhs')) end) - it ('can set/unset '..printable_mode..'-mode mappings with maparg '.. + it ('can set/unset '..mapmode..'-mode mappings with maparg '.. maparg..', whose value is false', function() meths.set_keymap(mapmode, 'lhs', 'rhs', {[maparg] = false}) eq(generate_mapargs(mapmode, 'lhs', 'rhs'), @@ -798,7 +799,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- Test with triplets of mappings, one of which is false for i = 1, (#optnames - 2) do local opt1, opt2, opt3 = optnames[i], optnames[i + 1], optnames[i + 2] - it('can set/unset '..printable_mode..'-mode mappings with mapargs '.. + it('can set/unset '..mapmode..'-mode mappings with mapargs '.. opt1..', '..opt2..', '..opt3, function() local opts = {[opt1] = true, [opt2] = false, [opt3] = true} meths.set_keymap(mapmode, 'lhs', 'rhs', opts) -- cgit From 199a990c9e4e36f72ddcd041af28185f2ee4b4d6 Mon Sep 17 00:00:00 2001 From: treatybreaker Date: Sun, 11 Jun 2023 16:57:23 -0500 Subject: feat: report "build" in vim.version() #23925 Problem: Nvim version string typically has a "build" component but vim.version() doesn't report it. Solution: Add the "build" field to vim.version(). Closes #23863 --- test/functional/api/version_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index 771192e9ab..6d466b0cc1 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -34,6 +34,7 @@ describe("api_info()['version']", function() local minor = version['minor'] local patch = version['patch'] local prerelease = version['prerelease'] + local build = version['build'] eq("number", type(major)) eq("number", type(minor)) eq("number", type(patch)) @@ -42,6 +43,7 @@ describe("api_info()['version']", function() eq(0, funcs.has("nvim-"..major.."."..minor.."."..(patch + 1))) eq(0, funcs.has("nvim-"..major.."."..(minor + 1).."."..patch)) eq(0, funcs.has("nvim-"..(major + 1).."."..minor.."."..patch)) + assert(build == nil or type(build) == 'string') end) end) -- cgit From a9cd8467cbd54035e7814b862054c828467c2ce2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Jun 2023 13:59:57 +0800 Subject: fix(api): wrong nvim_buf_set_extmark error for invalid hl_mode --- test/functional/api/extmark_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 675c8332de..ec1c9245ba 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -105,6 +105,10 @@ describe('API/extmarks', function() it('validation', function() eq("Invalid 'end_col': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = {}, end_row = 1 })) eq("Invalid 'end_row': expected Integer, got Array", pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = {} })) + eq("Invalid 'virt_text_pos': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 0 })) + eq("Invalid 'virt_text_pos': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 'foo' })) + eq("Invalid 'hl_mode': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 0 })) + eq("Invalid 'hl_mode': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 'foo' })) eq("Invalid 'id': expected positive Integer", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })) eq("Invalid mark position: expected 2 Integer items", pcall_err(get_extmarks, ns, {}, {-1, -1})) eq("Invalid mark position: expected mark id Integer or 2-item Array", pcall_err(get_extmarks, ns, true, {-1, -1})) -- cgit From 2f17ef1fc4b96cf1106fd95ba090d34a2e4b977b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 22 Jun 2023 04:09:14 -0700 Subject: fix(messages): use "Vimscript" instead of "VimL" #24111 followup to #24109 fix #16150 --- test/functional/api/vim_spec.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 98e5482218..d56f780ca6 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -346,15 +346,15 @@ describe('API', function() os.remove(fname) end) - it('VimL validation error: fails with specific error', function() + it('Vimscript validation error: fails with specific error', function() local status, rv = pcall(nvim, "command", "bogus_command") eq(false, status) -- nvim_command() failed. - eq("E492:", string.match(rv, "E%d*:")) -- VimL error was returned. + eq("E492:", string.match(rv, "E%d*:")) -- Vimscript error was returned. eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) end) - it('VimL execution error: fails with specific error', function() + it('Vimscript execution error: fails with specific error', function() local status, rv = pcall(nvim, "command", "buffer 23487") eq(false, status) -- nvim_command() failed. eq("E86: Buffer 23487 does not exist", string.match(rv, "E%d*:.*")) @@ -422,7 +422,7 @@ describe('API', function() eq(':!echo foo\r\n\nfoo'..win_lf..'\n', nvim('command_output', [[!echo foo]])) end) - it('VimL validation error: fails with specific error', function() + it('Vimscript validation error: fails with specific error', function() local status, rv = pcall(nvim, "command_output", "bogus commannnd") eq(false, status) -- nvim_command_output() failed. eq("E492: Not an editor command: bogus commannnd", @@ -432,7 +432,7 @@ describe('API', function() eq({mode='n', blocking=false}, nvim("get_mode")) end) - it('VimL execution error: fails with specific error', function() + it('Vimscript execution error: fails with specific error', function() local status, rv = pcall(nvim, "command_output", "buffer 42") eq(false, status) -- nvim_command_output() failed. eq("E86: Buffer 42 does not exist", string.match(rv, "E%d*:.*")) @@ -463,7 +463,7 @@ describe('API', function() eq(2, request("vim_eval", "1+1")) end) - it("VimL error: returns error details, does NOT update v:errmsg", function() + it("Vimscript error: returns error details, does NOT update v:errmsg", function() eq('Vim:E121: Undefined variable: bogus', pcall_err(request, 'nvim_eval', 'bogus expression')) eq('', eval('v:errmsg')) -- v:errmsg was not updated. @@ -478,7 +478,7 @@ describe('API', function() eq('foo', nvim('call_function', 'simplify', {'this/./is//redundant/../../../foo'})) end) - it("VimL validation error: returns specific error, does NOT update v:errmsg", function() + it("Vimscript validation error: returns specific error, does NOT update v:errmsg", function() eq('Vim:E117: Unknown function: bogus function', pcall_err(request, 'nvim_call_function', 'bogus function', {'arg1'})) eq('Vim:E119: Not enough arguments for function: atan', @@ -487,7 +487,7 @@ describe('API', function() eq('', eval('v:errmsg')) -- v:errmsg was not updated. end) - it("VimL error: returns error details, does NOT update v:errmsg", function() + it("Vimscript error: returns error details, does NOT update v:errmsg", function() eq('Vim:E808: Number or Float required', pcall_err(request, 'nvim_call_function', 'atan', {'foo'})) eq('Vim:Invalid channel stream "xxx"', @@ -498,7 +498,7 @@ describe('API', function() eq('', eval('v:errmsg')) -- v:errmsg was not updated. end) - it("VimL exception: returns exception details, does NOT update v:errmsg", function() + it("Vimscript exception: returns exception details, does NOT update v:errmsg", function() source([[ function! Foo() abort throw 'wtf' @@ -523,7 +523,7 @@ describe('API', function() end) describe('nvim_call_dict_function', function() - it('invokes VimL dict function', function() + it('invokes Vimscript dict function', function() source([[ function! F(name) dict return self.greeting.', '.a:name.'!' @@ -653,7 +653,7 @@ describe('API', function() end) describe('nvim_input', function() - it("VimL error: does NOT fail, updates v:errmsg", function() + it("Vimscript error: does NOT fail, updates v:errmsg", function() local status, _ = pcall(nvim, "input", ":call bogus_fn()") local v_errnum = string.match(nvim("eval", "v:errmsg"), "E%d*:") eq(true, status) -- nvim_input() did not fail. -- cgit From e0453d7f5743ad2f515deea76e363d11a7e1fa96 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 28 Jun 2023 04:51:55 -0700 Subject: fix(api): nvim_cmd{cmd="win_getid"} parsed as :winsize #24181 Problem: `:lua vim.cmd.win_getid(30,10)` is interpreted as `:win[size] 30 10`. User intention was to call `vim.fn.win_getid(30,10)`. Solution: Check that the `cmd` actually matches the resolved command. --- test/functional/api/vim_spec.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index d56f780ca6..1ac732b128 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -335,8 +335,7 @@ describe('API', function() nvim('command', 'edit '..fname) nvim('command', 'normal itesting\napi') nvim('command', 'w') - local f = io.open(fname) - ok(f ~= nil) + local f = assert(io.open(fname)) if is_os('win') then eq('testing\r\napi\r\n', f:read('*a')) else @@ -3950,7 +3949,7 @@ describe('API', function() } }, meths.parse_cmd('MyCommand test it', {})) end) - it('errors for invalid command', function() + it('validates command', function() eq('Error while parsing command line', pcall_err(meths.parse_cmd, '', {})) eq('Error while parsing command line', pcall_err(meths.parse_cmd, '" foo', {})) eq('Error while parsing command line: E492: Not an editor command: Fubar', @@ -4097,6 +4096,11 @@ describe('API', function() eq("Invalid 'reg': expected single character, got xx", pcall_err(meths.cmd, { cmd = "put", args = {}, reg = 'xx' }, {})) + -- #20681 + eq('Invalid command: "win_getid"', pcall_err(meths.cmd, { cmd = 'win_getid'}, {})) + eq('Invalid command: "echo "hi""', pcall_err(meths.cmd, { cmd = 'echo "hi"'}, {})) + eq('Invalid command: "win_getid"', pcall_err(exec_lua, [[return vim.cmd.win_getid{}]])) + -- Lua call allows empty {} for dict item. eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, magic = {} }]])) eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, mods = {} }]])) -- cgit From a741c7fd0465c949a0016fcbee5f4526b65f8c02 Mon Sep 17 00:00:00 2001 From: Alexandre Teoi Date: Sat, 1 Jul 2023 10:33:51 -0300 Subject: fix(api): nvim_parse_cmd error message in pcall() #23297 Problem: nvim_parse_cmd() in pcall() may show an error message (side-effect): :lua pcall(vim.api.nvim_parse_cmd, vim.fn.getcmdline(), {}) E16: Invalid range Solution: Avoid emsg() in the nvim_parse_cmd() codepath. - refactor(api): add error message output parameter to get_address() - fix: null check emsg() parameter - refactor: remove emsg_off workaround from do_incsearch_highlighting() - refactor: remove emsg_off workaround from cmdpreview_may_show() - refactor: remove remaining calls to emsg() from parse_cmd_address() and get_address() - (refactor): lint set_cmd_dflall_range() - refactor: addr_error() - move output parameter to return value Fix #20339 TODO: These are the functions called by `get_address()`: ``` nvim_parse_cmd() -> parse_cmdline() -> parse_cmd_address() -> get_address() skipwhite() addr_error() qf_get_cur_idx() qf_get_cur_valid_idx() qf_get_size() qf_get_valid_size() mark_get() mark_check() assert() skip_regexp() magic_isset() > do_search() > searchit() ascii_isdigit() getdigits() getdigits_int32() compute_buffer_local_count() hasFolding() ``` From these functions, I found at least two that call emsg directly: - do_search() - seems to be simple to refactor - searchit() - will be more challenging because it may generate multiple error messages, which can't be handled by the current `errormsg` out-parameter. For example, it makes multiple calls to `vim_regexec_multi()` in a loop that possibly generate error messages, and later `searchit()` itself may generate another one: - https://github.com/neovim/neovim/blob/c194acbfc479d8e5839fa629363f93f6550d035c/src/nvim/search.c#L631-L647 - https://github.com/neovim/neovim/blob/c194acbfc479d8e5839fa629363f93f6550d035c/src/nvim/search.c#L939-L954 --------- Co-authored-by: Justin M. Keyes --- test/functional/api/vim_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 1ac732b128..c4f89318e0 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3467,6 +3467,7 @@ describe('API', function() end) end) end) + describe('nvim_parse_cmd', function() it('works', function() eq({ @@ -4048,7 +4049,13 @@ describe('API', function() meths.cmd(meths.parse_cmd("set cursorline", {}), {}) eq(true, meths.get_option_value("cursorline", {})) end) + it('no side-effects (error messages) in pcall() #20339', function() + eq({ false, 'Error while parsing command line: E16: Invalid range' }, + exec_lua([=[return {pcall(vim.api.nvim_parse_cmd, "'<,'>n", {})}]=])) + eq('', eval('v:errmsg')) + end) end) + describe('nvim_cmd', function() it('works', function () meths.cmd({ cmd = "set", args = { "cursorline" } }, {}) -- cgit From 92760a7f42a95bb252966c2a38423e5bc9d57cc7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 4 Jul 2023 07:19:02 +0800 Subject: fix(api, lua): make blank lines in a message work properly (#24244) --- test/functional/api/vim_spec.lua | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c4f89318e0..664cd4cbca 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -577,7 +577,6 @@ describe('API', function() local start_dir before_each(function() - clear() funcs.mkdir("Xtestdir") start_dir = funcs.getcwd() end) @@ -1990,6 +1989,39 @@ describe('API', function() ]]) eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out')) end) + + it('blank line in message works', function() + local screen = Screen.new(40, 8) + screen:attach() + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, + [1] = {bold = true, foreground = Screen.colors.SeaGreen}, + [2] = {bold = true, reverse = true}, + }) + feed([[:call nvim_out_write("\na\n")]]) + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {2: }| + | + a | + {1:Press ENTER or type command to continue}^ | + ]]} + feed('') + feed([[:call nvim_out_write("b\n\nc\n")]]) + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }| + {2: }| + b | + | + c | + {1:Press ENTER or type command to continue}^ | + ]]} + end) end) describe('nvim_err_write', function() @@ -3029,11 +3061,10 @@ describe('API', function() local screen before_each(function() - clear() screen = Screen.new(40, 8) screen:attach() screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, + [0] = {bold = true, foreground = Screen.colors.Blue}, [1] = {bold = true, foreground = Screen.colors.SeaGreen}, [2] = {bold = true, reverse = true}, [3] = {foreground = Screen.colors.Brown, bold = true}, -- Statement @@ -3103,7 +3134,6 @@ describe('API', function() local screen before_each(function() - clear() screen = Screen.new(100, 35) screen:attach() screen:set_default_attr_ids({ -- cgit From 3ecd45ded044c47efa76b74e9e3b720fbe27adc7 Mon Sep 17 00:00:00 2001 From: notomo Date: Tue, 4 Jul 2023 23:07:55 +0900 Subject: fix(api): allow negative column arguments for nvim_buf_set_text (#23501) --- test/functional/api/buffer_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index d9d4539fe8..512a1a08a6 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -437,6 +437,10 @@ describe('api/buf', function() -- can append to a line set_text(1, 4, -1, 4, {' and', 'more'}) eq({'goodbye bar', 'text and', 'more'}, get_lines(0, 3, true)) + + -- can use negative column numbers + set_text(0, -5, 0, -1, {'!'}) + eq({'goodbye!'}, get_lines(0, 1, true)) end) it('works with undo', function() -- cgit From b2e8c0df2062f765a4cf7d96379c5f0f19393dfd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Jul 2023 12:06:14 +0800 Subject: fix(edit): fix K_EVENT interfering with 'digraph' (#24258) --- test/functional/api/vim_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 664cd4cbca..6f75de7f1b 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1828,6 +1828,23 @@ describe('API', function() feed('') expect('a') -- recognized i_0_CTRL-D end) + + it("does not interrupt with 'digraph'", function() + command('set digraph') + feed('i,') + eq(2, eval('1+1')) -- causes K_EVENT key + feed('') + eq(2, eval('1+1')) -- causes K_EVENT key + feed('.') + expect('…') -- digraph ",." worked + feed('') + feed(':,') + eq(2, eval('1+1')) -- causes K_EVENT key + feed('') + eq(2, eval('1+1')) -- causes K_EVENT key + feed('.') + eq('…', funcs.getcmdline()) -- digraph ",." worked + end) end) describe('nvim_get_context', function() -- cgit From 2afb04758c341e17c70b8d2e3869c901c8cdb7d2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Jul 2023 12:56:19 +0800 Subject: fix(vim.system): close check handle (#24270) Fix hang after running vim.system() with sanitizers. --- test/functional/api/vim_spec.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 6f75de7f1b..617d0f12ff 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -440,7 +440,7 @@ describe('API', function() eq({mode='n', blocking=false}, nvim("get_mode")) end) - it('Does not cause heap buffer overflow with large output', function() + it('does not cause heap buffer overflow with large output', function() eq(eval('string(range(1000000))'), nvim('command_output', 'echo range(1000000)')) end) @@ -4411,8 +4411,6 @@ describe('API', function() eq('1', meths.cmd({cmd = 'echo', args = {true}}, {output = true})) end) describe('first argument as count', function() - before_each(clear) - it('works', function() command('vsplit | enew') meths.cmd({cmd = 'bdelete', args = {meths.get_current_buf()}}, {}) -- cgit From db8fe63a9398efd57c3ff28aa3d93e45fb70ee1a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 11 Jul 2023 07:15:46 +0800 Subject: feat(api): add nvim_win_text_height (#24236) It uses the same code as "scroll_delta" of "win_viewport" UI event to calculate text height, but is more flexible. --- test/functional/api/window_spec.lua | 211 ++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 55d4ff6b2e..8038a84139 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -595,6 +595,217 @@ describe('API/win', function() end) end) + describe('text_height', function() + it('validation', function() + local X = meths.get_vvar('maxcol') + insert([[ + aaa + bbb + ccc + ddd + eee]]) + eq("Invalid window id: 23", + pcall_err(meths.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("'start_row' is higher than 'end_row'", + pcall_err(curwinmeths.text_height, { start_row = 3, end_row = 1 })) + eq("'start_vcol' specified without 'start_row'", + pcall_err(curwinmeths.text_height, { end_row = 2, start_vcol = 0 })) + eq("'end_vcol' specified without 'end_row'", + pcall_err(curwinmeths.text_height, { start_row = 2, end_vcol = 0 })) + eq("Invalid 'start_vcol': out of range", + pcall_err(curwinmeths.text_height, { 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 })) + eq("Invalid 'end_vcol': out of range", + pcall_err(curwinmeths.text_height, { 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 })) + eq("'start_vcol' is higher than 'end_vcol'", + pcall_err(curwinmeths.text_height, { start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 })) + end) + + it('with two diff windows', function() + local X = meths.get_vvar('maxcol') + local screen = Screen.new(45, 22) + screen:set_default_attr_ids({ + [0] = {foreground = Screen.colors.Blue1, bold = true}; + [1] = {foreground = Screen.colors.Blue4, background = Screen.colors.Grey}; + [2] = {foreground = Screen.colors.Brown}; + [3] = {foreground = Screen.colors.Blue1, background = Screen.colors.LightCyan1, bold = true}; + [4] = {background = Screen.colors.LightBlue}; + [5] = {foreground = Screen.colors.Blue4, background = Screen.colors.LightGrey}; + [6] = {background = Screen.colors.Plum1}; + [7] = {background = Screen.colors.Red, bold = true}; + [8] = {reverse = true}; + [9] = {bold = true, reverse = true}; + }) + screen:attach() + exec([[ + set diffopt+=context:2 number + let expr = 'printf("%08d", v:val) .. repeat("!", v:val)' + call setline(1, map(range(1, 20) + range(25, 45), expr)) + vnew + call setline(1, map(range(3, 20) + range(28, 50), expr)) + windo diffthis + ]]) + feed('24gg') + screen:expect{grid=[[ + {1: }{2: }{3:----------------}│{1: }{2: 1 }{4:00000001! }| + {1: }{2: }{3:----------------}│{1: }{2: 2 }{4:00000002!! }| + {1: }{2: 1 }00000003!!! │{1: }{2: 3 }00000003!!! | + {1: }{2: 2 }00000004!!!! │{1: }{2: 4 }00000004!!!! | + {1:+ }{2: 3 }{5:+-- 14 lines: 00}│{1:+ }{2: 5 }{5:+-- 14 lines: 00}| + {1: }{2: 17 }00000019!!!!!!!!│{1: }{2: 19 }00000019!!!!!!!!| + {1: }{2: 18 }00000020!!!!!!!!│{1: }{2: 20 }00000020!!!!!!!!| + {1: }{2: }{3:----------------}│{1: }{2: 21 }{4:00000025!!!!!!!!}| + {1: }{2: }{3:----------------}│{1: }{2: 22 }{4:00000026!!!!!!!!}| + {1: }{2: }{3:----------------}│{1: }{2: 23 }{4:00000027!!!!!!!!}| + {1: }{2: 19 }00000028!!!!!!!!│{1: }{2: 24 }^00000028!!!!!!!!| + {1: }{2: 20 }00000029!!!!!!!!│{1: }{2: 25 }00000029!!!!!!!!| + {1:+ }{2: 21 }{5:+-- 14 lines: 00}│{1:+ }{2: 26 }{5:+-- 14 lines: 00}| + {1: }{2: 35 }00000044!!!!!!!!│{1: }{2: 40 }00000044!!!!!!!!| + {1: }{2: 36 }00000045!!!!!!!!│{1: }{2: 41 }00000045!!!!!!!!| + {1: }{2: 37 }{4:00000046!!!!!!!!}│{1: }{2: }{3:----------------}| + {1: }{2: 38 }{4:00000047!!!!!!!!}│{1: }{2: }{3:----------------}| + {1: }{2: 39 }{4:00000048!!!!!!!!}│{1: }{2: }{3:----------------}| + {1: }{2: 40 }{4:00000049!!!!!!!!}│{1: }{2: }{3:----------------}| + {1: }{2: 41 }{4:00000050!!!!!!!!}│{1: }{2: }{3:----------------}| + {8:[No Name] [+] }{9:[No Name] [+] }| + | + ]]} + screen:try_resize(45, 3) + screen:expect{grid=[[ + {1: }{2: 19 }00000028!!!!!!!!│{1: }{2: 24 }^00000028!!!!!!!!| + {8:[No Name] [+] }{9:[No Name] [+] }| + | + ]]} + eq(20, meths.win_text_height(1000, {})) + eq(20, meths.win_text_height(1001, {})) + eq(20, meths.win_text_height(1000, { start_row = 0 })) + eq(20, meths.win_text_height(1001, { start_row = 0 })) + eq(15, meths.win_text_height(1000, { end_row = -1 })) + eq(20, meths.win_text_height(1001, { end_row = -1 })) + eq(15, meths.win_text_height(1000, { end_row = 40 })) + eq(20, meths.win_text_height(1001, { end_row = 40 })) + eq(10, meths.win_text_height(1000, { start_row = 23 })) + eq(13, meths.win_text_height(1001, { start_row = 18 })) + eq(11, meths.win_text_height(1000, { end_row = 23 })) + eq(11, meths.win_text_height(1001, { end_row = 18 })) + eq(11, meths.win_text_height(1000, { start_row = 3, end_row = 39 })) + eq(11, meths.win_text_height(1001, { start_row = 1, end_row = 34 })) + eq(9, meths.win_text_height(1000, { start_row = 4, end_row = 38 })) + eq(9, meths.win_text_height(1001, { start_row = 2, end_row = 33 })) + eq(9, meths.win_text_height(1000, { start_row = 5, end_row = 37 })) + eq(9, meths.win_text_height(1001, { start_row = 3, end_row = 32 })) + eq(9, meths.win_text_height(1000, { start_row = 17, end_row = 25 })) + eq(9, meths.win_text_height(1001, { start_row = 15, end_row = 20 })) + eq(7, meths.win_text_height(1000, { start_row = 18, end_row = 24 })) + eq(7, meths.win_text_height(1001, { start_row = 16, end_row = 19 })) + eq(6, meths.win_text_height(1000, { start_row = -1 })) + eq(5, meths.win_text_height(1000, { start_row = -1, start_vcol = X })) + eq(0, meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1 })) + eq(0, meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1, end_vcol = X })) + eq(1, meths.win_text_height(1000, { start_row = -1, start_vcol = 0, end_row = -1, end_vcol = X })) + eq(3, meths.win_text_height(1001, { end_row = 0 })) + eq(2, meths.win_text_height(1001, { end_row = 0, end_vcol = 0 })) + eq(2, meths.win_text_height(1001, { start_row = 0, end_row = 0, end_vcol = 0 })) + eq(0, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = 0 })) + eq(1, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = X })) + eq(11, meths.win_text_height(1001, { end_row = 18 })) + eq(9, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18 })) + eq(10, meths.win_text_height(1001, { end_row = 18, end_vcol = 0 })) + eq(8, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18, end_vcol = 0 })) + end) + + it('with wrapped lines', function() + local X = meths.get_vvar('maxcol') + local screen = Screen.new(45, 22) + screen:set_default_attr_ids({ + [0] = {foreground = Screen.colors.Blue1, bold = true}; + [1] = {foreground = Screen.colors.Brown}; + [2] = {background = Screen.colors.Yellow}; + }) + screen:attach() + exec([[ + set number cpoptions+=n + call setline(1, repeat([repeat('foobar-', 36)], 3)) + ]]) + local ns = meths.create_namespace('') + meths.buf_set_extmark(0, ns, 1, 100, { virt_text = {{('?'):rep(15), 'Search'}}, virt_text_pos = 'inline' }) + meths.buf_set_extmark(0, ns, 2, 200, { virt_text = {{('!'):rep(75), 'Search'}}, virt_text_pos = 'inline' }) + screen:expect{grid=[[ + {1: 1 }^foobar-foobar-foobar-foobar-foobar-foobar| + -foobar-foobar-foobar-foobar-foobar-foobar-fo| + obar-foobar-foobar-foobar-foobar-foobar-fooba| + r-foobar-foobar-foobar-foobar-foobar-foobar-f| + oobar-foobar-foobar-foobar-foobar-foobar-foob| + ar-foobar-foobar-foobar-foobar- | + {1: 2 }foobar-foobar-foobar-foobar-foobar-foobar| + -foobar-foobar-foobar-foobar-foobar-foobar-fo| + obar-foobar-fo{2:???????????????}obar-foobar-foob| + ar-foobar-foobar-foobar-foobar-foobar-foobar-| + foobar-foobar-foobar-foobar-foobar-foobar-foo| + bar-foobar-foobar-foobar-foobar-foobar-foobar| + - | + {1: 3 }foobar-foobar-foobar-foobar-foobar-foobar| + -foobar-foobar-foobar-foobar-foobar-foobar-fo| + obar-foobar-foobar-foobar-foobar-foobar-fooba| + r-foobar-foobar-foobar-foobar-foobar-foobar-f| + oobar-foobar-foobar-foob{2:!!!!!!!!!!!!!!!!!!!!!}| + {2:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}| + {2:!!!!!!!!!}ar-foobar-foobar-foobar-foobar-fooba| + r-foobar-foobar- | + | + ]]} + screen:try_resize(45, 2) + screen:expect{grid=[[ + {1: 1 }^foobar-foobar-foobar-foobar-foobar-foobar| + | + ]]} + eq(21, meths.win_text_height(0, {})) + eq(6, meths.win_text_height(0, { start_row = 0, end_row = 0 })) + eq(7, meths.win_text_height(0, { start_row = 1, end_row = 1 })) + eq(8, meths.win_text_height(0, { start_row = 2, end_row = 2 })) + eq(1, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 41 })) + eq(2, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 42 })) + eq(2, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 86 })) + eq(3, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 87 })) + eq(6, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 266 })) + eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 267 })) + eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 311 })) + eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 312 })) + eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = X })) + eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 40, end_row = 1, end_vcol = X })) + eq(6, meths.win_text_height(0, { start_row = 1, start_vcol = 41, end_row = 1, end_vcol = X })) + eq(6, meths.win_text_height(0, { start_row = 1, start_vcol = 85, end_row = 1, end_vcol = X })) + eq(5, meths.win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = X })) + eq(2, meths.win_text_height(0, { start_row = 1, start_vcol = 265, end_row = 1, end_vcol = X })) + eq(1, meths.win_text_height(0, { start_row = 1, start_vcol = 266, end_row = 1, end_vcol = X })) + eq(1, meths.win_text_height(0, { start_row = 1, start_vcol = 310, end_row = 1, end_vcol = X })) + eq(0, meths.win_text_height(0, { start_row = 1, start_vcol = 311, end_row = 1, end_vcol = X })) + eq(18, meths.win_text_height(0, { start_row = 0, start_vcol = 131 })) + eq(19, meths.win_text_height(0, { start_row = 0, start_vcol = 130 })) + eq(20, meths.win_text_height(0, { end_row = 2, end_vcol = 311 })) + eq(21, meths.win_text_height(0, { end_row = 2, end_vcol = 312 })) + eq(17, meths.win_text_height(0, { start_row = 0, start_vcol = 131, end_row = 2, end_vcol = 311 })) + eq(19, meths.win_text_height(0, { start_row = 0, start_vcol = 130, end_row = 2, end_vcol = 312 })) + eq(16, meths.win_text_height(0, { start_row = 0, start_vcol = 221 })) + eq(17, meths.win_text_height(0, { start_row = 0, start_vcol = 220 })) + eq(14, meths.win_text_height(0, { end_row = 2, end_vcol = 41 })) + eq(15, meths.win_text_height(0, { end_row = 2, end_vcol = 42 })) + eq(9, meths.win_text_height(0, { start_row = 0, start_vcol = 221, end_row = 2, end_vcol = 41 })) + eq(11, meths.win_text_height(0, { start_row = 0, start_vcol = 220, end_row = 2, end_vcol = 42 })) + end) + end) + describe('open_win', function() it('noautocmd option works', function() command('autocmd BufEnter,BufLeave,BufWinEnter * let g:fired = 1') -- cgit From abe39f2b243dc813456225a779fbeb7ae6affc27 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Jul 2023 18:02:53 +0800 Subject: feat(api)!: change return type of nvim_win_text_height to Dict (#24365) --- test/functional/api/window_spec.lua | 141 ++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 69 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 8038a84139..19511f30f1 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -687,42 +687,42 @@ describe('API/win', function() {8:[No Name] [+] }{9:[No Name] [+] }| | ]]} - eq(20, meths.win_text_height(1000, {})) - eq(20, meths.win_text_height(1001, {})) - eq(20, meths.win_text_height(1000, { start_row = 0 })) - eq(20, meths.win_text_height(1001, { start_row = 0 })) - eq(15, meths.win_text_height(1000, { end_row = -1 })) - eq(20, meths.win_text_height(1001, { end_row = -1 })) - eq(15, meths.win_text_height(1000, { end_row = 40 })) - eq(20, meths.win_text_height(1001, { end_row = 40 })) - eq(10, meths.win_text_height(1000, { start_row = 23 })) - eq(13, meths.win_text_height(1001, { start_row = 18 })) - eq(11, meths.win_text_height(1000, { end_row = 23 })) - eq(11, meths.win_text_height(1001, { end_row = 18 })) - eq(11, meths.win_text_height(1000, { start_row = 3, end_row = 39 })) - eq(11, meths.win_text_height(1001, { start_row = 1, end_row = 34 })) - eq(9, meths.win_text_height(1000, { start_row = 4, end_row = 38 })) - eq(9, meths.win_text_height(1001, { start_row = 2, end_row = 33 })) - eq(9, meths.win_text_height(1000, { start_row = 5, end_row = 37 })) - eq(9, meths.win_text_height(1001, { start_row = 3, end_row = 32 })) - eq(9, meths.win_text_height(1000, { start_row = 17, end_row = 25 })) - eq(9, meths.win_text_height(1001, { start_row = 15, end_row = 20 })) - eq(7, meths.win_text_height(1000, { start_row = 18, end_row = 24 })) - eq(7, meths.win_text_height(1001, { start_row = 16, end_row = 19 })) - eq(6, meths.win_text_height(1000, { start_row = -1 })) - eq(5, meths.win_text_height(1000, { start_row = -1, start_vcol = X })) - eq(0, meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1 })) - eq(0, meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1, end_vcol = X })) - eq(1, meths.win_text_height(1000, { start_row = -1, start_vcol = 0, end_row = -1, end_vcol = X })) - eq(3, meths.win_text_height(1001, { end_row = 0 })) - eq(2, meths.win_text_height(1001, { end_row = 0, end_vcol = 0 })) - eq(2, meths.win_text_height(1001, { start_row = 0, end_row = 0, end_vcol = 0 })) - eq(0, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = 0 })) - eq(1, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = X })) - eq(11, meths.win_text_height(1001, { end_row = 18 })) - eq(9, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18 })) - eq(10, meths.win_text_height(1001, { end_row = 18, end_vcol = 0 })) - eq(8, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18, end_vcol = 0 })) + eq({ all = 20, fill = 5 }, meths.win_text_height(1000, {})) + eq({ all = 20, fill = 5 }, meths.win_text_height(1001, {})) + eq({ all = 20, fill = 5 }, meths.win_text_height(1000, { start_row = 0 })) + eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { start_row = 0 })) + eq({ all = 15, fill = 0 }, meths.win_text_height(1000, { end_row = -1 })) + eq({ all = 15, fill = 0 }, meths.win_text_height(1000, { end_row = 40 })) + eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { end_row = -1 })) + eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { end_row = 40 })) + eq({ all = 10, fill = 5 }, meths.win_text_height(1000, { start_row = 23 })) + eq({ all = 13, fill = 3 }, meths.win_text_height(1001, { start_row = 18 })) + eq({ all = 11, fill = 0 }, meths.win_text_height(1000, { end_row = 23 })) + eq({ all = 11, fill = 5 }, meths.win_text_height(1001, { end_row = 18 })) + eq({ all = 11, fill = 0 }, meths.win_text_height(1000, { start_row = 3, end_row = 39 })) + eq({ all = 11, fill = 3 }, meths.win_text_height(1001, { start_row = 1, end_row = 34 })) + eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 4, end_row = 38 })) + eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 2, end_row = 33 })) + eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 5, end_row = 37 })) + eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 3, end_row = 32 })) + eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 17, end_row = 25 })) + eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 15, end_row = 20 })) + eq({ all = 7, fill = 0 }, meths.win_text_height(1000, { start_row = 18, end_row = 24 })) + eq({ all = 7, fill = 3 }, meths.win_text_height(1001, { start_row = 16, end_row = 19 })) + eq({ all = 6, fill = 5 }, meths.win_text_height(1000, { start_row = -1 })) + eq({ all = 5, fill = 5 }, meths.win_text_height(1000, { start_row = -1, start_vcol = X })) + eq({ all = 0, fill = 0 }, meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1 })) + eq({ all = 0, fill = 0 }, meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1, end_vcol = X })) + eq({ all = 1, fill = 0 }, meths.win_text_height(1000, { start_row = -1, start_vcol = 0, end_row = -1, end_vcol = X })) + eq({ all = 3, fill = 2 }, meths.win_text_height(1001, { end_row = 0 })) + eq({ all = 2, fill = 2 }, meths.win_text_height(1001, { end_row = 0, end_vcol = 0 })) + eq({ all = 2, fill = 2 }, meths.win_text_height(1001, { start_row = 0, end_row = 0, end_vcol = 0 })) + eq({ all = 0, fill = 0 }, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = 0 })) + eq({ all = 1, fill = 0 }, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = X })) + eq({ all = 11, fill = 5 }, meths.win_text_height(1001, { end_row = 18 })) + eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18 })) + eq({ all = 10, fill = 5 }, meths.win_text_height(1001, { end_row = 18, end_vcol = 0 })) + eq({ all = 8, fill = 3 }, meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18, end_vcol = 0 })) end) it('with wrapped lines', function() @@ -770,39 +770,42 @@ describe('API/win', function() {1: 1 }^foobar-foobar-foobar-foobar-foobar-foobar| | ]]} - eq(21, meths.win_text_height(0, {})) - eq(6, meths.win_text_height(0, { start_row = 0, end_row = 0 })) - eq(7, meths.win_text_height(0, { start_row = 1, end_row = 1 })) - eq(8, meths.win_text_height(0, { start_row = 2, end_row = 2 })) - eq(1, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 41 })) - eq(2, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 42 })) - eq(2, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 86 })) - eq(3, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 87 })) - eq(6, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 266 })) - eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 267 })) - eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 311 })) - eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 312 })) - eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = X })) - eq(7, meths.win_text_height(0, { start_row = 1, start_vcol = 40, end_row = 1, end_vcol = X })) - eq(6, meths.win_text_height(0, { start_row = 1, start_vcol = 41, end_row = 1, end_vcol = X })) - eq(6, meths.win_text_height(0, { start_row = 1, start_vcol = 85, end_row = 1, end_vcol = X })) - eq(5, meths.win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = X })) - eq(2, meths.win_text_height(0, { start_row = 1, start_vcol = 265, end_row = 1, end_vcol = X })) - eq(1, meths.win_text_height(0, { start_row = 1, start_vcol = 266, end_row = 1, end_vcol = X })) - eq(1, meths.win_text_height(0, { start_row = 1, start_vcol = 310, end_row = 1, end_vcol = X })) - eq(0, meths.win_text_height(0, { start_row = 1, start_vcol = 311, end_row = 1, end_vcol = X })) - eq(18, meths.win_text_height(0, { start_row = 0, start_vcol = 131 })) - eq(19, meths.win_text_height(0, { start_row = 0, start_vcol = 130 })) - eq(20, meths.win_text_height(0, { end_row = 2, end_vcol = 311 })) - eq(21, meths.win_text_height(0, { end_row = 2, end_vcol = 312 })) - eq(17, meths.win_text_height(0, { start_row = 0, start_vcol = 131, end_row = 2, end_vcol = 311 })) - eq(19, meths.win_text_height(0, { start_row = 0, start_vcol = 130, end_row = 2, end_vcol = 312 })) - eq(16, meths.win_text_height(0, { start_row = 0, start_vcol = 221 })) - eq(17, meths.win_text_height(0, { start_row = 0, start_vcol = 220 })) - eq(14, meths.win_text_height(0, { end_row = 2, end_vcol = 41 })) - eq(15, meths.win_text_height(0, { end_row = 2, end_vcol = 42 })) - eq(9, meths.win_text_height(0, { start_row = 0, start_vcol = 221, end_row = 2, end_vcol = 41 })) - eq(11, meths.win_text_height(0, { start_row = 0, start_vcol = 220, end_row = 2, end_vcol = 42 })) + eq({ all = 21, fill = 0 }, meths.win_text_height(0, {})) + eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 0, end_row = 0 })) + eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, end_row = 1 })) + eq({ all = 8, fill = 0 }, meths.win_text_height(0, { start_row = 2, end_row = 2 })) + eq({ all = 0, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 0 })) + eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 41 })) + eq({ all = 2, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 42 })) + eq({ all = 2, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 86 })) + eq({ all = 3, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 87 })) + eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 266 })) + eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 267 })) + eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 311 })) + eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 312 })) + eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = X })) + eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 40, end_row = 1, end_vcol = X })) + eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 41, end_row = 1, end_vcol = X })) + eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 85, end_row = 1, end_vcol = X })) + eq({ all = 5, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = X })) + eq({ all = 2, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 265, end_row = 1, end_vcol = X })) + eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 266, end_row = 1, end_vcol = X })) + eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 310, end_row = 1, end_vcol = X })) + eq({ all = 0, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 311, end_row = 1, end_vcol = X })) + eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = 131 })) + eq({ all = 1, fill = 0 }, meths.win_text_height(0, { start_row = 1, start_vcol = 221, end_row = 1, end_vcol = 266 })) + eq({ all = 18, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 131 })) + eq({ all = 19, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 130 })) + eq({ all = 20, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 311 })) + eq({ all = 21, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 312 })) + eq({ all = 17, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 131, end_row = 2, end_vcol = 311 })) + eq({ all = 19, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 130, end_row = 2, end_vcol = 312 })) + eq({ all = 16, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 221 })) + eq({ all = 17, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 220 })) + eq({ all = 14, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 41 })) + eq({ all = 15, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 42 })) + eq({ all = 9, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 221, end_row = 2, end_vcol = 41 })) + eq({ all = 11, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 220, end_row = 2, end_vcol = 42 })) end) end) -- cgit From 24e3ee9d07e1433cb13b4d96ec20999f5f02b204 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 22 Jul 2023 09:52:13 +0100 Subject: fix(api/options): validate buf and win Fixes #24398 --- test/functional/api/vim_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 617d0f12ff..6aa9dcc8fa 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2445,7 +2445,7 @@ describe('API', function() it('can throw exceptions', function() local status, err = pcall(nvim, 'get_option_value', 'invalid-option', {}) eq(false, status) - ok(err:match("Invalid 'option': 'invalid%-option'") ~= nil) + ok(err:match("Unknown option 'invalid%-option'") ~= nil) end) it('does not truncate error message <1 MB #5984', function() -- cgit From a8cfdf43bc6226e32679ec59769ea3e48ca26193 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 07:16:41 +0800 Subject: fix(events): trigger VimResume on next UI request (#24426) --- test/functional/api/ui_spec.lua | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua index b616f51d10..60d115c6f1 100644 --- a/test/functional/api/ui_spec.lua +++ b/test/functional/api/ui_spec.lua @@ -1,8 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear +local command = helpers.command local eq = helpers.eq local eval = helpers.eval +local exec = helpers.exec +local feed = helpers.feed local meths = helpers.meths local request = helpers.request local pcall_err = helpers.pcall_err @@ -76,3 +79,59 @@ it('autocmds UIEnter/UILeave', function() 'UILeave', }, eval('g:evs')) end) + +it('autocmds VimSuspend/VimResume #22041', function() + clear() + local screen = Screen.new() + screen:attach() + exec([[ + let g:ev = [] + autocmd VimResume * :call add(g:ev, 'r') + autocmd VimSuspend * :call add(g:ev, 's') + ]]) + + eq(false, screen.suspended) + feed('') + screen:expect(function() eq (true, screen.suspended) end) + eq({ 's' }, eval('g:ev')) + screen.suspended = false + feed('') + eq({ 's', 'r' }, eval('g:ev')) + + command('suspend') + screen:expect(function() eq (true, screen.suspended) end) + eq({ 's', 'r', 's' }, eval('g:ev')) + screen.suspended = false + meths.input_mouse('move', '', '', 0, 0, 0) + eq({ 's', 'r', 's', 'r' }, eval('g:ev')) + + feed('') + screen:expect(function() eq (true, screen.suspended) end) + meths.ui_set_focus(false) + eq({ 's', 'r', 's', 'r', 's' }, eval('g:ev')) + screen.suspended = false + meths.ui_set_focus(true) + eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) + + command('suspend') + screen:expect(function() eq (true, screen.suspended) end) + screen:detach() + eq({ 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev')) + screen.suspended = false + screen:attach() + eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) + + eq(false, screen.suspended) + feed('') + screen:expect(function() eq (true, screen.suspended) end) + eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev')) + screen.suspended = false + feed('') + eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev')) + screen:expect(function() eq (true, screen.suspended) end) + screen.suspended = false + feed('i=g:ev') + eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) + eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r', '' }, + meths.buf_get_lines(0, 0, -1, true)) +end) -- cgit From f56c1848091bb64c63b5bc25ec74bcbd2f52bdde Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 10:03:05 +0800 Subject: test: fix VimResume test flakiness (#24438) --- test/functional/api/ui_spec.lua | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua index 60d115c6f1..2cadfe117f 100644 --- a/test/functional/api/ui_spec.lua +++ b/test/functional/api/ui_spec.lua @@ -92,46 +92,32 @@ it('autocmds VimSuspend/VimResume #22041', function() eq(false, screen.suspended) feed('') - screen:expect(function() eq (true, screen.suspended) end) + screen:expect(function() eq(true, screen.suspended) end) eq({ 's' }, eval('g:ev')) screen.suspended = false feed('') eq({ 's', 'r' }, eval('g:ev')) command('suspend') - screen:expect(function() eq (true, screen.suspended) end) + screen:expect(function() eq(true, screen.suspended) end) eq({ 's', 'r', 's' }, eval('g:ev')) screen.suspended = false meths.input_mouse('move', '', '', 0, 0, 0) eq({ 's', 'r', 's', 'r' }, eval('g:ev')) - feed('') - screen:expect(function() eq (true, screen.suspended) end) + feed('') + screen:expect(function() eq(true, screen.suspended) end) meths.ui_set_focus(false) eq({ 's', 'r', 's', 'r', 's' }, eval('g:ev')) screen.suspended = false meths.ui_set_focus(true) eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) - command('suspend') - screen:expect(function() eq (true, screen.suspended) end) + command('suspend | suspend | suspend') + screen:expect(function() eq(true, screen.suspended) end) screen:detach() eq({ 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev')) screen.suspended = false screen:attach() eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) - - eq(false, screen.suspended) - feed('') - screen:expect(function() eq (true, screen.suspended) end) - eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev')) - screen.suspended = false - feed('') - eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's' }, eval('g:ev')) - screen:expect(function() eq (true, screen.suspended) end) - screen.suspended = false - feed('i=g:ev') - eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) - eq({ 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r', 's', 'r', '' }, - meths.buf_get_lines(0, 0, -1, true)) end) -- cgit From 6b4970f6e0ac36021b2a8bd0533f5078040d31f7 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 23 Jul 2023 19:50:20 +0100 Subject: feat(api): allow open_win/win_set_buf in the cmdwin in some cases Problem: As discussed on Matrix, there was some interest in having `nvim_open_win` again be able to open floats in the cmdwin (e.g: displaying a hover doc related to what's in the cmdwin). After #23228, this was disallowed. Solution: Allow `nvim_open_win` in the cmdwin as long as `!enter` and `buffer != curbuf` (the former can cause all sorts of issues, and the latter can crash Nvim after closing cmdwin). Also allow `nvim_win_set_buf` in a similar fashion. Note that we're not *entirely* sure if this is 100% safe (cmdwin is a global-state-using-main-loop-calling beast), but this seems to work OK..? Also: - Check the buffer argument of `nvim_open_win` earlier, and abort if it's invalid (it used to still open a window in this case). - Untranslate `e_cmdwin` errors in the API (other errors in the API are not translated: although not detailed in the API contract yet, errors are supposed to be stable). --- test/functional/api/window_spec.lua | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 19511f30f1..e7e767817b 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -43,6 +43,22 @@ describe('API/win', 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'))) end) + + it('disallowed in cmdwin if win=curwin or buf=curbuf', function() + local new_buf = meths.create_buf(true, true) + local new_win = meths.open_win(new_buf, false, { + relative='editor', row=10, col=10, width=50, height=10, + }) + feed('q:') + eq('E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.win_set_buf, 0, new_buf)) + eq('E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.win_set_buf, new_win, 0)) + + local next_buf = meths.create_buf(true, true) + meths.win_set_buf(new_win, next_buf) + eq(next_buf, meths.win_get_buf(new_win)) + end) end) describe('{get,set}_cursor', function() @@ -821,6 +837,31 @@ describe('API/win', function() }) eq(1, funcs.exists('g:fired')) end) + + it('disallowed in cmdwin if enter=true or buf=curbuf', function() + local new_buf = meths.create_buf(true, true) + feed('q:') + eq('E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.open_win, new_buf, true, { + relative='editor', row=5, col=5, width=5, height=5, + })) + eq('E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.open_win, 0, false, { + relative='editor', row=5, col=5, width=5, height=5, + })) + + eq(new_buf, meths.win_get_buf(meths.open_win(new_buf, false, { + relative='editor', row=5, col=5, width=5, height=5, + }))) + end) + + it('aborts if buffer is invalid', function() + local wins_before = meths.list_wins() + eq('Invalid buffer id: 1337', pcall_err(meths.open_win, 1337, false, { + relative='editor', row=5, col=5, width=5, height=5, + })) + eq(wins_before, meths.list_wins()) + end) end) describe('get_config', function() -- cgit From 5d921e28c1cc33eced22bbfa823460ca241e3dc1 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 23 Jul 2023 23:10:28 +0100 Subject: feat(api): allow win_close in cmdwin to close wins except previous Disallow closing the previous window from `nvim_win_close`, as this will cause issues. Again, no telling how safe this is. It also requires exposing old_curwin. :/ Also note that it's possible for the `&cmdheight` to change if, for example, there are 2 tabpages and `nvim_win_close` is used to close the last window in the other tabpage while `&stal` is 1. This is addressed in a later commit. --- test/functional/api/window_spec.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index e7e767817b..74aaae0c6f 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -540,15 +540,21 @@ describe('API/win', function() command('split') eq(2, #meths.list_wins()) local oldwin = meths.get_current_win() + local otherwin = meths.open_win(0, false, { + relative='editor', row=10, col=10, width=10, height=10, + }) -- Open cmdline-window. feed('q:') - eq(3, #meths.list_wins()) + eq(4, #meths.list_wins()) eq(':', funcs.getcmdwintype()) - -- Vim: not allowed to close other windows from cmdline-window. + -- Not allowed to close previous window from cmdline-window. eq('E11: Invalid in command-line window; executes, CTRL-C quits', - pcall_err(meths.win_close, oldwin, true)) + pcall_err(meths.win_close, oldwin, true)) + -- Closing other windows is fine. + meths.win_close(otherwin, true) + eq(false, meths.win_is_valid(otherwin)) -- Close cmdline-window. - meths.win_close(0,true) + meths.win_close(0, true) eq(2, #meths.list_wins()) eq('', funcs.getcmdwintype()) end) -- cgit From 472271199e483d3f23d62c272b20c5290eec5474 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 24 Jul 2023 14:19:01 +0100 Subject: feat(api): allow win_hide to close cmdwin or non-previous windows This aligns its behaviour better with `nvim_win_close`. Note that `:hide` is actually incapable of closing the cmdwin, unlike `:close` and `:quit`, so this is a bit of a difference in behaviour. --- test/functional/api/window_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 74aaae0c6f..00896a97d8 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -615,6 +615,24 @@ describe('API/win', function() eq({oldwin}, meths.list_wins()) eq({oldbuf}, meths.list_bufs()) end) + it('in the cmdwin', function() + feed('q:') + -- Can close the cmdwin. + meths.win_hide(0) + eq('', funcs.getcmdwintype()) + + local old_win = meths.get_current_win() + local other_win = meths.open_win(0, false, { + relative='win', row=3, col=3, width=12, height=3 + }) + feed('q:') + -- Cannot close the previous window. + eq('E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.win_hide, old_win)) + -- Can close other windows. + meths.win_hide(other_win) + eq(false, meths.win_is_valid(other_win)) + end) end) describe('text_height', function() -- cgit From 7bc93e0e2f246dd78026a3472d929a0fe450f70d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 1 Aug 2023 14:01:19 +0200 Subject: refactor(api): use typed keysets Initially this is just for geting rid of boilerplate, but eventually the types could get exposed as metadata --- test/functional/api/extmark_spec.lua | 2 +- test/functional/api/highlight_spec.lua | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index ec1c9245ba..6d8e3d8e0a 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -109,7 +109,7 @@ describe('API/extmarks', function() eq("Invalid 'virt_text_pos': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 'foo' })) eq("Invalid 'hl_mode': expected String, got Integer", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 0 })) eq("Invalid 'hl_mode': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 'foo' })) - eq("Invalid 'id': expected positive Integer", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })) + eq("Invalid 'id': expected Integer, got Array", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })) eq("Invalid mark position: expected 2 Integer items", pcall_err(get_extmarks, ns, {}, {-1, -1})) eq("Invalid mark position: expected mark id Integer or 2-item Array", pcall_err(get_extmarks, ns, true, {-1, -1})) -- No memory leak with virt_text, virt_lines, sign_text diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index d3a79327ae..5fa2235018 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -434,10 +434,8 @@ describe('API: get highlight', function() before_each(clear) it('validation', function() - eq( - 'Invalid highlight name: expected String, got Integer', - pcall_err(meths.get_hl, 0, { name = 177 }) - ) + eq("Invalid 'name': expected String, got Integer", + pcall_err(meths.get_hl, 0, { name = 177 })) eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' })) end) @@ -534,7 +532,7 @@ describe('API: get highlight', function() eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 })) eq( - 'Invalid highlight id: expected Integer, got String', + "Invalid 'id': expected Integer, got String", pcall_err(meths.get_hl, 0, { id = 'Test_set_hl' }) ) -- cgit From 0b351c3740d621689b17267171e162abd421e759 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 2 Aug 2023 13:00:13 +0200 Subject: test(api): update tests to new error messages --- test/functional/api/autocmd_spec.lua | 2 +- test/functional/api/vim_spec.lua | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 4cfe8672b1..ba267e7539 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -737,7 +737,7 @@ describe('autocmd api', function() eq("Invalid 'group': 0", pcall_err(meths.exec_autocmds, 'FileType', { group = 0, })) - eq("Invalid 'buffer': expected Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'buffer': expected Buffer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { buffer = {}, })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.exec_autocmds, diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 6aa9dcc8fa..70fa80f2a2 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -4112,12 +4112,10 @@ describe('API', function() it('validation', function() eq("Invalid 'cmd': expected non-empty String", pcall_err(meths.cmd, { cmd = ""}, {})) - eq("Invalid 'cmd': expected non-empty String", + eq("Invalid 'cmd': expected String, got Array", pcall_err(meths.cmd, { cmd = {}}, {})) eq("Invalid 'args': expected Array, got Boolean", pcall_err(meths.cmd, { cmd = "set", args = true }, {})) - eq("Invalid 'magic': expected Dict, got Array", - pcall_err(meths.cmd, { cmd = "set", args = {}, magic = {} }, {})) eq("Invalid command arg: expected non-whitespace", pcall_err(meths.cmd, { cmd = "set", args = {' '}, }, {})) eq("Invalid command arg: expected valid type, got Array", @@ -4138,7 +4136,7 @@ describe('API', function() eq("Command cannot accept count: set", pcall_err(meths.cmd, { cmd = "set", args = {}, count = 1 }, {})) - eq("Invalid 'count': expected non-negative Integer", + eq("Invalid 'count': expected Integer, got Boolean", pcall_err(meths.cmd, { cmd = "print", args = {}, count = true }, {})) eq("Invalid 'count': expected non-negative Integer", pcall_err(meths.cmd, { cmd = "print", args = {}, count = -1 }, {})) @@ -4158,9 +4156,10 @@ describe('API', function() -- Lua call allows empty {} for dict item. eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, magic = {} }]])) eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, mods = {} }]])) + eq('', meths.cmd({ cmd = "set", args = {}, magic = {} }, {})) -- Lua call does not allow non-empty list-like {} for dict item. - eq("Invalid 'magic': expected Dict, got Array", + eq("Invalid 'magic': Expected Dict-like Lua table", pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, magic = { 'a' } }]])) eq("Invalid key: 'bogus'", pcall_err(exec_lua, [[return vim.cmd{ cmd = "set", args = {}, magic = { bogus = true } }]])) -- cgit From 017ff93b020e1915d03d9a2dd9a895613148f181 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Aug 2023 22:14:48 +0800 Subject: fix(keycodes): recognize as a key (#24700) Problem: The result of keytrans() sometimes can't be translated back. Solution: Recognize as a key. --- test/functional/api/vim_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 70fa80f2a2..7edf1d9cde 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1957,6 +1957,12 @@ describe('API', function() -- value. eq('', meths.replace_termcodes('', true, true, true)) end) + + -- Not exactly the case, as nvim_replace_termcodes() escapes K_SPECIAL in Unicode + it('translates the result of keytrans() on string with 0x80 byte back', function() + local s = 'ff\128\253\097tt' + eq(s, meths.replace_termcodes(funcs.keytrans(s), true, true, true)) + end) end) describe('nvim_feedkeys', function() -- cgit From 22d9338afceae5f8ef3845f152dea07a19d512d1 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 17 Aug 2023 00:53:10 +0100 Subject: fix(api): disallow win_set_buf from changing cmdwin's old curbuf (#24745) A command typed in the cmdwin and executed with `` is expected to be executed in the context of the old curwin/buf, so it shouldn't be changed. --- test/functional/api/window_spec.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 00896a97d8..44d4470337 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -44,14 +44,17 @@ describe('API/win', function() eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf'))) end) - it('disallowed in cmdwin if win=curwin or buf=curbuf', function() + it('disallowed in cmdwin if win={old_}curwin or buf=curbuf', function() local new_buf = meths.create_buf(true, true) + local old_win = meths.get_current_win() local new_win = meths.open_win(new_buf, false, { relative='editor', row=10, col=10, width=50, height=10, }) feed('q:') eq('E11: Invalid in command-line window; executes, CTRL-C quits', pcall_err(meths.win_set_buf, 0, new_buf)) + eq('E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(meths.win_set_buf, old_win, new_buf)) eq('E11: Invalid in command-line window; executes, CTRL-C quits', pcall_err(meths.win_set_buf, new_win, 0)) -- cgit From 008154954791001efcc46c28146e21403f3a698b Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 21 Aug 2023 14:52:17 +0200 Subject: refactor(change): do API changes to buffer without curbuf switch Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired. --- test/functional/api/buffer_spec.lua | 76 +++++++++++++++++++++++++++++++++++++ test/functional/api/vim_spec.lua | 5 ++- 2 files changed, 79 insertions(+), 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 512a1a08a6..4784c0a9dd 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -76,6 +76,38 @@ describe('api/buf', function() eq({4, 2}, curwin('get_cursor')) end) + it('cursor position is maintained in non-current window', function() + meths.buf_set_lines(0, 0, -1, 1, {"line1", "line2", "line3", "line4"}) + meths.win_set_cursor(0, {3, 2}) + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command('new') + + meths.buf_set_lines(buf, 1, 2, 1, {"line5", "line6"}) + eq({"line1", "line5", "line6", "line3", "line4"}, meths.buf_get_lines(buf, 0, -1, true)) + eq({4, 2}, meths.win_get_cursor(win)) + end) + + it('cursor position is maintained in TWO non-current windows', function() + meths.buf_set_lines(0, 0, -1, 1, {"line1", "line2", "line3", "line4"}) + meths.win_set_cursor(0, {3, 2}) + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command('split') + meths.win_set_cursor(0, {4, 2}) + local win2 = meths.get_current_win() + + -- set current window to third one with another buffer + command("new") + + meths.buf_set_lines(buf, 1, 2, 1, {"line5", "line6"}) + eq({"line1", "line5", "line6", "line3", "line4"}, meths.buf_get_lines(buf, 0, -1, true)) + eq({4, 2}, meths.win_get_cursor(win)) + eq({5, 2}, meths.win_get_cursor(win2)) + end) + 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') @@ -484,6 +516,50 @@ describe('api/buf', function() eq({1, 9}, curwin('get_cursor')) end) + it('updates the cursor position in non-current window', function() + insert([[ + hello world!]]) + + -- position the cursor on `!` + meths.win_set_cursor(0, {1, 11}) + + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command("new") + + -- replace 'world' with 'foo' + meths.buf_set_text(buf, 0, 6, 0, 11, {'foo'}) + eq({'hello foo!'}, meths.buf_get_lines(buf, 0, -1, true)) + -- cursor should be moved left by two columns (replacement is shorter by 2 chars) + eq({1, 9}, meths.win_get_cursor(win)) + end) + + it('updates the cursor position in TWO non-current windows', function() + insert([[ + hello world!]]) + + -- position the cursor on `!` + meths.win_set_cursor(0, {1, 11}) + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command("split") + local win2 = meths.get_current_win() + -- position the cursor on `w` + meths.win_set_cursor(0, {1, 6}) + + command("new") + + -- replace 'hello' with 'foo' + meths.buf_set_text(buf, 0, 0, 0, 5, {'foo'}) + eq({'foo world!'}, meths.buf_get_lines(buf, 0, -1, true)) + + -- both cursors should be moved left by two columns (replacement is shorter by 2 chars) + eq({1, 9}, meths.win_get_cursor(win)) + eq({1, 4}, meths.win_get_cursor(win2)) + end) + it('can handle NULs', function() set_text(0, 0, 0, 0, {'ab\0cd'}) eq('ab\0cd', curbuf_depr('get_line', 0)) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 7edf1d9cde..2de1990b14 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -28,7 +28,6 @@ local write_file = helpers.write_file local exec_lua = helpers.exec_lua local exc_exec = helpers.exc_exec local insert = helpers.insert -local expect_exit = helpers.expect_exit local skip = helpers.skip local pcall_err = helpers.pcall_err @@ -2832,7 +2831,9 @@ describe('API', function() it('does not cause heap-use-after-free on exit while setting options', function() command('au OptionSet * q') - expect_exit(command, 'silent! call nvim_create_buf(0, 1)') + command('silent! call nvim_create_buf(0, 1)') + -- nowadays this works because we don't execute any spurious autocmds at all #24824 + assert_alive() end) end) -- cgit From 9b9030ff2ca820d4c4f4b559f86b0f9a3496645b Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 27 Aug 2023 11:20:59 +0200 Subject: fix(api): fix inconsistent behavior of topline touched in recent refactor The change in #24824 0081549 was not a regression, however it was an incomplete change. Unfortunately some common plugins come to depend on this exising self-inconsistent behavior. These plugins are going to need to update for 0.10 nvim_buf_set_lines used to NOT adjust the topline correctly if a buffer was displayed in just one window. However, if displayed in multiple windows, it was correctly adjusted for any window not deemed the current window for the buffer (which could be an arbitrary choice if the buffer was not already current, as noted in the last rafactor) This fixes so that all windows have their topline adjusted. The added tests show this behavior, which should be the reasonable one. --- test/functional/api/buffer_spec.lua | 266 ++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 4784c0a9dd..fda2ea17b8 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -137,6 +137,139 @@ describe('api/buf', function() -- it's impossible to get out-of-bounds errors for an unloaded buffer eq({}, buffer('get_lines', bufnr, 8888, 9999, 1)) end) + + describe('handles topline', function() + local screen + before_each(function() + screen = Screen.new(20, 12) + screen:set_default_attr_ids { + [1] = {bold = true, foreground = Screen.colors.Blue1}; + [2] = {reverse = true, bold = true}; + [3] = {reverse = true}; + } + screen:attach() + meths.buf_set_lines(0, 0, -1, 1, {"aaa", "bbb", "ccc", "ddd", "www", "xxx", "yyy", "zzz"}) + meths.set_option_value('modified', false, {}) + end) + + it('of current window', function() + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command('new | wincmd w') + meths.win_set_cursor(win, {8,0}) + + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + www | + xxx | + yyy | + ^zzz | + {2:[No Name] }| + | + ]]} + meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"}) + + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + www | + xxx | + yyy | + ^zzz | + {2:[No Name] [+] }| + | + ]]} + end) + + it('of non-current window', function() + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command('new') + meths.win_set_cursor(win, {8,0}) + + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + www | + xxx | + yyy | + zzz | + {3:[No Name] }| + | + ]]} + + meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"}) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + www | + xxx | + yyy | + zzz | + {3:[No Name] [+] }| + | + ]]} + end) + + it('of split windows with same buffer', function() + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command('split') + meths.win_set_cursor(win, {8,0}) + meths.win_set_cursor(0, {1,0}) + + screen:expect{grid=[[ + ^aaa | + bbb | + ccc | + ddd | + www | + {2:[No Name] }| + www | + xxx | + yyy | + zzz | + {3:[No Name] }| + | + ]]} + meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"}) + + screen:expect{grid=[[ + ^aaabbb | + ccc | + ddd | + www | + xxx | + {2:[No Name] [+] }| + www | + xxx | + yyy | + zzz | + {3:[No Name] [+] }| + | + ]]} + end) + end) end) describe('deprecated: {get,set,del}_line', function() @@ -659,6 +792,139 @@ describe('api/buf', function() ]]) eq({'one', 'two'}, get_lines(0, 2, true)) end) + + describe('handles topline', function() + local screen + before_each(function() + screen = Screen.new(20, 12) + screen:set_default_attr_ids { + [1] = {bold = true, foreground = Screen.colors.Blue1}; + [2] = {reverse = true, bold = true}; + [3] = {reverse = true}; + } + screen:attach() + meths.buf_set_lines(0, 0, -1, 1, {"aaa", "bbb", "ccc", "ddd", "www", "xxx", "yyy", "zzz"}) + meths.set_option_value('modified', false, {}) + end) + + it('of current window', function() + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command('new | wincmd w') + meths.win_set_cursor(win, {8,0}) + + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + www | + xxx | + yyy | + ^zzz | + {2:[No Name] }| + | + ]]} + meths.buf_set_text(buf, 0,3, 1,0, {"X"}) + + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + www | + xxx | + yyy | + ^zzz | + {2:[No Name] [+] }| + | + ]]} + end) + + it('of non-current window', function() + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command('new') + meths.win_set_cursor(win, {8,0}) + + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + www | + xxx | + yyy | + zzz | + {3:[No Name] }| + | + ]]} + + meths.buf_set_text(buf, 0,3, 1,0, {"X"}) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + www | + xxx | + yyy | + zzz | + {3:[No Name] [+] }| + | + ]]} + end) + + it('of split windows with same buffer', function() + local win = meths.get_current_win() + local buf = meths.get_current_buf() + + command('split') + meths.win_set_cursor(win, {8,0}) + meths.win_set_cursor(0, {1,1}) + + screen:expect{grid=[[ + a^aa | + bbb | + ccc | + ddd | + www | + {2:[No Name] }| + www | + xxx | + yyy | + zzz | + {3:[No Name] }| + | + ]]} + meths.buf_set_text(buf, 0,3, 1,0, {"X"}) + + screen:expect{grid=[[ + a^aaXbbb | + ccc | + ddd | + www | + xxx | + {2:[No Name] [+] }| + www | + xxx | + yyy | + zzz | + {3:[No Name] [+] }| + | + ]]} + end) + end) end) describe_lua_and_rpc('nvim_buf_get_text', function(api) -- cgit From 840749d6c971f93aa9744bd6f76b383f11043463 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 27 Aug 2023 11:26:54 +0200 Subject: fix(undo): fix crash caused by checking undolevels in wrong buffer fixes #24894 --- test/functional/api/buffer_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index fda2ea17b8..0afe619b03 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -16,6 +16,7 @@ local command = helpers.command local bufmeths = helpers.bufmeths local feed = helpers.feed local pcall_err = helpers.pcall_err +local assert_alive = helpers.assert_alive describe('api/buf', function() before_each(clear) @@ -41,6 +42,14 @@ describe('api/buf', function() eq(1, curbuf_depr('line_count')) end) + it("doesn't crash just after set undolevels=1 #24894", function() + local buf = meths.create_buf(false, true) + meths.buf_set_option(buf, 'undolevels', -1) + meths.buf_set_lines(buf, 0, 1, false, { }) + + assert_alive() + end) + 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"}) -- cgit From 132bbd1cbd490a65bc186c4a9f449c6d2f0a7666 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 28 Aug 2023 12:36:00 +0200 Subject: fix(api): handle clearing out last line of non-current buffer fixes #24911 --- test/functional/api/buffer_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 0afe619b03..73a8749682 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -279,6 +279,18 @@ describe('api/buf', function() ]]} end) end) + + it('handles clearing out non-current buffer #24911', function() + local buf = meths.get_current_buf() + meths.buf_set_lines(buf, 0, -1, true, {"aaa", "bbb", "ccc"}) + command("new") + + meths.buf_set_lines(0, 0, -1, true, {"xxx", "yyy", "zzz"}) + + meths.buf_set_lines(buf, 0, -1, true, {}) + eq({"xxx", "yyy", "zzz"}, meths.buf_get_lines(0, 0, -1, true)) + eq({''}, meths.buf_get_lines(buf, 0, -1, true)) + end) end) describe('deprecated: {get,set,del}_line', function() -- cgit From 0a81ec14a4c006822509b06396871509140b7a79 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 28 Aug 2023 11:35:09 +0200 Subject: fix(api): better topline adjustments in nvim_buf_set_lines Some more reasonable defaults for topline: - if topline was replaced with another line, that now becomes topline - if line was inserted just before topline, display it. This is more similar to the previous API behavior. --- test/functional/api/buffer_spec.lua | 136 +++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 73a8749682..aea1f359e6 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -182,8 +182,8 @@ describe('api/buf', function() {2:[No Name] }| | ]]} - meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"}) + meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"}) screen:expect{grid=[[ | {1:~ }| @@ -198,6 +198,72 @@ describe('api/buf', function() {2:[No Name] [+] }| | ]]} + + -- replacing topline keeps it the topline + meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + wwweeee | + xxx | + yyy | + ^zzz | + {2:[No Name] [+] }| + | + ]]} + + -- inserting just before topline does not scroll up if cursor would be moved + meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + wwweeee | + xxx | + yyy | + ^zzz | + {2:[No Name] [+] }| + | + ]], unchanged=true} + + meths.win_set_cursor(0, {7, 0}) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + wwweeee | + xxx | + ^yyy | + zzz | + {2:[No Name] [+] }| + | + ]]} + + meths.buf_set_lines(buf, 4, 4, true, {"mmmeeeee"}) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:[No Name] }| + mmmeeeee | + wwweeee | + xxx | + ^yyy | + {2:[No Name] [+] }| + | + ]]} end) it('of non-current window', function() @@ -237,6 +303,40 @@ describe('api/buf', function() {3:[No Name] [+] }| | ]]} + + -- replacing topline keeps it the topline + meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + wwweeee | + xxx | + yyy | + zzz | + {3:[No Name] [+] }| + | + ]]} + + -- inserting just before topline scrolls up + meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + mmm | + wwweeee | + xxx | + yyy | + {3:[No Name] [+] }| + | + ]]} end) it('of split windows with same buffer', function() @@ -277,6 +377,40 @@ describe('api/buf', function() {3:[No Name] [+] }| | ]]} + + -- replacing topline keeps it the topline + meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"}) + screen:expect{grid=[[ + ^aaabbb | + ccc | + ddd | + wwweeee | + xxx | + {2:[No Name] [+] }| + wwweeee | + xxx | + yyy | + zzz | + {3:[No Name] [+] }| + | + ]]} + + -- inserting just before topline scrolls up + meths.buf_set_lines(buf, 3, 3, true, {"mmm"}) + screen:expect{grid=[[ + ^aaabbb | + ccc | + ddd | + mmm | + wwweeee | + {2:[No Name] [+] }| + mmm | + wwweeee | + xxx | + yyy | + {3:[No Name] [+] }| + | + ]]} end) end) -- cgit From b051b131f5ce99ffe1b1bc22a2032ebc886e4e35 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 30 Aug 2023 11:53:58 +0200 Subject: fix(api): nvim_buf_get_offset in a new buffer with zero or one lines fixes #24930 --- test/functional/api/buffer_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index aea1f359e6..292e5a2d56 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -1151,6 +1151,18 @@ describe('api/buf', function() eq(6, bufmeths.get_offset(1,1)) command("bunload! 1") eq(-1, bufmeths.get_offset(1,1)) + eq(-1, bufmeths.get_offset(1,0)) + end) + + it('works in empty buffer', function() + eq(0, get_offset(0)) + eq(1, get_offset(1)) + end) + + it('works in buffer with one line inserted', function() + feed('itext') + eq(0, get_offset(0)) + eq(5, get_offset(1)) end) end) -- cgit From c3e176f6e24e2b97603b59bb89b125d540e1274d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 5 Sep 2023 20:03:25 +0800 Subject: fix(options): correct condition for calling did_set_option() (#25026) --- test/functional/api/vim_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 2de1990b14..f734bfb0c0 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1416,6 +1416,20 @@ describe('API', function() 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, nvim('get_option_info2', 'cmdwinheight', {}).was_set) + nvim('set_option_value', 'cmdwinheight', 10, {}) + eq(true, 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) + end) end) describe('nvim_get_option_value, nvim_set_option_value', function() -- cgit From 8afb3a49c0762eb60368aee0314e6de261daa6ef Mon Sep 17 00:00:00 2001 From: glepnir Date: Thu, 7 Sep 2023 18:42:38 +0800 Subject: fix(highlight): add create param in nvim_get_hl --- test/functional/api/highlight_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 5fa2235018..492fd73223 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -439,6 +439,15 @@ describe('API: get highlight', function() eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' })) end) + it('nvim_get_hl with create flag', function() + eq({}, nvim("get_hl", 0, {name = 'Foo', create = false})) + eq(0, funcs.hlexists('Foo')) + meths.get_hl(0, {name = 'Bar', create = true}) + eq(1, funcs.hlexists('Bar')) + meths.get_hl(0, {name = 'FooBar'}) + eq(1, funcs.hlexists('FooBar')) + end) + it('can get all highlights in current namespace', function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) -- cgit From af0684f0d578631dae7d857cd065d81288be3cf2 Mon Sep 17 00:00:00 2001 From: Sergey Slipchenko Date: Mon, 11 Sep 2023 01:53:05 +0400 Subject: test: unignore test which froze sourcehut (#25067) --- test/functional/api/server_notifications_spec.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 53642858b2..bc43f6564d 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -6,9 +6,7 @@ local eq, clear, eval, command, nvim, next_msg = local meths = helpers.meths local exec_lua = helpers.exec_lua local retry = helpers.retry -local is_ci = helpers.is_ci local assert_alive = helpers.assert_alive -local skip = helpers.skip local testlog = 'Xtest-server-notify-log' @@ -90,7 +88,6 @@ describe('notify', function() end) it('cancels stale events on channel close', function() - skip(is_ci(), 'hangs on CI #14083 #15251') local catchan = eval("jobstart(['cat'], {'rpc': v:true})") local catpath = eval('exepath("cat")') eq({id=catchan, argv={catpath}, stream='job', mode='rpc', client = {}}, exec_lua ([[ -- cgit From d22172f36bbe147f3aa6b76a1c43ae445f481c2e Mon Sep 17 00:00:00 2001 From: Sergey Slipchenko Date: Mon, 11 Sep 2023 08:16:03 +0400 Subject: fix(api): more intuitive cursor updates in nvim_buf_set_text Fixes #22526 --- test/functional/api/buffer_spec.lua | 704 ++++++++++++++++++++++++++++++++++++ 1 file changed, 704 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 292e5a2d56..9833ebee4c 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -848,6 +848,710 @@ describe('api/buf', function() eq({1, 4}, meths.win_get_cursor(win2)) end) + describe('when text is being added right at cursor position #22526', function() + it('updates the cursor position in NORMAL mode', function() + insert([[ + abcd]]) + + -- position the cursor on 'c' + curwin('set_cursor', {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')) + end) + + it('updates the cursor position only in non-current window when in INSERT mode', function() + insert([[ + abcd]]) + + -- position the cursor on 'c' + curwin('set_cursor', {1, 2}) + -- open vertical split + feed('v') + -- get into INSERT mode to treat cursor + -- as being after 'b', not on 'c' + feed('i') + -- add 'xxx' between 'b' and 'c' + 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')) + -- quit INSERT mode + feed('') + -- close current window + feed('c') + -- in another window cursor should be on 'c' + eq({1, 5}, curwin('get_cursor')) + end) + end) + + describe('when text is being deleted right at cursor position', function() + it('leaves cursor at the same position in NORMAL mode', function() + insert([[ + abcd]]) + + -- position the cursor on 'b' + curwin('set_cursor', {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')) + end) + + it('leaves cursor at the same position in INSERT mode in current and non-current window', function() + insert([[ + abcd]]) + + -- position the cursor on 'b' + curwin('set_cursor', {1, 1}) + -- open vertical split + feed('v') + -- get into INSERT mode to treat cursor + -- as being after 'a', not on 'b' + feed('i') + -- delete 'b' + 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')) + -- quit INSERT mode + feed('') + -- close current window + feed('c') + -- cursor in non-current window should stay on 'c' + eq({1, 1}, curwin('get_cursor')) + end) + end) + + describe('when cursor is inside replaced row range', function() + it('keeps cursor at the same position if cursor is at start_row, but before start_col', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on ' ' before 'first' + curwin('set_cursor', {1, 14}) + + set_text(0, 15, 2, 11, { + 'the line we do not want', + 'but hopefully', + }) + + eq({ + 'This should be the line we do not want', + 'but hopefully the last one', + }, get_lines(0, -1, true)) + -- cursor should stay at the same position + eq({1, 14}, curwin('get_cursor')) + end) + + it('keeps cursor at the same position if cursor is at start_row and column is still valid', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'f' in 'first' + curwin('set_cursor', {1, 15}) + + set_text(0, 15, 2, 11, { + 'the line we do not want', + 'but hopefully', + }) + + eq({ + 'This should be the line we do not want', + 'but hopefully the last one', + }, get_lines(0, -1, true)) + -- cursor should stay at the same position + eq({1, 15}, curwin('get_cursor')) + end) + + it('adjusts cursor column to keep it valid if start_row got smaller', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 't' in 'first' + curwin('set_cursor', {1, 19}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 24, {'last'}) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ 'This should be last' }, get_lines(0, -1, true)) + -- cursor should end up on 't' in 'last' + eq({1, 18}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 18}, cursor) + end) + + it('adjusts cursor column to keep it valid if start_row got smaller in INSERT mode', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 't' in 'first' + curwin('set_cursor', {1, 19}) + -- enter INSERT mode to treat cursor as being after 't' + feed('a') + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 24, {'last'}) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ 'This should be last' }, get_lines(0, -1, true)) + -- cursor should end up after 't' in 'last' + eq({1, 19}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 19}, cursor) + end) + + it('adjusts cursor column to keep it valid in a row after start_row if it got smaller', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'w' in 'want' + curwin('set_cursor', {2, 31}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { + '1', + 'then 2', + 'and then', + }) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ + 'This should be 1', + 'then 2', + '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')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({2, 5}, cursor) + end) + + it('adjusts cursor column to keep it valid in a row after start_row if it got smaller in INSERT mode', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'w' in 'want' + curwin('set_cursor', {2, 31}) + -- enter INSERT mode + feed('a') + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { + '1', + 'then 2', + 'and then', + }) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ + 'This should be 1', + 'then 2', + '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')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({2, 6}, cursor) + end) + + it('adjusts cursor line and column to keep it inside replacement range', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'n' in 'finally' + curwin('set_cursor', {3, 6}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { + 'the line we do not want', + 'but hopefully', + }) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ + 'This should be the line we do not want', + 'but hopefully the last one', + }, 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')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({2, 12}, cursor) + end) + + it('adjusts cursor line and column if replacement is empty', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'r' in 'there' + curwin('set_cursor', {2, 8}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 12, {}) + return vim.api.nvim_win_get_cursor(0) + ]]) + + 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')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 15}, cursor) + end) + + it('adjusts cursor line and column if replacement is empty and start_col == 0', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'r' in 'there' + curwin('set_cursor', {2, 8}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 0, 2, 4, {}) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ 'finally the last one' }, get_lines(0, -1, true)) + -- cursor should end up in column 0 + eq({1, 0}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 0}, cursor) + end) + + it('adjusts cursor column if replacement ends at cursor row, after cursor column', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'y' in 'finally' + curwin('set_cursor', {3, 10}) + set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' }) + + eq({ + 'This should be 1', + 'this 2', + 'and then the last one', + }, get_lines(0, -1, true)) + -- cursor should end up on 'n' in 'then' + eq({3, 7}, curwin('get_cursor')) + end) + + it('adjusts cursor column if replacement ends at cursor row, at cursor column in INSERT mode', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'y' at 'finally' + curwin('set_cursor', {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' }) + + eq({ + 'This should be 1', + 'this 2', + 'and then the last one', + }, get_lines(0, -1, true)) + -- cursor should end up after 'n' in 'then' + eq({3, 8}, curwin('get_cursor')) + end) + + it('adjusts cursor column if replacement is inside of a single line', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'y' in 'finally' + curwin('set_cursor', {3, 10}) + set_text(2, 4, 2, 11, { 'then' }) + + eq({ + 'This should be first', + 'then there is a line we do not want', + 'and then the last one', + }, get_lines(0, -1, true)) + -- cursor should end up on 'n' in 'then' + eq({3, 7}, curwin('get_cursor')) + end) + + it('does not move cursor column after end of a line', function() + insert([[ + This should be the only line here + !!!]]) + + -- position cursor on the last '1' + curwin('set_cursor', {2, 2}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 33, 1, 3, {}) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ 'This should be the only line here' }, get_lines(0, -1, true)) + -- cursor should end up on '!' + eq({1, 32}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 32}, cursor) + end) + + it('does not move cursor column before start of a line', function() + insert('\n!!!') + + -- position cursor on the last '1' + curwin('set_cursor', {2, 2}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 0, 1, 3, {}) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ '' }, get_lines(0, -1, true)) + -- cursor should end up on '!' + eq({1, 0}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 0}, cursor) + end) + + describe('with virtualedit', function() + it('adjusts cursor line and column to keep it inside replacement range if cursor is not after eol', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position cursor on 't' in 'want' + curwin('set_cursor', {2, 34}) + -- turn on virtualedit + command('set virtualedit=all') + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { + 'the line we do not want', + 'but hopefully', + }) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ + 'This should be the line we do not want', + 'but hopefully the last one', + }, get_lines(0, -1, true)) + -- cursor should end up on 'y' in 'hopefully' + -- to stay in the range + eq({2, 12}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({2, 12}, cursor) + -- coladd should be 0 + eq(0, exec_lua([[ + return vim.fn.winsaveview().coladd + ]])) + end) + + it('does not change cursor screen column when cursor is after eol and row got shorter', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position cursor on 't' in 'want' + curwin('set_cursor', {2, 34}) + -- turn on virtualedit + command('set virtualedit=all') + -- move cursor after eol + exec_lua([[ + vim.fn.winrestview({ coladd = 5 }) + ]]) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { + 'the line we do not want', + 'but hopefully', + }) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ + 'This should be the line we do not want', + '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')) + -- 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 + eq(13, exec_lua([[ + return vim.fn.winsaveview().coladd + ]])) + end) + + it('does not change cursor screen column when cursor is after eol and row got longer', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position cursor on 't' in 'first' + curwin('set_cursor', {1, 19}) + -- turn on virtualedit + command('set virtualedit=all') + -- move cursor after eol + exec_lua([[ + vim.fn.winrestview({ coladd = 21 }) + ]]) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { + 'the line we do not want', + 'but hopefully', + }) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ + 'This should be the line we do not want', + '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')) + -- 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 + eq(2, exec_lua([[ + return vim.fn.winsaveview().coladd + ]])) + end) + + it('does not change cursor screen column when cursor is after eol and row extended past cursor column', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position cursor on 't' in 'first' + curwin('set_cursor', {1, 19}) + -- turn on virtualedit + command('set virtualedit=all') + -- move cursor after eol just a bit + exec_lua([[ + vim.fn.winrestview({ coladd = 3 }) + ]]) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { + 'the line we do not want', + 'but hopefully', + }) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ + 'This should be the line we do not want', + 'but hopefully the last one', + }, get_lines(0, -1, true)) + -- cursor should stay at the same screen column + eq({1, 22}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 22}, cursor) + -- coladd should become 0 + eq(0, exec_lua([[ + return vim.fn.winsaveview().coladd + ]])) + end) + + it('does not change cursor screen column when cursor is after eol and row range decreased', function() + insert([[ + This should be first + then there is a line we do not want + and one more + and finally the last one]]) + + -- position cursor on 'e' in 'more' + curwin('set_cursor', {3, 11}) + -- turn on virtualedit + command('set virtualedit=all') + -- move cursor after eol + exec_lua([[ + vim.fn.winrestview({ coladd = 28 }) + ]]) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 15, 3, 11, { + 'the line we do not want', + 'but hopefully', + }) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ + 'This should be the line we do not want', + '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')) + -- 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 + eq(13, exec_lua([[ + return vim.fn.winsaveview().coladd + ]])) + end) + end) + end) + + describe('when cursor is at end_row and after end_col', function() + it('adjusts cursor column when only a newline is added or deleted', function() + insert([[ + first line + second + line]]) + + -- position the cursor on 'i' + curwin('set_cursor', {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')) + + -- 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')) + end) + + it('adjusts cursor column if the range is not bound to either start or end of a line', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 'h' in 'the' + curwin('set_cursor', {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')) + -- add deleted lines back + set_text(0, 14, 0, 14, { + ' first', + 'then there is a line we do not want', + 'and finally', + }) + eq({ + 'This should be first', + 'then there is a line we do not want', + 'and finally the last one', + }, get_lines(0, -1, true)) + -- cursor should return back to the original position + eq({3, 13}, curwin('get_cursor')) + end) + + it('adjusts cursor column if replacing lines in range, not just deleting and adding', function() + insert([[ + This should be first + then there is a line we do not want + and finally the last one]]) + + -- position the cursor on 's' in 'last' + curwin('set_cursor', {3, 18}) + set_text(0, 15, 2, 11, { + 'the line we do not want', + 'but hopefully', + }) + + eq({ + 'This should be the line we do not want', + 'but hopefully the last one', + }, get_lines(0, -1, true)) + -- cursor should stay on 's' + eq({2, 20}, curwin('get_cursor')) + + set_text(0, 15, 1, 13, { + 'first', + 'then there is a line we do not want', + 'and finally', + }) + + eq({ + 'This should be first', + 'then there is a line we do not want', + 'and finally the last one', + }, get_lines(0, -1, true)) + -- cursor should return back to the original position + eq({3, 18}, curwin('get_cursor')) + end) + + it('does not move cursor column after end of a line', function() + insert([[ + This should be the only line here + ]]) + + -- position cursor at the empty line + curwin('set_cursor', {2, 0}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 33, 1, 0, {'!'}) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ 'This should be the only line here!' }, get_lines(0, -1, true)) + -- cursor should end up on '!' + eq({1, 33}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 33}, cursor) + end) + + it('does not move cursor column before start of a line', function() + insert('\n') + + eq({ '', '' }, get_lines(0, -1, true)) + + -- position cursor on the last '1' + curwin('set_cursor', {2, 2}) + + local cursor = exec_lua([[ + vim.api.nvim_buf_set_text(0, 0, 0, 1, 0, {''}) + return vim.api.nvim_win_get_cursor(0) + ]]) + + eq({ '' }, get_lines(0, -1, true)) + -- cursor should end up on '!' + eq({1, 0}, curwin('get_cursor')) + -- immediate call to nvim_win_get_cursor should have returned the same position + eq({1, 0}, cursor) + end) + end) + it('can handle NULs', function() set_text(0, 0, 0, 0, {'ab\0cd'}) eq('ab\0cd', curbuf_depr('get_line', 0)) -- cgit From b04286a187d57c50f01cd36cd4668b7a69026579 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 22 Nov 2020 10:10:37 +0100 Subject: feat(extmark): support proper multiline ranges The removes the previous restriction that nvim_buf_set_extmark() could not be used to highlight arbitrary multi-line regions The problem can be summarized as follows: let's assume an extmark with a hl_group is placed covering the region (5,0) to (50,0) Now, consider what happens if nvim needs to redraw a window covering the lines 20-30. It needs to be able to ask the marktree what extmarks cover this region, even if they don't begin or end here. Therefore the marktree needs to be augmented with the information covers a point, not just what marks begin or end there. To do this, we augment each node with a field "intersect" which is a set the ids of the marks which overlap this node, but only if it is not part of the set of any parent. This ensures the number of nodes that need to be explicitly marked grows only logarithmically with the total number of explicitly nodes (and thus the number of of overlapping marks). Thus we can quickly iterate all marks which overlaps any query position by looking up what leaf node contains that position. Then we only need to consider all "start" marks within that leaf node, and the "intersect" set of that node and all its parents. Now, and the major source of complexity is that the tree restructuring operations (to ensure that each node has T-1 <= size <= 2*T-1) also need to update these sets. If a full inner node is split in two, one of the new parents might start to completely overlap some ranges and its ids will need to be moved from its children's sets to its own set. Similarly, if two undersized nodes gets joined into one, it might no longer completely overlap some ranges, and now the children which do needs to have the have the ids in its set instead. And then there are the pivots! Yes the pivot operations when a child gets moved from one parent to another. --- test/functional/api/extmark_spec.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 6d8e3d8e0a..a917432dab 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -753,7 +753,14 @@ describe('API/extmarks', function() }) end) - -- TODO(bfredl): add more tests! + it('can get overlapping extmarks', function() + set_extmark(ns, 1, 0, 0, {end_row = 5, end_col=0}) + set_extmark(ns, 2, 2, 5, {end_row = 2, end_col=30}) + set_extmark(ns, 3, 0, 5, {end_row = 2, end_col=10}) + set_extmark(ns, 4, 0, 0, {end_row = 1, end_col=0}) + eq({{ 2, 2, 5 }}, get_extmarks(ns, {2, 0}, {2, -1}, { overlap=false })) + eq({{ 1, 0, 0 }, { 3, 0, 5}, {2, 2, 5}}, get_extmarks(ns, {2, 0}, {2, -1}, { overlap=true })) + end) end) it('replace works', function() -- cgit From 585549625d8aef073e874d7cace9ab9df0d71847 Mon Sep 17 00:00:00 2001 From: L Lllvvuu Date: Fri, 15 Sep 2023 21:43:49 -0700 Subject: fix(marktree): off-by-one error in `marktree_move` If you would insert element X at position j, then if you are moving that same element X from position i < j, you should move it to position j - 1, because you are losing an element. This error caused a gap to be left in the array, so that it looked like [x, null, y] instead of [x, y], where len = 2. This triggered #25147. Fixes: #25147 --- test/functional/api/extmark_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index a917432dab..c4449bc201 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -208,6 +208,23 @@ describe('API/extmarks', function() eq({}, get_extmarks(ns2, {0, 0}, {-1, -1})) end) + it('can undo with extmarks (#25147)', function() + feed('itest') + set_extmark(ns, 1, 0, 0) + set_extmark(ns, 2, 1, 0) + 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) + 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) + end) + it('querying for information and ranges', function() --marks = {1, 2, 3} --positions = {{0, 0,}, {0, 2}, {0, 3}} -- cgit From 51836517738babaa406bc615fd9984129c5179a4 Mon Sep 17 00:00:00 2001 From: glepnir Date: Sat, 16 Sep 2023 19:08:40 +0800 Subject: fix(highlight): correct hi command output --- test/functional/api/highlight_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 492fd73223..5d6aaa57e6 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -608,4 +608,21 @@ describe('API: get highlight', function() meths.set_hl(0, 'Tried', { fg = "#00ff00", default = true }) eq({ fg = tonumber('00ff00', 16), default = true }, meths.get_hl(0, { name = 'Tried' })) end) + + it('should not output empty gui and cterm #23474', function() + meths.set_hl(0, 'Foo', {default = true}) + meths.set_hl(0, 'Bar', { default = true, fg = '#ffffff' }) + meths.set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = {bold = true} }) + meths.set_hl(0, 'FooBarA', { default = true, fg = '#ffffff', cterm = {bold = true,italic = true}}) + + eq('Foo xxx cleared', + exec_capture('highlight Foo')) + eq({default = true}, meths.get_hl(0, {name = 'Foo'})) + eq('Bar xxx guifg=#ffffff', + exec_capture('highlight Bar')) + eq('FooBar xxx cterm=bold guifg=#ffffff', + exec_capture('highlight FooBar')) + eq('FooBarA xxx cterm=bold,italic guifg=#ffffff', + exec_capture('highlight FooBarA')) + end) end) -- cgit From b7763d7f6b7fdcabe06658c664457df8bc147563 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 22 Sep 2023 17:56:05 +0800 Subject: fix(api): get virtual text with multiple hl properly (#25307) --- test/functional/api/extmark_spec.lua | 18 ++++++++++++------ test/functional/api/window_spec.lua | 22 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index c4449bc201..133ec67942 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1524,16 +1524,19 @@ describe('API/extmarks', function() sign_hl_group = "Statement", sign_text = ">>", spell = true, - virt_lines = { { { "lines", "Statement" } }}, + virt_lines = { + { { "lines", "Macro" }, { "???" } }, + { { "stack", { "Type", "Search" } }, { "!!!" } }, + }, virt_lines_above = true, virt_lines_leftcol = true, - virt_text = { { "text", "Statement" } }, + virt_text = { { "text", "Macro" }, { "???" }, { "stack", { "Type", "Search" } } }, virt_text_hide = true, virt_text_pos = "right_align", }) set_extmark(ns, marks[2], 0, 0, { priority = 0, - virt_text = { { "text", "Statement" } }, + virt_text = { { "", "Macro" }, { "", { "Type", "Search" } }, { "" } }, virt_text_win_col = 1, }) eq({0, 0, { @@ -1553,10 +1556,13 @@ describe('API/extmarks', function() sign_hl_group = "Statement", sign_text = ">>", spell = true, - virt_lines = { { { "lines", "Statement" } }}, + virt_lines = { + { { "lines", "Macro" }, { "???" } }, + { { "stack", { "Type", "Search" } }, { "!!!" } }, + }, virt_lines_above = true, virt_lines_leftcol = true, - virt_text = { { "text", "Statement" } }, + virt_text = { { "text", "Macro" }, { "???" }, { "stack", { "Type", "Search" } } }, virt_text_hide = true, virt_text_pos = "right_align", } }, get_extmark_by_id(ns, marks[1], { details = true })) @@ -1564,7 +1570,7 @@ describe('API/extmarks', function() ns_id = 1, right_gravity = true, priority = 0, - virt_text = { { "text", "Statement" } }, + virt_text = { { "", "Macro" }, { "", { "Type", "Search" } }, { "" } }, virt_text_hide = false, virt_text_pos = "win_col", virt_text_win_col = 1, diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 44d4470337..6737c2d15b 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -895,13 +895,14 @@ describe('API/win', function() it('includes border', function() local b = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' } local win = meths.open_win(0, true, { - relative='win', row=3, col=3, width=12, height=3, - border = b, + relative='win', row=3, col=3, width=12, height=3, + border = b, }) local cfg = meths.win_get_config(win) eq(b, cfg.border) end) + it('includes border with highlight group', function() local b = { {'a', 'Normal'}, @@ -914,12 +915,25 @@ describe('API/win', function() {'h', 'PreProc'}, } local win = meths.open_win(0, true, { - relative='win', row=3, col=3, width=12, height=3, - border = b, + relative='win', row=3, col=3, width=12, height=3, + border = b, }) local cfg = meths.win_get_config(win) eq(b, cfg.border) end) + + it('includes title and footer', function() + local title = { {'A', {'StatusLine', 'TabLine'}}, {'B'}, {'C', 'WinBar'} } + local footer = { {'A', 'WinBar'}, {'B'}, {'C', {'StatusLine', 'TabLine'}} } + local win = meths.open_win(0, true, { + relative='win', row=3, col=3, width=12, height=3, + border = 'single', title = title, footer = footer, + }) + + local cfg = meths.win_get_config(win) + eq(title, cfg.title) + eq(footer, cfg.footer) + end) end) end) -- cgit From 5331d5772ffbbdb3635d0a4b41306817097e86de Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 23 Sep 2023 15:59:37 +0800 Subject: fix(lua): show error message when failing to set variable (#25321) --- test/functional/api/vim_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index f734bfb0c0..fcf3eae5ec 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1353,6 +1353,9 @@ describe('API', function() -- Set readonly v: var. eq('Key is read-only: count', pcall_err(request, 'nvim_set_vvar', 'count', 42)) + -- Set non-existent v: var. + eq('Dictionary is locked', + pcall_err(request, 'nvim_set_vvar', 'nosuchvar', 42)) -- Set writable v: var. meths.set_vvar('errmsg', 'set by API') eq('set by API', meths.get_vvar('errmsg')) -- cgit From 4d3a38ac074fff7e2a4bede4cee7699bdd55ffdc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Sep 2023 10:57:09 +0800 Subject: fix(api, lua): handle setting v: variables properly (#25325) --- test/functional/api/vim_spec.lua | 58 +++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index fcf3eae5ec..d82e5f66c9 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1350,15 +1350,59 @@ describe('API', function() end) it('nvim_get_vvar, nvim_set_vvar', function() - -- Set readonly v: var. - eq('Key is read-only: count', - pcall_err(request, 'nvim_set_vvar', 'count', 42)) - -- Set non-existent v: var. - eq('Dictionary is locked', - pcall_err(request, 'nvim_set_vvar', 'nosuchvar', 42)) - -- Set writable v: var. + 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.set_vvar('errmsg', 'set by API') eq('set by API', meths.get_vvar('errmsg')) + meths.set_vvar('errmsg', 42) + eq('42', eval('v:errmsg')) + meths.set_vvar('oldfiles', { 'one', 'two' }) + eq({ 'one', 'two' }, eval('v:oldfiles')) + meths.set_vvar('oldfiles', {}) + eq({}, eval('v:oldfiles')) + eq('Setting v:oldfiles to value with wrong type', pcall_err(meths.set_vvar, 'oldfiles', 'a')) + eq({}, eval('v:oldfiles')) + + feed('i foo foo foo0/foo') + eq({1, 1}, meths.win_get_cursor(0)) + eq(1, eval('v:searchforward')) + feed('n') + eq({1, 5}, meths.win_get_cursor(0)) + meths.set_vvar('searchforward', 0) + eq(0, eval('v:searchforward')) + feed('n') + eq({1, 1}, meths.win_get_cursor(0)) + meths.set_vvar('searchforward', 1) + eq(1, eval('v:searchforward')) + feed('n') + eq({1, 5}, meths.win_get_cursor(0)) + + local screen = Screen.new(60, 3) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, + [1] = {background = Screen.colors.Yellow}, + }) + screen:attach() + eq(1, eval('v:hlsearch')) + screen:expect{grid=[[ + {1:foo} {1:^foo} {1:foo} | + {0:~ }| + | + ]]} + meths.set_vvar('hlsearch', 0) + eq(0, eval('v:hlsearch')) + screen:expect{grid=[[ + foo ^foo foo | + {0:~ }| + | + ]]} + meths.set_vvar('hlsearch', 1) + eq(1, eval('v:hlsearch')) + screen:expect{grid=[[ + {1:foo} {1:^foo} {1:foo} | + {0:~ }| + | + ]]} end) it('vim_set_var returns the old value', function() -- cgit From b3be7b741386bbbf076e87859cb1e3d990316f5c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 25 Sep 2023 11:06:15 +0800 Subject: fix(api): handle NUL in nvim_err_write() and nvim_out_write() (#25354) --- test/functional/api/vim_spec.lua | 50 +++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index d82e5f66c9..09495fbaac 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2053,6 +2053,19 @@ describe('API', function() end) describe('nvim_out_write', function() + local screen + + before_each(function() + screen = Screen.new(40, 8) + screen:attach() + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, + [1] = {bold = true, foreground = Screen.colors.SeaGreen}, + [2] = {bold = true, reverse = true}, + [3] = {foreground = Screen.colors.Blue}, + }) + end) + it('prints long messages correctly #20534', function() exec([[ set more @@ -2073,14 +2086,7 @@ describe('API', function() eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out')) end) - it('blank line in message works', function() - local screen = Screen.new(40, 8) - screen:attach() - screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, - [1] = {bold = true, foreground = Screen.colors.SeaGreen}, - [2] = {bold = true, reverse = true}, - }) + it('blank line in message', function() feed([[:call nvim_out_write("\na\n")]]) screen:expect{grid=[[ | @@ -2105,6 +2111,20 @@ describe('API', function() {1:Press ENTER or type command to continue}^ | ]]} end) + + it('NUL bytes in message', function() + feed([[:lua vim.api.nvim_out_write('aaa\0bbb\0\0ccc\nddd\0\0\0eee\n')]]) + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {2: }| + aaa{3:^@}bbb{3:^@^@}ccc | + ddd{3:^@^@^@}eee | + {1:Press ENTER or type command to continue}^ | + ]]} + end) end) describe('nvim_err_write', function() @@ -2193,6 +2213,20 @@ describe('API', function() ]]) feed('') -- exit the press ENTER screen end) + + it('NUL bytes in message', function() + nvim_async('err_write', 'aaa\0bbb\0\0ccc\nddd\0\0\0eee\n') + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {3: }| + {1:aaa^@bbb^@^@ccc} | + {1:ddd^@^@^@eee} | + {2:Press ENTER or type command to continue}^ | + ]]} + end) end) describe('nvim_err_writeln', function() -- cgit From f8ea49cfe1f4f3ed30da160d346553f0949ec1de Mon Sep 17 00:00:00 2001 From: glepnir Date: Mon, 18 Sep 2023 14:50:27 +0800 Subject: fix(highlight): add force in nvim_set_hl --- test/functional/api/highlight_spec.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 5d6aaa57e6..1a054741ef 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -625,4 +625,15 @@ describe('API: get highlight', function() eq('FooBarA xxx cterm=bold,italic guifg=#ffffff', exec_capture('highlight FooBarA')) end) + + it('can override exist highlight group by force #20323', function() + local white = tonumber('ffffff', 16) + local green = tonumber('00ff00', 16) + meths.set_hl(0, 'Foo', { fg=white }) + meths.set_hl(0, 'Foo', { fg=green, force = true }) + eq({ fg = green },meths.get_hl(0, {name = 'Foo'})) + meths.set_hl(0, 'Bar', {link = 'Comment', default = true}) + meths.set_hl(0, 'Bar', {link = 'Foo',default = true, force = true}) + eq({link ='Foo', default = true}, meths.get_hl(0, {name = 'Bar'})) + end) end) -- cgit From 2615ed879e66a3d05920c47177e77383adc7aca0 Mon Sep 17 00:00:00 2001 From: Daniel Steinberg Date: Tue, 18 Jul 2023 17:02:45 -0400 Subject: feat(ui): allow to get the highlight namespace --- test/functional/api/highlight_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 1a054741ef..7d7d07e30e 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -637,3 +637,19 @@ describe('API: get highlight', function() eq({link ='Foo', default = true}, meths.get_hl(0, {name = 'Bar'})) end) end) + +describe('API: set/get highlight namespace', function() + it('set/get highlight namespace', function() + eq(0, meths.get_hl_ns({})) + local ns = meths.create_namespace('') + meths.set_hl_ns(ns) + eq(ns, meths.get_hl_ns({})) + end) + + it('set/get window highlight namespace', function() + eq(-1, meths.get_hl_ns({winid = 0})) + local ns = meths.create_namespace('') + meths.win_set_hl_ns(0, ns) + eq(ns, meths.get_hl_ns({winid = 0})) + end) +end) -- cgit From b2a8a9314798e18c0685faf7463bda32f691d755 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 3 Oct 2023 20:54:42 +0800 Subject: fix(api): avoid immediate TextChanged with nvim_create_buf (#25492) --- test/functional/api/vim_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 09495fbaac..f28d6ea869 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2869,6 +2869,18 @@ describe('API', function() eq(false, eval('g:fired')) end) + it('TextChanged and TextChangedI do not trigger without changes', function() + local buf = meths.create_buf(true, false) + command([[let g:changed = '']]) + meths.create_autocmd({'TextChanged', 'TextChangedI'}, { + buffer = buf, + command = 'let g:changed ..= mode()', + }) + meths.set_current_buf(buf) + feed('i') + eq('', meths.get_var('changed')) + end) + it('scratch-buffer', function() eq({id=2}, meths.create_buf(false, true)) eq({id=3}, meths.create_buf(true, true)) -- cgit From 139e6f68f937b9efcadf2709ee1c83213d3266fa Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:50:44 +0200 Subject: fix(autocmd): API functions accept garbage after event name #25523 "VimEnter foo" was accepted as a valid event name for "VimEnter". Events delimited with commas, eg. "VimEnter,BufRead", were also accepted, even though only the first event was actually parsed. Co-authored-by: ii14 --- test/functional/api/autocmd_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index ba267e7539..bcae35d724 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -43,6 +43,11 @@ describe('autocmd api', function() group = 0, command = 'ls', })) + + eq("Invalid 'event': 'foo'", pcall_err(meths.create_autocmd, 'foo', { command = '' })) + eq("Invalid 'event': 'VimEnter '", pcall_err(meths.create_autocmd, 'VimEnter ', { command = '' })) + eq("Invalid 'event': 'VimEnter foo'", pcall_err(meths.create_autocmd, 'VimEnter foo', { command = '' })) + eq("Invalid 'event': 'BufAdd,BufDelete'", pcall_err(meths.create_autocmd, 'BufAdd,BufDelete', { command = '' })) end) it('doesnt leak when you use ++once', function() -- cgit From 6c87d3e0fbf88ae693be11a3ede3a1ec6ec0e30e Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Thu, 19 Oct 2023 20:09:02 +0600 Subject: refactor(options): `get_option_value_strict()` and `SREQ_*` `SREQ_*` values are now actual typedef'd enums. `get_option_value_strict()` has also been refactored and split into two functions, `get_option_attrs()` for getting the option attributes, and `get_option_value_strict()` for getting the actual value. Moreover, it now returns an `OptVal`. Other miscellaneous refactors have also been made. --- test/functional/api/vim_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index f28d6ea869..4e259befa8 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1493,7 +1493,7 @@ describe('API', function() pcall_err(nvim, 'set_option_value', 'scrolloff', 1, {scope = 'bogus'})) eq("Invalid 'scope': expected String, got Integer", pcall_err(nvim, 'get_option_value', 'scrolloff', {scope = 42})) - eq("Invalid 'value': expected Integer/Boolean/String, got Array", + eq("Invalid 'value': expected valid option type, got Array", pcall_err(nvim, 'set_option_value', 'scrolloff', {}, {})) eq("Invalid value for option 'scrolloff': expected Number, got Boolean true", pcall_err(nvim, 'set_option_value', 'scrolloff', true, {})) -- cgit From 43a7945f1b483d121e76ea7495d1dabc773935ea Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sat, 28 Oct 2023 22:51:07 +0600 Subject: test: add test coverage for #25741 --- test/functional/api/vim_spec.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 4e259befa8..2849fcc6af 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1477,14 +1477,6 @@ describe('API', function() nvim('set_option_value', 'debug', 'beep', {}) eq(true, nvim('get_option_info2', 'debug', {}).was_set) 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', {})) - end) it('validation', function() eq("Invalid 'scope': expected 'local' or 'global'", @@ -1616,6 +1608,15 @@ describe('API', function() pcall_err(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)) + insert([[ + foo + bar + baz + ]]) + eq(false, nvim('get_option_value', 'modified', {})) + end) end) describe('nvim_{get,set}_current_buf, nvim_list_bufs', function() -- cgit From 0da27e9bdec14acf82731c4d5e0ad7d673697af7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 29 Oct 2023 15:44:52 +0800 Subject: fix(api): load buffer first on nvim_buf_set_lines (#25823) Fix #22670 Fix #8659 --- test/functional/api/buffer_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 9833ebee4c..6ed9aa574a 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -713,6 +713,21 @@ describe('api/buf', function() feed('p') eq(3, funcs.winnr()) end) + + it('set_lines on unloaded buffer #8659 #22670', function() + local bufnr = curbuf('get_number') + meths.buf_set_lines(bufnr, 0, -1, false, {'a', 'b', 'c'}) + meths.buf_set_name(bufnr, 'set_lines') + finally(function() + os.remove('set_lines') + end) + command('write!') + command('new') + command('bunload! '..bufnr) + local new_bufnr = funcs.bufnr('set_lines', true) + meths.buf_set_lines(new_bufnr, 0, -1, false, {}) + eq({''}, meths.buf_get_lines(new_bufnr, 0, -1, false)) + end) end) describe('nvim_buf_set_text', function() -- cgit From 2dc9ceb99c018b15dcf0c443cad46efecccaf94e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:02:32 +0100 Subject: docs: small fixes (#25585) Co-authored-by: tmummert Co-authored-by: parikshit adhikari --- test/functional/api/autocmd_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index bcae35d724..fd46a1dcfa 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -1333,7 +1333,7 @@ describe('autocmd api', function() local without_group = meths.get_autocmds(search) eq(2, #without_group) - -- Doest clear with passing group. + -- Doesn't clear with passing group. meths.clear_autocmds { buffer = 0, group = search.group } local with_group = meths.get_autocmds(search) eq(1, #with_group) -- cgit From e19cc9c9b715d8171f7940632b8855104b5290b6 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sat, 14 Oct 2023 22:19:11 +0600 Subject: refactor(options)!: unify `set_option` and `set_string_option` While the interfaces for setting number and boolean options are now unified by #25394, there is still a separate `set_string_option` function that is used for setting a string option. This PR removes that function and merges it with set_option. BREAKING CHANGE: `v:option_old` is now the old global value for all global-local options, instead of just string global-local options. Local value for a global-local number/boolean option is now unset when the option is set (e.g. using `:set` or `nvim_set_option_value`) without a scope, which means they now behave the same way as string options. Ref: #25672 --- test/functional/api/vim_spec.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 2849fcc6af..c346dfbe6c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1536,14 +1536,18 @@ describe('API', function() -- Now try with options with a special "local is unset" value (e.g. 'undolevels') nvim('set_option_value', 'undolevels', 1000, {}) - eq(1000, nvim('get_option_value', 'undolevels', {scope = 'local'})) + 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', {})) nvim('set_option_value', 'autoread', true, {}) - eq(true, nvim('get_option_value', 'autoread', {scope = 'local'})) + 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', {})) end) it('set window options', function() -- cgit From d7359a87425dc38efda4f74bd580bae9946abe31 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 1 Nov 2023 12:16:37 +0800 Subject: fix(startup): trigger UIEnter for the correct channel (#25860) --- test/functional/api/ui_spec.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua index 2cadfe117f..a668d47448 100644 --- a/test/functional/api/ui_spec.lua +++ b/test/functional/api/ui_spec.lua @@ -60,14 +60,13 @@ describe('nvim_ui_attach()', function() end) it('autocmds UIEnter/UILeave', function() - clear{ - args_rm={'--headless'}, - args={ - '--cmd', 'let g:evs = []', - '--cmd', 'autocmd UIEnter * :call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event)', - '--cmd', 'autocmd UILeave * :call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event)', - '--cmd', 'autocmd VimEnter * :call add(g:evs, "VimEnter")', - }} + clear{args_rm={'--headless'}} + exec([[ + let g:evs = [] + autocmd UIEnter * call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event) + autocmd UILeave * call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event) + autocmd VimEnter * call add(g:evs, "VimEnter") + ]]) local screen = Screen.new() screen:attach() eq({chan=1}, eval('g:uienter_ev')) -- cgit From 4e6f559b8c5f77924fdbe2e5abd9c6aa8efad13f Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Tue, 24 Oct 2023 13:32:00 +0200 Subject: feat(extmarks): add 'invalidate' property to extmarks Problem: No way to have extmarks automatically removed when the range it is attached to is deleted. Solution: Add new 'invalidate' property that will hide a mark when the entirety of its range is deleted. When "undo_restore" is set to false, delete the mark from the buffer instead. --- test/functional/api/extmark_spec.lua | 60 +++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 133ec67942..6e00be611d 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1599,12 +1599,70 @@ describe('API/extmarks', function() set_extmark(ns, 3, 0, 0, { sign_text = '>>' }) set_extmark(ns, 4, 0, 0, { virt_text = {{'text', 'Normal'}}}) set_extmark(ns, 5, 0, 0, { virt_lines = {{{ 'line', 'Normal' }}}}) - eq(5, #get_extmarks(-1, 0, -1, { details = true })) + eq(5, #get_extmarks(-1, 0, -1, {})) eq({{ 2, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'highlight' })) eq({{ 3, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'sign' })) eq({{ 4, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'virt_text' })) eq({{ 5, 0, 0 }}, get_extmarks(-1, 0, -1, { type = 'virt_lines' })) end) + + it("invalidated marks are deleted", function() + screen = Screen.new(40, 6) + screen:attach() + feed('dd6iaaa bbb cccgg') + set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1' }) + set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2' }) + -- mark with invalidate is removed + command('d') + screen:expect([[ + S2^aaa bbb ccc | + aaa bbb ccc | + aaa bbb ccc | + aaa bbb ccc | + aaa bbb ccc | + | + ]]) + -- mark is restored with undo_restore == true + command('silent undo') + screen:expect([[ + S1^aaa bbb ccc | + S2aaa bbb ccc | + aaa bbb ccc | + aaa bbb ccc | + aaa bbb ccc | + | + ]]) + -- mark is deleted with undo_restore == false + set_extmark(ns, 1, 0, 0, { invalidate = true, undo_restore = false, sign_text = 'S1' }) + set_extmark(ns, 2, 1, 0, { invalidate = true, undo_restore = false, sign_text = 'S2' }) + command('1d 2') + eq(0, #get_extmarks(-1, 0, -1, {})) + -- mark is not removed when deleting bytes before the range + set_extmark(ns, 3, 0, 4, { invalidate = true, undo_restore = false, + hl_group = 'Error', end_col = 7 }) + feed('dw') + eq(3, get_extmark_by_id(ns, 3, { details = true })[3].end_col) + -- mark is not removed when deleting bytes at the start of the range + feed('x') + eq(2, get_extmark_by_id(ns, 3, { details = true })[3].end_col) + -- mark is not removed when deleting bytes from the end of the range + feed('lx') + eq(1, get_extmark_by_id(ns, 3, { details = true})[3].end_col) + -- mark is not removed when deleting bytes beyond end of the range + feed('x') + eq(1, get_extmark_by_id(ns, 3, { details = true})[3].end_col) + -- mark is removed when all bytes in the range are deleted + feed('hx') + eq({}, get_extmark_by_id(ns, 3, {})) + -- multiline mark is not removed when start of its range is deleted + set_extmark(ns, 4, 1, 4, { undo_restore = false, invalidate = true, + hl_group = 'Error', end_col = 7, end_row = 3 }) + feed('ddDdd') + eq({0, 0}, get_extmark_by_id(ns, 4, {})) + -- multiline mark is removed when entirety of its range is deleted + feed('vj2ed') + eq({}, get_extmark_by_id(ns, 4, {})) + end) end) describe('Extmarks buffer api with many marks', function() -- cgit From 43b0e2752c06ec5460a417fb9a8c60856011f563 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 12:28:43 +0800 Subject: refactor(api): simplify nvim_set_keymap shortname check (#25945) --- test/functional/api/keymap_spec.lua | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 953402ada3..811c4210fa 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -488,18 +488,22 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it('throws errors when given too-long mode shortnames', function() - eq('Shortname is too long: map', - pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {})) - - eq('Shortname is too long: vmap', - pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {})) - - eq('Shortname is too long: xnoremap', - pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {})) - - eq('Shortname is too long: map', pcall_err(meths.del_keymap, 'map', 'lhs')) - eq('Shortname is too long: vmap', pcall_err(meths.del_keymap, 'vmap', 'lhs')) - eq('Shortname is too long: xnoremap', pcall_err(meths.del_keymap, 'xnoremap', 'lhs')) + eq('Invalid mode shortname: "a"', pcall_err(meths.set_keymap, 'a', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "oa"', pcall_err(meths.set_keymap, 'oa', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "!o"', pcall_err(meths.set_keymap, '!o', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "!i"', pcall_err(meths.set_keymap, '!i', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "!!"', pcall_err(meths.set_keymap, '!!', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "map"', pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "vmap"', pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "a"', pcall_err(meths.del_keymap, 'a', 'lhs')) + eq('Invalid mode shortname: "oa"', pcall_err(meths.del_keymap, 'oa', 'lhs')) + eq('Invalid mode shortname: "!o"', pcall_err(meths.del_keymap, '!o', 'lhs')) + eq('Invalid mode shortname: "!i"', pcall_err(meths.del_keymap, '!i', 'lhs')) + eq('Invalid mode shortname: "!!"', pcall_err(meths.del_keymap, '!!', 'lhs')) + eq('Invalid mode shortname: "map"', pcall_err(meths.del_keymap, 'map', 'lhs')) + eq('Invalid mode shortname: "vmap"', pcall_err(meths.del_keymap, 'vmap', 'lhs')) + eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.del_keymap, 'xnoremap', 'lhs')) end) it('error on invalid mode shortname', function() -- cgit From a4b80c71eae09a5f6f76bce46be46efd247c7223 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 15:17:53 +0800 Subject: vim-patch:8.2.4140: maparg() does not indicate the type of script Problem: maparg() does not indicate the type of script where it was defined. Solution: Add "scriptversion". https://github.com/vim/vim/commit/a9528b39a666dbaa026320f73bae4b1628a7fe51 Co-authored-by: Bram Moolenaar --- test/functional/api/keymap_spec.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 811c4210fa..8cb97e5ef0 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -32,6 +32,7 @@ describe('nvim_get_keymap', function() rhs='bar', expr=0, sid=0, + scriptversion=1, buffer=0, nowait=0, mode='n', @@ -258,6 +259,7 @@ describe('nvim_get_keymap', function() silent=0, expr=0, sid=0, + scriptversion=1, buffer=0, nowait=0, noremap=1, @@ -327,6 +329,7 @@ describe('nvim_get_keymap', function() silent=0, expr=0, sid=0, + scriptversion=1, buffer=0, nowait=0, noremap=1, @@ -365,6 +368,7 @@ describe('nvim_get_keymap', function() silent=0, expr=0, sid=sid_lua, + scriptversion=1, buffer=0, nowait=0, mode='n', @@ -373,7 +377,7 @@ describe('nvim_get_keymap', function() }, mapargs[1]) end) - it ('can handle map descriptions', function() + it('can handle map descriptions', function() meths.set_keymap('n', 'lhs', 'rhs', {desc="map description"}) eq({ lhs='lhs', @@ -383,6 +387,7 @@ describe('nvim_get_keymap', function() silent=0, expr=0, sid=sid_api_client, + scriptversion=1, buffer=0, nowait=0, mode='n', @@ -429,6 +434,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() to_return.nowait = not opts.nowait and 0 or 1 to_return.expr = not opts.expr and 0 or 1 to_return.sid = not opts.sid and sid_api_client or opts.sid + to_return.scriptversion = 1 to_return.buffer = not opts.buffer and 0 or opts.buffer to_return.lnum = not opts.lnum and 0 or opts.lnum to_return.desc = opts.desc -- cgit From f748a73a357710db6094d4a428cd056f5df226a9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 19:48:50 +0800 Subject: vim-patch:8.2.4861: it is not easy to restore saved mappings Problem: It is not easy to restore saved mappings. Solution: Make mapset() accept a dict argument. (Ernie Rael, closes vim/vim#10295) https://github.com/vim/vim/commit/51d04d16f21e19d6eded98f9530d84089102f925 Co-authored-by: Ernie Rael --- test/functional/api/keymap_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 8cb97e5ef0..f105a31ed9 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -36,6 +36,7 @@ describe('nvim_get_keymap', function() buffer=0, nowait=0, mode='n', + abbr=0, noremap=1, lnum=0, } @@ -262,6 +263,7 @@ describe('nvim_get_keymap', function() scriptversion=1, buffer=0, nowait=0, + abbr=0, noremap=1, lnum=0, } @@ -325,6 +327,7 @@ describe('nvim_get_keymap', function() lhsraw='| |', rhs='| |', mode='n', + abbr=0, script=0, silent=0, expr=0, @@ -372,6 +375,7 @@ describe('nvim_get_keymap', function() buffer=0, nowait=0, mode='n', + abbr=0, noremap=0, lnum=0, }, mapargs[1]) @@ -391,6 +395,7 @@ describe('nvim_get_keymap', function() buffer=0, nowait=0, mode='n', + abbr=0, noremap=0, lnum=0, desc='map description' @@ -426,6 +431,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() local to_return = {} to_return.mode = normalize_mapmode(mode, true) + to_return.abbr = mode:sub(-1) == 'a' and 1 or 0 to_return.noremap = not opts.noremap and 0 or 1 to_return.lhs = lhs to_return.rhs = rhs -- cgit From 04d299c17014b0802c79613252e4de26da84a7c9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 20:42:55 +0800 Subject: vim-patch:8.2.4932: not easy to filter the output of maplist() Problem: Not easy to filter the output of maplist(). Solution: Add mode_bits to the dictionary. (Ernie Rael, closes vim/vim#10356) https://github.com/vim/vim/commit/d8f5f766219273a8579947cc80b92580b6988a4b Co-authored-by: Ernie Rael --- test/functional/api/keymap_spec.lua | 58 +++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index f105a31ed9..3af1faaece 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -19,6 +19,20 @@ local sleep = helpers.sleep local sid_api_client = -9 local sid_lua = -8 +local mode_bits_map = { + ['n'] = 0x01, + ['x'] = 0x02, + ['o'] = 0x04, + ['c'] = 0x08, + ['i'] = 0x10, + ['l'] = 0x20, + ['s'] = 0x40, + ['t'] = 0x80, + [' '] = 0x47, + ['v'] = 0x42, + ['!'] = 0x18, +} + describe('nvim_get_keymap', function() before_each(clear) @@ -36,6 +50,7 @@ describe('nvim_get_keymap', function() buffer=0, nowait=0, mode='n', + mode_bits=0x01, abbr=0, noremap=1, lnum=0, @@ -83,6 +98,7 @@ describe('nvim_get_keymap', function() -- The table will be the same except for the mode local insert_table = shallowcopy(foo_bar_map_table) insert_table['mode'] = 'i' + insert_table['mode_bits'] = 0x10 eq({insert_table}, meths.get_keymap('i')) end) @@ -272,6 +288,7 @@ describe('nvim_get_keymap', function() ret.lhs = lhs ret.rhs = rhs ret.mode = mode + ret.mode_bits = mode_bits_map[mode] return ret end @@ -327,6 +344,7 @@ describe('nvim_get_keymap', function() lhsraw='| |', rhs='| |', mode='n', + mode_bits=0x01, abbr=0, script=0, silent=0, @@ -375,6 +393,7 @@ describe('nvim_get_keymap', function() buffer=0, nowait=0, mode='n', + mode_bits=0x01, abbr=0, noremap=0, lnum=0, @@ -395,6 +414,7 @@ describe('nvim_get_keymap', function() buffer=0, nowait=0, mode='n', + mode_bits=0x01, abbr=0, noremap=0, lnum=0, @@ -430,7 +450,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end local to_return = {} - to_return.mode = normalize_mapmode(mode, true) + local expected_mode = normalize_mapmode(mode, true) + to_return.mode = expected_mode + to_return.mode_bits = mode_bits_map[expected_mode] to_return.abbr = mode:sub(-1) == 'a' and 1 or 0 to_return.noremap = not opts.noremap and 0 or 1 to_return.lhs = lhs @@ -499,7 +521,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function() get_mapargs('', 'lhs')) end) - it('throws errors when given too-long mode shortnames', function() + it('error on invalid mode shortname', function() + eq('Invalid mode shortname: " "', pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "m"', pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "?"', pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "y"', pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "p"', pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "a"', pcall_err(meths.set_keymap, 'a', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "oa"', pcall_err(meths.set_keymap, 'oa', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "!o"', pcall_err(meths.set_keymap, '!o', 'lhs', 'rhs', {})) @@ -508,6 +535,11 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('Invalid mode shortname: "map"', pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "vmap"', pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: " "', pcall_err(meths.del_keymap, ' ', 'lhs')) + eq('Invalid mode shortname: "m"', pcall_err(meths.del_keymap, 'm', 'lhs')) + eq('Invalid mode shortname: "?"', pcall_err(meths.del_keymap, '?', 'lhs')) + eq('Invalid mode shortname: "y"', pcall_err(meths.del_keymap, 'y', 'lhs')) + eq('Invalid mode shortname: "p"', pcall_err(meths.del_keymap, 'p', 'lhs')) eq('Invalid mode shortname: "a"', pcall_err(meths.del_keymap, 'a', 'lhs')) eq('Invalid mode shortname: "oa"', pcall_err(meths.del_keymap, 'oa', 'lhs')) eq('Invalid mode shortname: "!o"', pcall_err(meths.del_keymap, '!o', 'lhs')) @@ -518,22 +550,6 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.del_keymap, 'xnoremap', 'lhs')) end) - it('error on invalid mode shortname', function() - eq('Invalid mode shortname: " "', - pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "m"', - pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "?"', - pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "y"', - pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "p"', - pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "?"', pcall_err(meths.del_keymap, '?', 'lhs')) - eq('Invalid mode shortname: "y"', pcall_err(meths.del_keymap, 'y', 'lhs')) - eq('Invalid mode shortname: "p"', pcall_err(meths.del_keymap, 'p', 'lhs')) - end) - it('error on invalid optnames', function() eq("Invalid key: 'silentt'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', {silentt = true})) @@ -839,7 +855,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq(1, exec_lua[[return GlobalCount]]) end) - it (':map command shows lua mapping correctly', function() + it(':map command shows lua mapping correctly', function() exec_lua [[ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] @@ -851,7 +867,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() ) end) - it ('mapcheck() returns lua mapping correctly', function() + it('mapcheck() returns lua mapping correctly', function() exec_lua [[ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] @@ -859,7 +875,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() "^")) end) - it ('maparg() returns lua mapping correctly', function() + it('maparg() returns lua mapping correctly', function() eq(0, exec_lua([[ GlobalCount = 0 vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) -- cgit From e9b9a86cd5a555943b87f0ba40c4527561c3c124 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Nov 2023 10:21:14 +0800 Subject: fix(context): don't crash on invalid arg to nvim_get_context (#25977) Note: The crash happens in the second test case when using uninitialized memory, and therefore doesn't happen with ASAN. --- test/functional/api/vim_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c346dfbe6c..bc7e747916 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1979,6 +1979,13 @@ describe('API', function() 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 = { {} } })) + eq("Empty dictionary keys aren't allowed", + pcall_err(nvim, 'load_context', { regs = { { [''] = '' } } })) + end) end) describe('nvim_replace_termcodes', function() -- cgit From fdaf6bc5573f578d100321dfc084d513884fd73a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Nov 2023 13:10:26 +0800 Subject: fix(context): don't leak memory on multiple invalid objects (#25979) --- test/functional/api/vim_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index bc7e747916..8bbadda9b0 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1982,7 +1982,7 @@ describe('API', function() it('errors when context dictionary is invalid', function() eq('E474: Failed to convert list to msgpack string buffer', - pcall_err(nvim, 'load_context', { regs = { {} } })) + pcall_err(nvim, 'load_context', { regs = { {} }, jumps = { {} } })) eq("Empty dictionary keys aren't allowed", pcall_err(nvim, 'load_context', { regs = { { [''] = '' } } })) end) -- cgit From 8d9789a0f3b748b75ac4ae1b8e43d27af40d49fe Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 7 Nov 2023 11:31:21 -0600 Subject: docs: deprecate the "term_background" UI field --- test/functional/api/ui_spec.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua index a668d47448..6efb6726fe 100644 --- a/test/functional/api/ui_spec.lua +++ b/test/functional/api/ui_spec.lua @@ -36,8 +36,6 @@ describe('nvim_ui_attach()', function() pcall_err(meths.ui_attach, 80, 24, { term_name=true })) eq("Invalid 'term_colors': expected Integer, got Boolean", pcall_err(meths.ui_attach, 80, 24, { term_colors=true })) - eq("Invalid 'term_background': expected String, got Boolean", - pcall_err(meths.ui_attach, 80, 24, { term_background=true })) eq("Invalid 'stdin_fd': expected Integer, got String", pcall_err(meths.ui_attach, 80, 24, { stdin_fd='foo' })) eq("Invalid 'stdin_tty': expected Boolean, got String", -- cgit From 0b38fe4dbb77c15ae6f5779174855acab25fc86c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 8 Mar 2023 15:18:02 +0100 Subject: refactor(decorations): break up Decoration struct into smaller pieces Remove the monolithic Decoration struct. Before this change, each extmark could either represent just a hl_id + priority value as a inline decoration, or it would take a pointer to this monolitic 112 byte struct which has to be allocated. This change separates the decorations into two pieces: DecorSignHighlight for signs, highlights and simple set-flag decorations (like spell, ui-watched), and DecorVirtText for virtual text and lines. The main separation here is whether they are expected to allocate more memory. Currently this is not really true as sign text has to be an allocated string, but the plan is to get rid of this eventually (it can just be an array of two schar_T:s). Further refactors are expected to improve the representation of each decoration kind individually. The goal of this particular PR is to get things started by cutting the Gordian knot which was the monolithic struct Decoration. Now, each extmark can either contain chained indicies/pointers to these kinds of objects, or it can fit a subset of DecorSignHighlight inline. The point of this change is not only to make decorations smaller in memory. In fact, the main motivation is to later allow them to grow _larger_, but on a dynamic, on demand fashion. As a simple example, it would be possible to augment highlights to take a list of multiple `hl_group`:s, which then would trivially map to a chain of multiple DecorSignHighlight entries. One small feature improvement included with this refactor itself, is that the restriction that extmarks cannot be removed inside a decoration provider has been lifted. These are instead safely lifetime extended on a "to free" list until the current iteration of screen drawing is done. NB: flags is a mess. but DecorLevel is useless, this slightly less so --- test/functional/api/extmark_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 6e00be611d..2115c7c244 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1579,6 +1579,7 @@ describe('API/extmarks', function() eq({0, 0, { ns_id = 1, cursorline_hl_group = "Statement", + priority = 4096, right_gravity = true, } }, get_extmark_by_id(ns, marks[3], { details = true })) end) -- cgit From c249058758af6919f718750b2f4acb96bafeb2dd Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sat, 18 Nov 2023 23:49:11 +0100 Subject: feat(extmarks): add sign name to extmark "details" array Problem: Unable to identify legacy signs when fetching extmarks with `nvim_buf_get_extmarks()`. Solution: Add "sign_name" to the extmark detail array. Add some misc. changes as follow-up to #25724 --- test/functional/api/extmark_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 2115c7c244..44a151cf6a 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1582,6 +1582,23 @@ describe('API/extmarks', function() priority = 4096, right_gravity = true, } }, get_extmark_by_id(ns, marks[3], { details = true })) + curbufmeths.clear_namespace(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') + eq({ {1, 0, 0, { + cursorline_hl_group = 'CursorLine', + invalidate = true, + line_hl_group = 'LineNr', + ns_id = 0, + number_hl_group = 'Normal', + priority = 10, + right_gravity = true, + sign_hl_group = 'Title', + sign_name = 'sign1', + sign_text = 's1', + undo_restore = false + } } }, get_extmarks(-1, 0, -1, { details = true })) end) it('can get marks from anonymous namespaces', function() -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- test/functional/api/keymap_spec.lua | 2 +- test/functional/api/server_requests_spec.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 3af1faaece..434f117956 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -487,7 +487,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it('error if LHS longer than MAXMAPLEN', function() - -- assume MAXMAPLEN of 50 chars, as declared in vim.h + -- assume MAXMAPLEN of 50 chars, as declared in mapping_defs.h local MAXMAPLEN = 50 local lhs = '' for i=1,MAXMAPLEN do diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index cb273aedba..1ad4ad3a02 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -199,7 +199,7 @@ describe('server -> client', function() it('can communicate buffers, tabpages, and windows', function() eq({1}, eval("rpcrequest(vim, 'nvim_list_tabpages')")) - -- Window IDs start at 1000 (LOWEST_WIN_ID in vim.h) + -- Window IDs start at 1000 (LOWEST_WIN_ID in window.h) eq({1000}, eval("rpcrequest(vim, 'nvim_list_wins')")) local buf = eval("rpcrequest(vim, 'nvim_list_bufs')")[1] -- cgit