diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2025-02-05 23:09:29 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2025-02-05 23:09:29 +0000 |
commit | d5f194ce780c95821a855aca3c19426576d28ae0 (patch) | |
tree | d45f461b19f9118ad2bb1f440a7a08973ad18832 /test/functional/api | |
parent | c5d770d311841ea5230426cc4c868e8db27300a8 (diff) | |
parent | 44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff) | |
download | rneovim-rahm.tar.gz rneovim-rahm.tar.bz2 rneovim-rahm.zip |
Diffstat (limited to 'test/functional/api')
-rw-r--r-- | test/functional/api/autocmd_spec.lua | 133 | ||||
-rw-r--r-- | test/functional/api/buffer_updates_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/api/command_spec.lua | 9 | ||||
-rw-r--r-- | test/functional/api/deprecated_spec.lua | 21 | ||||
-rw-r--r-- | test/functional/api/extmark_spec.lua | 20 | ||||
-rw-r--r-- | test/functional/api/highlight_spec.lua | 23 | ||||
-rw-r--r-- | test/functional/api/server_requests_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/api/version_spec.lua | 18 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 160 | ||||
-rw-r--r-- | test/functional/api/window_spec.lua | 62 |
10 files changed, 389 insertions, 76 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 3f9883f43f..64b28e7bf7 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -273,54 +273,72 @@ describe('autocmd api', function() eq({}, api.nvim_get_autocmds({ event = 'User', pattern = 'Test' })) end) - it('receives an args table', function() + local function test_autocmd_args(event) + local function get_amatch(pat) + return event == 'User' and pat or vim.fs.normalize(n.fn.fnamemodify(pat, ':p')) + end + local group_id = api.nvim_create_augroup('TestGroup', {}) -- Having an existing autocmd calling expand("<afile>") shouldn't change args #18964 - api.nvim_create_autocmd('User', { + api.nvim_create_autocmd(event, { group = 'TestGroup', pattern = 'Te*', command = 'call expand("<afile>")', }) - local autocmd_id = exec_lua [[ - return vim.api.nvim_create_autocmd("User", { + local autocmd_id = exec_lua(([[ + return vim.api.nvim_create_autocmd(%q, { group = "TestGroup", pattern = "Te*", callback = function(args) vim.g.autocmd_args = args end, }) - ]] + ]]):format(event)) - api.nvim_exec_autocmds('User', { pattern = 'Test pattern' }) + local exec_pat = 'Test pattern' + local amatch = get_amatch(exec_pat) + api.nvim_exec_autocmds(event, { pattern = exec_pat }) eq({ id = autocmd_id, group = group_id, - event = 'User', - match = 'Test pattern', - file = 'Test pattern', + event = event, + match = amatch, + file = exec_pat, buf = 1, }, api.nvim_get_var('autocmd_args')) -- Test without a group - autocmd_id = exec_lua [[ - return vim.api.nvim_create_autocmd("User", { + autocmd_id = exec_lua(([[ + return vim.api.nvim_create_autocmd(%q, { pattern = "*", callback = function(args) vim.g.autocmd_args = args end, }) - ]] + ]]):format(event)) - api.nvim_exec_autocmds('User', { pattern = 'some_pat' }) + exec_pat = 'some_pat' + amatch = get_amatch(exec_pat) + api.nvim_exec_autocmds(event, { pattern = exec_pat }) eq({ id = autocmd_id, group = nil, - event = 'User', - match = 'some_pat', - file = 'some_pat', + event = event, + match = amatch, + file = exec_pat, buf = 1, }, api.nvim_get_var('autocmd_args')) + end + + describe('receives correct args table', function() + it('for event that takes non-file pattern', function() + test_autocmd_args('User') + end) + + it('for event that takes file pattern', function() + test_autocmd_args('BufEnter') + end) end) it('can receive arbitrary data', function() @@ -881,6 +899,89 @@ describe('autocmd api', function() eq([[:echo "Buffer"]], normalized_aus[1].command) end) end) + + describe('id', function() + it('gets events by ID', function() + local id = api.nvim_create_autocmd('BufEnter', { + command = 'echo "hello"', + }) + eq({ + { + buflocal = false, + command = 'echo "hello"', + event = 'BufEnter', + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id })) + end) + + it('gets events by ID by other filters', function() + local group_name = 'NVIM_GET_AUTOCMDS_ID' + local group = api.nvim_create_augroup(group_name, { clear = true }) + local id = api.nvim_create_autocmd('BufEnter', { + command = 'set number', + group = group, + }) + api.nvim_create_autocmd('WinEnter', { + group = group, + command = 'set cot&', + }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'BufEnter', + group = group, + group_name = group_name, + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id, group = group })) + end) + + it('gets events by ID and a specific event', function() + local id = api.nvim_create_autocmd('InsertEnter', { command = 'set number' }) + api.nvim_create_autocmd('InsertEnter', { command = 'set wrap' }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'InsertEnter', + id = id, + once = false, + pattern = '*', + }, + }, api.nvim_get_autocmds({ id = id, event = 'InsertEnter' })) + end) + + it('gets events by ID and a specific pattern', function() + local id = api.nvim_create_autocmd('InsertEnter', { + pattern = '*.c', + command = 'set number', + }) + api.nvim_create_autocmd('InsertEnter', { + pattern = '*.c', + command = 'set wrap', + }) + eq({ + { + buflocal = false, + command = 'set number', + event = 'InsertEnter', + id = id, + once = false, + pattern = '*.c', + }, + }, api.nvim_get_autocmds({ id = id, pattern = '*.c' })) + end) + + it('empty result when id does not found', function() + eq({}, api.nvim_get_autocmds({ id = 255 })) + end) + end) end) describe('nvim_exec_autocmds', function() diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 527394bfd1..489f601d31 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -879,7 +879,8 @@ describe('API: buffer events:', function() it('when :terminal lines change', function() local buffer_lines = {} local expected_lines = {} - fn.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, { + fn.jobstart({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index a16c6a88e3..fabd9be6d6 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -651,6 +651,11 @@ describe('nvim_create_user_command', function() api.nvim_set_current_buf(bufnr) command('Hello') assert_alive() + eq( + 'Invalid buffer id: 1234', + pcall_err(api.nvim_buf_create_user_command, 1234, 'Hello', '', {}) + ) + assert_alive() end) it('can use a Lua complete function', function() @@ -771,5 +776,9 @@ describe('nvim_del_user_command', function() command('Hello') api.nvim_buf_del_user_command(0, 'Hello') matches('Not an editor command: Hello', pcall_err(command, 'Hello')) + eq('Invalid command (not found): Hello', pcall_err(api.nvim_buf_del_user_command, 0, 'Hello')) + eq('Invalid command (not found): Bye', pcall_err(api.nvim_buf_del_user_command, 0, 'Bye')) + eq('Invalid buffer id: 1234', pcall_err(api.nvim_buf_del_user_command, 1234, 'Hello')) + assert_alive() end) end) diff --git a/test/functional/api/deprecated_spec.lua b/test/functional/api/deprecated_spec.lua new file mode 100644 index 0000000000..2efcfda873 --- /dev/null +++ b/test/functional/api/deprecated_spec.lua @@ -0,0 +1,21 @@ +-- Island of misfit toys. +--- @diagnostic disable: deprecated + +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +describe('deprecated', function() + before_each(n.clear) + + describe('nvim_notify', function() + it('can notify a info message', function() + n.api.nvim_notify('hello world', 2, {}) + end) + + it('can be overridden', function() + n.command('lua vim.notify = function(...) return 42 end') + t.eq(42, n.api.nvim_exec_lua("return vim.notify('Hello world')", {})) + n.api.nvim_notify('hello world', 4, {}) + end) + end) +end) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 43be0c0e43..8a4aea1efe 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -249,7 +249,7 @@ describe('API/extmarks', function() 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 })) + eq({ { 1, 0, 0 }, { 2, 0, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) api.nvim_buf_clear_namespace(0, ns, 0, -1) end) @@ -1731,7 +1731,7 @@ describe('API/extmarks', function() -- mark with invalidate is removed command('d2') screen:expect([[ - S2^aaa bbb ccc | + {7:S2}^aaa bbb ccc | {7: }aaa bbb ccc |*3 {7: } | | @@ -1739,9 +1739,9 @@ describe('API/extmarks', function() -- mark is restored with undo_restore == true command('silent undo') screen:expect([[ - S1{7: }^aaa bbb ccc | - S2S1aaa bbb ccc | - S2{7: }aaa bbb ccc | + {7:S1 }^aaa bbb ccc | + {7:S2S1}aaa bbb ccc | + {7:S2 }aaa bbb ccc | {7: }aaa bbb ccc |*2 | ]]) @@ -1794,6 +1794,16 @@ describe('API/extmarks', function() eq({}, get_extmark_by_id(ns, 4, {})) end) + it('no crash checking invalidated flag of sign pair end key #31856', function() + api.nvim_buf_set_lines(0, 0, 1, false, { '', '' }) + api.nvim_set_option_value('signcolumn', 'auto:2', {}) + set_extmark(ns, 1, 0, 0, { sign_text = 'S1', invalidate = true, end_row = 0 }) + set_extmark(ns, 2, 1, 0, { sign_text = 'S2', end_row = 1 }) + command('d') + api.nvim_buf_clear_namespace(0, ns, 0, -1) + n.assert_alive() + end) + it('can set a URL', function() local url1 = 'https://example.com' local url2 = 'http://127.0.0.1' diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index dd0611f184..8f98ae3650 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -309,6 +309,15 @@ describe('API: set highlight', function() eq({ underdotted = true }, api.nvim_get_hl_by_name('Test_hl', true)) end) + it('can set all underline cterm attributes #31385', function() + local ns = get_ns() + local attrs = { 'underline', 'undercurl', 'underdouble', 'underdotted', 'underdashed' } + for _, attr in ipairs(attrs) do + api.nvim_set_hl(ns, 'Test_' .. attr, { cterm = { [attr] = true } }) + eq({ [attr] = true }, api.nvim_get_hl_by_name('Test_' .. attr, false)) + end + end) + it('can set a highlight in the global namespace', function() api.nvim_set_hl(0, 'Test_hl', highlight2_config) eq( @@ -710,4 +719,18 @@ describe('API: set/get highlight namespace', function() api.nvim_win_set_hl_ns(0, ns) eq(ns, api.nvim_get_hl_ns({ winid = 0 })) end) + + it('setting namespace takes priority over &winhighlight', function() + command('set winhighlight=Visual:Search') + n.insert('foobar') + local ns = api.nvim_create_namespace('') + api.nvim_win_set_hl_ns(0, ns) + eq(ns, api.nvim_get_hl_ns({ winid = 0 })) + command('enew') -- switching buffer keeps namespace #30904 + eq(ns, api.nvim_get_hl_ns({ winid = 0 })) + command('set winhighlight=') + eq(ns, api.nvim_get_hl_ns({ winid = 0 })) + command('set winhighlight=Visual:Search') + eq(ns, api.nvim_get_hl_ns({ winid = 0 })) + end) end) diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index bdd340f6c6..c022ba28de 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -9,7 +9,6 @@ local nvim_prog, command, fn = n.nvim_prog, n.command, n.fn local source, next_msg = n.source, n.next_msg local ok = t.ok local api = n.api -local spawn, merge_args = n.spawn, n.merge_args local set_session = n.set_session local pcall_err = t.pcall_err local assert_alive = n.assert_alive @@ -281,10 +280,9 @@ describe('server -> client', function() end) describe('connecting to another (peer) nvim', function() - local nvim_argv = merge_args(n.nvim_argv, { '--headless' }) local function connect_test(server, mode, address) local serverpid = fn.getpid() - local client = spawn(nvim_argv, false, nil, true) + local client = n.new_session(true) set_session(client) local clientpid = fn.getpid() @@ -312,7 +310,7 @@ describe('server -> client', function() end it('via named pipe', function() - local server = spawn(nvim_argv) + local server = n.new_session(false) set_session(server) local address = fn.serverlist()[1] local first = string.sub(address, 1, 1) @@ -321,7 +319,7 @@ describe('server -> client', function() end) it('via ipv4 address', function() - local server = spawn(nvim_argv) + local server = n.new_session(false) set_session(server) local status, address = pcall(fn.serverstart, '127.0.0.1:') if not status then @@ -332,7 +330,7 @@ describe('server -> client', function() end) it('via ipv6 address', function() - local server = spawn(nvim_argv) + local server = n.new_session(false) set_session(server) local status, address = pcall(fn.serverstart, '::1:') if not status then @@ -343,7 +341,7 @@ describe('server -> client', function() end) it('via hostname', function() - local server = spawn(nvim_argv) + local server = n.new_session(false) set_session(server) local address = fn.serverstart('localhost:') eq('localhost:', string.sub(address, 1, 10)) @@ -351,10 +349,10 @@ describe('server -> client', function() end) it('does not crash on receiving UI events', function() - local server = spawn(nvim_argv) + local server = n.new_session(false) set_session(server) local address = fn.serverlist()[1] - local client = spawn(nvim_argv, false, nil, true) + local client = n.new_session(true) set_session(client) local id = fn.sockconnect('pipe', address, { rpc = true }) diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index 617786eb2d..68c4ef7503 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -43,7 +43,7 @@ describe("api_info()['version']", function() eq(0, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1))) eq(0, fn.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch)) eq(0, fn.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch)) - assert(build == nil or type(build) == 'string') + assert(build == vim.NIL or type(build) == 'string') end) end) @@ -93,28 +93,28 @@ describe('api metadata', function() local function clean_level_0(metadata) for _, f in ipairs(metadata.functions) do f.can_fail = nil - f.async = nil + f.async = nil -- XXX: renamed to "fast". f.receives_channel_id = nil f.since = 0 end end - local api_info, compat, stable, api_level + local api_info --[[@type table]] + local compat --[[@type integer]] + local stable --[[@type integer]] + local api_level --[[@type integer]] local old_api = {} setup(function() clear() -- Ensure a session before requesting api_info. + --[[@type { version: {api_compatible: integer, api_level: integer, api_prerelease: boolean} }]] api_info = api.nvim_get_api_info()[2] compat = api_info.version.api_compatible api_level = api_info.version.api_level - if api_info.version.api_prerelease then - stable = api_level - 1 - else - stable = api_level - end + stable = api_info.version.api_prerelease and api_level - 1 or api_level for level = compat, stable do local path = ('test/functional/fixtures/api_level_' .. tostring(level) .. '.mpack') - old_api[level] = read_mpack_file(path) + old_api[level] = read_mpack_file(path) --[[@type table]] if old_api[level] == nil then local errstr = 'missing metadata fixture for stable level ' .. level .. '. ' if level == api_level and not api_info.version.api_prerelease then diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 3f1e378bc1..3aa9ba49d5 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -96,12 +96,19 @@ describe('API', function() assert_alive() end) - it('input is processed first when followed immediately by non-fast events', function() + it('input is processed first if followed immediately by non-fast events', function() api.nvim_set_current_line('ab') async_meths.nvim_input('x') async_meths.nvim_exec_lua('_G.res1 = vim.api.nvim_get_current_line()', {}) async_meths.nvim_exec_lua('_G.res2 = vim.api.nvim_get_current_line()', {}) eq({ 'b', 'b' }, exec_lua('return { _G.res1, _G.res2 }')) + -- Also test with getchar() + async_meths.nvim_command('let g:getchar = 1 | call getchar() | let g:getchar = 0') + eq(1, api.nvim_get_var('getchar')) + async_meths.nvim_input('x') + async_meths.nvim_exec_lua('_G.res1 = vim.g.getchar', {}) + async_meths.nvim_exec_lua('_G.res2 = vim.g.getchar', {}) + eq({ 0, 0 }, exec_lua('return { _G.res1, _G.res2 }')) end) it('does not set CA_COMMAND_BUSY #7254', function() @@ -695,7 +702,7 @@ describe('API', function() pcall_err(request, 'nvim_call_dict_function', 42, 'f', { 1, 2 }) ) eq( - 'Failed to evaluate dict expression', + 'Vim:E121: Undefined variable: foo', pcall_err(request, 'nvim_call_dict_function', 'foo', 'f', { 1, 2 }) ) eq('dict not found', pcall_err(request, 'nvim_call_dict_function', '42', 'f', { 1, 2 })) @@ -781,18 +788,6 @@ describe('API', function() end) end) - describe('nvim_notify', function() - it('can notify a info message', function() - api.nvim_notify('hello world', 2, {}) - end) - - it('can be overridden', function() - command('lua vim.notify = function(...) return 42 end') - eq(42, api.nvim_exec_lua("return vim.notify('Hello world')", {})) - api.nvim_notify('hello world', 4, {}) - end) - end) - describe('nvim_input', function() it('Vimscript error: does NOT fail, updates v:errmsg', function() local status, _ = pcall(api.nvim_input, ':call bogus_fn()<CR>') @@ -1770,6 +1765,11 @@ describe('API', function() end) it('validation', function() + eq("Unknown option 'foobar'", pcall_err(api.nvim_set_option_value, 'foobar', 'baz', {})) + eq( + "Unknown option 'foobar'", + pcall_err(api.nvim_set_option_value, 'foobar', 'baz', { win = api.nvim_get_current_win() }) + ) eq( "Invalid 'scope': expected 'local' or 'global'", pcall_err(api.nvim_get_option_value, 'scrolloff', { scope = 'bogus' }) @@ -1952,6 +1952,16 @@ describe('API', function() api.nvim_set_current_win(api.nvim_list_wins()[2]) eq(api.nvim_list_wins()[2], api.nvim_get_current_win()) end) + + it('failure modes', function() + n.command('split') + + eq('Invalid window id: 9999', pcall_err(api.nvim_set_current_win, 9999)) + + -- XXX: force nvim_set_current_win to fail somehow. + n.command("au WinLeave * throw 'foo'") + eq('WinLeave Autocommands for "*": foo', pcall_err(api.nvim_set_current_win, 1000)) + end) end) describe('nvim_{get,set}_current_tabpage, nvim_list_tabpages', function() @@ -1971,6 +1981,16 @@ describe('API', function() eq(api.nvim_list_tabpages()[2], api.nvim_get_current_tabpage()) eq(api.nvim_list_wins()[2], api.nvim_get_current_win()) end) + + it('failure modes', function() + n.command('tabnew') + + eq('Invalid tabpage id: 999', pcall_err(api.nvim_set_current_tabpage, 999)) + + -- XXX: force nvim_set_current_tabpage to fail somehow. + n.command("au TabLeave * throw 'foo'") + eq('TabLeave Autocommands for "*": foo', pcall_err(api.nvim_set_current_tabpage, 1)) + end) end) describe('nvim_get_mode', function() @@ -2679,7 +2699,8 @@ describe('API', function() -- :terminal with args + running process. command('enew') local progpath_esc = eval('shellescape(v:progpath)') - fn.termopen(('%s -u NONE -i NONE'):format(progpath_esc), { + fn.jobstart(('%s -u NONE -i NONE'):format(progpath_esc), { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) eq(-1, eval('jobwait([&channel], 0)[0]')) -- Running? @@ -3654,6 +3675,30 @@ describe('API', function() async_meths.nvim_echo({ { 'msg\nmsg' }, { 'msg' } }, false, {}) eq('', exec_capture('messages')) end) + + it('can print error message', function() + async_meths.nvim_echo({ { 'Error\nMessage' } }, false, { err = true }) + screen:expect([[ + | + {1:~ }|*3 + {3: }| + {9:Error} | + {9:Message} | + {6:Press ENTER or type command to continue}^ | + ]]) + feed(':messages<CR>') + screen:expect([[ + ^ | + {1:~ }|*6 + | + ]]) + async_meths.nvim_echo({ { 'Error' }, { 'Message', 'Special' } }, false, { err = true }) + screen:expect([[ + ^ | + {1:~ }|*6 + {9:Error}{16:Message} | + ]]) + end) end) describe('nvim_open_term', function() @@ -3760,7 +3805,7 @@ describe('API', function() screen:expect { grid = [[ | - {1:~}{102: }{4: }{1: }| + {1:~}{4:^ }{1: }| {1:~}{4: }{1: }|*4 {1:~ }|*3 {5:-- TERMINAL --} | @@ -3776,7 +3821,7 @@ describe('API', function() screen:expect { grid = [[ | - {1:~}{4:herrejösses!}{102: }{4: }{1: }| + {1:~}{4:herrejösses!^ }{1: }| {1:~}{4: }{1: }|*4 {1:~ }|*3 {5:-- TERMINAL --} | @@ -3955,8 +4000,8 @@ describe('API', function() str = 'TextWithWarningHighlightTextWithUserHighlight', width = 45, highlights = { - { start = 0, group = 'WarningMsg' }, - { start = 24, group = 'User1' }, + { start = 0, group = 'WarningMsg', groups = { 'StatusLine', 'WarningMsg' } }, + { start = 24, group = 'User1', groups = { 'StatusLine', 'User1' } }, }, }, api.nvim_eval_statusline( @@ -3971,7 +4016,7 @@ describe('API', function() str = 'TextWithNoHighlight', width = 19, highlights = { - { start = 0, group = 'StatusLine' }, + { start = 0, group = 'StatusLine', groups = { 'StatusLine' } }, }, }, api.nvim_eval_statusline('TextWithNoHighlight', { highlights = true })) end) @@ -3983,8 +4028,8 @@ describe('API', function() str = 'TextWithNoHighlightTextWithWarningHighlight', width = 43, highlights = { - { start = 0, group = 'StatusLineNC' }, - { start = 19, group = 'WarningMsg' }, + { start = 0, group = 'StatusLineNC', groups = { 'StatusLineNC' } }, + { start = 19, group = 'WarningMsg', groups = { 'StatusLineNC', 'WarningMsg' } }, }, }, api.nvim_eval_statusline( @@ -4000,8 +4045,8 @@ describe('API', function() str = 'TextWithNoHighlightTextWithWarningHighlight', width = 43, highlights = { - { start = 0, group = 'TabLineFill' }, - { start = 19, group = 'WarningMsg' }, + { start = 0, group = 'TabLineFill', groups = { 'TabLineFill' } }, + { start = 19, group = 'WarningMsg', groups = { 'TabLineFill', 'WarningMsg' } }, }, }, api.nvim_eval_statusline( @@ -4017,8 +4062,8 @@ describe('API', function() str = 'TextWithNoHighlightTextWithWarningHighlight', width = 43, highlights = { - { start = 0, group = 'WinBar' }, - { start = 19, group = 'WarningMsg' }, + { start = 0, group = 'WinBar', groups = { 'WinBar' } }, + { start = 19, group = 'WarningMsg', groups = { 'WinBar', 'WarningMsg' } }, }, }, api.nvim_eval_statusline( @@ -4045,11 +4090,11 @@ describe('API', function() str = '││bbaa 4 ', width = 9, highlights = { - { group = 'CursorLineFold', start = 0 }, - { group = 'Normal', start = 6 }, - { group = 'ErrorMsg', start = 6 }, - { group = 'IncSearch', start = 8 }, - { group = 'Normal', start = 10 }, + { group = 'CursorLineFold', start = 0, groups = { 'CursorLineFold' } }, + { group = 'Normal', start = 6, groups = { 'Normal' } }, + { group = 'ErrorMsg', start = 6, groups = { 'CursorLineSign', 'ErrorMsg' } }, + { group = 'IncSearch', start = 8, groups = { 'CursorLineSign', 'IncSearch' } }, + { group = 'Normal', start = 10, groups = { 'Normal' } }, }, }, api.nvim_eval_statusline( '%C%s%=%l ', @@ -4060,8 +4105,8 @@ describe('API', function() str = ' 3 ', width = 9, highlights = { - { group = 'LineNr', start = 0 }, - { group = 'ErrorMsg', start = 8 }, + { group = 'LineNr', start = 0, groups = { 'LineNr' } }, + { group = 'ErrorMsg', start = 8, groups = { 'LineNr', 'ErrorMsg' } }, }, }, api.nvim_eval_statusline('%l%#ErrorMsg# ', { use_statuscol_lnum = 3, highlights = true }) @@ -5359,8 +5404,53 @@ describe('API', function() 13 | ]], }) - -- takes buffer line count from correct buffer with "win" and {0, -1} "range" - api.nvim__redraw({ win = 0, range = { 0, -1 } }) + end) + + it('nvim__redraw range parameter', function() + Screen.new(10, 5) + fn.setline(1, fn.range(4)) + + exec_lua([[ + _G.lines_list = {} + ns = vim.api.nvim_create_namespace('') + vim.api.nvim_set_decoration_provider(ns, { + on_win = function() + end, + on_line = function(_, _, _, line) + table.insert(_G.lines_list, line) + end, + }) + function _G.get_lines() + local lines = _G.lines_list + _G.lines_list = {} + return lines + end + ]]) + + api.nvim__redraw({ flush = true, valid = false }) + exec_lua('_G.get_lines()') + + local actual_lines = {} + local function test(range) + api.nvim__redraw({ win = 0, range = range }) + table.insert(actual_lines, exec_lua('return _G.get_lines()')) + end + + test({ 0, -1 }) + test({ 2, 2 ^ 31 }) + test({ 2, 2 ^ 32 }) + test({ 2 ^ 31 - 1, 2 }) + test({ 2 ^ 32 - 1, 2 }) + + local expected_lines = { + { 0, 1, 2, 3 }, + { 2, 3 }, + { 2, 3 }, + {}, + {}, + } + eq(expected_lines, actual_lines) + n.assert_alive() end) end) diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 92999f383a..028f0beb38 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -359,6 +359,15 @@ describe('API/win', function() eq(2, api.nvim_win_get_height(api.nvim_list_wins()[2])) end) + it('failure modes', function() + command('split') + eq('Invalid window id: 999999', pcall_err(api.nvim_win_set_height, 999999, 10)) + eq( + 'Wrong type for argument 2 when calling nvim_win_set_height, expecting Integer', + pcall_err(api.nvim_win_set_height, 0, 0.9) + ) + end) + it('correctly handles height=1', function() command('split') api.nvim_set_current_win(api.nvim_list_wins()[1]) @@ -409,6 +418,15 @@ describe('API/win', function() eq(2, api.nvim_win_get_width(api.nvim_list_wins()[2])) end) + it('failure modes', function() + command('vsplit') + eq('Invalid window id: 999999', pcall_err(api.nvim_win_set_width, 999999, 10)) + eq( + 'Wrong type for argument 2 when calling nvim_win_set_width, expecting Integer', + pcall_err(api.nvim_win_set_width, 0, 0.9) + ) + end) + it('do not cause ml_get errors with foldmethod=expr #19989', function() insert([[ aaaaa @@ -488,6 +506,48 @@ describe('API/win', function() assert_alive() end) + describe('after closing', function() + local buf, win0, win1, win2 + + before_each(function() + win0 = api.nvim_get_current_win() + command('new') + buf = api.nvim_get_current_buf() + win1 = api.nvim_get_current_win() + command('set numberwidth=10') + command('split') + win2 = api.nvim_get_current_win() + command('set numberwidth=15') + command('enew') + api.nvim_set_current_win(win1) + command('normal ix') + command('enew') + api.nvim_set_current_win(win0) + eq(4, api.nvim_get_option_value('numberwidth', {})) + end) + + -- at this point buffer `buf` is current in no windows. Closing shouldn't affect its defaults + it('0 windows', function() + api.nvim_set_current_buf(buf) + eq(10, api.nvim_get_option_value('numberwidth', {})) + end) + + it('1 window', function() + api.nvim_win_close(win1, false) + + api.nvim_set_current_buf(buf) + eq(10, api.nvim_get_option_value('numberwidth', {})) + end) + + it('2 windows', function() + api.nvim_win_close(win1, false) + api.nvim_win_close(win2, false) + + api.nvim_set_current_buf(buf) + eq(10, api.nvim_get_option_value('numberwidth', {})) + end) + end) + it('returns values for unset local options', function() eq(-1, api.nvim_get_option_value('scrolloff', { win = 0, scope = 'local' })) end) @@ -1664,7 +1724,7 @@ describe('API/win', function() autocmd BufWinEnter * ++once let fired = v:true ]]) eq( - 'Failed to set buffer 2', + 'Vim:E37: No write since last change (add ! to override)', pcall_err(api.nvim_open_win, api.nvim_create_buf(true, true), false, { split = 'left' }) ) eq(false, eval('fired')) |