diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-05-24 19:18:11 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-05-24 19:18:11 +0000 |
commit | ff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch) | |
tree | 729bbcb92231538fa61dab6c3d890b025484b7f5 /test/functional/lua/vim_spec.lua | |
parent | 376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff) | |
parent | 28c04948a1c887a1cc0cb64de79fa32631700466 (diff) | |
download | rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2 rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r-- | test/functional/lua/vim_spec.lua | 306 |
1 files changed, 183 insertions, 123 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index a262d239e8..c8f94c6ffa 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1,32 +1,33 @@ -- Test suite for testing interactions with API bindings -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local nvim_prog = helpers.nvim_prog -local fn = helpers.fn -local api = helpers.api -local command = helpers.command -local dedent = helpers.dedent -local insert = helpers.insert -local clear = helpers.clear -local eq = helpers.eq -local ok = helpers.ok +local nvim_prog = n.nvim_prog +local fn = n.fn +local api = n.api +local command = n.command +local dedent = t.dedent +local insert = n.insert +local clear = n.clear +local eq = t.eq +local ok = t.ok local pesc = vim.pesc -local eval = helpers.eval -local feed = helpers.feed -local pcall_err = helpers.pcall_err -local exec_lua = helpers.exec_lua -local matches = helpers.matches -local exec = helpers.exec +local eval = n.eval +local feed = n.feed +local pcall_err = t.pcall_err +local exec_lua = n.exec_lua +local matches = t.matches +local exec = n.exec local NIL = vim.NIL -local retry = helpers.retry -local next_msg = helpers.next_msg -local remove_trace = helpers.remove_trace -local mkdir_p = helpers.mkdir_p -local rmdir = helpers.rmdir -local write_file = helpers.write_file -local poke_eventloop = helpers.poke_eventloop -local assert_alive = helpers.assert_alive +local retry = t.retry +local next_msg = n.next_msg +local remove_trace = t.remove_trace +local mkdir_p = n.mkdir_p +local rmdir = n.rmdir +local write_file = t.write_file +local poke_eventloop = n.poke_eventloop +local assert_alive = n.assert_alive describe('lua stdlib', function() before_each(clear) @@ -128,63 +129,62 @@ describe('lua stdlib', function() eq(1, fn.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")')) end) - local function test_vim_deprecate(current_version) + --- @param prerel string | nil + local function test_vim_deprecate(prerel) -- vim.deprecate(name, alternative, version, plugin, backtrace) -- See MAINTAIN.md for the soft/hard deprecation policy - describe(('vim.deprecate [current_version = %s]'):format(current_version), function() - before_each(function() - -- mock vim.version() behavior, should be pinned for consistent testing - exec_lua( - [[ - local current_version_mock = vim.version.parse(...) - getmetatable(vim.version).__call = function() - return current_version_mock - end - ]], - current_version - ) - end) + describe(('vim.deprecate prerel=%s,'):format(prerel or 'nil'), function() + local curver = exec_lua('return vim.version()') --[[@as {major:number, minor:number}]] + -- "0.10" or "0.10-dev+xxx" + local curstr = ('%s.%s%s'):format(curver.major, curver.minor, prerel or '') + -- "0.10" or "0.11" + local nextver = ('%s.%s'):format(curver.major, curver.minor + (prerel and 0 or 1)) + local was_removed = prerel and 'was removed' or 'will be removed' - it('when plugin = nil', function() + it('plugin=nil, same message skipped', function() eq( - dedent [[ - foo.bar() is deprecated, use zub.wooo{ok=yay} instead. :help deprecated - This feature will be removed in Nvim version 0.10]], - exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10') + dedent( + [[ + foo.bar() is deprecated. Run ":checkhealth vim.deprecated" for more information]] + ):format(curstr), + exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', curstr) ) - -- Same message, skipped. - eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10')) + -- Same message as above; skipped this time. + eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', curstr)) + end) - -- Don't show error if not hard-deprecated (only soft-deprecated) + it('plugin=nil, no error if soft-deprecated', function() eq( vim.NIL, - exec_lua('return vim.deprecate(...)', 'foo.baz()', 'foo.better_baz()', '0.12.0') + exec_lua('return vim.deprecate(...)', 'foo.baz()', 'foo.better_baz()', '0.99.0') ) + end) - -- Show error if hard-deprecated + it('plugin=nil, show error if hard-deprecated', function() eq( - dedent [[ - foo.hard_dep() is deprecated, use vim.new_api() instead. :help deprecated - This feature will be removed in Nvim version 0.11]], - exec_lua('return vim.deprecate(...)', 'foo.hard_dep()', 'vim.new_api()', '0.11') + dedent( + [[ + foo.hard_dep() is deprecated. Run ":checkhealth vim.deprecated" for more information]] + ):format(was_removed, nextver), + exec_lua('return vim.deprecate(...)', 'foo.hard_dep()', 'vim.new_api()', nextver) ) + end) - -- To be deleted in the next major version (1.0) + it('plugin=nil, to be deleted in the next major version (1.0)', function() eq( dedent [[ - foo.baz() is deprecated. :help deprecated - This feature will be removed in Nvim version 1.0]], + foo.baz() is deprecated. Run ":checkhealth vim.deprecated" for more information]], exec_lua [[ return vim.deprecate('foo.baz()', nil, '1.0') ]] ) end) - it('when plugin is specified', function() + it('plugin specified', function() -- When `plugin` is specified, don't show ":help deprecated". #22235 eq( dedent [[ foo.bar() is deprecated, use zub.wooo{ok=yay} instead. - This feature will be removed in my-plugin.nvim version 0.3.0]], + Feature will be removed in my-plugin.nvim 0.3.0]], exec_lua( 'return vim.deprecate(...)', 'foo.bar()', @@ -199,7 +199,7 @@ describe('lua stdlib', function() eq( dedent [[ foo.bar() is deprecated, use zub.wooo{ok=yay} instead. - This feature will be removed in my-plugin.nvim version 0.11.0]], + Feature will be removed in my-plugin.nvim 0.11.0]], exec_lua( 'return vim.deprecate(...)', 'foo.bar()', @@ -213,8 +213,8 @@ describe('lua stdlib', function() end) end - test_vim_deprecate('0.10') - test_vim_deprecate('0.10-dev+g0000000') + test_vim_deprecate() + test_vim_deprecate('-dev+g0000000') it('vim.startswith', function() eq(true, fn.luaeval('vim.startswith("123", "1")')) @@ -592,8 +592,8 @@ describe('lua stdlib', function() { 'x*yz*oo*l', '*', true, false, { 'x', 'yz', 'oo', 'l' } }, } - for _, t in ipairs(tests) do - eq(t[5], vim.split(t[1], t[2], { plain = t[3], trimempty = t[4] }), t[1]) + for _, q in ipairs(tests) do + eq(q[5], vim.split(q[1], q[2], { plain = q[3], trimempty = q[4] }), q[1]) end -- Test old signature @@ -603,8 +603,8 @@ describe('lua stdlib', function() { 'abc', '.-' }, } - for _, t in ipairs(loops) do - matches('Infinite loop detected', pcall_err(vim.split, t[1], t[2])) + for _, q in ipairs(loops) do + matches('Infinite loop detected', pcall_err(vim.split, q[1], q[2])) end -- Validates args. @@ -626,8 +626,8 @@ describe('lua stdlib', function() { 'r\n', 'r' }, } - for _, t in ipairs(trims) do - assert(t[2], trim(t[1])) + for _, q in ipairs(trims) do + assert(q[2], trim(q[1])) end -- Validates args. @@ -636,8 +636,8 @@ describe('lua stdlib', function() it('vim.inspect', function() -- just make sure it basically works, it has its own test suite - local inspect = function(t, opts) - return exec_lua('return vim.inspect(...)', t, opts) + local inspect = function(q, opts) + return exec_lua('return vim.inspect(...)', q, opts) end eq('2', inspect(2)) @@ -670,21 +670,21 @@ describe('lua stdlib', function() local a = {} local b = vim.deepcopy(a) - return vim.tbl_islist(b) and vim.tbl_count(b) == 0 and tostring(a) ~= tostring(b) + return vim.islist(b) and vim.tbl_count(b) == 0 and tostring(a) ~= tostring(b) ]])) ok(exec_lua([[ local a = vim.empty_dict() local b = vim.deepcopy(a) - return not vim.tbl_islist(b) and vim.tbl_count(b) == 0 + return not vim.islist(b) and vim.tbl_count(b) == 0 ]])) ok(exec_lua([[ local a = {x = vim.empty_dict(), y = {}} local b = vim.deepcopy(a) - return not vim.tbl_islist(b.x) and vim.tbl_islist(b.y) + return not vim.islist(b.x) and vim.islist(b.y) and vim.tbl_count(b) == 2 and tostring(a) ~= tostring(b) ]])) @@ -822,30 +822,30 @@ describe('lua stdlib', function() ) end) - it('vim.tbl_isarray', function() - eq(true, exec_lua('return vim.tbl_isarray({})')) - eq(false, exec_lua('return vim.tbl_isarray(vim.empty_dict())')) - eq(true, exec_lua("return vim.tbl_isarray({'a', 'b', 'c'})")) - eq(false, exec_lua("return vim.tbl_isarray({'a', '32', a='hello', b='baz'})")) - eq(false, exec_lua("return vim.tbl_isarray({1, a='hello', b='baz'})")) - eq(false, exec_lua("return vim.tbl_isarray({a='hello', b='baz', 1})")) - eq(false, exec_lua("return vim.tbl_isarray({1, 2, nil, a='hello'})")) - eq(true, exec_lua('return vim.tbl_isarray({1, 2, nil, 4})')) - eq(true, exec_lua('return vim.tbl_isarray({nil, 2, 3, 4})')) - eq(false, exec_lua('return vim.tbl_isarray({1, [1.5]=2, [3]=3})')) + it('vim.isarray', function() + eq(true, exec_lua('return vim.isarray({})')) + eq(false, exec_lua('return vim.isarray(vim.empty_dict())')) + eq(true, exec_lua("return vim.isarray({'a', 'b', 'c'})")) + eq(false, exec_lua("return vim.isarray({'a', '32', a='hello', b='baz'})")) + eq(false, exec_lua("return vim.isarray({1, a='hello', b='baz'})")) + eq(false, exec_lua("return vim.isarray({a='hello', b='baz', 1})")) + eq(false, exec_lua("return vim.isarray({1, 2, nil, a='hello'})")) + eq(true, exec_lua('return vim.isarray({1, 2, nil, 4})')) + eq(true, exec_lua('return vim.isarray({nil, 2, 3, 4})')) + eq(false, exec_lua('return vim.isarray({1, [1.5]=2, [3]=3})')) end) - it('vim.tbl_islist', function() - eq(true, exec_lua('return vim.tbl_islist({})')) - eq(false, exec_lua('return vim.tbl_islist(vim.empty_dict())')) - eq(true, exec_lua("return vim.tbl_islist({'a', 'b', 'c'})")) - eq(false, exec_lua("return vim.tbl_islist({'a', '32', a='hello', b='baz'})")) - eq(false, exec_lua("return vim.tbl_islist({1, a='hello', b='baz'})")) - eq(false, exec_lua("return vim.tbl_islist({a='hello', b='baz', 1})")) - eq(false, exec_lua("return vim.tbl_islist({1, 2, nil, a='hello'})")) - eq(false, exec_lua('return vim.tbl_islist({1, 2, nil, 4})')) - eq(false, exec_lua('return vim.tbl_islist({nil, 2, 3, 4})')) - eq(false, exec_lua('return vim.tbl_islist({1, [1.5]=2, [3]=3})')) + it('vim.islist', function() + eq(true, exec_lua('return vim.islist({})')) + eq(false, exec_lua('return vim.islist(vim.empty_dict())')) + eq(true, exec_lua("return vim.islist({'a', 'b', 'c'})")) + eq(false, exec_lua("return vim.islist({'a', '32', a='hello', b='baz'})")) + eq(false, exec_lua("return vim.islist({1, a='hello', b='baz'})")) + eq(false, exec_lua("return vim.islist({a='hello', b='baz', 1})")) + eq(false, exec_lua("return vim.islist({1, 2, nil, a='hello'})")) + eq(false, exec_lua('return vim.islist({1, 2, nil, 4})')) + eq(false, exec_lua('return vim.islist({nil, 2, 3, 4})')) + eq(false, exec_lua('return vim.islist({1, [1.5]=2, [3]=3})')) end) it('vim.tbl_isempty', function() @@ -918,7 +918,7 @@ describe('lua stdlib', function() local b = {} local c = vim.tbl_extend("keep", a, b) - return not vim.tbl_islist(c) and vim.tbl_count(c) == 0 + return not vim.islist(c) and vim.tbl_count(c) == 0 ]])) ok(exec_lua([[ @@ -926,7 +926,7 @@ describe('lua stdlib', function() local b = vim.empty_dict() local c = vim.tbl_extend("keep", a, b) - return vim.tbl_islist(c) and vim.tbl_count(c) == 0 + return vim.islist(c) and vim.tbl_count(c) == 0 ]])) ok(exec_lua([[ @@ -1026,7 +1026,7 @@ describe('lua stdlib', function() local count = 0 for _ in pairs(c) do count = count + 1 end - return not vim.tbl_islist(c) and count == 0 + return not vim.islist(c) and count == 0 ]])) ok(exec_lua([[ @@ -1037,7 +1037,7 @@ describe('lua stdlib', function() local count = 0 for _ in pairs(c) do count = count + 1 end - return vim.tbl_islist(c) and count == 0 + return vim.islist(c) and count == 0 ]])) eq( @@ -1282,7 +1282,7 @@ describe('lua stdlib', function() vim.rpcrequest(chan, 'nvim_exec', 'let xx = {}\nlet yy = []', false) local dict = vim.rpcrequest(chan, 'nvim_eval', 'xx') local list = vim.rpcrequest(chan, 'nvim_eval', 'yy') - return {dict, list, vim.tbl_islist(dict), vim.tbl_islist(list)} + return {dict, list, vim.islist(dict), vim.islist(list)} ]]) ) @@ -1355,7 +1355,7 @@ describe('lua stdlib', function() vim.api.nvim_set_var('dicty', vim.empty_dict()) local listy = vim.fn.eval("listy") local dicty = vim.fn.eval("dicty") - return {vim.tbl_islist(listy), vim.tbl_islist(dicty), next(listy) == nil, next(dicty) == nil} + return {vim.islist(listy), vim.islist(dicty), next(listy) == nil, next(dicty) == nil} ]]) ) @@ -1569,7 +1569,7 @@ describe('lua stdlib', function() eq(NIL, exec_lua([[return vim.g.Unknown_script_func]])) -- Check if autoload works properly - local pathsep = helpers.get_pathsep() + local pathsep = n.get_pathsep() local xconfig = 'Xhome' .. pathsep .. 'Xconfig' local xdata = 'Xhome' .. pathsep .. 'Xdata' local autoload_folder = table.concat({ xconfig, 'nvim', 'autoload' }, pathsep) @@ -2016,7 +2016,7 @@ describe('lua stdlib', function() vim.opt.scrolloff = 10 return vim.o.scrolloff ]] - eq(scrolloff, 10) + eq(10, scrolloff) end) pending('should handle STUPID window things', function() @@ -2037,7 +2037,7 @@ describe('lua stdlib', function() vim.opt.wildignore = { 'hello', 'world' } return vim.o.wildignore ]] - eq(wildignore, 'hello,world') + eq('hello,world', wildignore) end) it('should allow setting tables with shortnames', function() @@ -2045,7 +2045,7 @@ describe('lua stdlib', function() vim.opt.wig = { 'hello', 'world' } return vim.o.wildignore ]] - eq(wildignore, 'hello,world') + eq('hello,world', wildignore) end) it('should error when you attempt to set string values to numeric options', function() @@ -2451,13 +2451,13 @@ describe('lua stdlib', function() vim.opt.wildignore = 'foo' return vim.o.wildignore ]] - eq(wildignore, 'foo') + eq('foo', wildignore) wildignore = exec_lua [[ vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' } return vim.o.wildignore ]] - eq(wildignore, 'foo,bar,baz') + eq('foo,bar,baz', wildignore) end) it('should handle adding duplicates', function() @@ -2465,19 +2465,19 @@ describe('lua stdlib', function() vim.opt.wildignore = 'foo' return vim.o.wildignore ]] - eq(wildignore, 'foo') + eq('foo', wildignore) wildignore = exec_lua [[ vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' } return vim.o.wildignore ]] - eq(wildignore, 'foo,bar,baz') + eq('foo,bar,baz', wildignore) wildignore = exec_lua [[ vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' } return vim.o.wildignore ]] - eq(wildignore, 'foo,bar,baz') + eq('foo,bar,baz', wildignore) end) it('should allow adding multiple times', function() @@ -2486,7 +2486,7 @@ describe('lua stdlib', function() vim.opt.wildignore = vim.opt.wildignore + 'bar' + 'baz' return vim.o.wildignore ]] - eq(wildignore, 'foo,bar,baz') + eq('foo,bar,baz', wildignore) end) it('should remove values when you use minus', function() @@ -2494,19 +2494,19 @@ describe('lua stdlib', function() vim.opt.wildignore = 'foo' return vim.o.wildignore ]] - eq(wildignore, 'foo') + eq('foo', wildignore) wildignore = exec_lua [[ vim.opt.wildignore = vim.opt.wildignore + { 'bar', 'baz' } return vim.o.wildignore ]] - eq(wildignore, 'foo,bar,baz') + eq('foo,bar,baz', wildignore) wildignore = exec_lua [[ vim.opt.wildignore = vim.opt.wildignore - 'bar' return vim.o.wildignore ]] - eq(wildignore, 'foo,baz') + eq('foo,baz', wildignore) end) it('should prepend values when using ^', function() @@ -2521,7 +2521,7 @@ describe('lua stdlib', function() vim.opt.wildignore = vim.opt.wildignore ^ 'super_first' return vim.o.wildignore ]] - eq(wildignore, 'super_first,first,foo') + eq('super_first,first,foo', wildignore) end) it('should not remove duplicates from wildmode: #14708', function() @@ -2530,7 +2530,7 @@ describe('lua stdlib', function() return vim.o.wildmode ]] - eq(wildmode, 'full,list,full') + eq('full,list,full', wildmode) end) describe('option types', function() @@ -2738,7 +2738,7 @@ describe('lua stdlib', function() return vim.go.whichwrap ]] - eq(ww, 'b,s') + eq('b,s', ww) eq( 'b,s,<,>,[,]', exec_lua [[ @@ -3007,25 +3007,65 @@ describe('lua stdlib', function() end) describe('vim.on_key', function() - it('tracks keystrokes', function() + it('tracks Unicode input', function() insert([[hello world ]]) exec_lua [[ keys = {} + typed = {} - vim.on_key(function(buf) + vim.on_key(function(buf, typed_buf) if buf:byte() == 27 then buf = "<ESC>" end + if typed_buf:byte() == 27 then + typed_buf = "<ESC>" + end table.insert(keys, buf) + table.insert(typed, typed_buf) end) ]] - insert([[next 🤦 lines å ]]) + insert([[next 🤦 lines å …]]) -- It has escape in the keys pressed - eq('inext 🤦 lines å <ESC>', exec_lua [[return table.concat(keys, '')]]) + eq('inext 🤦 lines å …<ESC>', exec_lua [[return table.concat(keys, '')]]) + eq('inext 🤦 lines å …<ESC>', exec_lua [[return table.concat(typed, '')]]) + end) + + it('tracks input with modifiers', function() + exec_lua [[ + keys = {} + typed = {} + + vim.on_key(function(buf, typed_buf) + table.insert(keys, vim.fn.keytrans(buf)) + table.insert(typed, vim.fn.keytrans(typed_buf)) + end) + ]] + + feed([[i<C-V><C-;><C-V><C-…><Esc>]]) + + eq('i<C-V><C-;><C-V><C-…><Esc>', exec_lua [[return table.concat(keys, '')]]) + eq('i<C-V><C-;><C-V><C-…><Esc>', exec_lua [[return table.concat(typed, '')]]) + end) + + it('works with character find and Select mode', function() + insert('12345') + + exec_lua [[ + typed = {} + + vim.cmd('snoremap # @') + + vim.on_key(function(buf, typed_buf) + table.insert(typed, vim.fn.keytrans(typed_buf)) + end) + ]] + + feed('F3gHβγδεζ<Esc>gH…<Esc>gH#$%^') + eq('F3gHβγδεζ<Esc>gH…<Esc>gH#$%^', exec_lua [[return table.concat(typed, '')]]) end) it('allows removing on_key listeners', function() @@ -3087,23 +3127,29 @@ describe('lua stdlib', function() eq('inext l', exec_lua [[ return table.concat(keys, '') ]]) end) - it('processes mapped keys, not unmapped keys', function() + it('argument 1 is keys after mapping, argument 2 is typed keys', function() exec_lua [[ keys = {} + typed = {} vim.cmd("inoremap hello world") - vim.on_key(function(buf) + vim.on_key(function(buf, typed_buf) if buf:byte() == 27 then buf = "<ESC>" end + if typed_buf:byte() == 27 then + typed_buf = "<ESC>" + end table.insert(keys, buf) + table.insert(typed, typed_buf) end) ]] insert('hello') eq('iworld<ESC>', exec_lua [[return table.concat(keys, '')]]) + eq('ihello<ESC>', exec_lua [[return table.concat(typed, '')]]) end) it('can call vim.fn functions on Ctrl-C #17273', function() @@ -3664,6 +3710,20 @@ describe('lua stdlib', function() ]] ) end) + + it('layout in current tabpage does not affect windows in others', function() + command('tab split') + local t2_move_win = api.nvim_get_current_win() + command('vsplit') + local t2_other_win = api.nvim_get_current_win() + command('tabprevious') + matches('E36: Not enough room$', pcall_err(command, 'execute "split|"->repeat(&lines)')) + command('vsplit') + + -- Without vim-patch:8.2.3862, this gives E36, despite just the 1st tabpage being full. + exec_lua('vim.api.nvim_win_call(..., function() vim.cmd.wincmd "J" end)', t2_move_win) + eq({ 'col', { { 'leaf', t2_other_win }, { 'leaf', t2_move_win } } }, fn.winlayout(2)) + end) end) describe('vim.iconv', function() @@ -4011,7 +4071,7 @@ describe('vim.keymap', function() feed('asdf\n') eq(1, exec_lua [[return GlobalCount]]) - eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) + eq('\nNo mapping found', n.exec_capture('nmap asdf')) end) it('works with buffer-local mappings', function() @@ -4035,7 +4095,7 @@ describe('vim.keymap', function() feed('asdf\n') eq(1, exec_lua [[return GlobalCount]]) - eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) + eq('\nNo mapping found', n.exec_capture('nmap asdf')) end) it('does not mutate the opts parameter', function() |