From fa747d004a1e91b30066020f2f592e4dc5d94084 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 19:47:10 +0800 Subject: fix(api): nvim_set_hl bail out on invalid group name (#20021) --- test/functional/api/highlight_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 2730f7e23d..3b36563d21 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -354,4 +354,9 @@ describe("API: set highlight", function() 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})) + assert_alive() + end) end) -- cgit From 933c80e8f9d7ff4ab634c14d370440702c7c8ed7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 21:14:14 +0800 Subject: refactor(mappings)!: mapblock_fill_dict() use API Dictionary (#20020) This introduces the following breaking changes: - nvim_get_keymap now always returns a LuaRef object as "callback" for a Lua mapping regardless of how it is called. The LuaRef object can be called from Lua and Vim script, but is lost over RPC. - maparg() now returns a Funcref instead of a ref number as "callback" for a Lua mapping. The Funcref can be called from Lua and Vim script, but is lost over RPC. This may also make nvim_get_keymap faster, but make maparg() slower. --- test/functional/api/keymap_spec.lua | 42 ++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index a93a4544ff..fedcbfa76a 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -6,6 +6,7 @@ local command = helpers.command local curbufmeths = helpers.curbufmeths local eq, neq = helpers.eq, helpers.neq local exec_lua = helpers.exec_lua +local exec = helpers.exec local feed = helpers.feed local funcs = helpers.funcs local meths = helpers.meths @@ -336,21 +337,26 @@ describe('nvim_get_keymap', function() end) it('can handle lua mappings', function() - eq(0, exec_lua [[ + 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]]) + eq(1, exec_lua([[return GlobalCount]])) - eq(2, exec_lua[[ + eq(2, exec_lua([[ vim.api.nvim_get_keymap('n')[1].callback() return GlobalCount + ]])) + + exec([[ + call nvim_get_keymap('n')[0].callback() ]]) + eq(3, exec_lua([[return GlobalCount]])) + local mapargs = meths.get_keymap('n') - assert(type(mapargs[1].callback) == 'number', 'callback is not luaref number') mapargs[1].callback = nil eq({ lhs='asdf', @@ -834,17 +840,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it ('maparg() returns lua mapping correctly', function() - exec_lua [[ - vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end }) - ]] - assert.truthy(string.match(funcs.maparg('asdf', 'n'), - "^")) + eq(0, exec_lua([[ + GlobalCount = 0 + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + return GlobalCount + ]])) + + assert.truthy(string.match(funcs.maparg('asdf', 'n'), "^")) + local mapargs = funcs.maparg('asdf', 'n', false, true) - assert(type(mapargs.callback) == 'number', 'callback is not luaref number') mapargs.callback = nil mapargs.lhsraw = nil mapargs.lhsrawalt = nil eq(generate_mapargs('n', 'asdf', nil, {sid=sid_lua}), mapargs) + + eq(1, exec_lua([[ + vim.fn.maparg('asdf', 'n', false, true).callback() + return GlobalCount + ]])) + + exec([[ + call maparg('asdf', 'n', v:false, v:true).callback() + ]]) + eq(2, exec_lua([[return GlobalCount]])) end) it('can make lua expr mappings replacing keycodes', function() -- cgit From f31db30975479cb6b57247f124a65f4362f80bfe Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 30 Jun 2022 13:26:31 +0600 Subject: feat(lua): vim.ui_attach to get ui events from lua Co-authored-by: Famiu Haque --- test/functional/lua/ui_event_spec.lua | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 test/functional/lua/ui_event_spec.lua (limited to 'test/functional') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua new file mode 100644 index 0000000000..05322a0fdb --- /dev/null +++ b/test/functional/lua/ui_event_spec.lua @@ -0,0 +1,107 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local eq = helpers.eq +local exec_lua = helpers.exec_lua +local clear = helpers.clear +local feed = helpers.feed +local funcs = helpers.funcs +local inspect = require'vim.inspect' + +describe('vim.ui_attach', function() + local screen + before_each(function() + clear() + exec_lua [[ + ns = vim.api.nvim_create_namespace 'testspace' + events = {} + function on_event(event, ...) + events[#events+1] = {event, ...} + return true + end + + function get_events() + local ret_events = events + events = {} + return ret_events + end + ]] + + screen = Screen.new(40,5) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}; + [2] = {bold = true}; + [3] = {background = Screen.colors.Grey}; + [4] = {background = Screen.colors.LightMagenta}; + }) + screen:attach() + end) + + local function expect_events(expected) + local evs = exec_lua "return get_events(...)" + eq(expected, evs, inspect(evs)) + end + + it('can receive popupmenu events', function() + exec_lua [[ vim.ui_attach(ns, {ext_popupmenu=true}, on_event) ]] + feed('ifo') + screen:expect{grid=[[ + fo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]} + + funcs.complete(1, {'food', 'foobar', 'foo'}) + screen:expect{grid=[[ + food^ | + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]} + expect_events { + { "popupmenu_show", { { "food", "", "", "" }, { "foobar", "", "", "" }, { "foo", "", "", "" } }, 0, 0, 0, 1 }; + } + + feed '' + screen:expect{grid=[[ + foobar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]} + expect_events { + { "popupmenu_select", 1 }; + } + + feed '' + screen:expect{grid=[[ + foobar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], intermediate=true} + expect_events { + { "popupmenu_hide" }; + } + + -- ui_detach stops events, and reenables builtin pum + exec_lua [[ vim.ui_detach(ns) ]] + + funcs.complete(1, {'food', 'foobar', 'foo'}) + screen:expect{grid=[[ + food^ | + {3:food }{1: }| + {4:foobar }{1: }| + {4:foo }{1: }| + {2:-- INSERT --} | + ]]} + expect_events { + } + + + end) +end) -- cgit From 0c6b39894f4cac99c3d81857986e4eae533fb59a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 06:19:49 +0800 Subject: feat(mapset): support restoring Lua callback (#20024) vim-patch:9.0.0341: mapset() does not restore mapping properly Problem: mapset() does not restore mapping properly. Solution: Use an empty string for . (closes vim/vim#11022) https://github.com/vim/vim/commit/92a3d20682d46359bb50a452b4f831659e799155 --- test/functional/vimscript/map_functions_spec.lua | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/functional') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index aa64006de0..96b86d053e 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -3,6 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval +local exec = helpers.exec +local exec_lua = helpers.exec_lua local expect = helpers.expect local feed = helpers.feed local funcs = helpers.funcs @@ -10,6 +12,7 @@ local meths = helpers.meths local nvim = helpers.nvim local source = helpers.source local command = helpers.command +local pcall_err = helpers.pcall_err describe('maparg()', function() before_each(clear) @@ -194,4 +197,43 @@ describe('mapset()', function() feed('foo') expect('<<') end) + + it('can restore Lua callback from the dict returned by maparg()', function() + eq(0, exec_lua([[ + GlobalCount = 0 + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end }) + return GlobalCount + ]])) + feed('asdf') + eq(1, exec_lua([[return GlobalCount]])) + + exec_lua([[ + _G.saved_asdf_map = vim.fn.maparg('asdf', 'n', false, true) + vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 10 end }) + ]]) + feed('asdf') + eq(11, exec_lua([[return GlobalCount]])) + + exec_lua([[vim.fn.mapset('n', false, _G.saved_asdf_map)]]) + feed('asdf') + eq(12, exec_lua([[return GlobalCount]])) + + exec([[ + let g:saved_asdf_map = maparg('asdf', 'n', v:false, v:true) + lua vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 10 end }) + ]]) + feed('asdf') + eq(22, exec_lua([[return GlobalCount]])) + + command([[call mapset('n', v:false, g:saved_asdf_map)]]) + feed('asdf') + eq(23, exec_lua([[return GlobalCount]])) + end) + + it('does not leak memory if lhs is missing', function() + eq('Error executing lua: Vim:E460: entries missing in mapset() dict argument', + pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]])) + eq('Error executing lua: Vim:E460: entries missing in mapset() dict argument', + pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]])) + end) end) -- cgit From db2e5f46f5aa5a6300395eaa9c4923835683c770 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 16:37:29 +0800 Subject: fix(lua): make ui_attach()/ui_detach() take effect immediately (#20037) --- test/functional/lua/ui_event_spec.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 05322a0fdb..294222ad13 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -88,10 +88,12 @@ describe('vim.ui_attach', function() { "popupmenu_hide" }; } - -- ui_detach stops events, and reenables builtin pum - exec_lua [[ vim.ui_detach(ns) ]] + -- vim.ui_detach() stops events, and reenables builtin pum immediately + exec_lua [[ + vim.ui_detach(ns) + vim.fn.complete(1, {'food', 'foobar', 'foo'}) + ]] - funcs.complete(1, {'food', 'foobar', 'foo'}) screen:expect{grid=[[ food^ | {3:food }{1: }| @@ -102,6 +104,5 @@ describe('vim.ui_attach', function() expect_events { } - end) end) -- cgit From 689f5d604e59eba1ddab6f91b458a8163dc6629d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:32:59 +0800 Subject: feat(api): add support for :horizontal modifier --- test/functional/api/command_spec.lua | 13 +++++++++++-- test/functional/api/vim_spec.lua | 26 ++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 440e93da0e..2d8bf23f5b 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -125,6 +125,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -160,6 +161,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -195,6 +197,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -224,12 +227,13 @@ describe('nvim_create_user_command', function() bang = true, line1 = 10, line2 = 10, - mods = "confirm unsilent botright", + mods = "confirm unsilent botright horizontal", smods = { browse = false, confirm = true, emsg_silent = false, hide = false, + horizontal = true, keepalt = false, keepjumps = false, keepmarks = false, @@ -249,7 +253,7 @@ describe('nvim_create_user_command', function() count = 10, reg = "", }, exec_lua [=[ - vim.api.nvim_command('unsilent botright confirm 10CommandWithLuaCallback! h\tey ') + vim.api.nvim_command('unsilent horizontal botright confirm 10CommandWithLuaCallback! h\tey ') return result ]=]) @@ -265,6 +269,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -300,6 +305,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -347,6 +353,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -383,6 +390,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -429,6 +437,7 @@ describe('nvim_create_user_command', function() confirm = false, emsg_silent = false, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 24d0b6da45..2e37c4787d 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3195,6 +3195,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3236,6 +3237,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3277,6 +3279,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3318,6 +3321,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3359,6 +3363,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3400,6 +3405,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3441,6 +3447,7 @@ describe('API', function() force = false }, hide = false, + horizontal = true, keepalt = false, keepjumps = false, keepmarks = false, @@ -3456,7 +3463,7 @@ describe('API', function() verbose = 15, vertical = false, }, - }, meths.parse_cmd('15verbose silent! aboveleft topleft tab filter /foo/ split foo.txt', {})) + }, meths.parse_cmd('15verbose silent! horizontal topleft tab filter /foo/ split foo.txt', {})) eq({ cmd = 'split', args = { 'foo.txt' }, @@ -3480,6 +3487,7 @@ describe('API', function() force = true }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3522,6 +3530,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3563,6 +3572,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3605,6 +3615,7 @@ describe('API', function() force = false }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3697,6 +3708,7 @@ describe('API', function() force = false, }, hide = false, + horizontal = false, keepalt = false, keepjumps = false, keepmarks = false, @@ -3798,10 +3810,20 @@ describe('API', function() eq('1', meths.cmd({ cmd = 'echomsg', args = { '1' }, mods = { silent = true } }, { output = true })) - -- with :silent message isn't added to message history + -- but message isn't added to message history eq('', meths.cmd({ cmd = 'messages' }, { output = true })) meths.create_user_command("Foo", 'set verbose', {}) eq(" verbose=1", meths.cmd({ cmd = "Foo", mods = { verbose = 1 } }, { output = true })) + meths.create_user_command("Mods", "echo ''", {}) + eq('keepmarks keeppatterns silent 3verbose aboveleft horizontal', + meths.cmd({ cmd = "Mods", mods = { + horizontal = true, + keepmarks = true, + keeppatterns = true, + silent = true, + split = 'aboveleft', + verbose = 3, + } }, { output = true })) eq(0, meths.get_option_value("verbose", {})) command('edit foo.txt | edit bar.txt') eq(' 1 #h "foo.txt" line 1', -- cgit From 2afcdbd63a5b0cbeaad9d83b096a3af5201c67a9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 2 Sep 2022 15:20:29 +0100 Subject: feat(Man): port to Lua (#19912) Co-authored-by: zeertzjq --- test/functional/plugin/man_spec.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 9304aa6da9..3e63c5df9a 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -1,7 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local command, eval, rawfeed = helpers.command, helpers.eval, helpers.rawfeed +local command, rawfeed = helpers.command, helpers.rawfeed local clear = helpers.clear +local exec_lua = helpers.exec_lua local funcs = helpers.funcs local nvim_prog = helpers.nvim_prog local matches = helpers.matches @@ -50,7 +51,7 @@ describe(':Man', function() | ]]} - eval('man#init_pager()') + exec_lua[[require'man'.init_pager()]] screen:expect([[ ^this {b:is} {b:a} test | @@ -74,7 +75,7 @@ describe(':Man', function() | ]=]} - eval('man#init_pager()') + exec_lua[[require'man'.init_pager()]] screen:expect([[ ^this {b:is }{bi:a }{biu:test} | @@ -89,7 +90,7 @@ describe(':Man', function() rawfeed([[ ithis iiss ああ test with _ö_v_e_r_s_t_r_u_̃_c_k te[3mxt¶[0m]]) - eval('man#init_pager()') + exec_lua[[require'man'.init_pager()]] screen:expect([[ ^this {b:is} {b:あ} test | @@ -105,7 +106,7 @@ describe(':Man', function() i__bbeeggiinnss mmiidd__ddllee _m_i_d___d_l_e]]) - eval('man#init_pager()') + exec_lua[[require'man'.init_pager()]] screen:expect([[ {b:^_begins} | @@ -121,7 +122,7 @@ describe(':Man', function() i· ·· +o ++oo double]]) - eval('man#init_pager()') + exec_lua[[require'man'.init_pager()]] screen:expect([[ ^· {b:·} | @@ -138,7 +139,7 @@ describe(':Man', function() [44m 4 [45m 5 [46m 6 [47m 7 [100m 8 [101m 9 [102m 10 [103m 11 [104m 12 [105m 13 [106m 14 [107m 15 [48:5:16m 16 ]]) - eval('man#init_pager()') + exec_lua[[require'man'.init_pager()]] screen:expect([[ ^ 0 1 2 3 | -- cgit From 1ef7720567b08caec0c077605fb2a01a9d6eafbc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 18:46:34 +0800 Subject: fix(api)!: correctly deal with number before :tab Now nvim_parse_cmd and nvim_create_user_command use a "tab" value which is the same as the number passed before :tab modifier instead of the number plus 1, and "tab" value is -1 if :tab modifier is not used. --- test/functional/api/command_spec.lua | 41 +++++++++++++++++++++++++++--------- test/functional/api/vim_spec.lua | 24 ++++++++++----------- 2 files changed, 43 insertions(+), 22 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 2d8bf23f5b..44a19d8348 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -136,7 +136,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -172,7 +172,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -208,7 +208,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -244,7 +244,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "botright", - tab = 0, + tab = -1, unsilent = true, verbose = -1, vertical = false, @@ -280,7 +280,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -316,7 +316,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -364,7 +364,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -401,7 +401,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -448,7 +448,7 @@ describe('nvim_create_user_command', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -523,8 +523,29 @@ describe('nvim_create_user_command', function() vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {}) end, {}) ]] - eq("3", meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true })) + + eq(1, #meths.list_tabpages()) + exec_lua[[ + vim.api.nvim_create_user_command('MySplit', function(opts) + vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {}) + end, {}) + ]] + meths.cmd({ cmd = 'MySplit' }, {}) + eq(1, #meths.list_tabpages()) + eq(2, #meths.list_wins()) + meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) + eq(2, #meths.list_tabpages()) + eq(2, funcs.tabpagenr()) + meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) + eq(3, #meths.list_tabpages()) + eq(2, funcs.tabpagenr()) + meths.cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {}) + eq(4, #meths.list_tabpages()) + eq(4, funcs.tabpagenr()) + meths.cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {}) + eq(5, #meths.list_tabpages()) + eq(1, funcs.tabpagenr()) end) end) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 2e37c4787d..edbdd54c2f 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3206,7 +3206,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3248,7 +3248,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3290,7 +3290,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3332,7 +3332,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3374,7 +3374,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3416,7 +3416,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3458,7 +3458,7 @@ describe('API', function() sandbox = false, silent = true, split = "topleft", - tab = 2, + tab = 1, unsilent = false, verbose = 15, vertical = false, @@ -3503,7 +3503,7 @@ describe('API', function() verbose = 0, vertical = false, }, - }, meths.parse_cmd('0verbose unsilent botright confirm filter! /foo/ split foo.txt', {})) + }, meths.parse_cmd('0verbose unsilent botright 0tab confirm filter! /foo/ split foo.txt', {})) end) it('works with user commands', function() command('command -bang -nargs=+ -range -addr=lines MyCommand echo foo') @@ -3541,7 +3541,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3583,7 +3583,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3626,7 +3626,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, @@ -3719,7 +3719,7 @@ describe('API', function() sandbox = false, silent = false, split = "", - tab = 0, + tab = -1, unsilent = false, verbose = -1, vertical = false, -- cgit From a5fe7940c8b9436b78ae408eae8345266423f2c8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 11:32:56 +0800 Subject: feat(ui-ext): make 'mousemoveevent' a ui_option --- test/functional/ui/options_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua index 8d7c404637..bd0d2104db 100644 --- a/test/functional/ui/options_spec.lua +++ b/test/functional/ui/options_spec.lua @@ -19,6 +19,7 @@ describe('UI receives option updates', function() linespace=0, pumblend=0, mousefocus=false, + mousemoveevent=false, showtabline=1, termguicolors=false, ttimeout=true, @@ -131,6 +132,12 @@ describe('UI receives option updates', function() eq(expected, screen.options) end) + command("set mousemoveevent") + expected.mousemoveevent = true + screen:expect(function() + eq(expected, screen.options) + end) + command("set nottimeout") expected.ttimeout = false screen:expect(function() -- cgit From 04bd700ac3bc2bdea0e0d8747de95dab2034aa11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 11:26:54 +0800 Subject: feat(tui): support 'mousemoveevent' --- test/functional/ui/popupmenu_spec.lua | 40 +++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index dcd4ad3d9a..bcd146e40d 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -2755,7 +2755,7 @@ describe('builtin popupmenu', function() menu PopUp.bar :let g:menustr = 'bar' menu PopUp.baz :let g:menustr = 'baz' ]]) - meths.input_mouse('right', 'press', '', 0, 0, 4) + feed('<4,0>') screen:expect([[ ^popup menu test | {1:~ }{n: foo }{1: }| @@ -2792,7 +2792,7 @@ describe('builtin popupmenu', function() :let g:menustr = 'bar' | ]]) eq('bar', meths.get_var('menustr')) - meths.input_mouse('right', 'press', '', 0, 1, 20) + feed('<20,1>') screen:expect([[ ^popup menu test | {1:~ }| @@ -2801,7 +2801,7 @@ describe('builtin popupmenu', function() {1:~ }{n: baz }{1: }| :let g:menustr = 'bar' | ]]) - meths.input_mouse('left', 'press', '', 0, 4, 22) + feed('<22,4>') screen:expect([[ ^popup menu test | {1:~ }| @@ -2811,7 +2811,7 @@ describe('builtin popupmenu', function() :let g:menustr = 'baz' | ]]) eq('baz', meths.get_var('menustr')) - meths.input_mouse('right', 'press', '', 0, 0, 4) + feed('<4,0>') screen:expect([[ ^popup menu test | {1:~ }{n: foo }{1: }| @@ -2820,7 +2820,7 @@ describe('builtin popupmenu', function() {1:~ }| :let g:menustr = 'baz' | ]]) - meths.input_mouse('right', 'drag', '', 0, 3, 6) + feed('<6,3>') screen:expect([[ ^popup menu test | {1:~ }{n: foo }{1: }| @@ -2829,7 +2829,7 @@ describe('builtin popupmenu', function() {1:~ }| :let g:menustr = 'baz' | ]]) - meths.input_mouse('right', 'release', '', 0, 1, 6) + feed('<6,1>') screen:expect([[ ^popup menu test | {1:~ }| @@ -2839,6 +2839,34 @@ describe('builtin popupmenu', function() :let g:menustr = 'foo' | ]]) eq('foo', meths.get_var('menustr')) + feed('<4,0>') + screen:expect([[ + ^popup menu test | + {1:~ }{n: foo }{1: }| + {1:~ }{n: bar }{1: }| + {1:~ }{n: baz }{1: }| + {1:~ }| + :let g:menustr = 'foo' | + ]]) + feed('<6,3>') + screen:expect([[ + ^popup menu test | + {1:~ }{n: foo }{1: }| + {1:~ }{n: bar }{1: }| + {1:~ }{s: baz }{1: }| + {1:~ }| + :let g:menustr = 'foo' | + ]]) + feed('<6,2>') + screen:expect([[ + ^popup menu test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :let g:menustr = 'bar' | + ]]) + eq('bar', meths.get_var('menustr')) end) end) -- cgit From ceb09701f29dcabcf219f458fffbb64f5adced9b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 13:58:29 +0800 Subject: feat(api): add "move" to nvim_input_mouse --- test/functional/ui/mouse_spec.lua | 15 ++++++++- test/functional/ui/popupmenu_spec.lua | 63 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index 9896b11218..8c5475ecce 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -1585,7 +1585,20 @@ describe('ui/mouse/input', function() eq(0, meths.get_var('mouse_up2')) end) - it('feeding does not use uninitialized memory #19480', function() + it(' is not translated into multiclicks and can be mapped', function() + meths.set_var('mouse_move', 0) + meths.set_var('mouse_move2', 0) + command('nnoremap let g:mouse_move += 1') + command('nnoremap <2-MouseMove> let g:mouse_move2 += 1') + feed('<0,0>') + feed('<0,0>') + meths.input_mouse('move', '', '', 0, 0, 0) + meths.input_mouse('move', '', '', 0, 0, 0) + eq(4, meths.get_var('mouse_move')) + eq(0, meths.get_var('mouse_move2')) + end) + + it('feeding in Normal mode does not use uninitialized memory #19480', function() feed('') helpers.poke_eventloop() helpers.assert_alive() diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index bcd146e40d..b16e404ea8 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -3075,5 +3075,68 @@ describe('builtin popupmenu with ui/ext_multigrid', function() :let g:menustr = 'foo' | ]]}) eq('foo', meths.get_var('menustr')) + meths.input_mouse('right', 'press', '', 2, 0, 4) + screen:expect({grid=[[ + ## grid 1 + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [3:--------------------------------]| + ## grid 2 + ^popup menu test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + :let g:menustr = 'foo' | + ## grid 4 + {n: foo }| + {n: bar }| + {n: baz }| + ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}}) + meths.input_mouse('move', '', '', 2, 3, 6) + screen:expect({grid=[[ + ## grid 1 + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [3:--------------------------------]| + ## grid 2 + ^popup menu test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + :let g:menustr = 'foo' | + ## grid 4 + {n: foo }| + {n: bar }| + {s: baz }| + ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}}) + meths.input_mouse('left', 'press', '', 2, 2, 6) + screen:expect({grid=[[ + ## grid 1 + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [2:--------------------------------]| + [3:--------------------------------]| + ## grid 2 + ^popup menu test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + :let g:menustr = 'bar' | + ]]}) + eq('bar', meths.get_var('menustr')) end) end) -- cgit From 82d128405aaeb619a0c04353449f5717da126249 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 15:24:15 +0800 Subject: feat(pum): pretend 'mousemoveevent' is set when showing right-click menu --- test/functional/terminal/tui_spec.lua | 52 +++++++++++++++++++++++++++++++++++ test/functional/ui/popupmenu_spec.lua | 8 ++++++ 2 files changed, 60 insertions(+) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 4f444316c3..3c56ad5f79 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -21,6 +21,7 @@ local nvim_set = helpers.nvim_set local ok = helpers.ok local read_file = helpers.read_file local funcs = helpers.funcs +local meths = helpers.meths if helpers.pending_win32(pending) then return end @@ -666,6 +667,57 @@ describe('TUI', function() ]], attrs) end) + it('mouse events work with right-click menu', function() + child_session:request('nvim_command', [[ + call setline(1, 'popup menu test') + set mouse=a mousemodel=popup + + aunmenu PopUp + menu PopUp.foo :let g:menustr = 'foo' + menu PopUp.bar :let g:menustr = 'bar' + menu PopUp.baz :let g:menustr = 'baz' + highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse + highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold + ]]) + local attrs = screen:get_default_attr_ids() + attrs[11] = {underline = true, reverse = true} + attrs[12] = {underline = true, reverse = true, bold = true} + meths.input_mouse('right', 'press', '', 0, 0, 4) + screen:expect([[ + {1:p}opup menu test | + {4:~ }{11: foo }{4: }| + {4:~ }{11: bar }{4: }| + {4:~ }{11: baz }{4: }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} | + ]], attrs) + meths.input_mouse('right', 'release', '', 0, 0, 4) + screen:expect_unchanged() + meths.input_mouse('move', '', '', 0, 3, 6) + screen:expect([[ + {1:p}opup menu test | + {4:~ }{11: foo }{4: }| + {4:~ }{11: bar }{4: }| + {4:~ }{12: baz }{4: }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} | + ]], attrs) + meths.input_mouse('left', 'press', '', 0, 2, 6) + screen:expect([[ + {1:p}opup menu test | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + :let g:menustr = 'bar' | + {3:-- TERMINAL --} | + ]], attrs) + meths.input_mouse('left', 'release', '', 0, 2, 6) + screen:expect_unchanged() + end) + it('paste: Insert mode', function() -- "bracketed paste" feed_data('i""\027i\027[200~') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index b16e404ea8..3c752875f0 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -2839,6 +2839,7 @@ describe('builtin popupmenu', function() :let g:menustr = 'foo' | ]]) eq('foo', meths.get_var('menustr')) + eq(false, screen.options.mousemoveevent) feed('<4,0>') screen:expect([[ ^popup menu test | @@ -2848,6 +2849,7 @@ describe('builtin popupmenu', function() {1:~ }| :let g:menustr = 'foo' | ]]) + eq(true, screen.options.mousemoveevent) feed('<6,3>') screen:expect([[ ^popup menu test | @@ -2857,6 +2859,7 @@ describe('builtin popupmenu', function() {1:~ }| :let g:menustr = 'foo' | ]]) + eq(true, screen.options.mousemoveevent) feed('<6,2>') screen:expect([[ ^popup menu test | @@ -2866,6 +2869,7 @@ describe('builtin popupmenu', function() {1:~ }| :let g:menustr = 'bar' | ]]) + eq(false, screen.options.mousemoveevent) eq('bar', meths.get_var('menustr')) end) end) @@ -3075,6 +3079,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function() :let g:menustr = 'foo' | ]]}) eq('foo', meths.get_var('menustr')) + eq(false, screen.options.mousemoveevent) meths.input_mouse('right', 'press', '', 2, 0, 4) screen:expect({grid=[[ ## grid 1 @@ -3097,6 +3102,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function() {n: bar }| {n: baz }| ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}}) + eq(true, screen.options.mousemoveevent) meths.input_mouse('move', '', '', 2, 3, 6) screen:expect({grid=[[ ## grid 1 @@ -3119,6 +3125,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function() {n: bar }| {s: baz }| ]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}}) + eq(true, screen.options.mousemoveevent) meths.input_mouse('left', 'press', '', 2, 2, 6) screen:expect({grid=[[ ## grid 1 @@ -3137,6 +3144,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function() ## grid 3 :let g:menustr = 'bar' | ]]}) + eq(false, screen.options.mousemoveevent) eq('bar', meths.get_var('menustr')) end) end) -- cgit From 6254b0fd3bc725705020192dc9e35635136b9929 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 4 Sep 2022 16:13:37 +0200 Subject: ci(tests): don't skip parsers on functionaltest Treesitter parsers are now a mandatory part of the installation and should be tested on all platforms. Remove `pending_c_parser` helper. --- test/functional/helpers.lua | 10 ---------- test/functional/treesitter/highlight_spec.lua | 18 ------------------ test/functional/treesitter/language_spec.lua | 12 ++---------- test/functional/treesitter/node_spec.lua | 5 ----- test/functional/treesitter/parser_spec.lua | 3 --- test/functional/treesitter/utils_spec.lua | 2 -- 6 files changed, 2 insertions(+), 48 deletions(-) (limited to 'test/functional') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 93fb0f245e..d672037a1e 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -755,16 +755,6 @@ function module.pending_win32(pending_fn) end end -function module.pending_c_parser(pending_fn) - local status, _ = unpack(module.exec_lua([[ return {pcall(vim.treesitter.require_language, 'c')} ]])) - if not status then - pending_fn 'no C parser, skipping' - return true - end - module.exec_lua [[vim._ts_remove_language 'c']] - return false -end - -- Calls pending() and returns `true` if the system is too slow to -- run fragile or expensive tests. Else returns `false`. function module.skip_fragile(pending_fn, cond) diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index 4b0bd1eb50..5a1081592e 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -5,7 +5,6 @@ local clear = helpers.clear local insert = helpers.insert local exec_lua = helpers.exec_lua local feed = helpers.feed -local pending_c_parser = helpers.pending_c_parser local command = helpers.command local meths = helpers.meths local eq = helpers.eq @@ -111,8 +110,6 @@ describe('treesitter highlighting', function() end) it('is updated with edits', function() - if pending_c_parser(pending) then return end - insert(hl_text) screen:expect{grid=[[ /// Schedule Lua callback on main loop's event queue | @@ -276,8 +273,6 @@ describe('treesitter highlighting', function() end) it('is updated with :sort', function() - if pending_c_parser(pending) then return end - insert(test_text) exec_lua [[ local parser = vim.treesitter.get_parser(0, "c") @@ -351,8 +346,6 @@ describe('treesitter highlighting', function() end) it("supports with custom parser", function() - if pending_c_parser(pending) then return end - screen:set_default_attr_ids { [1] = {bold = true, foreground = Screen.colors.SeaGreen4}; } @@ -417,8 +410,6 @@ describe('treesitter highlighting', function() end) it("supports injected languages", function() - if pending_c_parser(pending) then return end - insert([[ int x = INT_MAX; #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) @@ -479,8 +470,6 @@ describe('treesitter highlighting', function() end) it("supports overriding queries, like ", function() - if pending_c_parser(pending) then return end - insert([[ int x = INT_MAX; #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) @@ -520,8 +509,6 @@ describe('treesitter highlighting', function() end) it("supports highlighting with custom highlight groups", function() - if pending_c_parser(pending) then return end - insert(hl_text) exec_lua [[ @@ -577,8 +564,6 @@ describe('treesitter highlighting', function() end) it("supports highlighting with priority", function() - if pending_c_parser(pending) then return end - insert([[ int x = INT_MAX; #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) @@ -625,8 +610,6 @@ describe('treesitter highlighting', function() end) it("allows to use captures with dots (don't use fallback when specialization of foo exists)", function() - if pending_c_parser(pending) then return end - insert([[ char* x = "Will somebody ever read this?"; ]]) @@ -708,7 +691,6 @@ describe('treesitter highlighting', function() end) it("supports conceal attribute", function() - if pending_c_parser(pending) then return end insert(hl_text) -- conceal can be empty or a single cchar. diff --git a/test/functional/treesitter/language_spec.lua b/test/functional/treesitter/language_spec.lua index 8e9941d797..ed84dedb5a 100644 --- a/test/functional/treesitter/language_spec.lua +++ b/test/functional/treesitter/language_spec.lua @@ -6,7 +6,6 @@ local command = helpers.command local exec_lua = helpers.exec_lua local pcall_err = helpers.pcall_err local matches = helpers.matches -local pending_c_parser = helpers.pending_c_parser local insert = helpers.insert before_each(clear) @@ -28,15 +27,11 @@ describe('treesitter language API', function() eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", pcall_err(exec_lua, "parser = vim.treesitter.inspect_language('borklang')")) - if not pending_c_parser(pending) then - matches("Error executing lua: Failed to load parser: uv_dlsym: .+", - pcall_err(exec_lua, 'vim.treesitter.require_language("c", nil, false, "borklang")')) - end + matches("Error executing lua: Failed to load parser: uv_dlsym: .+", + pcall_err(exec_lua, 'vim.treesitter.require_language("c", nil, false, "borklang")')) end) it('inspects language', function() - if pending_c_parser(pending) then return end - local keys, fields, symbols = unpack(exec_lua([[ local lang = vim.treesitter.inspect_language('c') local keys, symbols = {}, {} @@ -76,7 +71,6 @@ describe('treesitter language API', function() end) it('checks if vim.treesitter.get_parser tries to create a new parser on filetype change', function () - if pending_c_parser(pending) then return end command("set filetype=c") -- Should not throw an error when filetype is c eq('c', exec_lua("return vim.treesitter.get_parser(0):lang()")) @@ -87,7 +81,6 @@ describe('treesitter language API', function() end) it('retrieve the tree given a range', function () - if pending_c_parser(pending) then return end insert([[ int main() { int x = 3; @@ -102,7 +95,6 @@ describe('treesitter language API', function() end) it('retrieve the node given a range', function () - if pending_c_parser(pending) then return end insert([[ int main() { int x = 3; diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index 87ce1b973c..a82dce47b7 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -4,7 +4,6 @@ local clear = helpers.clear local eq = helpers.eq local exec_lua = helpers.exec_lua local insert = helpers.insert -local pending_c_parser = helpers.pending_c_parser before_each(clear) @@ -15,10 +14,6 @@ end describe('treesitter node API', function() clear() - if pending_c_parser(pending) then - return - end - it('can move between siblings', function() insert([[ int main(int x, int y, int z) { diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua index 7f3b0e770a..ccbd55df0e 100644 --- a/test/functional/treesitter/parser_spec.lua +++ b/test/functional/treesitter/parser_spec.lua @@ -5,13 +5,11 @@ local eq = helpers.eq local insert = helpers.insert local exec_lua = helpers.exec_lua local feed = helpers.feed -local pending_c_parser = helpers.pending_c_parser before_each(clear) describe('treesitter parser API', function() clear() - if pending_c_parser(pending) then return end it('parses buffer', function() if helpers.pending_win32(pending) then return end @@ -249,7 +247,6 @@ void ui_refresh(void) end) it('supports getting text of multiline node', function() - if pending_c_parser(pending) then return end insert(test_text) local res = exec_lua([[ local parser = vim.treesitter.get_parser(0, "c") diff --git a/test/functional/treesitter/utils_spec.lua b/test/functional/treesitter/utils_spec.lua index 4f4c18a748..7f5a864c3d 100644 --- a/test/functional/treesitter/utils_spec.lua +++ b/test/functional/treesitter/utils_spec.lua @@ -4,7 +4,6 @@ local clear = helpers.clear local insert = helpers.insert local eq = helpers.eq local exec_lua = helpers.exec_lua -local pending_c_parser = helpers.pending_c_parser before_each(clear) @@ -12,7 +11,6 @@ describe('treesitter utils', function() before_each(clear) it('can find an ancestor', function() - if pending_c_parser(pending) then return end insert([[ int main() { -- cgit From 64cc78c9f39b3066b74f01ec7e3f50fd316416e4 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 4 Sep 2022 16:37:24 +0200 Subject: feat(treesitter): add injections --- test/functional/treesitter/highlight_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index 5a1081592e..5e38a8c2df 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -579,9 +579,9 @@ describe('treesitter highlighting', function() -- expect everything to have Error highlight screen:expect{grid=[[ {12:int}{8: x = INT_MAX;} | - {8:#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))}| - {8:#define foo void main() { \} | - {8: return 42; \} | + {8:#define READ_STRING(x, y) (}{12:char_u}{8: *)read_string((x), (}{12:size_t}{8:)(y))}| + {8:#define foo }{12:void}{8: main() { \} | + {8: }{12:return}{8: 42; \} | {8: }} | ^ | {1:~ }| -- cgit From 97f38f0a9bbae4969f672746a62caa6cba136b45 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 4 Sep 2022 17:58:33 +0200 Subject: fix(treesitter): do not link @error by default The @error capture is used for tree-sitter's ERROR node, which indicates a parsing error -- which can be quite frequent (and jarring) while typing. Users can still manually `hi link @error Error` in their config. --- test/functional/treesitter/highlight_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional') diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index 5e38a8c2df..d557b2c012 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -106,6 +106,7 @@ describe('treesitter highlighting', function() } exec_lua([[ hl_query = ... ]], hl_query) + command [[ hi link @error ErrorMsg ]] command [[ hi link @warning WarningMsg ]] end) -- cgit From 75adfefc85bcf0d62d2c0f51a951e6003b595cea Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Mon, 18 Jul 2022 14:21:40 +0200 Subject: feat(extmarks,ts,spell): full support for spelling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added 'spell' option to extmarks: Extmarks with this set will have the region spellchecked. - Added 'noplainbuffer' option to 'spelloptions': This is used to tell Neovim not to spellcheck the buffer. The old behaviour was to spell check the whole buffer unless :syntax was set. - Added spelling support to the treesitter highlighter: @spell captures in highlights.scm are used to define regions which should be spell checked. - Added support for navigating spell errors for extmarks: Works for both ephemeral and static extmarks - Added '_on_spell_nav' callback for decoration providers: Since ephemeral callbacks are only drawn for the visible screen, providers must implement this callback to instruct Neovim which regions in the buffer need can be spell checked. The callback takes a start position and an end position. Note: this callback is subject to change hence the _ prefix. - Added spell captures for built-in support languages Co-authored-by: Lewis Russell Co-authored-by: Björn Linse --- test/functional/ui/decorations_spec.lua | 86 +++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 789f1c6487..db5a775632 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -31,6 +31,8 @@ describe('decorations providers', function() [12] = {foreground = tonumber('0x990000')}; [13] = {background = Screen.colors.LightBlue}; [14] = {background = Screen.colors.WebGray, foreground = Screen.colors.DarkBlue}; + [15] = {special = Screen.colors.Blue1, undercurl = true}, + [16] = {special = Screen.colors.Red, undercurl = true}, } end) @@ -56,7 +58,7 @@ describe('decorations providers', function() a.nvim_set_decoration_provider(_G.ns1, { on_start = on_do; on_buf = on_do; on_win = on_do; on_line = on_do; - on_end = on_do; + on_end = on_do; _on_spell_nav = on_do; }) return _G.ns1 ]]) @@ -95,7 +97,7 @@ describe('decorations providers', function() | ]]} check_trace { - { "start", 4, 40 }; + { "start", 4 }; { "win", 1000, 1, 0, 8 }; { "line", 1000, 1, 0 }; { "line", 1000, 1, 1 }; @@ -119,7 +121,7 @@ describe('decorations providers', function() | ]]} check_trace { - { "start", 5, 10 }; + { "start", 5 }; { "buf", 1 }; { "win", 1000, 1, 0, 8 }; { "line", 1000, 1, 6 }; @@ -156,6 +158,84 @@ describe('decorations providers', function() ]]} end) + it('can indicate spellchecked points', function() + exec [[ + set spell + set spelloptions=noplainbuffer + syntax off + ]] + + insert [[ + I am well written text. + i am not capitalized. + I am a speling mistakke. + ]] + + setup_provider [[ + local ns = a.nvim_create_namespace "spell" + beamtrace = {} + local function on_do(kind, ...) + if kind == 'win' or kind == 'spell' then + a.nvim_buf_set_extmark(0, ns, 0, 0, { end_row = 2, end_col = 23, spell = true, ephemeral = true }) + end + table.insert(beamtrace, {kind, ...}) + end + ]] + + check_trace { + { "start", 5 }; + { "win", 1000, 1, 0, 5 }; + { "line", 1000, 1, 0 }; + { "line", 1000, 1, 1 }; + { "line", 1000, 1, 2 }; + { "line", 1000, 1, 3 }; + { "end", 5 }; + } + + feed "gg0" + + screen:expect{grid=[[ + ^I am well written text. | + {15:i} am not capitalized. | + I am a {16:speling} {16:mistakke}. | + | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + feed "]s" + check_trace { + { "spell", 1000, 1, 1, 0, 1, -1 }; + } + screen:expect{grid=[[ + I am well written text. | + {15:^i} am not capitalized. | + I am a {16:speling} {16:mistakke}. | + | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + feed "]s" + check_trace { + { "spell", 1000, 1, 2, 7, 2, -1 }; + } + screen:expect{grid=[[ + I am well written text. | + {15:i} am not capitalized. | + I am a {16:^speling} {16:mistakke}. | + | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + end) + it('can predefine highlights', function() screen:try_resize(40, 16) insert(mulholland) -- cgit From b76e33b5989dcdbc48cdb6f099c9c0c917efa610 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 9 Feb 2022 08:46:37 +0100 Subject: fix(terminal): adopt altscreen test for libvterm 0.2 changes Due to a rewrite of the resize handling logic in libvterm, the behavior changed. It's actually fixing a bug. https://github.com/cryptomilk/libvterm/commit/16b857457575c3fd6ffdb0866d7a190b69c28312 --- test/functional/terminal/altscreen_spec.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/altscreen_spec.lua b/test/functional/terminal/altscreen_spec.lua index 155a156d15..e4e1aa5fa2 100644 --- a/test/functional/terminal/altscreen_spec.lua +++ b/test/functional/terminal/altscreen_spec.lua @@ -126,13 +126,13 @@ describe(':terminal altscreen', function() wait_removal() feed('4k') screen:expect([[ - ^line3 | + ^ | | | rows: 4, cols: 50 | | ]]) - eq(8, curbuf('line_count')) + eq(9, curbuf('line_count')) end) describe('and after exit', function() @@ -142,15 +142,11 @@ describe(':terminal altscreen', function() end) it('restore buffer state', function() - -- FIXME(tarruda): Note that the last line was lost after restoring the - -- screen. This is a libvterm bug: When the main screen is restored it - -- seems to "cut" lines that would have been left below the new visible - -- screen. screen:expect([[ - line4 | line5 | line6 | line7 | + line8 | {3:-- TERMINAL --} | ]]) end) -- cgit From f32fd19f1eedbd75e6a37b73f28cf8761e0e875c Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Wed, 7 Sep 2022 03:55:03 +0100 Subject: fix(diagnostic): remove buf from cache on `BufWipeout` (#20099) Doing so on `BufDelete` has issues: - `BufDelete` is also fired for listed buffers that are made unlisted. - `BufDelete` is not fired for unlisted buffers that are deleted. This means that diagnostics will be lost for a buffer that becomes unlisted. It also means that if an entry exists for an unlisted buffer, deleting that buffer later will not remove its entry from the cache (and you may see "Invalid buffer id" errors when using diagnostic functions if it was wiped). Instead, remove a buffer from the cache if it is wiped out. This means simply `:bd`ing a buffer will not clear its diagnostics now. --- test/functional/lua/diagnostic_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 4226bcebac..1514dadca8 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -148,6 +148,15 @@ describe('vim.diagnostic', function() vim.cmd('bwipeout!') return #vim.diagnostic.get() ]]) + eq(2, exec_lua [[ + vim.api.nvim_set_current_buf(diagnostic_bufnr) + vim.opt_local.buflisted = false + return #vim.diagnostic.get() + ]]) + eq(0, exec_lua [[ + vim.cmd('bwipeout!') + return #vim.diagnostic.get() + ]]) end) it('resolves buffer number 0 to the current buffer', function() -- cgit From fd1595514b747d8b083f78007579d869ccfbe89c Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Wed, 7 Sep 2022 08:39:56 +0200 Subject: Use weak tables in tree-sitter code (#17117) feat(treesitter): use weak tables when possible Also add the defaulttable function to create a table whose values are created when a key is missing. --- test/functional/lua/vim_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index f2fb661b70..cd3240cd30 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2754,6 +2754,24 @@ describe('lua stdlib', function() end) + describe("vim.defaulttable", function() + it("creates nested table by default", function() + eq({ b = {c = 1 } }, exec_lua[[ + local a = vim.defaulttable() + a.b.c = 1 + return a + ]]) + end) + + it("allows to create default objects", function() + eq({ b = 1 }, exec_lua[[ + local a = vim.defaulttable(function() return 0 end) + a.b = a.b + 1 + return a + ]]) + end) + end) + end) describe('lua: builtin modules', function() -- cgit From 4dc4cf346755375e49410e16635c00a602b26c36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Wed, 7 Sep 2022 17:59:27 +0200 Subject: fix(options): mark `winhighlight` as list style (#19477) Also add missing fcs, lcs and winhighlight to list of key-value options for `vim.opt`. Co-authored-by: ii14 --- test/functional/api/vim_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index edbdd54c2f..44775ef85c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2732,8 +2732,8 @@ describe('API', function() it('should have information about window options', function() eq({ - allows_duplicates = true, - commalist = false; + allows_duplicates = false, + commalist = true; default = ""; flaglist = false; global_local = false; -- cgit From 4a67f9d386bb16149eecf32f45a3cb73878f12e7 Mon Sep 17 00:00:00 2001 From: ii14 Date: Wed, 7 Sep 2022 20:45:22 +0200 Subject: vim-patch:9.0.0409: #{g:x} was seen as a curly-braces expression Problem: #{g:x} was seen as a curly-braces expression. Solution: Do never see #{} as a curly-braces expression. (closes vim/vim#11075) https://github.com/vim/vim/commit/7c7e1e9b98d4e5dbe7358c795a635c6f1f36f418 --- test/functional/ex_cmds/source_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index cd1f43f9fd..10ebefd8cd 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -104,7 +104,7 @@ describe(':source', function() eq("0zBEEFCAFE", meths.exec('echo d', true)) exec('set cpoptions+=C') - eq('Vim(let):E15: Invalid expression: #{', exc_exec('source')) + eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source')) end) it('selection in current buffer', function() @@ -138,7 +138,7 @@ describe(':source', function() eq('Vim(echo):E117: Unknown function: s:C', exc_exec('echo D()')) exec('set cpoptions+=C') - eq('Vim(let):E15: Invalid expression: #{', exc_exec("'<,'>source")) + eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec("'<,'>source")) end) it('does not break if current buffer is modified while sourced', function() -- cgit From 11167ab6d569994dd0a4f58155c84b118706380c Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Thu, 8 Sep 2022 11:33:04 +0200 Subject: feat(lsp): add range option to lsp.buf.format (#19998) --- test/functional/plugin/lsp_spec.lua | 48 ++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index fa731f6faf..9da2c4aa61 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3180,8 +3180,54 @@ describe('LSP', function() end, } end) + it('format formats range in visual mode', function() + local result = exec_lua([[ + local messages = {} + local server = function(dispatchers) + local closing = false + return { + request = function(method, params, callback) + table.insert(messages, { + method = method, + params = params, + }) + if method == 'initialize' then + callback(nil, { + capabilities = { + documentFormattingProvider = true, + documentRangeFormattingProvider = true, + } + }) + end + end, + notify = function(...) + end, + is_closing = function() + return closing + end, + terminate = function() + closing = true + end + } + end + local bufnr = vim.api.nvim_get_current_buf() + local client_id = vim.lsp.start({ name = 'dummy', cmd = server }) + vim.api.nvim_win_set_buf(0, bufnr) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, {'foo', 'bar'}) + vim.api.nvim_win_set_cursor(0, { 1, 0 }) + vim.cmd.normal('v') + vim.api.nvim_win_set_cursor(0, { 2, 3 }) + vim.lsp.buf.format({ bufnr = bufnr, false }) + return messages + ]]) + eq("textDocument/rangeFormatting", result[2].method) + local expected_range = { + start = { line = 0, character = 0 }, + ['end'] = { line = 1, character = 4 }, + } + eq(expected_range, result[2].params.range) + end) end) - describe('cmd', function() it('can connect to lsp server via rpc.connect', function() local result = exec_lua [[ -- cgit From 30ca6d23a9c77175a76a4cd59da81de83d9253af Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 8 Sep 2022 23:09:32 +0800 Subject: fix(lsp): when buffer detach remove buffer from client attached buffers (#20081) Co-authored-by: Mathias Fussenegger --- test/functional/plugin/lsp_spec.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 9da2c4aa61..e0035e2e8b 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -418,6 +418,42 @@ describe('LSP', function() } end) + it('should detach buffer on bufwipe', function() + local result = exec_lua([[ + local server = function(dispatchers) + local closing = false + return { + request = function(method, params, callback) + if method == 'initialize' then + callback(nil, { capabilities = {} }) + end + end, + notify = function(...) + end, + is_closing = function() return closing end, + terminate = function() closing = true end + } + end + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_set_current_buf(bufnr) + local client_id = vim.lsp.start({ name = 'detach-dummy', cmd = server }) + assert(client_id, "lsp.start must return client_id") + local client = vim.lsp.get_client_by_id(client_id) + local num_attached_before = vim.tbl_count(client.attached_buffers) + vim.api.nvim_buf_delete(bufnr, { force = true }) + local num_attached_after = vim.tbl_count(client.attached_buffers) + return { + bufnr = bufnr, + client_id = client_id, + num_attached_before = num_attached_before, + num_attached_after = num_attached_after, + } + ]]) + eq(true, result ~= nil, "exec_lua must return result") + eq(1, result.num_attached_before) + eq(0, result.num_attached_after) + end) + it('client should return settings via workspace/configuration handler', function() local expected_handlers = { {NIL, {}, {method="shutdown", client_id=1}}; -- cgit From 2d6735d8cecc587eb5549f65260ee9ddeb8e1d78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 9 Sep 2022 00:12:42 +0200 Subject: ci: move BSD jobs from sourcehut to Cirrus CI #19616 dispatch.sr.ht is being deprecated, meaning that using sourcehut CI won't be possible (see https://github.com/neovim/neovim/issues/19609). Since Github Actions doesn't provide any BSD runners an external service is required and Cirrus CI seems like a good replacement for sourcehut. Initially experimented with using FreeBSD and OpenBSD virtual machines in GitHub Actions, but Cirrus has been a much better fit with better performance, logs and overall experience. Failing tests are automatically skipped on FreeBSD regardless if it's on CI or not. Ideally these tests should only be skipped in CI with the help of `isCI` helper function. Unfortunately, the tests don't recognize the environment variable CIRRUS_CI even if it's set manually. This workaround is good enough for the time being, but we might want to only skip tests when using the CI (or even better, fix the failing tests). Closes: https://github.com/neovim/neovim/issues/19609 --- test/functional/api/server_notifications_spec.lua | 4 ++++ test/functional/core/fileio_spec.lua | 7 +++++++ test/functional/ex_cmds/write_spec.lua | 7 +++++++ test/functional/terminal/ex_terminal_spec.lua | 4 ++++ 4 files changed, 22 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 1c00f001ff..1c554b05a3 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -7,6 +7,7 @@ local exec_lua = helpers.exec_lua local retry = helpers.retry local isCI = helpers.isCI local assert_alive = helpers.assert_alive +local uname = helpers.uname describe('notify', function() local channel @@ -78,6 +79,9 @@ describe('notify', function() end) it('cancels stale events on channel close', function() + if uname() == 'freebsd' then + pending('Failing FreeBSD test') + end if isCI() then pending('hangs on CI #14083 #15251') return diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index a4d22685e8..e71131dcf8 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -23,6 +23,7 @@ local iswin = helpers.iswin local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit local write_file = helpers.write_file +local uname = helpers.uname describe('fileio', function() before_each(function() @@ -83,6 +84,9 @@ describe('fileio', function() end) it('backup #9709', function() + if uname() == 'freebsd' then + pending('Failing FreeBSD test') + end clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) @@ -102,6 +106,9 @@ describe('fileio', function() end) it('backup with full path #11214', function() + if uname() == 'freebsd' then + pending('Failing FreeBSD test') + end clear() mkdir('Xtest_backupdir') command('set backup') diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 32fe397c03..14035a4341 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -9,6 +9,7 @@ local feed_command = helpers.feed_command local funcs = helpers.funcs local meths = helpers.meths local iswin = helpers.iswin +local uname = helpers.uname local fname = 'Xtest-functional-ex_cmds-write' local fname_bak = fname .. '~' @@ -52,6 +53,9 @@ describe(':write', function() end) it('&backupcopy=no replaces symlink with new file', function() + if uname() == 'freebsd' then + pending('Failing FreeBSD test') + end command('set backupcopy=no') write_file('test_bkc_file.txt', 'content0') if iswin() then @@ -91,6 +95,9 @@ describe(':write', function() end) it('errors out correctly', function() + if uname() == 'freebsd' then + pending('Failing FreeBSD test') + end command('let $HOME=""') eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) -- Message from check_overwrite diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 23b69319f0..36f9f90143 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -10,6 +10,7 @@ local retry = helpers.retry local ok = helpers.ok local iswin = helpers.iswin local command = helpers.command +local uname = helpers.uname describe(':terminal', function() local screen @@ -45,6 +46,9 @@ describe(':terminal', function() end) it("reads output buffer on terminal reporting #4151", function() + if uname() == 'freebsd' then + pending('Failing FreeBSD test') + end if helpers.pending_win32(pending) then return end if iswin() then feed_command([[terminal powershell -NoProfile -NoLogo -Command Write-Host -NoNewline "\"$([char]27)[6n\""; Start-Sleep -Milliseconds 500 ]]) -- cgit From 7533ceec13a1dd9a1e46a523975bddf52f533a93 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 8 Sep 2022 15:56:35 +0100 Subject: refactor(vim.opt): unify vim.bo/wo building --- test/functional/lua/vim_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index cd3240cd30..2466e9cc31 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1396,7 +1396,7 @@ describe('lua stdlib', function() ]] eq('', funcs.luaeval "vim.bo.filetype") eq(true, funcs.luaeval "vim.bo[BUF].modifiable") - matches("unknown option 'nosuchopt'$", + matches("no such option: 'nosuchopt'$", pcall_err(exec_lua, 'return vim.bo.nosuchopt')) matches("Expected lua string$", pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) @@ -1417,7 +1417,7 @@ describe('lua stdlib', function() eq(0, funcs.luaeval "vim.wo.cole") eq(0, funcs.luaeval "vim.wo[0].cole") eq(0, funcs.luaeval "vim.wo[1001].cole") - matches("unknown option 'notanopt'$", + matches("no such option: 'notanopt'$", pcall_err(exec_lua, 'return vim.wo.notanopt')) matches("Expected lua string$", pcall_err(exec_lua, 'return vim.wo[0][0].list')) -- cgit From 38059b4f31d8c9374002e209bc9ee2df28ac17fa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Sep 2022 14:03:32 +0800 Subject: vim-patch:8.2.2646: Vim9: error for not using string doesn't mention argument Problem: Vim9: error for not using string doesn't mention argument. Solution: Add argument number. https://github.com/vim/vim/commit/f28f2ac425600b88da0bdcc12a82cd620f575681 --- test/functional/vimscript/executable_spec.lua | 6 ++++-- test/functional/vimscript/exepath_spec.lua | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'test/functional') diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua index b4162b2336..b49eb09512 100644 --- a/test/functional/vimscript/executable_spec.lua +++ b/test/functional/vimscript/executable_spec.lua @@ -34,11 +34,13 @@ describe('executable()', function() it('fails for invalid values', function() for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do - eq('Vim(call):E928: String required', exc_exec('call executable('..input..')')) + eq('Vim(call):E1174: String required for argument 1', + exc_exec('call executable('..input..')')) end command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') for _, input in ipairs({'v:null', 'v:true', 'v:false'}) do - eq('Vim(call):E928: String required', exc_exec('call executable('..input..')')) + eq('Vim(call):E1174: String required for argument 1', + exc_exec('call executable('..input..')')) end end) diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua index bbca954511..439dd96fcd 100644 --- a/test/functional/vimscript/exepath_spec.lua +++ b/test/functional/vimscript/exepath_spec.lua @@ -21,12 +21,12 @@ describe('exepath()', function() it('fails for invalid values', function() for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do - eq('Vim(call):E928: String required', exc_exec('call exepath('..input..')')) + eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')')) end - eq('Vim(call):E1142: Non-empty string required', exc_exec('call exepath("")')) + eq('Vim(call):E1142: Non-empty string required for argument 1', exc_exec('call exepath("")')) command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') for _, input in ipairs({'v:null', 'v:true', 'v:false'}) do - eq('Vim(call):E928: String required', exc_exec('call exepath('..input..')')) + eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')')) end end) -- cgit From 91a150d0a9f81d8db34ba45de2a8a270010e2f3a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 13 Sep 2022 06:01:35 +0800 Subject: test(lsp): call clear() before bufwipe test (#20170) Otherwise this test cannot be run alone, and fails frequently on CI. --- test/functional/plugin/lsp_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index e0035e2e8b..395f8ed32a 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -419,6 +419,7 @@ describe('LSP', function() end) it('should detach buffer on bufwipe', function() + clear() local result = exec_lua([[ local server = function(dispatchers) local closing = false -- cgit From f19e91acd8b90eaddaaa6070db260acf8de9aa10 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 13 Sep 2022 22:08:01 +0800 Subject: vim-patch:9.0.0457: substitute prompt does not highlight an empty match (#20186) Problem: Substitute prompt does not highlight an empty match. Solution: Highlight at least one character. https://github.com/vim/vim/commit/a04f457a6c071179bac4088c9314007d39d5c5e0 --- test/functional/legacy/080_substitute_spec.lua | 162 --------------------- test/functional/legacy/substitute_spec.lua | 189 +++++++++++++++++++++++++ 2 files changed, 189 insertions(+), 162 deletions(-) delete mode 100644 test/functional/legacy/080_substitute_spec.lua create mode 100644 test/functional/legacy/substitute_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/080_substitute_spec.lua b/test/functional/legacy/080_substitute_spec.lua deleted file mode 100644 index faeb61e3af..0000000000 --- a/test/functional/legacy/080_substitute_spec.lua +++ /dev/null @@ -1,162 +0,0 @@ --- Test for *sub-replace-special* and *sub-replace-expression* on substitute(). --- Test for submatch() on substitute(). --- Test for *:s%* on :substitute. - -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect -local eq, eval = helpers.eq, helpers.eval - -describe('substitue()', function() - before_each(clear) - - -- The original test contained several TEST_X lines to delimit different - -- parts. These where used to split the test into different it() blocks. - -- The TEST_X strings are repeated in the description of the blocks to make - -- it easier to incorporate upstream changes. - - local function test_1_and_2() - eq('AA', eval("substitute('A', 'A', '&&', '')")) - eq('&', eval([[substitute('B', 'B', '\&', '')]])) - eq('C123456789987654321', eval([[substitute('C123456789', ]] .. - [['C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. - [['\0\9\8\7\6\5\4\3\2\1', '')]])) - eq('d', eval("substitute('D', 'D', 'd', '')")) - eq('~', eval("substitute('E', 'E', '~', '')")) - eq('~', eval([[substitute('F', 'F', '\~', '')]])) - eq('Gg', eval([[substitute('G', 'G', '\ugg', '')]])) - eq('Hh', eval([[substitute('H', 'H', '\Uh\Eh', '')]])) - eq('iI', eval([[substitute('I', 'I', '\lII', '')]])) - eq('jJ', eval([[substitute('J', 'J', '\LJ\EJ', '')]])) - eq('Kk', eval([[substitute('K', 'K', '\Uk\ek', '')]])) - eq('l\rl', eval("substitute('lLl', 'L', '\r', '')")) - eq('m\rm', eval([[substitute('mMm', 'M', '\r', '')]])) - eq('n\rn', eval("substitute('nNn', 'N', '\\\r', '')")) - eq('o\no', eval([[substitute('oOo', 'O', '\n', '')]])) - eq('p\bp', eval([[substitute('pPp', 'P', '\b', '')]])) - eq('q\tq', eval([[substitute('qQq', 'Q', '\t', '')]])) - eq('r\\r', eval([[substitute('rRr', 'R', '\\', '')]])) - eq('scs', eval([[substitute('sSs', 'S', '\c', '')]])) - eq('t\rt', eval([[substitute('tTt', 'T', "\r", '')]])) - eq('u\nu', eval([[substitute('uUu', 'U', "\n", '')]])) - eq('v\bv', eval([[substitute('vVv', 'V', "\b", '')]])) - eq('w\\w', eval([[substitute('wWw', 'W', "\\", '')]])) - eq('XxxX', eval([[substitute('X', 'X', '\L\uxXx\l\EX', '')]])) - eq('yYYy', eval([[substitute('Y', 'Y', '\U\lYyY\u\Ey', '')]])) - end - - it('with "set magic" (TEST_1)', function() - feed_command('set magic') - test_1_and_2() - end) - - it('with "set nomagic" (TEST_2)', function() - feed_command('set nomagic') - test_1_and_2() - end) - - it('with sub-replace-expression (TEST_3)', function() - feed_command('set magic&') - eq('a\\a', eval([[substitute('aAa', 'A', '\="\\"', '')]])) - eq('b\\\\b', eval([[substitute('bBb', 'B', '\="\\\\"', '')]])) - eq('c\rc', eval([[substitute('cCc', 'C', '\="]]..'\r'..[["', '')]])) - eq('d\\\rd', eval([[substitute('dDd', 'D', '\="\\]]..'\r'..[["', '')]])) - eq('e\\\\\re', - eval([[substitute('eEe', 'E', '\="\\\\]]..'\r'..[["', '')]])) - eq('f\\rf', eval([[substitute('fFf', 'F', '\="\\r"', '')]])) - eq('j\\nj', eval([[substitute('jJj', 'J', '\="\\n"', '')]])) - eq('k\rk', eval([[substitute('kKk', 'K', '\="\r"', '')]])) - eq('l\nl', eval([[substitute('lLl', 'L', '\="\n"', '')]])) - end) - - it('with submatch() (TEST_4)', function() - feed_command('set magic&') - eq('a\\a', eval([[substitute('aAa', 'A', ]] .. - [['\=substitute(submatch(0), ".", "\\", "")', '')]])) - eq('b\\b', eval([[substitute('bBb', 'B', ]] .. - [['\=substitute(submatch(0), ".", "\\\\", "")', '')]])) - eq('c\rc', eval([[substitute('cCc', 'C', ]] .. - [['\=substitute(submatch(0), ".", "]]..'\r'..[[", "")', '')]])) - eq('d\rd', eval([[substitute('dDd', 'D', ]] .. - [['\=substitute(submatch(0), ".", "\\]]..'\r'..[[", "")', '')]])) - eq('e\\\re', eval([[substitute('eEe', 'E', ]] .. - [['\=substitute(submatch(0), ".", "\\\\]]..'\r'..[[", "")', '')]])) - eq('f\rf', eval([[substitute('fFf', 'F', ]] .. - [['\=substitute(submatch(0), ".", "\\r", "")', '')]])) - eq('j\nj', eval([[substitute('jJj', 'J', ]] .. - [['\=substitute(submatch(0), ".", "\\n", "")', '')]])) - eq('k\rk', eval([[substitute('kKk', 'K', ]] .. - [['\=substitute(submatch(0), ".", "\r", "")', '')]])) - eq('l\nl', eval([[substitute('lLl', 'L', ]] .. - [['\=substitute(submatch(0), ".", "\n", "")', '')]])) - end) - - it('with submatch() (TEST_5)', function() - feed_command('set magic&') - eq('A123456789987654321', eval([[substitute('A123456789', ]] .. - [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. - [['\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . ]] .. - [[submatch(6) . submatch(5) . submatch(4) . submatch(3) . ]] .. - [[submatch(2) . submatch(1)', '')]])) - eq("[['A123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], " .. - "['2'], ['1']]", eval([[substitute('A123456789', ]] .. - [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. - [['\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), ]] .. - [[submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), ]] .. - [[submatch(3, 1), submatch(2, 1), submatch(1, 1)])', '')]])) - end) - - -- TEST_6 was about the 'cpoptions' flag / which was removed in pull request - -- #2943. - - it('with submatch or \\ze (TEST_7)', function() - feed_command('set magic&') - eq('A\rA', eval("substitute('A\rA', 'A.', '\\=submatch(0)', '')")) - eq('B\nB', eval([[substitute("B\nB", 'B.', '\=submatch(0)', '')]])) - eq("['B\n']B", - eval([[substitute("B\nB", 'B.', '\=string(submatch(0, 1))', '')]])) - eq('-abab', eval([[substitute('-bb', '\zeb', 'a', 'g')]])) - eq('c-cbcbc', eval([[substitute('-bb', '\ze', 'c', 'g')]])) - end) - - it('with \\zs and \\ze (TEST_10)', function() - feed_command('set magic&') - eq('a1a2a3a', eval([[substitute('123', '\zs', 'a', 'g')]])) - eq('aaa', eval([[substitute('123', '\zs.', 'a', 'g')]])) - eq('1a2a3a', eval([[substitute('123', '.\zs', 'a', 'g')]])) - eq('a1a2a3a', eval([[substitute('123', '\ze', 'a', 'g')]])) - eq('a1a2a3', eval([[substitute('123', '\ze.', 'a', 'g')]])) - eq('aaa', eval([[substitute('123', '.\ze', 'a', 'g')]])) - eq('aa2a3a', eval([[substitute('123', '1\|\ze', 'a', 'g')]])) - eq('1aaa', eval([[substitute('123', '1\zs\|[23]', 'a', 'g')]])) - end) -end) - -describe(':substitue', function() - before_each(clear) - - it('with \\ze and \\zs and confirmation dialog (TEST_8)', function() - insert([[ - ,,X - ,,Y - ,,Z]]) - feed_command('set magic&') - feed_command([[1s/\(^\|,\)\ze\(,\|X\)/\1N/g]]) - feed_command([[2s/\(^\|,\)\ze\(,\|Y\)/\1N/gc]]) - feed('a') -- For the dialog of the previous :s command. - feed_command([[3s/\(^\|,\)\ze\(,\|Z\)/\1N/gc]]) - feed('yy') -- For the dialog of the previous :s command. - expect([[ - N,,NX - N,,NY - N,,NZ]]) - end) - - it('with confirmation dialog (TEST_9)', function() - insert('xxx') - feed_command('set magic&') - feed_command('s/x/X/gc') - feed('yyq') -- For the dialog of the previous :s command. - expect('XXx') - end) -end) diff --git a/test/functional/legacy/substitute_spec.lua b/test/functional/legacy/substitute_spec.lua new file mode 100644 index 0000000000..f3ce343680 --- /dev/null +++ b/test/functional/legacy/substitute_spec.lua @@ -0,0 +1,189 @@ +-- Test for *sub-replace-special* and *sub-replace-expression* on substitute(). +-- Test for submatch() on substitute(). +-- Test for *:s%* on :substitute. + +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local feed, insert = helpers.feed, helpers.insert +local exec = helpers.exec +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect +local eq, eval = helpers.eq, helpers.eval + +describe('substitute()', function() + before_each(clear) + + -- The original test contained several TEST_X lines to delimit different + -- parts. These where used to split the test into different it() blocks. + -- The TEST_X strings are repeated in the description of the blocks to make + -- it easier to incorporate upstream changes. + + local function test_1_and_2() + eq('AA', eval("substitute('A', 'A', '&&', '')")) + eq('&', eval([[substitute('B', 'B', '\&', '')]])) + eq('C123456789987654321', eval([[substitute('C123456789', ]] .. + [['C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. + [['\0\9\8\7\6\5\4\3\2\1', '')]])) + eq('d', eval("substitute('D', 'D', 'd', '')")) + eq('~', eval("substitute('E', 'E', '~', '')")) + eq('~', eval([[substitute('F', 'F', '\~', '')]])) + eq('Gg', eval([[substitute('G', 'G', '\ugg', '')]])) + eq('Hh', eval([[substitute('H', 'H', '\Uh\Eh', '')]])) + eq('iI', eval([[substitute('I', 'I', '\lII', '')]])) + eq('jJ', eval([[substitute('J', 'J', '\LJ\EJ', '')]])) + eq('Kk', eval([[substitute('K', 'K', '\Uk\ek', '')]])) + eq('l\rl', eval("substitute('lLl', 'L', '\r', '')")) + eq('m\rm', eval([[substitute('mMm', 'M', '\r', '')]])) + eq('n\rn', eval("substitute('nNn', 'N', '\\\r', '')")) + eq('o\no', eval([[substitute('oOo', 'O', '\n', '')]])) + eq('p\bp', eval([[substitute('pPp', 'P', '\b', '')]])) + eq('q\tq', eval([[substitute('qQq', 'Q', '\t', '')]])) + eq('r\\r', eval([[substitute('rRr', 'R', '\\', '')]])) + eq('scs', eval([[substitute('sSs', 'S', '\c', '')]])) + eq('t\rt', eval([[substitute('tTt', 'T', "\r", '')]])) + eq('u\nu', eval([[substitute('uUu', 'U', "\n", '')]])) + eq('v\bv', eval([[substitute('vVv', 'V', "\b", '')]])) + eq('w\\w', eval([[substitute('wWw', 'W', "\\", '')]])) + eq('XxxX', eval([[substitute('X', 'X', '\L\uxXx\l\EX', '')]])) + eq('yYYy', eval([[substitute('Y', 'Y', '\U\lYyY\u\Ey', '')]])) + end + + it('with "set magic" (TEST_1)', function() + feed_command('set magic') + test_1_and_2() + end) + + it('with "set nomagic" (TEST_2)', function() + feed_command('set nomagic') + test_1_and_2() + end) + + it('with sub-replace-expression (TEST_3)', function() + feed_command('set magic&') + eq('a\\a', eval([[substitute('aAa', 'A', '\="\\"', '')]])) + eq('b\\\\b', eval([[substitute('bBb', 'B', '\="\\\\"', '')]])) + eq('c\rc', eval([[substitute('cCc', 'C', '\="]]..'\r'..[["', '')]])) + eq('d\\\rd', eval([[substitute('dDd', 'D', '\="\\]]..'\r'..[["', '')]])) + eq('e\\\\\re', + eval([[substitute('eEe', 'E', '\="\\\\]]..'\r'..[["', '')]])) + eq('f\\rf', eval([[substitute('fFf', 'F', '\="\\r"', '')]])) + eq('j\\nj', eval([[substitute('jJj', 'J', '\="\\n"', '')]])) + eq('k\rk', eval([[substitute('kKk', 'K', '\="\r"', '')]])) + eq('l\nl', eval([[substitute('lLl', 'L', '\="\n"', '')]])) + end) + + it('with submatch() (TEST_4)', function() + feed_command('set magic&') + eq('a\\a', eval([[substitute('aAa', 'A', ]] .. + [['\=substitute(submatch(0), ".", "\\", "")', '')]])) + eq('b\\b', eval([[substitute('bBb', 'B', ]] .. + [['\=substitute(submatch(0), ".", "\\\\", "")', '')]])) + eq('c\rc', eval([[substitute('cCc', 'C', ]] .. + [['\=substitute(submatch(0), ".", "]]..'\r'..[[", "")', '')]])) + eq('d\rd', eval([[substitute('dDd', 'D', ]] .. + [['\=substitute(submatch(0), ".", "\\]]..'\r'..[[", "")', '')]])) + eq('e\\\re', eval([[substitute('eEe', 'E', ]] .. + [['\=substitute(submatch(0), ".", "\\\\]]..'\r'..[[", "")', '')]])) + eq('f\rf', eval([[substitute('fFf', 'F', ]] .. + [['\=substitute(submatch(0), ".", "\\r", "")', '')]])) + eq('j\nj', eval([[substitute('jJj', 'J', ]] .. + [['\=substitute(submatch(0), ".", "\\n", "")', '')]])) + eq('k\rk', eval([[substitute('kKk', 'K', ]] .. + [['\=substitute(submatch(0), ".", "\r", "")', '')]])) + eq('l\nl', eval([[substitute('lLl', 'L', ]] .. + [['\=substitute(submatch(0), ".", "\n", "")', '')]])) + end) + + it('with submatch() (TEST_5)', function() + feed_command('set magic&') + eq('A123456789987654321', eval([[substitute('A123456789', ]] .. + [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. + [['\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . ]] .. + [[submatch(6) . submatch(5) . submatch(4) . submatch(3) . ]] .. + [[submatch(2) . submatch(1)', '')]])) + eq("[['A123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], " .. + "['2'], ['1']]", eval([[substitute('A123456789', ]] .. + [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. + [['\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), ]] .. + [[submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), ]] .. + [[submatch(3, 1), submatch(2, 1), submatch(1, 1)])', '')]])) + end) + + -- TEST_6 was about the 'cpoptions' flag / which was removed in pull request + -- #2943. + + it('with submatch or \\ze (TEST_7)', function() + feed_command('set magic&') + eq('A\rA', eval("substitute('A\rA', 'A.', '\\=submatch(0)', '')")) + eq('B\nB', eval([[substitute("B\nB", 'B.', '\=submatch(0)', '')]])) + eq("['B\n']B", + eval([[substitute("B\nB", 'B.', '\=string(submatch(0, 1))', '')]])) + eq('-abab', eval([[substitute('-bb', '\zeb', 'a', 'g')]])) + eq('c-cbcbc', eval([[substitute('-bb', '\ze', 'c', 'g')]])) + end) + + it('with \\zs and \\ze (TEST_10)', function() + feed_command('set magic&') + eq('a1a2a3a', eval([[substitute('123', '\zs', 'a', 'g')]])) + eq('aaa', eval([[substitute('123', '\zs.', 'a', 'g')]])) + eq('1a2a3a', eval([[substitute('123', '.\zs', 'a', 'g')]])) + eq('a1a2a3a', eval([[substitute('123', '\ze', 'a', 'g')]])) + eq('a1a2a3', eval([[substitute('123', '\ze.', 'a', 'g')]])) + eq('aaa', eval([[substitute('123', '.\ze', 'a', 'g')]])) + eq('aa2a3a', eval([[substitute('123', '1\|\ze', 'a', 'g')]])) + eq('1aaa', eval([[substitute('123', '1\zs\|[23]', 'a', 'g')]])) + end) +end) + +describe(':substitute', function() + before_each(clear) + + it('with \\ze and \\zs and confirmation dialog (TEST_8)', function() + insert([[ + ,,X + ,,Y + ,,Z]]) + feed_command('set magic&') + feed_command([[1s/\(^\|,\)\ze\(,\|X\)/\1N/g]]) + feed_command([[2s/\(^\|,\)\ze\(,\|Y\)/\1N/gc]]) + feed('a') -- For the dialog of the previous :s command. + feed_command([[3s/\(^\|,\)\ze\(,\|Z\)/\1N/gc]]) + feed('yy') -- For the dialog of the previous :s command. + expect([[ + N,,NX + N,,NY + N,,NZ]]) + end) + + it('with confirmation dialog (TEST_9)', function() + insert('xxx') + feed_command('set magic&') + feed_command('s/x/X/gc') + feed('yyq') -- For the dialog of the previous :s command. + expect('XXx') + end) + + it('first char is highlighted with confirmation dialog and empty match', function() + local screen = Screen.new(60, 8) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {reverse = true}, -- IncSearch + [2] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg + }) + screen:attach() + exec([[ + set nohlsearch noincsearch + call setline(1, ['one', 'two', 'three']) + ]]) + feed(':%s/^/ /c') + screen:expect([[ + {1:o}ne | + two | + three | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:replace with (y/n/a/q/l/^E/^Y)?}^ | + ]]) + end) +end) -- cgit From 1970d2ac43059639e4e2c83223d86397b38786ff Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 13 Sep 2022 08:33:39 -0600 Subject: feat(diagnostic): pass diagnostics as data to DiagnosticChanged autocmd (#20173) --- test/functional/lua/diagnostic_spec.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 1514dadca8..28a8679205 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1983,19 +1983,26 @@ end) end) it('triggers the autocommand when diagnostics are set', function() - eq(true, exec_lua [[ + eq({true, true}, exec_lua [[ -- Set a different buffer as current to test that is being set properly in -- DiagnosticChanged callbacks local tmp = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_current_buf(tmp) - vim.g.diagnostic_autocmd_triggered = 0 - vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = +expand("")') + local triggered = {} + vim.api.nvim_create_autocmd('DiagnosticChanged', { + callback = function(args) + triggered = {args.buf, #args.data.diagnostics} + end, + }) vim.api.nvim_buf_set_name(diagnostic_bufnr, "test | test") vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic', 0, 0, 0, 0) }) - return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr + return { + triggered[1] == diagnostic_bufnr, + triggered[2] == 1, + } ]]) end) -- cgit From a8c9e721d91efe4730db78c1115261fc128dca68 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Tue, 13 Sep 2022 22:16:20 +0200 Subject: feat(fs): extend fs.find to accept predicate (#20193) Makes it possible to use `vim.fs.find` to find files where only a substring is known. This is useful for `vim.lsp.start` to get the `root_dir` for languages where the project-file is only known by its extension, not by the full name. For example in .NET projects there is usually a `.csproj` file in the project root. Example: vim.fs.find(function(x) return vim.endswith(x, '.csproj') end, { upward = true }) --- test/functional/lua/fs_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 2bcc84db0f..3123ec324c 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -78,6 +78,23 @@ describe('vim.fs', function() return vim.fs.find(nvim, { path = dir, type = 'file' }) ]], test_build_dir, nvim_prog_basename)) end) + + it('accepts predicate as names', function() + eq({test_build_dir}, exec_lua([[ + local dir = ... + local opts = { path = dir, upward = true, type = 'directory' } + return vim.fs.find(function(x) return x == 'build' end, opts) + ]], nvim_dir)) + eq({nvim_prog}, exec_lua([[ + local dir, nvim = ... + return vim.fs.find(function(x) return x == nvim end, { path = dir, type = 'file' }) + ]], test_build_dir, nvim_prog_basename)) + eq({}, exec_lua([[ + local dir = ... + local opts = { path = dir, upward = true, type = 'directory' } + return vim.fs.find(function(x) return x == 'no-match' end, opts) + ]], nvim_dir)) + end) end) describe('normalize()', function() -- cgit From 25e4af439f3b5620406776ca77417d897097a3e9 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 12 Sep 2022 11:26:27 +0200 Subject: fix(lua): make vim.str_utfindex and vim.str_byteindex handle NUL bytes fixes #16290 --- test/functional/lua/vim_spec.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index cd3240cd30..33f4b108da 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -158,17 +158,20 @@ describe('lua stdlib', function() end) it("vim.str_utfindex/str_byteindex", function() - exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]]) - local indicies32 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,29,33,34,35,37,38,40,42,44,46,48} - local indicies16 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,28,29,33,33,34,35,37,38,40,42,44,46,48} + exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ\000ъ"]]) + local indicies32 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,29,33,34,35,37,38,40,42,44,46,48,49,51} + local indicies16 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,28,29,33,33,34,35,37,38,40,42,44,46,48,49,51} for i,k in pairs(indicies32) do eq(k, exec_lua("return vim.str_byteindex(_G.test_text, ...)", i), i) end for i,k in pairs(indicies16) do eq(k, exec_lua("return vim.str_byteindex(_G.test_text, ..., true)", i), i) end + matches(": index out of range$", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ...)", #indicies32 + 1)) + matches(": index out of range$", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ..., true)", #indicies16 + 1)) local i32, i16 = 0, 0 - for k = 0,48 do + local len = 51 + for k = 0,len do if indicies32[i32] < k then i32 = i32 + 1 end @@ -180,6 +183,7 @@ describe('lua stdlib', function() end eq({i32, i16}, exec_lua("return {vim.str_utfindex(_G.test_text, ...)}", k), k) end + matches(": index out of range$", pcall_err(exec_lua, "return vim.str_utfindex(_G.test_text, ...)", len + 1)) end) it("vim.str_utf_start", function() -- cgit From 708bd686516b420c2b65f4bc4d2c58fe43fb945e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 13 Sep 2022 12:56:30 +0200 Subject: feat(ui): use msg_grid based implementation for cmdheight=0 --- test/functional/ui/cmdline_spec.lua | 20 ++++++++++---------- test/functional/vimscript/timer_spec.lua | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index db13647cc6..40dee4186b 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1022,7 +1022,7 @@ describe('cmdheight=0', function() ~ | :^ | ]]} - eq(1, eval('&cmdheight')) + eq(0, eval('&cmdheight')) feed('') screen:expect{grid=[[ ^ | @@ -1040,11 +1040,11 @@ describe('cmdheight=0', function() screen:expect{grid=[[ | ~ | - ~ | - ~ | + | + :call input("foo >") | foo >^ | ]]} - eq(1, eval('&cmdheight')) + eq(0, eval('&cmdheight')) feed('') screen:expect{grid=[[ ^ | @@ -1060,8 +1060,8 @@ describe('cmdheight=0', function() command("set cmdheight=0 noruler laststatus=3 winbar=foo") feed(':split') screen:expect{grid=[[ - foo | | + :split | E36: Not enough room | Press ENTER or type comma| nd to continue^ | @@ -1079,7 +1079,7 @@ describe('cmdheight=0', function() foo | | ~ | - [No Name] | + ~ | :^ | ]]} feed('') @@ -1103,8 +1103,8 @@ describe('cmdheight=0', function() ~ | ~ | ~ | - recording @q | - ]], showmode={}} + ~ | + ]]} feed('q') screen:expect{grid=[[ ^ | @@ -1112,7 +1112,7 @@ describe('cmdheight=0', function() ~ | ~ | ~ | - ]], showmode={}} + ]], unchanged=true} end) it("when substitute text", function() @@ -1131,7 +1131,7 @@ describe('cmdheight=0', function() foo | ~ | ~ | - [No Name] [+] | + ~ | replace wi...q/l/^E/^Y)?^ | ]]} diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 5463cfb234..1818a71ea2 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -131,34 +131,34 @@ describe('timers', function() nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem', {'repeat': -1})") screen:expect([[ - ITEM 1 | + ^ITEM 1 | ITEM 2 | {1:~ }| {1:~ }| {1:~ }| - ^ | + | ]]) nvim_async("command", "let g:cont = 1") screen:expect([[ - ITEM 1 | + ^ITEM 1 | ITEM 2 | ITEM 3 | {1:~ }| {1:~ }| - ^ | + | ]]) feed("3") eq(51, eval("g:c2")) - screen:expect([[ + screen:expect{grid=[[ ^ITEM 1 | ITEM 2 | ITEM 3 | {1:~ }| {1:~ }| | - ]]) + ]], unchanged=true} end) it('can be stopped', function() -- cgit From 9ec4b20be695501ba166f31dec39ef9e30cc7dd8 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 16 Sep 2022 09:05:05 +0200 Subject: fix(treesitter): return full metadata for get_captures_at_position (#20203) fix(treesitter): get_captures_at_position returns metadata Return the full `metadata` table for the capture instead of just the priority. Further cleanup of related docs. --- test/functional/treesitter/highlight_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index d557b2c012..1684337c3c 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -605,8 +605,8 @@ describe('treesitter highlighting', function() }} eq({ - {capture='Error', priority='101'}; - {capture='type'}; + {capture='Error', metadata = { priority='101' }}; + {capture='type', metadata = { } }; }, exec_lua [[ return vim.treesitter.get_captures_at_position(0, 0, 2) ]]) end) -- cgit From b616458af90cc12ef7379d06c3ef1fde4958e62b Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 16 Sep 2022 10:31:37 +0200 Subject: fix(messages): do not crash on cmdheight=0 and g< redisplay fixes #20153 --- test/functional/ui/messages_spec.lua | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 522c9ccba2..6b8fa99b38 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -2020,4 +2020,55 @@ aliquip ex ea commodo consequat.]]) | ]]} end) + + it('with cmdheight=0 does not crash with g<', function() + command('set cmdheight=0') + feed(':ls') + screen:expect{grid=[[ + | + {1:~ }| + {12: }| + :ls | + 1 %a "[No Name]" | + line 1 | + {4:Press ENTER or type command to cont}| + {4:inue}^ | + ]]} + + feed('') + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]} + + feed('g') + screen:expect{grid=[[ + | + {1:~ }| + {12: }| + :ls | + 1 %a "[No Name]" | + line 1 | + {4:Press ENTER or type command to cont}| + {4:inue}^ | + ]]} + + feed('') + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]} + end) end) -- cgit From 754822a066e6ce92462aa17fce8999472c23b777 Mon Sep 17 00:00:00 2001 From: notomo Date: Fri, 16 Sep 2022 18:06:37 +0900 Subject: fix(lua): free vim.ui_attach callback before lua close (#20205) --- test/functional/lua/ui_event_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 294222ad13..57ffcf7b4e 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -105,4 +105,16 @@ describe('vim.ui_attach', function() } end) + + it('does not crash on exit', function() + helpers.funcs.system({ + helpers.nvim_prog, + '-u', 'NONE', + '-i', 'NONE', + '--cmd', [[ lua ns = vim.api.nvim_create_namespace 'testspace' ]], + '--cmd', [[ lua vim.ui_attach(ns, {ext_popupmenu=true}, function() end) ]], + '--cmd', 'quitall!', + }) + eq(0, helpers.eval('v:shell_error')) + end) end) -- cgit From 6b2f0f43b5f9d375d2be1b4eb4784716dd89ec8f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 16 Sep 2022 23:09:26 +0800 Subject: fix(eval)!: make Lua Funcref work as method and in substitute() (#20217) BREAKING CHANGE: When using a Funcref converted from a Lua function as a method in Vim script, the result of the base expression is now passed as the first argument instead of being ignored. vim-patch:8.2.5117: crash when calling a Lua callback from a :def function Problem: Crash when calling a Lua callback from a :def function. (Bohdan Makohin) Solution: Handle FC_CFUNC in call_user_func_check(). (closes vim/vim#10587) https://github.com/vim/vim/commit/7d149f899d423b7bf2b90d7b11ebe3e560c462b9 --- test/functional/lua/vim_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 33f4b108da..00ce44f48a 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -792,6 +792,11 @@ describe('lua stdlib', function() local x = vim.fn.VarArg(function() return 'foo' end, function() return 'bar' end) return #x == 2 and x[1]() == 'foo' and x[2]() == 'bar' ]])) + + -- Test for #20211 + eq('a (b) c', exec_lua([[ + return vim.fn.substitute('a b c', 'b', function(m) return '(' .. m[1] .. ')' end, 'g') + ]])) end) it('vim.fn should error when calling API function', function() @@ -1033,6 +1038,7 @@ describe('lua stdlib', function() vim.g.AddCounter = add_counter vim.g.GetCounter = get_counter vim.g.funcs = {add = add_counter, get = get_counter} + vim.g.AddParens = function(s) return '(' .. s .. ')' end ]] eq(0, eval('g:GetCounter()')) @@ -1048,6 +1054,7 @@ describe('lua stdlib', function() eq(5, exec_lua([[return vim.g.funcs.get()]])) exec_lua([[vim.api.nvim_get_var('funcs').add()]]) eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]])) + eq('((foo))', eval([['foo'->AddParens()->AddParens()]])) exec_lua [[ local counter = 0 @@ -1056,6 +1063,7 @@ describe('lua stdlib', function() vim.api.nvim_set_var('AddCounter', add_counter) vim.api.nvim_set_var('GetCounter', get_counter) vim.api.nvim_set_var('funcs', {add = add_counter, get = get_counter}) + vim.api.nvim_set_var('AddParens', function(s) return '(' .. s .. ')' end) ]] eq(0, eval('g:GetCounter()')) @@ -1071,6 +1079,7 @@ describe('lua stdlib', function() eq(5, exec_lua([[return vim.g.funcs.get()]])) exec_lua([[vim.api.nvim_get_var('funcs').add()]]) eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]])) + eq('((foo))', eval([['foo'->AddParens()->AddParens()]])) exec([[ function Test() @@ -1137,6 +1146,7 @@ describe('lua stdlib', function() vim.b.AddCounter = add_counter vim.b.GetCounter = get_counter vim.b.funcs = {add = add_counter, get = get_counter} + vim.b.AddParens = function(s) return '(' .. s .. ')' end ]] eq(0, eval('b:GetCounter()')) @@ -1152,6 +1162,7 @@ describe('lua stdlib', function() eq(5, exec_lua([[return vim.b.funcs.get()]])) exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]]) eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]])) + eq('((foo))', eval([['foo'->b:AddParens()->b:AddParens()]])) exec_lua [[ local counter = 0 @@ -1160,6 +1171,7 @@ describe('lua stdlib', function() vim.api.nvim_buf_set_var(0, 'AddCounter', add_counter) vim.api.nvim_buf_set_var(0, 'GetCounter', get_counter) vim.api.nvim_buf_set_var(0, 'funcs', {add = add_counter, get = get_counter}) + vim.api.nvim_buf_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end) ]] eq(0, eval('b:GetCounter()')) @@ -1175,6 +1187,7 @@ describe('lua stdlib', function() eq(5, exec_lua([[return vim.b.funcs.get()]])) exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]]) eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]])) + eq('((foo))', eval([['foo'->b:AddParens()->b:AddParens()]])) exec([[ function Test() @@ -1231,6 +1244,7 @@ describe('lua stdlib', function() vim.w.AddCounter = add_counter vim.w.GetCounter = get_counter vim.w.funcs = {add = add_counter, get = get_counter} + vim.w.AddParens = function(s) return '(' .. s .. ')' end ]] eq(0, eval('w:GetCounter()')) @@ -1246,6 +1260,7 @@ describe('lua stdlib', function() eq(5, exec_lua([[return vim.w.funcs.get()]])) exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]]) eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]])) + eq('((foo))', eval([['foo'->w:AddParens()->w:AddParens()]])) exec_lua [[ local counter = 0 @@ -1254,6 +1269,7 @@ describe('lua stdlib', function() vim.api.nvim_win_set_var(0, 'AddCounter', add_counter) vim.api.nvim_win_set_var(0, 'GetCounter', get_counter) vim.api.nvim_win_set_var(0, 'funcs', {add = add_counter, get = get_counter}) + vim.api.nvim_win_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end) ]] eq(0, eval('w:GetCounter()')) @@ -1269,6 +1285,7 @@ describe('lua stdlib', function() eq(5, exec_lua([[return vim.w.funcs.get()]])) exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]]) eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]])) + eq('((foo))', eval([['foo'->w:AddParens()->w:AddParens()]])) exec([[ function Test() @@ -1320,6 +1337,7 @@ describe('lua stdlib', function() vim.t.AddCounter = add_counter vim.t.GetCounter = get_counter vim.t.funcs = {add = add_counter, get = get_counter} + vim.t.AddParens = function(s) return '(' .. s .. ')' end ]] eq(0, eval('t:GetCounter()')) @@ -1335,6 +1353,7 @@ describe('lua stdlib', function() eq(5, exec_lua([[return vim.t.funcs.get()]])) exec_lua([[vim.api.nvim_tabpage_get_var(0, 'funcs').add()]]) eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'funcs').get()]])) + eq('((foo))', eval([['foo'->t:AddParens()->t:AddParens()]])) exec_lua [[ local counter = 0 @@ -1343,6 +1362,7 @@ describe('lua stdlib', function() vim.api.nvim_tabpage_set_var(0, 'AddCounter', add_counter) vim.api.nvim_tabpage_set_var(0, 'GetCounter', get_counter) vim.api.nvim_tabpage_set_var(0, 'funcs', {add = add_counter, get = get_counter}) + vim.api.nvim_tabpage_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end) ]] eq(0, eval('t:GetCounter()')) @@ -1358,6 +1378,7 @@ describe('lua stdlib', function() eq(5, exec_lua([[return vim.t.funcs.get()]])) exec_lua([[vim.api.nvim_tabpage_get_var(0, 'funcs').add()]]) eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'funcs').get()]])) + eq('((foo))', eval([['foo'->t:AddParens()->t:AddParens()]])) exec_lua [[ vim.cmd "tabnew" -- cgit From 3c3f3e7353ba2cb9071183cd05036ca2a98d3672 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 17 Sep 2022 16:17:51 +0800 Subject: test(remote_spec): reduce flakiness in waiting for client exit (#20230) It is less likely for client to exit between jobstart() and jobwait() if they are invoked in the same RPC request instead of two separate ones. --- test/functional/core/remote_spec.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index d7bd075eb2..846d79abf3 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq +local exec_lua = helpers.exec_lua local expect = helpers.expect local funcs = helpers.funcs local insert = helpers.insert @@ -48,8 +49,8 @@ describe('Remote', function() -- our incoming --remote calls. local client_starter = spawn(new_argv(), false, nil, true) set_session(client_starter) - local client_job_id = funcs.jobstart(client_argv) - eq({ 0 }, funcs.jobwait({client_job_id})) + -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. + eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(...) })]], client_argv)) client_starter:close() set_session(server) end @@ -121,8 +122,8 @@ describe('Remote', function() -- the event loop. If the server event loop is blocked, it can't process -- our incoming --remote calls. clear() - local bogus_job_id = funcs.jobstart(bogus_argv) - eq({2}, funcs.jobwait({bogus_job_id})) + -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. + eq({ 2 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(...) })]], bogus_argv)) end it('bogus subcommand', function() run_and_check_exit_code('--remote-bogus') -- cgit From 644a3f48b117abd1d0d0aab5ec96cd62392ca0f1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 14 Sep 2022 19:49:55 +0800 Subject: fix(events): make CursorHold behave as documented --- test/functional/autocmd/cursorhold_spec.lua | 57 ++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua index 506b688853..5d54610e1d 100644 --- a/test/functional/autocmd/cursorhold_spec.lua +++ b/test/functional/autocmd/cursorhold_spec.lua @@ -5,22 +5,61 @@ local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed local retry = helpers.retry -local source = helpers.source +local exec = helpers.source local sleep = helpers.sleep +local meths = helpers.meths -describe('CursorHoldI', function() - before_each(clear) +before_each(clear) + +describe('CursorHold', function() + it('is triggered correctly #12587', function() + exec([[ + augroup test + au CursorHold * let g:cursorhold += 1 + augroup END + ]]) + + local function test_cursorhold(fn, early) + local ut = 2 + -- if testing with small 'updatetime' fails, double its value and test again + retry(10, nil, function() + ut = ut * 2 + meths.set_option('updatetime', ut) + feed('0') -- reset did_cursorhold + meths.set_var('cursorhold', 0) + sleep(ut / 4) + fn() + eq(0, meths.get_var('cursorhold')) + sleep(ut / 2) + fn() + eq(0, meths.get_var('cursorhold')) + sleep(ut / 2) + eq(early, meths.get_var('cursorhold')) + sleep(ut / 4 * 3) + eq(1, meths.get_var('cursorhold')) + end) + end + local ignore_key = meths.replace_termcodes('', true, true, true) + test_cursorhold(function() end, 1) + test_cursorhold(function() feed('') end, 1) + test_cursorhold(function() meths.feedkeys('', 'n', true) end, 1) + test_cursorhold(function() feed('') end, 0) + test_cursorhold(function() meths.feedkeys(ignore_key, 'n', true) end, 0) + end) +end) + +describe('CursorHoldI', function() -- NOTE: since this test uses RPC it is not necessary to trigger the initial -- issue (#3757) via timer's or RPC callbacks in the first place. it('is triggered after input', function() - source([[ - set updatetime=1 + exec([[ + set updatetime=1 - let g:cursorhold = 0 - augroup test - au CursorHoldI * let g:cursorhold += 1 - augroup END + let g:cursorhold = 0 + augroup test + au CursorHoldI * let g:cursorhold += 1 + augroup END ]]) feed('ifoo') retry(5, nil, function() -- cgit From 6d557e324fd4223fff3279a0112f40431c540163 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 18 Sep 2022 03:17:15 +0200 Subject: vim-patch:8.1.0941: macros for MS-Windows are inconsistent (#20215) Problem: Macros for MS-Windows are inconsistent, using "32", "3264 and others. Solution: Use MSWIN for all MS-Windows builds. Use FEAT_GUI_MSWIN for the GUI build. (Hirohito Higashi, closes vim/vim#3932) https://github.com/vim/vim/commit/4f97475d326c2773a78561fb874e4f23c25cbcd9 --- test/functional/fixtures/printenv-test.c | 6 +++--- test/functional/fixtures/tty-test.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'test/functional') diff --git a/test/functional/fixtures/printenv-test.c b/test/functional/fixtures/printenv-test.c index 0e68129543..295b4f04c3 100644 --- a/test/functional/fixtures/printenv-test.c +++ b/test/functional/fixtures/printenv-test.c @@ -3,13 +3,13 @@ #include -#ifdef WIN32 +#ifdef MSWIN # include #else # include #endif -#ifdef WIN32 +#ifdef MSWIN int wmain(int argc, wchar_t **argv) #else int main(int argc, char **argv) @@ -19,7 +19,7 @@ int main(int argc, char **argv) return 1; } -#ifdef WIN32 +#ifdef MSWIN wchar_t *value = _wgetenv(argv[1]); if (value == NULL) { return 1; diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 4438b73a22..6ee7715021 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -5,7 +5,7 @@ #include #include #include -#ifdef _WIN32 +#ifdef MSWIN # include #else # include @@ -23,7 +23,7 @@ uv_tty_t tty_out; bool owns_tty(void); // silence -Wmissing-prototypes bool owns_tty(void) { -#ifdef _WIN32 +#ifdef MSWIN // XXX: We need to make proper detect owns tty // HWND consoleWnd = GetConsoleWindow(); // DWORD dwProcessId; @@ -38,14 +38,14 @@ bool owns_tty(void) static void walk_cb(uv_handle_t *handle, void *arg) { if (!uv_is_closing(handle)) { -#ifdef WIN32 +#ifdef MSWIN uv_tty_set_mode(&tty, UV_TTY_MODE_NORMAL); #endif uv_close(handle, NULL); } } -#ifndef WIN32 +#ifndef MSWIN static void sig_handler(int signum) { switch (signum) { @@ -64,7 +64,7 @@ static void sig_handler(int signum) } #endif -#ifdef WIN32 +#ifdef MSWIN static void sigwinch_cb(uv_signal_t *handle, int signum) { int width, height; @@ -102,7 +102,7 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_write_t req; uv_buf_t b = { .base = buf->base, -#ifdef WIN32 +#ifdef MSWIN .len = (ULONG)cnt #else .len = (size_t)cnt @@ -171,7 +171,7 @@ int main(int argc, char **argv) uv_prepare_t prepare; uv_prepare_init(uv_default_loop(), &prepare); uv_prepare_start(&prepare, prepare_cb); -#ifndef WIN32 +#ifndef MSWIN uv_tty_init(uv_default_loop(), &tty, fileno(stderr), 1); #else uv_tty_init(uv_default_loop(), &tty, fileno(stdin), 1); @@ -182,7 +182,7 @@ int main(int argc, char **argv) uv_tty_set_mode(&tty, UV_TTY_MODE_RAW); tty.data = &interrupted; uv_read_start(STRUCT_CAST(uv_stream_t, &tty), alloc_cb, read_cb); -#ifndef WIN32 +#ifndef MSWIN struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; @@ -196,7 +196,7 @@ int main(int argc, char **argv) #endif uv_run(uv_default_loop(), UV_RUN_DEFAULT); -#ifndef WIN32 +#ifndef MSWIN // XXX: Without this the SIGHUP handler is skipped on some systems. sleep(100); #endif -- cgit From 67df3347fd1e637f643b35239f7a20ac813ee588 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 18 Sep 2022 15:20:20 +0200 Subject: vim-patch:9712ff1288f9 (#20240) Update runtime files https://github.com/vim/vim/commit/9712ff1288f942736ed76c0dec014909f067eec9 --- test/functional/ui/decorations_spec.lua | 54 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index db5a775632..eff6fe6d23 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -686,15 +686,15 @@ end]] screen:expect{grid=[[ {5:^for} _,item {5:in} {6:ipairs}(items) {5:do} | - {5:local} text, hl_id_cell, count = unpack(item) | - {5:if} hl_id_cell ~= {13:nil} {5:then} | - hl_id = hl_id_cell | + {5:local} text, hl_id_cell, count {5:=} unpack(item) | + {5:if} hl_id_cell {5:~=} {13:nil} {5:then} | + hl_id {5:=} hl_id_cell | {5:end} | - {5:for} _ = {13:1}, (count {5:or} {13:1}) {5:do} | - {5:local} cell = line[colpos] | - cell.text = text | - cell.hl_id = hl_id | - colpos = colpos+{13:1} | + {5:for} _ {5:=} {13:1}, (count {5:or} {13:1}) {5:do} | + {5:local} cell {5:=} line[colpos] | + cell.text {5:=} text | + cell.hl_id {5:=} hl_id | + colpos {5:=} colpos{5:+}{13:1} | {5:end} | {5:end} | {1:~ }| @@ -713,15 +713,15 @@ end]] screen:expect{grid=[[ {5:^for} _,item {5:in} {6:ipairs}(items) {5:do} | - {5:l}{8:blen}{7:dy}{10:e}{7:text}{10:h}{7:-}{10:_}{7:here}ell, count = unpack(item) | - {5:i}{12:c}{11:ombining color} {13:nil} {5:then} | + {5:l}{8:blen}{7:dy}{10:e}{7:text}{10:h}{7:-}{10:_}{7:here}ell, count {5:=} unpack(item) | + {5:i}{12:c}{11:ombining col}{12:or} {13:nil} {5:then} | {11:replacing color}d_cell | {5:e}{8:bl}{7:endy}{10: }{7:text}{10: }{7:-}{10: }{7:here} | - {5:f}{12:co}{11:mbini}{16:n}{11:g color}t {5:or} {13:1}) {5:do} | + {5:f}{12:co}{11:mbi}{12:n}{11:i}{16:n}{11:g color}t {5:or} {13:1}) {5:do} | {11:replacing color} line[colpos] | - cell.text = text | - cell.hl_id = hl_id | - colpos = colpos+{13:1} | + cell.text {5:=} text | + cell.hl_id {5:=} hl_id | + colpos {5:=} colpos{5:+}{13:1} | {5:end} | {5:end} | {1:~ }| @@ -732,15 +732,15 @@ end]] feed 'V5G' screen:expect{grid=[[ {17:for}{18: _,item }{17:in}{18: }{19:ipairs}{18:(items) }{17:do} | - {18: }{17:l}{20:blen}{21:dy}{22:e}{21:text}{22:h}{21:-}{22:_}{21:here}{18:ell, count = unpack(item)} | - {18: }{17:i}{12:c}{11:ombining color}{18: }{23:nil}{18: }{17:then} | + {18: }{17:l}{20:blen}{21:dy}{22:e}{21:text}{22:h}{21:-}{22:_}{21:here}{18:ell, count }{17:=}{18: unpack(item)} | + {18: }{17:i}{12:c}{11:ombining col}{12:or}{18: }{23:nil}{18: }{17:then} | {18: }{11:replacing color}{18:d_cell} | {18: }{5:^e}{17:nd} | - {5:f}{12:co}{11:mbini}{16:n}{11:g color}t {5:or} {13:1}) {5:do} | + {5:f}{12:co}{11:mbi}{12:n}{11:i}{16:n}{11:g color}t {5:or} {13:1}) {5:do} | {11:replacing color} line[colpos] | - cell.text = text | - cell.hl_id = hl_id | - colpos = colpos+{13:1} | + cell.text {5:=} text | + cell.hl_id {5:=} hl_id | + colpos {5:=} colpos{5:+}{13:1} | {5:end} | {5:end} | {1:~ }| @@ -751,15 +751,15 @@ end]] feed 'jj' screen:expect{grid=[[ {17:for}{18: _,item }{17:in}{18: }{19:ipairs}{18:(items) }{17:do} | - {18: }{17:l}{20:blen}{21:dy}{22:e}{21:text}{22:h}{21:-}{22:_}{21:here}{18:ell, count = unpack(item)} | - {18: }{17:i}{12:c}{11:ombining color}{18: }{23:nil}{18: }{17:then} | + {18: }{17:l}{20:blen}{21:dy}{22:e}{21:text}{22:h}{21:-}{22:_}{21:here}{18:ell, count }{17:=}{18: unpack(item)} | + {18: }{17:i}{12:c}{11:ombining col}{12:or}{18: }{23:nil}{18: }{17:then} | {18: }{11:replacing color}{18:d_cell} | {18: }{17:end} | - {18: }{17:for}{18: _ = }{23:1}{18:, (count }{17:or}{18: }{23:1}{18:) }{17:do} | - {18: }^ {18: }{17:local}{18: cell = line[colpos]} | - cell.text = text | - cell.hl_id = hl_id | - colpos = colpos+{13:1} | + {18: }{17:for}{18: _ }{17:=}{18: }{23:1}{18:, (count }{17:or}{18: }{23:1}{18:) }{17:do} | + {18: }^ {18: }{17:local}{18: cell }{17:=}{18: line[colpos]} | + cell.text {5:=} text | + cell.hl_id {5:=} hl_id | + colpos {5:=} colpos{5:+}{13:1} | {5:end} | {5:end} | {1:~ }| -- cgit From 647da34bbd4cf19a4bcc11899df24e00d6b8fcbe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 18 Sep 2022 22:55:30 +0800 Subject: fix: assert failure when changing 'ut' while waiting for CursorHold (#20241) --- test/functional/autocmd/cursorhold_spec.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua index 5d54610e1d..b04bd5233a 100644 --- a/test/functional/autocmd/cursorhold_spec.lua +++ b/test/functional/autocmd/cursorhold_spec.lua @@ -2,7 +2,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local eval = helpers.eval local feed = helpers.feed local retry = helpers.retry local exec = helpers.source @@ -12,13 +11,16 @@ local meths = helpers.meths before_each(clear) describe('CursorHold', function() - it('is triggered correctly #12587', function() + before_each(function() exec([[ + let g:cursorhold = 0 augroup test au CursorHold * let g:cursorhold += 1 augroup END ]]) + end) + it('is triggered correctly #12587', function() local function test_cursorhold(fn, early) local ut = 2 -- if testing with small 'updatetime' fails, double its value and test again @@ -47,6 +49,17 @@ describe('CursorHold', function() test_cursorhold(function() feed('') end, 0) test_cursorhold(function() meths.feedkeys(ignore_key, 'n', true) end, 0) end) + + it("reducing 'updatetime' while waiting for CursorHold #20241", function() + meths.set_option('updatetime', 10000) + feed('0') -- reset did_cursorhold + meths.set_var('cursorhold', 0) + sleep(50) + eq(0, meths.get_var('cursorhold')) + meths.set_option('updatetime', 20) + sleep(10) + eq(1, meths.get_var('cursorhold')) + end) end) describe('CursorHoldI', function() @@ -64,7 +77,7 @@ describe('CursorHoldI', function() feed('ifoo') retry(5, nil, function() sleep(1) - eq(1, eval('g:cursorhold')) + eq(1, meths.get_var('cursorhold')) end) end) end) -- cgit From 7bd4c8e8ee2f623fbde017987f2989e8b8792829 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 19 Sep 2022 12:37:25 +0800 Subject: fix(inccommand): avoid unnecessary redraw when not showing (#20244) --- test/functional/ui/inccommand_spec.lua | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index 9ca4673efe..49b3c7a655 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -1190,6 +1190,8 @@ describe(":substitute, inccommand=split", function() end) it("deactivates if 'redrawtime' is exceeded #5602", function() + -- prevent redraws from 'incsearch' + meths.set_option('incsearch', false) -- Assert that 'inccommand' is ENABLED initially. eq("split", eval("&inccommand")) -- Set 'redrawtime' to minimal value, to ensure timeout is triggered. @@ -2972,6 +2974,59 @@ it(':substitute with inccommand, does not crash if range contains invalid marks' ]]) end) +it(':substitute with inccommand, no unnecessary redraw if preview is not shown', function() + local screen = Screen.new(60, 6) + clear() + common_setup(screen, 'split', 'test') + feed(':ls') + screen:expect([[ + test | + {15:~ }| + {11: }| + :ls | + 1 %a + "[No Name]" line 1 | + {13:Press ENTER or type command to continue}^ | + ]]) + feed(':s') + -- no unnecessary redraw, so messages are still shown + screen:expect([[ + test | + {15:~ }| + {11: }| + :ls | + 1 %a + "[No Name]" line 1 | + :s^ | + ]]) + feed('o') + screen:expect([[ + test | + {15:~ }| + {11: }| + :ls | + 1 %a + "[No Name]" line 1 | + :so^ | + ]]) + feed('') + screen:expect([[ + test | + {15:~ }| + {11: }| + :ls | + 1 %a + "[No Name]" line 1 | + :s^ | + ]]) + feed('/test') + -- now inccommand is shown, so screen is redrawn + screen:expect([[ + {12:test} | + {15:~ }| + {15:~ }| + {15:~ }| + {15:~ }| + :s/test^ | + ]]) +end) + it(":substitute doesn't crash with inccommand, if undo is empty #12932", function() local screen = Screen.new(10,5) clear() -- cgit From 10196f1b462400b8a4a9e8f13893da2514f8c850 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Tue, 20 Sep 2022 09:28:23 +0200 Subject: fix(lsp): support `false` result in handlers (#20252) Closes https://github.com/neovim/neovim/issues/20111 --- test/functional/plugin/lsp_spec.lua | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 395f8ed32a..e7ea089fbf 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3292,4 +3292,75 @@ describe('LSP', function() eq(result.method, "initialize") end) end) + + describe('handlers', function() + it('handler can return false as response', function() + local result = exec_lua [[ + local uv = vim.loop + local server = uv.new_tcp() + local messages = {} + local responses = {} + server:bind('127.0.0.1', 0) + server:listen(127, function(err) + assert(not err, err) + local socket = uv.new_tcp() + server:accept(socket) + socket:read_start(require('vim.lsp.rpc').create_read_loop(function(body) + local payload = vim.json.decode(body) + if payload.method then + table.insert(messages, payload.method) + if payload.method == 'initialize' then + local msg = vim.json.encode({ + id = payload.id, + jsonrpc = '2.0', + result = { + capabilities = {} + }, + }) + socket:write(table.concat({'Content-Length: ', tostring(#msg), '\r\n\r\n', msg})) + elseif payload.method == 'initialized' then + local msg = vim.json.encode({ + id = 10, + jsonrpc = '2.0', + method = 'dummy', + params = {}, + }) + socket:write(table.concat({'Content-Length: ', tostring(#msg), '\r\n\r\n', msg})) + end + else + table.insert(responses, payload) + socket:close() + end + end)) + end) + local port = server:getsockname().port + local handler_called = false + vim.lsp.handlers['dummy'] = function(err, result) + handler_called = true + return false + end + local client_id = vim.lsp.start({ name = 'dummy', cmd = vim.lsp.rpc.connect('127.0.0.1', port) }) + local client = vim.lsp.get_client_by_id(client_id) + vim.wait(1000, function() return #messages == 2 and handler_called and #responses == 1 end) + server:close() + server:shutdown() + return { + messages = messages, + handler_called = handler_called, + responses = responses } + ]] + local expected = { + messages = { 'initialize', 'initialized' }, + handler_called = true, + responses = { + { + id = 10, + jsonrpc = '2.0', + result = false + } + } + } + eq(expected, result) + end) + end) end) -- cgit From 9413f7544bcab6951f9a0c26c4b2e1a6dc477c82 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Sep 2022 20:38:44 +0800 Subject: vim-patch:9.0.0507: cmdline cleared when using :redrawstatus in CmdlineChanged Problem: Command line cleared when using :redrawstatus in CmdlineChanged autocommand event. Solution: Postpone the redraw. (closes vim/vim#11162) https://github.com/vim/vim/commit/bcd6924245c0e73d8be256282656c06aaf91f17c Cherry-pick Test_redraw_in_autocmd() from Vim patch 8.2.4789. --- test/functional/legacy/cmdline_spec.lua | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 99d2d0f30e..8ea5754cfa 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -140,6 +140,62 @@ describe('cmdline', function() :^ | ]]) end) + + -- oldtest: Test_redraw_in_autocmd() + it('cmdline cursor position is correct after :redraw with cmdheight=2', function() + local screen = Screen.new(30, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + }) + screen:attach() + exec([[ + set cmdheight=2 + autocmd CmdlineChanged * redraw + ]]) + feed(':for i in range(3)') + screen:expect([[ + | + {0:~ }| + {0:~ }| + {0:~ }| + :for i in range(3) | + : ^ | + ]]) + feed(':let i =') + -- Note: this may still be considered broken, ref #18140 + screen:expect([[ + | + {0:~ }| + {0:~ }| + {0:~ }| + : :let i =^ | + | + ]]) + end) + + -- oldtest: Test_redrawstatus_in_autocmd() + it(':redrawstatus in cmdline mode', function() + local screen = Screen.new(60, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, reverse = true}, -- MsgSeparator + }) + screen:attach() + exec([[ + set cmdheight=2 + autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif + ]]) + feed([[:echo "one\ntwo\nthree\nfour"]]) + feed(':foobar') + screen:expect([[ + {1: }| + one | + two | + three | + four | + :foobar^ | + ]]) + end) end) describe('cmdwin', function() -- cgit From 2e4532bea50e5f6fb68ebf750c461c5704fc58c2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Sep 2022 20:54:07 +0800 Subject: vim-patch:9.0.0512: cannot redraw the status lines when editing a command Problem: Cannot redraw the status lines when editing a command. Solution: Only postpone the redraw when messages have scrolled. (closes vim/vim#11170) https://github.com/vim/vim/commit/c14bfc31d907cbee6a3636f780561ad1787cdb9b --- test/functional/legacy/cmdline_spec.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 8ea5754cfa..8325f7eeb0 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -178,13 +178,15 @@ describe('cmdline', function() local screen = Screen.new(60, 6) screen:set_default_attr_ids({ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [1] = {bold = true, reverse = true}, -- MsgSeparator + [1] = {bold = true, reverse = true}, -- MsgSeparator, StatusLine }) screen:attach() exec([[ - set cmdheight=2 + set laststatus=2 + set statusline=%=:%{getcmdline()} autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif ]]) + -- :redrawstatus is postponed if messages have scrolled feed([[:echo "one\ntwo\nthree\nfour"]]) feed(':foobar') screen:expect([[ @@ -195,6 +197,16 @@ describe('cmdline', function() four | :foobar^ | ]]) + -- it is not postponed if messages have not scrolled + feed(':foobar') + screen:expect([[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {1: :foobar}| + :foobar^ | + ]]) end) end) -- cgit From cfdc93e8ac3e6c1577f1582c4b9546c118aa7987 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Sep 2022 21:58:39 +0800 Subject: vim-patch:9.0.0511: unnecessary scrolling for message of only one line (#20261) Problem: Unnecessary scrolling for message of only one line. Solution: Only set msg_scroll when needed. (closes vim/vim#11178) https://github.com/vim/vim/commit/bdedd2bcce3a59028c7504a397ff77d901b1b12a --- test/functional/legacy/messages_spec.lua | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/messages_spec.lua b/test/functional/legacy/messages_spec.lua index 159cf7a551..c76ce62ef0 100644 --- a/test/functional/legacy/messages_spec.lua +++ b/test/functional/legacy/messages_spec.lua @@ -10,6 +10,43 @@ before_each(clear) describe('messages', function() local screen + -- oldtest: Test_warning_scroll() + it('a warning causes scrolling if and only if it has a stacktrace', function() + screen = Screen.new(75, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg + [2] = {bold = true, reverse = true}, -- MsgSeparator + [3] = {foreground = Screen.colors.Red}, -- WarningMsg + }) + screen:attach() + + -- When the warning comes from a script, messages are scrolled so that the + -- stacktrace is visible. + -- It is a bit hard to assert the screen when sourcing a script, so skip this part. + + -- When the warning does not come from a script, messages are not scrolled. + command('enew') + command('set readonly') + feed('u') + screen:expect({grid = [[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {3:W10: Warning: Changing a readonly file}^ | + ]], timeout = 500}) + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + Already at oldest change | + ]]) + end) + describe('more prompt', function() before_each(function() screen = Screen.new(75, 6) -- cgit From ec94014cd1d09884b12cb19021d5a1eff52cb76d Mon Sep 17 00:00:00 2001 From: ofwinterpassed Date: Tue, 20 Sep 2022 22:14:58 +0200 Subject: fix(lsp): out of bounds error in lsp.util.apply_text_edits (#20137) Co-authored-by: Jonas Strittmatter <40792180+smjonas@users.noreply.github.com> --- test/functional/plugin/lsp_spec.lua | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index e7ea089fbf..e032f3bc2b 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1719,6 +1719,46 @@ describe('LSP', function() end) end) + describe('apply_text_edits regression tests for #20116', function() + before_each(function() + insert(dedent([[ + Test line one + Test line two 21 char]])) + end) + describe('with LSP end column out of bounds and start column at 0', function() + it('applies edits at the end of the buffer', function() + local edits = { + make_edit(0, 0, 1, 22, {'#include "whatever.h"\r\n#include \r'}); + } + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") + eq({'#include "whatever.h"', '#include '}, buf_lines(1)) + end) + it('applies edits in the middle of the buffer', function() + local edits = { + make_edit(0, 0, 0, 22, {'#include "whatever.h"\r\n#include \r'}); + } + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") + eq({'#include "whatever.h"', '#include ', 'Test line two 21 char'}, buf_lines(1)) + end) + end) + describe('with LSP end column out of bounds and start column NOT at 0', function() + it('applies edits at the end of the buffer', function() + local edits = { + make_edit(0, 2, 1, 22, {'#include "whatever.h"\r\n#include \r'}); + } + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") + eq({'Te#include "whatever.h"', '#include '}, buf_lines(1)) + end) + it('applies edits in the middle of the buffer', function() + local edits = { + make_edit(0, 2, 0, 22, {'#include "whatever.h"\r\n#include \r'}); + } + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, "utf-8") + eq({'Te#include "whatever.h"', '#include ', 'Test line two 21 char'}, buf_lines(1)) + end) + end) + end) + describe('apply_text_document_edit', function() local target_bufnr local text_document_edit = function(editVersion) -- cgit From ad1f353fe1aeb54144a34d1a0de8e318bd5113aa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 21 Sep 2022 06:47:29 +0800 Subject: vim-patch:9.0.0517: when at the command line :redrawstatus does not work well (#20266) Problem: When at the command line :redrawstatus does not work well. Solution: Only update the statuslines instead of the screen. (closes vim/vim#11180) https://github.com/vim/vim/commit/320d910064320f894a09ffdd1cd800ff5371e97f --- test/functional/legacy/cmdline_spec.lua | 53 +++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 8325f7eeb0..49e3825693 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -175,7 +175,7 @@ describe('cmdline', function() -- oldtest: Test_redrawstatus_in_autocmd() it(':redrawstatus in cmdline mode', function() - local screen = Screen.new(60, 6) + local screen = Screen.new(60, 8) screen:set_default_attr_ids({ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText [1] = {bold = true, reverse = true}, -- MsgSeparator, StatusLine @@ -184,13 +184,16 @@ describe('cmdline', function() exec([[ set laststatus=2 set statusline=%=:%{getcmdline()} - autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif + autocmd CmdlineChanged * redrawstatus + set display-=msgsep ]]) -- :redrawstatus is postponed if messages have scrolled feed([[:echo "one\ntwo\nthree\nfour"]]) feed(':foobar') screen:expect([[ - {1: }| + {0:~ }| + {0:~ }| + {1: :echo "one\ntwo\nthree\nfour"}| one | two | three | @@ -198,14 +201,52 @@ describe('cmdline', function() :foobar^ | ]]) -- it is not postponed if messages have not scrolled - feed(':foobar') + feed(':for in in range(3)') screen:expect([[ | {0:~ }| {0:~ }| {0:~ }| - {1: :foobar}| - :foobar^ | + {0:~ }| + {0:~ }| + {1: :for in in range(3)}| + :for in in range(3)^ | + ]]) + -- with cmdheight=1 messages have scrolled when typing :endfor + feed(':endfor') + screen:expect([[ + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {1: :for in in range(3)}| + :for in in range(3) | + : :endfor^ | + ]]) + feed(':set cmdheight=2') + -- with cmdheight=2 messages haven't scrolled when typing :for or :endfor + feed(':for in in range(3)') + screen:expect([[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {1: :for in in range(3)}| + :for in in range(3)^ | + | + ]]) + feed(':endfor') + screen:expect([[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {1: ::endfor}| + :for in in range(3) | + : :endfor^ | ]]) end) end) -- cgit From 71e70d0c9919f1ab25fe3940b32ce549f49b30e8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 09:43:37 +0800 Subject: vim-patch:9.0.0537: the do_set() function is much too long (#20274) Problem: The do_set() function is much too long. Solution: Move setting of a string option to a separate function. https://github.com/vim/vim/commit/4740394f230dda09d6e9337465305741d8ee4fa3 Cherry-pick some tests from Vim patch 8.2.0540. --- test/functional/shada/shada_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional') diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index d10a2facbb..f5a81eb2ef 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -238,6 +238,15 @@ describe('ShaDa support code', function() eq('', meths.get_option('shada')) end) + it('setting &shada gives proper error message on missing number', function() + eq([[Vim(set):E526: Missing number after <">: shada="]], + exc_exec([[set shada=\"]])) + for _, c in ipairs({"'", "/", ":", "<", "@", "s"}) do + eq(([[Vim(set):E526: Missing number after <%s>: shada=%s]]):format(c, c), + exc_exec(([[set shada=%s]]):format(c))) + end + end) + it('does not crash when ShaDa file directory is not writable', function() if helpers.pending_win32(pending) then return end -- cgit From 00cfc1dcebd1c81dd0d8c111740782e86cf2e385 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 16 Sep 2022 19:21:32 +0200 Subject: fix(redraw): avoid unnecessary redraws and glitches with floats+messages fixes #20106 fixes #20229 --- test/functional/ui/cmdline_spec.lua | 175 ++++++++++-------- test/functional/ui/float_spec.lua | 360 ++++++++++++++++++++++++++++++++++++ 2 files changed, 463 insertions(+), 72 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 40dee4186b..92eb853686 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -934,6 +934,15 @@ describe('cmdheight=0', function() before_each(function() clear() screen = Screen.new(25, 5) + screen:set_default_attr_ids { + [1] = {bold = true, foreground = Screen.colors.Blue}; + [2] = {bold = true, reverse = true}; + [3] = {bold = true}; + [4] = {foreground = Screen.colors.White, background = Screen.colors.Red}; + [5] = {foreground = Screen.colors.SeaGreen4, bold = true}; + [6] = {reverse = true}; + [7] = {background = Screen.colors.Yellow}; + } screen:attach() end) @@ -941,9 +950,9 @@ describe('cmdheight=0', function() command("set cmdheight=1 noruler laststatus=2") screen:expect{grid=[[ ^ | - ~ | - ~ | - [No Name] | + {1:~ }| + {1:~ }| + {2:[No Name] }| | ]]} end) @@ -952,10 +961,10 @@ describe('cmdheight=0', function() command("set cmdheight=0 noruler laststatus=2") screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - [No Name] | + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| ]]} end) @@ -963,10 +972,10 @@ describe('cmdheight=0', function() command("set cmdheight=0 ruler laststatus=0") screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - ~ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| ]]} end) @@ -975,10 +984,10 @@ describe('cmdheight=0', function() feed('i') screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - ~ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| ]], showmode={}} feed('') eq(0, eval('&cmdheight')) @@ -989,10 +998,10 @@ describe('cmdheight=0', function() feed('i') screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - ~ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| ]], showmode={}} feed('') eq(0, eval('&cmdheight')) @@ -1003,10 +1012,10 @@ describe('cmdheight=0', function() feed('i') screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - -- INSERT -- | + {1:~ }| + {1:~ }| + {1:~ }| + {3:-- INSERT --} | ]]} feed('') eq(1, eval('&cmdheight')) @@ -1017,19 +1026,19 @@ describe('cmdheight=0', function() feed(':') screen:expect{grid=[[ | - ~ | - ~ | - ~ | + {1:~ }| + {1:~ }| + {1:~ }| :^ | ]]} eq(0, eval('&cmdheight')) feed('') screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - ~ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| ]], showmode={}} eq(0, eval('&cmdheight')) end) @@ -1039,8 +1048,8 @@ describe('cmdheight=0', function() feed(':call input("foo >")') screen:expect{grid=[[ | - ~ | - | + {1:~ }| + {2: }| :call input("foo >") | foo >^ | ]]} @@ -1048,10 +1057,10 @@ describe('cmdheight=0', function() feed('') screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - ~ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| ]], showmode={}} eq(0, eval('&cmdheight')) end) @@ -1060,35 +1069,35 @@ describe('cmdheight=0', function() command("set cmdheight=0 noruler laststatus=3 winbar=foo") feed(':split') screen:expect{grid=[[ - | + {2: }| :split | - E36: Not enough room | - Press ENTER or type comma| - nd to continue^ | + {4:E36: Not enough room} | + {5:Press ENTER or type comma}| + {5:nd to continue}^ | ]]} feed('') screen:expect{grid=[[ - foo | + {3:foo }| ^ | - ~ | - ~ | - [No Name] | + {1:~ }| + {1:~ }| + {2:[No Name] }| ]]} feed(':') screen:expect{grid=[[ - foo | + {3:foo }| | - ~ | - ~ | + {1:~ }| + {1:~ }| :^ | ]]} feed('') screen:expect{grid=[[ - foo | + {3:foo }| ^ | - ~ | - ~ | - [No Name] | + {1:~ }| + {1:~ }| + {2:[No Name] }| ]], showmode={}} eq(0, eval('&cmdheight')) @@ -1100,18 +1109,18 @@ describe('cmdheight=0', function() feed('qq') screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - ~ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| ]]} feed('q') screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | - ~ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| ]], unchanged=true} end) @@ -1120,28 +1129,28 @@ describe('cmdheight=0', function() feed('ifoo') screen:expect{grid=[[ fo^o | - ~ | - ~ | - ~ | - [No Name] [+] | + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] [+] }| ]]} feed(':%s/foo/bar/gc') screen:expect{grid=[[ - foo | - ~ | - ~ | - ~ | - replace wi...q/l/^E/^Y)?^ | + {6:foo} | + {1:~ }| + {1:~ }| + {1:~ }| + {5:replace wi...q/l/^E/^Y)?}^ | ]]} feed('y') screen:expect{grid=[[ ^bar | - ~ | - ~ | - ~ | - [No Name] [+] | + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] [+] }| ]]} assert_alive() @@ -1152,4 +1161,26 @@ describe('cmdheight=0', function() feed('+') eq(0, eval('&cmdheight')) end) + + it("with non-silent mappings with cmdline", function() + command("set cmdheight=0") + command("map :nohlsearch") + feed('iaabbaa/aa') + screen:expect{grid=[[ + {7:^aa}bb{7:aa} | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]} + + feed('') + screen:expect{grid=[[ + ^aabbaa | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]} + end) end) diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 5967b630f6..a5a664cb3d 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -8147,6 +8147,366 @@ describe('float window', function() ]]} end end) + + it('it can be resized with messages and cmdheight=0 #20106', function() + screen:try_resize(40,9) + command 'set cmdheight=0' + local buf = meths.create_buf(false,true) + local win = meths.open_win(buf, false, {relative='editor', width=40, height=4, anchor='SW', row=9, col=0, style='minimal', border="single", noautocmd=true}) + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + ## grid 5 + {5:┌────────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└────────────────────────────────────────┘}| + ]], float_pos={ + [5] = {{id = 1002}, "SW", 1, 9, 0, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + {5:┌──────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└──────────────────────────────────────┘}| + ]]} + end + + exec_lua([[ + local win = ... + vim.api.nvim_win_set_height(win, 2) + vim.api.nvim_echo({ { "" } }, false, {}) + ]], win) + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + ## grid 5 + {5:┌────────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└────────────────────────────────────────┘}| + ]], float_pos={ + [5] = {{id = 1002}, "SW", 1, 9, 0, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {5:┌──────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└──────────────────────────────────────┘}| + ]]} + + end + + meths.win_close(win, true) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + ]], win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ]]} + end + end) + + it('it can be resized with messages and cmdheight=1', function() + screen:try_resize(40,9) + local buf = meths.create_buf(false,true) + local win = meths.open_win(buf, false, {relative='editor', width=40, height=4, anchor='SW', row=8, col=0, style='minimal', border="single", noautocmd=true}) + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {5:┌────────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└────────────────────────────────────────┘}| + ]], float_pos={ + [5] = {{id = 1002}, "SW", 1, 8, 0, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {5:┌──────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└──────────────────────────────────────┘}| + | + ]]} + end + + exec_lua([[ + -- echo prompt is blocking, so schedule + local win = ... + vim.schedule(function() + vim.api.nvim_win_set_height(win, 2) + vim.api.nvim_echo({ { "\n" } }, false, {}) + end) + ]], win) + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + {8:Press ENTER or type command to continue}^ | + ## grid 5 + {5:┌────────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└────────────────────────────────────────┘}| + ]], float_pos={ + [5] = {{id = 1002}, "SW", 1, 8, 0, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + else + screen:expect{grid=[[ + | + {0:~ }| + {5:┌──────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {4: }| + | + {8:Press ENTER or type command to continue}^ | + ]]} + end + + feed('') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {5:┌────────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└────────────────────────────────────────┘}| + ]], float_pos={ + [5] = {{id = 1002}, "SW", 1, 8, 0, true, 50}; + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {5:┌──────────────────────────────────────┐}| + {5:│}{1: }{5:│}| + {5:│}{1: }{5:│}| + {5:└──────────────────────────────────────┘}| + | + ]]} + end + + meths.win_close(win, true) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ]], win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + end + end) end describe('with ext_multigrid', function() -- cgit From 93b30582db520ae20d66b000053007c11b62c15d Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 17 Aug 2022 15:40:21 +0200 Subject: fix(redraw): make redrawdebug=nodelta handle all the cases Before only win_line lines were considered. this applies nodelta to all screen elements. Causes some failures, which might indeed indicate excessive redraws. --- test/functional/ui/syntax_conceal_spec.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/syntax_conceal_spec.lua b/test/functional/ui/syntax_conceal_spec.lua index f790597140..e8798ddd93 100644 --- a/test/functional/ui/syntax_conceal_spec.lua +++ b/test/functional/ui/syntax_conceal_spec.lua @@ -947,7 +947,7 @@ describe('Screen', function() {0:~ }| | ]]} - eq({{2, 0, {{'c', 0, 3}}}}, grid_lines) + eq({{2, 0, {{'c', 0, 3}, {' ', 0, 50}}}, {3, 0, {{' ', 0, 53}}}}, grid_lines) end) it('K_EVENT should not cause extra redraws with concealcursor #13196', function() @@ -994,10 +994,11 @@ describe('Screen', function() {0:~ }| | ]]} - eq({{2, 0, {{'c', 0, 3}}}}, grid_lines) + eq({{2, 0, {{'c', 0, 3}, {' ', 0, 50}}}}, grid_lines) + grid_lines = {} poke_eventloop() -- causes K_EVENT key screen:expect_unchanged() - eq({{2, 0, {{'c', 0, 3}}}}, grid_lines) + eq({}, grid_lines) -- no redraw was done end) -- Copy of Test_cursor_column_in_concealed_line_after_window_scroll in -- cgit From 02f8ca59a80cd3570593c717ff6ceadc33239b89 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 20 Sep 2022 22:03:16 +0200 Subject: fix(tests): indicate in test logs when nvim exit times out When it happens it wastes 2 seconds which is NOT included in the normal busted timing info. It is hard to correct this, but we can at least print a warning when this happens. --- .../fixtures/start/nvim-leftpad/lua/async_leftpad.lua | 4 +++- test/functional/helpers.lua | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua b/test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua index a312572c5b..45226ce24b 100644 --- a/test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua +++ b/test/functional/fixtures/start/nvim-leftpad/lua/async_leftpad.lua @@ -1,3 +1,5 @@ return function (val, res) - vim.loop.new_async(function() _G[res] = require'leftpad'(val) end):send() + local handle + handle = vim.loop.new_async(function() _G[res] = require'leftpad'(val) handle:close() end) + handle:send() end diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index d672037a1e..eff54b6d4a 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -380,10 +380,23 @@ local function remove_args(args, args_rm) return new_args end +function module.check_close(old_session) + local start_time = luv.now() + old_session:close() + luv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). + local end_time = luv.now() + local delta = end_time - start_time + if delta > 500 then + print("nvim took " .. delta .. " milliseconds to exit after last test\n".. + "This indicates a likely problem with the test even if it passed!\n") + io.stdout:flush() + end +end + --- @param io_extra used for stdin_fd, see :help ui-option function module.spawn(argv, merge, env, keep, io_extra) if session and not keep then - session:close() + module.check_close(session) end local child_stream = ChildProcessStream.spawn( -- cgit From 2083c1771ad2de44c8e085062a0777e694b0fd4d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 20:25:34 +0800 Subject: fix(window): close floats first when closing buffer in other tab (#20284) --- test/functional/ui/float_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index a5a664cb3d..5e819f14a3 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -596,6 +596,11 @@ describe('float window', function() meths.buf_delete(old_buf, {force = true}) eq(old_win, curwin().id) end) + it('if called from non-floating window in another tabpage', function() + command('tab split') + eq(3, #meths.list_tabpages()) + meths.buf_delete(old_buf, {force = true}) + end) it('if called from floating window with the same buffer', function() meths.set_current_win(same_buf_float) command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()') -- cgit From 09b64d75bd92a95d89c4f39f9df7918760abe98d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 27 Mar 2022 19:47:34 -0700 Subject: feat(docs): gen_help_html.lua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: The :help docs HTML generated is driven by an old awk script `runtime/doc/makehtml.awk` that is hard to maintain (ad hoc parser and no one has touched it in decades) and has bugs like: - https://github.com/neovim/neovim.github.io/issues/96 - https://github.com/neovim/neovim.github.io/issues/97 Solution: Use Lua + treesitter (https://github.com/vigoux/tree-sitter-vimdoc) to generate :help docs HTML. Also validates tag links. fix https://github.com/neovim/neovim.github.io/issues/96 fix https://github.com/neovim/neovim.github.io/issues/97 TODO: - delete doc_html build task - delete runtime/doc/Makefile - delete makehtml.awk - delete maketags.awk OUTPUT: $ nvim -V1 -es --clean +"lua require('scripts.gen_help_html')" output dir: /…/neovim.github.io/_site/doc/ generated (207 errors): api.txt => api.html generated (122 errors): arabic.txt => arabic.html generated (285 errors): autocmd.txt => autocmd.html generated (641 errors): builtin.txt => builtin.html generated (623 errors): change.txt => change.html generated (65 errors): channel.txt => channel.html generated (353 errors): cmdline.txt => cmdline.html generated (3 errors): debug.txt => debug.html generated (28 errors): deprecated.txt => deprecated.html generated (193 errors): dev_style.txt => dev_style.html generated (460 errors): develop.txt => develop.html generated (19 errors): diagnostic.txt => diagnostic.html generated (57 errors): diff.txt => diff.html generated (818 errors): digraph.txt => digraph.html generated (330 errors): editing.txt => editing.html generated (368 errors): eval.txt => eval.html generated (184 errors): fold.txt => fold.html generated (61 errors): ft_ada.txt => ft_ada.html generated (0 errors): ft_ps1.txt => ft_ps1.html generated (20 errors): ft_raku.txt => ft_raku.html generated (5 errors): ft_rust.txt => ft_rust.html generated (41 errors): ft_sql.txt => ft_sql.html generated (110 errors): gui.txt => gui.html generated (79 errors): hebrew.txt => hebrew.html generated (17 errors): help.txt => index.html generated (104 errors): helphelp.txt => helphelp.html generated (0 errors): if_cscop.txt => if_cscop.html generated (23 errors): if_perl.txt => if_perl.html generated (16 errors): if_pyth.txt => if_pyth.html generated (9 errors): if_ruby.txt => if_ruby.html generated (216 errors): indent.txt => indent.html generated (634 errors): index.txt => vimindex.html generated (320 errors): insert.txt => insert.html generated (265 errors): intro.txt => intro.html generated (9 errors): job_control.txt => job_control.html generated (0 errors): lsp-extension.txt => lsp-extension.html generated (214 errors): lsp.txt => lsp.html generated (311 errors): lua.txt => lua.html generated (592 errors): luaref.txt => luaref.html generated (798 errors): luvref.txt => luvref.html generated (663 errors): map.txt => map.html generated (228 errors): mbyte.txt => mbyte.html generated (228 errors): message.txt => message.html generated (0 errors): mlang.txt => mlang.html generated (761 errors): motion.txt => motion.html generated (4 errors): nvim.txt => nvim.html generated (226 errors): nvim_terminal_emulator.txt => nvim_terminal_emulator.html generated (988 errors): options.txt => options.html generated (567 errors): pattern.txt => pattern.html generated (15 errors): pi_gzip.txt => pi_gzip.html generated (10 errors): pi_health.txt => pi_health.html generated (27 errors): pi_msgpack.txt => pi_msgpack.html generated (2177 errors): pi_netrw.txt => pi_netrw.html generated (41 errors): pi_paren.txt => pi_paren.html generated (9 errors): pi_spec.txt => pi_spec.html generated (218 errors): pi_tar.txt => pi_tar.html generated (0 errors): pi_tutor.txt => pi_tutor.html generated (235 errors): pi_zip.txt => pi_zip.html generated (265 errors): print.txt => print.html generated (31 errors): provider.txt => provider.html generated (335 errors): quickfix.txt => quickfix.html generated (572 errors): quickref.txt => quickref.html generated (109 errors): recover.txt => recover.html generated (14 errors): remote.txt => remote.html generated (14 errors): remote_plugin.txt => remote_plugin.html generated (351 errors): repeat.txt => repeat.html generated (23 errors): rileft.txt => rileft.html generated (12 errors): russian.txt => russian.html generated (6 errors): scroll.txt => scroll.html generated (106 errors): sign.txt => sign.html generated (347 errors): spell.txt => spell.html generated (784 errors): starting.txt => starting.html generated (1499 errors): syntax.txt => syntax.html generated (23 errors): tabpage.txt => tabpage.html generated (257 errors): tagsrch.txt => tagsrch.html generated (31 errors): term.txt => term.html generated (0 errors): testing.txt => testing.html generated (96 errors): tips.txt => tips.html generated (57 errors): treesitter.txt => treesitter.html generated (71 errors): uganda.txt => uganda.html generated (74 errors): ui.txt => ui.html generated (87 errors): undo.txt => undo.html generated (17 errors): userfunc.txt => userfunc.html generated (1 errors): usr_01.txt => usr_01.html generated (89 errors): usr_02.txt => usr_02.html generated (293 errors): usr_03.txt => usr_03.html generated (46 errors): usr_04.txt => usr_04.html generated (96 errors): usr_05.txt => usr_05.html generated (54 errors): usr_06.txt => usr_06.html generated (20 errors): usr_07.txt => usr_07.html generated (241 errors): usr_08.txt => usr_08.html generated (130 errors): usr_09.txt => usr_09.html generated (50 errors): usr_10.txt => usr_10.html generated (33 errors): usr_11.txt => usr_11.html generated (32 errors): usr_12.txt => usr_12.html generated (22 errors): usr_20.txt => usr_20.html generated (75 errors): usr_21.txt => usr_21.html generated (8 errors): usr_22.txt => usr_22.html generated (3 errors): usr_23.txt => usr_23.html generated (163 errors): usr_25.txt => usr_25.html generated (13 errors): usr_26.txt => usr_26.html generated (84 errors): usr_27.txt => usr_27.html generated (173 errors): usr_28.txt => usr_28.html generated (285 errors): usr_29.txt => usr_29.html generated (280 errors): usr_30.txt => usr_30.html generated (11 errors): usr_31.txt => usr_31.html generated (13 errors): usr_32.txt => usr_32.html generated (156 errors): usr_40.txt => usr_40.html generated (134 errors): usr_41.txt => usr_41.html generated (35 errors): usr_42.txt => usr_42.html generated (19 errors): usr_43.txt => usr_43.html generated (60 errors): usr_44.txt => usr_44.html generated (13 errors): usr_45.txt => usr_45.html generated (1 errors): usr_toc.txt => usr_toc.html generated (69 errors): various.txt => various.html generated (68 errors): vi_diff.txt => vi_diff.html generated (437 errors): vim_diff.txt => vim_diff.html generated (296 errors): visual.txt => visual.html generated (181 errors): windows.txt => windows.html generated 119 html pages total errors: 23862 invalid tags: 537 --- test/functional/lua/help_spec.lua | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/functional/lua/help_spec.lua (limited to 'test/functional') diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua new file mode 100644 index 0000000000..266f261ab9 --- /dev/null +++ b/test/functional/lua/help_spec.lua @@ -0,0 +1,54 @@ +-- Tests for gen_help_html.lua. Validates :help tags/links and HTML doc generation. +-- +-- TODO: extract parts of gen_help_html.lua into Nvim stdlib? + +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local exec_lua = helpers.exec_lua +local eq = helpers.eq +local ok = helpers.ok + +describe(':help docs', function() + before_each(clear) + it('validate', function() + -- If this test fails, try these steps (in order): + -- 1. Try to fix/cleanup the :help docs, especially Nvim-owned :help docs. + -- 2. Try to fix the parser: https://github.com/vigoux/tree-sitter-vimdoc + -- 3. File a parser bug, and adjust the tolerance of this test in the meantime. + + local rv = exec_lua([[return require('scripts.gen_help_html').validate('./build/runtime/doc')]]) + -- Check that parse errors did not increase wildly. + -- TODO: yes, there are currently 24k+ parser errors. + -- WIP: https://github.com/vigoux/tree-sitter-vimdoc/pull/16 + ok(rv.err_count < 24000, '<24000', rv.err_count) + -- TODO: should be eq(0, …) + ok(exec_lua('return vim.tbl_count(...)', rv.invalid_tags) < 538, '<538', + exec_lua('return vim.inspect(...)', rv.invalid_tags)) + end) + + it('gen_help_html.lua generates HTML', function() + -- Test: + -- 1. Check that parse errors did not increase wildly. Because we explicitly test only a few + -- :help files, we can be more precise about the tolerances here. + -- 2. exercise gen_help_html.lua, check that it actually works. + -- 3. check that its tree-sitter-vimdoc dependency is working. + + local tmpdir = exec_lua('return vim.fs.dirname(vim.fn.tempname())') + -- Because gen() is slow (1 min), this test is limited to a few files. + local rv = exec_lua([[ + local to_dir = ... + return require('scripts.gen_help_html').gen( + './build/runtime/doc', + to_dir, + { 'pi_health.txt', 'help.txt', 'index.txt', 'nvim.txt', } + ) + ]], + tmpdir + ) + eq(4, #rv.helpfiles) + ok(rv.err_count < 700, '<700', rv.err_count) + -- TODO: should be eq(0, …) + ok(exec_lua('return vim.tbl_count(...)', rv.invalid_tags) <= 32, '<=32', + exec_lua('return vim.inspect(...)', rv.invalid_tags)) + end) +end) -- cgit From d7052e8e1f0311113199ae5c25886fa9690367e4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 23 Sep 2022 07:21:51 +0800 Subject: test: add tests for #13549 #20285 #20290 --- test/functional/editor/tabpage_spec.lua | 42 ++++++++++++++++++++++++++++++++ test/functional/terminal/buffer_spec.lua | 6 +++++ 2 files changed, 48 insertions(+) (limited to 'test/functional') diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index 849a02c28b..01779a9a92 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -9,6 +9,9 @@ local feed = helpers.feed local eval = helpers.eval local exec = helpers.exec local funcs = helpers.funcs +local meths = helpers.meths +local curwin = helpers.curwin +local assert_alive = helpers.assert_alive describe('tabpage', function() before_each(clear) @@ -54,6 +57,45 @@ describe('tabpage', function() neq(999, eval('g:win_closed')) end) + it('no segfault with strange WinClosed autocommand #20290', function() + pcall(exec, [[ + set nohidden + edit Xa + split Xb + tab split + new + autocmd WinClosed * tabprev | bwipe! + close + ]]) + assert_alive() + end) + + it('nvim_win_close and nvim_win_hide update tabline #20285', function() + eq(1, #meths.list_tabpages()) + eq({1, 1}, funcs.win_screenpos(0)) + local win1 = curwin().id + + command('tabnew') + eq(2, #meths.list_tabpages()) + eq({2, 1}, funcs.win_screenpos(0)) + local win2 = curwin().id + + meths.win_close(win1, true) + eq(win2, curwin().id) + eq(1, #meths.list_tabpages()) + eq({1, 1}, funcs.win_screenpos(0)) + + command('tabnew') + eq(2, #meths.list_tabpages()) + eq({2, 1}, funcs.win_screenpos(0)) + local win3 = curwin().id + + meths.win_close(win2, true) + eq(win3, curwin().id) + eq(1, #meths.list_tabpages()) + eq({1, 1}, funcs.win_screenpos(0)) + end) + it('switching tabpage after setting laststatus=3 #19591', function() local screen = Screen.new(40, 8) screen:set_default_attr_ids({ diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 23430a620b..9d10f43ec6 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -4,6 +4,7 @@ local assert_alive = helpers.assert_alive local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim local poke_eventloop = helpers.poke_eventloop local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source +local pcall_err = helpers.pcall_err local eq, neq = helpers.eq, helpers.neq local meths = helpers.meths local retry = helpers.retry @@ -339,6 +340,11 @@ describe(':terminal buffer', function() ]]} eq('t', funcs.mode(1)) end) + + it('writing to an existing file with :w fails #13549', function() + eq('Vim(write):E13: File exists (add ! to override)', + pcall_err(command, 'write test/functional/fixtures/tty-test.c')) + end) end) describe('No heap-buffer-overflow when using', function() -- cgit From 7a70e9587c866c506182a32839f4c3b27b9a3b40 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 23 Sep 2022 10:17:44 +0800 Subject: test(tabpage_spec): actually test for nvim_win_hide --- test/functional/editor/tabpage_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index 01779a9a92..f8ca6986bd 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -90,7 +90,7 @@ describe('tabpage', function() eq({2, 1}, funcs.win_screenpos(0)) local win3 = curwin().id - meths.win_close(win2, true) + meths.win_hide(win2) eq(win3, curwin().id) eq(1, #meths.list_tabpages()) eq({1, 1}, funcs.win_screenpos(0)) -- cgit From caf5738fa9cc12fd448a9c0787a3ebf0c8e696e9 Mon Sep 17 00:00:00 2001 From: shaunsingh Date: Sat, 24 Sep 2022 06:46:21 -0400 Subject: fix(lsp): create missing directory before creating file (#19835) Co-authored-by: Mathias Fussenegger --- test/functional/plugin/lsp_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index e032f3bc2b..bcae9b4084 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1977,6 +1977,22 @@ describe('LSP', function() exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', tmpfile)) end) + it('Supports file creation in folder that needs to be created with CreateFile payload', function() + local tmpfile = helpers.tmpname() + os.remove(tmpfile) -- Should not exist, only interested in a tmpname + tmpfile = tmpfile .. '/dummy/x/' + local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) + local edit = { + documentChanges = { + { + kind = 'create', + uri = uri, + }, + } + } + exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') + eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', tmpfile)) + end) it('createFile does not touch file if it exists and ignoreIfExists is set', function() local tmpfile = helpers.tmpname() write_file(tmpfile, 'Dummy content') -- cgit From 291a6496327e90056ea68085ad52ab74ca1df752 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Sep 2022 21:07:18 +0800 Subject: fix(mapset): remove existing abbreviation of same lhs (#20320) --- test/functional/vimscript/map_functions_spec.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index 96b86d053e..ed1863754a 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -12,6 +12,7 @@ local meths = helpers.meths local nvim = helpers.nvim local source = helpers.source local command = helpers.command +local exec_capture = helpers.exec_capture local pcall_err = helpers.pcall_err describe('maparg()', function() @@ -178,8 +179,9 @@ describe('mapset()', function() eq('\nn lhs rhs\n map description', helpers.exec_capture("nmap lhs")) local mapargs = funcs.maparg('lhs', 'n', false, true) - meths.del_keymap('n', 'lhs') - eq('\nNo mapping found', helpers.exec_capture("nmap lhs")) + meths.set_keymap('n', 'lhs', 'rhs', {desc = 'MAP DESCRIPTION'}) + eq('\nn lhs rhs\n MAP DESCRIPTION', + helpers.exec_capture("nmap lhs")) funcs.mapset('n', false, mapargs) eq('\nn lhs rhs\n map description', helpers.exec_capture("nmap lhs")) @@ -198,6 +200,22 @@ describe('mapset()', function() expect('<<') end) + it('replaces an abbreviation of the same lhs #20320', function() + command('inoreabbr foo bar') + eq('\ni foo * bar', exec_capture('iabbr foo')) + feed('ifoo ') + expect('bar ') + local mapargs = funcs.maparg('foo', 'i', true, true) + command('inoreabbr foo BAR') + eq('\ni foo * BAR', exec_capture('iabbr foo')) + feed('foo ') + expect('bar BAR ') + funcs.mapset('i', true, mapargs) + eq('\ni foo * bar', exec_capture('iabbr foo')) + feed('foo') + expect('bar BAR bar') + end) + it('can restore Lua callback from the dict returned by maparg()', function() eq(0, exec_lua([[ GlobalCount = 0 -- cgit From 8317b9199edc6936fec829f4908f9c74dc874ce4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Sep 2022 22:28:41 +0800 Subject: fix(input): use click number of last click for mouse drag (#20300) --- test/functional/ui/mouse_spec.lua | 96 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index 8c5475ecce..cb8dfdb8e1 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -648,8 +648,10 @@ describe('ui/mouse/input', function() ]]} end) - it('two clicks will select the word and enter VISUAL', function() - feed('<2,2><2,2>') + it('two clicks will enter VISUAL and dragging selects words', function() + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') screen:expect([[ testing | mouse | @@ -657,10 +659,38 @@ describe('ui/mouse/input', function() {0:~ }| {2:-- VISUAL --} | ]]) + feed('<0,1>') + screen:expect([[ + testing | + ^m{1:ouse} | + {1:support} and selection | + {0:~ }| + {2:-- VISUAL --} | + ]]) + feed('<4,0>') + screen:expect([[ + ^t{1:esting} | + {1:mouse} | + {1:support} and selection | + {0:~ }| + {2:-- VISUAL --} | + ]]) + feed('<14,2>') + screen:expect([[ + testing | + mouse | + {1:support and selectio}^n | + {0:~ }| + {2:-- VISUAL --} | + ]]) end) - it('three clicks will select the line and enter VISUAL LINE', function() - feed('<2,2><2,2><2,2>') + it('three clicks will enter VISUAL LINE and dragging selects lines', function() + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') screen:expect([[ testing | mouse | @@ -668,10 +698,40 @@ describe('ui/mouse/input', function() {0:~ }| {2:-- VISUAL LINE --} | ]]) + feed('<0,1>') + screen:expect([[ + testing | + ^m{1:ouse} | + {1:support and selection} | + {0:~ }| + {2:-- VISUAL LINE --} | + ]]) + feed('<4,0>') + screen:expect([[ + {1:test}^i{1:ng} | + {1:mouse} | + {1:support and selection} | + {0:~ }| + {2:-- VISUAL LINE --} | + ]]) + feed('<14,2>') + screen:expect([[ + testing | + mouse | + {1:support and se}^l{1:ection} | + {0:~ }| + {2:-- VISUAL LINE --} | + ]]) end) - it('four clicks will enter VISUAL BLOCK', function() - feed('<2,2><2,2><2,2><2,2>') + it('four clicks will enter VISUAL BLOCK and dragging selects blockwise', function() + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') screen:expect([[ testing | mouse | @@ -679,6 +739,30 @@ describe('ui/mouse/input', function() {0:~ }| {2:-- VISUAL BLOCK --} | ]]) + feed('<0,1>') + screen:expect([[ + testing | + ^m{1:ou}se | + {1:sup}port and selection | + {0:~ }| + {2:-- VISUAL BLOCK --} | + ]]) + feed('<4,0>') + screen:expect([[ + te{1:st}^ing | + mo{1:use} | + su{1:ppo}rt and selection | + {0:~ }| + {2:-- VISUAL BLOCK --} | + ]]) + feed('<14,2>') + screen:expect([[ + testing | + mouse | + su{1:pport and se}^lection | + {0:~ }| + {2:-- VISUAL BLOCK --} | + ]]) end) it('right click extends visual selection to the clicked location', function() -- cgit From 2a3cb0893b03aeff4d8c0b2116cbddda53bba5a2 Mon Sep 17 00:00:00 2001 From: Louis Sven Goulet <31444858+lorlouis@users.noreply.github.com> Date: Sat, 24 Sep 2022 21:57:10 -0400 Subject: feat: ":write!" skips "file changed" warning #18665 Problem: Cannot opt-out of "WARNING: The file has been changed since reading it!!!", even with ":write!". Solution: Change ":write!" to skip the warning. closes #7270 --- test/functional/core/fileio_spec.lua | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'test/functional') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index e71131dcf8..a589d088a4 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -23,6 +23,8 @@ local iswin = helpers.iswin local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit local write_file = helpers.write_file +local Screen = require('test.functional.ui.screen') +local feed_command = helpers.feed_command local uname = helpers.uname describe('fileio', function() @@ -36,6 +38,7 @@ describe('fileio', function() os.remove('Xtest_startup_file2') os.remove('Xtest_тест.md') os.remove('Xtest-u8-int-max') + os.remove('Xtest-overwrite-forced') rmdir('Xtest_startup_swapdir') rmdir('Xtest_backupdir') end) @@ -151,6 +154,61 @@ describe('fileio', function() command('edit ++enc=utf32 Xtest-u8-int-max') assert_alive() end) + + it(':w! does not show "file has been changed" warning', function() + clear() + write_file("Xtest-overwrite-forced", 'foobar') + command('set nofixendofline') + local screen = Screen.new(40,4) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}, + [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + [3] = {bold = true, foreground = Screen.colors.SeaGreen4} + }) + screen:attach() + command("set display-=msgsep shortmess-=F") + + command("e Xtest-overwrite-forced") + screen:expect([[ + ^foobar | + {1:~ }| + {1:~ }| + "Xtest-overwrite-forced" [noeol] 1L, 6B | + ]]) + + -- Get current unix time. + local cur_unix_time = os.time(os.date("!*t")) + local future_time = cur_unix_time + 999999 + -- Set the file's access/update time to be + -- greater than the time at which it was created. + local uv = require("luv") + uv.fs_utime('Xtest-overwrite-forced', future_time, future_time) + -- use async feed_command because nvim basically hangs on the prompt + feed_command("w") + screen:expect([[ + {2:WARNING: The file has been changed since}| + {2: reading it!!!} | + {3:Do you really want to write to it (y/n)^?}| + | + ]]) + + feed("n") + feed("") + screen:expect([[ + ^foobar | + {1:~ }| + {1:~ }| + | + ]]) + -- Use a screen test because the warning does not set v:errmsg. + command("w!") + screen:expect([[ + ^foobar | + {1:~ }| + {1:~ }| + Date: Sun, 25 Sep 2022 00:45:15 +0200 Subject: refactor(treesitter): rename x_position => x_pos "pos" has a long precedent as "position" in vim, and there is no reason to use a verbose name here. --- test/functional/treesitter/highlight_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index 1684337c3c..ae3f42ff0a 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -607,7 +607,7 @@ describe('treesitter highlighting', function() eq({ {capture='Error', metadata = { priority='101' }}; {capture='type', metadata = { } }; - }, exec_lua [[ return vim.treesitter.get_captures_at_position(0, 0, 2) ]]) + }, exec_lua [[ return vim.treesitter.get_captures_at_pos(0, 0, 2) ]]) end) it("allows to use captures with dots (don't use fallback when specialization of foo exists)", function() -- cgit From fded344f38f0814256b3acd01d94d5942a22f7fc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 25 Sep 2022 21:38:46 +0800 Subject: fix(extmarks): make virt_lines always start at 0 virtcol --- test/functional/ui/decorations_spec.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index eff6fe6d23..44b88d702f 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -1550,6 +1550,38 @@ if (h->n_buckets < new_n_buckets) { // expand } | | ]]} + + command 'set number' + screen:expect{grid=[[ + {9: 1 }^if (h->n_buckets < new_n_buckets) { // expand | + {9: 2 } khkey_t *new_keys = (khkey_t *)krealloc((voi| + {9: }d *)h->keys, new_n_buckets * sizeof(khkey_t));| + {9: }{1:>>}{2: very tabby}text with tabs | + {9: 3 } h->keys = new_keys; | + {9: 4 } if (kh_is_map && val_size) { | + {9: 5 } char *new_vals = krealloc( h->vals_buf, ne| + {9: }w_n_buckets * val_size); | + {9: 6 } h->vals_buf = new_vals; | + {9: 7 } } | + {9: 8 }} | + | + ]]} + + command 'set tabstop&' + screen:expect{grid=[[ + {9: 1 }^if (h->n_buckets < new_n_buckets) { // expand | + {9: 2 } khkey_t *new_keys = (khkey_t *)krealloc((voi| + {9: }d *)h->keys, new_n_buckets * sizeof(khkey_t));| + {9: }{1:>>}{2: very tabby}text with tabs | + {9: 3 } h->keys = new_keys; | + {9: 4 } if (kh_is_map && val_size) { | + {9: 5 } char *new_vals = krealloc( h->vals_buf, ne| + {9: }w_n_buckets * val_size); | + {9: 6 } h->vals_buf = new_vals; | + {9: 7 } } | + {9: 8 }} | + | + ]]} end) end) -- cgit From f8a1cadccff39923643fdea2e282be9fffa60e99 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 25 Sep 2022 22:29:25 +0800 Subject: fix(filetype): use :setf instead of nvim_buf_set_option (#20334) --- test/functional/lua/filetype_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua index be57b2db31..2a7be53164 100644 --- a/test/functional/lua/filetype_spec.lua +++ b/test/functional/lua/filetype_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local exec_lua = helpers.exec_lua local eq = helpers.eq +local meths = helpers.meths local clear = helpers.clear local pathroot = helpers.pathroot local command = helpers.command @@ -94,3 +95,10 @@ describe('vim.filetype', function() ]]) end) end) + +describe('filetype.lua', function() + it('does not override user autocommands that set filetype #20333', function() + clear({args={'--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md'}}) + eq('notmarkdown', meths.buf_get_option(0, 'filetype')) + end) +end) -- cgit From a6c9764edaa349f5f268e5e3bf8b940e137fb5c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Sep 2022 07:00:37 +0800 Subject: fix(inccommand): deal with unsynced undo (#20041) --- test/functional/ui/inccommand_spec.lua | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index 49b3c7a655..6fbf9b72c8 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -3047,6 +3047,43 @@ it(":substitute doesn't crash with inccommand, if undo is empty #12932", functio assert_alive() end) +it(':substitute with inccommand works properly if undo is not synced #20029', function() + local screen = Screen.new(30, 6) + clear() + common_setup(screen, 'nosplit', 'foo\nbar\nbaz') + meths.set_keymap('x', '', '``>obbbbb asdfV`lljj') + screen:expect([[ + aaaaa | + foo | + bar | + baz | + bbbbb | + :'<,'>s/asdf/^ | + ]]) + feed('hjkl') + screen:expect([[ + aaaaa {12:hjkl} | + foo | + bar | + baz | + bbbbb {12:hjkl} | + :'<,'>s/asdf/hjkl^ | + ]]) + feed('') + expect([[ + aaaaa hjkl + foo + bar + baz + bbbbb hjkl]]) + feed('u') + expect([[ + foo + bar + baz]]) +end) + it('long :%s/ with inccommand does not collapse cmdline', function() local screen = Screen.new(10,5) clear() -- cgit From ac66f5af06ac1f306b0ddb366ba81093508546c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Sep 2022 07:15:07 +0800 Subject: fix!: make :undo! notify buffer update callbacks (#20344) When :undo! was introduced to Nvim the implementation of 'inccommand' preview callback hasn't been fully decided yet, so not notifying buffer update callbacks made sense for 'inccommand' preview callback in case it needs to undo the changes itself. Now it turns out that the undo-and-forget is done automatically for 'inccommand', so it doesn't make sense for :undo! to avoid notifying buffer update callbacks anymore. --- test/functional/lua/buffer_updates_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 10de45274c..c6c0964ddb 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -118,6 +118,24 @@ describe('lua buffer event callbacks: on_lines', function() } tick = tick + 1 + tick = tick + 1 + command('redo') + check_events { + { "test1", "lines", 1, tick, 3, 5, 4, 32 }; + { "test2", "lines", 1, tick, 3, 5, 4, 32 }; + { "test2", "changedtick", 1, tick+1 }; + } + tick = tick + 1 + + tick = tick + 1 + command('undo!') + check_events { + { "test1", "lines", 1, tick, 3, 4, 5, 13 }; + { "test2", "lines", 1, tick, 3, 4, 5, 13 }; + { "test2", "changedtick", 1, tick+1 }; + } + tick = tick + 1 + -- simulate next callback returning true exec_lua("test_unreg = 'test1'") -- cgit From 9ffa041a9a5fc8cd9acca97cae16f66ba0c82805 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Sep 2022 07:46:58 +0800 Subject: vim-patch:9.0.0586: missing change in test (#20347) Problem: Missing change in test. Solution: Add the test change. https://github.com/vim/vim/commit/124af71a28a633fa655cff41bc21d398481ce45f vim-patch:9.0.0585: when long message test fails the error message is not visible Problem: When long message test fails the error message is not visible. Solution: Dump more lines. https://github.com/vim/vim/commit/6a879878f4e1918a05244e6acd4c73c3135cf941 --- test/functional/legacy/messages_spec.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/legacy/messages_spec.lua b/test/functional/legacy/messages_spec.lua index c76ce62ef0..5b671bbfdf 100644 --- a/test/functional/legacy/messages_spec.lua +++ b/test/functional/legacy/messages_spec.lua @@ -352,7 +352,7 @@ describe('messages', function() -- oldtest: Test_quit_long_message() it('with control characters can be quit vim-patch:8.2.1844', function() - screen:try_resize(40, 6) + screen:try_resize(40, 10) feed([[:echom range(9999)->join("\x01")]]) screen:expect([[ 0{3:^A}1{3:^A}2{3:^A}3{3:^A}4{3:^A}5{3:^A}6{3:^A}7{3:^A}8{3:^A}9{3:^A}10{3:^A}11{3:^A}12| @@ -360,6 +360,10 @@ describe('messages', function() {3:^A}23{3:^A}24{3:^A}25{3:^A}26{3:^A}27{3:^A}28{3:^A}29{3:^A}30{3:^A}31{3:^A}32| {3:^A}33{3:^A}34{3:^A}35{3:^A}36{3:^A}37{3:^A}38{3:^A}39{3:^A}40{3:^A}41{3:^A}42| {3:^A}43{3:^A}44{3:^A}45{3:^A}46{3:^A}47{3:^A}48{3:^A}49{3:^A}50{3:^A}51{3:^A}52| + {3:^A}53{3:^A}54{3:^A}55{3:^A}56{3:^A}57{3:^A}58{3:^A}59{3:^A}60{3:^A}61{3:^A}62| + {3:^A}63{3:^A}64{3:^A}65{3:^A}66{3:^A}67{3:^A}68{3:^A}69{3:^A}70{3:^A}71{3:^A}72| + {3:^A}73{3:^A}74{3:^A}75{3:^A}76{3:^A}77{3:^A}78{3:^A}79{3:^A}80{3:^A}81{3:^A}82| + {3:^A}83{3:^A}84{3:^A}85{3:^A}86{3:^A}87{3:^A}88{3:^A}89{3:^A}90{3:^A}91{3:^A}92| {1:-- More --}^ | ]]) feed('q') @@ -368,6 +372,10 @@ describe('messages', function() {0:~ }| {0:~ }| {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| {0:~ }| | ]]) -- cgit From 4bb1d1df79bd1f125499e556d5d4e21ac2ff1e5a Mon Sep 17 00:00:00 2001 From: Andrey Bushev Date: Sat, 24 Sep 2022 22:54:30 -0700 Subject: feat(terminal): recognize underdouble and undercurl --- test/functional/terminal/helpers.lua | 4 ++++ test/functional/terminal/highlight_spec.lua | 10 ++++++++++ 2 files changed, 14 insertions(+) (limited to 'test/functional') diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index bcfd3559e6..d69f3207f1 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -31,6 +31,8 @@ local function set_bg(num) feed_termcode('[48;5;'..num..'m') end local function set_bold() feed_termcode('[1m') end local function set_italic() feed_termcode('[3m') end local function set_underline() feed_termcode('[4m') end +local function set_underdouble() feed_termcode('[4:2m') end +local function set_undercurl() feed_termcode('[4:3m') end local function set_strikethrough() feed_termcode('[9m') end local function clear_attrs() feed_termcode('[0;10m') end -- mouse @@ -116,6 +118,8 @@ return { set_bold = set_bold, set_italic = set_italic, set_underline = set_underline, + set_underdouble = set_underdouble, + set_undercurl = set_undercurl, set_strikethrough = set_strikethrough, clear_attrs = clear_attrs, enable_mouse = enable_mouse, diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index 28ca07d815..a119d4acd3 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -26,6 +26,8 @@ describe(':terminal highlight', function() [9] = {foreground = 130}, [10] = {reverse = true}, [11] = {background = 11}, + [12] = {bold = true, underdouble = true}, + [13] = {italic = true, undercurl = true}, }) screen:attach({rgb=false}) command(("enew | call termopen(['%s'])"):format(testprg('tty-test'))) @@ -114,6 +116,14 @@ describe(':terminal highlight', function() thelpers.set_underline() thelpers.set_strikethrough() end) + descr('bold and underdouble', 12, function() + thelpers.set_bold() + thelpers.set_underdouble() + end) + descr('italics and undercurl', 13, function() + thelpers.set_italic() + thelpers.set_undercurl() + end) end) it(':terminal highlight has lower precedence than editor #9964', function() -- cgit From db0ea1ab444c5e45fe02e1f2984aefc2eb613096 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 26 Sep 2022 10:40:34 +0200 Subject: fix(messages): validate msg_grid before silent! message with cmdheight=0 fixes #20316 --- test/functional/ui/cmdline_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 92eb853686..3669352901 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1183,4 +1183,17 @@ describe('cmdheight=0', function() {1:~ }| ]]} end) + + it('with silent! at startup', function() + clear{args={'-c', 'set cmdheight=0', '-c', 'autocmd VimEnter * silent! call Foo()'}} + screen:attach() + -- doesn't crash while not displaying silent! error message + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]} + end) end) -- cgit From c815aadfccd6bada47ecfb09fe188ee7f7c5caf3 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 26 Sep 2022 11:43:23 +0200 Subject: docs: fix typos (#20150) Co-authored-by: Miguel Carneiro Co-authored-by: Gregory Anders Co-authored-by: Raphael Co-authored-by: C.D. MacEachern Co-authored-by: zeertzjq --- test/functional/vimscript/map_functions_spec.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index ed1863754a..8645b1e506 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -176,15 +176,12 @@ describe('mapset()', function() it('can restore mapping description from the dict returned by maparg()', function() meths.set_keymap('n', 'lhs', 'rhs', {desc = 'map description'}) - eq('\nn lhs rhs\n map description', - helpers.exec_capture("nmap lhs")) + eq('\nn lhs rhs\n map description', exec_capture("nmap lhs")) local mapargs = funcs.maparg('lhs', 'n', false, true) meths.set_keymap('n', 'lhs', 'rhs', {desc = 'MAP DESCRIPTION'}) - eq('\nn lhs rhs\n MAP DESCRIPTION', - helpers.exec_capture("nmap lhs")) + eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture("nmap lhs")) funcs.mapset('n', false, mapargs) - eq('\nn lhs rhs\n map description', - helpers.exec_capture("nmap lhs")) + eq('\nn lhs rhs\n map description', exec_capture("nmap lhs")) end) it('can restore "replace_keycodes" from the dict returned by maparg()', function() -- cgit From be72af2f9b6aa9ff57ef21eb4e517a74b7c2a2da Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 26 Sep 2022 11:40:06 +0200 Subject: fix(cmdline): don't send invalid cursor with incsearch and cmdheight=0 fixes #20306 --- test/functional/ui/cmdline_spec.lua | 42 +++++++++++++++++++++++++++++++++++++ test/functional/ui/screen.lua | 1 + 2 files changed, 43 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 3669352901..845291b2eb 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1196,4 +1196,46 @@ describe('cmdheight=0', function() {1:~ }| ]]} end) + + it('with multigrid', function() + clear{args={'--cmd', 'set cmdheight=0'}} + screen:attach{ext_multigrid=true} + screen:expect{grid=[[ + ## grid 1 + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + ## grid 2 + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + ]], win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + + feed '/p' + screen:expect{grid=[[ + ## grid 1 + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [3:-------------------------]| + ## grid 2 + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + /p^ | + ]], win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + end) end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 6ee9e7b393..028fa2825d 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -769,6 +769,7 @@ end function Screen:_handle_grid_cursor_goto(grid, row, col) self._cursor.grid = grid + assert(row >= 0 and col >= 0) self._cursor.row = row + 1 self._cursor.col = col + 1 end -- cgit From be693462d5a5fd696b46ea4ea854c924421089b4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Sep 2022 21:23:43 +0800 Subject: fix(ui): allow redrawing statusline when msgsep is used (#20337) --- test/functional/ui/cmdline_spec.lua | 128 ++++++++++++++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 845291b2eb..d7f2b2335e 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -5,6 +5,7 @@ local source = helpers.source local command = helpers.command local assert_alive = helpers.assert_alive local uname = helpers.uname +local exec = helpers.exec local eval = helpers.eval local eq = helpers.eq @@ -821,12 +822,23 @@ describe('statusline is redrawn on entering cmdline', function() ]]} end) - it('but not with scrolled messages', function() - command('set statusline=%{mode()}') - screen:try_resize(35,10) + it('with scrolled messages and msgsep', function() + screen:try_resize(35,14) + exec([[ + let g:count = 0 + autocmd CmdlineEnter * let g:count += 1 + split + resize 1 + setlocal statusline=%{mode()}%{g:count} + setlocal winbar=%{mode()}%{g:count} + ]]) feed(':echoerr doesnotexist') screen:expect{grid=[[ + {9:c1 }| | + {3:c1 }| + | + {1:~ }| {1:~ }| {1:~ }| {1:~ }| @@ -839,8 +851,27 @@ describe('statusline is redrawn on entering cmdline', function() ]]} feed(':echoerr doesnotexist') screen:expect{grid=[[ + {9:c2 }| + | + {3:c2 }| | {1:~ }| + {1:~ }| + {3: }| + {4:E121: Undefined variable: doesnotex}| + {4:ist} | + {5:Press ENTER or type command to cont}| + {4:E121: Undefined variable: doesnotex}| + {4:ist} | + {5:Press ENTER or type command to cont}| + {5:inue}^ | + ]]} + + feed(':echoerr doesnotexist') + screen:expect{grid=[[ + {9:c3 }| + | + {3:c3 }| {3: }| {4:E121: Undefined variable: doesnotex}| {4:ist} | @@ -848,6 +879,63 @@ describe('statusline is redrawn on entering cmdline', function() {4:E121: Undefined variable: doesnotex}| {4:ist} | {5:Press ENTER or type command to cont}| + {4:E121: Undefined variable: doesnotex}| + {4:ist} | + {5:Press ENTER or type command to cont}| + {5:inue}^ | + ]]} + + feed('') + screen:expect{grid=[[ + {9:n3 }| + ^ | + {3:n3 }| + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + | + ]]} + end) + + it('but not with scrolled messages without msgsep', function() + screen:try_resize(35,10) + exec([[ + let g:count = 0 + autocmd CmdlineEnter * let g:count += 1 + set display-=msgsep + set statusline=%{mode()}%{g:count} + ]]) + feed(':echoerr doesnotexist') + screen:expect{grid=[[ + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {3:c1 }| + {4:E121: Undefined variable: doesnotex}| + {4:ist} | + {5:Press ENTER or type command to cont}| + {5:inue}^ | + ]]} + feed(':echoerr doesnotexist') + screen:expect{grid=[[ + {1:~ }| + {1:~ }| + {3:c1 }| + {4:E121: Undefined variable: doesnotex}| + {4:ist} | + {5:Press ENTER or type command to cont}| + {4:E121: Undefined variable: doesnotex}| + {4:ist} | + {5:Press ENTER or type command to cont}| {5:inue}^ | ]]} @@ -875,7 +963,7 @@ describe('statusline is redrawn on entering cmdline', function() {1:~ }| {1:~ }| {1:~ }| - {3:n }| + {3:n3 }| | ]]} end) @@ -1238,4 +1326,36 @@ describe('cmdheight=0', function() [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; }} end) + + it('winbar is redrawn on entering cmdline and :redrawstatus #20336', function() + exec([[ + set cmdheight=0 + set winbar=%{mode()}%=:%{getcmdline()} + ]]) + feed(':') + screen:expect([[ + {3:c :}| + | + {1:~ }| + {1:~ }| + :^ | + ]]) + feed('echo') + -- not redrawn yet + screen:expect([[ + {3:c :}| + | + {1:~ }| + {1:~ }| + :echo^ | + ]]) + command('redrawstatus') + screen:expect([[ + {3:c :echo}| + | + {1:~ }| + {1:~ }| + :echo^ | + ]]) + end) end) -- cgit From 7e98821e56a88487f24584463869432d8373a28e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Sep 2022 06:33:48 +0800 Subject: fix(ui): redraw end of buffer if last line is modified (#20354) --- test/functional/ui/decorations_spec.lua | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index eff6fe6d23..9b48f0ac35 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -1281,6 +1281,110 @@ if (h->n_buckets < new_n_buckets) { // expand ]]} end) + it('works beyond end of the buffer with virt_lines_above', function() + insert(example_text) + feed 'G' + + screen:expect{grid=[[ + if (h->n_buckets < new_n_buckets) { // expand | + khkey_t *new_keys = (khkey_t *)krealloc((void *)| + h->keys, new_n_buckets * sizeof(khkey_t)); | + h->keys = new_keys; | + if (kh_is_map && val_size) { | + char *new_vals = krealloc( h->vals_buf, new_n_| + buckets * val_size); | + h->vals_buf = new_vals; | + } | + ^} | + {1:~ }| + | + ]]} + + local id = meths.buf_set_extmark(0, ns, 8, 0, { + virt_lines={{{"Grugg"}}}; + virt_lines_above = true, + }) + + screen:expect{grid=[[ + if (h->n_buckets < new_n_buckets) { // expand | + khkey_t *new_keys = (khkey_t *)krealloc((void *)| + h->keys, new_n_buckets * sizeof(khkey_t)); | + h->keys = new_keys; | + if (kh_is_map && val_size) { | + char *new_vals = krealloc( h->vals_buf, new_n_| + buckets * val_size); | + h->vals_buf = new_vals; | + } | + ^} | + Grugg | + | + ]]} + + feed('dd') + screen:expect{grid=[[ + if (h->n_buckets < new_n_buckets) { // expand | + khkey_t *new_keys = (khkey_t *)krealloc((void *)| + h->keys, new_n_buckets * sizeof(khkey_t)); | + h->keys = new_keys; | + if (kh_is_map && val_size) { | + char *new_vals = krealloc( h->vals_buf, new_n_| + buckets * val_size); | + h->vals_buf = new_vals; | + ^} | + Grugg | + {1:~ }| + | + ]]} + + feed('dk') + screen:expect{grid=[[ + if (h->n_buckets < new_n_buckets) { // expand | + khkey_t *new_keys = (khkey_t *)krealloc((void *)| + h->keys, new_n_buckets * sizeof(khkey_t)); | + h->keys = new_keys; | + if (kh_is_map && val_size) { | + ^char *new_vals = krealloc( h->vals_buf, new_n_| + buckets * val_size); | + Grugg | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + feed('dgg') + screen:expect{grid=[[ + ^ | + Grugg | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + --No lines in buffer-- | + ]]} + + meths.buf_del_extmark(0, ns, id) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + --No lines in buffer-- | + ]]} + end) + it('does not cause syntax ml_get error at the end of a buffer #17816', function() command([[syntax region foo keepend start='^foo' end='^$']]) command('syntax sync minlines=100') -- cgit From 1d337d4e2f2265b13ecf19a3bc17ad302d3b0d96 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Sep 2022 08:29:21 +0800 Subject: vim-patch:9.0.0595: extra newline in messages after a verbose shell message (#20359) Problem: Extra newline in messages after a verbose shell message. Solution: Output the newline with msg_putchar_attr(). (closes vim/vim#11233) Make it possible to filter a screendump before comparing it. https://github.com/vim/vim/commit/1190139ed01c27539615beea9559a88b2551daf3 Cherry-pick Test_message_more_scrolledback() from patch 9.0.0592 because Nvim already behaves as intended. --- test/functional/legacy/messages_spec.lua | 152 +++++++++++++++++++++++++++---- 1 file changed, 136 insertions(+), 16 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/messages_spec.lua b/test/functional/legacy/messages_spec.lua index 5b671bbfdf..71a53c8381 100644 --- a/test/functional/legacy/messages_spec.lua +++ b/test/functional/legacy/messages_spec.lua @@ -4,6 +4,8 @@ local clear = helpers.clear local command = helpers.command local exec = helpers.exec local feed = helpers.feed +local meths = helpers.meths +local nvim_dir = helpers.nvim_dir before_each(clear) @@ -49,19 +51,18 @@ describe('messages', function() describe('more prompt', function() before_each(function() + command('set more') + end) + + -- oldtest: Test_message_more() + it('works', function() screen = Screen.new(75, 6) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText [1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg [2] = {foreground = Screen.colors.Brown}, -- LineNr - [3] = {foreground = Screen.colors.Blue}, -- SpecialKey }) screen:attach() - command('set more') - end) - -- oldtest: Test_message_more() - it('works', function() command('call setline(1, range(1, 100))') feed(':%pfoo#') @@ -350,20 +351,139 @@ describe('messages', function() ]]) end) + -- oldtest: Test_echo_verbose_system() + it('verbose message before echo command', function() + screen = Screen.new(60, 10) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg + }) + screen:attach() + + command('cd '..nvim_dir) + meths.set_option('shell', './shell-test') + meths.set_option('shellcmdflag', 'REP 20') + meths.set_option('shellxquote', '') -- win: avoid extra quotes + + -- display a page and go back, results in exactly the same view + feed([[:4 verbose echo system('foo')]]) + screen:expect([[ + Executing command: "'./shell-test' 'REP' '20' 'foo'" | + | + 0: foo | + 1: foo | + 2: foo | + 3: foo | + 4: foo | + 5: foo | + 6: foo | + {1:-- More --}^ | + ]]) + feed('') + screen:expect([[ + 7: foo | + 8: foo | + 9: foo | + 10: foo | + 11: foo | + 12: foo | + 13: foo | + 14: foo | + 15: foo | + {1:-- More --}^ | + ]]) + feed('b') + screen:expect([[ + Executing command: "'./shell-test' 'REP' '20' 'foo'" | + | + 0: foo | + 1: foo | + 2: foo | + 3: foo | + 4: foo | + 5: foo | + 6: foo | + {1:-- More --}^ | + ]]) + + -- do the same with 'cmdheight' set to 2 + feed('q') + command('set ch=2') + command('mode') -- FIXME: bottom is invalid after scrolling + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + | + ]]) + feed([[:4 verbose echo system('foo')]]) + screen:expect([[ + Executing command: "'./shell-test' 'REP' '20' 'foo'" | + | + 0: foo | + 1: foo | + 2: foo | + 3: foo | + 4: foo | + 5: foo | + 6: foo | + {1:-- More --}^ | + ]]) + feed('') + screen:expect([[ + 7: foo | + 8: foo | + 9: foo | + 10: foo | + 11: foo | + 12: foo | + 13: foo | + 14: foo | + 15: foo | + {1:-- More --}^ | + ]]) + feed('b') + screen:expect([[ + Executing command: "'./shell-test' 'REP' '20' 'foo'" | + | + 0: foo | + 1: foo | + 2: foo | + 3: foo | + 4: foo | + 5: foo | + 6: foo | + {1:-- More --}^ | + ]]) + end) + -- oldtest: Test_quit_long_message() it('with control characters can be quit vim-patch:8.2.1844', function() - screen:try_resize(40, 10) + screen = Screen.new(40, 10) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg + [2] = {foreground = Screen.colors.Blue}, -- SpecialKey + }) + screen:attach() + feed([[:echom range(9999)->join("\x01")]]) screen:expect([[ - 0{3:^A}1{3:^A}2{3:^A}3{3:^A}4{3:^A}5{3:^A}6{3:^A}7{3:^A}8{3:^A}9{3:^A}10{3:^A}11{3:^A}12| - {3:^A}13{3:^A}14{3:^A}15{3:^A}16{3:^A}17{3:^A}18{3:^A}19{3:^A}20{3:^A}21{3:^A}22| - {3:^A}23{3:^A}24{3:^A}25{3:^A}26{3:^A}27{3:^A}28{3:^A}29{3:^A}30{3:^A}31{3:^A}32| - {3:^A}33{3:^A}34{3:^A}35{3:^A}36{3:^A}37{3:^A}38{3:^A}39{3:^A}40{3:^A}41{3:^A}42| - {3:^A}43{3:^A}44{3:^A}45{3:^A}46{3:^A}47{3:^A}48{3:^A}49{3:^A}50{3:^A}51{3:^A}52| - {3:^A}53{3:^A}54{3:^A}55{3:^A}56{3:^A}57{3:^A}58{3:^A}59{3:^A}60{3:^A}61{3:^A}62| - {3:^A}63{3:^A}64{3:^A}65{3:^A}66{3:^A}67{3:^A}68{3:^A}69{3:^A}70{3:^A}71{3:^A}72| - {3:^A}73{3:^A}74{3:^A}75{3:^A}76{3:^A}77{3:^A}78{3:^A}79{3:^A}80{3:^A}81{3:^A}82| - {3:^A}83{3:^A}84{3:^A}85{3:^A}86{3:^A}87{3:^A}88{3:^A}89{3:^A}90{3:^A}91{3:^A}92| + 0{2:^A}1{2:^A}2{2:^A}3{2:^A}4{2:^A}5{2:^A}6{2:^A}7{2:^A}8{2:^A}9{2:^A}10{2:^A}11{2:^A}12| + {2:^A}13{2:^A}14{2:^A}15{2:^A}16{2:^A}17{2:^A}18{2:^A}19{2:^A}20{2:^A}21{2:^A}22| + {2:^A}23{2:^A}24{2:^A}25{2:^A}26{2:^A}27{2:^A}28{2:^A}29{2:^A}30{2:^A}31{2:^A}32| + {2:^A}33{2:^A}34{2:^A}35{2:^A}36{2:^A}37{2:^A}38{2:^A}39{2:^A}40{2:^A}41{2:^A}42| + {2:^A}43{2:^A}44{2:^A}45{2:^A}46{2:^A}47{2:^A}48{2:^A}49{2:^A}50{2:^A}51{2:^A}52| + {2:^A}53{2:^A}54{2:^A}55{2:^A}56{2:^A}57{2:^A}58{2:^A}59{2:^A}60{2:^A}61{2:^A}62| + {2:^A}63{2:^A}64{2:^A}65{2:^A}66{2:^A}67{2:^A}68{2:^A}69{2:^A}70{2:^A}71{2:^A}72| + {2:^A}73{2:^A}74{2:^A}75{2:^A}76{2:^A}77{2:^A}78{2:^A}79{2:^A}80{2:^A}81{2:^A}82| + {2:^A}83{2:^A}84{2:^A}85{2:^A}86{2:^A}87{2:^A}88{2:^A}89{2:^A}90{2:^A}91{2:^A}92| {1:-- More --}^ | ]]) feed('q') -- cgit From c7d30c152d1639523d05154e245ea60ed9a51a2b Mon Sep 17 00:00:00 2001 From: smolck <46855713+smolck@users.noreply.github.com> Date: Sat, 14 Aug 2021 12:19:05 -0500 Subject: fix(api): notify dict watchers on nvim_set_var and vim.g setter Co-authored-by: bfredl Co-authored-by: Christian Clason --- .../functional/ex_cmds/dict_notifications_spec.lua | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 21adcf37da..afa6b519d5 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -4,6 +4,7 @@ local clear, nvim, source = helpers.clear, helpers.nvim, helpers.source local insert = helpers.insert local eq, next_msg = helpers.eq, helpers.next_msg local exc_exec = helpers.exc_exec +local exec_lua = helpers.exec_lua local command = helpers.command local eval = helpers.eval @@ -21,6 +22,8 @@ describe('VimL dictionary notifications', function() -- t:) and a dictionary variable, so we generate them in the following -- function. local function gentests(dict_expr, dict_init) + local is_g = dict_expr == 'g:' + local function update(opval, key) if not key then key = 'watched' @@ -32,6 +35,28 @@ describe('VimL dictionary notifications', function() end end + local function update_with_api(opval, key) + if not key then + key = 'watched' + end + if opval == '' then + exec_lua(('vim.api.nvim_del_var(\'%s\')'):format(key)) + else + exec_lua(('vim.api.nvim_set_var(\'%s\', %s)'):format(key, opval)) + end + end + + local function update_with_vim_g(opval, key) + if not key then + key = 'watched' + end + if opval == '' then + exec_lua(('vim.g.%s = nil'):format(key)) + else + exec_lua(('vim.g.%s %s'):format(key, opval)) + end + end + local function verify_echo() -- helper to verify that no notifications are sent after certain change -- to a dict @@ -76,6 +101,18 @@ describe('VimL dictionary notifications', function() update('', 'watched2') update('') verify_echo() + if is_g then + update_with_api('"test"') + update_with_api('"test2"', 'watched2') + update_with_api('', 'watched2') + update_with_api('') + verify_echo() + update_with_vim_g('= "test"') + update_with_vim_g('= "test2"', 'watched2') + update_with_vim_g('', 'watched2') + update_with_vim_g('') + verify_echo() + end end) it('is not triggered when unwatched keys are updated', function() @@ -83,6 +120,16 @@ describe('VimL dictionary notifications', function() update('.= "noop2"', 'unwatched') update('', 'unwatched') verify_echo() + if is_g then + update_with_api('"noop"', 'unwatched') + update_with_api('vim.g.unwatched .. "noop2"', 'unwatched') + update_with_api('', 'unwatched') + verify_echo() + update_with_vim_g('= "noop"', 'unwatched') + update_with_vim_g('= vim.g.unwatched .. "noop2"', 'unwatched') + update_with_vim_g('', 'unwatched') + verify_echo() + end end) it('is triggered by remove()', function() @@ -92,6 +139,22 @@ describe('VimL dictionary notifications', function() verify_value({old = 'test'}) end) + if is_g then + it('is triggered by remove() when updated with nvim_*_var', function() + update_with_api('"test"') + verify_value({new = 'test'}) + nvim('command', 'call remove('..dict_expr..', "watched")') + verify_value({old = 'test'}) + end) + + it('is triggered by remove() when updated with vim.g', function() + update_with_vim_g('= "test"') + verify_value({new = 'test'}) + nvim('command', 'call remove('..dict_expr..', "watched")') + verify_value({old = 'test'}) + end) + end + it('is triggered by extend()', function() update('= "xtend"') verify_value({new = 'xtend'}) -- cgit From e6c214033a4fadf60faf99e95f8e9787e3c5e630 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 28 Sep 2022 06:22:11 +0800 Subject: fix(window): fix equalization with cmdheight=0 (#20369) --- test/functional/ui/cmdline_spec.lua | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index d7f2b2335e..1528b5307d 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1358,4 +1358,61 @@ describe('cmdheight=0', function() :echo^ | ]]) end) + + it('window equalization with laststatus=0 #20367', function() + screen:try_resize(60, 9) + command('set cmdheight=0 laststatus=0') + command('vsplit') + screen:expect([[ + ^ │ | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + ]]) + feed(':') + command('split') + feed('') + screen:expect([[ + ^ │ | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {2:[No Name] }│{1:~ }| + │{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + ]]) + command('resize 2') + screen:expect([[ + ^ │ | + {1:~ }│{1:~ }| + {2:[No Name] }│{1:~ }| + │{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + ]]) + feed(':') + command('wincmd =') + feed('') + screen:expect([[ + ^ │ | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {2:[No Name] }│{1:~ }| + │{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + ]]) + end) end) -- cgit From 35e2c4a2edd28f72c48c70530c5486365c2502a4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 28 Sep 2022 18:27:59 +0800 Subject: fix(lua): fix architecture-dependent behavior in usercmd "reg" (#20384) I don't think using an integer as a NUL-terminated string can work on big-endian systems, at least. This is also not tested. Add a test. Also fix a mistake in the docs of nvim_parse_cmd. --- test/functional/api/command_spec.lua | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 44a19d8348..f19d7a362b 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -423,6 +423,7 @@ describe('nvim_create_user_command', function() nargs = 0, bang = true, count = 2, + register = true, }) ]] eq({ @@ -460,6 +461,42 @@ describe('nvim_create_user_command', function() vim.cmd('CommandWithNoArgs') return result ]]) + -- register can be specified + eq({ + args = "", + fargs = {}, + bang = false, + line1 = 1, + line2 = 1, + mods = "", + smods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + }, + range = 0, + count = 2, + reg = "+", + }, exec_lua [[ + vim.cmd('CommandWithNoArgs +') + return result + ]]) end) -- cgit From bafeb32b95c61b91220b3090e4293478a74ce31d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 28 Sep 2022 21:55:22 +0800 Subject: fix(spell): correct spell move behavior without "noplainbuffer" (#20386) --- test/functional/ui/spell_spec.lua | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/spell_spec.lua b/test/functional/ui/spell_spec.lua index de77100cc0..1aa73e7b13 100644 --- a/test/functional/ui/spell_spec.lua +++ b/test/functional/ui/spell_spec.lua @@ -19,6 +19,10 @@ describe("'spell'", function() [0] = {bold=true, foreground=Screen.colors.Blue}, [1] = {special = Screen.colors.Red, undercurl = true}, [2] = {special = Screen.colors.Blue1, undercurl = true}, + [3] = {foreground = tonumber('0x6a0dad')}, + [4] = {foreground = Screen.colors.Magenta}, + [5] = {bold = true, foreground = Screen.colors.SeaGreen}, + [6] = {foreground = Screen.colors.Red}, }) end) @@ -68,4 +72,94 @@ describe("'spell'", function() | ]]) end) + + it('"noplainbuffer" and syntax #20385', function() + command('set filetype=c') + command('syntax on') + command('set spell') + insert([[ + #include + bool func(void);]]) + screen:expect([[ + {3:#include }{4:} | + {5:bool} func({5:void})^; | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + feed('[s') + screen:expect([[ + {3:#include }{4:} | + {5:bool} func({5:void})^; | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {6:search hit TOP, continuing at BOTTOM} | + ]]) + -- "noplainbuffer" shouldn't change spellchecking behavior with syntax enabled + command('set spelloptions+=noplainbuffer') + screen:expect_unchanged() + feed(']s') + screen:expect([[ + {3:#include }{4:} | + {5:bool} func({5:void})^; | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {6:search hit BOTTOM, continuing at TOP} | + ]]) + -- no spellchecking with "noplainbuffer" and syntax disabled + command('syntax off') + screen:expect([[ + #include | + bool func(void)^; | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {6:search hit BOTTOM, continuing at TOP} | + ]]) + feed('[s') + screen:expect([[ + #include | + bool func(void)^; | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {6:search hit TOP, continuing at BOTTOM} | + ]]) + -- everything is spellchecked without "noplainbuffer" with syntax disabled + command('set spelloptions&') + screen:expect([[ + #include <{1:stdbool}.h> | + {1:bool} {1:func}(void)^; | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {6:search hit TOP, continuing at BOTTOM} | + ]]) + feed(']s') + screen:expect([[ + #include <{1:^stdbool}.h> | + {1:bool} {1:func}(void); | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {6:search hit BOTTOM, continuing at TOP} | + ]]) + end) end) -- cgit From 16336c486ecb5a60e85a870904316308c7d7fc3f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 25 Sep 2022 02:20:47 +0200 Subject: feat(gen_help_html.lua): adapt to new parser - adapt to parser changes from https://github.com/vigoux/tree-sitter-vimdoc/pull/16 - numerous other generator improvements --- test/functional/core/startup_spec.lua | 4 ++- test/functional/helpers.lua | 13 +++++-- test/functional/lua/help_spec.lua | 31 +++++++---------- test/functional/options/defaults_spec.lua | 58 ++++++++++++++++++------------- 4 files changed, 60 insertions(+), 46 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 4f9df4010e..a32c801c97 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -354,7 +354,9 @@ describe('startup', function() local function pack_clear(cmd) -- add packages after config dir in rtp but before config/after - clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', 'let paths=split(&rtp, ",")', '--cmd', 'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}} + clear{args={'--cmd', 'set packpath=test/functional/fixtures', '--cmd', 'let paths=split(&rtp, ",")', '--cmd', 'let &rtp = paths[0]..",test/functional/fixtures,test/functional/fixtures/middle,"..join(paths[1:],",")', '--cmd', cmd}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}, + args_rm={'runtimepath'}, + } end diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index eff54b6d4a..3aec834bea 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -29,6 +29,7 @@ local module = { } local start_dir = lfs.currentdir() +local runtime_set = 'set runtimepath^=./build/lib/nvim/' module.nvim_prog = ( os.getenv('NVIM_PRG') or global_helpers.test_build_dir .. '/bin/nvim' @@ -40,6 +41,8 @@ module.nvim_set = ( ..' belloff= wildoptions-=pum joinspaces noshowcmd noruler nomore redrawdebug=invalid') module.nvim_argv = { module.nvim_prog, '-u', 'NONE', '-i', 'NONE', + -- XXX: find treesitter parsers. + '--cmd', runtime_set, '--cmd', module.nvim_set, '--cmd', 'mapclear', '--cmd', 'mapclear!', @@ -345,14 +348,17 @@ end -- Removes Nvim startup args from `args` matching items in `args_rm`. -- --- "-u", "-i", "--cmd" are treated specially: their "values" are also removed. +-- - Special case: "-u", "-i", "--cmd" are treated specially: their "values" are also removed. +-- - Special case: "runtimepath" will remove only { '--cmd', 'set runtimepath^=…', } +-- -- Example: -- args={'--headless', '-u', 'NONE'} -- args_rm={'--cmd', '-u'} -- Result: -- {'--headless'} -- --- All cases are removed. +-- All matching cases are removed. +-- -- Example: -- args={'--cmd', 'foo', '-N', '--cmd', 'bar'} -- args_rm={'--cmd', '-u'} @@ -373,6 +379,9 @@ local function remove_args(args, args_rm) last = '' elseif tbl_contains(args_rm, arg) then last = arg + elseif arg == runtime_set and tbl_contains(args_rm, 'runtimepath') then + table.remove(new_args) -- Remove the preceding "--cmd". + last = '' else table.insert(new_args, arg) end diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua index 266f261ab9..2ddabc15ae 100644 --- a/test/functional/lua/help_spec.lua +++ b/test/functional/lua/help_spec.lua @@ -12,29 +12,26 @@ describe(':help docs', function() before_each(clear) it('validate', function() -- If this test fails, try these steps (in order): - -- 1. Try to fix/cleanup the :help docs, especially Nvim-owned :help docs. - -- 2. Try to fix the parser: https://github.com/vigoux/tree-sitter-vimdoc + -- 1. Fix/cleanup the :help docs. + -- 2. Fix the parser: https://github.com/neovim/tree-sitter-vimdoc -- 3. File a parser bug, and adjust the tolerance of this test in the meantime. local rv = exec_lua([[return require('scripts.gen_help_html').validate('./build/runtime/doc')]]) + -- Check that we actually found helpfiles. + ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles) -- Check that parse errors did not increase wildly. - -- TODO: yes, there are currently 24k+ parser errors. - -- WIP: https://github.com/vigoux/tree-sitter-vimdoc/pull/16 - ok(rv.err_count < 24000, '<24000', rv.err_count) - -- TODO: should be eq(0, …) - ok(exec_lua('return vim.tbl_count(...)', rv.invalid_tags) < 538, '<538', - exec_lua('return vim.inspect(...)', rv.invalid_tags)) + -- TODO: Fix all parse errors in :help files. + ok(rv.err_count < 1300, '<1300 parse errors', rv.err_count) + eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) it('gen_help_html.lua generates HTML', function() - -- Test: - -- 1. Check that parse errors did not increase wildly. Because we explicitly test only a few - -- :help files, we can be more precise about the tolerances here. - -- 2. exercise gen_help_html.lua, check that it actually works. - -- 3. check that its tree-sitter-vimdoc dependency is working. + -- 1. Test that gen_help_html.lua actually works. + -- 2. Test that parse errors did not increase wildly. Because we explicitly test only a few + -- :help files, we can be precise about the tolerances here. local tmpdir = exec_lua('return vim.fs.dirname(vim.fn.tempname())') - -- Because gen() is slow (1 min), this test is limited to a few files. + -- Because gen() is slow (~30s), this test is limited to a few files. local rv = exec_lua([[ local to_dir = ... return require('scripts.gen_help_html').gen( @@ -46,9 +43,7 @@ describe(':help docs', function() tmpdir ) eq(4, #rv.helpfiles) - ok(rv.err_count < 700, '<700', rv.err_count) - -- TODO: should be eq(0, …) - ok(exec_lua('return vim.tbl_count(...)', rv.invalid_tags) <= 32, '<=32', - exec_lua('return vim.inspect(...)', rv.invalid_tags)) + ok(rv.err_count < 16, '<16 parse errors', rv.err_count) + eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) end) diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 4e2f2ab63e..130ed73c34 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -220,7 +220,9 @@ describe('startup defaults', function() end) it("'packpath'", function() - clear() + clear{ + args_rm={'runtimepath'}, + } -- Defaults to &runtimepath. eq(meths.get_option('runtimepath'), meths.get_option('packpath')) @@ -332,17 +334,19 @@ describe('XDG defaults', function() describe('with too long XDG variables', function() before_each(function() - clear({env={ - XDG_CONFIG_HOME=(root_path .. ('/x'):rep(4096)), - XDG_CONFIG_DIRS=(root_path .. ('/a'):rep(2048) - .. env_sep.. root_path .. ('/b'):rep(2048) - .. (env_sep .. root_path .. '/c'):rep(512)), - XDG_DATA_HOME=(root_path .. ('/X'):rep(4096)), - XDG_RUNTIME_DIR=(root_path .. ('/X'):rep(4096)), - XDG_STATE_HOME=(root_path .. ('/X'):rep(4096)), - XDG_DATA_DIRS=(root_path .. ('/A'):rep(2048) - .. env_sep .. root_path .. ('/B'):rep(2048) - .. (env_sep .. root_path .. '/C'):rep(512)), + clear({ + args_rm={'runtimepath'}, + env={ + XDG_CONFIG_HOME=(root_path .. ('/x'):rep(4096)), + XDG_CONFIG_DIRS=(root_path .. ('/a'):rep(2048) + .. env_sep.. root_path .. ('/b'):rep(2048) + .. (env_sep .. root_path .. '/c'):rep(512)), + XDG_DATA_HOME=(root_path .. ('/X'):rep(4096)), + XDG_RUNTIME_DIR=(root_path .. ('/X'):rep(4096)), + XDG_STATE_HOME=(root_path .. ('/X'):rep(4096)), + XDG_DATA_DIRS=(root_path .. ('/A'):rep(2048) + .. env_sep .. root_path .. ('/B'):rep(2048) + .. (env_sep .. root_path .. '/C'):rep(512)), }}) end) @@ -405,13 +409,15 @@ describe('XDG defaults', function() describe('with XDG variables that can be expanded', function() before_each(function() - clear({env={ - XDG_CONFIG_HOME='$XDG_DATA_HOME', - XDG_CONFIG_DIRS='$XDG_DATA_DIRS', - XDG_DATA_HOME='$XDG_CONFIG_HOME', - XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR', - XDG_STATE_HOME='$XDG_CONFIG_HOME', - XDG_DATA_DIRS='$XDG_CONFIG_DIRS', + clear({ + args_rm={'runtimepath'}, + env={ + XDG_CONFIG_HOME='$XDG_DATA_HOME', + XDG_CONFIG_DIRS='$XDG_DATA_DIRS', + XDG_DATA_HOME='$XDG_CONFIG_HOME', + XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR', + XDG_STATE_HOME='$XDG_CONFIG_HOME', + XDG_DATA_DIRS='$XDG_CONFIG_DIRS', }}) end) @@ -478,12 +484,14 @@ describe('XDG defaults', function() describe('with commas', function() before_each(function() - clear({env={ - XDG_CONFIG_HOME=', , ,', - XDG_CONFIG_DIRS=',-,-,' .. env_sep .. '-,-,-', - XDG_DATA_HOME=',=,=,', - XDG_STATE_HOME=',=,=,', - XDG_DATA_DIRS=',≡,≡,' .. env_sep .. '≡,≡,≡', + clear({ + args_rm={'runtimepath'}, + env={ + XDG_CONFIG_HOME=', , ,', + XDG_CONFIG_DIRS=',-,-,' .. env_sep .. '-,-,-', + XDG_DATA_HOME=',=,=,', + XDG_STATE_HOME=',=,=,', + XDG_DATA_DIRS=',≡,≡,' .. env_sep .. '≡,≡,≡', }}) end) -- cgit From a80ab395aa7beedf8f39870d331b4b32cc6e5d2d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 29 Sep 2022 08:56:00 +0800 Subject: test: add a Lua test for #17501 (#20392) --- test/functional/lua/vim_spec.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 3184f01ef4..294ff5d3ca 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1390,11 +1390,23 @@ describe('lua stdlib', function() end) it('vim.env', function() - exec_lua [[ - vim.fn.setenv("A", 123) - ]] - eq('123', funcs.luaeval "vim.env.A") - eq(true, funcs.luaeval "vim.env.B == nil") + exec_lua([[vim.fn.setenv('A', 123)]]) + eq('123', funcs.luaeval('vim.env.A')) + exec_lua([[vim.env.A = 456]]) + eq('456', funcs.luaeval('vim.env.A')) + exec_lua([[vim.env.A = nil]]) + eq(NIL, funcs.luaeval('vim.env.A')) + + eq(true, funcs.luaeval('vim.env.B == nil')) + + command([[let $HOME = 'foo']]) + eq('foo', funcs.expand('~')) + eq('foo', funcs.luaeval('vim.env.HOME')) + exec_lua([[vim.env.HOME = nil]]) + eq('foo', funcs.expand('~')) + exec_lua([[vim.env.HOME = 'bar']]) + eq('bar', funcs.expand('~')) + eq('bar', funcs.luaeval('vim.env.HOME')) end) it('vim.v', function() -- cgit From 1cf44d6f5794c7b6bd181dfb2ce51f5ff4381ee8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 29 Sep 2022 15:48:39 +0800 Subject: fix(column): move sign sentinel after inserting/deleting lines (#20400) --- test/functional/ui/sign_spec.lua | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua index dbc92ca222..ff3e143126 100644 --- a/test/functional/ui/sign_spec.lua +++ b/test/functional/ui/sign_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, feed, command = helpers.clear, helpers.feed, helpers.command local source = helpers.source +local meths = helpers.meths describe('Signs', function() local screen @@ -592,4 +593,88 @@ describe('Signs', function() ]]) end) end) + + it('signcolumn width is updated when removing all signs after deleting lines', function() + meths.buf_set_lines(0, 0, 1, true, {'a', 'b', 'c', 'd', 'e'}) + command('sign define piet text=>>') + command('sign place 10001 line=1 name=piet') + command('sign place 10002 line=5 name=piet') + command('2delete') + command('sign unplace 10001') + screen:expect([[ + {2: }a | + {2: }^c | + {2: }d | + >>e | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + command('sign unplace 10002') + screen:expect([[ + a | + ^c | + d | + e | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end) + + it('signcolumn width is updated when removing all signs after inserting lines', function() + meths.buf_set_lines(0, 0, 1, true, {'a', 'b', 'c', 'd', 'e'}) + command('sign define piet text=>>') + command('sign place 10001 line=1 name=piet') + command('sign place 10002 line=5 name=piet') + command('copy .') + command('sign unplace 10001') + screen:expect([[ + {2: }a | + {2: }^a | + {2: }b | + {2: }c | + {2: }d | + >>e | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + command('sign unplace 10002') + screen:expect([[ + a | + ^a | + b | + c | + d | + e | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end) end) -- cgit From 45707c1eae62667e5c482a09f6d9a62e01db0e21 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 29 Sep 2022 16:04:14 +0800 Subject: fix(api): fix nvim_cmd crash with filename expansion (#20397) --- test/functional/api/vim_spec.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 44775ef85c..c2f3a5ec5e 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -14,6 +14,7 @@ local funcs = helpers.funcs local iswin = helpers.iswin local meths = helpers.meths local matches = helpers.matches +local pesc = helpers.pesc local mkdir_p = helpers.mkdir_p local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed local is_os = helpers.is_os @@ -3912,11 +3913,23 @@ describe('API', function() eq({'aa'}, meths.buf_get_lines(0, 0, 1, false)) assert_alive() end) + it('supports filename expansion', function() + meths.cmd({ cmd = 'argadd', args = { '%:p:h:t', '%:p:h:t' } }, {}) + local arg = funcs.expand('%:p:h:t') + eq({ arg, arg }, funcs.argv()) + end) it("'make' command works when argument count isn't 1 #19696", function() command('set makeprg=echo') - meths.cmd({ cmd = 'make' }, {}) + command('set shellquote=') + matches('^:!echo ', + meths.cmd({ cmd = 'make' }, { output = true })) + assert_alive() + matches('^:!echo foo bar', + meths.cmd({ cmd = 'make', args = { 'foo', 'bar' } }, { output = true })) assert_alive() - meths.cmd({ cmd = 'make', args = { 'foo', 'bar' } }, {}) + local arg_pesc = pesc(funcs.expand('%:p:h:t')) + matches(('^:!echo %s %s'):format(arg_pesc, arg_pesc), + meths.cmd({ cmd = 'make', args = { '%:p:h:t', '%:p:h:t' } }, { output = true })) assert_alive() end) it('doesn\'t display messages when output=true', function() -- cgit From 563bc39aac10185a03e74faa8f992ce2d10f68e8 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 29 Sep 2022 12:08:49 +0200 Subject: feat(docs): fixes for :help HTML generator Generate correct leading whitespace for argument, taglink, tag, etc. --- test/functional/lua/help_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua index 2ddabc15ae..a00aaea9d2 100644 --- a/test/functional/lua/help_spec.lua +++ b/test/functional/lua/help_spec.lua @@ -21,7 +21,7 @@ describe(':help docs', function() ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles) -- Check that parse errors did not increase wildly. -- TODO: Fix all parse errors in :help files. - ok(rv.err_count < 1300, '<1300 parse errors', rv.err_count) + ok(rv.err_count < 250, '<250 parse errors', rv.err_count) eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) @@ -43,7 +43,7 @@ describe(':help docs', function() tmpdir ) eq(4, #rv.helpfiles) - ok(rv.err_count < 16, '<16 parse errors', rv.err_count) + ok(rv.err_count <= 6, '<=6 parse errors', rv.err_count) eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) end) -- cgit From e46eef75ac2c3336928269e28a1fa138f7327207 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 28 Sep 2022 17:43:18 +0600 Subject: feat(nvim_cmd): allow using first argument as count Allows `nvim_cmd` to use the first argument as count for applicable commands. Also adds support for non-String arguments to `nvim_cmd`. --- test/functional/api/vim_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c2f3a5ec5e..ca1c5070a6 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1,6 +1,7 @@ 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 local assert_alive = helpers.assert_alive @@ -3962,5 +3963,23 @@ describe('API', function() 15 | ]]} end) + it('works with non-String args', function() + eq('2', meths.cmd({cmd = 'echo', args = {2}}, {output = true})) + 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()}}, {}) + eq(1, meths.get_current_buf().id) + end) + it('works with :sleep using milliseconds', function() + local start = luv.now() + meths.cmd({cmd = 'sleep', args = {'100m'}}, {}) + ok(luv.now() - start <= 300) + end) + end) end) end) -- cgit From cb62592bcb03d7934416cf46bede3b8296254c87 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Sep 2022 14:40:10 +0800 Subject: fix(api)!: nvim_parse_cmd omit "count" "range" "reg" if not supported --- test/functional/api/vim_spec.lua | 66 ++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c2f3a5ec5e..703a5fb9e0 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3177,9 +3177,6 @@ describe('API', function() cmd = 'echo', args = { 'foo' }, bang = false, - range = {}, - count = -1, - reg = '', addr = 'none', magic = { file = false, @@ -3220,8 +3217,6 @@ describe('API', function() args = { '/math.random/math.max/' }, bang = false, range = { 4, 6 }, - count = -1, - reg = '', addr = 'line', magic = { file = false, @@ -3263,7 +3258,6 @@ describe('API', function() bang = false, range = { 1 }, count = 1, - reg = '', addr = 'buf', magic = { file = false, @@ -3304,7 +3298,6 @@ describe('API', function() args = {}, bang = false, range = {}, - count = -1, reg = '+', addr = 'line', magic = { @@ -3339,6 +3332,45 @@ describe('API', function() vertical = false, } }, meths.parse_cmd('put +', {})) + eq({ + cmd = 'put', + args = {}, + bang = false, + range = {}, + reg = '', + addr = 'line', + magic = { + file = false, + bar = true + }, + nargs = '0', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + filter = { + pattern = "", + force = false + }, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = "", + tab = -1, + unsilent = false, + verbose = -1, + vertical = false, + } + }, meths.parse_cmd('put', {})) end) it('works with range, count and register', function() eq({ @@ -3388,8 +3420,6 @@ describe('API', function() args = {}, bang = true, range = {}, - count = -1, - reg = '', addr = 'line', magic = { file = true, @@ -3430,8 +3460,6 @@ describe('API', function() args = { 'foo.txt' }, bang = false, range = {}, - count = -1, - reg = '', addr = '?', magic = { file = true, @@ -3470,8 +3498,6 @@ describe('API', function() args = { 'foo.txt' }, bang = false, range = {}, - count = -1, - reg = '', addr = '?', magic = { file = true, @@ -3513,8 +3539,6 @@ describe('API', function() args = { 'test', 'it' }, bang = true, range = { 4, 6 }, - count = -1, - reg = '', addr = 'line', magic = { file = false, @@ -3555,8 +3579,6 @@ describe('API', function() args = { 'a.txt' }, bang = false, range = {}, - count = -1, - reg = '', addr = 'arg', magic = { file = true, @@ -3597,9 +3619,6 @@ describe('API', function() cmd = 'MyCommand', args = { 'test it' }, bang = false, - range = {}, - count = -1, - reg = '', addr = 'none', magic = { file = false, @@ -3691,8 +3710,6 @@ describe('API', function() args = {'x'}, bang = true, range = {3, 4}, - count = -1, - reg = '', addr = 'line', magic = { file = false, @@ -3730,6 +3747,11 @@ describe('API', function() eq('', funcs.getreg('/')) eq('', funcs.histget('search')) end) + it('result can be used directly by nvim_cmd #20051', function() + eq("foo", meths.cmd(meths.parse_cmd('echo "foo"', {}), { output = true })) + meths.cmd(meths.parse_cmd("set cursorline", {}), {}) + eq(true, meths.get_option_value("cursorline", {})) + end) end) describe('nvim_cmd', function() it('works', function () -- cgit From df646572c53f55268a5dbb61628d7c3b302d5663 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 30 Sep 2022 09:53:52 +0200 Subject: docs: fix typos (#20394) Co-authored-by: Raphael Co-authored-by: smjonas Co-authored-by: zeertzjq --- test/functional/api/extmark_spec.lua | 22 +++++++++++----------- test/functional/api/keymap_spec.lua | 2 +- test/functional/ex_cmds/quit_spec.lua | 2 +- test/functional/legacy/030_fileformats_spec.lua | 2 +- .../legacy/055_list_and_dict_types_spec.lua | 2 +- test/functional/legacy/072_undo_file_spec.lua | 2 +- .../083_tag_search_with_file_encoding_spec.lua | 2 +- test/functional/legacy/autocmd_option_spec.lua | 6 +++--- test/functional/lua/api_spec.lua | 2 +- test/functional/lua/buffer_updates_spec.lua | 2 +- test/functional/lua/uri_spec.lua | 14 +++++++------- test/functional/lua/vim_spec.lua | 2 +- test/functional/options/keymap_spec.lua | 2 +- test/functional/provider/clipboard_spec.lua | 12 ++++++------ test/functional/ui/bufhl_spec.lua | 2 +- test/functional/ui/float_spec.lua | 4 ++-- test/functional/ui/inccommand_user_spec.lua | 2 +- test/functional/ui/options_spec.lua | 2 +- test/functional/ui/screen.lua | 6 +++--- .../vimscript/container_functions_spec.lua | 2 +- test/functional/vimscript/json_functions_spec.lua | 2 +- 21 files changed, 47 insertions(+), 47 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index bc8d811c6d..00f5b25b8a 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1046,7 +1046,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[3], 0, 4, 0, 8) end) - it('substitions over multiple lines with newline in pattern', function() + it('substitutes over multiple lines with newline in pattern', function() feed('A67890xx') set_extmark(ns, marks[1], 0, 3) set_extmark(ns, marks[2], 0, 4) @@ -1078,7 +1078,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[6], 1, 2, 0, 5) end) - it('substitions with multiple newlines in pattern', function() + it('substitutes with multiple newlines in pattern', function() feed('A67890xx') set_extmark(ns, marks[1], 0, 4) set_extmark(ns, marks[2], 0, 5) @@ -1093,7 +1093,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[5], 2, 0, 0, 6) end) - it('substitions over multiple lines with replace in substition', function() + it('substitutes over multiple lines with replace in substitution', function() feed('A67890xx') set_extmark(ns, marks[1], 0, 1) set_extmark(ns, marks[2], 0, 2) @@ -1111,7 +1111,7 @@ describe('API/extmarks', function() eq({1, 3}, get_extmark_by_id(ns, marks[3])) end) - it('substitions over multiple lines with replace in substition', function() + it('substitutes over multiple lines with replace in substitution', function() feed('Ax3xx') set_extmark(ns, marks[1], 1, 0) set_extmark(ns, marks[2], 1, 1) @@ -1122,7 +1122,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[3], 1, 2, 2, 0) end) - it('substitions over multiple lines with replace in substition', function() + it('substitutes over multiple lines with replace in substitution', function() feed('Ax3xx') set_extmark(ns, marks[1], 0, 1) set_extmark(ns, marks[2], 0, 2) @@ -1140,7 +1140,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[3], 0, 4, 1, 3) end) - it('substitions with newline in match and sub, delta is 0', function() + it('substitutes with newline in match and sub, delta is 0', function() feed('A67890xx') set_extmark(ns, marks[1], 0, 3) set_extmark(ns, marks[2], 0, 4) @@ -1157,7 +1157,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[6], 2, 0, 2, 0) end) - it('substitions with newline in match and sub, delta > 0', function() + it('substitutes with newline in match and sub, delta > 0', function() feed('A67890xx') set_extmark(ns, marks[1], 0, 3) set_extmark(ns, marks[2], 0, 4) @@ -1174,7 +1174,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[6], 2, 0, 3, 0) end) - it('substitions with newline in match and sub, delta < 0', function() + it('substitutes with newline in match and sub, delta < 0', function() feed('A67890xxxx') set_extmark(ns, marks[1], 0, 3) set_extmark(ns, marks[2], 0, 4) @@ -1193,7 +1193,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[7], 3, 0, 2, 0) end) - it('substitions with backrefs, newline inserted into sub', function() + it('substitutes with backrefs, newline inserted into sub', function() feed('A67890xxxx') set_extmark(ns, marks[1], 0, 3) set_extmark(ns, marks[2], 0, 4) @@ -1210,7 +1210,7 @@ describe('API/extmarks', function() check_undo_redo(ns, marks[6], 2, 0, 3, 0) end) - it('substitions a ^', function() + it('substitutes a ^', function() set_extmark(ns, marks[1], 0, 0) set_extmark(ns, marks[2], 0, 1) feed([[:s:^:x]]) @@ -1397,7 +1397,7 @@ describe('API/extmarks', function() eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {})) end) - it('does not crash with append/delete/undo seqence', function() + it('does not crash with append/delete/undo sequence', function() meths.exec([[ let ns = nvim_create_namespace('myplugin') call nvim_buf_set_extmark(0, ns, 0, 0, {}) diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index fedcbfa76a..30c351b26a 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -885,7 +885,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() eq({''}, meths.buf_get_lines(0, 0, -1, false)) end) - it('lua expr mapping returning nil is equivalent to returnig an empty string', 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 }) ]] diff --git a/test/functional/ex_cmds/quit_spec.lua b/test/functional/ex_cmds/quit_spec.lua index fe138a24c8..3680801dae 100644 --- a/test/functional/ex_cmds/quit_spec.lua +++ b/test/functional/ex_cmds/quit_spec.lua @@ -7,7 +7,7 @@ describe(':qa', function() end) it('verify #3334', function() - -- just testing if 'qa' passed as a program argument wont result in memory + -- just testing if 'qa' passed as a program argument won't result in memory -- errors end) end) diff --git a/test/functional/legacy/030_fileformats_spec.lua b/test/functional/legacy/030_fileformats_spec.lua index 15dbd05cf5..e88afd9c47 100644 --- a/test/functional/legacy/030_fileformats_spec.lua +++ b/test/functional/legacy/030_fileformats_spec.lua @@ -255,7 +255,7 @@ describe('fileformats option', function() -- Assert buffer contents. This has to be done manually as -- helpers.expect() calls helpers.dedent() which messes up the white space - -- and carrige returns. + -- and carriage returns. eq( 'unix\n'.. 'unix\n'.. diff --git a/test/functional/legacy/055_list_and_dict_types_spec.lua b/test/functional/legacy/055_list_and_dict_types_spec.lua index 4d71a526c1..c0ff3ed17a 100644 --- a/test/functional/legacy/055_list_and_dict_types_spec.lua +++ b/test/functional/legacy/055_list_and_dict_types_spec.lua @@ -907,7 +907,7 @@ describe('list and dictionary types', function() feed('o=a') feed_command('lang C') feed_command('redir => a') - -- The test failes if this is not in one line. + -- The test fails if this is not in one line. feed_command("try|foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry") feed_command('redir END') feed('o=a') diff --git a/test/functional/legacy/072_undo_file_spec.lua b/test/functional/legacy/072_undo_file_spec.lua index b4927e779e..80665027c3 100644 --- a/test/functional/legacy/072_undo_file_spec.lua +++ b/test/functional/legacy/072_undo_file_spec.lua @@ -69,7 +69,7 @@ describe('72', function() feed_command('set undofile ul=100') feed('uuuuuu:w >>test.out') - ---- Open the output to see if it meets the expections + ---- Open the output to see if it meets the expectations feed_command('e! test.out') -- Assert buffer contents. diff --git a/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua b/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua index e94b46ca66..54620c7104 100644 --- a/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua +++ b/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua @@ -26,7 +26,7 @@ describe('tag search with !_TAG_FILE_ENCODING', function() '!_TAG_FILE_ENCODING cp932 //\n' .. '\130`\130a\130b Xtags2.txt /\130`\130a\130b\n' ) - -- The last file is very long but repetetive and can be generated on the + -- The last file is very long but repetitive and can be generated on the -- fly. local text = helpers.dedent([[ !_TAG_FILE_SORTED 1 // diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua index 5e586d3a6a..e00b468c16 100644 --- a/test/functional/legacy/autocmd_option_spec.lua +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -211,7 +211,7 @@ describe('au OptionSet', function() expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'}) end) - it('should trigger if the current buffer is different from the targetted buffer', function() + it('should trigger if the current buffer is different from the targeted buffer', function() local new_buffer = make_buffer() local new_bufnr = buf.get_number(new_buffer) @@ -590,7 +590,7 @@ describe('au OptionSet', function() expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'}) end) - it('should trigger if the current buffer is different from the targetted buffer', function() + it('should trigger if the current buffer is different from the targeted buffer', function() set_hook('buftype') local new_buffer = make_buffer() @@ -616,7 +616,7 @@ describe('au OptionSet', function() expected_combination({'backup', 0, 0, '', 1, 'local', 'setlocal'}) end) - it('should not trigger if the current window is different from the targetted window', function() + it('should not trigger if the current window is different from the targeted window', function() set_hook('cursorcolumn') local new_winnr = get_new_window_number() diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index f173a15d32..03832978a4 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -166,7 +166,7 @@ describe('luaeval(vim.api.…)', function() eq({v={}}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})')) -- If API requests dictionary, then empty table will be the one. This is not - -- the case normally because empty table is an empty arrray. + -- the case normally because empty table is an empty array. eq({}, funcs.luaeval('vim.api.nvim__id_dictionary({})')) eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({})'))]])) end) diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index c6c0964ddb..2fd44b8b5f 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -333,7 +333,7 @@ describe('lua: nvim_buf_attach on_bytes', function() start_txt = meths.buf_get_lines(0, 0, -1, true) end local shadowbytes = table.concat(start_txt, '\n') .. '\n' - -- TODO: while we are brewing the real strong coffe, + -- TODO: while we are brewing the real strong coffee, -- verify should check buf_get_offset after every check_events if verify then local len = meths.buf_get_offset(0, meths.buf_line_count(0)) diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua index 4635f17557..2cb0b26c6d 100644 --- a/test/functional/lua/uri_spec.lua +++ b/test/functional/lua/uri_spec.lua @@ -11,7 +11,7 @@ describe('URI methods', function() describe('file path to uri', function() describe('encode Unix file path', function() - it('file path includes only ascii charactors', function() + it('file path includes only ascii characters', function() exec_lua("filepath = '/Foo/Bar/Baz.txt'") eq('file:///Foo/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)")) @@ -23,7 +23,7 @@ describe('URI methods', function() eq('file:///Foo%20/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)")) end) - it('file path including Unicode charactors', function() + it('file path including Unicode characters', function() exec_lua("filepath = '/xy/åäö/ɧ/汉语/↥/🤦/🦄/å/بِيَّ.txt'") -- The URI encoding should be case-insensitive @@ -32,7 +32,7 @@ describe('URI methods', function() end) describe('encode Windows filepath', function() - it('file path includes only ascii charactors', function() + it('file path includes only ascii characters', function() exec_lua([[filepath = 'C:\\Foo\\Bar\\Baz.txt']]) eq('file:///C:/Foo/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)")) @@ -44,7 +44,7 @@ describe('URI methods', function() eq('file:///C:/Foo%20/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)")) end) - it('file path including Unicode charactors', function() + it('file path including Unicode characters', function() exec_lua([[filepath = 'C:\\xy\\åäö\\ɧ\\汉语\\↥\\🤦\\🦄\\å\\بِيَّ.txt']]) eq('file:///C:/xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', exec_lua("return vim.uri_from_fname(filepath)")) @@ -72,7 +72,7 @@ describe('URI methods', function() eq('/Foo /Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)")) end) - it('file path including Unicode charactors', function() + it('file path including Unicode characters', function() local test_case = [[ local uri = 'file:///xy/%C3%A5%C3%A4%C3%B6/%C9%A7/%E6%B1%89%E8%AF%AD/%E2%86%A5/%F0%9F%A4%A6/%F0%9F%A6%84/a%CC%8A/%D8%A8%D9%90%D9%8A%D9%8E%D9%91.txt' return vim.uri_to_fname(uri) @@ -83,7 +83,7 @@ describe('URI methods', function() end) describe('decode Windows filepath', function() - it('file path includes only ascii charactors', function() + it('file path includes only ascii characters', function() local test_case = [[ local uri = 'file:///C:/Foo/Bar/Baz.txt' return vim.uri_to_fname(uri) @@ -119,7 +119,7 @@ describe('URI methods', function() eq('C:\\Foo \\Bar\\Baz.txt', exec_lua(test_case)) end) - it('file path including Unicode charactors', function() + it('file path including Unicode characters', function() local test_case = [[ local uri = 'file:///C:/xy/%C3%A5%C3%A4%C3%B6/%C9%A7/%E6%B1%89%E8%AF%AD/%E2%86%A5/%F0%9F%A4%A6/%F0%9F%A6%84/a%CC%8A/%D8%A8%D9%90%D9%8A%D9%8E%D9%91.txt' return vim.uri_to_fname(uri) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 294ff5d3ca..6451453ce0 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -905,7 +905,7 @@ describe('lua stdlib', function() ]])) -- vim.empty_dict() gives new value each time - -- equality is not overriden (still by ref) + -- equality is not overridden (still by ref) -- non-empty table uses the usual heuristics (ignores the tag) eq({false, {"foo"}, {namey="bar"}}, exec_lua([[ local aa = vim.empty_dict() diff --git a/test/functional/options/keymap_spec.lua b/test/functional/options/keymap_spec.lua index a814c35a39..4fdc6ef4be 100644 --- a/test/functional/options/keymap_spec.lua +++ b/test/functional/options/keymap_spec.lua @@ -184,7 +184,7 @@ describe("'keymap' / :lmap", function() feed('il') expect('alllaaa') end) - -- This is a problem introduced when introducting :lmap and macro + -- This is a problem introduced when introducing :lmap and macro -- compatibility. There are no plans to fix this as the complexity involved -- seems too great. pending('mappings not applied to macro replay of :lnoremap', function() diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua index fbaef3ae00..401dc84ccc 100644 --- a/test/functional/provider/clipboard_spec.lua +++ b/test/functional/provider/clipboard_spec.lua @@ -310,18 +310,18 @@ describe('clipboard (with fake clipboard.vim)', function() insert([[ text: first line - secound line + second line third line]]) feed('G"+dd"*dddd"+p"*pp') expect([[ text: third line - secound line + second line first line]]) -- linewise selection should be encoded as an extra newline eq({{'third line', ''}, 'V'}, eval("g:test_clip['+']")) - eq({{'secound line', ''}, 'V'}, eval("g:test_clip['*']")) + eq({{'second line', ''}, 'V'}, eval("g:test_clip['*']")) end) it('handles null bytes when pasting and in getreg', function() @@ -477,7 +477,7 @@ describe('clipboard (with fake clipboard.vim)', function() expect("indeed star") end) - it('unamed operations work even if the provider fails', function() + it('unnamed operations work even if the provider fails', function() insert('the text') feed('yy') feed_command("let g:cliperror = 1") @@ -511,7 +511,7 @@ describe('clipboard (with fake clipboard.vim)', function() eq('textstar', meths.get_current_line()) end) - it('Block paste works currectly', function() + it('Block paste works correctly', function() insert([[ aabbcc ddeeff @@ -559,7 +559,7 @@ describe('clipboard (with fake clipboard.vim)', function() eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['+']")) eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['*']")) - -- unnamedplus takes predecence when pasting + -- unnamedplus takes precedence when pasting eq('+', eval('v:register')) feed_command("let g:test_clip['+'] = ['the plus','']") feed_command("let g:test_clip['*'] = ['the star','']") diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua index 7c0831bd09..46bfae8de2 100644 --- a/test/functional/ui/bufhl_spec.lua +++ b/test/functional/ui/bufhl_spec.lua @@ -762,7 +762,7 @@ describe('Buffer highlighting', function() local s1 = {{'Köttbullar', 'Comment'}, {'Kräuterbutter'}} local s2 = {{'こんにちは', 'Comment'}} - -- TODO: only a virtual text from the same ns curretly overrides + -- TODO: only a virtual text from the same ns currently overrides -- an existing virtual text. We might add a prioritation system. set_virtual_text(id1, 0, s1, {}) eq({{1, 0, 0, { diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 5e819f14a3..1a9a13f7d4 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -569,7 +569,7 @@ describe('float window', function() end) end) - describe('with mulitple tabpages but only one listed buffer,', function() + describe('with multiple tabpages but only one listed buffer,', function() local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1} local unlisted_buf, old_buf, old_win before_each(function() @@ -2761,7 +2761,7 @@ describe('float window', function() }, "NW", 2, 1, 32, true } }} else - -- note: appears misalinged due to cursor + -- note: appears misaligned due to cursor screen:expect{grid=[[ ^example text that is wider than the window | {1:some info! } | diff --git a/test/functional/ui/inccommand_user_spec.lua b/test/functional/ui/inccommand_user_spec.lua index 0b25d4f8d2..43e9b94feb 100644 --- a/test/functional/ui/inccommand_user_spec.lua +++ b/test/functional/ui/inccommand_user_spec.lua @@ -220,7 +220,7 @@ local setup_replace_cmd = [[ end -- ":Replace " - -- Replaces all occurences of in with + -- Replaces all occurrences of in with vim.api.nvim_create_user_command( 'Replace', replace, diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua index bd0d2104db..6f9cea8f24 100644 --- a/test/functional/ui/options_spec.lua +++ b/test/functional/ui/options_spec.lua @@ -194,7 +194,7 @@ end) describe('UI can set terminal option', function() local screen before_each(function() - -- by default we implicity "--cmd 'set bg=light'" which ruins everything + -- by default we implicitly "--cmd 'set bg=light'" which ruins everything clear{args_rm={'--cmd'}} screen = Screen.new(20,5) end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 028fa2825d..c44e147c4d 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -519,7 +519,7 @@ function Screen:_wait(check, flags) end assert(timeout >= minimal_timeout) - local did_miminal_timeout = false + local did_minimal_timeout = false local function notification_cb(method, args) assert(method == 'redraw', string.format( @@ -536,7 +536,7 @@ function Screen:_wait(check, flags) if not err then success_seen = true - if did_miminal_timeout then + if did_minimal_timeout then self._session:stop() end elseif success_seen and #args > 0 then @@ -558,7 +558,7 @@ function Screen:_wait(check, flags) end if not success_seen and not eof then - did_miminal_timeout = true + did_minimal_timeout = true eof = run_session(self._session, flags.request_cb, notification_cb, nil, timeout-minimal_timeout) end diff --git a/test/functional/vimscript/container_functions_spec.lua b/test/functional/vimscript/container_functions_spec.lua index 04a3248c49..5bef3fce05 100644 --- a/test/functional/vimscript/container_functions_spec.lua +++ b/test/functional/vimscript/container_functions_spec.lua @@ -8,7 +8,7 @@ local clear = helpers.clear before_each(clear) describe('extend()', function() - it('suceeds to extend list with itself', function() + it('succeeds to extend list with itself', function() meths.set_var('l', {1, {}}) eq({1, {}, 1, {}}, eval('extend(l, l)')) eq({1, {}, 1, {}}, meths.get_var('l')) diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua index 5d1597f53d..70d0934756 100644 --- a/test/functional/vimscript/json_functions_spec.lua +++ b/test/functional/vimscript/json_functions_spec.lua @@ -343,7 +343,7 @@ describe('json_decode() function', function() exc_exec('call json_decode("\\t\\"abc\\\\u0000")')) end) - it('fails to parse unknown escape sequnces', function() + it('fails to parse unknown escape sequences', function() eq('Vim(call):E474: Unknown escape sequence: \\a"', exc_exec('call json_decode("\\t\\"\\\\a\\"")')) end) -- cgit From b4d42bb9058308c38e3fe9d59458ce65b3f65eb0 Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Wed, 20 Jul 2022 01:43:26 +0600 Subject: fix: make_filter_cmd for :! powershell Problem: `Start-Process` requires the command to be split into the shell command and its arguments. Previously it was done by parsing, which didn't handle cases such as - commands with escaped space in their filepath - quoted commands with space in their filepath Solution: Use - `pwsh -Command` instead of `Start-Process` - `Get-Content` instead of `-RedirectStandardInput` - `Out-File` instead of `-RedirectStandardOutput` --- test/functional/helpers.lua | 6 +++--- test/functional/vimscript/system_spec.lua | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test/functional') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 3aec834bea..4fcc190dee 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -562,16 +562,16 @@ function module.set_shell_powershell(fake) assert(found) end local shell = found and (iswin() and 'powershell' or 'pwsh') or module.testprg('pwsh-test') - local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;' + local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();' local cmd = set_encoding..'Remove-Item -Force '..table.concat(iswin() - and {'alias:cat', 'alias:echo', 'alias:sleep'} + and {'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort'} or {'alias:echo'}, ',')..';' module.exec([[ let &shell = ']]..shell..[[' set shellquote= shellxquote= let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ]]..cmd..[[' let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' - let &shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait' + let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' ]]) return found end diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index a778e2f435..d0061d051e 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -642,12 +642,12 @@ describe('shell :!', function() if iswin() then feed(':4verbose %!sort /R') screen:expect{ - any=[[Executing command: .?Start%-Process sort %-ArgumentList "/R" %-RedirectStandardInput .* %-RedirectStandardOutput .* %-NoNewWindow %-Wait]] + any=[[Executing command: .?Get%-Content .* | & sort /R 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]] } else feed(':4verbose %!sort -r') screen:expect{ - any=[[Executing command: .?Start%-Process sort %-ArgumentList "%-r" %-RedirectStandardInput .* %-RedirectStandardOutput .* %-NoNewWindow %-Wait]] + any=[[Executing command: .?Get%-Content .* | & sort %-r 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]] } end feed('') -- cgit From f2482b3b533c8ed131a33aaead332c226a9e6aca Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Wed, 20 Jul 2022 20:55:28 +0600 Subject: fix: :! pwsh redirection for `command not found` Problem: If the shell command passed to the filtered bang command isn't found, the error isn't redirected to the temp.out file when shell is set to powershell. Solution: Use anonymous function with Invoke-Command operator (&). --- test/functional/vimscript/system_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index d0061d051e..ed822add72 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -642,12 +642,12 @@ describe('shell :!', function() if iswin() then feed(':4verbose %!sort /R') screen:expect{ - any=[[Executing command: .?Get%-Content .* | & sort /R 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]] + any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]] } else feed(':4verbose %!sort -r') screen:expect{ - any=[[Executing command: .?Get%-Content .* | & sort %-r 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]] + any=[[Executing command: .?& { Get%-Content .* | & sort %-r } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]] } end feed('') -- cgit From d367ed9b23d481998d297d812f54b950e5511c24 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 30 Sep 2022 17:09:47 +0200 Subject: NVIM v0.8.0 BREAKING CHANGES - Remove 'insertmode' 'remap' and 'terse' options - highlight: Rename attributes to match Vim (#19159) - highlight: Error on invalid names and allow '.' and '@' - terminal: Drop winpty, require Windows 10 #18253 - treesitter: Use @foo.bar style highlight groups - treesitter: Do not merge queries by default (#20105) FEATURES - runtime: Enable filetype.lua by default (#19216) - Add `undo!` - Add "prerelease" to version dict - Click support for 'statusline', 'winbar' #18650 - Add preview functionality to user commands - allow cmdheight=0 (EXPERIMENTAL) #16251 - Stdpath('run'), /tmp/nvim.user/ #18993 - Add 'mousescroll' option (#12355) - Allow :wincmd to accept a count (#19815) - Multibuffer preview support for inccommand - Man: Port to Lua (#19912) - api: Ui options relevant for remote TUI - api: Add `nvim_parse_cmd` And `nvim_cmd` - api: Support handling stdin stream in remote ui - api: Add `group_name` to `nvim_get_autocmds` - api: Enable nvim_exec_autocmds to pass arbitrary data (#18613) - api: Support pattern array for exec_autocmds - api: Add `unsilent` to command APIs - api: Add replace_keycodes to nvim_set_keymap (#19598) - api: Add support for :horizontal modifier - api: Add "move" to nvim_input_mouse - api/ui: "ui_watched" option for ui-side extmarks - build: Add_glob_target runs only on changed files #19070 - checkhealth: Check for slow shell #17829 - defaults: Session data in $XDG_STATE_HOME #15583 - defaults: Search selection by * and # in visual mode (#18538) - defaults: Nnoremap & :&& #19365 - defaults: enable mouse by default (set mouse=nvi) #19290 - diagnostic: Pass diagnostics as data to DiagnosticChanged autocmd (#20173) - docs: Gen_help_html.lua - edit: Insert an unsimplified key using CTRL-SHIFT-V - treesitter: Full support for spelling - filetype: Convert more patterns to filetype.lua - filetype: Remove side effects from vim.filetype.match (#18894) - filetype: Expand environment variables in filetype patterns (#20145) - fs: Add vim.fs functions: parents() dirname() basename() dir() find() normalize() - highlight: Implement CurSearch highlight - highlight: Support scoped @spam.eggs.baked_beans groups - input: Delay all simplifications - l10n: Turkish translations #19441 - l10n: Improve zh_CN translations (#19483) - lsp: Remove capabilities sanitization (#17814) - lsp: Show feedback on empty hover response (#18308) - lsp: Options to filter and auto-apply code actions (#18221) - lsp: Add vim.lsp.buf.format (#18193) - lsp: Add logging level "OFF" (#18379) - lsp: Add LspAttach and LspDetach autocommands - lsp: Add filter to vim.lsp.get_active_clients() - lsp: Option to reuse_win for jump actions (#18577) - lsp: Add a start function (#18631) - lsp: Send didChangeConfiguration after init (#18847) - lsp: Defaults: tagfunc, omnifunc, formatexpr (#19003, #19677) - lsp: Allow passing custom list handler to LSP functions that return lists (#19213) - lsp: Provide feedback if server can't compute rename result (#19546) - lsp: Add range option to code_action; deprecate range_code_action (#19551) - lsp: Disable exit_timeout by default (#19672) - lsp: Add tcp support - lua: Vim.deprecate() #18320 - lua: Vim.cmd() with kwargs acts like nvim_cmd() #18523 - lua: Allow some vim script functions to run in fast callbacks - lua: Measure require in --startuptime - lua: Allow vim.cmd to be indexed (#19238) - lua: Print source locations of lua callbacks (#19597) - lua: Add vim.iconv (#18286) - lua: Vim.ui_attach to get ui events from lua (EXPERIMENTAL) - man.vim: List command flags in "gO" outline #17558 - mappings: Do not replace existing mapping for simplified form - mappings: Allow special keys and modifiers in mapping - mapset: Support restoring "replace_keycodes" and "desc" - mapset: Support restoring Lua callback (#20024) - marks: Restore viewport on jump #15831 - nvim_create_user_command: Pass structured modifiers to commands - pum: Pretend 'mousemoveevent' is set when showing right-click menu - server: Set $NVIM, unset $NVIM_LISTEN_ADDRESS #11009 - server: Instance "name", store pipes in stdpath(state) - term: Add support for libvterm >= 0.2 - terminal: Implement for terminal mode - terminal: Recognize underdouble and undercurl - terminfo: Bump built-in terminfo entries (#18570) - treesitter: Allow customizing language symbol name - treesitter: Add ability to retreive a tree/node given a range - treesitter: Upstream node methods from nvim-treesitter - treesitter: Include language in invalid query error (#14053) - treesitter: Bundle Lua parser and queries - treesitter: Add viml parser and queries - treesitter: Add injections - treesitter: Add vim.treesitter.start(), enable for Lua - treesitter: Bundle :help parser and queries - tui: Query terminal for CSI u support (#18181) - tui: Recognize keypad keys when using kitty keyboard protocol - tui: Try terminfo for [re]set_cursor_color OSC #19255 - tui: Allow grid and host to disagree on ambiguous-width chars (#19686) - tui: Recognize sidescroll events (#19992) - tui: Support 'mousemoveevent' - ui: Add `'winbar'` - ui: Clear message history explicitly with msg_history_clear event - ui: Make right-click menu work properly with ext_multigrid - ui: Allow to set the highlight namespace per window - ui: Use msg_grid based implementation for cmdheight=0 - ui-ext: Make 'mousemoveevent' a ui_option - eval: Make Lua Funcref work as method and in substitute() (#20217) - eval: Input() support any type for "cancelreturn" in a dict (#19357) BUG FIXES - Show autocmd output when F is in shortmess (#18251) - Has() should preserve v:shell_error #18280 - Suppress "is a directory" messages with shortmess 'F' (#18296) - Display global statusline correctly with ext_messages - Correct nlua_wait error message #18867 - Right-click in clickable statusline #19252 - Remote UI may get invalid 'pumblend' value #19379 - Assertion failure when requiring missing module in autocmd - api: Nvim_eval_statusline should validate input #18347 - api: Check error after getting win/buf handle (#19052) - api: Check for inclusive buffer line index out of bounds correctly (#19056) - api: Change default value of 'pattern' in nvim_exec_autocmds (#19115) - api: Do not switch win/buf if getting option in current win/buf (#19383) - api: Make nvim_set_hl(ns=0, ...) redraw screen properly - api: Nvim_set_hl bail out on invalid group name (#20021) - api: Notify dict watchers on nvim_set_var and vim.g setter - api/command: Fargs behavior when no arguments are passed (#19862) - autocmds: Separate command from desc (#18617) - buffer: Disable buffer-updates before removing from window #18933 - build: Missing definitions for sizeof macros #16393 - build: Only pass -municode if MINGW #19049 - build: Strip trailing newline from variable (#19084) - build: Don't disable byte precompilation on debug builds - build: Fails if git is missing #19366 - charclass: Make behavior with empty str match latest Vim (#19749) - checkhealth: Skip vim.health #18816 - ci: Remove 2000ms blocking wait in many plugin/lsp_spec.lua tests - cmd: Make :-tabmove work with modifiers (#18447) - cmdheight=0: Various issues part3 #19816 - cmdline: Fix passing -1 as char - cmdline: Trigger CmdlineEnter and ModeChanged earlier (#19474) - cmdline: Do not trigger completion at wrong time (#19920) - cmdline: Don't send invalid cursor with incsearch and cmdheight=0 - column: Move sign sentinel after inserting/deleting lines (#20400) - completion: Remove wrong FUNC_ATTR_NONNULL_ALL (#19627) - diagnostic: Use nvim_exec_autocmds to trigger DiagnosticChanged (#18188) - diagnostic: Check for negative column value (#18868) - diagnostic: Remove buf from cache on `BufWipeout` (#20099) - diagnostic: Populate data key in DiagnosticChanged autocmd in reset (#20207) - docs: Correct obsolete note about 'writedelay' in dev docs - docs: Remove internal function from docs - edit.c: Indentkeys double indent after "!" #12894 - eval: Check for v:lua when calling callback (#19855) - eval/f_getmatches: Return empty list for invalid win argument (#18893) - events: Make CursorHold behave as documented - ex_cmds: Correct flags for :const (#19387) - exceptions: Restore `did_throw` (#20000) - exmode: Do not throttle messages when pressing enter to print line - extmarks: Make virt_lines always start at 0 virtcol - filetype: Fix and improve filetype patterns - fillchars: Change fallback after setcellwidths() - float: Make `screen*()` functions respect floating windows - float: Fix glitch when making float window with border a split - float: Fix mouse drag position if float window turned to a split - folds: Fix fold regression with :move (#18685) - folds: Fix fold remains when :delete makes buffer empty (#19673) - ftdetect: Source plugins in autogroup (#18237) - gen_vimdoc.py: Handle missing luajit - getchar: Flush screen before doing a blocking wait - handlers: More specific error messages (#16772) - health: Correct shada file path #18603 - health: Handle non-existent log file #18610 - highlight: Use ctermbg/fg instead of bg/fg when use_rgb=false #18982 - highlight: Add missing 'nocombine' to nvim_get_hl apis (#19586) - highlight: Set the window namespace when redrawing statusline - hl: Set Normal hl group sg_attr value #18820 - hl: Return cterm fg/bg even if they match Normal #18981 - inccommand: Do not try to preview an ambiguous command (#18827) - inccommand: Avoid crash if callback changes inccommand option (#18830) - inccommand: Clear cmdpreview state if preview is not shown (#18923) - inccommand: Skip split window if not enough room #18937 - inccommand: Never preview if parsing command failed (#18944) - inccommand: Parse the command to check if it is previewable - inccommand: Deal with unsynced undo (#20041) - input: Allow Ctrl-C to interrupt a recursive mapping even if mapped (#18885) - input: Fix macro recording with ALT and special key (#18917) - input: Use correct grid when restoring cursor for mapping (#19047) - input: Do no reinterpret mouse keys with ALT modifiers - input: Use click number of last click for mouse drag (#20300) - inspect: Escape identifiers that are lua keywords (#19898) - keywordprg: Default to :help if set to empty string (#19983) - l10n: Improve zh_CN and zh_TW translations (#19969) - log: Back even again - logging: Skip recursion, fix crash #18764 - logging: Make logmsg() thread-safe again - logging: Try harder to resolve Nvim "name" #19016 - lsp: Unify progress message handling (#18040) - lsp: Fix unnecessary buffers being added on empty diagnostics (#18275) - lsp: Fix infinite loop in resolved_capabilities deprecation message (#18333) - lsp: Add missing bufnr argument (#18382) - lsp: Fix rename capability checks and multi client support (#18441) - lsp: Detach spawned LSP server processes (#18477) - lsp: Perform client side filtering of code actions (#18392) - lsp: Only send diagnostics from current buffer in code_action() (#18639) - lsp: Respect global syntax setting in open float preview (#15225) - lsp: Include cancellable in progress message table (#18809) - lsp: Adjust offset encoding in lsp.buf.rename() (#18829) - lsp: Set buflisted before switching to buffer (#18854) - lsp: Fix multi client handling in code action (#18869) - lsp: Small bugs in snippet-parser #18998 - lsp: Pcall nvim_del_augroup_by_name (#19302) - lsp: Abort pending changes after flush when debouncing (#19314) - lsp: Don't attach a client in lsp.start() if there is none (#19328) - lsp: Account for initializing servers in vim.lsp.start (#19329) - lsp: Move augroup define to if statement (#19406) - lsp: Set workspace.configuration capability (#19548) - lsp: Send didOpen if name changes on write (#19583) - lsp: Prevent unexpected position jumps (#19370) - lsp: Avoid ^M character in hover window on Windows (#19640) - lsp: Set end_col in formatexpr (#19676) - lsp: Handle multiple clients with incremental sync (#19658) - lsp: Fix some type annotations in lsp.rpc (#19714) - lsp: Avoid pipe leaks if lsp cmd isn't executable (#19717) - lsp: Handle nil client in onexit callback (#19722) - lsp: Fix nil value error in get_group (#19735) - lsp: Clean the diagnostic cache when buffer delete (#19449) - lsp: When buffer detach remove buffer from client attached buffers (#20081) - lsp: Schedule removal of client object (#20148) - lsp: Support `false` result in handlers (#20252) - lsp: Out of bounds error in lsp.util.apply_text_edits (#20137) - lsp: Use correct function name in deprecated message (#20308) - lsp: Create missing directory before creating file (#19835) - lua: Don't mutate opts parameter of vim.keymap.del (#18227) - lua: Stop pending highlight.on_yank timer, if any (#18824) - lua: Highlight.on_yank can close timer in twice #18976 - lua: Clear got_int when calling vim.on_key() callback (#18979) - lua: Don't leak memory on error - lua: Double entries in :lua completion #19410 - lua: Make it possible to cancel vim.wait() with Ctrl-C (#19217) - lua: Make ui_attach()/ui_detach() take effect immediately (#20037) - lua: Make vim.str_utfindex and vim.str_byteindex handle NUL bytes - lua: Free vim.ui_attach callback before lua close (#20205) - lua: Fix architecture-dependent behavior in usercmd "reg" (#20384) - mac: Use same $LANG fallback mechanism as Vim - mac: Add CoreServices to flake.nix #18358 - man.vim: Q in "$MANPAGER mode" does not quit #18443 - maparg: Remove double allocation (#20033) - mappings: Fix double-free when unmapping simplifiable Lua mapping - mapset: Remove existing abbreviation of same lhs (#20320) - mark: Set mark fnum from buffer (#19195) - mark: Mark without a view restores at topline #19224 - mark: Fix unexpected cursor movements (#19253) - mark: Give correct error message when mark is in another buffer (#19454) - menu: Make :menu still print header when there are no menus - messages: Add color when showing nvim_echo in :messages history - messages: Do not crash on cmdheight=0 and g< redisplay - messages: Validate msg_grid before silent! message with cmdheight=0 - mksession: Don't store floats in session #18635 - mouse: Click on global statusline with splits (#19390) - mouse: Fix using uninitialized memory with K_MOUSEMOVE (#19480) - mpack: Make sure a `bool` always is a `bool` - normal: Fix segfault with bracket command jumping to a mark - options: Properly free string options (#19510) - options: Mark `winhighlight` as list style (#19477) - packaging: Remove excess forward slash in Wix Patch (#18121) - paste: Ignore mappings in Cmdline mode (#18114) - path: Path_is_url returns false for "foo:/" #19797 - powershell: Filter ":!" commands with args #19268 - pum: Make right drag in anchor grid to select work in multigrid UI (#19382) - query: Fix unnatural order for inherits in treesitter queries (#20298) - redraw: Make sure :redraw! redraws command line - redraw: Handle switching to a tabpage with larger p_ch value - redraw: Avoid unnecessary redraws and glitches with floats+messages - redraw: Make redrawdebug=nodelta handle all the cases - rpc: Break nvim_error_event feedback loop between two nvim instances - runtime/genvimvim: Omit s[ubstitute] from vimCommand #18480 - screen: Restart win_update() if a decor provider changes signcols (#18768) - screen: Check for col instead of vcol when drawing fold (#19572) - session: Respect sessionoptions=terminal #19497 - shared: Avoid indexing unindexable values in vim.tbl_get() (#18337) - signs: Priority of extmark signs (#19718) - source: Make changing 'shellslash' change expand() result - source: Fix expand('') no longer works for Lua - spell: Make setting 'encoding' clear word list - spell: Correct spell move behavior without "noplainbuffer" (#20386) - startup: Nvim with --clean should not load user rplugins - substitute: Subtract number of backslashes later - tabpage: Check if ROWS_AVAIL changed for resize (#19620) - terminal: Invalid pointer comparison #18453 - terminal: Do not trim whitespace that is actually in the terminal (#16423) - terminal: Scrollback delete lines immediately #18832 - terminal: Coverity USE_AFTER_FREE #18978 - terminal: Crash if TermClose deletes own buffer #19222 - terminal: Avoid reading over the end of cell.chars (#19580) - terminal: Skip aucmd_win when checking terminal size (#19668) - terminal: Adopt altscreen test for libvterm 0.2 changes - terminfo: Disable smglr for vtpcon and conemu (#18855) - termopen: Avoid ambiguity in URI when CWD is root dir (#16988) - tests: Fix some screen.lua warnings - tests: Fix some issues with ui/inccommand_spec.lua causing slowness - tests: Unreliable parser_spec #18911 - tests: Check for EOF on exit of nvim properly - tests: Missing clear() #18927 - tests: Remove misleading $TEST_PATH segment #19050 - tests: Remove irrelevant usage of display-=msgsep - tests: Use pending_c_parser when needed - tests: Indicate in test logs when nvim exit times out - tmpdir: Invalid tempname() if username has slashes #19323 - treesitter: Create new parser if language is not the same as cached parser (#18149) - treesitter: Bump match limit up - treesitter: Offset directive associates range with capture (#18276) - treesitter: Correct region for string parser (#18794) - treesitter: New iter if folded - treesitter: Don't error when node argument of predicate is nil (#19355) - treesitter: Free memory on removing parser (#19933) - treesitter: More efficient node:root() - treesitter: Make it get_captures_at_position - treesitter: Do not link @error by default - treesitter: Don't support legacy syntax in start() - treesitter: Use the right loading order for base queries (#20117) - treesitter: Prevent endless loop on self-inheritence - treesitter: Return full metadata for get_captures_at_position (#20203) - ts: Do not clobber spelloptions (#20095) - tui: Update modifyOtherKeys reporting (#18158) - tui: Disable extended keys before exiting alternate screen (#18318) - tui: Piping nodejs to nvim breaks input handling #18932 - tui: Resize at startup #17795 - tui: Add fixups for hterm family #19078 - tui: Handle padding requirements for visual bell (#20238) - ui: Require window-local value to show winbar on floating windows (#18773) - ui: Do not call showmode() when setting window height (#18969) - ui: Set redraw_cmdline when setting window height (#19630) - ui: Don't allow decor provider with ns_id==0 - ui: Ui compositor does not correctly free event callbacks - ui: Allow redrawing statusline when msgsep is used (#20337) - ui: Redraw end of buffer if last line is modified (#20354) - unittests: Coredump when running unit tests #18663 - usercmd: Also check for whitespace after escaped character (#19942) - version.c: Mark N/A vim patches #18587 - vim.ui.input: Accept nil or empty "opts" #19109 - window: Close floats first when closing buffer in other tab (#20284) - window: Fix equalization with cmdheight=0 (#20369) - windows: Stdpath("state") => "nvim-data" #18546 - windows: Exepath, stdpath return wrong slashes #19111 - winhl: Do not crash when unsetting winhl in just opened window - Make :undo! notify buffer update callbacks (#20344) - eval: Make Vim functions return inner window width and height (#19743) BUILD SYSTEM - Bump Doxyfile to minimum required version 1.9.0 #18118 - Bump msgpack to 4.0.0 - Enable EXITFREE on Debug builds (#17783) - Add formatting targets for c and lua files (#19488) - clang-format: Align with project style #18192 - clint: Remove all python2-isms with pyupgrade - clint: Remove "function size is too large" warning - clint: Remove rules for includes, whitespace, tabs #18611 - cmake: Simplify and speed up the uninstall target - cmake: Simplify def_cmd_target function - cmake: Use glob_wrapper instead of file(GLOB in main CMakeLists - cmake: Fix static `libintl` test on macOS - deps: Bump LuaJIT, Luv and libuv - deps: Support universal builds on macOS - deps: Bump tree-sitter to v0.20.7 (#20067) - deps: Bump tree-sitter parsers - deps: Bump required libvterm to v0.3 (#20222) - deps: Require libtermkey version 0.22 - deps: update neovim-qt, win32tools.zip PERFORMANCE - Only redraw for CurSearch when it is currently in use - highlight: Allocate permanent names in an arena for fun and cache locality - highlight: Use binary search to lookup RGB color names - map: Visit only one hash bucket instead of all, like an actual hash table - memory: Get rid of extraneous heap allocations - memory: implement arena memory allocation with a shared freelist - memory: Use an arena for RPC decoding and some API return values - messages: Don't call ui_flush() per message line in various places - treesitter: Use a reuse list for query cursors - ui: Reduce allocations when encoding and decoding "redraw" events - ui: Avoid ui_flush() work in headless mode REFACTOR - checkhealth: Rename to vim.health, move logic to Lua #18720 - Add pure attribute to pure functions - Replace char_u variables and functions with char - Enable -Wconversion warning for all Nvim source files - Add warnings for deprecated functions (#18662) - Change type of linenr_T from long to int32_t - Use nvim_get/set_option_value for vim.{b,w}o - Remove functions marked for deprecation in 0.8 (#19299) - Rename function prefix mb to the more accurate utf_cp (#19590) - Remove some unused includes - Change remaining sourcing_name/sourcing_lnum to exestack - Change FALSE/TRUE to false/true - api: Use a hashy hash for looking up api method and event names - api: Use a unpacker based on libmpack instead of msgpack-c - api: restructure api/vim.c and api/private/helpers.c code in separate files - api: Remove redundant fields of CmdParseInfo - aucmd: Call define_autocmd() directly for default autocmds - ci: Cleanup release.yml #19132 - cmd: Format do_one_cmd() - cmd: Hoist out some code into functions - cmd: Unify execute_cmd with do_one_cmd - decor: Use decor levels properly - drawline.c: Factor out utf8 multibyte check - eval: Use Hashy McHashFace instead of gperf - eval.c: Resolve all clint issues (#19774) - eval/funcs.c: Resolve all clint errors - events: Remove unnecessary fudging of updating_screen - ex_cd: Add an early return to fix clint warning - ex_docmd.c: Resolve most clint errors (#19775) - filetype: Allow vim.filetype.match to accept buf and filename (#19114) - highlight: Make hlattrs2dict always use pre-allocated dict - log: Simplify log_path_init #18898 - log: Use msg_schedule_semsg #18950 - lsp: Remove redundant client cleanup (#18744) - lsp: Make the use of local aliases more consistent - lsp: Use autocmd api (#19407) - lsp: Factor out read_loop function - lsp: Encapsulate rpc uv handle - lsp: Extract rpc client from rpc.start - lua: Replace hard-coded gsub with vim.pesc() (#18407) - lua: Reformat with stylua 0.14.0 (#19264) - lua: Git-blame-ignore stylua update PR (#19273) - lua: Replace vim.cmd use with API calls (#19283) - map: Simplify free_all_mem handling - map: Statically initialize maphash array - map: Simplify add_map params - normal: Convert function comments to doxygen format - object: Get rid of redundant FIXED_TEMP_ARRAY - ops: Doxygen docstrings #17743 - option: DRY get/set option value #19038 - plines: Use a struct for chartabsize state - provider: Use list comprehension #19027 - regexp_nfa.c: Match where Vim calls fopen() (#18778) - runtime: Convert dist#ft functions to lua (#18247) - runtime: Convert more dist#ft functions to lua (#18430) - runtime: Convert the remaining dist#ft functions to lua (#18623) - runtime: Port remaining patterns from filetype.vim to filetype.lua (#18814) - runtime: Refactor filetype.lua (#18813) - runtime: Port scripts.vim to lua (#18710) - setcellwidths: Use TV_LIST_ITEM_NEXT properly - signs: Handle non-sign attrs separately (#19784) - tests: Introduce testprg() - treesitter: Get_{nodes,captures}_at_{position,cursor} - typval: Change FC_CFUNC abstraction into FC_LUAREF - ui: Simplify stdin handling - uncrustify: Format all c code under /src/nvim/ - vim.opt: Remove del arg - vim.opt: Unify vim.bo/wo building - vim.opt: Optimize append/prepend/remove - Format runtime with stylua --- test/functional/fixtures/api_level_10.mpack | Bin 0 -> 30761 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/functional/fixtures/api_level_10.mpack (limited to 'test/functional') diff --git a/test/functional/fixtures/api_level_10.mpack b/test/functional/fixtures/api_level_10.mpack new file mode 100644 index 0000000000..2a1f51045d Binary files /dev/null and b/test/functional/fixtures/api_level_10.mpack differ -- cgit From 9353e2f7ef6d0919257548e1a43988404900bf03 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 1 Oct 2022 21:29:54 +0800 Subject: vim-patch:8.2.2542: highlight of char beyond line end is not correct (#20424) Problem: Highlight of char beyond line end is not correct. (Chuan Wei Foo) Solution: Fix counting NUL as one cell. Draw one more character if the EOL is part of the match. (closes vim/vim#7883) https://github.com/vim/vim/commit/41f0895c6e3c7b921e3c102ad42be52b1be48018 Reorder test_search.vim to match Vim. --- test/functional/legacy/search_spec.lua | 30 +++++++++++++++++++++++++++++- test/functional/ui/searchhl_spec.lua | 22 +++++++++++----------- 2 files changed, 40 insertions(+), 12 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua index 67991f5d48..5a94fca794 100644 --- a/test/functional/legacy/search_spec.lua +++ b/test/functional/legacy/search_spec.lua @@ -644,7 +644,35 @@ end) describe('Search highlight', function() before_each(clear) - it('Search highlight is combined with Visual highlight vim-patch:8.2.2797', function() + + -- oldtest: Test_hlsearch_dump() + it('beyond line end vim-patch:8.2.2542', function() + local screen = Screen.new(50, 6) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [2] = {background = Screen.colors.Yellow}, -- Search + [3] = {background = Screen.colors.Grey90}, -- CursorLine + }) + screen:attach() + exec([[ + set hlsearch noincsearch cursorline + call setline(1, ["xxx", "xxx", "xxx"]) + /.* + 2 + ]]) + feed([[/\_.*]]) + screen:expect([[ + {2:xxx } | + {2:xxx } | + {2:^xxx }{3: }| + {1:~ }| + {1:~ }| + /\_.* | + ]]) + end) + + -- oldtest: Test_hlsearch_and_visual() + it('is combined with Visual highlight vim-patch:8.2.2797', function() local screen = Screen.new(40, 6) screen:set_default_attr_ids({ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua index c5c88323a2..18bbb56a61 100644 --- a/test/functional/ui/searchhl_spec.lua +++ b/test/functional/ui/searchhl_spec.lua @@ -221,10 +221,10 @@ describe('search highlighting', function() feed('gg/foo\\nbar') screen:expect([[ one | - {2:^foo} | + {2:^foo } | {2:bar} | baz | - {1:foo} | + {1:foo } | {1:bar} | /foo\nbar | ]]) @@ -232,20 +232,20 @@ describe('search highlighting', function() feed('gg/efg\\nhij') screen:expect([[ --- | - abcd{2:^efg} | + abcd{2:^efg } | {2:hij}kl | --- | - abcd{1:efg} | + abcd{1:efg } | {1:hij}kl | /efg\nhij | ]]) feed('n') screen:expect([[ --- | - abcd{1:efg} | + abcd{1:efg } | {1:hij}kl | --- | - abcd{2:^efg} | + abcd{2:^efg } | {2:hij}kl | /efg\nhij | ]]) @@ -548,9 +548,9 @@ describe('search highlighting', function() feed('/line\\na') screen:expect([[ | - a repeated {2:^line} | - {2:a} repeated {2:line} | - {2:a} repeated {2:line} | + a repeated {2:^line } | + {2:a} repeated {2:line } | + {2:a} repeated {2:line } | {2:a} repeated line | {1:~ }| {4:search hit BOTTOM, continuing at TOP} | @@ -560,9 +560,9 @@ describe('search highlighting', function() feed('4Grb') screen:expect([[ | - a repeated {2:line} | + a repeated {2:line } | {2:a} repeated line | - ^b repeated {2:line} | + ^b repeated {2:line } | {2:a} repeated line | {1:~ }| {4:search hit BOTTOM, continuing at TOP} | -- cgit From 85c7d4f7a92326dcd70317b048bafe96c8051701 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 1 Oct 2022 18:32:08 +0800 Subject: vim-patch:9.0.0620: matchaddpos() can only add up to 8 matches Problem: matchaddpos() can only add up to 8 matches. Solution: Allocate the array of positions. (closes vim/vim#11248) https://github.com/vim/vim/commit/50faf02f43d7f1a56ec2023028fca7c72dbce83e --- test/functional/legacy/match_spec.lua | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/functional/legacy/match_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/match_spec.lua b/test/functional/legacy/match_spec.lua new file mode 100644 index 0000000000..271f844f9d --- /dev/null +++ b/test/functional/legacy/match_spec.lua @@ -0,0 +1,38 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local exec = helpers.exec + +before_each(clear) + +describe('matchaddpos()', function() + -- oldtest: Test_matchaddpos_dump() + it('can add more than 8 match positions vim-patch:9.0.0620', function() + local screen = Screen.new(60, 14) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.Yellow}, -- Search + }) + screen:attach() + exec([[ + call setline(1, ['1234567890123']->repeat(14)) + call matchaddpos('Search', range(1, 12)->map({i, v -> [v, v]})) + ]]) + screen:expect([[ + {1:^1}234567890123 | + 1{1:2}34567890123 | + 12{1:3}4567890123 | + 123{1:4}567890123 | + 1234{1:5}67890123 | + 12345{1:6}7890123 | + 123456{1:7}890123 | + 1234567{1:8}90123 | + 12345678{1:9}0123 | + 123456789{1:0}123 | + 1234567890{1:1}23 | + 12345678901{1:2}3 | + 1234567890123 | + | + ]]) + end) +end) -- cgit From cb310d2901a0eb63721ac5930daaadee91929208 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 1 Oct 2022 21:59:53 +0800 Subject: vim-patch:9.0.0622: matchaddpos() can get slow when adding many matches Problem: matchaddpos() can get slow when adding many matches. Solution: Update the next available match ID when manually picking an ID and remove check if the available ID can be used. (idea by Rick Howe) https://github.com/vim/vim/commit/9f573a8df02d9f699a43d2afbd1d2841d700b9ad --- .../legacy/063_match_and_matchadd_spec.lua | 100 +-------------------- 1 file changed, 1 insertion(+), 99 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/063_match_and_matchadd_spec.lua b/test/functional/legacy/063_match_and_matchadd_spec.lua index d164d9c02f..235a826640 100644 --- a/test/functional/legacy/063_match_and_matchadd_spec.lua +++ b/test/functional/legacy/063_match_and_matchadd_spec.lua @@ -3,10 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local eval, clear, command = helpers.eval, helpers.clear, helpers.command -local eq, neq = helpers.eq, helpers.neq +local clear, command = helpers.clear, helpers.command local insert = helpers.insert -local pcall_err = helpers.pcall_err describe('063: Test for ":match", "matchadd()" and related functions', function() setup(clear) @@ -19,105 +17,9 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( [1] = {background = Screen.colors.Red}, }) - -- Check that "matcharg()" returns the correct group and pattern if a match - -- is defined. command("highlight MyGroup1 term=bold ctermbg=red guibg=red") command("highlight MyGroup2 term=italic ctermbg=green guibg=green") command("highlight MyGroup3 term=underline ctermbg=blue guibg=blue") - command("match MyGroup1 /TODO/") - command("2match MyGroup2 /FIXME/") - command("3match MyGroup3 /XXX/") - eq({'MyGroup1', 'TODO'}, eval('matcharg(1)')) - eq({'MyGroup2', 'FIXME'}, eval('matcharg(2)')) - eq({'MyGroup3', 'XXX'}, eval('matcharg(3)')) - - -- Check that "matcharg()" returns an empty list if the argument is not 1, - -- 2 or 3 (only 0 and 4 are tested). - eq({}, eval('matcharg(0)')) - eq({}, eval('matcharg(4)')) - - -- Check that "matcharg()" returns ['', ''] if a match is not defined. - command("match") - command("2match") - command("3match") - eq({'', ''}, eval('matcharg(1)')) - eq({'', ''}, eval('matcharg(2)')) - eq({'', ''}, eval('matcharg(3)')) - - -- Check that "matchadd()" and "getmatches()" agree on added matches and - -- that default values apply. - command("let m1 = matchadd('MyGroup1', 'TODO')") - command("let m2 = matchadd('MyGroup2', 'FIXME', 42)") - command("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") - eq({{group = 'MyGroup1', pattern = 'TODO', priority = 10, id = 4}, - {group = 'MyGroup2', pattern = 'FIXME', priority = 42, id = 5}, - {group = 'MyGroup3', pattern = 'XXX', priority = 60, id = 17}}, - eval('getmatches()')) - - -- Check that "matchdelete()" deletes the matches defined in the previous - -- test correctly. - command("call matchdelete(m1)") - command("call matchdelete(m2)") - command("call matchdelete(m3)") - eq({}, eval('getmatches()')) - - --- Check that "matchdelete()" returns 0 if successful and otherwise -1. - command("let m = matchadd('MyGroup1', 'TODO')") - eq(0, eval('matchdelete(m)')) - - -- matchdelete throws error and returns -1 on failure - neq(true, pcall(function() eval('matchdelete(42)') end)) - eq('Vim(let):E803: ID not found: 42', pcall_err(command, 'let r2 = matchdelete(42)')) - - -- Check that "clearmatches()" clears all matches defined by ":match" and - -- "matchadd()". - command("let m1 = matchadd('MyGroup1', 'TODO')") - command("let m2 = matchadd('MyGroup2', 'FIXME', 42)") - command("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") - command("match MyGroup1 /COFFEE/") - command("2match MyGroup2 /HUMPPA/") - command("3match MyGroup3 /VIM/") - command("call clearmatches()") - eq({}, eval('getmatches()')) - - -- Check that "setmatches()" restores a list of matches saved by - -- "getmatches()" without changes. (Matches with equal priority must also - -- remain in the same order.) - command("let m1 = matchadd('MyGroup1', 'TODO')") - command("let m2 = matchadd('MyGroup2', 'FIXME', 42)") - command("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") - command("match MyGroup1 /COFFEE/") - command("2match MyGroup2 /HUMPPA/") - command("3match MyGroup3 /VIM/") - command("let ml = getmatches()") - local ml = eval("ml") - command("call clearmatches()") - command("call setmatches(ml)") - eq(ml, eval('getmatches()')) - - -- Check that "setmatches()" can correctly restore the matches from matchaddpos() - command("call clearmatches()") - command("call setmatches(ml)") - eq(ml, eval('getmatches()')) - - -- Check that "setmatches()" will not add two matches with the same ID. The - -- expected behaviour (for now) is to add the first match but not the - -- second and to return -1. - eq('Vim(let):E801: ID already taken: 1', - pcall_err(command, "let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])")) - eq({{group = 'MyGroup1', pattern = 'TODO', priority = 10, id = 1}}, eval('getmatches()')) - - -- Check that "setmatches()" returns 0 if successful and otherwise -1. - -- (A range of valid and invalid input values are tried out to generate the - -- return values.) - eq(0,eval("setmatches([])")) - eq(0,eval("setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}])")) - command("call clearmatches()") - eq('Vim(let):E714: List required', pcall_err(command, 'let rf1 = setmatches(0)')) - eq('Vim(let):E474: List item 0 is either not a dictionary or an empty one', - pcall_err(command, 'let rf2 = setmatches([0])')) - eq('Vim(let):E474: List item 0 is missing one of the required keys', - pcall_err(command, "let rf3 = setmatches([{'wrong key': 'wrong value'}])")) -- Check that "matchaddpos()" positions matches correctly insert('abcdefghijklmnopq') -- cgit From 0643645d5c9e34f7c385925b98bbcf8f64260385 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 2 Oct 2022 16:32:33 +0800 Subject: fix(folds): fix fold marker multibyte comparison (#20439) --- test/functional/ui/fold_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index 6bb8bb81c6..3c143d87ca 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -4,6 +4,7 @@ local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq local command = helpers.command local feed_command = helpers.feed_command local insert = helpers.insert +local expect = helpers.expect local funcs = helpers.funcs local meths = helpers.meths local source = helpers.source @@ -1911,4 +1912,19 @@ describe("folded lines", function() command('%delete') eq(0, funcs.foldlevel(1)) end) + + it('multibyte fold markers work #20438', function() + meths.win_set_option(0, 'foldmethod', 'marker') + meths.win_set_option(0, 'foldmarker', '«,»') + insert([[ + bbbbb + bbbbb + bbbbb]]) + feed('zfgg') + expect([[ + bbbbb/*«*/ + bbbbb + bbbbb/*»*/]]) + eq(1, funcs.foldlevel(1)) + end) end) -- cgit From 71497c164db3180bbec539765f987b483662f73f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 4 Oct 2022 07:31:06 +0800 Subject: test: add test for :function followed by --- test/functional/vimscript/eval_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index d4fa7afe89..1fbdedb815 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -17,6 +17,7 @@ local clear = helpers.clear local eq = helpers.eq local exc_exec = helpers.exc_exec local exec = helpers.exec +local exec_capture = helpers.exec_capture local eval = helpers.eval local command = helpers.command local write_file = helpers.write_file @@ -247,3 +248,16 @@ describe("uncaught exception", function() eq('123', eval('result')) end) end) + +describe('lambda function', function() + before_each(clear) + + it('can be shown using :function followed by #20466', function() + command('let A = {-> 1}') + local num = exec_capture('echo A'):match("function%('(%d+)'%)") + eq(([[ + function %s(...) +1 return 1 + endfunction]]):format(num), exec_capture(('function %s'):format(num))) + end) +end) -- cgit From 28fbdd338586e066aa3e540333513b04c54361bc Mon Sep 17 00:00:00 2001 From: Shougo Date: Tue, 4 Oct 2022 22:22:42 +0900 Subject: fix(ui): msg_ext_set_kind for nvim_echo (#20476) --- test/functional/ui/messages_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 6b8fa99b38..d6dfcf2aa9 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -869,7 +869,7 @@ stack traceback: {1:~ }| {1:~ }| ]], messages={ - { content = { { "wow, ", 7 }, { "such\n\nvery ", 2 }, { "color", 10 } }, kind = "" } + { content = { { "wow, ", 7 }, { "such\n\nvery ", 2 }, { "color", 10 } }, kind = "echomsg" } }} feed ':ls' @@ -880,7 +880,7 @@ stack traceback: {1:~ }| {1:~ }| ]], messages={ - { content = { { '\n 1 %a "[No Name]" line 1' } }, kind = "echomsg" } + { content = { { '\n 1 %a "[No Name]" line 1' } }, kind = "" } }} feed ':messages' -- cgit From 088abbeb6e6aecfc34b42db9b8d1396f493a2466 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 29 Sep 2022 13:46:44 +0200 Subject: feat(docs): nested lists in HTML, update :help parser - Docs HTML: improvements in https://github.com/neovim/tree-sitter-vimdoc allow us to many hacks in `gen_help_html.lua`. - Docs HTML: support nested lists. - Docs HTML: avoid extra newlines (too much whitespace) in old (preformatted) layout. - Docs HTML: disable golden-grid for narrow viewport. - Workaround for https://github.com/neovim/neovim/issues/20404 closes https://github.com/neovim/neovim/issues/20404 --- test/functional/lua/help_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua index a00aaea9d2..6743648819 100644 --- a/test/functional/lua/help_spec.lua +++ b/test/functional/lua/help_spec.lua @@ -21,7 +21,7 @@ describe(':help docs', function() ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles) -- Check that parse errors did not increase wildly. -- TODO: Fix all parse errors in :help files. - ok(rv.err_count < 250, '<250 parse errors', rv.err_count) + ok(rv.err_count < 280, '<280 parse errors', rv.err_count) eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) -- cgit From ddc363dce9020bce7d5bd931929f0d11cc87ad6d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 4 Oct 2022 21:52:01 +0800 Subject: vim-patch:9.0.0656: cannot specify another character to use instead of '@' Problem: Cannot specify another character to use instead of '@' at the end of the window. Solution: Add "lastline" to 'fillchars'. (Martin Tournoij, closes vim/vim#11264, closes vim/vim#10963) https://github.com/vim/vim/commit/4ba5f1dab656103e8f4a4505452d1816b9e83c1e Use latest code in drawscreen.c instead. --- test/functional/legacy/display_spec.lua | 88 +++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 27 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/display_spec.lua b/test/functional/legacy/display_spec.lua index f0ffaf2c48..28dbb4bc2e 100644 --- a/test/functional/legacy/display_spec.lua +++ b/test/functional/legacy/display_spec.lua @@ -9,6 +9,7 @@ local command = helpers.command describe('display', function() before_each(clear) + -- oldtest: Test_display_scroll_at_topline() it('scroll when modified at topline vim-patch:8.2.1488', function() local screen = Screen.new(20, 4) screen:attach() @@ -26,6 +27,7 @@ describe('display', function() ]]) end) + -- oldtest: Test_display_scroll_update_visual() it('scrolling when modified at topline in Visual mode vim-patch:8.2.4626', function() local screen = Screen.new(60, 8) screen:attach() @@ -56,8 +58,8 @@ describe('display', function() ]]) end) - it('@@@ in the last line shows correctly in a narrow window vim-patch:8.2.4718', function() - local screen = Screen.new(60, 10) + local function run_test_display_lastline(euro) + local screen = Screen.new(75, 10) screen:set_default_attr_ids({ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText [2] = {bold = true, reverse = true}, -- StatusLine @@ -65,39 +67,71 @@ describe('display', function() }) screen:attach() exec([[ - call setline(1, ['aaa', 'b'->repeat(100)]) + call setline(1, ['aaa', 'b'->repeat(200)]) set display=truncate + vsplit 100wincmd < ]]) - screen:expect([[ - ^a│aaa | - a│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| - a│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | - b│{1:~ }| - b│{1:~ }| - b│{1:~ }| - b│{1:~ }| - {1:@}│{1:~ }| - {2:< }{3:[No Name] [+] }| - | - ]]) + local fillchar = '@' + if euro then + command('set fillchars=lastline:€') + fillchar = '€' + end + screen:expect((([[ + ^a│aaa | + a│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| + a│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| + b│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | + b│{1:~ }| + b│{1:~ }| + b│{1:~ }| + {1:@}│{1:~ }| + {2:< }{3:[No Name] [+] }| + | + ]]):gsub('@', fillchar))) + command('set display=lastline') screen:expect_unchanged() + command('100wincmd >') - screen:expect([[ - ^aaa │a| - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb│a| - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb │a| - {1:~ }│b| - {1:~ }│b| - {1:~ }│b| - {1:~ }│b| - {1:~ }│{1:@}| - {2:[No Name] [+] }{3:<}| - | - ]]) + screen:expect((([[ + ^aaa │a| + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb│a| + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb│a| + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb │b| + {1:~ }│b| + {1:~ }│b| + {1:~ }│b| + {1:~ }│{1:@}| + {2:[No Name] [+] }{3:<}| + | + ]]):gsub('@', fillchar))) + command('set display=truncate') screen:expect_unchanged() + + command('close') + command('3split') + screen:expect((([[ + ^aaa | + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| + {1:@@@ }| + {2:[No Name] [+] }| + aaa | + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | + {3:[No Name] [+] }| + | + ]]):gsub('@', fillchar))) + end + + -- oldtest: Test_display_lastline() + it('display "lastline" works correctly', function() + run_test_display_lastline() + end) + it('display "lastline" works correctly with multibyte fillchar', function() + run_test_display_lastline(true) end) end) -- cgit From 98bb2c19309ced1131afce4fc2cdae518d0a2dcd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 06:48:40 +0800 Subject: vim-patch:9.0.0661: multi-byte "lastline" in 'fillchars' does not work properly Problem: Multi-byte "lastline" item in 'fillchars' does not work properly when the window is two columns wide. Solution: Compute the text length correctly. (closes vim/vim#11280) https://github.com/vim/vim/commit/18b3500b8c517e44c23197e558aa36aed1c6916c --- test/functional/legacy/display_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/display_spec.lua b/test/functional/legacy/display_spec.lua index 28dbb4bc2e..9160129a02 100644 --- a/test/functional/legacy/display_spec.lua +++ b/test/functional/legacy/display_spec.lua @@ -125,6 +125,21 @@ describe('display', function() {3:[No Name] [+] }| | ]]):gsub('@', fillchar))) + + command('close') + command('2vsplit') + screen:expect((([[ + ^aa│aaa | + a │bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| + bb│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb| + bb│bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | + bb│{1:~ }| + bb│{1:~ }| + bb│{1:~ }| + {1:@@}│{1:~ }| + {2:< }{3:[No Name] [+] }| + | + ]]):gsub('@', fillchar))) end -- oldtest: Test_display_lastline() -- cgit From fc1f84c4c57ba0ba284b0652d412b0402ef928a7 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 5 Oct 2022 11:23:11 +0200 Subject: test(api): migrate screenchar() test in in window API to screen test This produces actual output in case of regressions. --- test/functional/api/window_spec.lua | 106 +++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 32 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 901d24327c..7c65cf9c37 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -15,25 +15,6 @@ local command = helpers.command local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive --- check if str is visible at the beginning of some line -local function is_visible(str) - local slen = string.len(str) - local nlines = eval("&lines") - for i = 1,nlines do - local iseq = true - for j = 1,slen do - if string.byte(str,j) ~= eval("screenchar("..i..","..j..")") then - iseq = false - break - end - end - if iseq then - return true - end - end - return false -end - describe('API/win', function() before_each(clear) @@ -79,27 +60,61 @@ describe('API/win', function() end) it('updates the screen, and also when the window is unfocused', function() + local screen = Screen.new(30, 9) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, + [2] = {bold = true, reverse = true}; + [3] = {reverse = true}; + }) + screen:attach() + insert("prologue") feed('100o') insert("epilogue") local win = curwin() feed('gg') - poke_eventloop() -- let nvim process the 'gg' command + screen:expect{grid=[[ + ^prologue | + | + | + | + | + | + | + | + | + ]]} -- cursor position is at beginning eq({1, 0}, window('get_cursor', win)) - eq(true, is_visible("prologue")) - eq(false, is_visible("epilogue")) -- move cursor to end window('set_cursor', win, {101, 0}) - eq(false, is_visible("prologue")) - eq(true, is_visible("epilogue")) + screen:expect{grid=[[ + | + | + | + | + | + | + | + ^epilogue | + | + ]]} -- move cursor to the beginning again window('set_cursor', win, {1, 0}) - eq(true, is_visible("prologue")) - eq(false, is_visible("epilogue")) + screen:expect{grid=[[ + ^prologue | + | + | + | + | + | + | + | + | + ]]} -- move focus to new window nvim('command',"new") @@ -107,18 +122,45 @@ describe('API/win', function() -- sanity check, cursor position is kept eq({1, 0}, window('get_cursor', win)) - eq(true, is_visible("prologue")) - eq(false, is_visible("epilogue")) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {2:[No Name] }| + prologue | + | + | + {3:[No Name] [+] }| + | + ]]} -- move cursor to end window('set_cursor', win, {101, 0}) - eq(false, is_visible("prologue")) - eq(true, is_visible("epilogue")) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {2:[No Name] }| + | + | + epilogue | + {3:[No Name] [+] }| + | + ]]} -- move cursor to the beginning again window('set_cursor', win, {1, 0}) - eq(true, is_visible("prologue")) - eq(false, is_visible("epilogue")) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {2:[No Name] }| + prologue | + | + | + {3:[No Name] [+] }| + | + ]]} -- curwin didn't change back neq(win, curwin()) -- cgit From 9d8546e0c515f6ed2f45525ed79c7a98ac9d135d Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 5 Oct 2022 12:29:37 +0200 Subject: test(shada): fix shada syntax definitions test These tests contained errors due to synstack() and friends do not ensure syntax state is fully synced. Actually expecting what the user will see with a screen test does ensure it is fully synced. --- test/functional/plugin/shada_spec.lua | 71 ++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 9 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 6f22f865e6..dda8077f05 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local clear = helpers.clear local eq, meths, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf = helpers.eq, helpers.meths, helpers.eval, helpers.command, helpers.nvim, helpers.exc_exec, @@ -2538,13 +2539,26 @@ describe('ftplugin/shada.vim', function() end) describe('syntax/shada.vim', function() - local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) + local epoch = os.date('!%Y-%m-%dT%H:%M:%S', 0) before_each(reset) it('works', function() nvim_command('syntax on') nvim_command('setlocal syntax=shada') nvim_command('set laststatus&') + local screen = Screen.new(60, 37) + screen:set_default_attr_ids { + [1] = {bold = true, foreground = Screen.colors.Brown}; + [2] = {foreground = tonumber('0x6a0dad')}; + [3] = {foreground = Screen.colors.Fuchsia}; + [4] = {foreground = Screen.colors.Blue1}; + [5] = {bold = true, foreground = Screen.colors.SeaGreen4}; + [6] = {foreground = Screen.colors.SlateBlue}; + [7] = {bold = true, reverse = true}; + [8] = {bold = true, foreground = Screen.colors.Blue}; + } + screen:attach() + curbuf('set_lines', 0, 1, true, { 'Header with timestamp ' .. epoch .. ':', ' % Key Value', @@ -2580,6 +2594,46 @@ describe('syntax/shada.vim', function() ' % Key Description________ Value', ' + se place cursor at end TRUE', }) + screen:expect{grid=[=[ + {1:^Header} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00: | + {2: % Key Value} | + {1: +} {3:t } {1:"}{3:test}{1:"} | + {1:Jump} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00: | + {2: % Key________ Description Value} | + {1: +} {3:n } {4:name } {3:'A'} | + {1: +} {3:f } {4:file name } {1:["}{3:foo}{1:"]} | + {1: +} {3:l } {4:line number} {3:2} | + {1: +} {3:c } {4:column } {3:-200} | + {1:Register} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00: | + {2: % Key Description Value} | + {1: +} {3:rc } {4:contents } {1:@} | + {1: | -} {1:{"}{3:abcdefghijklmnopqrstuvwxyz}{1:":} {3:1.0}{1:}} | + {1: +} {3:rt } {4:type } {1:CHARACTERWISE} | + {1: +} {3:rt } {4:type } {1:LINEWISE} | + {1: +} {3:rt } {4:type } {1:BLOCKWISE} | + {1:Replacement string} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00: | + {2: @ Description__________ Value} | + {1: -} {4::s replacement string} {1:CMD} | + {1: -} {4::s replacement string} {1:SEARCH} | + {1: -} {4::s replacement string} {1:EXPR} | + {1: -} {4::s replacement string} {1:INPUT} | + {1: -} {4::s replacement string} {1:DEBUG} | + {1:Buffer list} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00: | + {4: # Expected array of maps} | + = {1:[{="}{3:a}{1:":} {1:+(}{5:10}{1:)"}{3:ac}{6:\0}{3:df}{6:\n}{3:gi}{6:\"}{3:tt\.}{1:",} {1:TRUE:} {1:FALSE},} {1:[NIL,} {1:+(}{5:-}| + {5:10}{1:)""]]} | + {1:Buffer list} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00: | + {2: % Key Description Value} | + | + {2: % Key Description Value} | + {1:Header} with timestamp 1970{1:-}01{1:-}01{1:T}00{1::}00{1::}00: | + {2: % Key Description________ Value} | + {1: +} {3:se } {4:place cursor at end} {1:TRUE} | + {8:~ }| + {7:[No Name] [+] }| + | + ]=]} + nvim_command([[ function GetSyntax() let lines = [] @@ -2613,7 +2667,7 @@ describe('syntax/shada.vim', function() year = htsnum(os.date('%Y', 0)), month = htsnum(os.date('%m', 0)), day = htsnum(os.date('%d', 0)), - hour = htsnum(os.date('%H', 0)), + hour = htsnum(os.date('!%H', 0)), minute = htsnum(os.date('%M', 0)), second = htsnum(os.date('%S', 0)), } @@ -2768,9 +2822,8 @@ describe('syntax/shada.vim', function() {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'INPUT'}, }, { - {{'ShaDaEntryArrayEntryStart'}, ' - '}, - {{'ShaDaEntryArrayDescription'}, ':s replacement string '}, - {{'ShaDaMsgpackShaDaKeyword'}, 'DEBUG'}, + as(), ad(':s replacement string '), + {{'ShaDaEntryArray', 'ShaDaMsgpackShaDaKeyword'}, 'DEBUG'}, }, { hname('Buffer list'), h(' with timestamp '), @@ -2872,10 +2925,10 @@ describe('syntax/shada.vim', function() mlh(' % Key Description________ Value'), }, { - {{'ShaDaEntryMapLongEntryStart'}, ' + '}, - {{'ShaDaEntryMapLongKey'}, 'se '}, - {{'ShaDaEntryMapLongDescription'}, 'place cursor at end '}, - {{'ShaDaMsgpackKeyword'}, 'TRUE'}, + mles(' + '), + mlk('se '), + mld('place cursor at end '), + {{'ShaDaEntryMapLong', 'ShaDaMsgpackKeyword'}, 'TRUE'}, }, } eq(exp, act) -- cgit From 824a31cd0d55752b01a9bdd1f38f756e079e25e8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 21:29:56 +0800 Subject: vim-patch:8.2.3885: arglist test fails Problem: Arglist test fails. Solution: Adjust for locking the arglist for ":all". https://github.com/vim/vim/commit/679140c56bbabf12a199d94f584b1b9dfc9809fd --- test/functional/legacy/006_argument_list_spec.lua | 85 -------- test/functional/legacy/arglist_spec.lua | 228 ---------------------- 2 files changed, 313 deletions(-) delete mode 100644 test/functional/legacy/006_argument_list_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/006_argument_list_spec.lua b/test/functional/legacy/006_argument_list_spec.lua deleted file mode 100644 index d269bf8ec9..0000000000 --- a/test/functional/legacy/006_argument_list_spec.lua +++ /dev/null @@ -1,85 +0,0 @@ --- Test for autocommand that redefines the argument list, when doing ":all". - -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command, dedent, eq = helpers.command, helpers.dedent, helpers.eq -local curbuf_contents = helpers.curbuf_contents -local poke_eventloop = helpers.poke_eventloop - -describe('argument list', function() - setup(clear) - - it('is working', function() - insert([[ - start of test file Xxx - this is a test - this is a test - this is a test - this is a test - end of test file Xxx]]) - poke_eventloop() - - command('au BufReadPost Xxx2 next Xxx2 Xxx1') - command('/^start of') - - -- Write test file Xxx1 - feed('A1:.,/end of/w! Xxx1') - - -- Write test file Xxx2 - feed('$r2:.,/end of/w! Xxx2') - - -- Write test file Xxx3 - feed('$r3:.,/end of/w! Xxx3') - poke_eventloop() - - -- Redefine arglist; go to Xxx1 - command('next! Xxx1 Xxx2 Xxx3') - - -- Open window for all args - command('all') - - -- Write contents of Xxx1 - command('%yank A') - - -- Append contents of last window (Xxx1) - feed('') - poke_eventloop() - command('%yank A') - - -- should now be in Xxx2 - command('rew') - - -- Append contents of Xxx2 - command('%yank A') - - command('%d') - command('0put=@a') - command('$d') - - eq(dedent([[ - start of test file Xxx1 - this is a test - this is a test - this is a test - this is a test - end of test file Xxx - start of test file Xxx1 - this is a test - this is a test - this is a test - this is a test - end of test file Xxx - start of test file Xxx2 - this is a test - this is a test - this is a test - this is a test - end of test file Xxx]]), curbuf_contents()) - end) - - teardown(function() - os.remove('Xxx1') - os.remove('Xxx2') - os.remove('Xxx3') - end) -end) diff --git a/test/functional/legacy/arglist_spec.lua b/test/functional/legacy/arglist_spec.lua index 4d9e88c446..a15809907b 100644 --- a/test/functional/legacy/arglist_spec.lua +++ b/test/functional/legacy/arglist_spec.lua @@ -3,7 +3,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, command, eq = helpers.clear, helpers.command, helpers.eq -local eval, exc_exec, neq = helpers.eval, helpers.exc_exec, helpers.neq local expect_exit = helpers.expect_exit local feed = helpers.feed local pcall_err = helpers.pcall_err @@ -11,233 +10,6 @@ local pcall_err = helpers.pcall_err describe('argument list commands', function() before_each(clear) - local function init_abc() - command('args a b c') - command('next') - end - - local function reset_arglist() - command('arga a | %argd') - end - - local function assert_fails(cmd, err) - neq(nil, exc_exec(cmd):find(err)) - end - - it('test that argidx() works', function() - command('args a b c') - command('last') - eq(2, eval('argidx()')) - command('%argdelete') - eq(0, eval('argidx()')) - - command('args a b c') - eq(0, eval('argidx()')) - command('next') - eq(1, eval('argidx()')) - command('next') - eq(2, eval('argidx()')) - command('1argdelete') - eq(1, eval('argidx()')) - command('1argdelete') - eq(0, eval('argidx()')) - command('1argdelete') - eq(0, eval('argidx()')) - end) - - it('test that argadd() works', function() - command('%argdelete') - command('argadd a b c') - eq(0, eval('argidx()')) - - command('%argdelete') - command('argadd a') - eq(0, eval('argidx()')) - command('argadd b c d') - eq(0, eval('argidx()')) - - init_abc() - command('argadd x') - eq({'a', 'b', 'x', 'c'}, eval('argv()')) - eq(1, eval('argidx()')) - - init_abc() - command('0argadd x') - eq({'x', 'a', 'b', 'c'}, eval('argv()')) - eq(2, eval('argidx()')) - - init_abc() - command('1argadd x') - eq({'a', 'x', 'b', 'c'}, eval('argv()')) - eq(2, eval('argidx()')) - - init_abc() - command('$argadd x') - eq({'a', 'b', 'c', 'x'}, eval('argv()')) - eq(1, eval('argidx()')) - - init_abc() - command('$argadd x') - command('+2argadd y') - eq({'a', 'b', 'c', 'x', 'y'}, eval('argv()')) - eq(1, eval('argidx()')) - - command('%argd') - command('edit d') - command('arga') - eq(1, eval('len(argv())')) - eq('d', eval('get(argv(), 0, "")')) - - command('%argd') - command('new') - command('arga') - eq(0, eval('len(argv())')) - end) - - it('test for 0argadd and 0argedit', function() - reset_arglist() - - command('arga a b c d') - command('2argu') - command('0arga added') - eq({'added', 'a', 'b', 'c', 'd'}, eval('argv()')) - - command('%argd') - command('arga a b c d') - command('2argu') - command('0arge edited') - eq({'edited', 'a', 'b', 'c', 'd'}, eval('argv()')) - - command('2argu') - command('arga third') - eq({'edited', 'a', 'third', 'b', 'c', 'd'}, eval('argv()')) - end) - - it('test for argc()', function() - reset_arglist() - eq(0, eval('argc()')) - command('argadd a b') - eq(2, eval('argc()')) - end) - - it('test for arglistid()', function() - reset_arglist() - command('arga a b') - eq(0, eval('arglistid()')) - command('split') - command('arglocal') - eq(1, eval('arglistid()')) - command('tabnew | tabfirst') - eq(0, eval('arglistid(2)')) - eq(1, eval('arglistid(1, 1)')) - eq(0, eval('arglistid(2, 1)')) - eq(1, eval('arglistid(1, 2)')) - command('tabonly | only | enew!') - command('argglobal') - eq(0, eval('arglistid()')) - end) - - it('test for argv()', function() - reset_arglist() - eq({}, eval('argv()')) - eq('', eval('argv(2)')) - command('argadd a b c d') - eq('c', eval('argv(2)')) - end) - - it('test for :argedit command', function() - reset_arglist() - command('argedit a') - eq({'a'}, eval('argv()')) - eq('a', eval('expand("%:t")')) - command('argedit b') - eq({'a', 'b'}, eval('argv()')) - eq('b', eval('expand("%:t")')) - command('argedit a') - eq({'a', 'b', 'a'}, eval('argv()')) - eq('a', eval('expand("%:t")')) - command('argedit c') - eq({'a', 'b', 'a', 'c'}, eval('argv()')) - command('0argedit x') - eq({'x', 'a', 'b', 'a', 'c'}, eval('argv()')) - command('set nohidden') - command('enew! | set modified') - assert_fails('argedit y', 'E37:') - command('argedit! y') - eq({'x', 'y', 'y', 'a', 'b', 'a', 'c'}, eval('argv()')) - command('set hidden') - command('%argd') - command('argedit a b') - eq({'a', 'b'}, eval('argv()')) - end) - - it('test for :argdelete command', function() - reset_arglist() - command('args aa a aaa b bb') - command('argdelete a*') - eq({'b', 'bb'}, eval('argv()')) - eq('aa', eval('expand("%:t")')) - command('last') - command('argdelete %') - eq({'b'}, eval('argv()')) - assert_fails('argdelete', 'E610:') - assert_fails('1,100argdelete', 'E16:') - reset_arglist() - command('args a b c d') - command('next') - command('argdel') - eq({'a', 'c', 'd'}, eval('argv()')) - command('%argdel') - end) - - it('test for the :next, :prev, :first, :last, :rewind commands', function() - reset_arglist() - command('args a b c d') - command('last') - eq(3, eval('argidx()')) - assert_fails('next', 'E165:') - command('prev') - eq(2, eval('argidx()')) - command('Next') - eq(1, eval('argidx()')) - command('first') - eq(0, eval('argidx()')) - assert_fails('prev', 'E164:') - command('3next') - eq(3, eval('argidx()')) - command('rewind') - eq(0, eval('argidx()')) - command('%argd') - end) - - it('test for autocommand that redefines the argument list, when doing ":all"', function() - command('autocmd BufReadPost Xxx2 next Xxx2 Xxx1') - command("call writefile(['test file Xxx1'], 'Xxx1')") - command("call writefile(['test file Xxx2'], 'Xxx2')") - command("call writefile(['test file Xxx3'], 'Xxx3')") - - command('new') - -- redefine arglist; go to Xxx1 - command('next! Xxx1 Xxx2 Xxx3') - -- open window for all args - command('all') - eq('test file Xxx1', eval('getline(1)')) - command('wincmd w') - command('wincmd w') - eq('test file Xxx1', eval('getline(1)')) - -- should now be in Xxx2 - command('rewind') - eq('test file Xxx2', eval('getline(1)')) - - command('autocmd! BufReadPost Xxx2') - command('enew! | only') - command("call delete('Xxx1')") - command("call delete('Xxx2')") - command("call delete('Xxx3')") - command('argdelete Xxx*') - command('bwipe! Xxx1 Xxx2 Xxx3') - end) - it('quitting Vim with unedited files in the argument list throws E173', function() command('set nomore') command('args a b c') -- cgit From 6ae144a92171cf9ae52bddddc3a081a4efaabe9f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 27 Sep 2022 16:19:15 +0200 Subject: feat(messages)!: graduate the 'msgsep' feature The old behaviour (e.g. via `set display-=msgsep`) will not be available. Assuming that messages always are being drawn on msg_grid (or not drawn at all, and forwarded to `ext_messages` enabled UI) will allows some simplifcations and enhancements moving forward. --- test/functional/core/fileio_spec.lua | 2 +- test/functional/legacy/cmdline_spec.lua | 77 -------------------------------- test/functional/ui/cmdline_spec.lua | 66 +-------------------------- test/functional/ui/embed_spec.lua | 14 ------ test/functional/ui/highlight_spec.lua | 11 ----- test/functional/ui/messages_spec.lua | 22 --------- test/functional/ui/screen_basic_spec.lua | 61 +------------------------ test/functional/ui/wildmode_spec.lua | 42 +---------------- 8 files changed, 4 insertions(+), 291 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index a589d088a4..d1ff5b8036 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -166,7 +166,7 @@ describe('fileio', function() [3] = {bold = true, foreground = Screen.colors.SeaGreen4} }) screen:attach() - command("set display-=msgsep shortmess-=F") + command("set shortmess-=F") command("e Xtest-overwrite-forced") screen:expect([[ diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 49e3825693..88912b9cd4 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -172,83 +172,6 @@ describe('cmdline', function() | ]]) end) - - -- oldtest: Test_redrawstatus_in_autocmd() - it(':redrawstatus in cmdline mode', function() - local screen = Screen.new(60, 8) - screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [1] = {bold = true, reverse = true}, -- MsgSeparator, StatusLine - }) - screen:attach() - exec([[ - set laststatus=2 - set statusline=%=:%{getcmdline()} - autocmd CmdlineChanged * redrawstatus - set display-=msgsep - ]]) - -- :redrawstatus is postponed if messages have scrolled - feed([[:echo "one\ntwo\nthree\nfour"]]) - feed(':foobar') - screen:expect([[ - {0:~ }| - {0:~ }| - {1: :echo "one\ntwo\nthree\nfour"}| - one | - two | - three | - four | - :foobar^ | - ]]) - -- it is not postponed if messages have not scrolled - feed(':for in in range(3)') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {1: :for in in range(3)}| - :for in in range(3)^ | - ]]) - -- with cmdheight=1 messages have scrolled when typing :endfor - feed(':endfor') - screen:expect([[ - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {1: :for in in range(3)}| - :for in in range(3) | - : :endfor^ | - ]]) - feed(':set cmdheight=2') - -- with cmdheight=2 messages haven't scrolled when typing :for or :endfor - feed(':for in in range(3)') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {1: :for in in range(3)}| - :for in in range(3)^ | - | - ]]) - feed(':endfor') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {1: ::endfor}| - :for in in range(3) | - : :endfor^ | - ]]) - end) end) describe('cmdwin', function() diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 1528b5307d..8003947078 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -822,7 +822,7 @@ describe('statusline is redrawn on entering cmdline', function() ]]} end) - it('with scrolled messages and msgsep', function() + it('with scrolled messages', function() screen:try_resize(35,14) exec([[ let g:count = 0 @@ -904,70 +904,6 @@ describe('statusline is redrawn on entering cmdline', function() ]]} end) - it('but not with scrolled messages without msgsep', function() - screen:try_resize(35,10) - exec([[ - let g:count = 0 - autocmd CmdlineEnter * let g:count += 1 - set display-=msgsep - set statusline=%{mode()}%{g:count} - ]]) - feed(':echoerr doesnotexist') - screen:expect{grid=[[ - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {3:c1 }| - {4:E121: Undefined variable: doesnotex}| - {4:ist} | - {5:Press ENTER or type command to cont}| - {5:inue}^ | - ]]} - feed(':echoerr doesnotexist') - screen:expect{grid=[[ - {1:~ }| - {1:~ }| - {3:c1 }| - {4:E121: Undefined variable: doesnotex}| - {4:ist} | - {5:Press ENTER or type command to cont}| - {4:E121: Undefined variable: doesnotex}| - {4:ist} | - {5:Press ENTER or type command to cont}| - {5:inue}^ | - ]]} - - feed(':echoerr doesnotexist') - screen:expect{grid=[[ - {4:E121: Undefined variable: doesnotex}| - {4:ist} | - {5:Press ENTER or type command to cont}| - {4:E121: Undefined variable: doesnotex}| - {4:ist} | - {5:Press ENTER or type command to cont}| - {4:E121: Undefined variable: doesnotex}| - {4:ist} | - {5:Press ENTER or type command to cont}| - {5:inue}^ | - ]]} - - feed('') - screen:expect{grid=[[ - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {3:n3 }| - | - ]]} - end) - describe('if custom statusline is set by', function() before_each(function() command('set statusline=') diff --git a/test/functional/ui/embed_spec.lua b/test/functional/ui/embed_spec.lua index 92f5beebf5..e7addd1b85 100644 --- a/test/functional/ui/embed_spec.lua +++ b/test/functional/ui/embed_spec.lua @@ -82,20 +82,6 @@ local function test_embed(ext_linegrid) eq(Screen.colors.Green, screen.default_colors.rgb_bg) end} end) - - it("set display-=msgsep before first redraw", function() - startup('--cmd', 'set display-=msgsep') - screen:expect{grid=[[ - ^ | - {3:~ }| - {3:~ }| - {3:~ }| - {3:~ }| - {3:~ }| - {3:~ }| - | - ]]} - end) end describe('--embed UI on startup (ext_linegrid=true)', function() test_embed(true) end) diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 5ffe9ddaad..504a38d591 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -1560,17 +1560,6 @@ describe("MsgSeparator highlight and msgsep fillchar", function() 1 %a "[No Name]" line 1 | {3:Press ENTER or type command to continue}^ | ]]) - - -- when display doesn't contain msgsep, these options have no effect - feed_command("set display-=msgsep") - feed_command("ls") - screen:expect([[ - {1:~ }| - {1:~ }| - :ls | - 1 %a "[No Name]" line 1 | - {3:Press ENTER or type command to continue}^ | - ]]) end) it("and MsgArea", function() diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index d6dfcf2aa9..0898d7fe75 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -1200,28 +1200,6 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim it('prints lines in Ex mode correctly with a burst of carriage returns #19341', function() command('set number') meths.buf_set_lines(0, 0, 0, true, {'aaa', 'bbb', 'ccc'}) - command('set display-=msgsep') - feed('gggQ1vi') - screen:expect([[ - Entering Ex mode. Type "visual" to go to Normal mode. | - {11: 2 }bbb | - {11: 3 }ccc | - :1 | - {11: 1 }aaa | - {11: 2 }bbb | - :vi^ | - ]]) - feed('') - screen:expect([[ - {11: 1 }aaa | - {11: 2 }^bbb | - {11: 3 }ccc | - {11: 4 } | - {1:~ }| - {1:~ }| - | - ]]) - command('set display+=msgsep') feed('gggQ1vi') screen:expect([[ Entering Ex mode. Type "visual" to go to Normal mode. | diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 6c872e52d3..58c8238c35 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -682,30 +682,7 @@ local function screen_tests(linegrid) ]]) end) - it('execute command with multi-line output without msgsep', function() - command("set display-=msgsep") - feed(':ls') - screen:expect([[ - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - :ls | - 1 %a "[No Name]" line 1 | - {7:Press ENTER or type command to continue}^ | - ]]) - feed('') -- skip the "Press ENTER..." state or tests will hang - end) - - it('execute command with multi-line output and with msgsep', function() - command("set display+=msgsep") + it('execute command with multi-line output', function() feed(':ls') screen:expect([[ | @@ -1050,39 +1027,3 @@ describe('Screen default colors', function() end} end) end) - - -describe('screen with msgsep deactivated on startup', function() - local screen - - before_each(function() - clear('--cmd', 'set display-=msgsep') - screen = Screen.new() - screen:attach() - screen:set_default_attr_ids { - [0] = {bold=true, foreground=255}; - [7] = {bold = true, foreground = Screen.colors.SeaGreen}; - } - end) - - it('execute command with multi-line output', function() - feed ':ls' - screen:expect([[ - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - :ls | - 1 %a "[No Name]" line 1 | - {7:Press ENTER or type command to continue}^ | - ]]) - feed '' -- skip the "Press ENTER..." state or tests will hang - end) -end) diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua index 58ffa3bda8..f1e818119e 100644 --- a/test/functional/ui/wildmode_spec.lua +++ b/test/functional/ui/wildmode_spec.lua @@ -184,11 +184,10 @@ describe("'wildmenu'", function() screen:expect_unchanged() end) - it('wildmode=list,full and display+=msgsep interaction #10092', function() + it('wildmode=list,full and messages interaction #10092', function() -- Need more than 5 rows, else tabline is covered and will be redrawn. screen:try_resize(25, 7) - command('set display+=msgsep') command('set wildmenu wildmode=list,full') command('set showtabline=2') feed(':set wildm') @@ -223,44 +222,6 @@ describe("'wildmenu'", function() ]]) end) - it('wildmode=list,full and display-=msgsep interaction', function() - -- Need more than 5 rows, else tabline is covered and will be redrawn. - screen:try_resize(25, 7) - - command('set display-=msgsep') - command('set wildmenu wildmode=list,full') - feed(':set wildm') - screen:expect([[ - ~ | - ~ | - ~ | - ~ | - :set wildm | - wildmenu wildmode | - :set wildm^ | - ]]) - feed('') -- trigger wildmode full - screen:expect([[ - ~ | - ~ | - ~ | - :set wildm | - wildmenu wildmode | - wildmenu wildmode | - :set wildmenu^ | - ]]) - feed('') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - ~ | - ~ | - | - ]]) - end) - it('wildmode=longest,list', function() -- Need more than 5 rows, else tabline is covered and will be redrawn. screen:try_resize(25, 7) @@ -365,7 +326,6 @@ describe("'wildmenu'", function() screen:try_resize(25, 7) command('set laststatus=2') - command('set display+=msgsep') feed(':set wildm') feed('') screen:expect([[ -- cgit From bc64aa435b84bb3a43501e101c51507c75fbd349 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Oct 2022 09:03:49 +0800 Subject: vim-patch:9.0.0665: setting 'cmdheight' has no effect if last window was resized (#20500) Problem: Setting 'cmdheight' has no effect if last window was resized. Solution: Do apply 'cmdheight' when told to. Use the frame height instead of the cmdline_row. (closes vim/vim#11286) https://github.com/vim/vim/commit/0816f473ab2f6cf7d8311c0f97371cada7f20d18 --- test/functional/legacy/cmdline_spec.lua | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 88912b9cd4..e7f5c780dc 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -172,6 +172,47 @@ describe('cmdline', function() | ]]) end) + + it("setting 'cmdheight' works after outputting two messages vim-patch:9.0.0665", function() + local screen = Screen.new(60, 8) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, reverse = true}, -- StatusLine + }) + screen:attach() + exec([[ + set cmdheight=1 laststatus=2 + func EchoTwo() + set laststatus=2 + set cmdheight=5 + echo 'foo' + echo 'bar' + set cmdheight=1 + endfunc + ]]) + feed(':call EchoTwo()') + screen:expect([[ + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {1:[No Name] }| + :call EchoTwo()^ | + ]]) + feed('') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {1:[No Name] }| + | + ]]) + end) end) describe('cmdwin', function() -- cgit From 5acf52e19b1f9920fe95b55588eff256a439d816 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Thu, 6 Oct 2022 08:57:52 +0200 Subject: feat(window/ui): add splitkeep option (#19243) vim-patch:9.0.0445: when opening/closing window text moves up/down Problem: When opening/closing window text moves up/down. Solution: Add the 'splitscroll' option. When off text will keep its position as much as possible. https://github.com/vim/vim/commit/29ab524358ba429bcf6811710afc97a978641f0b vim-patch:9.0.0455: a few problems with 'splitscroll' Problem: A few problems with 'splitscroll'. Solution: Fix 'splitscroll' problems. (Luuk van Baal, closes vim/vim#11117) https://github.com/vim/vim/commit/5ed391708a62b4ebaa84dd23e32a416e5c3383d9 vim-patch:9.0.0461: 'scroll' is not always updated Problem: 'scroll' is not always updated. Solution: Call win_init_size() at the right place. https://github.com/vim/vim/commit/470a14140bc06f1653edf26ab0b3c9b801080353 vim-patch:9.0.0465: cursor moves when cmdwin is closed when 'splitscroll' is off Problem: Cursor moves when cmdwin is closed when 'splitscroll' is off. Solution: Temporarily set 'splitscroll' when jumping back to the original window. (closes vim/vim#11128) https://github.com/vim/vim/commit/e697d488901b6321ddaad68b553f0a434c97d849 vim-patch:9.0.0469: cursor moves if cmdwin is closed when 'splitscroll' is off Problem: Cursor moves if cmdwin is closed when 'splitscroll' is off. Solution: Skip win_fix_cursor if called when cmdwin is open or closing. (Luuk van Baal, closes vim/vim#11134) https://github.com/vim/vim/commit/3735f11050616652525bf80b4fbcb2b3bfeab113 vim-patch:9.0.0478: test for 'splitscroll' takes too much time Problem: Test for 'splitscroll' takes too much time. Solution: Only test some of the combinations. (Luuk van Baal, closes vim/vim#11139) https://github.com/vim/vim/commit/594f9e09cd68e6277b8aa08094405bc642c5792a vim-patch:9.0.0486: text scrolled with 'nosplitscroll', autocmd win and help Problem: Text scrolled with 'nosplitscroll', autocmd win opened and help window closed. Solution: Skip win_fix_scroll() in more situations. (Luuk van Baal, closes vim/vim#11150) https://github.com/vim/vim/commit/d5bc762dea1fd32fa04342f8149f95ccfc3b9709 vim-patch:9.0.0505: various problems with 'nosplitscroll' Problem: Various problems with 'nosplitscroll'. Solution: Fix 'nosplitscroll' problems. (Luuk van Baal, closes vim/vim#11166) https://github.com/vim/vim/commit/faf1d412f5e3665021500b528c0e7301eb02bf0b vim-patch:9.0.0555: scrolling with 'nosplitscroll' in callback changing curwin Problem: Scrolling with 'nosplitscroll' in callback changing curwin. Solution: Invalidate w_cline_row in the right place. (Luuk van Baal, closes vim/vim#11185) https://github.com/vim/vim/commit/20e58561abc4116f3bfbafaef242d886dd77b303 vim-patch:9.0.0603: with 'nosplitscroll' folds are not handled correctly Problem: With 'nosplitscroll' folds are not handled correctly. Solution: Take care of closed folds when moving the cursor. (Luuk van Baal, closes vim/vim#11234) https://github.com/vim/vim/commit/7c1cbb6cd437c6e0c3ccc05840cc931108b4a60a vim-patch:9.0.0605: dump file missing Problem: Dump file missing. Solution: Add the missing dump file. (issue vim/vim#11234) https://github.com/vim/vim/commit/439a2ba1749463718b6ce1e1375b68c7b7cff808 vim-patch:9.0.0647: the 'splitscroll' option is not a good name Problem: The 'splitscroll' option is not a good name. Solution: Rename 'splitscroll' to 'splitkeep' and make it a string option, also supporting "topline". (Luuk van Baal, closes vim/vim#11258) https://github.com/vim/vim/commit/13ece2ae1d09009d3fb8acf858c288e7848ecdac vim-patch:9.0.0667: ml_get error when 'splitkeep' is "screen" Problem: ml_get error when 'splitkeep' is "screen". (Marius Gedminas) Solution: Check the botline is not too large. (Luuk van Baal, closes vim/vim#11293, closes vim/vim#11292) https://github.com/vim/vim/commit/346823d3e5668b99d2c2fd920e7f215e21ad3ea7 --- test/functional/legacy/window_cmd_spec.lua | 196 +++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 test/functional/legacy/window_cmd_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/window_cmd_spec.lua b/test/functional/legacy/window_cmd_spec.lua new file mode 100644 index 0000000000..8b89c55f5b --- /dev/null +++ b/test/functional/legacy/window_cmd_spec.lua @@ -0,0 +1,196 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local exec = helpers.exec +local exec_lua = helpers.exec_lua +local feed = helpers.feed + +describe('splitkeep', function() + local screen = Screen.new() + before_each(function() + clear('--cmd', 'set splitkeep=screen') + screen:attach() + end) + + -- oldtest: Test_splitkeep_callback() + it('does not scroll when split in callback', function() + exec([[ + call setline(1, range(&lines)) + function C1(a, b, c) + split | wincmd p + endfunction + function C2(a, b, c) + close | split + endfunction + ]]) + exec_lua([[ + vim.api.nvim_set_keymap("n", "j", "", { callback = function() + vim.cmd("call jobstart([&sh, &shcf, 'true'], { 'on_exit': 'C1' })") + end + })]]) + exec_lua([[ + vim.api.nvim_set_keymap("n", "t", "", { callback = function() + vim.api.nvim_set_current_win( + vim.api.nvim_open_win(vim.api.nvim_create_buf(false, {}), false, { + width = 10, + relative = "cursor", + height = 4, + row = 0, + col = 0, + })) + vim.cmd("call termopen([&sh, &shcf, 'true'], { 'on_exit': 'C2' })") + end + })]]) + feed('j') + screen:expect([[ + 0 | + 1 | + 2 | + 3 | + 4 | + 5 | + [No Name] [+] | + ^7 | + 8 | + 9 | + 10 | + 11 | + [No Name] [+] | + | + ]]) + feed(':quitHt') + screen:expect([[ + ^0 | + 1 | + 2 | + 3 | + 4 | + 5 | + [No Name] [+] | + 7 | + 8 | + 9 | + 10 | + 11 | + [No Name] [+] | + :quit | + ]]) + feed(':set sb:quitGj') + screen:expect([[ + 1 | + 2 | + 3 | + 4 | + ^5 | + [No Name] [+] | + 7 | + 8 | + 9 | + 10 | + 11 | + 12 | + [No Name] [+] | + :quit | + ]]) + feed(':quitGt') + screen:expect([[ + 1 | + 2 | + 3 | + 4 | + 5 | + [No Name] [+] | + 7 | + 8 | + 9 | + 10 | + 11 | + ^12 | + [No Name] [+] | + :quit | + ]]) + end) + + -- oldtest: Test_splitkeep_fold() + it('does not scroll when window has closed folds', function() + exec([[ + set splitkeep=screen + set foldmethod=marker + set number + let line = 1 + for n in range(1, &lines) + call setline(line, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/', + \ 'after fold']) + let line += 8 + endfor + ]]) + feed('L:wincmd s') + screen:expect([[ + 1 +-- 7 lines: int FuncName() {···················| + 8 after fold | + 9 +-- 7 lines: int FuncName() {···················| + 16 after fold | + 17 +-- 7 lines: int FuncName() {···················| + 24 ^after fold | + [No Name] [+] | + 32 after fold | + 33 +-- 7 lines: int FuncName() {···················| + 40 after fold | + 41 +-- 7 lines: int FuncName() {···················| + 48 after fold | + [No Name] [+] | + :wincmd s | + ]]) + feed(':quit') + screen:expect([[ + 1 +-- 7 lines: int FuncName() {···················| + 8 after fold | + 9 +-- 7 lines: int FuncName() {···················| + 16 after fold | + 17 +-- 7 lines: int FuncName() {···················| + 24 after fold | + 25 +-- 7 lines: int FuncName() {···················| + 32 after fold | + 33 +-- 7 lines: int FuncName() {···················| + 40 after fold | + 41 +-- 7 lines: int FuncName() {···················| + 48 after fold | + 49 ^+-- 7 lines: int FuncName() {···················| + :quit | + ]]) + feed('H:below split') + screen:expect([[ + 1 +-- 7 lines: int FuncName() {···················| + 8 after fold | + 9 +-- 7 lines: int FuncName() {···················| + 16 after fold | + 17 +-- 7 lines: int FuncName() {···················| + [No Name] [+] | + 25 ^+-- 7 lines: int FuncName() {···················| + 32 after fold | + 33 +-- 7 lines: int FuncName() {···················| + 40 after fold | + 41 +-- 7 lines: int FuncName() {···················| + 48 after fold | + [No Name] [+] | + :below split | + ]]) + feed(':wincmd k:quit') + screen:expect([[ + 1 +-- 7 lines: int FuncName() {···················| + 8 after fold | + 9 +-- 7 lines: int FuncName() {···················| + 16 after fold | + 17 +-- 7 lines: int FuncName() {···················| + 24 after fold | + 25 ^+-- 7 lines: int FuncName() {···················| + 32 after fold | + 33 +-- 7 lines: int FuncName() {···················| + 40 after fold | + 41 +-- 7 lines: int FuncName() {···················| + 48 after fold | + 49 +-- 7 lines: int FuncName() {···················| + :quit | + ]]) + end) +end) -- cgit From 25dea99ce54de6a8c4369e28e0db82e1af669f24 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Oct 2022 20:03:59 +0800 Subject: vim-patch:9.0.0670: no space for command line when there is a tabline (#20512) Problem: No space for command line when there is a tabline. Solution: Correct computation of where the command line should be. (closes vim/vim#11295) https://github.com/vim/vim/commit/c9f5f73206272ccad0aa536854debc5f9781978a --- test/functional/legacy/cmdline_spec.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index e7f5c780dc..2fceb6a132 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -5,6 +5,7 @@ local command = helpers.command local feed = helpers.feed local feed_command = helpers.feed_command local exec = helpers.exec +local meths = helpers.meths local pesc = helpers.pesc describe('cmdline', function() @@ -213,6 +214,31 @@ describe('cmdline', function() | ]]) end) + + -- oldtest: Test_cmdheight_tabline() + it("changing 'cmdheight' when there is a tabline", function() + local screen = Screen.new(60, 8) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, reverse = true}, -- StatusLine + [2] = {bold = true}, -- TabLineSel + [3] = {reverse = true}, -- TabLineFill + }) + screen:attach() + meths.set_option('laststatus', 2) + meths.set_option('showtabline', 2) + meths.set_option('cmdheight', 1) + screen:expect([[ + {2: [No Name] }{3: }| + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {1:[No Name] }| + | + ]]) + end) end) describe('cmdwin', function() -- cgit From f7b175e049db9262a45ee1c5eb41a38bd5b8ac38 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 6 Oct 2022 09:16:00 -0400 Subject: fix(docs-html): keycodes, taglinks, column_heading #20498 Problem: - Docs HTML: "foo ~" headings (column_heading) are not aligned with their table columns/contents because the leading whitespace is not emitted. - taglinks starting with hyphen like |-x| were not recognized. - keycodes like `` and `CTRL-x` were not recognized. - ToC is not scrollable. Solution: - Add ws() to the column_heading case. - Update help parser to latest version - supports `keycode` - fixes for taglink, argument - Update .toc CSS. https://github.com/neovim/neovim.github.io/issues/297 fix https://github.com/neovim/neovim.github.io/issues/297 --- test/functional/lua/help_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua index 6743648819..251275b5cc 100644 --- a/test/functional/lua/help_spec.lua +++ b/test/functional/lua/help_spec.lua @@ -21,7 +21,7 @@ describe(':help docs', function() ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles) -- Check that parse errors did not increase wildly. -- TODO: Fix all parse errors in :help files. - ok(rv.err_count < 280, '<280 parse errors', rv.err_count) + ok(rv.err_count < 150, '<150 parse errors', rv.err_count) eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) @@ -43,7 +43,7 @@ describe(':help docs', function() tmpdir ) eq(4, #rv.helpfiles) - ok(rv.err_count <= 6, '<=6 parse errors', rv.err_count) + ok(rv.err_count <= 1, '<=1 parse errors', rv.err_count) eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) end) -- cgit From d191070913dc195309926a91f97008defd877a71 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 7 Oct 2022 08:52:51 +0800 Subject: fix(ui): setting 'cmdheight' with global statusline (#20515) --- test/functional/ui/statusline_spec.lua | 101 +++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua index add5144e1b..18391a575d 100644 --- a/test/functional/ui/statusline_spec.lua +++ b/test/functional/ui/statusline_spec.lua @@ -178,6 +178,7 @@ describe('global statusline', function() [2] = {bold = true, reverse = true}; [3] = {bold = true}; [4] = {reverse = true}; + [5] = {bold = true, foreground = Screen.colors.Fuchsia}; }) command('set laststatus=3') command('set ruler') @@ -398,6 +399,106 @@ describe('global statusline', function() meths.input_mouse('left', 'drag', '', 0, 14, 10) eq(1, meths.get_option('cmdheight')) end) + + it('cmdline row is correct after setting cmdheight #20514', function() + command('botright split test/functional/fixtures/bigfile.txt') + meths.set_option('cmdheight', 1) + feed('L') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ────────────────────────────────────────────────────────────| + 0000;;Cc;0;BN;;;;;N;NULL;;;; | + 0001;;Cc;0;BN;;;;;N;START OF HEADING;;;; | + 0002;;Cc;0;BN;;;;;N;START OF TEXT;;;; | + 0003;;Cc;0;BN;;;;;N;END OF TEXT;;;; | + 0004;;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;; | + 0005;;Cc;0;BN;;;;;N;ENQUIRY;;;; | + ^0006;;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; | + {2:test/functional/fixtures/bigfile.txt 7,1 Top}| + | + ]]) + feed('j') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ────────────────────────────────────────────────────────────| + 0001;;Cc;0;BN;;;;;N;START OF HEADING;;;; | + 0002;;Cc;0;BN;;;;;N;START OF TEXT;;;; | + 0003;;Cc;0;BN;;;;;N;END OF TEXT;;;; | + 0004;;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;; | + 0005;;Cc;0;BN;;;;;N;ENQUIRY;;;; | + 0006;;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; | + ^0007;;Cc;0;BN;;;;;N;BELL;;;; | + {2:test/functional/fixtures/bigfile.txt 8,1 0%}| + | + ]]) + meths.set_option('showtabline', 2) + screen:expect([[ + {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ────────────────────────────────────────────────────────────| + 0002;;Cc;0;BN;;;;;N;START OF TEXT;;;; | + 0003;;Cc;0;BN;;;;;N;END OF TEXT;;;; | + 0004;;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;; | + 0005;;Cc;0;BN;;;;;N;ENQUIRY;;;; | + 0006;;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; | + ^0007;;Cc;0;BN;;;;;N;BELL;;;; | + {2:test/functional/fixtures/bigfile.txt 8,1 0%}| + | + ]]) + meths.set_option('cmdheight', 0) + screen:expect([[ + {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ────────────────────────────────────────────────────────────| + 0001;;Cc;0;BN;;;;;N;START OF HEADING;;;; | + 0002;;Cc;0;BN;;;;;N;START OF TEXT;;;; | + 0003;;Cc;0;BN;;;;;N;END OF TEXT;;;; | + 0004;;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;; | + 0005;;Cc;0;BN;;;;;N;ENQUIRY;;;; | + 0006;;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; | + ^0007;;Cc;0;BN;;;;;N;BELL;;;; | + {2:test/functional/fixtures/bigfile.txt 8,1 0%}| + ]]) + meths.set_option('cmdheight', 1) + screen:expect([[ + {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ────────────────────────────────────────────────────────────| + 0002;;Cc;0;BN;;;;;N;START OF TEXT;;;; | + 0003;;Cc;0;BN;;;;;N;END OF TEXT;;;; | + 0004;;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;; | + 0005;;Cc;0;BN;;;;;N;ENQUIRY;;;; | + 0006;;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; | + ^0007;;Cc;0;BN;;;;;N;BELL;;;; | + {2:test/functional/fixtures/bigfile.txt 8,1 0%}| + | + ]]) + end) end) it('statusline does not crash if it has Arabic characters #19447', function() -- cgit From cfdb4cbada8c65aa57e69776bcc0f7b8b298317a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 7 Oct 2022 09:43:16 +0800 Subject: fix: find multibyte file name in line (#20519) And remove unnecessary unsigned casts in fold marker comparison. --- test/functional/core/path_spec.lua | 14 ++++++++++++++ .../filename_with_unicode_\316\261\316\261\316\261" | 0 2 files changed, 14 insertions(+) create mode 100644 "test/functional/fixtures/filename_with_unicode_\316\261\316\261\316\261" (limited to 'test/functional') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 669bc99136..61fae7622c 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -4,6 +4,8 @@ local eq = helpers.eq local eval = helpers.eval local command = helpers.command local iswin = helpers.iswin +local insert = helpers.insert +local feed = helpers.feed describe('path collapse', function() local targetdir @@ -54,3 +56,15 @@ describe('path collapse', function() eq(expected_path, eval('expand("%:p")')) end) end) + +describe('file search', function() + before_each(clear) + + it('find multibyte file name in line #20517', function() + command('cd test/functional/fixtures') + insert('filename_with_unicode_ααα') + eq('', eval('expand("%")')) + feed('gf') + eq('filename_with_unicode_ααα', eval('expand("%:t")')) + end) +end) diff --git "a/test/functional/fixtures/filename_with_unicode_\316\261\316\261\316\261" "b/test/functional/fixtures/filename_with_unicode_\316\261\316\261\316\261" new file mode 100644 index 0000000000..e69de29bb2 -- cgit From 0773a9ee3a21db54cd6b2376dd2e087bc09d5ea1 Mon Sep 17 00:00:00 2001 From: lvimuser <109605931+lvimuser@users.noreply.github.com> Date: Sat, 8 Oct 2022 05:22:25 -0300 Subject: feat(lsp): support window/showDocument (#19977) --- test/functional/plugin/lsp_spec.lua | 162 +++++++++++++++++++++++++++++++++++- 1 file changed, 161 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index bcae9b4084..425427be54 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2586,7 +2586,7 @@ describe('LSP', function() local mark = funcs.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - funcs.nvim_win_set_cursor(0, {2, 3}) + funcs.nvim_win_set_cursor(0, { 2, 3 }) jump(location(0, 9, 0, 9)) mark = funcs.nvim_buf_get_mark(target_bufnr, "'") @@ -2594,6 +2594,166 @@ describe('LSP', function() end) end) + describe('lsp.util.show_document', function() + local target_bufnr + local target_bufnr2 + + before_each(function() + target_bufnr = exec_lua([[ + local bufnr = vim.uri_to_bufnr("file:///fake/uri") + local lines = {"1st line of text", "å å ɧ 汉语 ↥ 🤦 🦄"} + vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines) + return bufnr + ]]) + + target_bufnr2 = exec_lua([[ + local bufnr = vim.uri_to_bufnr("file:///fake/uri2") + local lines = {"1st line of text", "å å ɧ 汉语 ↥ 🤦 🦄"} + vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines) + return bufnr + ]]) + end) + + local location = function(start_line, start_char, end_line, end_char, second_uri) + return { + uri = second_uri and 'file:///fake/uri2' or 'file:///fake/uri', + range = { + start = { line = start_line, character = start_char }, + ['end'] = { line = end_line, character = end_char }, + }, + } + end + + local show_document = function(msg, focus, reuse_win) + eq( + true, + exec_lua( + 'return vim.lsp.util.show_document(...)', + msg, + 'utf-16', + { reuse_win = reuse_win, focus = focus } + ) + ) + if focus == true or focus == nil then + eq(target_bufnr, exec_lua([[return vim.fn.bufnr('%')]])) + end + return { + line = exec_lua([[return vim.fn.line('.')]]), + col = exec_lua([[return vim.fn.col('.')]]), + } + end + + it('jumps to a Location if focus is true', function() + local pos = show_document(location(0, 9, 0, 9), true, true) + eq(1, pos.line) + eq(10, pos.col) + end) + + it('jumps to a Location if focus not set', function() + local pos = show_document(location(0, 9, 0, 9), nil, true) + eq(1, pos.line) + eq(10, pos.col) + end) + + it('does not add current position to jumplist if not focus', function() + funcs.nvim_win_set_buf(0, target_bufnr) + local mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + eq({ 1, 0 }, mark) + + funcs.nvim_win_set_cursor(0, { 2, 3 }) + show_document(location(0, 9, 0, 9), false, true) + show_document(location(0, 9, 0, 9, true), false, true) + + mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + eq({ 1, 0 }, mark) + end) + + it('does not change cursor position if not focus and not reuse_win', function() + funcs.nvim_win_set_buf(0, target_bufnr) + local cursor = funcs.nvim_win_get_cursor(0) + + show_document(location(0, 9, 0, 9), false, false) + eq(cursor, funcs.nvim_win_get_cursor(0)) + end) + + it('does not change window if not focus', function() + funcs.nvim_win_set_buf(0, target_bufnr) + local win = funcs.nvim_get_current_win() + + -- same document/bufnr + show_document(location(0, 9, 0, 9), false, true) + eq(win, funcs.nvim_get_current_win()) + + -- different document/bufnr, new window/split + show_document(location(0, 9, 0, 9, true), false, true) + eq(2, #funcs.nvim_list_wins()) + eq(win, funcs.nvim_get_current_win()) + end) + + it("respects 'reuse_win' parameter", function() + funcs.nvim_win_set_buf(0, target_bufnr) + + -- does not create a new window if the buffer is already open + show_document(location(0, 9, 0, 9), false, true) + eq(1, #funcs.nvim_list_wins()) + + -- creates a new window even if the buffer is already open + show_document(location(0, 9, 0, 9), false, false) + eq(2, #funcs.nvim_list_wins()) + end) + + it('correctly sets the cursor of the split if range is given without focus', function() + funcs.nvim_win_set_buf(0, target_bufnr) + + show_document(location(0, 9, 0, 9, true), false, true) + + local wins = funcs.nvim_list_wins() + eq(2, #wins) + table.sort(wins) + + eq({ 1, 0 }, funcs.nvim_win_get_cursor(wins[1])) + eq({ 1, 9 }, funcs.nvim_win_get_cursor(wins[2])) + end) + + it('does not change cursor of the split if not range and not focus', function() + funcs.nvim_win_set_buf(0, target_bufnr) + funcs.nvim_win_set_cursor(0, { 2, 3 }) + + exec_lua([[vim.cmd.new()]]) + funcs.nvim_win_set_buf(0, target_bufnr2) + funcs.nvim_win_set_cursor(0, { 2, 3 }) + + show_document({ uri = 'file:///fake/uri2' }, false, true) + + local wins = funcs.nvim_list_wins() + eq(2, #wins) + eq({ 2, 3 }, funcs.nvim_win_get_cursor(wins[1])) + eq({ 2, 3 }, funcs.nvim_win_get_cursor(wins[2])) + end) + + it('respects existing buffers', function() + funcs.nvim_win_set_buf(0, target_bufnr) + local win = funcs.nvim_get_current_win() + + exec_lua([[vim.cmd.new()]]) + funcs.nvim_win_set_buf(0, target_bufnr2) + funcs.nvim_win_set_cursor(0, { 2, 3 }) + local split = funcs.nvim_get_current_win() + + -- reuse win for open document/bufnr if called from split + show_document(location(0, 9, 0, 9, true), false, true) + eq({ 1, 9 }, funcs.nvim_win_get_cursor(split)) + eq(2, #funcs.nvim_list_wins()) + + funcs.nvim_set_current_win(win) + + -- reuse win for open document/bufnr if called outside the split + show_document(location(0, 9, 0, 9, true), false, true) + eq({ 1, 9 }, funcs.nvim_win_get_cursor(split)) + eq(2, #funcs.nvim_list_wins()) + end) + end) + describe('lsp.util._make_floating_popup_size', function() before_each(function() exec_lua [[ contents = -- cgit From 2a12faaec18115bf057427834832ff20ccb3ffd4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 8 Oct 2022 20:10:00 +0800 Subject: fix(api): dynamically allocate line buffer for nvim_out_write (#20537) --- test/functional/api/vim_spec.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 0b2b371046..909ff80837 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1905,11 +1905,32 @@ describe('API', function() end) end) + describe('nvim_out_write', function() + it('prints long messages correctly #20534', function() + exec([[ + set more + redir => g:out + silent! call nvim_out_write('a') + silent! call nvim_out_write('a') + silent! call nvim_out_write('a') + silent! call nvim_out_write("\n") + silent! call nvim_out_write('a') + silent! call nvim_out_write('a') + silent! call nvim_out_write(repeat('a', 5000) .. "\n") + silent! call nvim_out_write('a') + silent! call nvim_out_write('a') + silent! call nvim_out_write('a') + silent! call nvim_out_write("\n") + redir END + ]]) + eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out')) + end) + end) + describe('nvim_err_write', function() local screen before_each(function() - clear() screen = Screen.new(40, 8) screen:attach() screen:set_default_attr_ids({ -- cgit From 7cdaa74b3684d40a6e72bbf3eb4deedb0c5df7bc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 9 Oct 2022 18:57:22 +0800 Subject: vim-patch:9.0.0702: incomplete testing cursor position with 'linebreak' set Problem: Incomplete testing cursor position after change with 'linebreak' set. Solution: Add a test and move test cases together. (closes vim/vim#11313) https://github.com/vim/vim/commit/30c0c467d6cc2a7af960ccb9002b50115b0e55cf --- test/functional/legacy/listlbr_spec.lua | 96 ++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/legacy/listlbr_spec.lua b/test/functional/legacy/listlbr_spec.lua index f70d55f4a3..d4f11a61c2 100644 --- a/test/functional/legacy/listlbr_spec.lua +++ b/test/functional/legacy/listlbr_spec.lua @@ -1,11 +1,12 @@ -- Test for linebreak and list option (non-utf8) local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local feed, insert, source = helpers.feed, helpers.insert, helpers.source local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect describe('listlbr', function() - setup(clear) + before_each(clear) -- luacheck: ignore 621 (Indentation) -- luacheck: ignore 611 (Line contains only whitespaces) @@ -195,4 +196,97 @@ describe('listlbr', function() aa>-----a-$ ~ ]]) end) + + -- oldtest: Test_linebreak_reset_restore() + it('cursor position is drawn correctly after operator', function() + local screen = Screen.new(60, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.LightGrey}, -- Visual + [2] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg + }) + screen:attach() + + -- f_wincol() calls validate_cursor() + source([[ + set linebreak showcmd noshowmode formatexpr=wincol()-wincol() + call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c') + ]]) + + feed('$v$') + screen:expect([[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbb {1:c}^ | + {0:~ }| + {0:~ }| + {0:~ }| + 2 | + ]]) + feed('zo') + screen:expect([[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbb ^c | + {0:~ }| + {0:~ }| + {0:~ }| + {2:E490: No fold found} | + ]]) + + feed('$v$') + screen:expect([[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbb {1:c}^ | + {0:~ }| + {0:~ }| + {0:~ }| + {2:E490: No fold found} 2 | + ]]) + feed('gq') + screen:expect([[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbb ^c | + {0:~ }| + {0:~ }| + {0:~ }| + {2:E490: No fold found} | + ]]) + + feed('$$') + screen:expect([[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbb {1:c}^ | + {0:~ }| + {0:~ }| + {0:~ }| + {2:E490: No fold found} 1x2 | + ]]) + feed('I') + screen:expect([[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbb ^c | + {0:~ }| + {0:~ }| + {0:~ }| + {2:E490: No fold found} | + ]]) + + feed('$v$') + screen:expect([[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbb {1:c}^ | + {0:~ }| + {0:~ }| + {0:~ }| + {2:E490: No fold found} 2 | + ]]) + feed('s') + screen:expect([[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | + bbbbbbbbbb ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {2:E490: No fold found} | + ]]) + end) end) -- cgit From 09dffb9db7d16496e55e86f78ab60241533d86f6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 9 Oct 2022 08:21:52 -0400 Subject: docs: various #12823 - increase python line-length limit from 88 => 100. - gen_help_html: fix bug in "tag" case (tbl_count => tbl_contains) ref #15632 fix #18215 fix #18479 fix #20527 fix #20532 Co-authored-by: Ben Weedon --- test/functional/api/vim_spec.lua | 2 +- test/functional/helpers.lua | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 909ff80837..af6cee7e90 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2277,7 +2277,7 @@ describe('API', function() eq({'a', '', 'b'}, meths.list_runtime_paths()) meths.set_option('runtimepath', ',a,b') eq({'', 'a', 'b'}, meths.list_runtime_paths()) - -- trailing , is ignored, use ,, if you really really want $CWD + -- Trailing "," is ignored. Use ",," if you really really want CWD. meths.set_option('runtimepath', 'a,b,') eq({'a', 'b'}, meths.list_runtime_paths()) meths.set_option('runtimepath', 'a,b,,') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 4fcc190dee..723d2ccfa4 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -275,7 +275,6 @@ function module.command(cmd) module.request('nvim_command', cmd) end - -- Use for commands which expect nvim to quit. -- The first argument can also be a timeout. function module.expect_exit(fn_or_timeout, ...) -- cgit From a5597d1fc066a8512ce9434dbff70850dc7bd5a1 Mon Sep 17 00:00:00 2001 From: RZia <36330543+grassdne@users.noreply.github.com> Date: Sun, 9 Oct 2022 20:04:08 -0400 Subject: fix(lua): assert failure with vim.regex() error inside :silent! (#20555) Co-authored-by: zeertzjq --- test/functional/lua/vim_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 6451453ce0..47a0004183 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -24,6 +24,7 @@ local rmdir = helpers.rmdir local write_file = helpers.write_file local expect_exit = helpers.expect_exit local poke_eventloop = helpers.poke_eventloop +local assert_alive = helpers.assert_alive describe('lua stdlib', function() before_each(clear) @@ -2210,6 +2211,10 @@ describe('lua stdlib', function() eq({3,7}, exec_lua[[return {re1:match_line(0, 1, 1, 8)}]]) eq({}, exec_lua[[return {re1:match_line(0, 1, 1, 7)}]]) eq({0,3}, exec_lua[[return {re1:match_line(0, 1, 0, 7)}]]) + + -- vim.regex() error inside :silent! should not crash. #20546 + command([[silent! lua vim.regex('\\z')]]) + assert_alive() end) it('vim.defer_fn', function() -- cgit From 9115f665559777d1016af20f094c51e0eeff444c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 12 Oct 2022 11:35:47 +0800 Subject: test: add a test for #20605 --- test/functional/ui/screen_basic_spec.lua | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 58c8238c35..f111aa2513 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -1027,3 +1027,36 @@ describe('Screen default colors', function() end} end) end) + +it('CTRL-F or CTRL-B scrolls a page after UI attach/resize #20605', function() + clear() + local screen = Screen.new(100, 100) + screen:attach() + eq(100, meths.get_option('lines')) + eq(99, meths.get_option('window')) + eq(99, meths.win_get_height(0)) + feed('1000o') + eq(903, funcs.line('w0')) + feed('') + eq(806, funcs.line('w0')) + feed('') + eq(709, funcs.line('w0')) + feed('') + eq(806, funcs.line('w0')) + feed('') + eq(903, funcs.line('w0')) + feed('G') + screen:try_resize(50, 50) + eq(50, meths.get_option('lines')) + eq(49, meths.get_option('window')) + eq(49, meths.win_get_height(0)) + eq(953, funcs.line('w0')) + feed('') + eq(906, funcs.line('w0')) + feed('') + eq(859, funcs.line('w0')) + feed('') + eq(906, funcs.line('w0')) + feed('') + eq(953, funcs.line('w0')) +end) -- cgit From d339b4aad7461937e1e03ac0836b2eb1354ff442 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 13 Oct 2022 21:36:25 -0400 Subject: build(deps): bump vimdoc (help) parser to v1.2.1 #20642 --- test/functional/lua/help_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua index 251275b5cc..242897336d 100644 --- a/test/functional/lua/help_spec.lua +++ b/test/functional/lua/help_spec.lua @@ -21,7 +21,7 @@ describe(':help docs', function() ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles) -- Check that parse errors did not increase wildly. -- TODO: Fix all parse errors in :help files. - ok(rv.err_count < 150, '<150 parse errors', rv.err_count) + ok(rv.err_count < 100, '<100 parse errors', rv.err_count) eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) @@ -43,7 +43,7 @@ describe(':help docs', function() tmpdir ) eq(4, #rv.helpfiles) - ok(rv.err_count <= 1, '<=1 parse errors', rv.err_count) + ok(rv.err_count == 0, '0 parse errors', rv.err_count) eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) end) end) -- cgit From 81986a7349da7b88abde459194078e9893e8ae8b Mon Sep 17 00:00:00 2001 From: Daniel Zhang Date: Fri, 14 Oct 2022 17:12:46 +0800 Subject: fix(lua): on_yank error with blockwise multibyte region #20162 Prevent out of range error when calling `str_byteindex`. Use `vim.str_byteindex(bufline, #bufline)` to cacluate utf length of `bufline`. fix #20161 --- test/functional/lua/vim_spec.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 47a0004183..f250a3ec93 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2227,13 +2227,19 @@ describe('lua stdlib', function() eq(true, exec_lua[[return vim.g.test]]) end) - it('vim.region', function() - insert(helpers.dedent( [[ - text tααt tααt text - text tαxt txtα tex - text tαxt tαxt - ]])) - eq({5,15}, exec_lua[[ return vim.region(0,{1,5},{1,14},'v',true)[1] ]]) + describe('vim.region', function() + it('charwise', function() + insert(helpers.dedent( [[ + text tααt tααt text + text tαxt txtα tex + text tαxt tαxt + ]])) + eq({5,15}, exec_lua[[ return vim.region(0,{1,5},{1,14},'v',true)[1] ]]) + end) + it('blockwise', function() + insert([[αα]]) + eq({0,5}, exec_lua[[ return vim.region(0,{0,0},{0,4},'3',true)[0] ]]) + end) end) describe('vim.on_key', function() -- cgit From 546b294e74ac10d0a5e1216dd530fc96bdc66f29 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 14 Oct 2022 11:49:57 +0100 Subject: fix(decoration): redraw correctly when re-using ids 00cfc1d (from #20249) reduced the amount of unnecessary redraws. This surfaced an issue where if and extmark with a specific ID is repositioned to a different row, the decorations from the old row were not redrawn and removed. This change fixes that by redrawing the old row. --- test/functional/ui/decorations_spec.lua | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 0a5eefbf38..9448674a41 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -2085,4 +2085,39 @@ describe('decorations: virt_text', function() ]]} end) + it('redraws correctly when re-using extmark ids', function() + command 'normal 5ohello' + + screen:expect{grid=[[ + | + hello | + hello | + hello | + hello | + hell^o | + {3:~ }| + {3:~ }| + {3:~ }| + | + ]]} + + local ns = meths.create_namespace('ns') + for row = 1, 5 do + meths.buf_set_extmark(0, ns, row, 0, { id = 1, virt_text = {{'world', 'Normal'}} }) + end + + screen:expect{grid=[[ + | + hello | + hello | + hello | + hello | + hell^o world | + {3:~ }| + {3:~ }| + {3:~ }| + | + ]]} + end) + end) -- cgit From e6f7e038b8bbca487e78ebfc6fe21d6852330623 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Oct 2022 23:08:00 +0800 Subject: fix(completion): set pum_size even if ext_popupmenu is used (#20648) This allows CompleteChanged event to get the correct `v:event.size`. It should be harmless and more consistent to also set `pum_array`. --- test/functional/editor/completion_spec.lua | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test/functional') diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 6cdac3c079..1b9899174b 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -1128,6 +1128,49 @@ describe('completion', function() call cursor(4, 1) ]]) + -- v:event.size should be set with ext_popupmenu #20646 + screen:set_option('ext_popupmenu', true) + feed('Sf') + screen:expect({grid = [[ + foo | + bar | + foobar | + f^ | + {0:~ }| + {0:~ }| + {0:~ }| + {3:-- Keyword completion (^N^P) }{5:Back at original} | + ]], popupmenu = { + anchor = { 1, 3, 0 }, + items = { { "foo", "", "", "" }, { "foobar", "", "", "" } }, + pos = -1 + }}) + eq({completed_item = {}, width = 0, + height = 2, size = 2, + col = 0, row = 4, scrollbar = false}, + eval('g:event')) + feed('oob') + screen:expect({grid = [[ + foo | + bar | + foobar | + foob^ | + {0:~ }| + {0:~ }| + {0:~ }| + {3:-- Keyword completion (^N^P) }{5:Back at original} | + ]], popupmenu = { + anchor = { 1, 3, 0 }, + items = { { "foobar", "", "", "" } }, + pos = -1 + }}) + eq({completed_item = {}, width = 0, + height = 1, size = 1, + col = 0, row = 4, scrollbar = false}, + eval('g:event')) + feed('') + screen:set_option('ext_popupmenu', false) + feed('Sf') screen:expect([[ foo | -- cgit From 6bc2d6b66b683faedded01128af8ad98b7130fef Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Oct 2022 16:10:56 +0800 Subject: vim-patch:9.0.0614: SpellFileMissing autocmd may delete buffer Problem: SpellFileMissing autocmd may delete buffer. Solution: Disallow deleting the current buffer to avoid using freed memory. https://github.com/vim/vim/commit/ef976323e770315b5fca544efb6b2faa25674d15 --- test/functional/autocmd/termxx_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index 859c2ebf44..a38f9cb0ac 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -5,6 +5,7 @@ local clear, command, nvim, testprg = helpers.clear, helpers.command, helpers.nvim, helpers.testprg local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry +local matches = helpers.matches local ok = helpers.ok local feed = helpers.feed local pcall_err = helpers.pcall_err @@ -22,7 +23,8 @@ describe('autocmd TermClose', function() local function test_termclose_delete_own_buf() command('autocmd TermClose * bdelete!') command('terminal') - eq('Vim(bdelete):E937: Attempt to delete a buffer that is in use', pcall_err(command, 'bdelete!')) + matches('^Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://', + pcall_err(command, 'bdelete!')) assert_alive() end -- cgit From 2921de6a964e68bb0c9591c14b8550aee2e337da Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 15 Oct 2022 10:53:30 +0100 Subject: fix(decoration): call providers in win_update() earlier Fixes #20651 --- test/functional/ui/decorations_spec.lua | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 9448674a41..e9072ebf98 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -564,6 +564,7 @@ describe('extmark decorations', function() [24] = {bold = true}; [25] = {background = Screen.colors.LightRed}; [26] = {background=Screen.colors.DarkGrey, foreground=Screen.colors.LightGrey}; + [27] = {background = Screen.colors.Plum1}; } ns = meths.create_namespace 'test' @@ -959,6 +960,55 @@ end]] | ]]) end) + + it('avoids redraw issue #20651', function() + exec_lua[[ + vim.cmd.normal'10oXXX' + vim.cmd.normal'gg' + local ns = vim.api.nvim_create_namespace('ns') + + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_open_win(bufnr, false, { relative = 'win', height = 1, width = 1, row = 0, col = 0 }) + + vim.api.nvim_create_autocmd('CursorMoved', { callback = function() + local row = vim.api.nvim_win_get_cursor(0)[1] - 1 + vim.api.nvim_buf_set_extmark(0, ns, row, 0, { id = 1 }) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, {}) + vim.schedule(function() + vim.api.nvim_buf_set_extmark(0, ns, row, 0, { + id = 1, + virt_text = {{'HELLO', 'Normal'}}, + }) + end) + end + }) + ]] + + for _ = 1, 3 do + helpers.sleep(10) + feed 'j' + end + + screen:expect{grid=[[ + {27: } | + XXX | + XXX | + ^XXX HELLO | + XXX | + XXX | + XXX | + XXX | + XXX | + XXX | + XXX | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + end) + end) describe('decorations: virtual lines', function() -- cgit From 935e1ca743abb4fce1effef063e5645f3df88119 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Sun, 16 Oct 2022 15:55:18 -0600 Subject: feat: mention ":help news" in intro #20674 --- test/functional/ui/messages_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 0898d7fe75..8ab25d0102 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -1263,7 +1263,6 @@ describe('ui/ext_messages', function() {1:~ }| {1:~ }| {1:~ }| - {1:~ }| {MATCH:.*}| {1:~ }| {1:~ }Nvim is open source and freely distributable{1: }| @@ -1274,6 +1273,8 @@ describe('ui/ext_messages', function() {1:~ }type :q{5:} to exit {1: }| {1:~ }type :help{5:} for help {1: }| {1:~ }| + {1:~ }type :help news{5:} to see changes in v{MATCH:.*}| + {1:~ }| {MATCH:.*}| {MATCH:.*}| {1:~ }| @@ -1281,7 +1282,6 @@ describe('ui/ext_messages', function() {1:~ }| {1:~ }| {1:~ }| - {1:~ }| ]]) feed("") @@ -1319,7 +1319,6 @@ describe('ui/ext_messages', function() | | | - | {MATCH:.*}| | Nvim is open source and freely distributable | @@ -1330,6 +1329,8 @@ describe('ui/ext_messages', function() type :q{5:} to exit | type :help{5:} for help | | + type :help news{5:} to see changes in {MATCH:.*}| + | {MATCH:.*}| {MATCH:.*}| | @@ -1337,7 +1338,6 @@ describe('ui/ext_messages', function() | | | - | ]], messages={ {content = { { "Press ENTER or type command to continue", 4 } }, kind = "return_prompt" } }} -- cgit From 9701c9dc9f157c4d09d1783aab9913d05b0d73b1 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 17 Oct 2022 08:19:48 +0200 Subject: vim-patch:3c053a1a5ad2 (#20679) Update runtime files https://github.com/vim/vim/commit/3c053a1a5ad2a3c924929e11f2b9af20a8b901e2 --- test/functional/plugin/health_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index ba66117fb1..e5a60f5cb1 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -227,7 +227,7 @@ describe('health.vim', function() | {Heading:success1: health#success1#check} | {Bar:========================================================================}| - {Heading2:##}{Heading: report 1} | + {Heading2:## }{Heading:report 1} | {Bullet: -} {Ok:OK}: everything is fine | | ]]} -- cgit From 39911d76be560c998cc7dee51c5d94f811164f66 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Mon, 17 Oct 2022 04:37:44 -0500 Subject: fix(man): handle absolute paths as `:Man` targets (#20624) * fix(man): handle absolute paths as :Man targets Previously, attempting to provide `:Man` with an absolute path as the name would cause neovim to return the following error: ``` Error detected while processing command line: /usr/local/share/nvim/runtime/lua/man.lua:690: /usr/local/share/nvim/runtime/lua/man.lua:683: Vim:E426: tag not found: nil(nil) Press ENTER or type command to continue ``` ..because it would try to validate the existence of a man page for the provided name by executing `man -w /some/path` which (on at least some Linux machines [0]) returns `/some/path` instead of the path to the nroff files that would be formatted to satisfy the man(1) lookup. While man pages are not normally named after absolute paths, users shouldn't be blamed for trying. Given such a name/path, neovim would **not** complain that the path didn't have a corresponding man file but would error out when trying to call the tag function for the null-propagated name-and-section `nil(nil)`. (The same underlying error existed before this function was ported to lua, but did not exhibit the lua-specific `nil(nil)` name; instead a tag lookup for `()` would fail and error out.) With this patch, we detect the case where `man -w ...` returns the same value as the provided name to not only prevent invoking the tag function for a non-existent/malformed name+sect but also to properly report the non-existence of a man page for the provided lookup (the absolute path). While man(1) can be used to directly read an nroff-formatted document via `man /path/to/nroff.doc`, `:Man /path/to/nroff.doc` never supported this behavior so no functionality is lost in case the provided path _was_ an nroff file. [0]: `man -w /absolute/path` returning `/absolute/path` observed on an Ubuntu 18.04 installation. * test: add regression test for #20624 Add a functional test to `man_spec.lua` to check for a regression for #20624 by first obtaining an absolute path to a random file and materializing it to disk, then attempting to query `:Man` for an entry by that same name/path. The test passes if nvim correctly reports that there is no man page correspending to the provided name/path and fails if any other error (or no error) is shown. --- test/functional/plugin/man_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 3e63c5df9a..203424c855 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -6,6 +6,8 @@ local exec_lua = helpers.exec_lua local funcs = helpers.funcs local nvim_prog = helpers.nvim_prog local matches = helpers.matches +local write_file = helpers.write_file +local tmpname = helpers.tmpname clear() if funcs.executable('man') == 0 then @@ -156,4 +158,16 @@ describe(':Man', function() local args = {nvim_prog, '--headless', '+autocmd VimLeave * echo "quit works!!"', '+Man!', '+call nvim_input("q")'} matches('quit works!!', funcs.system(args, {'manpage contents'})) end) + + it('reports non-existent man pages for absolute paths', function() + local actual_file = tmpname() + -- actual_file must be an absolute path to an existent file for us to test against it + matches('^/.+', actual_file) + write_file(actual_file, '') + local args = {nvim_prog, '--headless', '+:Man ' .. actual_file, '+q'} + matches(('Error detected while processing command line:\r\n' .. + 'man.lua: "no manual entry for %s"'):format(actual_file), + funcs.system(args, {''})) + os.remove(actual_file) + end) end) -- cgit From 637ab296cba9e37e7374a8c076342487398605ee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Oct 2022 21:00:50 +0800 Subject: feat(api): nvim_select_popupmenu_item support cmdline pum (#20652) --- test/functional/ui/popupmenu_spec.lua | 409 ++++++++++++++++++++++++---------- 1 file changed, 287 insertions(+), 122 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 3c752875f0..33e201eb68 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -259,174 +259,339 @@ describe('ui/ext_popupmenu', function() {2:-- INSERT --} | ]]) - command('imap call nvim_select_popupmenu_item(2,v:true,v:false,{})') - command('imap call nvim_select_popupmenu_item(-1,v:false,v:false,{})') - command('imap call nvim_select_popupmenu_item(1,v:false,v:true,{})') - feed('=TestComplete()') - screen:expect{grid=[[ + command('set wildmenu') + command('set wildoptions=pum') + local expected_wildpum = { + { "define", "", "", "" }, + { "jump", "", "", "" }, + { "list", "", "", "" }, + { "place", "", "", "" }, + { "undefine", "", "", "" }, + { "unplace", "", "", "" }, + } + feed(':sign ') + screen:expect({grid = [[ + | | - foo^ | {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| - {2:-- INSERT --} | - ]], popupmenu={ - items=expected, - pos=0, - anchor={1,1,0}, - }} + :sign define^ | + ]], popupmenu = { + items = expected_wildpum, + pos = 0, + anchor = { 1, 7, 6 }, + }}) - feed('') - screen:expect{grid=[[ + meths.select_popupmenu_item(-1, true, false, {}) + screen:expect({grid = [[ + | | - spam^ | {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| - {2:-- INSERT --} | - ]], popupmenu={ - items=expected, - pos=2, - anchor={1,1,0}, - }} + :sign ^ | + ]], popupmenu = { + items = expected_wildpum, + pos = -1, + anchor = { 1, 7, 6 }, + }}) - feed('') - screen:expect{grid=[[ + meths.select_popupmenu_item(5, true, false, {}) + screen:expect({grid = [[ + | | - spam^ | {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| - {2:-- INSERT --} | - ]], popupmenu={ - items=expected, - pos=-1, - anchor={1,1,0}, - }} + :sign unplace^ | + ]], popupmenu = { + items = expected_wildpum, + pos = 5, + anchor = { 1, 7, 6 }, + }}) - feed('') - screen:expect([[ + meths.select_popupmenu_item(-1, true, true, {}) + screen:expect({grid = [[ + | | - bar^ | {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| - {2:-- INSERT --} | - ]]) + :sign ^ | + ]]}) - -- also should work for builtin popupmenu - screen:set_option('ext_popupmenu', false) - feed('=TestComplete()') - screen:expect([[ + feed('') + screen:expect({grid = [[ | - foo^ | - {6:fo x the foo }{1: }| - {7:bar }{1: }| - {7:spam }{1: }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | - ]]) - - feed('') - screen:expect([[ | - spam^ | - {7:fo x the foo }{1: }| - {7:bar }{1: }| - {6:spam }{1: }| {1:~ }| {1:~ }| - {2:-- INSERT --} | - ]]) - - feed('') - screen:expect([[ - | - spam^ | - {7:fo x the foo }{1: }| - {7:bar }{1: }| - {7:spam }{1: }| {1:~ }| {1:~ }| - {2:-- INSERT --} | - ]]) + {1:~ }| + :sign define^ | + ]], popupmenu = { + items = expected_wildpum, + pos = 0, + anchor = { 1, 7, 6 }, + }}) - feed('') - screen:expect([[ + meths.select_popupmenu_item(5, true, true, {}) + screen:expect({grid = [[ + | | - bar^ | {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| - {2:-- INSERT --} | - ]]) + :sign unplace^ | + ]]}) - command('iunmap ') - command('iunmap ') - command('iunmap ') - exec_lua([[ - vim.keymap.set('i', '', function() vim.api.nvim_select_popupmenu_item(2, true, false, {}) end) - vim.keymap.set('i', '', function() vim.api.nvim_select_popupmenu_item(-1, false, false, {}) end) - vim.keymap.set('i', '', function() vim.api.nvim_select_popupmenu_item(1, false, true, {}) end) - ]]) - feed('=TestComplete()') - screen:expect([[ - | - foo^ | - {6:fo x the foo }{1: }| - {7:bar }{1: }| - {7:spam }{1: }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | - ]]) + local function test_pum_select_mappings() + screen:set_option('ext_popupmenu', true) + feed('A=TestComplete()') + screen:expect{grid=[[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=0, + anchor={1,1,0}, + }} - feed('') - screen:expect([[ - | - spam^ | - {7:fo x the foo }{1: }| - {7:bar }{1: }| - {6:spam }{1: }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | - ]]) + feed('') + screen:expect{grid=[[ + | + spam^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=2, + anchor={1,1,0}, + }} - feed('') - screen:expect([[ - | - spam^ | - {7:fo x the foo }{1: }| - {7:bar }{1: }| - {7:spam }{1: }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | - ]]) + feed('') + screen:expect{grid=[[ + | + spam^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=-1, + anchor={1,1,0}, + }} - feed('') - screen:expect([[ - | - bar^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | + feed('') + screen:expect([[ + | + bar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + feed(':sign ') + screen:expect({grid = [[ + | + bar | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :sign define^ | + ]], popupmenu = { + items = expected_wildpum, + pos = 0, + anchor = { 1, 7, 6 }, + }}) + + feed('') + screen:expect({grid = [[ + | + bar | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :sign list^ | + ]], popupmenu = { + items = expected_wildpum, + pos = 2, + anchor = { 1, 7, 6 }, + }}) + + feed('') + screen:expect({grid = [[ + | + bar | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :sign ^ | + ]], popupmenu = { + items = expected_wildpum, + pos = -1, + anchor = { 1, 7, 6 }, + }}) + + feed('') + screen:expect({grid = [[ + | + bar | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :sign jump^ | + ]]}) + + -- also should work for builtin popupmenu + screen:set_option('ext_popupmenu', false) + feed('A=TestComplete()') + screen:expect([[ + | + foo^ | + {6:fo x the foo }{1: }| + {7:bar }{1: }| + {7:spam }{1: }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + feed('') + screen:expect([[ + | + spam^ | + {7:fo x the foo }{1: }| + {7:bar }{1: }| + {6:spam }{1: }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + feed('') + screen:expect([[ + | + spam^ | + {7:fo x the foo }{1: }| + {7:bar }{1: }| + {7:spam }{1: }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + feed('') + screen:expect([[ + | + bar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + feed(':sign ') + screen:expect([[ + | + bar {6: define } | + {1:~ }{7: jump }{1: }| + {1:~ }{7: list }{1: }| + {1:~ }{7: place }{1: }| + {1:~ }{7: undefine }{1: }| + {1:~ }{7: unplace }{1: }| + :sign define^ | + ]]) + + feed('') + screen:expect([[ + | + bar {7: define } | + {1:~ }{7: jump }{1: }| + {1:~ }{6: list }{1: }| + {1:~ }{7: place }{1: }| + {1:~ }{7: undefine }{1: }| + {1:~ }{7: unplace }{1: }| + :sign list^ | + ]]) + + feed('') + screen:expect([[ + | + bar {7: define } | + {1:~ }{7: jump }{1: }| + {1:~ }{7: list }{1: }| + {1:~ }{7: place }{1: }| + {1:~ }{7: undefine }{1: }| + {1:~ }{7: unplace }{1: }| + :sign ^ | + ]]) + + feed('') + screen:expect([[ + | + bar | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :sign jump^ | + ]]) + end + + command('map! call nvim_select_popupmenu_item(2,v:true,v:false,{})') + command('map! call nvim_select_popupmenu_item(-1,v:false,v:false,{})') + command('map! call nvim_select_popupmenu_item(1,v:false,v:true,{})') + test_pum_select_mappings() + + command('unmap! ') + command('unmap! ') + command('unmap! ') + exec_lua([[ + vim.keymap.set('!', '', function() vim.api.nvim_select_popupmenu_item(2, true, false, {}) end) + vim.keymap.set('!', '', function() vim.api.nvim_select_popupmenu_item(-1, false, false, {}) end) + vim.keymap.set('!', '', function() vim.api.nvim_select_popupmenu_item(1, false, true, {}) end) ]]) + test_pum_select_mappings() feed('ddiaa bb cc') feed('') -- cgit From 14a84ec169ca8ca29a80237e82f2bb8e15a28365 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Oct 2022 21:39:49 +0800 Subject: test: add a test for #20684 --- test/functional/ui/float_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 1a9a13f7d4..9ef36cf5ae 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -430,6 +430,13 @@ describe('float window', function() assert_alive() end) + it("'scroll' is computed correctly when opening float with splitkeep=screen #20684", function() + meths.set_option('splitkeep', 'screen') + local float_opts = {relative = 'editor', row = 1, col = 1, width = 10, height = 10} + local float_win = meths.open_win(0, true, float_opts) + eq(5, meths.win_get_option(float_win, 'scroll')) + end) + describe('with only one tabpage,', function() local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1} local old_buf, old_win -- cgit From 5046b4b4adb154bbdb50a5e96e29f777b5f807ac Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 17 Oct 2022 17:16:31 +0200 Subject: ci: add cirrus to isCI function to skip tests (#20526) The environment variable CIRRUS_CI is manually passed to RunTests.cmake as it doesn't get passed when using cmake script mode. --- test/functional/api/server_notifications_spec.lua | 4 ---- test/functional/core/fileio_spec.lua | 10 +++++----- test/functional/ex_cmds/write_spec.lua | 10 +++++----- test/functional/plugin/man_spec.lua | 4 ++++ test/functional/terminal/ex_terminal_spec.lua | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 1c554b05a3..1c00f001ff 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -7,7 +7,6 @@ local exec_lua = helpers.exec_lua local retry = helpers.retry local isCI = helpers.isCI local assert_alive = helpers.assert_alive -local uname = helpers.uname describe('notify', function() local channel @@ -79,9 +78,6 @@ describe('notify', function() end) it('cancels stale events on channel close', function() - if uname() == 'freebsd' then - pending('Failing FreeBSD test') - end if isCI() then pending('hangs on CI #14083 #15251') return diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index d1ff5b8036..07774866a8 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -25,7 +25,7 @@ local expect_exit = helpers.expect_exit local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') local feed_command = helpers.feed_command -local uname = helpers.uname +local isCI = helpers.isCI describe('fileio', function() before_each(function() @@ -87,8 +87,8 @@ describe('fileio', function() end) it('backup #9709', function() - if uname() == 'freebsd' then - pending('Failing FreeBSD test') + if isCI('cirrus') then + pending('FIXME: cirrus') end clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) @@ -109,8 +109,8 @@ describe('fileio', function() end) it('backup with full path #11214', function() - if uname() == 'freebsd' then - pending('Failing FreeBSD test') + if isCI('cirrus') then + pending('FIXME: cirrus') end clear() mkdir('Xtest_backupdir') diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 14035a4341..4045d13153 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -9,7 +9,7 @@ local feed_command = helpers.feed_command local funcs = helpers.funcs local meths = helpers.meths local iswin = helpers.iswin -local uname = helpers.uname +local isCI = helpers.isCI local fname = 'Xtest-functional-ex_cmds-write' local fname_bak = fname .. '~' @@ -53,8 +53,8 @@ describe(':write', function() end) it('&backupcopy=no replaces symlink with new file', function() - if uname() == 'freebsd' then - pending('Failing FreeBSD test') + if isCI('cirrus') then + pending('FIXME: cirrus') end command('set backupcopy=no') write_file('test_bkc_file.txt', 'content0') @@ -95,8 +95,8 @@ describe(':write', function() end) it('errors out correctly', function() - if uname() == 'freebsd' then - pending('Failing FreeBSD test') + if isCI('cirrus') then + pending('FIXME: cirrus') end command('let $HOME=""') eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 203424c855..ebf131fd4a 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -8,6 +8,7 @@ local nvim_prog = helpers.nvim_prog local matches = helpers.matches local write_file = helpers.write_file local tmpname = helpers.tmpname +local isCI = helpers.isCI clear() if funcs.executable('man') == 0 then @@ -160,6 +161,9 @@ describe(':Man', function() end) it('reports non-existent man pages for absolute paths', function() + if isCI('cirrus') then + pending('FIXME: cirrus') + end local actual_file = tmpname() -- actual_file must be an absolute path to an existent file for us to test against it matches('^/.+', actual_file) diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 36f9f90143..a423bc9a5a 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -10,7 +10,7 @@ local retry = helpers.retry local ok = helpers.ok local iswin = helpers.iswin local command = helpers.command -local uname = helpers.uname +local isCI = helpers.isCI describe(':terminal', function() local screen @@ -46,8 +46,8 @@ describe(':terminal', function() end) it("reads output buffer on terminal reporting #4151", function() - if uname() == 'freebsd' then - pending('Failing FreeBSD test') + if isCI('cirrus') then + pending('FIXME: cirrus') end if helpers.pending_win32(pending) then return end if iswin() then -- cgit From 97164748b933a351423824b1988c863cc5994cdb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Oct 2022 18:42:32 +0800 Subject: fix(intro): omit patch version in ":help news" item #20713 Because maintenance releases share the same news.txt as the last non-maintenance release. --- test/functional/ui/messages_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 8ab25d0102..a042291b54 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -1273,7 +1273,7 @@ describe('ui/ext_messages', function() {1:~ }type :q{5:} to exit {1: }| {1:~ }type :help{5:} for help {1: }| {1:~ }| - {1:~ }type :help news{5:} to see changes in v{MATCH:.*}| + {1:~ }type :help news{5:} to see changes in v{MATCH:%d+%.%d+}| {1:~ }| {MATCH:.*}| {MATCH:.*}| @@ -1329,7 +1329,7 @@ describe('ui/ext_messages', function() type :q{5:} to exit | type :help{5:} for help | | - type :help news{5:} to see changes in {MATCH:.*}| + type :help news{5:} to see changes in v{MATCH:%d+%.%d+}| | {MATCH:.*}| {MATCH:.*}| -- cgit From ef4c339fb9de87f7534303e006c281e40327f803 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 18 Oct 2022 10:18:44 -0400 Subject: feat(docs): update parser, HTML gen #20720 Note: although the tolerance in help_spec.lua increased, the actual error count with the new parser decreased by about 20%. The difference is that the old ignore_parse_error() ignored many more errors with the old parser. fix https://github.com/neovim/tree-sitter-vimdoc/issues/37 fix https://github.com/neovim/tree-sitter-vimdoc/issues/44 fix https://github.com/neovim/tree-sitter-vimdoc/issues/47 --- test/functional/lua/help_spec.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua index 242897336d..f5e67ec636 100644 --- a/test/functional/lua/help_spec.lua +++ b/test/functional/lua/help_spec.lua @@ -19,10 +19,11 @@ describe(':help docs', function() local rv = exec_lua([[return require('scripts.gen_help_html').validate('./build/runtime/doc')]]) -- Check that we actually found helpfiles. ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles) + eq({}, rv.invalid_links, 'found invalid :help tag links') + eq({}, rv.invalid_urls, 'found invalid URLs in :help docs') -- Check that parse errors did not increase wildly. -- TODO: Fix all parse errors in :help files. - ok(rv.err_count < 100, '<100 parse errors', rv.err_count) - eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) + ok(rv.err_count < 350, '<350 parse errors', rv.err_count) end) it('gen_help_html.lua generates HTML', function() @@ -43,7 +44,7 @@ describe(':help docs', function() tmpdir ) eq(4, #rv.helpfiles) - ok(rv.err_count == 0, '0 parse errors', rv.err_count) - eq({}, rv.invalid_links, exec_lua([[return 'found invalid :help tag links:\n'..vim.inspect(...)]], rv.invalid_links)) + ok(rv.err_count < 25, '<25 parse errors', rv.err_count) + eq({}, rv.invalid_links, 'found invalid :help tag links') end) end) -- cgit From 96cf385a7f4ab29f6987c10b5c3625d99b22f6fc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Oct 2022 11:32:26 +0800 Subject: vim-patch:9.0.0739: mouse column not correctly used for popup_setpos (#20729) Problem: Mouse column not correctly used for popup_setpos. Solution: Adjust off-by-one error and handle Visual line selection properly. (Yee Cheng Chin, closes vim/vim#11356) https://github.com/vim/vim/commit/17822c507c03d509037c9ee5eee5cfbb201b3f01 The test_termcodes.vim test cannot be used. Use a Lua test instead. --- test/functional/ui/mouse_spec.lua | 130 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index cb8dfdb8e1..b3ea0edb12 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -4,6 +4,7 @@ local clear, feed, meths = helpers.clear, helpers.feed, helpers.meths local insert, feed_command = helpers.insert, helpers.feed_command local eq, funcs = helpers.eq, helpers.funcs local command = helpers.command +local exec = helpers.exec describe('ui/mouse/input', function() local screen @@ -1687,4 +1688,133 @@ describe('ui/mouse/input', function() helpers.poke_eventloop() helpers.assert_alive() end) + + it('mousemodel=popup_setpos', function() + screen:try_resize(80, 24) + exec([[ + 5new + call setline(1, ['the dish ran away with the spoon', + \ 'the cow jumped over the moon' ]) + + set mouse=a mousemodel=popup_setpos + + aunmenu PopUp + nmenu PopUp.foo :let g:menustr = 'foo' + nmenu PopUp.bar :let g:menustr = 'bar' + nmenu PopUp.baz :let g:menustr = 'baz' + vmenu PopUp.foo y:let g:menustr = 'foo' + vmenu PopUp.bar y:let g:menustr = 'bar' + vmenu PopUp.baz y:let g:menustr = 'baz' + ]]) + + meths.win_set_cursor(0, {1, 0}) + meths.input_mouse('right', 'press', '', 0, 0, 4) + meths.input_mouse('right', 'release', '', 0, 0, 4) + feed('') + eq('bar', meths.get_var('menustr')) + eq({1, 4}, meths.win_get_cursor(0)) + + -- Test for right click in visual mode inside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 9}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 0, 11) + meths.input_mouse('right', 'release', '', 0, 0, 11) + feed('') + eq({1, 9}, meths.win_get_cursor(0)) + eq('ran away', funcs.getreg('"')) + + -- Test for right click in visual mode right before the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 9}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 0, 8) + meths.input_mouse('right', 'release', '', 0, 0, 8) + feed('') + eq({1, 8}, meths.win_get_cursor(0)) + eq('', funcs.getreg('"')) + + -- Test for right click in visual mode right after the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 9}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 0, 17) + meths.input_mouse('right', 'release', '', 0, 0, 17) + feed('') + eq({1, 17}, meths.win_get_cursor(0)) + eq('', funcs.getreg('"')) + + -- Test for right click in block-wise visual mode inside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('j3l') + meths.input_mouse('right', 'press', '', 0, 1, 16) + meths.input_mouse('right', 'release', '', 0, 1, 16) + feed('') + eq({1, 15}, meths.win_get_cursor(0)) + eq('\0224', funcs.getregtype('"')) + + -- Test for right click in block-wise visual mode outside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('j3l') + meths.input_mouse('right', 'press', '', 0, 1, 1) + meths.input_mouse('right', 'release', '', 0, 1, 1) + feed('') + eq({2, 1}, meths.win_get_cursor(0)) + eq('v', funcs.getregtype('"')) + eq('', funcs.getreg('"')) + + -- Test for right click in line-wise visual mode inside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('V') + meths.input_mouse('right', 'press', '', 0, 0, 9) + meths.input_mouse('right', 'release', '', 0, 0, 9) + feed('') + eq({1, 0}, meths.win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 + eq('V', funcs.getregtype('"')) + eq(1, #funcs.getreg('"', 1, true)) + + -- Test for right click in multi-line line-wise visual mode inside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('Vj') + meths.input_mouse('right', 'press', '', 0, 1, 19) + meths.input_mouse('right', 'release', '', 0, 1, 19) + feed('') + eq({1, 0}, meths.win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 + eq('V', funcs.getregtype('"')) + eq(2, #funcs.getreg('"', 1, true)) + + -- Test for right click in line-wise visual mode outside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('V') + meths.input_mouse('right', 'press', '', 0, 1, 9) + meths.input_mouse('right', 'release', '', 0, 1, 9) + feed('') + eq({2, 9}, meths.win_get_cursor(0)) + eq('', funcs.getreg('"')) + + -- Try clicking on the status line + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 9}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 5, 1) + meths.input_mouse('right', 'release', '', 0, 5, 1) + feed('') + eq({1, 9}, meths.win_get_cursor(0)) + eq('ran away', funcs.getreg('"')) + + -- Try clicking outside the window + funcs.setreg('"', '') + meths.win_set_cursor(0, {2, 1}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 6, 1) + meths.input_mouse('right', 'release', '', 0, 6, 1) + feed('') + eq(2, funcs.winnr()) + eq('', funcs.getreg('"')) + end) end) -- cgit From e6917306f6d3ba99747d14bea3f0b078631c5c0e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 20 Oct 2022 09:20:02 -0400 Subject: docs: update vimdoc parser #20747 Remove the user-manual ToC from help.txt, because: 1. it duplicates usr_toc.txt 2. it is not what most readers are looking for in the main help page. fix https://github.com/neovim/tree-sitter-vimdoc/issues/49 fix https://github.com/neovim/tree-sitter-vimdoc/issues/50 fix https://github.com/neovim/tree-sitter-vimdoc/issues/51 --- test/functional/lua/help_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua index f5e67ec636..b396e2ba30 100644 --- a/test/functional/lua/help_spec.lua +++ b/test/functional/lua/help_spec.lua @@ -19,11 +19,11 @@ describe(':help docs', function() local rv = exec_lua([[return require('scripts.gen_help_html').validate('./build/runtime/doc')]]) -- Check that we actually found helpfiles. ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles) - eq({}, rv.invalid_links, 'found invalid :help tag links') - eq({}, rv.invalid_urls, 'found invalid URLs in :help docs') + eq({}, rv.invalid_links, 'invalid tags in :help docs') + eq({}, rv.invalid_urls, 'invalid URLs in :help docs') -- Check that parse errors did not increase wildly. -- TODO: Fix all parse errors in :help files. - ok(rv.err_count < 350, '<350 parse errors', rv.err_count) + ok(rv.err_count < 250, '<250 parse errors', rv.err_count) end) it('gen_help_html.lua generates HTML', function() @@ -44,7 +44,7 @@ describe(':help docs', function() tmpdir ) eq(4, #rv.helpfiles) - ok(rv.err_count < 25, '<25 parse errors', rv.err_count) - eq({}, rv.invalid_links, 'found invalid :help tag links') + eq(0, rv.err_count, 'parse errors in :help docs') + eq({}, rv.invalid_links, 'invalid tags in :help docs') end) end) -- cgit From 2f9b94a26836ecb081c717e23913f5b6576cce99 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Oct 2022 07:53:39 +0800 Subject: fix(ui): send grid_resize events before triggering VimResized (#20760) --- test/functional/ui/screen_basic_spec.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index f111aa2513..5aacdc95e2 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -894,6 +894,31 @@ local function screen_tests(linegrid) :ls^ | ]]) end) + + it('VimResized autocommand does not cause invalid UI events #20692 #20759', function() + feed('') + command([[autocmd VimResized * redrawtabline]]) + command([[autocmd VimResized * lua vim.api.nvim_echo({ { 'Hello' } }, false, {})]]) + command([[autocmd VimResized * let g:echospace = v:echospace]]) + meths.set_option('showtabline', 2) + screen:expect([[ + {2: + [No Name] }{3: }| + resiz^e | + {0:~ }| + {0:~ }| + | + ]]) + screen:try_resize(30, 6) + screen:expect([[ + {2: + [No Name] }{3: }| + resiz^e | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + eq(29, meths.get_var('echospace')) + end) end) describe('press enter', function() -- cgit From 1887d8d7d0dd619fa90fe11182c436bc3c71c9d5 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 23 Oct 2022 03:45:39 +0200 Subject: docs: fix typos (#20724) Co-authored-by: Marco Lehmann --- test/functional/lua/vim_spec.lua | 24 ++++++++++++------------ test/functional/ui/decorations_spec.lua | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index f250a3ec93..ecfb7275cd 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1016,11 +1016,11 @@ describe('lua stdlib', function() eq('hi', funcs.luaeval "vim.g.testing") eq(123, funcs.luaeval "vim.g.other") eq(5120.1, funcs.luaeval "vim.g.floaty") - eq(NIL, funcs.luaeval "vim.g.nonexistant") + eq(NIL, funcs.luaeval "vim.g.nonexistent") eq(NIL, funcs.luaeval "vim.g.nullvar") -- lost over RPC, so test locally: eq({false, true}, exec_lua [[ - return {vim.g.nonexistant == vim.NIL, vim.g.nullvar == vim.NIL} + return {vim.g.nonexistent == vim.NIL, vim.g.nullvar == vim.NIL} ]]) eq({hello="world"}, funcs.luaeval "vim.g.to_delete") @@ -1123,12 +1123,12 @@ describe('lua stdlib', function() eq('bye', funcs.luaeval "vim.b[BUF].testing") eq(123, funcs.luaeval "vim.b.other") eq(5120.1, funcs.luaeval "vim.b.floaty") - eq(NIL, funcs.luaeval "vim.b.nonexistant") - eq(NIL, funcs.luaeval "vim.b[BUF].nonexistant") + eq(NIL, funcs.luaeval "vim.b.nonexistent") + eq(NIL, funcs.luaeval "vim.b[BUF].nonexistent") eq(NIL, funcs.luaeval "vim.b.nullvar") -- lost over RPC, so test locally: eq({false, true}, exec_lua [[ - return {vim.b.nonexistant == vim.NIL, vim.b.nullvar == vim.NIL} + return {vim.b.nonexistent == vim.NIL, vim.b.nullvar == vim.NIL} ]]) matches([[attempt to index .* nil value]], @@ -1207,7 +1207,7 @@ describe('lua stdlib', function() eq(NIL, funcs.luaeval "vim.b.testing") eq(NIL, funcs.luaeval "vim.b.other") - eq(NIL, funcs.luaeval "vim.b.nonexistant") + eq(NIL, funcs.luaeval "vim.b.nonexistent") end) it('vim.w', function() @@ -1226,8 +1226,8 @@ describe('lua stdlib', function() eq('hi', funcs.luaeval "vim.w.testing") eq('bye', funcs.luaeval "vim.w[WIN].testing") eq(123, funcs.luaeval "vim.w.other") - eq(NIL, funcs.luaeval "vim.w.nonexistant") - eq(NIL, funcs.luaeval "vim.w[WIN].nonexistant") + eq(NIL, funcs.luaeval "vim.w.nonexistent") + eq(NIL, funcs.luaeval "vim.w[WIN].nonexistent") matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.w[WIN][0].testing')) @@ -1305,7 +1305,7 @@ describe('lua stdlib', function() eq(NIL, funcs.luaeval "vim.w.testing") eq(NIL, funcs.luaeval "vim.w.other") - eq(NIL, funcs.luaeval "vim.w.nonexistant") + eq(NIL, funcs.luaeval "vim.w.nonexistent") end) it('vim.t', function() @@ -1317,10 +1317,10 @@ describe('lua stdlib', function() eq('hi', funcs.luaeval "vim.t.testing") eq(123, funcs.luaeval "vim.t.other") - eq(NIL, funcs.luaeval "vim.t.nonexistant") + eq(NIL, funcs.luaeval "vim.t.nonexistent") eq('hi', funcs.luaeval "vim.t[0].testing") eq(123, funcs.luaeval "vim.t[0].other") - eq(NIL, funcs.luaeval "vim.t[0].nonexistant") + eq(NIL, funcs.luaeval "vim.t[0].nonexistent") matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.t[0][0].testing')) @@ -1387,7 +1387,7 @@ describe('lua stdlib', function() eq(NIL, funcs.luaeval "vim.t.testing") eq(NIL, funcs.luaeval "vim.t.other") - eq(NIL, funcs.luaeval "vim.t.nonexistant") + eq(NIL, funcs.luaeval "vim.t.nonexistent") end) it('vim.env', function() diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index e9072ebf98..5b62f5b3e1 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -1115,7 +1115,7 @@ if (h->n_buckets < new_n_buckets) { // expand ]]} meths.buf_set_extmark(0, ns, 5, 0, { - virt_lines = { {{"^^ REVIEW:", "Todo"}, {" new_vals variable seems unneccesary?", "Comment"}} }; + virt_lines = { {{"^^ REVIEW:", "Todo"}, {" new_vals variable seems unnecessary?", "Comment"}} }; }) -- TODO: what about the cursor?? screen:expect{grid=[[ @@ -1128,7 +1128,7 @@ if (h->n_buckets < new_n_buckets) { // expand if (kh_is_map && val_size) { | ^char *new_vals = {3:krealloc}( h->vals_buf, new_n_| buckets * val_size); | - {5:^^ REVIEW:}{6: new_vals variable seems unneccesary?} | + {5:^^ REVIEW:}{6: new_vals variable seems unnecessary?} | h->vals_buf = new_vals; | | ]]} -- cgit From 0ed1429fcb826c0022744fa17edfbe36a750d5f6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 24 Oct 2022 15:49:16 +0800 Subject: test: add a test for a crash fixed by patch 8.2.0908 --- test/functional/vimscript/eval_spec.lua | 37 +++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 1fbdedb815..64a3cf5471 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -17,12 +17,16 @@ local clear = helpers.clear local eq = helpers.eq local exc_exec = helpers.exc_exec local exec = helpers.exec +local exec_lua = helpers.exec_lua local exec_capture = helpers.exec_capture local eval = helpers.eval local command = helpers.command local write_file = helpers.write_file local meths = helpers.meths local sleep = helpers.sleep +local matches = helpers.matches +local pcall_err = helpers.pcall_err +local assert_alive = helpers.assert_alive local poke_eventloop = helpers.poke_eventloop local feed = helpers.feed @@ -249,10 +253,10 @@ describe("uncaught exception", function() end) end) -describe('lambda function', function() +describe('listing functions using :function', function() before_each(clear) - it('can be shown using :function followed by #20466', function() + it('works for lambda functions with #20466', function() command('let A = {-> 1}') local num = exec_capture('echo A'):match("function%('(%d+)'%)") eq(([[ @@ -260,4 +264,33 @@ describe('lambda function', function() 1 return 1 endfunction]]):format(num), exec_capture(('function %s'):format(num))) end) + + -- FIXME: If the same function is deleted, the crash still happens. #20790 + it('does not crash if another function is deleted while listing', function() + local screen = Screen.new(80, 24) + screen:attach() + matches('.*: Vim%(function%):E454: function list was modified', pcall_err(exec_lua, [=[ + vim.cmd([[ + func Func1() + endfunc + func Func2() + endfunc + func Func3() + endfunc + ]]) + + local ns = vim.api.nvim_create_namespace('test') + + vim.ui_attach(ns, { ext_messages = true }, function(event, _, content) + if event == 'msg_show' and content[1][2] == 'function Func1()' then + vim.cmd('delfunc Func3') + end + end) + + vim.cmd('function') + + vim.ui_detach(ns) + ]=])) + assert_alive() + end) end) -- cgit From 4573cfa3adac3a7dbf1b6b032471a1c14adc7427 Mon Sep 17 00:00:00 2001 From: NAKAI Tsuyoshi <82267684+uga-rosa@users.noreply.github.com> Date: Mon, 24 Oct 2022 21:53:53 +0900 Subject: fix(lua): pesc, tbl_islist result types #20751 Problem: - pesc() returns multiple results, it should return a single result. - tbl_islist() returns non-boolean in some branches. - Docstring: @generic must be declared first Solution: Constrain docstring annotations. Fix return types. Co-authored-by: Justin M. Keyes --- test/functional/lua/vim_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index ecfb7275cd..38f772c5cf 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -430,6 +430,8 @@ describe('lua stdlib', function() it('vim.pesc', function() eq('foo%-bar', exec_lua([[return vim.pesc('foo-bar')]])) eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]])) + -- pesc() returns one result. #20751 + eq({'x'}, exec_lua([[return {vim.pesc('x')}]])) -- Validates args. matches('s: expected string, got number', -- cgit From a53998ae78902309c225b323e0b8d9f1f75fe147 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 22 Oct 2022 13:54:29 +0600 Subject: fix: setting tabline option not redrawing tabline With #20374 tabline option is marked with 'statuslines' redraw flag. But 'statuslines' doesn't redraw tabline. As a result, tabline doesn't get redrawn when tabline option is set and statuslines get unnecessarily redrawn. This patch fixes the issue by adding a new redraw flag P_RTABL to redraw tabline. --- test/functional/ui/tabline_spec.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index 809486d4db..0e35a03557 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -84,3 +84,39 @@ describe('ui/ext_tabline', function() end} end) end) + +describe("tabline", function() + local screen + + before_each(function() + clear() + screen = Screen.new(42, 5) + screen:attach() + end) + + it('redraws when tabline option is set', function() + command('set tabline=asdf') + command('set showtabline=2') + screen:expect{grid=[[ + {1:asdf }| + ^ | + {2:~ }| + {2:~ }| + | + ]], attr_ids={ + [1] = {reverse = true}; + [2] = {bold = true, foreground = Screen.colors.Blue1}; + }} + command('set tabline=jkl') + screen:expect{grid=[[ + {1:jkl }| + ^ | + {2:~ }| + {2:~ }| + | + ]], attr_ids={ + [1] = {reverse = true}; + [2] = {bold = true, foreground = Screen.colors.Blue}; + }} + end) +end) -- cgit From cfccae95844db21aad773c9a8f8b636f53d6c8c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 19:04:38 +0800 Subject: vim-patch:8.2.0610: some tests are still old style Problem: Some tests are still old style. Solution: Convert to new style tests. (Yegappan Lakshmanan, closes vim/vim#5957) https://github.com/vim/vim/commit/08f4157c5cabc55bcb22f04dd7c717aba40caa34 Fix missing error message when sort() compare function fails. Cherry-pick a line in test_utf8.vim from patch 8.2.0448. Cherry-pick builtin_function() change from patch 8.2.0595. --- test/functional/legacy/eval_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua index 05d853622e..b5e45a86c1 100644 --- a/test/functional/legacy/eval_spec.lua +++ b/test/functional/legacy/eval_spec.lua @@ -639,7 +639,7 @@ describe('eval', function() end) it('function name includes a colon', function() - eq('Vim(function):E128: Function name must start with a capital or "s:": b:test()\\nendfunction', + eq('Vim(function):E884: Function name cannot contain a colon: b:test()\\nendfunction', exc_exec(dedent([[ function! b:test() endfunction]]))) -- cgit From 25cf4f2fc712530a65dc3b533508c36d0439b728 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 13:04:08 +0800 Subject: vim-patch:8.2.2653: build failure Problem: Build failure. Solution: Add missing changes. https://github.com/vim/vim/commit/3a0f092ac0dbdd4ce71f9c4abe020e89f13df36c Omit E1176: only applicable to Vim9 script. Co-authored-by: Bram Moolenaar --- test/functional/vimscript/exepath_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua index 439dd96fcd..db96b79743 100644 --- a/test/functional/vimscript/exepath_spec.lua +++ b/test/functional/vimscript/exepath_spec.lua @@ -23,7 +23,7 @@ describe('exepath()', function() for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')')) end - eq('Vim(call):E1142: Non-empty string required for argument 1', exc_exec('call exepath("")')) + eq('Vim(call):E1175: Non-empty string required for argument 1', exc_exec('call exepath("")')) command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') for _, input in ipairs({'v:null', 'v:true', 'v:false'}) do eq('Vim(call):E1174: String required for argument 1', exc_exec('call exepath('..input..')')) -- cgit From a7d100f052b45a106d1385ed419509c047c12431 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 30 Oct 2022 06:49:39 +0800 Subject: fix: avoid unsigned overflow in home_replace() (#20854) --- test/functional/editor/tabpage_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional') diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index f8ca6986bd..a7f629a76b 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -144,4 +144,10 @@ describe('tabpage', function() command(' silent :keepalt :: ::: silent! -2 tabmove') eq(1, funcs.nvim_tabpage_get_number(0)) end) + + it(':tabs does not overflow IObuff with long path with comma #20850', function() + meths.buf_set_name(0, ('x'):rep(1024) .. ',' .. ('x'):rep(1024)) + command('tabs') + assert_alive() + end) end) -- cgit From 23080a4d7a9043913cb4875e18118731a4562032 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 30 Oct 2022 07:10:39 +0800 Subject: fix(mouse): ensure no scrolling with "ver:0" in 'mousescroll' (#20861) --- test/functional/options/mousescroll_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional') diff --git a/test/functional/options/mousescroll_spec.lua b/test/functional/options/mousescroll_spec.lua index 2c9b2d175e..5bff45a836 100644 --- a/test/functional/options/mousescroll_spec.lua +++ b/test/functional/options/mousescroll_spec.lua @@ -97,6 +97,24 @@ describe("'mousescroll'", function() eq(10, screencol()) scroll('left') eq(10, screencol()) + + -- vertical scrolling is still disabled with non-zero 'scrolloff' value + command('set scrolloff=1') + + eq(10, screenrow()) + scroll('up') + eq(10, screenrow()) + scroll('down') + eq(10, screenrow()) + + -- also in insert mode + feed('i') + + eq(10, screenrow()) + scroll('up') + eq(10, screenrow()) + scroll('down') + eq(10, screenrow()) end) local test_vertical_scrolling = function() -- cgit From cc7c378bf319d62491ca121ab598397428e4ced4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 30 Oct 2022 06:41:28 +0100 Subject: feat(checkhealth): check runtime ($VIMRUNTIME) Move man/health.lua into the "runtime" check. fix #20696 --- test/functional/plugin/health_spec.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index e5a60f5cb1..c970a03fcf 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -5,7 +5,7 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local curbuf_contents = helpers.curbuf_contents local command = helpers.command -local eq, neq = helpers.eq, helpers.neq +local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches local getcompletion = helpers.funcs.getcompletion describe(':checkhealth', function() @@ -29,8 +29,7 @@ describe(':checkhealth', function() -- Do this after startup, otherwise it just breaks $VIMRUNTIME. command("let $VIM='zub'") command("checkhealth nvim") - eq("ERROR: $VIM is invalid: zub", - string.match(curbuf_contents(), "ERROR: $VIM .* zub")) + matches('ERROR: $VIM .* zub', curbuf_contents()) end) it('completions can be listed via getcompletion()', function() clear() -- cgit From 428ab6f24e6b5bae60a71138d571d57ac18528d5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 1 Nov 2022 06:14:20 +0800 Subject: fix(mark): do not restore view in op-pending mode (#20889) --- test/functional/editor/mark_spec.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 2440867c6e..f300fea3a0 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -330,7 +330,7 @@ describe('named marks view', function() os.remove(file2) end) - it('is restored', function() + it('is restored in normal mode but not op-pending mode', function() local screen = Screen.new(5, 8) screen:attach() command("edit " .. file1) @@ -358,6 +358,18 @@ describe('named marks view', function() 8 line | | ]]) + -- not in op-pending mode #20886 + feed("ggj=`a") + screen:expect([[ + 1 line | + ^2 line | + 3 line | + 4 line | + 5 line | + 6 line | + 7 line | + | + ]]) end) it('is restored across files', function() -- cgit From 4716a578ae0c3516d685495bb55e40c939a4ac87 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 23 Oct 2022 10:17:45 +0200 Subject: docs: fix typos --- test/functional/api/keymap_spec.lua | 2 +- test/functional/core/startup_spec.lua | 2 +- test/functional/ex_cmds/verbose_spec.lua | 4 ++-- test/functional/legacy/increment_spec.lua | 2 +- test/functional/plugin/lsp_spec.lua | 4 ++-- test/functional/ui/sign_spec.lua | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 30c351b26a..5be4425162 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -1066,7 +1066,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() eq({'rhs'}, bufmeths.get_lines(0, 0, 1, 1)) end) - it("does not crash when setting keymap in a non-existing buffer #13541", function() + it("does not crash when setting mapping in a non-existing buffer #13541", function() pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs', {}) helpers.assert_alive() end) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index a32c801c97..2084d365a5 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -637,7 +637,7 @@ describe('runtime:', function() end) it('loads plugin/*.lua from start packages', function() - local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory', + local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'category', 'start', 'test_plugin'}, pathsep) local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua index e6f67ef18e..000e746f1c 100644 --- a/test/functional/ex_cmds/verbose_spec.lua +++ b/test/functional/ex_cmds/verbose_spec.lua @@ -77,7 +77,7 @@ nohlsearch script_location), result) end) - it('"Last set" for keymap set by Lua', function() + it('"Last set" for mapping set by Lua', function() local result = exec_capture(':verbose map key1') eq(string.format([[ @@ -86,7 +86,7 @@ n \key1 * :echo "test" script_location), result) end) - it('"Last set" for keymap set by vim.keymap', function() + it('"Last set" for mapping set by vim.keymap', function() local result = exec_capture(':verbose map key2') eq(string.format([[ diff --git a/test/functional/legacy/increment_spec.lua b/test/functional/legacy/increment_spec.lua index d51f9a2e02..d35f4bdae6 100644 --- a/test/functional/legacy/increment_spec.lua +++ b/test/functional/legacy/increment_spec.lua @@ -285,7 +285,7 @@ describe('Ctrl-A/Ctrl-X on visual selections', function() " 1 " 1 " 1 - " Expexted: + " Expected: " 1) g Ctrl-A on block selected indented lines " 2 " 1 diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 425427be54..a7094fff48 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2470,7 +2470,7 @@ describe('LSP', function() }, uri = "file:///test_a" }, - contanerName = "TestAContainer" + containerName = "TestAContainer" }, { deprecated = false, @@ -2489,7 +2489,7 @@ describe('LSP', function() }, uri = "file:///test_b" }, - contanerName = "TestBContainer" + containerName = "TestBContainer" } } return vim.lsp.util.symbols_to_items(sym_info, nil) diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua index ff3e143126..a1683a32c9 100644 --- a/test/functional/ui/sign_spec.lua +++ b/test/functional/ui/sign_spec.lua @@ -158,7 +158,7 @@ describe('Signs', function() ]]) end) - it('higlights the cursorline sign with culhl', function() + it('highlights the cursorline sign with culhl', function() feed('iabc') command('sign define piet text=>> texthl=Search culhl=ErrorMsg') command('sign place 1 line=1 name=piet buffer=1') -- cgit From 04fbb1de4488852c3ba332898b17180500f8984e Mon Sep 17 00:00:00 2001 From: Jonathon <32371757+jwhite510@users.noreply.github.com> Date: Fri, 4 Nov 2022 05:07:22 -0400 Subject: Enable new diff option linematch (#14537) Co-authored-by: Lewis Russell --- test/functional/ui/diff_spec.lua | 176 ++++++ test/functional/ui/linematch_spec.lua | 981 ++++++++++++++++++++++++++++++++++ 2 files changed, 1157 insertions(+) create mode 100644 test/functional/ui/linematch_spec.lua (limited to 'test/functional') diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua index 36dc5addcd..dd35f47ca1 100644 --- a/test/functional/ui/diff_spec.lua +++ b/test/functional/ui/diff_spec.lua @@ -1073,6 +1073,182 @@ int main(int argc, char **argv) :e | ]]) end) + + describe('line matching diff algorithm', function() + setup(function() + local f1 = [[if __name__ == "__main__": + import sys + app = QWidgets.QApplication(sys.args) + MainWindow = QtWidgets.QMainWindow() + ui = UI_MainWindow() + ui.setupUI(MainWindow) + MainWindow.show() + sys.exit(app.exec_())]] + write_file(fname, f1, false) + local f2 = [[if __name__ == "__main__": + import sys + comment these things + #app = QWidgets.QApplication(sys.args) + #MainWindow = QtWidgets.QMainWindow() + add a completely different line here + #ui = UI_MainWindow() + add another new line + ui.setupUI(MainWindow) + MainWindow.show() + sys.exit(app.exec_())]] + write_file(fname_2, f2, false) + end) + + it('diffopt+=linematch:20', function() + reread() + feed(':set diffopt=internal,filler') + screen:expect([[ + {1: }^if __name__ == "__│{1: }if __name__ == "_| + {1: } import sys │{1: } import sys | + {1: }{9: }{8:app = QWidgets}│{1: }{9: }{8:comment these}| + {1: }{9: }{8:MainWindow = Q}│{1: }{9: }{8:#app = QWidge}| + {1: }{9: }{8:ui = UI_}{9:MainWi}│{1: }{9: }{8:#MainWindow =}| + {1: }{2:------------------}│{1: }{4: add a complet}| + {1: }{2:------------------}│{1: }{4: #ui = UI_Main}| + {1: }{2:------------------}│{1: }{4: add another n}| + {1: } ui.setupUI(Mai│{1: } ui.setupUI(Ma| + {1: } MainWindow.sho│{1: } MainWindow.sh| + {1: } sys.exit(app.e│{1: } sys.exit(app.| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {7:') + screen:expect([[ + {1: }if __name__ == "__│{1: }if __name__ == "_| + {1: } import sys │{1: } import sys | + {1: }{2:------------------}│{1: }{4: comment these}| + {1: }{9: app = QWidgets}│{1: }{9: }{8:#}{9:app = QWidge}| + {1: }{9: MainWindow = Q}│{1: }{9: }{8:#}{9:MainWindow =}| + {1: }{2:------------------}│{1: }{4: add a complet}| + {1: }{9: ui = UI_MainWi}│{1: }{9: }{8:#}{9:ui = UI_Main}| + {1: }{2:------------------}│{1: }{4: add another n}| + {1: } ui.setupUI(Mai│{1: } ui.setupUI(Ma| + {1: } MainWindow.sho│{1: } MainWindow.sh| + {1: } ^sys.exit(app.e│{1: } sys.exit(app.| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {7:') + screen:expect([[ + {1: }^DDD │{1: }DDD | + {1: }{2:------------------}│{1: }{4:AAA }| + {1: }{8:_a}{9:a }│{1: }{8:ccc}{9:a }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {7:') + screen:expect([[ + {1: }^DDD │{1: }DDD | + {1: }{8:_}{9:aa }│{1: }{8:A}{9:AA }| + {1: }{2:------------------}│{1: }{4:ccca }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {7:') + screen:expect{grid=[[ + {1: }^BB │{1: }BB | + {1: }{9: AA}{8:A}{9: }│{1: }{9: AA}{8:B}{9: }| + {1: }{2:------------------}│{1: }{4:AAAB }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {7:') + screen:expect{grid=[[ + {1: }^BB │{1: }BB | + {1: }{2:------------------}│{1: }{4: AAB }| + {1: }{9: AAA }│{1: }{9:AAA}{8:B}{9: }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {7:w:ew:ew') + end + + setup(function() + clear() + os.remove(fname) + os.remove(fname_2) + os.remove(fname_3) + end) + + teardown(function() + os.remove(fname) + os.remove(fname_2) + os.remove(fname_3) + end) + + before_each(function() + clear() + feed(':set diffopt+=linematch:30') + feed(':e ' .. fname .. '') + feed(':vnew ' .. fname_2 .. '') + feed(':vnew ' .. fname_3 .. '') + feed(':windo diffthis') + + screen = Screen.new(100, 16) + screen:attach() + screen:set_default_attr_ids({ + [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.Gray}; + [2] = {foreground = Screen.colors.Blue1, bold = true, background = Screen.colors.LightCyan1}; + [3] = {reverse = true}; + [4] = {background = Screen.colors.LightBlue}; + [5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGray}; + [6] = {foreground = Screen.colors.Blue1, bold = true}; + [7] = {reverse = true, bold = true}; + [8] = {background = Screen.colors.Red1, bold = true}; + [10] = {foreground = Screen.colors.Brown}; + [9] = {background = Screen.colors.Plum1}; +}) + feed('=') + feed(':windo set nu!') + + + end) + describe('setup the diff screen to look like a merge conflict with 3 files in diff mode', function() + before_each(function() + + local f1 = [[ + + common line + AAA + AAA + AAA + ]] + local f2 = [[ + + common line + <<<<<<< HEAD + AAA + AAA + AAA + ======= + BBB + BBB + BBB + >>>>>>> branch1 + ]] + local f3 = [[ + + common line + BBB + BBB + BBB + ]] + + write_file(fname, f1, false) + write_file(fname_2, f2, false) + write_file(fname_3, f3, false) + reread() + end) + + it('get from window 1', function() + feed('1w') + feed(':2,6diffget screen-1.2') + screen:expect([[ + {1: }{10: 1 }^ │{1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }{9:<<<<<<< HEAD }│{1: }{10: 3 }{9:<<<<<<< HEAD }│{1: }{10: }{2:---------------------------}| + {1: }{10: 4 } AAA │{1: }{10: 4 } AAA │{1: }{10: 3 } AAA | + {1: }{10: 5 } AAA │{1: }{10: 5 } AAA │{1: }{10: 4 } AAA | + {1: }{10: 6 } AAA │{1: }{10: 6 } AAA │{1: }{10: 5 } AAA | + {1: }{10: 7 }{9:======= }│{1: }{10: 7 }{9:======= }│{1: }{10: }{2:---------------------------}| + {1: }{10: 8 }{9: BBB }│{1: }{10: 8 }{9: BBB }│{1: }{10: }{2:---------------------------}| + {1: }{10: 9 }{9: BBB }│{1: }{10: 9 }{9: BBB }│{1: }{10: }{2:---------------------------}| + {1: }{10: 10 }{9: BBB }│{1: }{10: 10 }{9: BBB }│{1: }{10: }{2:---------------------------}| + {1: }{10: 11 }{9:>>>>>>> branch1 }│{1: }{10: 11 }{9:>>>>>>> branch1 }│{1: }{10: }{2:---------------------------}| + {1: }{10: 12 } │{1: }{10: 12 } │{1: }{10: 6 } | + {6:~ }│{6:~ }│{6:~ }| + {6:~ }│{6:~ }│{6:~ }| + {7:<-functional-diff-screen-1.3 [+] }{3:w') + feed(':5,7diffget screen-1.3') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 }^ │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: }{2:---------------------------}│{1: }{10: 3 }{4:<<<<<<< HEAD }│{1: }{10: }{2:---------------------------}| + {1: }{10: }{2:---------------------------}│{1: }{10: 4 }{9: AAA }│{1: }{10: 3 }{9: AAA }| + {1: }{10: 3 }{9: BBB }│{1: }{10: 5 }{9: BBB }│{1: }{10: }{2:---------------------------}| + {1: }{10: 4 }{9: }{8:BBB}{9: }│{1: }{10: 6 }{9: }{8:BBB}{9: }│{1: }{10: 4 }{9: }{8:AAA}{9: }| + {1: }{10: 5 }{9: }{8:BBB}{9: }│{1: }{10: 7 }{9: }{8:BBB}{9: }│{1: }{10: 5 }{9: }{8:AAA}{9: }| + {1: }{10: }{2:---------------------------}│{1: }{10: 8 }{4:>>>>>>> branch1 }│{1: }{10: }{2:---------------------------}| + {1: }{10: 6 } │{1: }{10: 9 } │{1: }{10: 6 } | + {6:~ }│{6:~ }│{6:~ }| + {6:~ }│{6:~ }│{6:~ }| + {6:~ }│{6:~ }│{6:~ }| + {6:~ }│{6:~ }│{6:~ }| + {6:~ }│{6:~ }│{6:~ }| + {3:w') + feed(':5,6diffget screen-1.2') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } │{1: }{10: 1 }^ | + {1: }{10: 2 }common line │{1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: }{2:---------------------------}│{1: }{10: 3 }{4:<<<<<<< HEAD }│{1: }{10: }{2:---------------------------}| + {1: }{10: }{2:---------------------------}│{1: }{10: 4 }{9: AAA }│{1: }{10: 3 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 5 }{9: AAA }│{1: }{10: 4 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 6 }{9: AAA }│{1: }{10: 5 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 7 }{9:======= }│{1: }{10: 6 }{9:======= }| + {1: }{10: 3 } BBB │{1: }{10: 8 } BBB │{1: }{10: 7 } BBB | + {1: }{10: 4 } BBB │{1: }{10: 9 } BBB │{1: }{10: 8 } BBB | + {1: }{10: 5 } BBB │{1: }{10: 10 } BBB │{1: }{10: 9 } BBB | + {1: }{10: }{2:---------------------------}│{1: }{10: 11 }{9:>>>>>>> branch1 }│{1: }{10: 10 }{9:>>>>>>> branch1 }| + {1: }{10: 6 } │{1: }{10: 12 } │{1: }{10: 11 } | + {6:~ }│{6:~ }│{6:~ }| + {6:~ }│{6:~ }│{6:~ }| + {3:w') + feed(':6,8diffput screen-1') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 }^ │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: }{2:---------------------------}│{1: }{10: 3 }{4:<<<<<<< HEAD }│{1: }{10: }{2:---------------------------}| + {1: }{10: }{2:---------------------------}│{1: }{10: 4 }{9: AAA }│{1: }{10: 3 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 5 }{9: AAA }│{1: }{10: 4 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 6 }{9: AAA }│{1: }{10: 5 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 7 }{9:======= }│{1: }{10: 6 }{9:======= }| + {1: }{10: 3 }{9: BBB }│{1: }{10: 8 }{9: BBB }│{1: }{10: }{2:---------------------------}| + {1: }{10: 4 }{9: BBB }│{1: }{10: 9 }{9: BBB }│{1: }{10: }{2:---------------------------}| + {1: }{10: 5 } BBB │{1: }{10: 10 } BBB │{1: }{10: 7 } BBB | + {1: }{10: }{2:---------------------------}│{1: }{10: 11 }{4:>>>>>>> branch1 }│{1: }{10: }{2:---------------------------}| + {1: }{10: 6 } │{1: }{10: 12 } │{1: }{10: 8 } | + {6:~ }│{6:~ }│{6:~ }| + {6:~ }│{6:~ }│{6:~ }| + {3:w') + feed(':6,11diffput screen-1') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 }^ │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: }{2:---------------------------}│{1: }{10: 3 }{4:<<<<<<< HEAD }│{1: }{10: }{2:---------------------------}| + {1: }{10: }{2:---------------------------}│{1: }{10: 4 }{9: AAA }│{1: }{10: 3 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 5 }{9: AAA }│{1: }{10: 4 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 6 }{9: AAA }│{1: }{10: 5 }{9: AAA }| + {1: }{10: }{2:---------------------------}│{1: }{10: 7 }{9:======= }│{1: }{10: 6 }{9:======= }| + {1: }{10: 3 } BBB │{1: }{10: 8 } BBB │{1: }{10: 7 } BBB | + {1: }{10: 4 } BBB │{1: }{10: 9 } BBB │{1: }{10: 8 } BBB | + {1: }{10: 5 } BBB │{1: }{10: 10 } BBB │{1: }{10: 9 } BBB | + {1: }{10: }{2:---------------------------}│{1: }{10: 11 }{9:>>>>>>> branch1 }│{1: }{10: 10 }{9:>>>>>>> branch1 }| + {1: }{10: 6 } │{1: }{10: 12 } │{1: }{10: 11 } | + {6:~ }│{6:~ }│{6:~ }| + {6:~ }│{6:~ }│{6:~ }| + {3:w:ew:ew') + end + + setup(function() + clear() + os.remove(fname) + os.remove(fname_2) + end) + + teardown(function() + os.remove(fname) + os.remove(fname_2) + end) + + before_each(function() + clear() + feed(':e ' .. fname .. '') + feed(':vnew ' .. fname_2 .. '') + feed(':windo diffthis') + + screen = Screen.new(100, 20) + screen:attach() + screen:set_default_attr_ids({ + [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.Gray}; + [2] = {foreground = Screen.colors.Blue1, bold = true, background = Screen.colors.LightCyan1}; + [3] = {reverse = true}; + [4] = {background = Screen.colors.LightBlue}; + [5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGray}; + [6] = {foreground = Screen.colors.Blue1, bold = true}; + [7] = {reverse = true, bold = true}; + [8] = {background = Screen.colors.Red1, bold = true}; + [10] = {foreground = Screen.colors.Brown}; + [9] = {background = Screen.colors.Plum1}; +}) + feed('=') + feed(':windo set nu!') + + + end) + describe('setup a diff with 2 files and set linematch:30', function() + before_each(function() + feed(':set diffopt+=linematch:30') + local f1 = [[ + +common line +common line + +DEFabc +xyz +xyz +xyz +DEFabc +DEFabc +DEFabc +common line +common line +DEF +common line +DEF +something + ]] + local f2 = [[ + +common line +common line + +ABCabc +ABCabc +ABCabc +ABCabc +common line +common line +common line +something + ]] + write_file(fname, f1, false) + write_file(fname_2, f2, false) + reread() + end) + + it('get from window 1 from line 5 to 9', function() + feed('1w') + feed(':5,9diffget') + screen:expect([[ + {1:+ }{10: 1 }{5:^+-- 7 lines: common line··················}│{1:+ }{10: 1 }{5:+-- 7 lines: common line···················}| + {1: }{10: 8 }xyz │{1: }{10: 8 }xyz | + {1: }{10: 9 }DEFabc │{1: }{10: 9 }DEFabc | + {1: }{10: 10 }DEFabc │{1: }{10: 10 }DEFabc | + {1: }{10: 11 }DEFabc │{1: }{10: 11 }DEFabc | + {1: }{10: 12 }common line │{1: }{10: 12 }common line | + {1: }{10: 13 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 14 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 15 }something │{1: }{10: 17 }something | + {1: }{10: 16 } │{1: }{10: 18 } | + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {7:Xtest-functional-diff-screen-1.2 [+] }{3:Xtest-functional-diff-screen-1 }| + :5,9diffget | + ]]) + end) + it('get from window 2 from line 5 to 10', function() + feed('2w') + feed(':5,10diffget') + screen:expect([[ + {1:- }{10: 1 } │{1:- }{10: 1 }^ | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }ABCabc │{1: }{10: 5 }ABCabc | + {1: }{10: 6 }ABCabc │{1: }{10: 6 }ABCabc | + {1: }{10: 7 }ABCabc │{1: }{10: 7 }ABCabc | + {1: }{10: 8 }{8:ABC}{9:abc }│{1: }{10: 8 }{8:DEF}{9:abc }| + {1: }{10: 9 }common line │{1: }{10: 9 }common line | + {1: }{10: 10 }common line │{1: }{10: 10 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 11 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 12 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 13 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 14 }something | + {1: }{10: 13 } │{1: }{10: 15 } | + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {3:Xtest-functional-diff-screen-1.2 }{7:Xtest-functional-diff-screen-1 [+] }| + :5,10diffget | + ]]) + end) + it('get all from window 2', function() + feed('2w') + feed(':4,17diffget') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 }^ | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }ABCabc │{1: }{10: 5 }ABCabc | + {1: }{10: 6 }ABCabc │{1: }{10: 6 }ABCabc | + {1: }{10: 7 }ABCabc │{1: }{10: 7 }ABCabc | + {1: }{10: 8 }ABCabc │{1: }{10: 8 }ABCabc | + {1: }{10: 9 }common line │{1: }{10: 9 }common line | + {1: }{10: 10 }common line │{1: }{10: 10 }common line | + {1: }{10: 11 }common line │{1: }{10: 11 }common line | + {1: }{10: 12 }something │{1: }{10: 12 }something | + {1: }{10: 13 } │{1: }{10: 13 } | + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {3:Xtest-functional-diff-screen-1.2 }{7:Xtest-functional-diff-screen-1 [+] }| + :4,17diffget | + ]]) + + end) + it('get all from window 1', function() + feed('1w') + feed(':4,12diffget') + screen:expect([[ + {1: }{10: 1 }^ │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }DEFabc │{1: }{10: 5 }DEFabc | + {1: }{10: 6 }xyz │{1: }{10: 6 }xyz | + {1: }{10: 7 }xyz │{1: }{10: 7 }xyz | + {1: }{10: 8 }xyz │{1: }{10: 8 }xyz | + {1: }{10: 9 }DEFabc │{1: }{10: 9 }DEFabc | + {1: }{10: 10 }DEFabc │{1: }{10: 10 }DEFabc | + {1: }{10: 11 }DEFabc │{1: }{10: 11 }DEFabc | + {1: }{10: 12 }common line │{1: }{10: 12 }common line | + {1: }{10: 13 }common line │{1: }{10: 13 }common line | + {1: }{10: 14 }DEF │{1: }{10: 14 }DEF | + {1: }{10: 15 }common line │{1: }{10: 15 }common line | + {1: }{10: 16 }DEF │{1: }{10: 16 }DEF | + {1: }{10: 17 }something │{1: }{10: 17 }something | + {1: }{10: 18 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 [+] }{3:Xtest-functional-diff-screen-1 }| + :4,12diffget | + ]]) + end) + it('get from window 1 using do 1 line 5', function() + feed('1w') + feed('5gg') + feed('do') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }^DEFabc │{1: }{10: 5 }DEFabc | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 7 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 8 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 17 }something | + {1: }{10: 13 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 [+] }{3:Xtest-functional-diff-screen-1 }| + :e | + ]]) + end) + it('get from window 1 using do 2 line 6', function() + feed('1w') + feed('6gg') + feed('do') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }^DEFabc │{1: }{10: 9 }DEFabc | + {1: }{10: 7 }DEFabc │{1: }{10: 10 }DEFabc | + {1: }{10: 8 }DEFabc │{1: }{10: 11 }DEFabc | + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 17 }something | + {1: }{10: 13 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 [+] }{3:Xtest-functional-diff-screen-1 }| + :e | + ]]) + end) + it('get from window 1 using do 2 line 7', function() + feed('1w') + feed('7gg') + feed('do') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }DEFabc │{1: }{10: 9 }DEFabc | + {1: }{10: 7 }^DEFabc │{1: }{10: 10 }DEFabc | + {1: }{10: 8 }DEFabc │{1: }{10: 11 }DEFabc | + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 17 }something | + {1: }{10: 13 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 [+] }{3:Xtest-functional-diff-screen-1 }| + :e | + ]]) + end) + it('get from window 1 using do 2 line 11', function() + feed('1w') + feed('11gg') + feed('do') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 7 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 8 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: 11 }DEF │{1: }{10: 14 }DEF | + {1: }{10: 12 }^common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 13 }something │{1: }{10: 17 }something | + {1: }{10: 14 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 [+] }{3:Xtest-functional-diff-screen-1 }| + :e | + ]]) + end) + it('get from window 1 using do 2 line 12', function() + feed('1w') + feed('12gg') + feed('do') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 7 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 8 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: 12 }DEF │{1: }{10: 16 }DEF | + {1: }{10: 13 }^something │{1: }{10: 17 }something | + {1: }{10: 14 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 [+] }{3:Xtest-functional-diff-screen-1 }| + :e | + ]]) + end) + it('put from window 1 using dp 1 line 5', function() + feed('1w') + feed('5gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }^ABCabc │{1: }{10: 5 }ABCabc | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 7 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 8 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 17 }something | + {1: }{10: 13 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 [+] }| + :e | + ]]) + end) + it('put from window 1 using dp 2 line 6', function() + feed('1w') + feed('6gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }^ABCabc │{1: }{10: 9 }ABCabc | + {1: }{10: 7 }ABCabc │{1: }{10: 10 }ABCabc | + {1: }{10: 8 }ABCabc │{1: }{10: 11 }ABCabc | + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 17 }something | + {1: }{10: 13 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 [+] }| + :e | + ]]) + end) + it('put from window 1 using dp 2 line 7', function() + feed('1w') + feed('7gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }ABCabc │{1: }{10: 9 }ABCabc | + {1: }{10: 7 }^ABCabc │{1: }{10: 10 }ABCabc | + {1: }{10: 8 }ABCabc │{1: }{10: 11 }ABCabc | + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 17 }something | + {1: }{10: 13 } │{1: }{10: 18 } | + {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 [+] }| + :e | + ]]) + end) + it('put from window 1 using dp 2 line 11', function() + feed('1w') + feed('11gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 7 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 8 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: 11 }^common line │{1: }{10: 14 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 15 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 16 }something | + {1: }{10: 13 } │{1: }{10: 17 } | + {6:~ }│{6:~ }| + {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 [+] }| + :e | + ]]) + end) + it('put from window 1 using dp 2 line 12', function() + feed('1w') + feed('12gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 7 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 8 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: 12 }^something │{1: }{10: 16 }something | + {1: }{10: 13 } │{1: }{10: 17 } | + {6:~ }│{6:~ }| + {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 [+] }| + :e | + ]]) + end) + it('put from window 2 using dp line 6', function() + feed('2w') + feed('6gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: 6 }xyz │{1: }{10: 6 }^xyz | + {1: }{10: 7 }xyz │{1: }{10: 7 }xyz | + {1: }{10: 8 }xyz │{1: }{10: 8 }xyz | + {1: }{10: 9 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 10 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 11 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 12 }common line │{1: }{10: 12 }common line | + {1: }{10: 13 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 14 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 15 }something │{1: }{10: 17 }something | + {1: }{10: 16 } │{1: }{10: 18 } | + {3:Xtest-functional-diff-screen-1.2 [+] }{7:Xtest-functional-diff-screen-1 }| + :e | + ]]) + end) + it('put from window 2 using dp line 8', function() + feed('2w') + feed('8gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: 6 }xyz │{1: }{10: 6 }xyz | + {1: }{10: 7 }xyz │{1: }{10: 7 }xyz | + {1: }{10: 8 }xyz │{1: }{10: 8 }^xyz | + {1: }{10: 9 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 10 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 11 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 12 }common line │{1: }{10: 12 }common line | + {1: }{10: 13 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 14 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 15 }something │{1: }{10: 17 }something | + {1: }{10: 16 } │{1: }{10: 18 } | + {3:Xtest-functional-diff-screen-1.2 [+] }{7:Xtest-functional-diff-screen-1 }| + :e | + ]]) + end) + it('put from window 2 using dp line 9', function() + feed('2w') + feed('9gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }DEFabc │{1: }{10: 9 }^DEFabc | + {1: }{10: 7 }DEFabc │{1: }{10: 10 }DEFabc | + {1: }{10: 8 }DEFabc │{1: }{10: 11 }DEFabc | + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 16 }{4:DEF }| + {1: }{10: 12 }something │{1: }{10: 17 }something | + {1: }{10: 13 } │{1: }{10: 18 } | + {3:Xtest-functional-diff-screen-1.2 [+] }{7:Xtest-functional-diff-screen-1 }| + :e | + ]]) + end) + it('put from window 2 using dp line 17', function() + feed('2w') + feed('17gg') + feed('dp') + screen:expect([[ + {1: }{10: 1 } │{1: }{10: 1 } | + {1: }{10: 2 }common line │{1: }{10: 2 }common line | + {1: }{10: 3 }common line │{1: }{10: 3 }common line | + {1: }{10: 4 } │{1: }{10: 4 } | + {1: }{10: 5 }{8:ABC}{9:abc }│{1: }{10: 5 }{8:DEF}{9:abc }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 6 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 7 }{4:xyz }| + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 8 }{4:xyz }| + {1: }{10: 6 }{8:ABC}{9:abc }│{1: }{10: 9 }{8:DEF}{9:abc }| + {1: }{10: 7 }{8:ABC}{9:abc }│{1: }{10: 10 }{8:DEF}{9:abc }| + {1: }{10: 8 }{8:ABC}{9:abc }│{1: }{10: 11 }{8:DEF}{9:abc }| + {1: }{10: 9 }common line │{1: }{10: 12 }common line | + {1: }{10: 10 }common line │{1: }{10: 13 }common line | + {1: }{10: }{2:-------------------------------------------}│{1: }{10: 14 }{4:DEF }| + {1: }{10: 11 }common line │{1: }{10: 15 }common line | + {1: }{10: 12 }DEF │{1: }{10: 16 }DEF | + {1: }{10: 13 }something │{1: }{10: 17 }^something | + {1: }{10: 14 } │{1: }{10: 18 } | + {3:Xtest-functional-diff-screen-1.2 [+] }{7:Xtest-functional-diff-screen-1 }| + :e | + ]]) + + end) + end) + describe('setup a diff with 2 files and set linematch:10', function() + before_each(function() + feed(':set diffopt+=linematch:10') + local f1 = [[ +common line +HIL + +aABCabc +aABCabc +aABCabc +aABCabc +common line +HIL +common line +something + ]] + local f2 = [[ +common line +DEF +GHI +something + +aDEFabc +xyz +xyz +xyz +aDEFabc +aDEFabc +aDEFabc +common line +DEF +GHI +something else +common line +something + ]] + write_file(fname, f1, false) + write_file(fname_2, f2, false) + reread() + end) + + it('enable linematch for the longest diff block by increasing the number argument passed to linematch', function() + feed('1w') + -- linematch is disabled for the longest diff because it's combined line length is over 10 + screen:expect([[ + {1: }{10: 1 }^common line │{1: }{10: 1 }common line | + {1: }{10: 2 }{4:DEF }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 3 }{8:GHI}{9: }│{1: }{10: 2 }{8:HIL}{9: }| + {1: }{10: 4 }{4:something }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 5 } │{1: }{10: 3 } | + {1: }{10: 6 }{9:a}{8:DEF}{9:abc }│{1: }{10: 4 }{9:a}{8:ABC}{9:abc }| + {1: }{10: 7 }{8:xyz}{9: }│{1: }{10: 5 }{8:aABCabc}{9: }| + {1: }{10: 8 }{8:xyz}{9: }│{1: }{10: 6 }{8:aABCabc}{9: }| + {1: }{10: 9 }{8:xyz}{9: }│{1: }{10: 7 }{8:aABCabc}{9: }| + {1: }{10: 10 }{4:aDEFabc }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 11 }{4:aDEFabc }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 12 }{4:aDEFabc }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 13 }common line │{1: }{10: 8 }common line | + {1: }{10: 14 }{4:DEF }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 15 }{8:GHI}{9: }│{1: }{10: 9 }{8:HIL}{9: }| + {1: }{10: 16 }{4:something else }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 17 }common line │{1: }{10: 10 }common line | + {1: }{10: 18 }something │{1: }{10: 11 }something | + {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 }| + :e | + ]]) + -- enable it by increasing the number + feed(":set diffopt-=linematch:10") + feed(":set diffopt+=linematch:30") + screen:expect([[ + {1: }{10: 1 }^common line │{1: }{10: 1 }common line | + {1: }{10: 2 }{4:DEF }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 3 }{8:GHI}{9: }│{1: }{10: 2 }{8:HIL}{9: }| + {1: }{10: 4 }{4:something }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 5 } │{1: }{10: 3 } | + {1: }{10: 6 }{9:a}{8:DEF}{9:abc }│{1: }{10: 4 }{9:a}{8:ABC}{9:abc }| + {1: }{10: 7 }{4:xyz }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 8 }{4:xyz }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 9 }{4:xyz }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 10 }{9:a}{8:DEF}{9:abc }│{1: }{10: 5 }{9:a}{8:ABC}{9:abc }| + {1: }{10: 11 }{9:a}{8:DEF}{9:abc }│{1: }{10: 6 }{9:a}{8:ABC}{9:abc }| + {1: }{10: 12 }{9:a}{8:DEF}{9:abc }│{1: }{10: 7 }{9:a}{8:ABC}{9:abc }| + {1: }{10: 13 }common line │{1: }{10: 8 }common line | + {1: }{10: 14 }{4:DEF }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 15 }{8:GHI}{9: }│{1: }{10: 9 }{8:HIL}{9: }| + {1: }{10: 16 }{4:something else }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 17 }common line │{1: }{10: 10 }common line | + {1: }{10: 18 }something │{1: }{10: 11 }something | + {7:Xtest-functional-diff-screen-1.2 }{3:Xtest-functional-diff-screen-1 }| + :set diffopt+=linematch:30 | + ]]) + end) + it('get all from second window', function() + feed('2w') + feed(':1,12diffget') + screen:expect([[ + {1: }{10: 1 }common line │{1: }{10: 1 }^common line | + {1: }{10: 2 }DEF │{1: }{10: 2 }DEF | + {1: }{10: 3 }GHI │{1: }{10: 3 }GHI | + {1: }{10: 4 }something │{1: }{10: 4 }something | + {1: }{10: 5 } │{1: }{10: 5 } | + {1: }{10: 6 }aDEFabc │{1: }{10: 6 }aDEFabc | + {1: }{10: 7 }xyz │{1: }{10: 7 }xyz | + {1: }{10: 8 }xyz │{1: }{10: 8 }xyz | + {1: }{10: 9 }xyz │{1: }{10: 9 }xyz | + {1: }{10: 10 }aDEFabc │{1: }{10: 10 }aDEFabc | + {1: }{10: 11 }aDEFabc │{1: }{10: 11 }aDEFabc | + {1: }{10: 12 }aDEFabc │{1: }{10: 12 }aDEFabc | + {1: }{10: 13 }common line │{1: }{10: 13 }common line | + {1: }{10: 14 }DEF │{1: }{10: 14 }DEF | + {1: }{10: 15 }GHI │{1: }{10: 15 }GHI | + {1: }{10: 16 }something else │{1: }{10: 16 }something else | + {1: }{10: 17 }common line │{1: }{10: 17 }common line | + {1: }{10: 18 }something │{1: }{10: 18 }something | + {3:Xtest-functional-diff-screen-1.2 }{7:Xtest-functional-diff-screen-1 [+] }| + :1,12diffget | + ]]) + end) + it('get all from first window', function() + feed('1w') + feed(':1,19diffget') + screen:expect([[ + {1: }{10: 1 }^common line │{1: }{10: 1 }common line | + {1: }{10: 2 }HIL │{1: }{10: 2 }HIL | + {1: }{10: 3 } │{1: }{10: 3 } | + {1: }{10: 4 }aABCabc │{1: }{10: 4 }aABCabc | + {1: }{10: 5 }aABCabc │{1: }{10: 5 }aABCabc | + {1: }{10: 6 }aABCabc │{1: }{10: 6 }aABCabc | + {1: }{10: 7 }aABCabc │{1: }{10: 7 }aABCabc | + {1: }{10: 8 }common line │{1: }{10: 8 }common line | + {1: }{10: 9 }HIL │{1: }{10: 9 }HIL | + {1: }{10: 10 }common line │{1: }{10: 10 }common line | + {1: }{10: 11 }something │{1: }{10: 11 }something | + {1: }{10: 12 } │{1: }{10: 12 } | + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {6:~ }│{6:~ }| + {7:Xtest-functional-diff-screen-1.2 [+] }{3:Xtest-functional-diff-screen-1 }| + :1,19diffget | + ]]) + end) + it('get part of the non linematched diff block in window 2 line 7 - 8 (non line matched block)', function() + feed('2w') + feed(':7,8diffget') + screen:expect([[ + {1: }{10: 1 }common line │{1: }{10: 1 }^common line | + {1: }{10: 2 }{4:DEF }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 3 }{8:GHI}{9: }│{1: }{10: 2 }{8:HIL}{9: }| + {1: }{10: 4 }{4:something }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 5 } │{1: }{10: 3 } | + {1: }{10: 6 }{9:a}{8:DEF}{9:abc }│{1: }{10: 4 }{9:a}{8:ABC}{9:abc }| + {1: }{10: 7 }{8:xyz}{9: }│{1: }{10: 5 }{8:aABCabc}{9: }| + {1: }{10: 8 }{8:xyz}{9: }│{1: }{10: 6 }{8:aABCabc}{9: }| + {1: }{10: 9 }xyz │{1: }{10: 7 }xyz | + {1: }{10: 10 }aDEFabc │{1: }{10: 8 }aDEFabc | + {1: }{10: 11 }aDEFabc │{1: }{10: 9 }aDEFabc | + {1: }{10: 12 }aDEFabc │{1: }{10: 10 }aDEFabc | + {1: }{10: 13 }common line │{1: }{10: 11 }common line | + {1: }{10: 14 }{4:DEF }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 15 }{8:GHI}{9: }│{1: }{10: 12 }{8:HIL}{9: }| + {1: }{10: 16 }{4:something else }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 17 }common line │{1: }{10: 13 }common line | + {1: }{10: 18 }something │{1: }{10: 14 }something | + {3:Xtest-functional-diff-screen-1.2 }{7:Xtest-functional-diff-screen-1 [+] }| + :7,8diffget | + ]]) + end) + it('get part of the non linematched diff block in window 2 line 8 - 10 (line matched block)', function() + feed('2w') + feed(':8,10diffget') + screen:expect([[ + {1: }{10: 1 }common line │{1: }{10: 1 }^common line | + {1: }{10: 2 }{4:DEF }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 3 }{8:GHI}{9: }│{1: }{10: 2 }{8:HIL}{9: }| + {1: }{10: 4 }{4:something }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 5 } │{1: }{10: 3 } | + {1: }{10: 6 }{9:a}{8:DEF}{9:abc }│{1: }{10: 4 }{9:a}{8:ABC}{9:abc }| + {1: }{10: 7 }{8:xyz}{9: }│{1: }{10: 5 }{8:aABCabc}{9: }| + {1: }{10: 8 }{8:xyz}{9: }│{1: }{10: 6 }{8:aABCabc}{9: }| + {1: }{10: 9 }{8:xyz}{9: }│{1: }{10: 7 }{8:aABCabc}{9: }| + {1: }{10: 10 }{4:aDEFabc }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 11 }{4:aDEFabc }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 12 }{4:aDEFabc }│{1: }{10: }{2:--------------------------------------------}| + {1: }{10: 13 }common line │{1: }{10: 8 }common line | + {1: }{10: 14 }DEF │{1: }{10: 9 }DEF | + {1: }{10: 15 }GHI │{1: }{10: 10 }GHI | + {1: }{10: 16 }something else │{1: }{10: 11 }something else | + {1: }{10: 17 }common line │{1: }{10: 12 }common line | + {1: }{10: 18 }something │{1: }{10: 13 }something | + {3:Xtest-functional-diff-screen-1.2 }{7:Xtest-functional-diff-screen-1 [+] }| + :8,10diffget | + ]]) + end) + end) +end) -- cgit From 2476f41a4a4dcf940bce9ea9ae48a6017a35fbc2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Nov 2022 19:49:23 +0800 Subject: vim-patch:8.2.1022: various parts of code not covered by tests Problem: Various parts of code not covered by tests. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#6300) https://github.com/vim/vim/commit/845e0ee59430eac07e74b6cb92020e420d17953d Omit test_iminsert.vim: the commit that created this file was N/A. Omit test_viminfo.vim: the added tests are N/A. --- test/functional/legacy/digraph_spec.lua | 46 ++++++++++++++++++++++++ test/functional/legacy/edit_spec.lua | 64 ++++++++++++++++++++++++--------- 2 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 test/functional/legacy/digraph_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/digraph_spec.lua b/test/functional/legacy/digraph_spec.lua new file mode 100644 index 0000000000..0cb0bb84be --- /dev/null +++ b/test/functional/legacy/digraph_spec.lua @@ -0,0 +1,46 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local feed = helpers.feed + +before_each(clear) + +describe('digraph', function() + -- oldtest: Test_entering_digraph() + it('characters displayed on the screen', function() + local screen = Screen.new(10, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {foreground = Screen.colors.Blue}, -- SpecialKey + [2] = {bold = true}, -- ModeMsg + }) + screen:attach() + feed('i') + screen:expect([[ + {1:^?} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT -} | + ]]) + feed('1') + screen:expect([[ + {1:^1} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT -} | + ]]) + feed('2') + screen:expect([[ + ½^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT -} | + ]]) + end) +end) diff --git a/test/functional/legacy/edit_spec.lua b/test/functional/legacy/edit_spec.lua index 7fc5f11a79..362d33a0fd 100644 --- a/test/functional/legacy/edit_spec.lua +++ b/test/functional/legacy/edit_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command local expect = helpers.expect @@ -7,20 +8,51 @@ local sleep = helpers.sleep before_each(clear) --- oldtest: Test_autoindent_remove_indent() -it('autoindent removes indent when Insert mode is stopped', function() - command('set autoindent') - -- leaving insert mode in a new line with indent added by autoindent, should - -- remove the indent. - feed('ifoo') - -- Need to delay for sometime, otherwise the code in getchar.c will not be - -- exercised. - sleep(50) - -- when a line is wrapped and the cursor is at the start of the second line, - -- leaving insert mode, should move the cursor back to the first line. - feed('o' .. ('x'):rep(20) .. '') - -- Need to delay for sometime, otherwise the code in getchar.c will not be - -- exercised. - sleep(50) - expect('\tfoo\n\n' .. ('x'):rep(20)) +describe('edit', function() + -- oldtest: Test_autoindent_remove_indent() + it('autoindent removes indent when Insert mode is stopped', function() + command('set autoindent') + -- leaving insert mode in a new line with indent added by autoindent, should + -- remove the indent. + feed('ifoo') + -- Need to delay for sometime, otherwise the code in getchar.c will not be + -- exercised. + sleep(50) + -- when a line is wrapped and the cursor is at the start of the second line, + -- leaving insert mode, should move the cursor back to the first line. + feed('o' .. ('x'):rep(20) .. '') + -- Need to delay for sometime, otherwise the code in getchar.c will not be + -- exercised. + sleep(50) + expect('\tfoo\n\n' .. ('x'):rep(20)) + end) + + -- oldtest: Test_edit_insert_reg() + it('inserting a register using CTRL-R', function() + local screen = Screen.new(10, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {foreground = Screen.colors.Blue}, -- SpecialKey + [2] = {bold = true}, -- ModeMsg + }) + screen:attach() + feed('a') + screen:expect([[ + {1:^"} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT -} | + ]]) + feed('=') + screen:expect([[ + {1:"} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + =^ | + ]]) + end) end) -- cgit From 19a487bc86482392eb50c61375d20e440e6e16b7 Mon Sep 17 00:00:00 2001 From: Will Spurgin Date: Fri, 4 Nov 2022 20:24:34 -0500 Subject: fix(fileio): use first available directory in backupdir for backupcopy (#20655) Fix backups failing for symlink files Set backup to NULL prior to continuing & Clear backup prior to NULL set to avoid leaking Fixes #11349 Remove testing hacks in scripts for windows Skip FreeBSD Something appears up with these types of tests for FreeBSD on Circus, see 2d6735d8ce --- test/functional/core/fileio_spec.lua | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'test/functional') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 07774866a8..795f639dad 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -1,3 +1,4 @@ +local lfs = require('lfs') local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log @@ -5,6 +6,7 @@ local assert_nolog = helpers.assert_nolog local clear = helpers.clear local command = helpers.command local eq = helpers.eq +local neq = helpers.neq local ok = helpers.ok local feed = helpers.feed local funcs = helpers.funcs @@ -132,6 +134,57 @@ describe('fileio', function() eq('foo', foo_contents); end) + it('backup symlinked files #11349', function() + if isCI('cirrus') then + pending('FIXME: cirrus') + end + clear() + + local initial_content = 'foo' + local link_file_name = 'Xtest_startup_file2' + local backup_file_name = link_file_name .. '~' + + write_file('Xtest_startup_file1', initial_content, false) + lfs.link('Xtest_startup_file1', link_file_name, true) + command('set backup') + command('set backupcopy=yes') + command('edit ' .. link_file_name) + feed('Abar') + command('write') + + local backup_raw = read_file(backup_file_name) + neq(nil, backup_raw, "Expected backup file " .. backup_file_name .. "to exist but did not") + eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents') + end) + + + it('backup symlinked files in first avialable backupdir #11349', function() + if isCI('cirrus') then + pending('FIXME: cirrus') + end + clear() + + local initial_content = 'foo' + local backup_dir = 'Xtest_backupdir' + local sep = helpers.get_pathsep() + local link_file_name = 'Xtest_startup_file2' + local backup_file_name = backup_dir .. sep .. link_file_name .. '~' + + write_file('Xtest_startup_file1', initial_content, false) + lfs.link('Xtest_startup_file1', link_file_name, true) + mkdir(backup_dir) + command('set backup') + command('set backupcopy=yes') + command('set backupdir=.__this_does_not_exist__,' .. backup_dir) + command('edit ' .. link_file_name) + feed('Abar') + command('write') + + local backup_raw = read_file(backup_file_name) + neq(nil, backup_raw, "Expected backup file " .. backup_file_name .. " to exist but did not") + eq(initial_content, trim(backup_raw), 'Expected backup to contain original contents') + end) + it('readfile() on multibyte filename #10586', function() clear() local text = { -- cgit From a86295cd5c2bf15a11eb05e226fd8e226154f6a6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:26:17 +0800 Subject: vim-patch:8.2.0615: regexp benchmark stest is old style (#20940) Problem: Regexp benchmark stest is old style. Solution: Make it a new style test. Fix using a NULL list. Add more tests. (Yegappan Lakshmanan, closes vim/vim#5963) https://github.com/vim/vim/commit/ad48e6c1590842ab6d48e6caba3e9250734dae27 N/A patches: vim-patch:9.0.0829: wrong counts in macro comment --- test/functional/vimscript/null_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua index 2451da983e..1153baac46 100644 --- a/test/functional/vimscript/null_spec.lua +++ b/test/functional/vimscript/null_spec.lua @@ -69,7 +69,7 @@ describe('NULL', function() null_expr_test('can be splice-indexed', 'L[:]', 0, {}) null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) - null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() + null_expr_test('does not crash append()', 'append(0, L)', 0, 0, function() eq({''}, curbufmeths.get_lines(0, -1, false)) end) null_expr_test('does not crash setline()', 'setline(1, L)', 0, 0, function() -- cgit From 6374120558476b9ab0ec4dc1df0523c73756e4ae Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 19:08:25 +0800 Subject: vim-patch:8.2.4501: with 'showbreak' set cursor displayed in wrong position Problem: With 'showbreak' set and after the end of the line the cursor may be displayed in the wrong position. Solution: Do not apply 'showbreak' after the end of the line. (closes vim/vim#9884) https://github.com/vim/vim/commit/21efafe4c25373929979c72dc8aafa119f12dd8b Co-authored-by: Bram Moolenaar --- test/functional/legacy/breakindent_spec.lua | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/functional/legacy/breakindent_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/breakindent_spec.lua b/test/functional/legacy/breakindent_spec.lua new file mode 100644 index 0000000000..d7779684a4 --- /dev/null +++ b/test/functional/legacy/breakindent_spec.lua @@ -0,0 +1,44 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local exec = helpers.exec +local feed = helpers.feed + +before_each(clear) + +describe('breakindent', function() + -- oldtest: Test_cursor_position_with_showbreak() + it('cursor shown at correct position with showbreak', function() + local screen = Screen.new(75, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.Grey, foreground = Screen.colors.DarkBlue}, -- SignColumn + [2] = {bold = true}, -- ModeMsg + }) + screen:attach() + exec([[ + let &signcolumn = 'yes' + let &showbreak = '+' + let leftcol = win_getid()->getwininfo()->get(0, {})->get('textoff') + eval repeat('x', &columns - leftcol - 1)->setline(1) + eval 'second line'->setline(2) + ]]) + screen:expect([[ + {1: }^xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | + {1: }second line | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + feed('AX') + screen:expect([[ + {1: }xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX| + {1: }^second line | + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} | + ]]) + end) +end) -- cgit From 01ccfb40e3ac678829f301aec1d10f5fc06548c6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 20:16:29 +0800 Subject: vim-patch:8.2.1106: crash when trying to use s: variable in typed command Problem: Crash when trying to use s: variable in typed command. Solution: Don't use the script index when not set. (Ken Takata, closes vim/vim#6366) https://github.com/vim/vim/commit/8e6cbb72324b6fb25d1a9abd6cc4d102d0e5f14e --- test/functional/legacy/vimscript_spec.lua | 90 +++++++++++++++++++++++++++++++ test/functional/vimscript/eval_spec.lua | 74 ------------------------- 2 files changed, 90 insertions(+), 74 deletions(-) create mode 100644 test/functional/legacy/vimscript_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/vimscript_spec.lua b/test/functional/legacy/vimscript_spec.lua new file mode 100644 index 0000000000..f59a87f824 --- /dev/null +++ b/test/functional/legacy/vimscript_spec.lua @@ -0,0 +1,90 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local exec = helpers.exec +local feed = helpers.feed +local meths = helpers.meths + +before_each(clear) + +describe('Vim script', function() + -- oldtest: Test_deep_nest() + it('Error when if/for/while/try/function is nested too deep',function() + local screen = Screen.new(80, 24) + screen:attach() + meths.set_option('laststatus', 2) + exec([[ + " Deep nesting of if ... endif + func Test1() + let @a = join(repeat(['if v:true'], 51), "\n") + let @a ..= "\n" + let @a ..= join(repeat(['endif'], 51), "\n") + @a + let @a = '' + endfunc + + " Deep nesting of for ... endfor + func Test2() + let @a = join(repeat(['for i in [1]'], 51), "\n") + let @a ..= "\n" + let @a ..= join(repeat(['endfor'], 51), "\n") + @a + let @a = '' + endfunc + + " Deep nesting of while ... endwhile + func Test3() + let @a = join(repeat(['while v:true'], 51), "\n") + let @a ..= "\n" + let @a ..= join(repeat(['endwhile'], 51), "\n") + @a + let @a = '' + endfunc + + " Deep nesting of try ... endtry + func Test4() + let @a = join(repeat(['try'], 51), "\n") + let @a ..= "\necho v:true\n" + let @a ..= join(repeat(['endtry'], 51), "\n") + @a + let @a = '' + endfunc + + " Deep nesting of function ... endfunction + func Test5() + let @a = join(repeat(['function X()'], 51), "\n") + let @a ..= "\necho v:true\n" + let @a ..= join(repeat(['endfunction'], 51), "\n") + @a + let @a = '' + endfunc + ]]) + screen:expect({any = '%[No Name%]'}) + feed(':call Test1()') + screen:expect({any = 'E579: '}) + feed('') + screen:expect({any = '%[No Name%]'}) + feed(':call Test2()') + screen:expect({any = 'E585: '}) + feed('') + screen:expect({any = '%[No Name%]'}) + feed(':call Test3()') + screen:expect({any = 'E585: '}) + feed('') + screen:expect({any = '%[No Name%]'}) + feed(':call Test4()') + screen:expect({any = 'E601: '}) + feed('') + screen:expect({any = '%[No Name%]'}) + feed(':call Test5()') + screen:expect({any = 'E1058: '}) + end) + + -- oldtest: Test_typed_script_var() + it('using s: with a typed command', function() + local screen = Screen.new(80, 24) + screen:attach() + feed(":echo get(s:, 'foo', 'x')\n") + screen:expect({any = 'E116: '}) + end) +end) diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 64a3cf5471..9b0ace0882 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -16,7 +16,6 @@ local lfs = require('lfs') local clear = helpers.clear local eq = helpers.eq local exc_exec = helpers.exc_exec -local exec = helpers.exec local exec_lua = helpers.exec_lua local exec_capture = helpers.exec_capture local eval = helpers.eval @@ -152,79 +151,6 @@ describe('List support code', function() end) end) --- oldtest: Test_deep_nest() -it('Error when if/for/while/try/function is nested too deep',function() - clear() - local screen = Screen.new(80, 24) - screen:attach() - meths.set_option('laststatus', 2) - exec([[ - " Deep nesting of if ... endif - func Test1() - let @a = join(repeat(['if v:true'], 51), "\n") - let @a ..= "\n" - let @a ..= join(repeat(['endif'], 51), "\n") - @a - let @a = '' - endfunc - - " Deep nesting of for ... endfor - func Test2() - let @a = join(repeat(['for i in [1]'], 51), "\n") - let @a ..= "\n" - let @a ..= join(repeat(['endfor'], 51), "\n") - @a - let @a = '' - endfunc - - " Deep nesting of while ... endwhile - func Test3() - let @a = join(repeat(['while v:true'], 51), "\n") - let @a ..= "\n" - let @a ..= join(repeat(['endwhile'], 51), "\n") - @a - let @a = '' - endfunc - - " Deep nesting of try ... endtry - func Test4() - let @a = join(repeat(['try'], 51), "\n") - let @a ..= "\necho v:true\n" - let @a ..= join(repeat(['endtry'], 51), "\n") - @a - let @a = '' - endfunc - - " Deep nesting of function ... endfunction - func Test5() - let @a = join(repeat(['function X()'], 51), "\n") - let @a ..= "\necho v:true\n" - let @a ..= join(repeat(['endfunction'], 51), "\n") - @a - let @a = '' - endfunc - ]]) - screen:expect({any = '%[No Name%]'}) - feed(':call Test1()') - screen:expect({any = 'E579: '}) - feed('') - screen:expect({any = '%[No Name%]'}) - feed(':call Test2()') - screen:expect({any = 'E585: '}) - feed('') - screen:expect({any = '%[No Name%]'}) - feed(':call Test3()') - screen:expect({any = 'E585: '}) - feed('') - screen:expect({any = '%[No Name%]'}) - feed(':call Test4()') - screen:expect({any = 'E601: '}) - feed('') - screen:expect({any = '%[No Name%]'}) - feed(':call Test5()') - screen:expect({any = 'E1058: '}) -end) - describe("uncaught exception", function() before_each(clear) after_each(function() -- cgit From 850d7146fc7fb57691641c729d5580b834cd7dd2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 12:43:05 +0800 Subject: fix(paste): feed keys as typed in cmdline mode (#20959) --- test/functional/api/vim_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index af6cee7e90..114413365f 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1108,6 +1108,14 @@ describe('API', function() nvim('paste', 'a', true, -1) eq('a', funcs.getcmdline()) end) + it('pasted text is saved in cmdline history when comes from mapping #20957', function() + command('cnoremap ') + feed(':') + nvim('paste', 'echo', true, -1) + eq('', funcs.histget(':')) + feed('') + eq('echo', funcs.histget(':')) + end) it('pasting with empty last chunk in Cmdline mode', function() local screen = Screen.new(20, 4) screen:attach() -- cgit From 1af4bd04f9ad157edbfea30642250e854c5cb5d2 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 6 Nov 2022 18:59:43 +0800 Subject: feat(ui): add support to display a title in the border of a float (#20184) add "title" and "title_pos" keys to win config dict. --- test/functional/ui/cursor_spec.lua | 2 +- test/functional/ui/float_spec.lua | 194 +++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 03cd4bfd06..e261f0dfab 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -215,7 +215,7 @@ describe('ui/cursor', function() m.hl_id = 60 m.attr = {background = Screen.colors.DarkGray} end - if m.id_lm then m.id_lm = 61 end + if m.id_lm then m.id_lm = 62 end end -- Assert the new expectation. diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 9ef36cf5ae..cb90a902d7 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1716,6 +1716,200 @@ describe('float window', function() end end) + it('validates title title_pos', function() + local buf = meths.create_buf(false,false) + eq("title requires border to be set", + pcall_err(meths.open_win,buf, false, { + relative='editor', width=9, height=2, row=2, col=5, title='Title', + })) + eq("title_pos requires title to be set", + pcall_err(meths.open_win,buf, false, { + relative='editor', width=9, height=2, row=2, col=5, + border='single', title_pos='left', + })) + end) + + it('border with title', function() + local buf = meths.create_buf(false, false) + meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', + ' BORDAA '}) + local win = meths.open_win(buf, false, { + relative='editor', width=9, height=2, row=2, col=5, border="double", + title = "Left",title_pos = "left", + }) + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {5:╔}{11:Left}{5:═════╗}| + {5:║}{1: halloj! }{5:║}| + {5:║}{1: BORDAA }{5:║}| + {5:╚═════════╝}| + ]], float_pos={ + [5] = { { id = 1002 }, "NW", 1, 2, 5, true } + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }{5:╔}{11:Left}{5:═════╗}{0: }| + {0:~ }{5:║}{1: halloj! }{5:║}{0: }| + {0:~ }{5:║}{1: BORDAA }{5:║}{0: }| + {0:~ }{5:╚═════════╝}{0: }| + | + ]]} + end + + meths.win_set_config(win, {title= "Center",title_pos="center"}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {5:╔═}{11:Center}{5:══╗}| + {5:║}{1: halloj! }{5:║}| + {5:║}{1: BORDAA }{5:║}| + {5:╚═════════╝}| + ]], float_pos={ + [5] = { { id = 1002 }, "NW", 1, 2, 5, true } + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }{5:╔═}{11:Center}{5:══╗}{0: }| + {0:~ }{5:║}{1: halloj! }{5:║}{0: }| + {0:~ }{5:║}{1: BORDAA }{5:║}{0: }| + {0:~ }{5:╚═════════╝}{0: }| + | + ]]} + end + + meths.win_set_config(win, {title= "Right",title_pos="right"}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {5:╔════}{11:Right}{5:╗}| + {5:║}{1: halloj! }{5:║}| + {5:║}{1: BORDAA }{5:║}| + {5:╚═════════╝}| + ]], float_pos={ + [5] = { { id = 1002 }, "NW", 1, 2, 5, true } + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }{5:╔════}{11:Right}{5:╗}{0: }| + {0:~ }{5:║}{1: halloj! }{5:║}{0: }| + {0:~ }{5:║}{1: BORDAA }{5:║}{0: }| + {0:~ }{5:╚═════════╝}{0: }| + | + ]]} + end + + meths.win_set_config(win, {title= { {"🦄"},{"BB"}},title_pos="right"}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {5:╔═════}🦄BB{5:╗}| + {5:║}{1: halloj! }{5:║}| + {5:║}{1: BORDAA }{5:║}| + {5:╚═════════╝}| + ]], float_pos={ + [5] = { { id = 1002 }, "NW", 1, 2, 5, true } + }, win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }{5:╔═════}🦄BB{5:╗}{0: }| + {0:~ }{5:║}{1: halloj! }{5:║}{0: }| + {0:~ }{5:║}{1: BORDAA }{5:║}{0: }| + {0:~ }{5:╚═════════╝}{0: }| + | + ]]} + end + end) + it('terminates border on edge of viewport when window extends past viewport', function() local buf = meths.create_buf(false, false) meths.open_win(buf, false, {relative='editor', width=40, height=7, row=0, col=0, border="single"}) -- cgit From 72f8613e97e3ab4e375a1b9dd20c847f7148acf2 Mon Sep 17 00:00:00 2001 From: notomo Date: Mon, 7 Nov 2022 10:20:27 +0900 Subject: fix(ui-ext): correct message kind in history before vim.ui_attach() --- test/functional/lua/ui_event_spec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 57ffcf7b4e..6481da900e 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -117,4 +117,31 @@ describe('vim.ui_attach', function() }) eq(0, helpers.eval('v:shell_error')) end) + + it('can receive accurate message kinds even if they are history', function() + exec_lua([[ + vim.cmd.echomsg("'message1'") + print('message2') + vim.ui_attach(ns, { ext_messages = true }, on_event) + vim.cmd.echomsg("'message3'") + ]]) + feed(':messages') + feed('') + + local actual = exec_lua([[ + return vim.tbl_filter(function (event) + return event[1] == "msg_history_show" + end, events) + ]]) + eq({ + { + 'msg_history_show', + { + { 'echomsg', { { 0, 'message1' } } }, + { '', { { 0, 'message2' } } }, + { 'echomsg', { { 0, 'message3' } } }, + }, + }, + }, actual, inspect(actual)) + end) end) -- cgit From 4fd876271a8bc3349fccb14d2e0203af1f9e6698 Mon Sep 17 00:00:00 2001 From: Shougo Date: Mon, 7 Nov 2022 12:02:29 +0900 Subject: vim-patch:9.0.0756 #20680 Problem: No autocmd event for changing text in a terminal window. Solution: Add TextChangedT. (Shougo Matsushita, closes vim/vim#11366) https://github.com/vim/vim/commit/4ccaedfcd7526983f4b6b3b06b0bfb54f333f1f3 --- test/functional/terminal/buffer_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 9d10f43ec6..46d08897e0 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -410,6 +410,14 @@ describe('on_lines does not emit out-of-bounds line indexes when', function() feed_command('bdelete!') eq('', exec_lua([[return _G.cb_error]])) end) + + it('runs TextChangedT event', function() + meths.set_var('called', 0) + command('autocmd TextChangedT * ++once let g:called = 1') + feed_command('terminal') + feed('iaa') + eq(1, meths.get_var('called')) + end) end) it('terminal truncates number of composing characters to 5', function() -- cgit From d337814906b1377e34aa2c2dfd8aa16285328692 Mon Sep 17 00:00:00 2001 From: Victor Blanchard <48864055+Viblanc@users.noreply.github.com> Date: Mon, 7 Nov 2022 04:31:50 +0100 Subject: feat: ":write ++p" creates parent dirs #20835 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `:write ++p foo/bar/baz.txt` should create parent directories `foo/bar/` if they do not exist - Note: `:foo ++…` is usually for options. No existing options have a single-char abbreviation (presumably by design), so it's safe to special-case `++p` here. - Same for `writefile(…, 'foo/bar/baz.txt', 'p')` - `BufWriteCmd` can see the ++p flag via `v:cmdarg`. closes #19884 --- test/functional/ex_cmds/write_spec.lua | 27 +++++++++++++++++++++++++++ test/functional/vimscript/writefile_spec.lua | 20 ++++++++++++++++++++ 2 files changed, 47 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 4045d13153..d6b5c54de9 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -20,6 +20,9 @@ describe(':write', function() os.remove('test_bkc_file.txt') os.remove('test_bkc_link.txt') os.remove('test_fifo') + os.remove('test/write/p_opt.txt') + os.remove('test/write') + os.remove('test') os.remove(fname) os.remove(fname_bak) os.remove(fname_broken) @@ -94,6 +97,30 @@ describe(':write', function() fifo:close() end) + it("++p creates missing parent directories", function() + eq(0, eval("filereadable('p_opt.txt')")) + command("write ++p p_opt.txt") + eq(1, eval("filereadable('p_opt.txt')")) + os.remove("p_opt.txt") + + eq(0, eval("filereadable('p_opt.txt')")) + command("write ++p ./p_opt.txt") + eq(1, eval("filereadable('p_opt.txt')")) + os.remove("p_opt.txt") + + eq(0, eval("filereadable('test/write/p_opt.txt')")) + command("write ++p test/write/p_opt.txt") + eq(1, eval("filereadable('test/write/p_opt.txt')")) + + eq(('Vim(write):E32: No file name'), pcall_err(command, 'write ++p test_write/')) + if not iswin() then + eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), + pcall_err(command, 'write ++p .')) + eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), + pcall_err(command, 'write ++p ./')) + end + end) + it('errors out correctly', function() if isCI('cirrus') then pending('FIXME: cirrus') diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index 5f693249a9..8c8da9dc88 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -111,6 +111,26 @@ describe('writefile()', function() pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail))) end) + it('writefile(..., "p") creates missing parent directories', function() + os.remove(dname) + eq(nil, read_file(dfname)) + eq(0, funcs.writefile({'abc', 'def', 'ghi'}, dfname, 'p')) + eq('abc\ndef\nghi\n', read_file(dfname)) + os.remove(dfname) + os.remove(dname) + eq(nil, read_file(dfname)) + eq(0, funcs.writefile({'\na\nb\n'}, dfname, 'pb')) + eq('\0a\0b\0', read_file(dfname)) + os.remove(dfname) + os.remove(dname) + eq('Vim(call):E32: No file name', + pcall_err(command, ('call writefile([], "%s", "p")'):format(dfname .. '.d/'))) + eq(('Vim(call):E482: Can\'t open file ./ for writing: illegal operation on a directory'), + pcall_err(command, 'call writefile([], "./", "p")')) + eq(('Vim(call):E482: Can\'t open file . for writing: illegal operation on a directory'), + pcall_err(command, 'call writefile([], ".", "p")')) + end) + it('errors out with invalid arguments', function() write_file(fname, 'TEST') eq('Vim(call):E119: Not enough arguments for function: writefile', -- cgit From c022140ec6a66402e405152054b6ab0141940419 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 7 Nov 2022 22:27:37 +0600 Subject: feat(api): add command name to Lua command callback opts Adds a `name` key to the opts dict passed to Lua command callbacks created using `nvim_create_user_command()`. This is useful for when multiple commands use the same callback. Note that this kind of behavior is not as strange as one might think, even some internal Neovim commands reuse the same internal C function, differing their behavior by checking the command name. `substitute`, `smagic` and `snomagic` are examples of that. This will also be useful for generalized Lua command preview functions that can preview a wide range of commands, in which case knowing the command name is necessary for the preview function to actually be able to execute the command that it's supposed to preview. --- test/functional/api/command_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index f19d7a362b..d0fb26edc7 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -114,6 +114,7 @@ describe('nvim_create_user_command', function() ]] eq({ + name = "CommandWithLuaCallback", args = [[this\ is a\ test]], fargs = {"this ", "is", "a test"}, bang = false, @@ -150,6 +151,7 @@ describe('nvim_create_user_command', function() ]=]) eq({ + name = "CommandWithLuaCallback", args = [[this includes\ a backslash: \\]], fargs = {"this", "includes a", "backslash:", "\\"}, bang = false, @@ -186,6 +188,7 @@ describe('nvim_create_user_command', function() ]=]) eq({ + name = "CommandWithLuaCallback", args = "a\\b", fargs = {"a\\b"}, bang = false, @@ -222,6 +225,7 @@ describe('nvim_create_user_command', function() ]=]) eq({ + name = "CommandWithLuaCallback", args = 'h\tey ', fargs = {[[h]], [[ey]]}, bang = true, @@ -258,6 +262,7 @@ describe('nvim_create_user_command', function() ]=]) eq({ + name = "CommandWithLuaCallback", args = "h", fargs = {"h"}, bang = false, @@ -294,6 +299,7 @@ describe('nvim_create_user_command', function() ]]) eq({ + name = "CommandWithLuaCallback", args = "", fargs = {}, -- fargs works without args bang = false, @@ -342,6 +348,7 @@ describe('nvim_create_user_command', function() ]] eq({ + name = "CommandWithOneOrNoArg", args = "hello I'm one argument", fargs = {"hello I'm one argument"}, -- Doesn't split args bang = false, @@ -379,6 +386,7 @@ describe('nvim_create_user_command', function() -- f-args is an empty table if no args were passed eq({ + name = "CommandWithOneOrNoArg", args = "", fargs = {}, bang = false, @@ -427,6 +435,7 @@ describe('nvim_create_user_command', function() }) ]] eq({ + name = "CommandWithNoArgs", args = "", fargs = {}, bang = false, @@ -463,6 +472,7 @@ describe('nvim_create_user_command', function() ]]) -- register can be specified eq({ + name = "CommandWithNoArgs", args = "", fargs = {}, bang = false, -- cgit From 8147d3df284a075f89746f9d5e948b5220c45f0b Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Tue, 8 Nov 2022 00:21:22 +0100 Subject: vim-patch:9.0.0844: handling 'statusline' errors is spread out (#20992) Problem: Handling 'statusline' errors is spread out. Solution: Pass the option name to the lower levels so the option can be reset there when an error is encountered. (Luuk van Baal, closes vim/vim#11467) https://github.com/vim/vim/commit/7b224fdf4a29f115567d4fc8629c1cef92d8444a --- test/functional/lua/ffi_spec.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua index 80c01a2b8c..3969a7a478 100644 --- a/test/functional/lua/ffi_spec.lua +++ b/test/functional/lua/ffi_spec.lua @@ -35,11 +35,12 @@ describe('ffi.cdef', function() int build_stl_str_hl( win_T *wp, - char_u *out, + char *out, size_t outlen, - char_u *fmt, - int use_sandbox, - char_u fillchar, + char *fmt, + char *opt_name, + int opt_scope, + int fillchar, int maxwidth, stl_hlrec_t **hltab, StlClickRecord **tabtab @@ -48,9 +49,10 @@ describe('ffi.cdef', function() return ffi.C.build_stl_str_hl( ffi.C.find_window_by_handle(0, ffi.new('Error')), - ffi.new('char_u[1024]'), + ffi.new('char[1024]'), 1024, - ffi.cast('char_u*', 'StatusLineOfLength20'), + ffi.cast('char*', 'StatusLineOfLength20'), + nil, 0, 0, 0, -- cgit From 59ff4691f67fc1ddd3d1b7240a2f2eb095e58281 Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Mon, 7 Nov 2022 19:15:15 -0500 Subject: fix(vim.ui.input): return empty string when inputs nothing (#20883) fix(vim.ui.input): return empty string when inputs nothing The previous behavior of `vim.ui.input()` when typing with no text input (with an intention of having the empty string as input) was to execute `on_confirm(nil)`, conflicting with its documentation. Inputting an empty string should now correctly execute `on_confirm('')`. This should be clearly distinguished from cancelling or aborting the input UI, in which case `on_confirm(nil)` is executed as before. --- test/functional/lua/ui_spec.lua | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index 3fcb2dec8d..8f9d8e0f72 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -83,5 +83,51 @@ describe('vim.ui', function() feed('abcdefg') eq('abcdefg', exec_lua('return result')) end) + + it('can input empty text #18144', function() + feed(':lua vim.ui.input({}, function(input) result = input end)') + feed('') + eq('', exec_lua('return result')) + end) + + it('can input empty text with cancelreturn opt #18144', function() + feed(':lua vim.ui.input({ cancelreturn = "CANCEL" }, function(input) result = input end)') + feed('') + eq('', exec_lua('return result')) + end) + + it('can return nil when aborted with ESC #18144', function() + feed(':lua result = "on_confirm not called"') + feed(':lua vim.ui.input({}, function(input) result = input end)') + feed('Inputted Text') + -- Note: When `result == nil`, exec_lua('returns result') returns vim.NIL + eq(true, exec_lua('return (nil == result)')) + end) + + it('can return opts.cacelreturn when aborted with ESC with cancelreturn opt #18144', function() + feed(':lua result = "on_confirm not called"') + feed(':lua vim.ui.input({ cancelreturn = "CANCEL" }, function(input) result = input end)') + feed('Inputted Text') + eq('CANCEL', exec_lua('return result')) + end) + + it('does not call on_confirm when interrupted with Ctrl-C #18144', function() + feed(':lua result = "on_confirm not called"') + eq('on_confirm not called', exec_lua('return result')) + feed(':lua vim.ui.input({}, function(input) result = input end)') + feed('Inputted Text') + -- Ctrl-C would make vim.ui.input() throw, so `result = input` won't be executed + eq('on_confirm not called', exec_lua('return result')) + end) + + it('can return the identical object when an arbitrary opts.cancelreturn object is given', function() + feed(':lua fn = function() return 42 end') + eq(42, exec_lua('return fn()')) + feed(':lua vim.ui.input({ cancelreturn = fn }, function(input) result = input end)') + feed('cancel') + eq(true, exec_lua('return (result == fn)')) + eq(42, exec_lua('return result()')) + end) + end) end) -- cgit From f2857dcd5abaf3a5aee9271b79ffa4eee345d21c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 10 Nov 2022 06:16:54 +0800 Subject: fix(messages): reset msg_grid_scroll_discount when redrawing (#21000) --- test/functional/ui/messages_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index a042291b54..8ca29e79d9 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -10,9 +10,11 @@ local async_meths = helpers.async_meths local test_build_dir = helpers.test_build_dir local nvim_prog = helpers.nvim_prog local iswin = helpers.iswin +local exec = helpers.exec local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua local poke_eventloop = helpers.poke_eventloop +local assert_alive = helpers.assert_alive describe('ui/ext_messages', function() local screen @@ -1236,6 +1238,17 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim end) end) +it('calling screenstring() after redrawing between messages without UI #20999', function() + clear() + exec([[ + echo repeat('a', 100) + redraw + echo "\n" + call screenstring(1, 1) + ]]) + assert_alive() +end) + describe('ui/ext_messages', function() local screen -- cgit From fc7ac688c397b5f748920597fcc70fe46e907944 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 11 Nov 2022 16:46:45 +0800 Subject: fix(messages): don't set cmdline_row when messages have scrolled (#21015) When 'cmdheight' is changed while messages have scrolled, the position of msg_grid is not moved up, so cmdline_row should not be set based on the position of msg_grid. --- test/functional/ui/messages_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 8ca29e79d9..60b538eee5 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -1236,6 +1236,34 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim bar^ | ]]) end) + + it('consecutive calls to win_move_statusline() work after multiline message #21014',function() + async_meths.exec([[ + echo "\n" + call win_move_statusline(0, -4) + call win_move_statusline(0, 4) + ]], false) + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {3: }| + | + {4:Press ENTER or type command to continue}^ | + ]]) + feed('') + screen:expect([[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + eq(1, meths.get_option('cmdheight')) + end) end) it('calling screenstring() after redrawing between messages without UI #20999', function() -- cgit From 2425fe2dc5e5985779912319433ddf914a20dd6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Nov 2022 09:57:29 +0800 Subject: vim-patch:8.2.2207: illegal memory access if popup menu items are changed (#21028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Illegal memory access if popup menu items are changed while the menu is visible. (Tomáš Janoušek) Solution: Make a copy of the text. (closes vim/vim#7537) https://github.com/vim/vim/commit/38455a921395a56690790c8c1d28c1c43ca04c8a Co-authored-by: Bram Moolenaar --- test/functional/ex_cmds/map_spec.lua | 2 + test/functional/legacy/search_stat_spec.lua | 4 + test/functional/ui/highlight_spec.lua | 9 ++ test/functional/ui/popupmenu_spec.lua | 160 ++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index c6bdd017bd..dd9f7027cf 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -161,6 +161,7 @@ describe('Screen', function() ]]) end) + -- oldtest: Test_expr_map_restore_cursor() it('cursor is restored after :map which redraws statusline vim-patch:8.1.2336', function() exec([[ call setline(1, ['one', 'two', 'three']) @@ -246,6 +247,7 @@ describe('Screen', function() ]]) end) + -- oldtest: Test_map_listing() it('listing mappings clears command line vim-patch:8.2.4401', function() screen:try_resize(40, 5) command('nmap a b') diff --git a/test/functional/legacy/search_stat_spec.lua b/test/functional/legacy/search_stat_spec.lua index c2ca393a56..9fcf798836 100644 --- a/test/functional/legacy/search_stat_spec.lua +++ b/test/functional/legacy/search_stat_spec.lua @@ -17,6 +17,7 @@ describe('search stat', function() screen:attach() end) + -- oldtest: Test_search_stat_screendump() it('right spacing with silent mapping vim-patch:8.1.1970', function() exec([[ set shortmess-=S @@ -57,6 +58,7 @@ describe('search stat', function() ]]) end) + -- oldtest: Test_search_stat_foldopen() it('when only match is in fold vim-patch:8.2.0840', function() exec([[ set shortmess-=S @@ -86,6 +88,7 @@ describe('search stat', function() screen:expect_unchanged() end) + -- oldtest: Test_search_stat_then_gd() it('is cleared by gd and gD vim-patch:8.2.3583', function() exec([[ call setline(1, ['int cat;', 'int dog;', 'cat = dog;']) @@ -120,6 +123,7 @@ describe('search stat', function() ]]) end) + -- oldtest: Test_search_stat_and_incsearch() it('is not broken by calling searchcount() in tabline vim-patch:8.2.4378', function() exec([[ call setline(1, ['abc--c', '--------abc', '--abc']) diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 504a38d591..173d422334 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -1048,6 +1048,7 @@ describe('CursorLine and CursorLineNr highlights', function() ]]) end) + -- oldtest: Test_cursorline_after_yank() it('always updated. vim-patch:8.1.0849', function() local screen = Screen.new(50,5) screen:set_default_attr_ids({ @@ -1081,6 +1082,7 @@ describe('CursorLine and CursorLineNr highlights', function() ]]) end) + -- oldtest: Test_cursorline_with_visualmode() it('with visual area. vim-patch:8.1.1001', function() local screen = Screen.new(50,5) screen:set_default_attr_ids({ @@ -1108,6 +1110,7 @@ describe('CursorLine and CursorLineNr highlights', function() ]]) end) + -- oldtest: Test_cursorline_callback() it('is updated if cursor is moved up from timer vim-patch:8.2.4591', function() local screen = Screen.new(50, 8) screen:set_default_attr_ids({ @@ -1237,6 +1240,7 @@ describe('CursorLine and CursorLineNr highlights', function() }) end) + -- oldtest: Test_diff_with_cursorline_number() it('CursorLineNr shows correctly just below filler lines', function() local screen = Screen.new(50,12) screen:set_default_attr_ids({ @@ -1357,6 +1361,7 @@ describe('CursorColumn highlight', function() ]]) end) + -- oldtest: Test_cursorcolumn_callback() it('is updated if cursor is moved from timer', function() exec([[ call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd']) @@ -1412,6 +1417,7 @@ describe('ColorColumn highlight', function() screen:attach() end) + -- oldtest: Test_colorcolumn() it('when entering a buffer vim-patch:8.1.2073', function() exec([[ set nohidden @@ -1443,6 +1449,7 @@ describe('ColorColumn highlight', function() ]]) end) + -- oldtest: Test_colorcolumn_bri() it("in 'breakindent' vim-patch:8.2.1689", function() exec([[ call setline(1, 'The quick brown fox jumped over the lazy dogs') @@ -1467,6 +1474,7 @@ describe('ColorColumn highlight', function() ]]) end) + -- oldtest: Test_colorcolumn_sbr() it("in 'showbreak' vim-patch:8.2.1689", function() exec([[ call setline(1, 'The quick brown fox jumped over the lazy dogs') @@ -1686,6 +1694,7 @@ describe("'number' and 'relativenumber' highlight", function() ]]) end) + -- oldtest: Test_relativenumber_callback() it('relative number highlight is updated if cursor is moved from timer', function() local screen = Screen.new(50, 8) screen:set_default_attr_ids({ diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 33e201eb68..e43eef4dfd 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -967,6 +967,7 @@ describe('builtin popupmenu', function() [4] = {bold = true, reverse = true}, [5] = {bold = true, foreground = Screen.colors.SeaGreen}, [6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + [7] = {background = Screen.colors.Yellow}, -- Search }) end) @@ -3037,6 +3038,165 @@ describe('builtin popupmenu', function() eq(false, screen.options.mousemoveevent) eq('bar', meths.get_var('menustr')) end) + + -- oldtest: Test_popup_command() + it(':popup command', function() + exec([[ + menu Test.Foo Foo + call assert_fails('popup Test.Foo', 'E336:') + call assert_fails('popup Test.Foo.X', 'E327:') + call assert_fails('popup Foo', 'E337:') + unmenu Test.Foo + ]]) + eq({}, meths.get_vvar('errors')) + + exec([[ + func ChangeMenu() + aunmenu PopUp.&Paste + nnoremenu 1.40 PopUp.&Paste :echomsg "pasted" + echomsg 'changed' + return "\" + endfunc + + let lines =<< trim END + one two three four five + and one two Xthree four five + one more two three four five + END + call setline(1, lines) + + aunmenu * + source $VIMRUNTIME/menu.vim + ]]) + feed('/X:popup PopUp') + screen:expect([[ + one two three four five | + and one two {7:^X}three four five | + one more tw{n: Undo } | + {1:~ }{n: }{1: }| + {1:~ }{n: Paste }{1: }| + {1:~ }{n: }{1: }| + {1:~ }{n: Select Word }{1: }| + {1:~ }{n: Select Sentence }{1: }| + {1:~ }{n: Select Paragraph }{1: }| + {1:~ }{n: Select Line }{1: }| + {1:~ }{n: Select Block }{1: }| + {1:~ }{n: Select All }{1: }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :popup PopUp | + ]]) + + -- go to the Paste entry in the menu + feed('jj') + screen:expect([[ + one two three four five | + and one two {7:^X}three four five | + one more tw{n: Undo } | + {1:~ }{n: }{1: }| + {1:~ }{s: Paste }{1: }| + {1:~ }{n: }{1: }| + {1:~ }{n: Select Word }{1: }| + {1:~ }{n: Select Sentence }{1: }| + {1:~ }{n: Select Paragraph }{1: }| + {1:~ }{n: Select Line }{1: }| + {1:~ }{n: Select Block }{1: }| + {1:~ }{n: Select All }{1: }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :popup PopUp | + ]]) + + -- Select a word + feed('j') + screen:expect([[ + one two three four five | + and one two {7:^X}three four five | + one more tw{n: Undo } | + {1:~ }{n: }{1: }| + {1:~ }{n: Paste }{1: }| + {1:~ }{n: }{1: }| + {1:~ }{s: Select Word }{1: }| + {1:~ }{n: Select Sentence }{1: }| + {1:~ }{n: Select Paragraph }{1: }| + {1:~ }{n: Select Line }{1: }| + {1:~ }{n: Select Block }{1: }| + {1:~ }{n: Select All }{1: }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :popup PopUp | + ]]) + + feed('') + + -- Set an mapping to change a menu entry while it's displayed. + -- The text should not change but the command does. + -- Also verify that "changed" shows up, which means the mapping triggered. + command('nnoremap ChangeMenu()') + feed('/X:popup PopUp') + screen:expect([[ + one two three four five | + and one two {7:^X}three four five | + one more tw{n: Undo } | + {1:~ }{n: }{1: }| + {1:~ }{n: Paste }{1: }| + {1:~ }{n: }{1: }| + {1:~ }{n: Select Word }{1: }| + {1:~ }{n: Select Sentence }{1: }| + {1:~ }{n: Select Paragraph }{1: }| + {1:~ }{n: Select Line }{1: }| + {1:~ }{n: Select Block }{1: }| + {1:~ }{n: Select All }{1: }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + changed | + ]]) + + -- Select the Paste entry, executes the changed menu item. + feed('jj') + screen:expect([[ + one two three four five | + and one two {7:^X}three four five | + one more two three four five | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + pasted | + ]]) + end) end) describe('builtin popupmenu with ui/ext_multigrid', function() -- cgit From 4d2373f5f6570fcc851b818198f45fbda391fd6a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 11 Nov 2022 21:33:31 -0500 Subject: feat(checkhealth): use "help" syntax, avoid tabpage #20879 - If Nvim was just started, don't create a new tab. - Name the buffer "health://". - Use "help" syntax instead of "markdown". It fits better, and eliminates various workarounds. - Simplfy formatting, avoid visual noise. - Don't print a "INFO" status, it is noisy. - Drop the ":" after statuses, they are already UPPERCASE and highlighted. --- test/functional/plugin/health_spec.lua | 175 ++++++++++++++++++--------------- 1 file changed, 94 insertions(+), 81 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index c970a03fcf..97d32313e5 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -29,7 +29,7 @@ describe(':checkhealth', function() -- Do this after startup, otherwise it just breaks $VIMRUNTIME. command("let $VIM='zub'") command("checkhealth nvim") - matches('ERROR: $VIM .* zub', curbuf_contents()) + matches('ERROR $VIM .* zub', curbuf_contents()) end) it('completions can be listed via getcompletion()', function() clear() @@ -55,21 +55,22 @@ describe('health.vim', function() command("checkhealth full_render") helpers.expect([[ + ============================================================================== full_render: health#full_render#check - ======================================================================== - ## report 1 - - OK: life is fine - - WARNING: no what installed - - ADVICE: - - pip what - - make what - - ## report 2 - - INFO: stuff is stable - - ERROR: why no hardcopy - - ADVICE: - - :help |:hardcopy| - - :help |:TOhtml| + + report 1 ~ + - OK life is fine + - WARNING no what installed + - ADVICE: + - pip what + - make what + + report 2 ~ + - stuff is stable + - ERROR why no hardcopy + - ADVICE: + - :help |:hardcopy| + - :help |:TOhtml| ]]) end) @@ -77,26 +78,29 @@ describe('health.vim', function() command("checkhealth success1 success2 test_plug") helpers.expect([[ + ============================================================================== success1: health#success1#check - ======================================================================== - ## report 1 - - OK: everything is fine - ## report 2 - - OK: nothing to see here + report 1 ~ + - OK everything is fine + + report 2 ~ + - OK nothing to see here + ============================================================================== success2: health#success2#check - ======================================================================== - ## another 1 - - OK: ok + another 1 ~ + - OK ok + + ============================================================================== test_plug: require("test_plug.health").check() - ======================================================================== - ## report 1 - - OK: everything is fine - ## report 2 - - OK: nothing to see here + report 1 ~ + - OK everything is fine + + report 2 ~ + - OK nothing to see here ]]) end) @@ -106,13 +110,14 @@ describe('health.vim', function() -- and the Lua healthcheck is used instead. helpers.expect([[ + ============================================================================== test_plug: require("test_plug.health").check() - ======================================================================== - ## report 1 - - OK: everything is fine - ## report 2 - - OK: nothing to see here + report 1 ~ + - OK everything is fine + + report 2 ~ + - OK nothing to see here ]]) end) @@ -120,13 +125,14 @@ describe('health.vim', function() command("checkhealth test_plug.submodule") helpers.expect([[ + ============================================================================== test_plug.submodule: require("test_plug.submodule.health").check() - ======================================================================== - ## report 1 - - OK: everything is fine - ## report 2 - - OK: nothing to see here + report 1 ~ + - OK everything is fine + + report 2 ~ + - OK nothing to see here ]]) end) @@ -137,30 +143,34 @@ describe('health.vim', function() local received = table.concat(buf_lines, '\n', 1, #buf_lines - 5) local expected = helpers.dedent([[ + ============================================================================== test_plug: require("test_plug.health").check() - ======================================================================== - ## report 1 - - OK: everything is fine - ## report 2 - - OK: nothing to see here + report 1 ~ + - OK everything is fine + + report 2 ~ + - OK nothing to see here + ============================================================================== test_plug.submodule: require("test_plug.submodule.health").check() - ======================================================================== - ## report 1 - - OK: everything is fine - ## report 2 - - OK: nothing to see here + report 1 ~ + - OK everything is fine + report 2 ~ + - OK nothing to see here + + ============================================================================== test_plug.submodule_empty: require("test_plug.submodule_empty.health").check() - ======================================================================== - - ERROR: The healthcheck report for "test_plug.submodule_empty" plugin is empty. + - ERROR The healthcheck report for "test_plug.submodule_empty" plugin is empty. + + ============================================================================== test_plug.submodule_failed: require("test_plug.submodule_failed.health").check() - ======================================================================== - - ERROR: Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception: - function health#check, line 20]]) + + - ERROR Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception: + function health#check, line 25]]) eq(expected, received) end) @@ -168,11 +178,12 @@ describe('health.vim', function() command("checkhealth broken") helpers.expect([[ + ============================================================================== broken: health#broken#check - ======================================================================== - - ERROR: Failed to run healthcheck for "broken" plugin. Exception: - function health#check[20]..health#broken#check, line 1 - caused an error + + - ERROR Failed to run healthcheck for "broken" plugin. Exception: + function health#check[25]..health#broken#check, line 1 + caused an error ]]) end) @@ -180,9 +191,10 @@ describe('health.vim', function() command("checkhealth test_plug.submodule_empty") helpers.expect([[ + ============================================================================== test_plug.submodule_empty: require("test_plug.submodule_empty.health").check() - ======================================================================== - - ERROR: The healthcheck report for "test_plug.submodule_empty" plugin is empty. + + - ERROR The healthcheck report for "test_plug.submodule_empty" plugin is empty. ]]) end) @@ -197,38 +209,38 @@ describe('health.vim', function() local expected = global_helpers.dedent([[ + ============================================================================== test_plug.submodule_failed: require("test_plug.submodule_failed.health").check() - ======================================================================== - - ERROR: Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception: - function health#check, line 20]]) + + - ERROR Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception: + function health#check, line 25]]) eq(expected, received) end) it("highlights OK, ERROR", function() - local screen = Screen.new(72, 10) + local screen = Screen.new(50, 12) screen:attach() screen:set_default_attr_ids({ Ok = { foreground = Screen.colors.Grey3, background = 6291200 }, Error = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, - Heading = { bold=true, foreground=Screen.colors.Magenta }, - Heading2 = { foreground = Screen.colors.SlateBlue }, - Bar = { foreground = 0x6a0dad }, - Bullet = { bold=true, foreground=Screen.colors.Brown }, + Heading = { foreground = tonumber('0x6a0dad') }, + Bar = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGrey }, }) command("checkhealth foo success1") - command("1tabclose") - command("set laststatus=0") + command("set nowrap laststatus=0") screen:expect{grid=[[ - ^ | - {Heading:foo: } | - {Bar:========================================================================}| - {Bullet: -} {Error:ERROR}: No healthcheck found for "foo" plugin. | - | - {Heading:success1: health#success1#check} | - {Bar:========================================================================}| - {Heading2:## }{Heading:report 1} | - {Bullet: -} {Ok:OK}: everything is fine | - | + ^ | + {Bar:──────────────────────────────────────────────────}| + {Heading:foo: } | + | + - {Error:ERROR} No healthcheck found for "foo" plugin. | + | + {Bar:──────────────────────────────────────────────────}| + {Heading:success1: health#success1#check} | + | + {Heading:report 1} | + - {Ok:OK} everything is fine | + | ]]} end) @@ -237,9 +249,10 @@ describe('health.vim', function() -- luacheck: ignore 613 helpers.expect([[ + ============================================================================== non_existent_healthcheck: - ======================================================================== - - ERROR: No healthcheck found for "non_existent_healthcheck" plugin. + + - ERROR No healthcheck found for "non_existent_healthcheck" plugin. ]]) end) -- cgit From 7e6d785d19926714615758e75c4d43e856d13a6f Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Tue, 13 Sep 2022 09:44:24 +0200 Subject: feat(extmarks): allow preventing spellchecking with spell = false --- test/functional/ui/decorations_spec.lua | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 5b62f5b3e1..489c33d8b1 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -176,7 +176,13 @@ describe('decorations providers', function() beamtrace = {} local function on_do(kind, ...) if kind == 'win' or kind == 'spell' then - a.nvim_buf_set_extmark(0, ns, 0, 0, { end_row = 2, end_col = 23, spell = true, ephemeral = true }) + a.nvim_buf_set_extmark(0, ns, 0, 0, { + end_row = 2, + end_col = 23, + spell = true, + priority = 20, + ephemeral = true + }) end table.insert(beamtrace, {kind, ...}) end @@ -234,6 +240,36 @@ describe('decorations providers', function() {1:~ }| | ]]} + + -- spell=false with lower priority doesn't disable spell + local ns = meths.create_namespace "spell" + local id = helpers.curbufmeths.set_extmark(ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false }) + + screen:expect{grid=[[ + I am well written text. | + i am not capitalized. | + I am a ^speling mistakke. | + | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + -- spell=false with higher priority does disable spell + helpers.curbufmeths.set_extmark(ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false }) + + screen:expect{grid=[[ + I am well written text. | + {15:i} am not capitalized. | + I am a {16:^speling} {16:mistakke}. | + | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + end) it('can predefine highlights', function() -- cgit From b3f781ba912b0d24896d85fc8434faaedfddfeb2 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Sat, 12 Nov 2022 06:57:35 -0800 Subject: fix: vim.ui.input always calls callback #21006 Followup to #20883 Related: #18144 This patch changes the behavior of the default `vim.ui.input` when the user aborts with ``. Currently, it produces an error message + stack and causes `on_confirm` to not be called. With this patch, `` will cause `on_confirm` to be called with `nil`, the same behavior as when the user aborts with ``. I can think of three good reasons why the behavior should be this way: 1. Easier for the user to understand** It's not intuitive for there to be two ways to abort an input dialog that have _different_ outcomes. As a user, I would expect any action that cancels the input to leave me in the same state. As a plugin author, I see no value in having two possible outcomes for aborting the input. I have to handle both cases, but I can't think of a situation where I would want to treat one differently than the other. 2. Provides an API that can be overridden by other implementations** The current contract of "throw an error upon ``" cannot be replicated by async implementations of `vim.ui.input`. If the callsite wants to handle the case of the user hitting `` they need to use `pcall(vim.ui.input, ...)`, however an async implementation will instantly return and so there will be no way for it to produce the same error-throwing behavior when the user inputs ``. This makes it impossible to be fully API-compatible with the built-in `vim.ui.input`. 3. Provides a useful guarantee to the callsite** As a plugin author, I want the guarantee that `on_confirm` will _always_ be called (only catastrophic errors should prevent this). If I am in the middle of some async thread of logic, I need some way to resume that logic after handing off control to `vim.ui.input`. The only way to handle the `` case is with `pcall`, which as already mentioned, breaks down if you're using an alternative implementation. --- test/functional/lua/ui_spec.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index 8f9d8e0f72..c34d947b8b 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -111,13 +111,11 @@ describe('vim.ui', function() eq('CANCEL', exec_lua('return result')) end) - it('does not call on_confirm when interrupted with Ctrl-C #18144', function() + it('can return nil when interrupted with Ctrl-C #18144', function() feed(':lua result = "on_confirm not called"') - eq('on_confirm not called', exec_lua('return result')) feed(':lua vim.ui.input({}, function(input) result = input end)') feed('Inputted Text') - -- Ctrl-C would make vim.ui.input() throw, so `result = input` won't be executed - eq('on_confirm not called', exec_lua('return result')) + eq(true, exec_lua('return (nil == result)')) end) it('can return the identical object when an arbitrary opts.cancelreturn object is given', function() -- cgit From 47ad4c8701b4233aa302c1c21ff08a5f223596c7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Nov 2022 07:06:37 +0800 Subject: vim-patch:9.0.0866: no test for what patch 8.2.2207 fixes (#21034) Problem: No test for what patch 8.2.2207 fixes. Solution: Add a test case. (closes vim/vim#11531) https://github.com/vim/vim/commit/f7570f2107d91f35dc67dd0e400fc638585b226c --- test/functional/ui/popupmenu_spec.lua | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index e43eef4dfd..7e81d1a577 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -3039,17 +3039,8 @@ describe('builtin popupmenu', function() eq('bar', meths.get_var('menustr')) end) - -- oldtest: Test_popup_command() + -- oldtest: Test_popup_command_dump() it(':popup command', function() - exec([[ - menu Test.Foo Foo - call assert_fails('popup Test.Foo', 'E336:') - call assert_fails('popup Test.Foo.X', 'E327:') - call assert_fails('popup Foo', 'E337:') - unmenu Test.Foo - ]]) - eq({}, meths.get_vvar('errors')) - exec([[ func ChangeMenu() aunmenu PopUp.&Paste -- cgit From e7ba5ba3cd8e426d07a8359a3d85a62b095faf61 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Nov 2022 08:16:06 +0800 Subject: test(lua/ui_spec): fix Ctrl-C test flakiness (#21039) Prevent Ctrl-C from flushing the command that starts the prompt. --- test/functional/lua/ui_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index c34d947b8b..9ee99b4905 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -4,6 +4,7 @@ local exec_lua = helpers.exec_lua local clear = helpers.clear local feed = helpers.feed local eval = helpers.eval +local poke_eventloop = helpers.poke_eventloop describe('vim.ui', function() before_each(function() @@ -114,6 +115,7 @@ describe('vim.ui', function() it('can return nil when interrupted with Ctrl-C #18144', function() feed(':lua result = "on_confirm not called"') feed(':lua vim.ui.input({}, function(input) result = input end)') + poke_eventloop() -- This is needed because Ctrl-C flushes input feed('Inputted Text') eq(true, exec_lua('return (nil == result)')) end) -- cgit From d7e7578ada343eab090643eb698bd146d5bbfd27 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 12 Nov 2022 16:41:36 +0100 Subject: fix(ui): fix some cases of stale highlight definitions fixes #20695 --- test/functional/ui/highlight_spec.lua | 91 +++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 31 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 173d422334..bcb437a55d 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -1743,38 +1743,40 @@ describe("'winhighlight' highlight", function() clear() screen = Screen.new(20,8) screen:attach() - screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - [1] = {background = Screen.colors.DarkBlue}, - [2] = {background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Blue1}, - [3] = {bold = true, reverse = true}, - [4] = {reverse = true}, - [5] = {background = Screen.colors.DarkGreen}, - [6] = {background = Screen.colors.DarkGreen, bold = true, foreground = Screen.colors.Blue1}, - [7] = {background = Screen.colors.DarkMagenta}, - [8] = {background = Screen.colors.DarkMagenta, bold = true, foreground = Screen.colors.Blue1}, - [9] = {foreground = Screen.colors.Brown}, - [10] = {foreground = Screen.colors.Brown, background = Screen.colors.DarkBlue}, - [11] = {background = Screen.colors.DarkBlue, bold = true, reverse = true}, - [12] = {background = Screen.colors.DarkGreen, reverse = true}, - [13] = {background = Screen.colors.Magenta4, reverse = true}, - [14] = {background = Screen.colors.DarkBlue, reverse = true}, - [15] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [16] = {foreground = Screen.colors.Blue1}, - [17] = {background = Screen.colors.LightRed}, - [18] = {background = Screen.colors.Gray90}, - [19] = {foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray}, - [20] = {background = Screen.colors.LightGrey, underline = true}, - [21] = {bold = true}, - [22] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [23] = {background = Screen.colors.LightMagenta}, - [24] = {background = Screen.colors.WebGray}, - [25] = {bold = true, foreground = Screen.colors.Green1}, - [26] = {background = Screen.colors.Red}, - [27] = {background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Green1}, - [28] = {bold = true, foreground = Screen.colors.Brown}, + screen:set_default_attr_ids { + [0] = {bold=true, foreground=Screen.colors.Blue}; + [1] = {background = Screen.colors.DarkBlue}; + [2] = {background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Blue1}; + [3] = {bold = true, reverse = true}; + [4] = {reverse = true}; + [5] = {background = Screen.colors.DarkGreen}; + [6] = {background = Screen.colors.DarkGreen, bold = true, foreground = Screen.colors.Blue1}; + [7] = {background = Screen.colors.DarkMagenta}; + [8] = {background = Screen.colors.DarkMagenta, bold = true, foreground = Screen.colors.Blue1}; + [9] = {foreground = Screen.colors.Brown}; + [10] = {foreground = Screen.colors.Brown, background = Screen.colors.DarkBlue}; + [11] = {background = Screen.colors.DarkBlue, bold = true, reverse = true}; + [12] = {background = Screen.colors.DarkGreen, reverse = true}; + [13] = {background = Screen.colors.Magenta4, reverse = true}; + [14] = {background = Screen.colors.DarkBlue, reverse = true}; + [15] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}; + [16] = {foreground = Screen.colors.Blue1}; + [17] = {background = Screen.colors.LightRed}; + [18] = {background = Screen.colors.Gray90}; + [19] = {foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray}; + [20] = {background = Screen.colors.LightGrey, underline = true}; + [21] = {bold = true}; + [22] = {bold = true, foreground = Screen.colors.SeaGreen4}; + [23] = {background = Screen.colors.LightMagenta}; + [24] = {background = Screen.colors.WebGray}; + [25] = {bold = true, foreground = Screen.colors.Green1}; + [26] = {background = Screen.colors.Red}; + [27] = {background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Green1}; + [28] = {bold = true, foreground = Screen.colors.Brown}; [29] = {foreground = Screen.colors.Blue1, background = Screen.colors.Red, bold = true}; - }) + [30] = {background = tonumber('0xff8800')}; + [31] = {background = tonumber('0xff8800'), bold = true, foreground = Screen.colors.Blue}; + } command("hi Background1 guibg=DarkBlue") command("hi Background2 guibg=DarkGreen") end) @@ -2019,6 +2021,33 @@ describe("'winhighlight' highlight", function() ]]) end) + it('updates background to changed linked group', function() + command("split") + command("setlocal winhl=Normal:FancyGroup") -- does not yet exist + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + {3:[No Name] }| + | + {0:~ }| + {4:[No Name] }| + | + ]]} + + command("hi FancyGroup guibg=#FF8800") -- nice orange + screen:expect{grid=[[ + {30:^ }| + {31:~ }| + {31:~ }| + {3:[No Name] }| + | + {0:~ }| + {4:[No Name] }| + | + ]]} + end) + it('background applies also to non-text', function() command('set sidescroll=0') insert('Lorem ipsum dolor sit amet ') -- cgit From 736c36c02f316c979da363c5120495179a2b6c2a Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 13 Nov 2022 14:52:19 +0100 Subject: test: introduce skip() #21010 This is essentially a convenience wrapper around the `pending()` function, similar to `skip_fragile()` but more general-purpose. Also remove `pending_win32` function as it can be replaced by `skip(iswin())`. --- test/functional/api/server_notifications_spec.lua | 9 ++------- test/functional/api/server_requests_spec.lua | 2 +- test/functional/api/vim_spec.lua | 3 ++- test/functional/autocmd/focus_spec.lua | 2 +- test/functional/autocmd/signal_spec.lua | 7 +++---- test/functional/autocmd/termxx_spec.lua | 5 +++-- test/functional/core/channels_spec.lua | 6 ++++-- test/functional/core/fileio_spec.lua | 21 ++++++--------------- test/functional/core/job_spec.lua | 11 ++++++----- test/functional/core/main_spec.lua | 4 +++- test/functional/ex_cmds/cd_spec.lua | 6 +++--- test/functional/ex_cmds/mksession_spec.lua | 6 ++---- test/functional/ex_cmds/write_spec.lua | 12 ++++-------- test/functional/helpers.lua | 11 ++++------- test/functional/legacy/filechanged_spec.lua | 4 +++- test/functional/lua/uri_spec.lua | 4 +++- test/functional/plugin/lsp_spec.lua | 4 +++- test/functional/plugin/man_spec.lua | 5 ++--- test/functional/provider/perl_spec.lua | 6 ++++-- test/functional/shada/shada_spec.lua | 4 +++- test/functional/terminal/altscreen_spec.lua | 2 +- test/functional/terminal/api_spec.lua | 3 +-- test/functional/terminal/buffer_spec.lua | 4 +++- test/functional/terminal/cursor_spec.lua | 12 +++++++----- test/functional/terminal/edit_spec.lua | 2 +- test/functional/terminal/ex_terminal_spec.lua | 20 +++++++++----------- test/functional/terminal/highlight_spec.lua | 10 ++++++---- test/functional/terminal/mouse_spec.lua | 14 ++++++++------ test/functional/terminal/scrollback_spec.lua | 11 ++++++----- test/functional/terminal/tui_spec.lua | 2 +- test/functional/terminal/window_spec.lua | 7 +++---- test/functional/treesitter/parser_spec.lua | 6 ++++-- test/functional/ui/hlstate_spec.lua | 3 ++- test/functional/ui/output_spec.lua | 11 ++++------- 34 files changed, 118 insertions(+), 121 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 1c00f001ff..77a80ac7f3 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -7,6 +7,7 @@ local exec_lua = helpers.exec_lua local retry = helpers.retry local isCI = helpers.isCI local assert_alive = helpers.assert_alive +local skip = helpers.skip describe('notify', function() local channel @@ -78,13 +79,7 @@ describe('notify', function() end) it('cancels stale events on channel close', function() - if isCI() then - pending('hangs on CI #14083 #15251') - return - elseif helpers.skip_fragile(pending) then - return - end - if helpers.pending_win32(pending) then return end + skip(isCI(), '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 ([[ diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 00a4dd041d..045de94de2 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -250,7 +250,7 @@ describe('server -> client', function() pcall(funcs.jobstop, jobid) end) - if helpers.pending_win32(pending) then return end + if helpers.skip(helpers.iswin()) then return end it('rpc and text stderr can be combined', function() local status, rv = pcall(funcs.rpcrequest, jobid, 'poll') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 114413365f..32b7c349b2 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -30,6 +30,7 @@ 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 local format_string = helpers.format_string @@ -2729,7 +2730,7 @@ describe('API', function() eq({}, meths.get_runtime_file("foobarlang/", true)) end) it('can handle bad patterns', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) eq("Vim:E220: Missing }.", pcall_err(meths.get_runtime_file, "{", false)) diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua index e3c9e1f9ee..b5fc6b7600 100644 --- a/test/functional/autocmd/focus_spec.lua +++ b/test/functional/autocmd/focus_spec.lua @@ -6,7 +6,7 @@ local nvim_prog = helpers.nvim_prog local feed_command = helpers.feed_command local feed_data = thelpers.feed_data -if helpers.pending_win32(pending) then return end +if helpers.skip(helpers.iswin()) then return end describe('autoread TUI FocusGained/FocusLost', function() local f1 = 'xtest-foo' diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua index d4f65cc61d..bbe1c186b2 100644 --- a/test/functional/autocmd/signal_spec.lua +++ b/test/functional/autocmd/signal_spec.lua @@ -5,11 +5,10 @@ local command = helpers.command local eq = helpers.eq local funcs = helpers.funcs local next_msg = helpers.next_msg +local iswin = helpers.iswin +local skip = helpers.skip -if helpers.pending_win32(pending) then - -- Only applies to POSIX systems. - return -end +if skip(iswin(), 'Only applies to POSIX systems') then return end local function posix_kill(signame, pid) os.execute('kill -s '..signame..' -- '..pid..' >/dev/null') diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index a38f9cb0ac..5601965bd9 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -11,6 +11,7 @@ local feed = helpers.feed local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive local iswin = helpers.iswin +local skip = helpers.skip describe('autocmd TermClose', function() before_each(function() @@ -55,7 +56,7 @@ describe('autocmd TermClose', function() end) it('kills job trapping SIGTERM', function() - if iswin() then return end + skip(iswin()) nvim('set_option', 'shell', 'sh') nvim('set_option', 'shellcmdflag', '-c') command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] @@ -75,7 +76,7 @@ describe('autocmd TermClose', function() end) it('kills PTY job trapping SIGHUP and SIGTERM', function() - if iswin() then return end + skip(iswin()) nvim('set_option', 'shell', 'sh') nvim('set_option', 'shellcmdflag', '-c') command([[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index ca52404d3b..63bd85ff43 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -12,6 +12,8 @@ local retry = helpers.retry local expect_twostreams = helpers.expect_twostreams local assert_alive = helpers.assert_alive local pcall_err = helpers.pcall_err +local iswin = helpers.iswin +local skip = helpers.skip describe('channels', function() local init = [[ @@ -145,7 +147,7 @@ describe('channels', function() end it('can use stdio channel with pty', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) source([[ let g:job_opts = { \ 'on_stdout': function('OnEvent'), @@ -199,7 +201,7 @@ describe('channels', function() it('stdio channel can use rpc and stderr simultaneously', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) source([[ let g:job_opts = { \ 'on_stderr': function('OnEvent'), diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 795f639dad..00b9074e29 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -28,6 +28,7 @@ local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') local feed_command = helpers.feed_command local isCI = helpers.isCI +local skip = helpers.skip describe('fileio', function() before_each(function() @@ -89,9 +90,7 @@ describe('fileio', function() end) it('backup #9709', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) @@ -111,9 +110,7 @@ describe('fileio', function() end) it('backup with full path #11214', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) clear() mkdir('Xtest_backupdir') command('set backup') @@ -135,9 +132,7 @@ describe('fileio', function() end) it('backup symlinked files #11349', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) clear() local initial_content = 'foo' @@ -159,9 +154,7 @@ describe('fileio', function() it('backup symlinked files in first avialable backupdir #11349', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) clear() local initial_content = 'foo' @@ -306,9 +299,7 @@ describe('tmpdir', function() end) -- "…/nvim./" has wrong permissions: - if iswin() then - return -- TODO(justinmk): need setfperm/getfperm on Windows. #8244 - end + skip(iswin(), 'TODO(justinmk): need setfperm/getfperm on Windows. #8244') os.remove(testlog) os.remove(tmproot) mkdir(tmproot) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 02ff18bdda..4e5c4ca351 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -23,6 +23,7 @@ local expect_msg_seq = helpers.expect_msg_seq local pcall_err = helpers.pcall_err local matches = helpers.matches local Screen = require('test.functional.ui.screen') +local skip = helpers.skip describe('jobs', function() local channel @@ -87,7 +88,7 @@ describe('jobs', function() end) it('append environment with pty #env', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") nvim('command', "let g:job_opts.pty = v:true") @@ -225,7 +226,7 @@ describe('jobs', function() end) it('error on non-executable `cwd`', function() - if iswin() then return end -- N/A for Windows + skip(iswin(), 'Not applicable for Windows') local dir = 'Xtest_not_executable_dir' mkdir(dir) @@ -805,7 +806,7 @@ describe('jobs', function() end) it('can be called recursively', function() - if helpers.pending_win32(pending) then return end -- TODO: Need `cat`. + skip(iswin(), "TODO: Need `cat`") source([[ let g:opts = {} let g:counter = 0 @@ -1027,7 +1028,7 @@ describe('jobs', function() end) describe('running tty-test program', function() - if helpers.pending_win32(pending) then return end + if skip(iswin()) then return end local function next_chunk() local rv while true do @@ -1124,7 +1125,7 @@ describe("pty process teardown", function() end) it("does not prevent/delay exit. #4798 #4900", function() - if helpers.pending_win32(pending) then return end + skip(iswin()) -- Use a nested nvim (in :term) to test without --headless. feed_command(":terminal '"..helpers.nvim_prog .."' -u NONE -i NONE --cmd '"..nvim_set.."' " diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index f6fb859ccc..782a03bfed 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -9,6 +9,8 @@ local clear = helpers.clear local funcs = helpers.funcs local nvim_prog_abs = helpers.nvim_prog_abs local write_file = helpers.write_file +local iswin = helpers.iswin +local skip = helpers.skip describe('Command-line option', function() describe('-s', function() @@ -49,7 +51,7 @@ describe('Command-line option', function() eq(#('100500\n'), attrs.size) end) it('does not crash after reading from stdin in non-headless mode', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) local screen = Screen.new(40, 8) screen:attach() local args = { diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index 42a811f5da..d2135d0613 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -9,6 +9,8 @@ local clear = helpers.clear local command = helpers.command local exc_exec = helpers.exc_exec local pathsep = helpers.get_pathsep() +local iswin = helpers.iswin +local skip = helpers.skip -- These directories will be created for testing local directories = { @@ -279,9 +281,7 @@ describe("getcwd()", function () end) it("returns empty string if working directory does not exist", function() - if helpers.iswin() then - return - end + skip(iswin()) command("cd "..directories.global) command("call delete('../"..directories.global.."', 'd')") eq("", helpers.eval("getcwd()")) diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index ee8da2932d..b7ff6a7bf7 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -14,6 +14,7 @@ local pesc = helpers.pesc local rmdir = helpers.rmdir local sleep = helpers.sleep local meths = helpers.meths +local skip = helpers.skip local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec' @@ -194,10 +195,7 @@ describe(':mksession', function() end) it('restores CWD for :terminal buffer at root directory #16988', function() - if iswin() then - pending('N/A for Windows') - return - end + skip(iswin(), 'N/A for Windows') local screen local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index d6b5c54de9..e2a6b6460d 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -10,6 +10,7 @@ local funcs = helpers.funcs local meths = helpers.meths local iswin = helpers.iswin local isCI = helpers.isCI +local skip = helpers.skip local fname = 'Xtest-functional-ex_cmds-write' local fname_bak = fname .. '~' @@ -56,9 +57,7 @@ describe(':write', function() end) it('&backupcopy=no replaces symlink with new file', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) command('set backupcopy=no') write_file('test_bkc_file.txt', 'content0') if iswin() then @@ -122,9 +121,7 @@ describe(':write', function() end) it('errors out correctly', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) command('let $HOME=""') eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) -- Message from check_overwrite @@ -155,8 +152,7 @@ describe(':write', function() eq(true, os.remove(fname_bak)) end write_file(fname_bak, 'TTYX') - -- FIXME: exc_exec('write!') outputs 0 in Windows - if iswin() then return end + skip(iswin(), [[FIXME: exc_exec('write!') outputs 0 in Windows]]) lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true) eq('Vim(write):E166: Can\'t open linked file for writing', pcall_err(command, 'write!')) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 723d2ccfa4..f0a85785b3 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -763,13 +763,10 @@ function module.create_callindex(func) return table end --- Helper to skip tests. Returns true in Windows systems. --- pending_fn is pending() from busted -function module.pending_win32(pending_fn) - if iswin() then - if pending_fn ~= nil then - pending_fn('FIXME: Windows', function() end) - end +function module.skip(cond, reason) + if cond then + local pending = getfenv(2).pending + pending(reason or 'FIXME') return true else return false diff --git a/test/functional/legacy/filechanged_spec.lua b/test/functional/legacy/filechanged_spec.lua index 1f23528d61..747eca1c45 100644 --- a/test/functional/legacy/filechanged_spec.lua +++ b/test/functional/legacy/filechanged_spec.lua @@ -1,6 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear, source = helpers.clear, helpers.source local call, eq, meths = helpers.call, helpers.eq, helpers.meths +local iswin = helpers.iswin +local skip = helpers.skip local function expected_empty() eq({}, meths.get_vvar('errors')) @@ -15,7 +17,7 @@ describe('file changed dialog', function() end) it('works', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) source([[ func Test_file_changed_dialog() au! FileChangedShell diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua index 2cb0b26c6d..38c7801d55 100644 --- a/test/functional/lua/uri_spec.lua +++ b/test/functional/lua/uri_spec.lua @@ -2,6 +2,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq +local iswin = helpers.iswin +local skip = helpers.skip local write_file = require('test.helpers').write_file describe('URI methods', function() @@ -167,7 +169,7 @@ describe('URI methods', function() describe('uri from bufnr', function() it('Windows paths should not be treated as uris', function() - if not helpers.iswin() then return end + skip(not iswin(), "Not applicable on non-Windows") local file = helpers.tmpname() write_file(file, 'Test content') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index a7094fff48..572d7a7d97 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -19,13 +19,15 @@ local read_file = require('test.helpers').read_file local write_file = require('test.helpers').write_file local isCI = helpers.isCI local meths = helpers.meths +local iswin = helpers.iswin +local skip = helpers.skip -- Use these to get access to a coroutine so that I can run async tests and use -- yield. local run, stop = helpers.run, helpers.stop -- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837 -if helpers.pending_win32(pending) then return end +if skip(iswin()) then return end -- Fake LSP server. local fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index ebf131fd4a..c57f43c632 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -9,6 +9,7 @@ local matches = helpers.matches local write_file = helpers.write_file local tmpname = helpers.tmpname local isCI = helpers.isCI +local skip = helpers.skip clear() if funcs.executable('man') == 0 then @@ -161,9 +162,7 @@ describe(':Man', function() end) it('reports non-existent man pages for absolute paths', function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end + skip(isCI('cirrus')) local actual_file = tmpname() -- actual_file must be an absolute path to an existent file for us to test against it matches('^/.+', actual_file) diff --git a/test/functional/provider/perl_spec.lua b/test/functional/provider/perl_spec.lua index aff5e36e24..4c5c3ece15 100644 --- a/test/functional/provider/perl_spec.lua +++ b/test/functional/provider/perl_spec.lua @@ -9,6 +9,8 @@ local curbufmeths = helpers.curbufmeths local insert = helpers.insert local expect = helpers.expect local feed = helpers.feed +local iswin = helpers.iswin +local skip = helpers.skip do clear() @@ -24,7 +26,7 @@ before_each(function() end) describe('legacy perl provider', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) it('feature test', function() eq(1, eval('has("perl")')) @@ -68,7 +70,7 @@ describe('legacy perl provider', function() end) describe('perl provider', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) teardown(function () os.remove('Xtest-perl-hello.pl') os.remove('Xtest-perl-hello-plugin.pl') diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index f5a81eb2ef..210c09e187 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -5,6 +5,8 @@ local meths, nvim_command, funcs, eq = local write_file, spawn, set_session, nvim_prog, exc_exec = helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.exc_exec +local iswin = helpers.iswin +local skip = helpers.skip local lfs = require('lfs') local paths = require('test.cmakeconfig.paths') @@ -248,7 +250,7 @@ describe('ShaDa support code', function() end) it('does not crash when ShaDa file directory is not writable', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) funcs.mkdir(dirname, '', 0) eq(0, funcs.filewritable(dirname)) diff --git a/test/functional/terminal/altscreen_spec.lua b/test/functional/terminal/altscreen_spec.lua index e4e1aa5fa2..457a5aa18f 100644 --- a/test/functional/terminal/altscreen_spec.lua +++ b/test/functional/terminal/altscreen_spec.lua @@ -6,7 +6,7 @@ local feed_data = thelpers.feed_data local enter_altscreen = thelpers.enter_altscreen local exit_altscreen = thelpers.exit_altscreen -if helpers.pending_win32(pending) then return end +if helpers.skip(helpers.iswin()) then return end describe(':terminal altscreen', function() local screen diff --git a/test/functional/terminal/api_spec.lua b/test/functional/terminal/api_spec.lua index 5305b8af9c..b5697c4c6b 100644 --- a/test/functional/terminal/api_spec.lua +++ b/test/functional/terminal/api_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local child_session = require('test.functional.terminal.helpers') local ok = helpers.ok -if helpers.pending_win32(pending) then return end +if helpers.skip(helpers.iswin()) then return end describe('api', function() local screen @@ -67,4 +67,3 @@ describe('api', function() socket_session1:request("nvim_command", "qa!") end) end) - diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 46d08897e0..5a75af69c0 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -15,6 +15,8 @@ local matches = helpers.matches local exec_lua = helpers.exec_lua local sleep = helpers.sleep local funcs = helpers.funcs +local iswin = helpers.iswin +local skip = helpers.skip describe(':terminal buffer', function() local screen @@ -262,7 +264,7 @@ describe(':terminal buffer', function() end) it('it works with set rightleft #11438', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) local columns = eval('&columns') feed(string.rep('a', columns)) command('set rightleft') diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index 2d1c790d2f..fdd7b9407b 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -9,6 +9,8 @@ local matches = helpers.matches local feed_command = helpers.feed_command local hide_cursor = thelpers.hide_cursor local show_cursor = thelpers.show_cursor +local iswin = helpers.iswin +local skip = helpers.skip describe(':terminal cursor', function() local screen @@ -88,7 +90,7 @@ describe(':terminal cursor', function() describe('when invisible', function() it('is not highlighted and is detached from screen cursor', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) hide_cursor() screen:expect([[ tty ready | @@ -361,7 +363,7 @@ describe('buffer cursor position is correct in terminal without number column', end) describe('in a line with single-cell composed multibyte characters and no trailing spaces,', function() - if helpers.pending_win32(pending) then return end -- These tests fail on Windows. Encoding problem? + if skip(iswin(), "Encoding problem?") then return end before_each(function() setup_ex_register('µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳') @@ -444,7 +446,7 @@ describe('buffer cursor position is correct in terminal without number column', end) describe('in a line with double-cell multibyte characters and no trailing spaces,', function() - if helpers.pending_win32(pending) then return end -- These tests fail on Windows. Encoding problem? + skip(iswin(), "Encoding problem?") before_each(function() setup_ex_register('哦哦哦哦哦哦哦哦') @@ -741,7 +743,7 @@ describe('buffer cursor position is correct in terminal with number column', fun end) describe('in a line with single-cell composed multibyte characters and no trailing spaces,', function() - if helpers.pending_win32(pending) then return end -- These tests fail on Windows. Encoding problem? + if skip(iswin(), "Encoding problem?") then return end before_each(function() setup_ex_register('µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳') @@ -824,7 +826,7 @@ describe('buffer cursor position is correct in terminal with number column', fun end) describe('in a line with double-cell multibyte characters and no trailing spaces,', function() - if helpers.pending_win32(pending) then return end -- These tests fail on Windows. Encoding problem? + skip(iswin(), "Encoding problem?") before_each(function() setup_ex_register('哦哦哦哦哦哦哦哦') diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index aeb4b7cc2e..95ee561d2b 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -36,7 +36,7 @@ describe(':edit term://*', function() end) it("runs TermOpen early enough to set buffer-local 'scrollback'", function() - if helpers.pending_win32(pending) then return end + if helpers.skip(helpers.iswin()) then return end local columns, lines = 20, 4 local scr = get_screen(columns, lines) local rep = 97 diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index a423bc9a5a..48254faa31 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -11,6 +11,7 @@ local ok = helpers.ok local iswin = helpers.iswin local command = helpers.command local isCI = helpers.isCI +local skip = helpers.skip describe(':terminal', function() local screen @@ -46,10 +47,7 @@ describe(':terminal', function() end) it("reads output buffer on terminal reporting #4151", function() - if isCI('cirrus') then - pending('FIXME: cirrus') - end - if helpers.pending_win32(pending) then return end + skip(isCI('cirrus') or iswin()) if iswin() then feed_command([[terminal powershell -NoProfile -NoLogo -Command Write-Host -NoNewline "\"$([char]27)[6n\""; Start-Sleep -Milliseconds 500 ]]) else @@ -146,7 +144,7 @@ describe(':terminal (with fake shell)', function() end it('with no argument, acts like termopen()', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) terminal_with_fake_shell() retry(nil, 4 * screen.timeout, function() screen:expect([[ @@ -170,7 +168,7 @@ describe(':terminal (with fake shell)', function() end) it("with no argument, but 'shell' has arguments, acts like termopen()", function() - if helpers.pending_win32(pending) then return end + skip(iswin()) nvim('set_option', 'shell', testprg('shell-test')..' -t jeff') terminal_with_fake_shell() screen:expect([[ @@ -182,7 +180,7 @@ describe(':terminal (with fake shell)', function() end) it('executes a given command through the shell', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell('echo hi') screen:expect([[ @@ -194,7 +192,7 @@ describe(':terminal (with fake shell)', function() end) it("executes a given command through the shell, when 'shell' has arguments", function() - if helpers.pending_win32(pending) then return end + skip(iswin()) nvim('set_option', 'shell', testprg('shell-test')..' -t jeff') command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell('echo hi') @@ -207,7 +205,7 @@ describe(':terminal (with fake shell)', function() end) it('allows quotes and slashes', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell([[echo 'hello' \ "world"]]) screen:expect([[ @@ -244,7 +242,7 @@ describe(':terminal (with fake shell)', function() end) it('works with :find', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) terminal_with_fake_shell() screen:expect([[ ^ready $ | @@ -263,7 +261,7 @@ describe(':terminal (with fake shell)', function() end) it('works with gf', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell([[echo "scripts/shadacat.py"]]) retry(nil, 4 * screen.timeout, function() diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index a119d4acd3..3e121405d8 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -7,6 +7,8 @@ local nvim_prog_abs = helpers.nvim_prog_abs local eq, eval = helpers.eq, helpers.eval local funcs = helpers.funcs local nvim_set = helpers.nvim_set +local iswin = helpers.iswin +local skip = helpers.skip describe(':terminal highlight', function() local screen @@ -58,7 +60,7 @@ describe(':terminal highlight', function() end) local function pass_attrs() - if helpers.pending_win32(pending) then return end + skip(iswin()) screen:expect(sub([[ tty ready | {NUM:text}text{10: } | @@ -73,7 +75,7 @@ describe(':terminal highlight', function() it('will pass the corresponding attributes', pass_attrs) it('will pass the corresponding attributes on scrollback', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) pass_attrs() local lines = {} for i = 1, 8 do @@ -197,7 +199,7 @@ describe(':terminal highlight forwarding', function() end) it('will handle cterm and rgb attributes', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) thelpers.set_fg(3) thelpers.feed_data('text') thelpers.feed_termcode('[38:2:255:128:0m') @@ -249,7 +251,7 @@ describe(':terminal highlight with custom palette', function() end) it('will use the custom color', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) thelpers.set_fg(3) thelpers.feed_data('text') thelpers.clear_attrs() diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 6e2c851df7..a062a77a14 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -3,6 +3,8 @@ local thelpers = require('test.functional.terminal.helpers') local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval local feed, nvim, command = helpers.feed, helpers.nvim, helpers.command local feed_data = thelpers.feed_data +local iswin = helpers.iswin +local skip = helpers.skip describe(':terminal mouse', function() local screen @@ -66,7 +68,7 @@ describe(':terminal mouse', function() end) it('does not leave terminal mode on left-release', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) feed('') eq('t', eval('mode(1)')) end) @@ -87,7 +89,7 @@ describe(':terminal mouse', function() end) it('will forward mouse press, drag and release to the program', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) feed('<1,2>') screen:expect([[ line27 | @@ -131,7 +133,7 @@ describe(':terminal mouse', function() end) it('will forward mouse scroll to the program', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) feed('<0,0>') screen:expect([[ line27 | @@ -145,7 +147,7 @@ describe(':terminal mouse', function() end) it('dragging and scrolling do not interfere with each other', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) feed('<1,2>') screen:expect([[ line27 | @@ -199,7 +201,7 @@ describe(':terminal mouse', function() end) it('will forward mouse clicks to the program with the correct even if set nu', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) command('set number') -- When the display area such as a number is clicked, it returns to the -- normal mode. @@ -230,7 +232,7 @@ describe(':terminal mouse', function() end) describe('with a split window and other buffer', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) before_each(function() feed(':vsp') screen:expect([[ diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index b491cb2735..873445f281 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -15,6 +15,7 @@ local feed_data = thelpers.feed_data local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua local assert_alive = helpers.assert_alive +local skip = helpers.skip describe(':terminal scrollback', function() local screen @@ -139,7 +140,7 @@ describe(':terminal scrollback', function() describe('and height decreased by 1', function() - if helpers.pending_win32(pending) then return end + if skip(iswin()) then return end local function will_hide_top_line() feed([[]]) screen:try_resize(screen._width - 2, screen._height - 1) @@ -185,7 +186,7 @@ describe(':terminal scrollback', function() -- XXX: Can't test this reliably on Windows unless the cursor is _moved_ -- by the resize. http://docs.libuv.org/en/v1.x/signal.html -- See also: https://github.com/rprichard/winpty/issues/110 - if helpers.pending_win32(pending) then return end + if skip(iswin()) then return end describe('and the height is decreased by 2', function() before_each(function() @@ -264,7 +265,7 @@ describe(':terminal scrollback', function() -- XXX: Can't test this reliably on Windows unless the cursor is _moved_ -- by the resize. http://docs.libuv.org/en/v1.x/signal.html -- See also: https://github.com/rprichard/winpty/issues/110 - if helpers.pending_win32(pending) then return end + if skip(iswin()) then return end local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) screen:expect([[ @@ -346,7 +347,7 @@ end) describe(':terminal prints more lines than the screen height and exits', function() it('will push extra lines to scrollback', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) clear() local screen = Screen.new(30, 7) screen:attach({rgb=false}) @@ -606,7 +607,7 @@ describe("pending scrollback line handling", function() end) it("does not crash after nvim_buf_call #14891", function() - if helpers.pending_win32(pending) then return end + skip(iswin()) exec_lua [[ local a = vim.api local bufnr = a.nvim_create_buf(false, true) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 3c56ad5f79..d2e409cc0f 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -23,7 +23,7 @@ local read_file = helpers.read_file local funcs = helpers.funcs local meths = helpers.meths -if helpers.pending_win32(pending) then return end +if helpers.skip(helpers.iswin()) then return end describe('TUI', function() local screen diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index 0d3295cf32..81cd1017db 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -8,6 +8,7 @@ local command = helpers.command local retry = helpers.retry local eq = helpers.eq local eval = helpers.eval +local skip = helpers.skip describe(':terminal window', function() local screen @@ -18,7 +19,7 @@ describe(':terminal window', function() end) it('sets topline correctly #8556', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) -- Test has hardcoded assumptions of dimensions. eq(7, eval('&lines')) feed_data('\n\n\n') -- Add blank lines. @@ -54,9 +55,7 @@ describe(':terminal window', function() {3:-- TERMINAL --} | ]]) - if iswin() then - return -- win: :terminal resize is unreliable #7007 - end + skip(iswin(), 'win: :terminal resize is unreliable #7007') -- numberwidth=9 feed([[]]) diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua index ccbd55df0e..22348c7e20 100644 --- a/test/functional/treesitter/parser_spec.lua +++ b/test/functional/treesitter/parser_spec.lua @@ -5,6 +5,8 @@ local eq = helpers.eq local insert = helpers.insert local exec_lua = helpers.exec_lua local feed = helpers.feed +local iswin = helpers.iswin +local skip = helpers.skip before_each(clear) @@ -12,7 +14,7 @@ describe('treesitter parser API', function() clear() it('parses buffer', function() - if helpers.pending_win32(pending) then return end + skip(iswin()) insert([[ int main() { @@ -684,7 +686,7 @@ int x = INT_MAX; end) it("should not inject bad languages", function() - if helpers.pending_win32(pending) then return end + skip(iswin()) exec_lua([=[ vim.treesitter.add_directive("inject-bad!", function(match, _, _, pred, metadata) metadata.language = "{" diff --git a/test/functional/ui/hlstate_spec.lua b/test/functional/ui/hlstate_spec.lua index dc74d6d401..a8b4c05747 100644 --- a/test/functional/ui/hlstate_spec.lua +++ b/test/functional/ui/hlstate_spec.lua @@ -7,6 +7,7 @@ local meths = helpers.meths local iswin = helpers.iswin local testprg = helpers.testprg local thelpers = require('test.functional.terminal.helpers') +local skip = helpers.skip describe('ext_hlstate detailed highlights', function() local screen @@ -182,7 +183,7 @@ describe('ext_hlstate detailed highlights', function() end) it("work with :terminal", function() - if helpers.pending_win32(pending) then return end + skip(iswin()) screen:set_default_attr_ids({ [1] = {{}, {{hi_name = "TermCursorNC", ui_name = "TermCursorNC", kind = "ui"}}}, diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua index 9bb067ed8e..0825772d57 100644 --- a/test/functional/ui/output_spec.lua +++ b/test/functional/ui/output_spec.lua @@ -13,6 +13,7 @@ local testprg = helpers.testprg local nvim_dir = helpers.nvim_dir local has_powershell = helpers.has_powershell local set_shell_powershell = helpers.set_shell_powershell +local skip = helpers.skip describe("shell command :!", function() local screen @@ -36,7 +37,7 @@ describe("shell command :!", function() end) it("displays output without LF/EOF. #4646 #4569 #3772", function() - if helpers.pending_win32(pending) then return end + skip(iswin()) -- NOTE: We use a child nvim (within a :term buffer) -- to avoid triggering a UI flush. child_session.feed_data(":!printf foo; sleep 200\n") @@ -52,9 +53,7 @@ describe("shell command :!", function() end) it("throttles shell-command output greater than ~10KB", function() - if 'openbsd' == helpers.uname() then - pending('FIXME #10804') - end + skip('openbsd' == helpers.uname(), 'FIXME #10804') child_session.feed_data((":!%s REP 30001 foo\n"):format(testprg('shell-test'))) -- If we observe any line starting with a dot, then throttling occurred. @@ -96,9 +95,7 @@ describe("shell command :!", function() end) it('handles control codes', function() - if iswin() then - pending('missing printf') - end + skip(iswin(), 'missing printf') local screen = Screen.new(50, 4) screen:set_default_attr_ids { [1] = {bold = true, reverse = true}; -- cgit From 5c5187c6f809c50e2cfd0ba04961ae8e0d2dabd0 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 14 Nov 2022 09:28:30 +0100 Subject: test: remove skip for 32-bit MSVC (#21030) We don't support 32-bit windows anymore so it's not needed. --- test/functional/api/vim_spec.lua | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 32b7c349b2..7c24f32f74 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2324,12 +2324,6 @@ describe('API', function() meths.set_option('isident', '') end) - local it_maybe_pending = it - if helpers.isCI() and os.getenv('CONFIGURATION') == 'MSVC_32' then - -- For "works with &opt" (flaky on MSVC_32), but not easy to skip alone. #10241 - it_maybe_pending = pending - end - local function simplify_east_api_node(line, east_api_node) if east_api_node == NIL then return nil @@ -2526,7 +2520,7 @@ describe('API', function() end end require('test.unit.viml.expressions.parser_tests')( - it_maybe_pending, _check_parsing, hl, fmtn) + it, _check_parsing, hl, fmtn) end) describe('nvim_list_uis', function() -- cgit From e8cc489accc435076afb4fdf89778b64f0a48473 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 14 Nov 2022 10:01:35 +0000 Subject: feat(test): add Lua forms for API methods (#20152) --- test/functional/api/buffer_spec.lua | 6 +- test/functional/api/vim_spec.lua | 6 +- test/functional/helpers.lua | 145 +++++++++++++++-------- test/functional/lua/diagnostic_spec.lua | 2 +- test/functional/lua/spell_spec.lua | 2 +- test/functional/lua/thread_spec.lua | 2 +- test/functional/lua/vim_spec.lua | 6 +- test/functional/lua/xdiff_spec.lua | 18 +-- test/functional/plugin/lsp_spec.lua | 4 +- test/functional/treesitter/language_spec.lua | 10 +- test/functional/ui/float_spec.lua | 4 +- test/functional/vimscript/eval_spec.lua | 2 +- test/functional/vimscript/map_functions_spec.lua | 4 +- 13 files changed, 127 insertions(+), 84 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 8f6fc666c9..598bfeb754 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq local curbufmeths, ok = helpers.curbufmeths, helpers.ok +local describe_lua_and_rpc = helpers.describe_lua_and_rpc(describe) local meths = helpers.meths local funcs = helpers.funcs local request = helpers.request @@ -579,9 +580,8 @@ describe('api/buf', function() end) end) - describe('nvim_buf_get_text', function() - local get_text = curbufmeths.get_text - + describe_lua_and_rpc('nvim_buf_get_text', function(api) + local get_text = api.curbufmeths.get_text before_each(function() insert([[ hello foo! diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 7c24f32f74..9df73c8d69 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -605,10 +605,10 @@ describe('API', function() eq([[Error loading lua: [string ""]:0: unexpected symbol]], pcall_err(meths.exec_lua, 'aa=bb\0', {})) - eq([[Error executing lua: [string ""]:0: attempt to call global 'bork' (a nil value)]], + eq([[attempt to call global 'bork' (a nil value)]], pcall_err(meths.exec_lua, 'bork()', {})) - eq('Error executing lua: [string ""]:0: did\nthe\nfail', + eq('did\nthe\nfail', pcall_err(meths.exec_lua, 'error("did\\nthe\\nfail")', {})) end) @@ -1149,7 +1149,7 @@ describe('API', function() end) it('vim.paste() failure', function() nvim('exec_lua', 'vim.paste = (function(lines, phase) error("fake fail") end)', {}) - eq([[Error executing lua: [string ""]:0: fake fail]], + eq('fake fail', pcall_err(request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1)) end) end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index f0a85785b3..1cd632f00b 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -112,6 +112,10 @@ function module.request(method, ...) return rv end +function module.request_lua(method, ...) + return module.exec_lua([[return vim.api[...](select(2, ...))]], method, ...) +end + function module.next_msg(timeout) return session:next_message(timeout and timeout or 10000) end @@ -299,12 +303,18 @@ function module.eval(expr) return module.request('nvim_eval', expr) end --- Executes a VimL function. +-- Executes a VimL function via RPC. -- Fails on VimL error, but does not update v:errmsg. function module.call(name, ...) return module.request('nvim_call_function', name, {...}) end +-- Executes a VimL function via Lua. +-- Fails on VimL error, but does not update v:errmsg. +function module.call_lua(name, ...) + return module.exec_lua([[return vim.call(...)]], name, ...) +end + -- Sends user input to Nvim. -- Does not fail on VimL error, but v:errmsg will be updated. local function nvim_feed(input) @@ -575,8 +585,16 @@ function module.set_shell_powershell(fake) return found end -function module.nvim(method, ...) - return module.request('nvim_'..method, ...) +function module.create_callindex(func) + local table = {} + setmetatable(table, { + __index = function(tbl, arg1) + local ret = function(...) return func(arg1, ...) end + tbl[arg1] = ret + return ret + end, + }) + return table end local function ui(method, ...) @@ -587,23 +605,83 @@ function module.nvim_async(method, ...) session:notify('nvim_'..method, ...) end -function module.buffer(method, ...) - return module.request('nvim_buf_'..method, ...) -end +module.async_meths = module.create_callindex(module.nvim_async) +module.uimeths = module.create_callindex(ui) -function module.window(method, ...) - return module.request('nvim_win_'..method, ...) -end +local function create_api(request, call) + local m = {} + function m.nvim(method, ...) + return request('nvim_'..method, ...) + end + + function m.buffer(method, ...) + return request('nvim_buf_'..method, ...) + end + + function m.window(method, ...) + return request('nvim_win_'..method, ...) + end + + function m.tabpage(method, ...) + return request('nvim_tabpage_'..method, ...) + end + + function m.curbuf(method, ...) + if not method then + return m.nvim('get_current_buf') + end + return m.buffer(method, 0, ...) + end -function module.tabpage(method, ...) - return module.request('nvim_tabpage_'..method, ...) + function m.curwin(method, ...) + if not method then + return m.nvim('get_current_win') + end + return m.window(method, 0, ...) + end + + function m.curtab(method, ...) + if not method then + return m.nvim('get_current_tabpage') + end + return m.tabpage(method, 0, ...) + end + + m.funcs = module.create_callindex(call) + m.meths = module.create_callindex(m.nvim) + m.bufmeths = module.create_callindex(m.buffer) + m.winmeths = module.create_callindex(m.window) + m.tabmeths = module.create_callindex(m.tabpage) + m.curbufmeths = module.create_callindex(m.curbuf) + m.curwinmeths = module.create_callindex(m.curwin) + m.curtabmeths = module.create_callindex(m.curtab) + + return m end -function module.curbuf(method, ...) - if not method then - return module.nvim('get_current_buf') +module.rpc = { + api = create_api(module.request, module.call), +} + +module.lua = { + api = create_api(module.request_lua, module.call_lua), +} + +module.describe_lua_and_rpc = function(describe) + return function(what, tests) + local function d(flavour) + describe(string.format('%s (%s)', what, flavour), function(...) + return tests(module[flavour].api, ...) + end) + end + + d('rpc') + d('lua') end - return module.buffer(method, 0, ...) +end + +for name, fn in pairs(module.rpc.api) do + module[name] = fn end function module.poke_eventloop() @@ -622,20 +700,6 @@ function module.curbuf_contents() return table.concat(module.curbuf('get_lines', 0, -1, true), '\n') end -function module.curwin(method, ...) - if not method then - return module.nvim('get_current_win') - end - return module.window(method, 0, ...) -end - -function module.curtab(method, ...) - if not method then - return module.nvim('get_current_tabpage') - end - return module.tabpage(method, 0, ...) -end - function module.expect(contents) return eq(dedent(contents), module.curbuf_contents()) end @@ -751,18 +815,6 @@ function module.exc_exec(cmd) return ret end -function module.create_callindex(func) - local table = {} - setmetatable(table, { - __index = function(tbl, arg1) - local ret = function(...) return func(arg1, ...) end - tbl[arg1] = ret - return ret - end, - }) - return table -end - function module.skip(cond, reason) if cond then local pending = getfenv(2).pending @@ -789,17 +841,6 @@ function module.skip_fragile(pending_fn, cond) return false end -module.funcs = module.create_callindex(module.call) -module.meths = module.create_callindex(module.nvim) -module.async_meths = module.create_callindex(module.nvim_async) -module.uimeths = module.create_callindex(ui) -module.bufmeths = module.create_callindex(module.buffer) -module.winmeths = module.create_callindex(module.window) -module.tabmeths = module.create_callindex(module.tabpage) -module.curbufmeths = module.create_callindex(module.curbuf) -module.curwinmeths = module.create_callindex(module.curwin) -module.curtabmeths = module.create_callindex(module.curtab) - function module.exec(code) return module.meths.exec(code, false) end diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 28a8679205..565243d5a0 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1776,7 +1776,7 @@ end) return lines ]]) - eq("Error executing lua: .../diagnostic.lua:0: prefix: expected 'string' or 'table' or 'function', got 42", + eq(".../diagnostic.lua:0: prefix: expected 'string' or 'table' or 'function', got 42", pcall_err(exec_lua, [[ vim.diagnostic.open_float({ prefix = 42 }) ]])) end) diff --git a/test/functional/lua/spell_spec.lua b/test/functional/lua/spell_spec.lua index 7e831f16a7..b3de6a0912 100644 --- a/test/functional/lua/spell_spec.lua +++ b/test/functional/lua/spell_spec.lua @@ -15,7 +15,7 @@ describe('vim.spell', function() end it('can handle nil', function() - eq([[Error executing lua: [string ""]:0: bad argument #1 to 'check' (expected string)]], + eq([[bad argument #1 to 'check' (expected string)]], pcall_err(exec_lua, [[vim.spell.check(nil)]])) end) diff --git a/test/functional/lua/thread_spec.lua b/test/functional/lua/thread_spec.lua index e183ce3a57..c7f2783cf3 100644 --- a/test/functional/lua/thread_spec.lua +++ b/test/functional/lua/thread_spec.lua @@ -272,7 +272,7 @@ describe('threadpool', function() work:queue({}) ]]) - eq([[Error executing lua: [string ""]:0: Error: thread arg not support type 'function' at 1]], + eq([[Error: thread arg not support type 'function' at 1]], status) end) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 38f772c5cf..6d0d87746c 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -168,8 +168,8 @@ describe('lua stdlib', function() for i,k in pairs(indicies16) do eq(k, exec_lua("return vim.str_byteindex(_G.test_text, ..., true)", i), i) end - matches(": index out of range$", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ...)", #indicies32 + 1)) - matches(": index out of range$", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ..., true)", #indicies16 + 1)) + eq("index out of range", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ...)", #indicies32 + 1)) + eq("index out of range", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ..., true)", #indicies16 + 1)) local i32, i16 = 0, 0 local len = 51 for k = 0,len do @@ -184,7 +184,7 @@ describe('lua stdlib', function() end eq({i32, i16}, exec_lua("return {vim.str_utfindex(_G.test_text, ...)}", k), k) end - matches(": index out of range$", pcall_err(exec_lua, "return vim.str_utfindex(_G.test_text, ...)", len + 1)) + eq("index out of range", pcall_err(exec_lua, "return vim.str_utfindex(_G.test_text, ...)", len + 1)) end) it("vim.str_utf_start", function() diff --git a/test/functional/lua/xdiff_spec.lua b/test/functional/lua/xdiff_spec.lua index d55268fc78..3121ac051f 100644 --- a/test/functional/lua/xdiff_spec.lua +++ b/test/functional/lua/xdiff_spec.lua @@ -74,11 +74,13 @@ describe('xdiff bindings', function() end) it('with error callback', function() - exec_lua([[on_hunk = function(sa, ca, sb, cb) + exec_lua[[ + on_hunk = function(sa, ca, sb, cb) error('ERROR1') - end]]) + end + ]] - eq([[Error executing lua: [string ""]:0: error running function on_hunk: [string ""]:0: ERROR1]], + eq([[error running function on_hunk: [string ""]:0: ERROR1]], pcall_err(exec_lua, [[vim.diff(a1, b1, {on_hunk = on_hunk})]])) end) @@ -135,19 +137,19 @@ describe('xdiff bindings', function() end) it('can handle bad args', function() - eq([[Error executing lua: [string ""]:0: Expected at least 2 arguments]], + eq([[Expected at least 2 arguments]], pcall_err(exec_lua, [[vim.diff('a')]])) - eq([[Error executing lua: [string ""]:0: bad argument #1 to 'diff' (expected string)]], + eq([[bad argument #1 to 'diff' (expected string)]], pcall_err(exec_lua, [[vim.diff(1, 2)]])) - eq([[Error executing lua: [string ""]:0: bad argument #3 to 'diff' (expected table)]], + eq([[bad argument #3 to 'diff' (expected table)]], pcall_err(exec_lua, [[vim.diff('a', 'b', true)]])) - eq([[Error executing lua: [string ""]:0: unexpected key: bad_key]], + eq([[unexpected key: bad_key]], pcall_err(exec_lua, [[vim.diff('a', 'b', { bad_key = true })]])) - eq([[Error executing lua: [string ""]:0: on_hunk is not a function]], + eq([[on_hunk is not a function]], pcall_err(exec_lua, [[vim.diff('a', 'b', { on_hunk = true })]])) end) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 572d7a7d97..2ab1e34de4 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -238,9 +238,9 @@ describe('LSP', function() end) it('should invalid cmd argument', function() - eq('Error executing lua: .../lsp.lua:0: cmd: expected list, got nvim', + eq('.../lsp.lua:0: cmd: expected list, got nvim', pcall_err(_cmd_parts, 'nvim')) - eq('Error executing lua: .../lsp.lua:0: cmd argument: expected string, got number', + eq('.../lsp.lua:0: cmd argument: expected string, got number', pcall_err(_cmd_parts, {'nvim', 1})) end) end) diff --git a/test/functional/treesitter/language_spec.lua b/test/functional/treesitter/language_spec.lua index ed84dedb5a..1db8381a93 100644 --- a/test/functional/treesitter/language_spec.lua +++ b/test/functional/treesitter/language_spec.lua @@ -13,21 +13,21 @@ before_each(clear) describe('treesitter language API', function() -- error tests not requiring a parser library it('handles missing language', function() - eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", + eq(".../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", pcall_err(exec_lua, "parser = vim.treesitter.get_parser(0, 'borklang')")) -- actual message depends on platform - matches("Error executing lua: Failed to load parser: uv_dlopen: .+", + matches("Failed to load parser: uv_dlopen: .+", pcall_err(exec_lua, "parser = vim.treesitter.require_language('borklang', 'borkbork.so')")) -- Should not throw an error when silent eq(false, exec_lua("return vim.treesitter.require_language('borklang', nil, true)")) eq(false, exec_lua("return vim.treesitter.require_language('borklang', 'borkbork.so', true)")) - eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", + eq(".../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", pcall_err(exec_lua, "parser = vim.treesitter.inspect_language('borklang')")) - matches("Error executing lua: Failed to load parser: uv_dlsym: .+", + matches("Failed to load parser: uv_dlsym: .+", pcall_err(exec_lua, 'vim.treesitter.require_language("c", nil, false, "borklang")')) end) @@ -76,7 +76,7 @@ describe('treesitter language API', function() eq('c', exec_lua("return vim.treesitter.get_parser(0):lang()")) command("set filetype=borklang") -- Should throw an error when filetype changes to borklang - eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", + eq(".../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", pcall_err(exec_lua, "new_parser = vim.treesitter.get_parser(0)")) end) diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index cb90a902d7..c7ee4ee87d 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -93,7 +93,7 @@ describe('float window', function() end) it('closed immediately by autocmd #11383', function() - eq('Error executing lua: [string ""]:0: Window was closed immediately', + eq('Window was closed immediately', pcall_err(exec_lua, [[ local a = vim.api local function crashes(contents) @@ -118,7 +118,7 @@ describe('float window', function() end) it('closed immediately by autocmd after win_enter #15548', function() - eq('Error executing lua: [string ""]:0: Window was closed immediately', + eq('Window was closed immediately', pcall_err(exec_lua, [[ vim.cmd "autocmd BufLeave * ++once quit!" local buf = vim.api.nvim_create_buf(true, true) diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 9b0ace0882..d50c252569 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -195,7 +195,7 @@ describe('listing functions using :function', function() it('does not crash if another function is deleted while listing', function() local screen = Screen.new(80, 24) screen:attach() - matches('.*: Vim%(function%):E454: function list was modified', pcall_err(exec_lua, [=[ + matches('Vim%(function%):E454: function list was modified', pcall_err(exec_lua, [=[ vim.cmd([[ func Func1() endfunc diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index 8645b1e506..ba1b4d7a76 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -246,9 +246,9 @@ describe('mapset()', function() end) it('does not leak memory if lhs is missing', function() - eq('Error executing lua: Vim:E460: entries missing in mapset() dict argument', + eq('Vim:E460: entries missing in mapset() dict argument', pcall_err(exec_lua, [[vim.fn.mapset('n', false, {rhs = 'foo'})]])) - eq('Error executing lua: Vim:E460: entries missing in mapset() dict argument', + eq('Vim:E460: entries missing in mapset() dict argument', pcall_err(exec_lua, [[vim.fn.mapset('n', false, {callback = function() end})]])) end) end) -- cgit From f8c671827710c6e9cca3bfd60c32098b2be8239a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 14 Nov 2022 18:04:36 +0000 Subject: feat(lua-api): avoid unnecessary allocations (#19877) Lua makes (or reuses) an internal copy of strings, so we can safely push buf pointers onto the stack. --- test/functional/api/buffer_spec.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 598bfeb754..5980d99f97 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -186,12 +186,13 @@ describe('api/buf', function() end) end) - describe('nvim_buf_get_lines, nvim_buf_set_lines', function() - local get_lines, set_lines = curbufmeths.get_lines, curbufmeths.set_lines - local line_count = curbufmeths.line_count + describe_lua_and_rpc('nvim_buf_get_lines, nvim_buf_set_lines', function(api) + local get_lines = api.curbufmeths.get_lines + local set_lines = api.curbufmeths.set_lines + local line_count = api.curbufmeths.line_count it('fails correctly when input is not valid', function() - eq(1, curbufmeths.get_number()) + eq(1, api.curbufmeths.get_number()) eq([[String cannot contain newlines]], pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'b\na'})) end) @@ -199,7 +200,7 @@ describe('api/buf', function() it("fails if 'nomodifiable'", function() command('set nomodifiable') eq([[Buffer is not 'modifiable']], - pcall_err(bufmeths.set_lines, 1, 1, 2, false, {'a','b'})) + pcall_err(api.bufmeths.set_lines, 1, 1, 2, false, {'a','b'})) end) it('has correct line_count when inserting and deleting', function() @@ -355,7 +356,7 @@ describe('api/buf', function() Who would win? A real window with proper text]]) - local buf = meths.create_buf(false,true) + local buf = api.meths.create_buf(false,true) screen:expect([[ Who would win? | A real window | @@ -364,7 +365,7 @@ describe('api/buf', function() | ]]) - meths.buf_set_lines(buf, 0, -1, true, {'or some', 'scratchy text'}) + api.meths.buf_set_lines(buf, 0, -1, true, {'or some', 'scratchy text'}) feed('i') -- provoke redraw screen:expect([[ Who would win? | @@ -380,15 +381,15 @@ describe('api/buf', function() visible buffer line 1 line 2 ]]) - local hiddenbuf = meths.create_buf(false,true) + local hiddenbuf = api.meths.create_buf(false,true) command('vsplit') command('vsplit') feed('lll') eq(3, funcs.winnr()) feed('h') eq(2, funcs.winnr()) - meths.buf_set_lines(hiddenbuf, 0, -1, true, - {'hidden buffer line 1', 'line 2'}) + api.meths.buf_set_lines(hiddenbuf, 0, -1, true, + {'hidden buffer line 1', 'line 2'}) feed('p') eq(3, funcs.winnr()) end) -- cgit From e15f61b1bd60f6a198a0d9969cea407784ff71d0 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 14 Nov 2022 20:26:27 +0100 Subject: fix(lua): make `vim.deepcopy` work with `vim.NIL` style: changed double quotes to single quotes feat: add tests fix tests --- test/functional/lua/vim_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 6d0d87746c..21f2c19fbb 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -419,6 +419,12 @@ describe('lua stdlib', function() return getmetatable(t2) == mt ]])) + ok(exec_lua([[ + local t1 = {a = vim.NIL} + local t2 = vim.deepcopy(t1) + return t2.a == vim.NIL + ]])) + matches('Cannot deepcopy object of type thread', pcall_err(exec_lua, [[ local thread = coroutine.create(function () return 0 end) -- cgit From 211c568e6452e62b119ac4b987ff47b9174ec9ad Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 15 Nov 2022 12:33:30 +0100 Subject: test: don't skip parser_spec on windows (#20294) --- test/functional/treesitter/parser_spec.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua index 22348c7e20..c6ddf812be 100644 --- a/test/functional/treesitter/parser_spec.lua +++ b/test/functional/treesitter/parser_spec.lua @@ -14,8 +14,6 @@ describe('treesitter parser API', function() clear() it('parses buffer', function() - skip(iswin()) - insert([[ int main() { int x = 3; -- cgit From c70d90dbfdf67bb009d2976a5d0760be4010e533 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Nov 2022 23:02:48 +0800 Subject: vim-patch:9.0.0884: mouse shape remains in op-pending mode after failed change (#21066) Problem: Mouse shape remains in op-pending mode after failed change. Solution: Reset finish_op and restore it. (closes vim/vim#11545) https://github.com/vim/vim/commit/cdeb65729d96c90320b9009e583ade305c396f29 --- test/functional/ui/mode_spec.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/mode_spec.lua b/test/functional/ui/mode_spec.lua index 9390f268b3..cf4eb034e0 100644 --- a/test/functional/ui/mode_spec.lua +++ b/test/functional/ui/mode_spec.lua @@ -17,6 +17,7 @@ describe('ui mode_change event', function() [1] = {bold=true, reverse=true}, [2] = {bold=true}, [3] = {reverse=true}, + [4] = {background=Screen.colors.Red, foreground=Screen.colors.White}, -- ErrorMsg }) end) @@ -43,6 +44,25 @@ describe('ui mode_change event', function() {0:~ }| | ]], mode="normal"} + + screen:try_resize(50, 4) + command('set nomodifiable') + + feed('c') + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + | + ]], mode="operator"} + + feed('c') + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + {4:E21: Cannot make changes, 'modifiable' is off} | + ]], mode="normal"} end) it('works in insert mode', function() -- cgit From fa7e1e26019112ff9e2ea42626995f04e2a4e032 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 15 Nov 2022 21:27:42 +0000 Subject: fix(api): nvim_buf_get_text regression (#21071) --- test/functional/api/buffer_spec.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 5980d99f97..6b13729994 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -586,7 +586,8 @@ describe('api/buf', function() before_each(function() insert([[ hello foo! - text]]) + text + more]]) end) it('works', function() @@ -594,16 +595,17 @@ describe('api/buf', function() eq({'hello foo!'}, get_text(0, 0, 0, 42, {})) eq({'foo!'}, get_text(0, 6, 0, 10, {})) eq({'foo!', 'tex'}, get_text(0, 6, 1, 3, {})) - eq({'foo!', 'tex'}, get_text(-2, 6, -1, 3, {})) + eq({'foo!', 'tex'}, get_text(-3, 6, -2, 3, {})) eq({''}, get_text(0, 18, 0, 20, {})) - eq({'ext'}, get_text(-1, 1, -1, 4, {})) + eq({'ext'}, get_text(-2, 1, -2, 4, {})) + eq({'hello foo!', 'text', 'm'}, get_text(0, 0, 2, 1, {})) end) it('errors on out-of-range', function() - eq('Index out of bounds', pcall_err(get_text, 2, 0, 3, 0, {})) - eq('Index out of bounds', pcall_err(get_text, -3, 0, 0, 0, {})) - eq('Index out of bounds', pcall_err(get_text, 0, 0, 2, 0, {})) - eq('Index out of bounds', pcall_err(get_text, 0, 0, -3, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 2, 0, 4, 0, {})) + eq('Index out of bounds', pcall_err(get_text, -4, 0, 0, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, 3, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, -4, 0, {})) -- no ml_get errors should happen #19017 eq('', meths.get_vvar('errmsg')) end) -- cgit From fedf002cb34d0d7a50c54f84a2f161984db2a4c2 Mon Sep 17 00:00:00 2001 From: Jlll1 Date: Thu, 17 Nov 2022 00:18:31 +0100 Subject: fix(api): nvim_win_set_cursor redraw cursorcolumn for non-current window (#21072) fix #19063 this fixes the cursorcolumn not being redrawn for non-current windows in `nvim_win_set_cursor()` --- test/functional/api/window_spec.lua | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 7c65cf9c37..48431ccfc7 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -229,6 +229,46 @@ describe('API/win', function() | ]]) end) + + it('updates cursorcolumn in non-current window', function() + local screen = Screen.new(60, 8) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [2] = {background = Screen.colors.Grey90}, -- CursorColumn + [3] = {bold = true, reverse = true}, -- StatusLine + [4] = {reverse = true}, -- StatusLineNC + }) + screen:attach() + command('set cursorcolumn') + insert([[ + aaa + bbb + ccc + ddd]]) + local oldwin = curwin() + command('vsplit') + screen:expect([[ + aa{2:a} │aa{2:a} | + bb{2:b} │bb{2:b} | + cc{2:c} │cc{2:c} | + dd^d │ddd | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {3:[No Name] [+] }{4:[No Name] [+] }| + | + ]]) + window('set_cursor', oldwin, {2, 0}) + screen:expect([[ + aa{2:a} │{2:a}aa | + bb{2:b} │bbb | + cc{2:c} │{2:c}cc | + dd^d │{2:d}dd | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {3:[No Name] [+] }{4:[No Name] [+] }| + | + ]]) + end) end) describe('{get,set}_height', function() -- cgit From a77be32cf90a8ef78eae3e243f4619d8bb739df5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 20:37:07 +0800 Subject: test: add a Lua test for swap file created before boot Change the file modification time instead of uptime. --- .../ex_cmds/swapfile_preserve_recover_spec.lua | 79 +++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua index 69404039ff..8eed00c973 100644 --- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua +++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -1,12 +1,14 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) local lfs = require('lfs') +local luv = require('luv') local eq, eval, expect, exec = helpers.eq, helpers.eval, helpers.expect, helpers.exec local assert_alive = helpers.assert_alive local clear = helpers.clear local command = helpers.command local feed = helpers.feed +local funcs = helpers.funcs local nvim_prog = helpers.nvim_prog local ok = helpers.ok local rmdir = helpers.rmdir @@ -100,7 +102,7 @@ describe('swapfile detection', function() -- attempt to create a swapfile in different directory. local init = [[ set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// - set swapfile fileformat=unix undolevels=-1 hidden + set swapfile fileformat=unix nomodified undolevels=-1 nohidden ]] before_each(function() nvim0 = spawn(new_argv()) @@ -263,4 +265,79 @@ describe('swapfile detection', function() ]]) nvim2:close() end) + + -- oldtest: Test_nocatch_process_still_running() + it('allows deleting swapfile created before boot vim-patch:8.2.2586', function() + local screen = Screen.new(75, 30) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg + [2] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg + }) + screen:attach() + + exec(init) + command('set nohidden') + + exec([=[ + " Make a copy of the current swap file to "Xswap". + " Return the name of the swap file. + func CopySwapfile() + preserve + " get the name of the swap file + let swname = split(execute("swapname"))[0] + let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '') + " make a copy of the swap file in Xswap + set binary + exe 'sp ' . fnameescape(swname) + w! Xswap + set nobinary + return swname + endfunc + ]=]) + + -- Edit a file and grab its swapfile. + exec([[ + edit Xswaptest + call setline(1, ['a', 'b', 'c']) + ]]) + local swname = funcs.CopySwapfile() + + -- Forget we edited this file + exec([[ + new + only! + bwipe! Xswaptest + ]]) + + os.rename('Xswap', swname) + + feed(':edit Xswaptest') + screen:expect({any = table.concat({ + pesc('{2:E325: ATTENTION}'), + 'file name: .*Xswaptest', + 'process ID: %d* %(STILL RUNNING%)', + pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'), + }, '.*')}) + + feed('e') + + -- Forget we edited this file + exec([[ + new + only! + bwipe! Xswaptest + ]]) + + -- pretend that the swapfile was created before boot + lfs.touch(swname, os.time() - luv.uptime() - 10) + + feed(':edit Xswaptest') + screen:expect({any = table.concat({ + pesc('{2:E325: ATTENTION}'), + pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: }^'), + }, '.*')}) + + feed('e') + end) end) -- cgit From f1922e78a1df1b1d32779769432fb5586edf5fbb Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Sat, 5 Nov 2022 13:37:05 -0600 Subject: feat: add vim.secure.read() This function accepts a path to a file and prompts the user if the file is trusted. If the user confirms that the file is trusted, the contents of the file are returned. The user's decision is stored in a trust database at $XDG_STATE_HOME/nvim/trust. When this function is invoked with a path that is already marked as trusted in the trust database, the user is not prompted for a response. --- test/functional/lua/secure_spec.lua | 171 ++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 test/functional/lua/secure_spec.lua (limited to 'test/functional') diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua new file mode 100644 index 0000000000..c348526d65 --- /dev/null +++ b/test/functional/lua/secure_spec.lua @@ -0,0 +1,171 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local eq = helpers.eq +local clear = helpers.clear +local command = helpers.command +local pathsep = helpers.get_pathsep() +local iswin = helpers.iswin() +local curbufmeths = helpers.curbufmeths +local exec_lua = helpers.exec_lua +local feed_command = helpers.feed_command +local feed = helpers.feed +local funcs = helpers.funcs +local pcall_err = helpers.pcall_err + +describe('vim.secure', function() + describe('read()', function() + local xstate = 'Xstate' + + setup(function() + helpers.mkdir_p(xstate .. pathsep .. (iswin and 'nvim-data' or 'nvim')) + end) + + teardown(function() + helpers.rmdir(xstate) + end) + + before_each(function() + helpers.write_file('Xfile', [[ + let g:foobar = 42 + ]]) + clear{env={XDG_STATE_HOME=xstate}} + end) + + after_each(function() + os.remove('Xfile') + helpers.rmdir(xstate) + end) + + it('works', function() + local screen = Screen.new(80, 8) + screen:attach() + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}, + [2] = {bold = true, reverse = true}, + [3] = {bold = true, foreground = Screen.colors.SeaGreen}, + [4] = {reverse = true}, + }) + + local cwd = funcs.getcwd() + + -- Need to use feed_command instead of exec_lua because of the confirmation prompt + feed_command([[lua vim.secure.read('Xfile')]]) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {2: }| + :lua vim.secure.read('Xfile') | + {3:]] .. cwd .. pathsep .. [[Xfile is untrusted}{MATCH:%s+}| + {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ | + ]]} + feed('d') + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('! %s', cwd .. pathsep .. 'Xfile'), vim.trim(trust)) + eq(helpers.NIL, exec_lua([[return vim.secure.read('Xfile')]])) + + os.remove(funcs.stdpath('state') .. pathsep .. 'trust') + + feed_command([[lua vim.secure.read('Xfile')]]) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {2: }| + :lua vim.secure.read('Xfile') | + {3:]] .. cwd .. pathsep .. [[Xfile is untrusted}{MATCH:%s+}| + {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ | + ]]} + feed('a') + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + local hash = funcs.sha256(helpers.read_file('Xfile')) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('%s %s', hash, cwd .. pathsep .. 'Xfile'), vim.trim(trust)) + eq(helpers.NIL, exec_lua([[vim.secure.read('Xfile')]])) + + os.remove(funcs.stdpath('state') .. pathsep .. 'trust') + + feed_command([[lua vim.secure.read('Xfile')]]) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {2: }| + :lua vim.secure.read('Xfile') | + {3:]] .. cwd .. pathsep .. [[Xfile is untrusted}{MATCH:%s+}| + {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ | + ]]} + feed('i') + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + -- Trust database is not updated + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(nil, trust) + + feed_command([[lua vim.secure.read('Xfile')]]) + screen:expect{grid=[[ + | + {1:~ }| + {1:~ }| + {1:~ }| + {2: }| + :lua vim.secure.read('Xfile') | + {3:]] .. cwd .. pathsep .. [[Xfile is untrusted}{MATCH:%s+}| + {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ | + ]]} + feed('v') + screen:expect{grid=[[ + ^ let g:foobar = 42 | + {1:~ }| + {1:~ }| + {2:]] .. cwd .. pathsep .. [[Xfile [RO]{MATCH:%s+}| + | + {1:~ }| + {4:[No Name] }| + | + ]]} + + -- Trust database is not updated + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(nil, trust) + + -- Cannot write file + pcall_err(command, 'write') + eq(false, curbufmeths.get_option('modifiable')) + end) + end) +end) -- cgit From 4650af38f07defb87d13d9567c127b0070bfccb9 Mon Sep 17 00:00:00 2001 From: Jakub Łuczyński Date: Sat, 19 Nov 2022 13:46:04 +0100 Subject: test: fix failing tui_spec.lua tests (#21117) * refactor(test): use exec_lua * fix(test): fix failing tui_spec tests test is failing when path of tty-test does not fit cmdline --- test/functional/terminal/helpers.lua | 25 +++++++++++++++++++------ test/functional/terminal/tui_spec.lua | 15 +++++++-------- 2 files changed, 26 insertions(+), 14 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index d69f3207f1..841c92387f 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -4,19 +4,31 @@ local helpers = require('test.functional.helpers')(nil) local Screen = require('test.functional.ui.screen') local testprg = helpers.testprg +local exec_lua = helpers.exec_lua local feed_command, nvim = helpers.feed_command, helpers.nvim local function feed_data(data) - -- A string containing NUL bytes is not converted to a Blob when - -- calling nvim_set_var() API, so convert it using Lua instead. - nvim('exec_lua', 'vim.g.term_data = ...', {data}) - nvim('command', 'call jobsend(b:terminal_job_id, term_data)') + if type(data) == 'table' then + data = table.concat(data, '\n') + end + exec_lua('vim.api.nvim_chan_send(vim.b.terminal_job_id, ...)', data) end local function feed_termcode(data) - -- feed with the job API - nvim('command', 'call jobsend(b:terminal_job_id, "\\x1b'..data..'")') + feed_data('\027' .. data) +end + +local function make_lua_executor(session) + return function(code, ...) + local status, rv = session:request('nvim_exec_lua', code, {...}) + if not status then + session:stop() + error(rv[2]) + end + return rv + end end + -- some helpers for controlling the terminal. the codes were taken from -- infocmp xterm-256color which is less what libvterm understands -- civis/cnorm @@ -109,6 +121,7 @@ end return { feed_data = feed_data, feed_termcode = feed_termcode, + make_lua_executor = make_lua_executor, hide_cursor = hide_cursor, show_cursor = show_cursor, enter_altscreen = enter_altscreen, diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index d2e409cc0f..4cfdd90187 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -28,6 +28,7 @@ if helpers.skip(helpers.iswin()) then return end describe('TUI', function() local screen local child_session + local child_exec_lua before_each(function() clear() @@ -45,6 +46,7 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) child_session = helpers.connect(child_server) + child_exec_lua = thelpers.make_lua_executor(child_session) end) -- Wait for mode in the child Nvim (avoid "typeahead race" #10826). @@ -823,8 +825,8 @@ describe('TUI', function() pending("tty-test complains about not owning the terminal -- actions/runner#241") return end - feed_data(':set statusline=^^^^^^^\n') - feed_data(':terminal '..testprg('tty-test')..'\n') + child_exec_lua('vim.o.statusline="^^^^^^^"') + child_exec_lua('vim.cmd.terminal(...)', testprg('tty-test')) feed_data('i') screen:expect{grid=[[ tty ready | @@ -1340,12 +1342,9 @@ describe('TUI', function() [5] = {{foreground = tonumber('0xff8000')}, {}}, }) - feed_data(':set statusline=^^^^^^^\n') - feed_data(':set termguicolors\n') - feed_data(':terminal '..testprg('tty-test')..'\n') - -- Depending on platform the above might or might not fit in the cmdline - -- so clear it for consistent behavior. - feed_data(':\027') + child_exec_lua('vim.o.statusline="^^^^^^^"') + child_exec_lua('vim.o.termguicolors=true') + child_exec_lua('vim.cmd.terminal(...)', testprg('tty-test')) screen:expect{grid=[[ {1:t}ty ready | | -- cgit From 6e8ed5abaa9c33d1d78ab7ff5b07dd5bac623a1d Mon Sep 17 00:00:00 2001 From: Raphael Date: Sat, 19 Nov 2022 21:41:47 +0800 Subject: perf(diagnostic): use api variable and improve validate (#21111) * fix(diagnostic): use api variable and improve validate * fix: fix test case --- test/functional/lua/diagnostic_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 565243d5a0..116a541358 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1776,7 +1776,7 @@ end) return lines ]]) - eq(".../diagnostic.lua:0: prefix: expected 'string' or 'table' or 'function', got 42", + eq(".../diagnostic.lua:0: prefix: expected string|table|function, got number", pcall_err(exec_lua, [[ vim.diagnostic.open_float({ prefix = 42 }) ]])) end) -- cgit From cb27c09930f576dc859aa6e4b80fb44119b9f95f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 20 Nov 2022 11:26:21 +0100 Subject: test: use isCI to simplify CI detection (#21134) --- test/functional/terminal/tui_spec.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 4cfdd90187..20c677c46c 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -22,6 +22,7 @@ local ok = helpers.ok local read_file = helpers.read_file local funcs = helpers.funcs local meths = helpers.meths +local isCI = helpers.isCI if helpers.skip(helpers.iswin()) then return end @@ -821,9 +822,8 @@ describe('TUI', function() end) it('paste: terminal mode', function() - if os.getenv('GITHUB_ACTIONS') ~= nil then + if isCI('github') then pending("tty-test complains about not owning the terminal -- actions/runner#241") - return end child_exec_lua('vim.o.statusline="^^^^^^^"') child_exec_lua('vim.cmd.terminal(...)', testprg('tty-test')) @@ -1329,9 +1329,8 @@ describe('TUI', function() end) it('forwards :term palette colors with termguicolors', function() - if os.getenv('GITHUB_ACTIONS') ~= nil then + if isCI('github') then pending("tty-test complains about not owning the terminal -- actions/runner#241") - return end screen:set_rgb_cterm(true) screen:set_default_attr_ids({ -- cgit From 035d41ac5e5fcbb49eb64b72a924c4d6f89f0579 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 20 Nov 2022 08:38:46 +0800 Subject: vim-patch:partial:9.0.0913: only change in current window triggers the WinScrolled event Problem: Only a change in the current window triggers the WinScrolled event. Solution: Trigger WinScrolled if any window scrolled or changed size. (issue vim/vim#11576) https://github.com/vim/vim/commit/0a60f79fd0c328b47b36279a95282e9f8d9e7512 Skip locking of window layout and E1312. Copy the latest version of all WinScrolled tests from Vim. Note: patch 9.0.0915 is needed for the Lua tests to pass. Co-authored-by: Bram Moolenaar --- test/functional/autocmd/winscrolled_spec.lua | 47 +++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua index 12b8e7c42d..6db2d53bbf 100644 --- a/test/functional/autocmd/winscrolled_spec.lua +++ b/test/functional/autocmd/winscrolled_spec.lua @@ -1,8 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval +local exec = helpers.exec local command = helpers.command local feed = helpers.feed local meths = helpers.meths @@ -89,11 +91,42 @@ describe('WinScrolled', function() end) end) -it('closing window in WinScrolled does not cause use-after-free #13265', function() - local lines = {'aaa', 'bbb'} - meths.buf_set_lines(0, 0, -1, true, lines) - command('vsplit') - command('autocmd WinScrolled * close') - feed('') - assert_alive() +describe('WinScrolled', function() + -- oldtest: Test_WinScrolled_mouse() + it('is triggered by mouse scrolling in another window', function() + local screen = Screen.new(75, 10) + screen:attach() + exec([[ + set nowrap scrolloff=0 + set mouse=a + call setline(1, ['foo']->repeat(32)) + split + let g:scrolled = 0 + au WinScrolled * let g:scrolled += 1 + ]]) + + -- With the upper split focused, send a scroll-down event to the unfocused one. + meths.input_mouse('wheel', 'down', '', 0, 6, 0) + eq(1, eval('g:scrolled')) + + -- Again, but this time while we're in insert mode. + feed('i') + meths.input_mouse('wheel', 'down', '', 0, 6, 0) + feed('') + eq(2, eval('g:scrolled')) + end) + + -- oldtest: Test_WinScrolled_close_curwin() + it('closing window does not cause use-after-free #13265', function() + exec([[ + set nowrap scrolloff=0 + call setline(1, ['aaa', 'bbb']) + vsplit + au WinScrolled * close + ]]) + + -- This was using freed memory + feed('') + assert_alive() + end) end) -- cgit From 91c192922da0240be5a8eb4045dae6cd968957e9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 20 Nov 2022 21:11:57 +0800 Subject: vim-patch:9.0.0915: WinScrolled may trigger immediately when defined Problem: WinScrolled may trigger immediately when defined. Solution: Initialize the fields in all windows. (closes vim/vim#11582) https://github.com/vim/vim/commit/29967732761d1ffb5592db5f5aa7036f5b52abf1 Co-authored-by: Bram Moolenaar --- test/functional/autocmd/winscrolled_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional') diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua index 6db2d53bbf..cd9c6dd168 100644 --- a/test/functional/autocmd/winscrolled_spec.lua +++ b/test/functional/autocmd/winscrolled_spec.lua @@ -104,6 +104,7 @@ describe('WinScrolled', function() let g:scrolled = 0 au WinScrolled * let g:scrolled += 1 ]]) + eq(0, eval('g:scrolled')) -- With the upper split focused, send a scroll-down event to the unfocused one. meths.input_mouse('wheel', 'down', '', 0, 6, 0) -- cgit From d6bd9c77335e6a0b936e5b15f1b1df7e8af7cafd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 20 Nov 2022 21:38:29 +0800 Subject: test: add a test for #18222 --- test/functional/autocmd/winscrolled_spec.lua | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/functional') diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua index cd9c6dd168..5a426fcfa1 100644 --- a/test/functional/autocmd/winscrolled_spec.lua +++ b/test/functional/autocmd/winscrolled_spec.lua @@ -130,4 +130,33 @@ describe('WinScrolled', function() feed('') assert_alive() end) + + it('is triggered by mouse scrolling in unfocused floating window #18222', function() + local screen = Screen.new(80, 24) + screen:attach() + local buf = meths.create_buf(true, true) + meths.buf_set_lines(buf, 0, -1, false, {'a', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'}) + local win = meths.open_win(buf, false, { + height = 5, + width = 10, + col = 0, + row = 1, + relative = 'editor', + style = 'minimal' + }) + exec([[ + let g:scrolled = 0 + autocmd WinScrolled * let g:scrolled += 1 + autocmd WinScrolled * let g:amatch = expand('') + ]]) + eq(0, eval('g:scrolled')) + + meths.input_mouse('wheel', 'down', '', 0, 3, 3) + eq(1, eval('g:scrolled')) + eq(tostring(win.id), eval('g:amatch')) + + meths.input_mouse('wheel', 'down', '', 0, 3, 3) + eq(2, eval('g:scrolled')) + eq(tostring(win.id), eval('g:amatch')) + end) end) -- cgit From fbce9f421ad1ad466126a24524ade9df978486d5 Mon Sep 17 00:00:00 2001 From: beardedsakimonkey <54521218+beardedsakimonkey@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:09:35 +0000 Subject: feat(diagnostic): add `suffix` option to `open_float()` (#21130) Closes #18687 This introduces a `suffix` option to `vim.diagnostic.open_float()` (and consequently `vim.diagnostic.config()`) that appends some text to each diagnostic in the float. It accepts the same types as `prefix`. For multiline diagnostics, the suffix is only appended to the last line. By default, the suffix will render the diagnostic error code, if any. --- test/functional/lua/diagnostic_spec.lua | 64 ++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 9 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 116a541358..816b359725 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -16,7 +16,7 @@ describe('vim.diagnostic', function() exec_lua [[ require('vim.diagnostic') - function make_diagnostic(msg, x1, y1, x2, y2, severity, source) + function make_diagnostic(msg, x1, y1, x2, y2, severity, source, code) return { lnum = x1, col = y1, @@ -25,23 +25,24 @@ describe('vim.diagnostic', function() message = msg, severity = severity, source = source, + code = code, } end - function make_error(msg, x1, y1, x2, y2, source) - return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.ERROR, source) + function make_error(msg, x1, y1, x2, y2, source, code) + return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.ERROR, source, code) end - function make_warning(msg, x1, y1, x2, y2, source) - return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.WARN, source) + function make_warning(msg, x1, y1, x2, y2, source, code) + return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.WARN, source, code) end - function make_info(msg, x1, y1, x2, y2, source) - return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.INFO, source) + function make_info(msg, x1, y1, x2, y2, source, code) + return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.INFO, source, code) end - function make_hint(msg, x1, y1, x2, y2, source) - return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.HINT, source) + function make_hint(msg, x1, y1, x2, y2, source, code) + return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.HINT, source, code) end function count_diagnostics(bufnr, severity, namespace) @@ -1780,6 +1781,51 @@ end) pcall_err(exec_lua, [[ vim.diagnostic.open_float({ prefix = 42 }) ]])) end) + it('can add a suffix to diagnostics', function() + -- Default is to render the diagnostic error code + eq({'1. Syntax error [code-x]', '2. Some warning [code-y]'}, exec_lua [[ + local diagnostics = { + make_error("Syntax error", 0, 1, 0, 3, nil, "code-x"), + make_warning("Some warning", 1, 1, 1, 3, nil, "code-y"), + } + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) + local float_bufnr, winnr = vim.diagnostic.open_float({header = false, scope = "buffer"}) + local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) + vim.api.nvim_win_close(winnr, true) + return lines + ]]) + + eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + local diagnostics = { + make_error("Syntax error", 0, 1, 0, 3, nil, "code-x"), + make_warning("Some warning", 1, 1, 1, 3, nil, "code-y"), + } + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) + local float_bufnr, winnr = vim.diagnostic.open_float({header = false, scope = "buffer", suffix = ""}) + local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) + vim.api.nvim_win_close(winnr, true) + return lines + ]]) + + -- Suffix is rendered on the last line of a multiline diagnostic + eq({'1. Syntax error', ' More context [code-x]'}, exec_lua [[ + local diagnostics = { + make_error("Syntax error\nMore context", 0, 1, 0, 3, nil, "code-x"), + } + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) + local float_bufnr, winnr = vim.diagnostic.open_float({header = false, scope = "buffer"}) + local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) + vim.api.nvim_win_close(winnr, true) + return lines + ]]) + + eq(".../diagnostic.lua:0: suffix: expected string|table|function, got number", + pcall_err(exec_lua, [[ vim.diagnostic.open_float({ suffix = 42 }) ]])) + end) + it('works with the old signature', function() eq({'1. Syntax error'}, exec_lua [[ local diagnostics = { -- cgit From 126ef65e5b3ff0da68bfe166be0bb0a33664142b Mon Sep 17 00:00:00 2001 From: beardedsakimonkey <54521218+beardedsakimonkey@users.noreply.github.com> Date: Sun, 20 Nov 2022 23:57:36 +0000 Subject: feat(diagnostic): add `suffix` option to `virt_text` config (#21140) This introduces a `suffix` option to the `virt_text` config in `vim.diagnostic.config()`. The suffix can either be a string which is appended to the diagnostic message or a function returning such. The function receives a `diagnostic` argument, which is the diagnostic table of the last diagnostic (the one whose message is rendered as virt text). --- test/functional/lua/diagnostic_spec.lua | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 816b359725..b7fe39cc91 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1161,6 +1161,44 @@ end) eq(" some_linter: 👀 Warning", result[1][2][1]) eq(" another_linter: 🔥 Error", result[2][2][1]) end) + + it('can add a suffix to virtual text', function() + eq(' Some error ✘', exec_lua [[ + local diagnostics = { + make_error('Some error', 0, 0, 0, 0), + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, { + underline = false, + virtual_text = { + prefix = '', + suffix = ' ✘', + } + }) + + local extmarks = get_virt_text_extmarks(diagnostic_ns) + local virt_text = extmarks[1][4].virt_text[2][1] + return virt_text + ]]) + + eq(' Some error [err-code]', exec_lua [[ + local diagnostics = { + make_error('Some error', 0, 0, 0, 0, nil, 'err-code'), + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, { + underline = false, + virtual_text = { + prefix = '', + suffix = function(diag) return string.format(' [%s]', diag.code) end, + } + }) + + local extmarks = get_virt_text_extmarks(diagnostic_ns) + local virt_text = extmarks[1][4].virt_text[2][1] + return virt_text + ]]) + end) end) describe('set()', function() -- cgit From 5eb5f4948826e9d47685ea9e257409cc3e693614 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 22 Nov 2022 01:13:30 +0100 Subject: test: simplify platform detection (#21020) Extend the capabilities of is_os to detect more platforms such as freebsd and openbsd. Also remove `iswin()` helper function as it can be replaced by `is_os("win")`. --- test/functional/api/proc_spec.lua | 4 +- test/functional/api/server_notifications_spec.lua | 4 +- test/functional/api/server_requests_spec.lua | 2 +- test/functional/api/vim_spec.lua | 11 +++-- test/functional/autocmd/dirchanged_spec.lua | 28 ++++++------- test/functional/autocmd/focus_spec.lua | 2 +- test/functional/autocmd/signal_spec.lua | 4 +- test/functional/autocmd/termxx_spec.lua | 8 ++-- test/functional/core/channels_spec.lua | 9 ++-- test/functional/core/fileio_spec.lua | 16 ++++---- test/functional/core/job_spec.lua | 48 +++++++++++----------- test/functional/core/main_spec.lua | 4 +- test/functional/core/path_spec.lua | 4 +- test/functional/core/startup_spec.lua | 12 +++--- test/functional/ex_cmds/cd_spec.lua | 4 +- test/functional/ex_cmds/mksession_spec.lua | 8 ++-- test/functional/ex_cmds/source_spec.lua | 4 +- test/functional/ex_cmds/write_spec.lua | 22 +++++----- test/functional/ex_cmds/wviminfo_spec.lua | 4 +- test/functional/helpers.lua | 21 +++++----- test/functional/legacy/011_autocommands_spec.lua | 4 +- .../functional/legacy/025_jump_tag_hidden_spec.lua | 6 +-- test/functional/legacy/097_glob_path_spec.lua | 6 +-- test/functional/legacy/delete_spec.lua | 2 +- test/functional/legacy/excmd_spec.lua | 8 ++-- test/functional/legacy/filechanged_spec.lua | 4 +- test/functional/legacy/memory_usage_spec.lua | 15 ++++--- test/functional/lua/fs_spec.lua | 6 +-- test/functional/lua/overrides_spec.lua | 4 +- test/functional/lua/secure_spec.lua | 4 +- test/functional/lua/uri_spec.lua | 4 +- test/functional/options/autochdir_spec.lua | 2 +- test/functional/options/defaults_spec.lua | 24 +++++------ test/functional/plugin/lsp_spec.lua | 8 ++-- test/functional/plugin/man_spec.lua | 4 +- test/functional/plugin/shada_spec.lua | 2 +- test/functional/preload.lua | 4 +- test/functional/provider/perl_spec.lua | 6 +-- test/functional/shada/compatibility_spec.lua | 2 +- test/functional/shada/merging_spec.lua | 2 +- test/functional/shada/shada_spec.lua | 4 +- test/functional/terminal/altscreen_spec.lua | 2 +- test/functional/terminal/api_spec.lua | 2 +- test/functional/terminal/buffer_spec.lua | 6 +-- test/functional/terminal/cursor_spec.lua | 12 +++--- test/functional/terminal/edit_spec.lua | 2 +- test/functional/terminal/ex_terminal_spec.lua | 26 ++++++------ test/functional/terminal/highlight_spec.lua | 10 ++--- test/functional/terminal/mouse_spec.lua | 14 +++---- test/functional/terminal/scrollback_spec.lua | 28 ++++++------- test/functional/terminal/tui_spec.lua | 25 +++++------ test/functional/terminal/window_spec.lua | 12 +++--- test/functional/terminal/window_split_tab_spec.lua | 4 +- test/functional/treesitter/parser_spec.lua | 4 +- test/functional/ui/cmdline_spec.lua | 4 +- test/functional/ui/embed_spec.lua | 2 +- test/functional/ui/hlstate_spec.lua | 8 ++-- test/functional/ui/messages_spec.lua | 7 ++-- test/functional/ui/output_spec.lua | 16 ++++---- test/functional/ui/screen_basic_spec.lua | 12 +++--- test/functional/ui/spell_spec.lua | 4 +- test/functional/ui/wildmode_spec.lua | 6 +-- test/functional/vimscript/eval_spec.lua | 4 +- test/functional/vimscript/executable_spec.lua | 22 ++++++---- test/functional/vimscript/execute_spec.lua | 4 +- test/functional/vimscript/exepath_spec.lua | 13 +++--- test/functional/vimscript/fnamemodify_spec.lua | 6 +-- test/functional/vimscript/functions_spec.lua | 4 +- test/functional/vimscript/has_spec.lua | 4 +- test/functional/vimscript/hostname_spec.lua | 6 +-- .../vimscript/msgpack_functions_spec.lua | 4 +- test/functional/vimscript/server_spec.lua | 10 ++--- test/functional/vimscript/system_spec.lua | 30 +++++++------- 73 files changed, 325 insertions(+), 328 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua index 0fbf58a8e7..3af1791e43 100644 --- a/test/functional/api/proc_spec.lua +++ b/test/functional/api/proc_spec.lua @@ -3,12 +3,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq local funcs = helpers.funcs -local iswin = helpers.iswin local neq = helpers.neq local nvim_argv = helpers.nvim_argv local request = helpers.request local retry = helpers.retry local NIL = helpers.NIL +local is_os = helpers.is_os describe('API', function() before_each(clear) @@ -62,7 +62,7 @@ describe('API', function() it('returns process info', function() local pid = funcs.getpid() local pinfo = request('nvim_get_proc', pid) - eq((iswin() and 'nvim.exe' or 'nvim'), pinfo.name) + eq((is_os('win') and 'nvim.exe' or 'nvim'), pinfo.name) eq(pid, pinfo.pid) eq('number', type(pinfo.ppid)) neq(pid, pinfo.ppid) diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 77a80ac7f3..833d54396b 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -5,7 +5,7 @@ local eq, clear, eval, command, nvim, next_msg = local meths = helpers.meths local exec_lua = helpers.exec_lua local retry = helpers.retry -local isCI = helpers.isCI +local is_ci = helpers.is_ci local assert_alive = helpers.assert_alive local skip = helpers.skip @@ -79,7 +79,7 @@ describe('notify', function() end) it('cancels stale events on channel close', function() - skip(isCI(), 'hangs on CI #14083 #15251') + 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 ([[ diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 045de94de2..ceff390dc5 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -250,7 +250,7 @@ describe('server -> client', function() pcall(funcs.jobstop, jobid) end) - if helpers.skip(helpers.iswin()) then return end + if helpers.skip(helpers.is_os('win')) then return end it('rpc and text stderr can be combined', function() local status, rv = pcall(funcs.rpcrequest, jobid, 'poll') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 9df73c8d69..3e1aab28ce 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -12,7 +12,6 @@ local exec = helpers.exec local eval = helpers.eval local expect = helpers.expect local funcs = helpers.funcs -local iswin = helpers.iswin local meths = helpers.meths local matches = helpers.matches local pesc = helpers.pesc @@ -400,7 +399,7 @@ describe('API', function() end) it('returns shell |:!| output', function() - local win_lf = iswin() and '\r' or '' + local win_lf = is_os('win') and '\r' or '' eq(':!echo foo\r\n\nfoo'..win_lf..'\n', nvim('command_output', [[!echo foo]])) end) @@ -2125,7 +2124,7 @@ describe('API', function() pty='?', } local event = meths.get_var("opened_event") - if not iswin() then + if not is_os('win') then info.pty = event.info.pty neq(nil, string.match(info.pty, "^/dev/")) end @@ -2141,7 +2140,7 @@ describe('API', function() stream = 'job', id = 4, argv = ( - iswin() and { + is_os('win') and { eval('&shell'), '/s', '/c', @@ -2163,7 +2162,7 @@ describe('API', function() -- :terminal with args + stopped process. eq(1, eval('jobstop(&channel)')) eval('jobwait([&channel], 1000)') -- Wait. - expected2.pty = (iswin() and '?' or '') -- pty stream was closed. + expected2.pty = (is_os('win') and '?' or '') -- pty stream was closed. eq(expected2, eval('nvim_get_chan_info(&channel)')) end) end) @@ -2724,7 +2723,7 @@ describe('API', function() eq({}, meths.get_runtime_file("foobarlang/", true)) end) it('can handle bad patterns', function() - skip(iswin()) + skip(is_os('win')) eq("Vim:E220: Missing }.", pcall_err(meths.get_runtime_file, "{", false)) diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 45dc06b39b..828cffa460 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -1,12 +1,12 @@ local lfs = require('lfs') -local h = require('test.functional.helpers')(after_each) +local helpers = require('test.functional.helpers')(after_each) -local clear = h.clear -local command = h.command -local eq = h.eq -local eval = h.eval -local request = h.request -local iswin = h.iswin +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local eval = helpers.eval +local request = helpers.request +local is_os = helpers.is_os describe('autocmd DirChanged and DirChangedPre', function() local curdir = string.gsub(lfs.currentdir(), '\\', '/') @@ -21,8 +21,8 @@ describe('autocmd DirChanged and DirChangedPre', function() curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR3', } - setup(function() for _, dir in pairs(dirs) do h.mkdir(dir) end end) - teardown(function() for _, dir in pairs(dirs) do h.rmdir(dir) end end) + setup(function() for _, dir in pairs(dirs) do helpers.mkdir(dir) end end) + teardown(function() for _, dir in pairs(dirs) do helpers.rmdir(dir) end end) before_each(function() clear() @@ -159,7 +159,7 @@ describe('autocmd DirChanged and DirChangedPre', function() eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) - if iswin() then + if is_os('win') then command('lcd '..win_dirs[1]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) @@ -182,7 +182,7 @@ describe('autocmd DirChanged and DirChangedPre', function() eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) - if iswin() then + if is_os('win') then command('tcd '..win_dirs[2]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) @@ -204,7 +204,7 @@ describe('autocmd DirChanged and DirChangedPre', function() eq(3, eval('g:cdprecount')) eq(3, eval('g:cdcount')) - if iswin() then + if is_os('win') then command('cd '..win_dirs[3]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) @@ -229,7 +229,7 @@ describe('autocmd DirChanged and DirChangedPre', function() eq(4, eval('g:cdprecount')) eq(4, eval('g:cdcount')) - if iswin() then + if is_os('win') then command('split '..win_dirs[1]..'/baz') eq({}, eval('g:evpre')) eq({}, eval('g:ev')) @@ -278,7 +278,7 @@ describe('autocmd DirChanged and DirChangedPre', function() eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - if iswin() then + if is_os('win') then command('tabnew') -- tab 3 eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua index b5fc6b7600..024dccbe8e 100644 --- a/test/functional/autocmd/focus_spec.lua +++ b/test/functional/autocmd/focus_spec.lua @@ -6,7 +6,7 @@ local nvim_prog = helpers.nvim_prog local feed_command = helpers.feed_command local feed_data = thelpers.feed_data -if helpers.skip(helpers.iswin()) then return end +if helpers.skip(helpers.is_os('win')) then return end describe('autoread TUI FocusGained/FocusLost', function() local f1 = 'xtest-foo' diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua index bbe1c186b2..738064090a 100644 --- a/test/functional/autocmd/signal_spec.lua +++ b/test/functional/autocmd/signal_spec.lua @@ -5,10 +5,10 @@ local command = helpers.command local eq = helpers.eq local funcs = helpers.funcs local next_msg = helpers.next_msg -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip -if skip(iswin(), 'Only applies to POSIX systems') then return end +if skip(is_os('win'), 'Only applies to POSIX systems') then return end local function posix_kill(signame, pid) os.execute('kill -s '..signame..' -- '..pid..' >/dev/null') diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index 5601965bd9..4717b1fa2e 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -10,8 +10,8 @@ local ok = helpers.ok local feed = helpers.feed local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive -local iswin = helpers.iswin local skip = helpers.skip +local is_os = helpers.is_os describe('autocmd TermClose', function() before_each(function() @@ -48,7 +48,7 @@ describe('autocmd TermClose', function() end) it('triggers when long-running terminal job gets stopped', function() - nvim('set_option', 'shell', iswin() and 'cmd.exe' or 'sh') + nvim('set_option', 'shell', is_os('win') and 'cmd.exe' or 'sh') command('autocmd TermClose * let g:test_termclose = 23') command('terminal') command('call jobstop(b:terminal_job_id)') @@ -56,7 +56,7 @@ describe('autocmd TermClose', function() end) it('kills job trapping SIGTERM', function() - skip(iswin()) + skip(is_os('win')) nvim('set_option', 'shell', 'sh') nvim('set_option', 'shellcmdflag', '-c') command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] @@ -76,7 +76,7 @@ describe('autocmd TermClose', function() end) it('kills PTY job trapping SIGHUP and SIGTERM', function() - skip(iswin()) + skip(is_os('win')) nvim('set_option', 'shell', 'sh') nvim('set_option', 'shellcmdflag', '-c') command([[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 63bd85ff43..8275575c24 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local uname = helpers.uname local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths @@ -12,7 +11,6 @@ local retry = helpers.retry local expect_twostreams = helpers.expect_twostreams local assert_alive = helpers.assert_alive local pcall_err = helpers.pcall_err -local iswin = helpers.iswin local skip = helpers.skip describe('channels', function() @@ -147,7 +145,7 @@ describe('channels', function() end it('can use stdio channel with pty', function() - skip(iswin()) + skip(is_os('win')) source([[ let g:job_opts = { \ 'on_stdout': function('OnEvent'), @@ -180,8 +178,7 @@ describe('channels', function() command("call chansend(id, 'incomplet\004')") - local is_bsd = not not string.find(uname(), 'bsd') - local bsdlike = is_bsd or is_os('mac') + local bsdlike = is_os('bsd') or is_os('mac') local extra = bsdlike and "^D\008\008" or "" expect_twoline(id, "stdout", "incomplet"..extra, "[1, ['incomplet'], 'stdin']", true) @@ -201,7 +198,7 @@ describe('channels', function() it('stdio channel can use rpc and stderr simultaneously', function() - skip(iswin()) + skip(is_os('win')) source([[ let g:job_opts = { \ 'on_stderr': function('OnEvent'), diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 00b9074e29..51189b7c32 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -21,14 +21,14 @@ local read_file = helpers.read_file local tmpname = helpers.tmpname local trim = helpers.trim local currentdir = helpers.funcs.getcwd -local iswin = helpers.iswin local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') local feed_command = helpers.feed_command -local isCI = helpers.isCI local skip = helpers.skip +local is_os = helpers.is_os +local is_ci = helpers.is_ci describe('fileio', function() before_each(function() @@ -90,7 +90,7 @@ describe('fileio', function() end) it('backup #9709', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) @@ -110,7 +110,7 @@ describe('fileio', function() end) it('backup with full path #11214', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) clear() mkdir('Xtest_backupdir') command('set backup') @@ -123,7 +123,7 @@ describe('fileio', function() -- Backup filename = fullpath, separators replaced with "%". local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1', - iswin() and '[:/\\]' or '/', '%%') .. '~' + is_os('win') and '[:/\\]' or '/', '%%') .. '~' local foo_contents = trim(read_file('Xtest_backupdir/'..backup_file_name)) local foobar_contents = trim(read_file('Xtest_startup_file1')) @@ -132,7 +132,7 @@ describe('fileio', function() end) it('backup symlinked files #11349', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) clear() local initial_content = 'foo' @@ -154,7 +154,7 @@ describe('fileio', function() it('backup symlinked files in first avialable backupdir #11349', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) clear() local initial_content = 'foo' @@ -299,7 +299,7 @@ describe('tmpdir', function() end) -- "…/nvim./" has wrong permissions: - skip(iswin(), 'TODO(justinmk): need setfperm/getfperm on Windows. #8244') + skip(is_os('win'), 'TODO(justinmk): need setfperm/getfperm on Windows. #8244') os.remove(testlog) os.remove(tmproot) mkdir(tmproot) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 4e5c4ca351..1bae626b98 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -13,7 +13,6 @@ local retry = helpers.retry local meths = helpers.meths local NIL = helpers.NIL local poke_eventloop = helpers.poke_eventloop -local iswin = helpers.iswin local get_pathsep = helpers.get_pathsep local pathroot = helpers.pathroot local exec_lua = helpers.exec_lua @@ -24,6 +23,7 @@ local pcall_err = helpers.pcall_err local matches = helpers.matches local Screen = require('test.functional.ui.screen') local skip = helpers.skip +local is_os = helpers.is_os describe('jobs', function() local channel @@ -56,7 +56,7 @@ describe('jobs', function() it('must specify env option as a dict', function() command("let g:job_opts.env = v:true") local _, err = pcall(function() - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('set', g:job_opts)") else nvim('command', "let j = jobstart('env', g:job_opts)") @@ -69,7 +69,7 @@ describe('jobs', function() nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") - if iswin() then + if is_os('win') then nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) @@ -88,12 +88,12 @@ describe('jobs', function() end) it('append environment with pty #env', function() - skip(iswin()) + skip(is_os('win')) nvim('command', "let $VAR = 'abc'") nvim('command', "let $TOTO = 'goodbye world'") nvim('command', "let g:job_opts.pty = v:true") nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") - if iswin() then + if is_os('win') then nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) @@ -123,7 +123,7 @@ describe('jobs', function() -- -- Rather than expecting a completely empty environment, ensure that $VAR -- is *not* in the environment but $TOTO is. - if iswin() then + if is_os('win') then nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) expect_msg_seq({ {'notification', 'stdout', {0, {'hello world %VAR%', ''}}} @@ -142,7 +142,7 @@ describe('jobs', function() -- Since $Toto is being set in the job, it should take precedence over the -- global $TOTO on Windows nvim('command', "let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") - if iswin() then + if is_os('win') then nvim('command', [[let j = jobstart('set | find /I "toto="', g:job_opts)]]) else nvim('command', [[let j = jobstart('env | grep -i toto=', g:job_opts)]]) @@ -151,7 +151,7 @@ describe('jobs', function() nvim('command', "let g:output = Normalize(g:job_opts.stdout)") local actual = eval('g:output') local expected - if iswin() then + if is_os('win') then -- Toto is normalized to TOTO so we can detect duplicates, and because -- Windows doesn't care about case expected = {'TOTO=def', ''} @@ -165,7 +165,7 @@ describe('jobs', function() it('uses &shell and &shellcmdflag if passed a string', function() nvim('command', "let $VAR = 'abc'") - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('echo %VAR%', g:job_opts)") else nvim('command', "let j = jobstart('echo $VAR', g:job_opts)") @@ -177,7 +177,7 @@ describe('jobs', function() it('changes to given / directory', function() nvim('command', "let g:job_opts.cwd = '/'") - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('cd', g:job_opts)") else nvim('command', "let j = jobstart('pwd', g:job_opts)") @@ -192,7 +192,7 @@ describe('jobs', function() local dir = eval("resolve(tempname())"):gsub("/", get_pathsep()) mkdir(dir) nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('cd', g:job_opts)") else nvim('command', "let j = jobstart('pwd', g:job_opts)") @@ -216,7 +216,7 @@ describe('jobs', function() local dir = eval('resolve(tempname())."-bogus"') local _, err = pcall(function() nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") - if iswin() then + if is_os('win') then nvim('command', "let j = jobstart('cd', g:job_opts)") else nvim('command', "let j = jobstart('pwd', g:job_opts)") @@ -226,7 +226,7 @@ describe('jobs', function() end) it('error on non-executable `cwd`', function() - skip(iswin(), 'Not applicable for Windows') + skip(is_os('win'), 'Not applicable for Windows') local dir = 'Xtest_not_executable_dir' mkdir(dir) @@ -249,7 +249,7 @@ describe('jobs', function() end local executable_jobid = new_job() - local exe = iswin() and './test/functional/fixtures' or './test/functional/fixtures/non_executable.txt' + local exe = is_os('win') and './test/functional/fixtures' or './test/functional/fixtures/non_executable.txt' eq("Vim:E475: Invalid value for argument cmd: '"..exe.."' is not executable", pcall_err(eval, "jobstart(['"..exe.."'])")) eq("", eval("v:errmsg")) @@ -703,7 +703,7 @@ describe('jobs', function() describe('jobwait', function() before_each(function() - if iswin() then + if is_os('win') then helpers.set_shell_powershell() end end) @@ -787,7 +787,7 @@ describe('jobs', function() feed_command('call rpcnotify(g:channel, "ready") | '.. 'call rpcnotify(g:channel, "wait", '.. 'jobwait([jobstart("'.. - (iswin() and 'Start-Sleep 10' or 'sleep 10').. + (is_os('win') and 'Start-Sleep 10' or 'sleep 10').. '; exit 55")]))') eq({'notification', 'ready', {}}, next_msg()) feed('') @@ -798,7 +798,7 @@ describe('jobs', function() feed_command('call rpcnotify(g:channel, "ready") | '.. 'call rpcnotify(g:channel, "wait", '.. 'jobwait([jobstart("'.. - (iswin() and 'Start-Sleep 10' or 'sleep 10').. + (is_os('win') and 'Start-Sleep 10' or 'sleep 10').. '; exit 55")], 10000))') eq({'notification', 'ready', {}}, next_msg()) feed('') @@ -806,7 +806,7 @@ describe('jobs', function() end) it('can be called recursively', function() - skip(iswin(), "TODO: Need `cat`") + skip(is_os('win'), "TODO: Need `cat`") source([[ let g:opts = {} let g:counter = 0 @@ -931,7 +931,7 @@ describe('jobs', function() -- ..c.."', '-c', '"..c.."'])") -- Create child with several descendants. - if iswin() then + if is_os('win') then source([[ function! s:formatprocs(pid, prefix) let result = '' @@ -980,13 +980,13 @@ describe('jobs', function() endfunction ]]) end - local sleep_cmd = (iswin() + local sleep_cmd = (is_os('win') and 'ping -n 31 127.0.0.1' or 'sleep 30') local j = eval("jobstart('"..sleep_cmd..' | '..sleep_cmd..' | '..sleep_cmd.."')") local ppid = funcs.jobpid(j) local children - if iswin() then + if is_os('win') then local status, result = pcall(retry, nil, nil, function() children = meths.get_proc_children(ppid) -- On Windows conhost.exe may exist, and @@ -1007,7 +1007,7 @@ describe('jobs', function() -- Assert that nvim_get_proc() sees the children. for _, child_pid in ipairs(children) do local info = meths.get_proc(child_pid) - -- eq((iswin() and 'nvim.exe' or 'nvim'), info.name) + -- eq((is_os('win') and 'nvim.exe' or 'nvim'), info.name) eq(ppid, info.ppid) end -- Kill the root of the tree. @@ -1028,7 +1028,7 @@ describe('jobs', function() end) describe('running tty-test program', function() - if skip(iswin()) then return end + if skip(is_os('win')) then return end local function next_chunk() local rv while true do @@ -1125,7 +1125,7 @@ describe("pty process teardown", function() end) it("does not prevent/delay exit. #4798 #4900", function() - skip(iswin()) + skip(is_os('win')) -- Use a nested nvim (in :term) to test without --headless. feed_command(":terminal '"..helpers.nvim_prog .."' -u NONE -i NONE --cmd '"..nvim_set.."' " diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 782a03bfed..53461f505a 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -9,7 +9,7 @@ local clear = helpers.clear local funcs = helpers.funcs local nvim_prog_abs = helpers.nvim_prog_abs local write_file = helpers.write_file -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip describe('Command-line option', function() @@ -51,7 +51,7 @@ describe('Command-line option', function() eq(#('100500\n'), attrs.size) end) it('does not crash after reading from stdin in non-headless mode', function() - skip(iswin()) + skip(is_os('win')) local screen = Screen.new(40, 8) screen:attach() local args = { diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 61fae7622c..a786887bbd 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -3,16 +3,16 @@ local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval local command = helpers.command -local iswin = helpers.iswin local insert = helpers.insert local feed = helpers.feed +local is_os = helpers.is_os describe('path collapse', function() local targetdir local expected_path local function join_path(...) - local pathsep = (iswin() and '\\' or '/') + local pathsep = (is_os('win') and '\\' or '/') return table.concat({...}, pathsep) end diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 2084d365a5..bab339e253 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -20,11 +20,11 @@ local read_file = helpers.read_file local retry = helpers.retry local rmdir = helpers.rmdir local sleep = helpers.sleep -local iswin = helpers.iswin local startswith = helpers.startswith local write_file = helpers.write_file local meths = helpers.meths local alter_slashes = helpers.alter_slashes +local is_os = helpers.is_os local testfile = 'Xtest_startuptime' after_each(function() @@ -79,7 +79,7 @@ describe('startup', function() it('in a TTY: has("ttyin")==1 has("ttyout")==1', function() local screen = Screen.new(25, 4) screen:attach() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -95,7 +95,7 @@ describe('startup', function() ]]) end) it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -111,7 +111,7 @@ describe('startup', function() end) end) it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -130,7 +130,7 @@ describe('startup', function() it('input from pipe (implicit) #7679', function() local screen = Screen.new(25, 4) screen:attach() - if iswin() then + if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal @@ -665,7 +665,7 @@ describe('runtime:', function() end) it('loads plugin/*.lua from site packages', function() - local nvimdata = iswin() and "nvim-data" or "nvim" + local nvimdata = is_os('win') and "nvim-data" or "nvim" local plugin_path = table.concat({xdata, nvimdata, 'site', 'pack', 'xa', 'start', 'yb'}, pathsep) local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep) local plugin_after_path = table.concat({plugin_path, 'after', 'plugin'}, pathsep) diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index d2135d0613..5ed71651c7 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -9,8 +9,8 @@ local clear = helpers.clear local command = helpers.command local exc_exec = helpers.exc_exec local pathsep = helpers.get_pathsep() -local iswin = helpers.iswin local skip = helpers.skip +local is_os = helpers.is_os -- These directories will be created for testing local directories = { @@ -281,7 +281,7 @@ describe("getcwd()", function () end) it("returns empty string if working directory does not exist", function() - skip(iswin()) + skip(is_os('win')) command("cd "..directories.global) command("call delete('../"..directories.global.."', 'd')") eq("", helpers.eval("getcwd()")) diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index b7ff6a7bf7..0a0c7ca410 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -5,7 +5,6 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command local get_pathsep = helpers.get_pathsep -local iswin = helpers.iswin local eq = helpers.eq local neq = helpers.neq local funcs = helpers.funcs @@ -15,6 +14,7 @@ local rmdir = helpers.rmdir local sleep = helpers.sleep local meths = helpers.meths local skip = helpers.skip +local is_os = helpers.is_os local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec' @@ -178,7 +178,7 @@ describe(':mksession', function() command('cd ' .. cwd_dir) command('mksession ' .. session_path) command('%bwipeout!') - if iswin() then + if is_os('win') then sleep(100) -- Make sure all child processes have exited. end @@ -189,13 +189,13 @@ describe(':mksession', function() local expected_cwd = cwd_dir .. '/' .. tab_dir matches('^term://' .. pesc(expected_cwd) .. '//%d+:', funcs.expand('%')) command('%bwipeout!') - if iswin() then + if is_os('win') then sleep(100) -- Make sure all child processes have exited. end end) it('restores CWD for :terminal buffer at root directory #16988', function() - skip(iswin(), 'N/A for Windows') + skip(is_os('win'), 'N/A for Windows') local screen local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 10ebefd8cd..64c3464be7 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -14,9 +14,9 @@ local eval = helpers.eval local exec_capture = helpers.exec_capture local neq = helpers.neq local matches = helpers.matches -local iswin = helpers.iswin local mkdir = helpers.mkdir local rmdir = helpers.rmdir +local is_os = helpers.is_os describe(':source', function() before_each(function() @@ -44,7 +44,7 @@ describe(':source', function() end) it("changing 'shellslash' changes the result of expand()", function() - if not iswin() then + if not is_os('win') then pending("'shellslash' only works on Windows") return end diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index e2a6b6460d..1ccd27875e 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -8,9 +8,9 @@ local command = helpers.command local feed_command = helpers.feed_command local funcs = helpers.funcs local meths = helpers.meths -local iswin = helpers.iswin -local isCI = helpers.isCI local skip = helpers.skip +local is_os = helpers.is_os +local is_ci = helpers.is_ci local fname = 'Xtest-functional-ex_cmds-write' local fname_bak = fname .. '~' @@ -39,7 +39,7 @@ describe(':write', function() it('&backupcopy=auto preserves symlinks', function() command('set backupcopy=auto') write_file('test_bkc_file.txt', 'content0') - if iswin() then + if is_os('win') then command("silent !mklink test_bkc_link.txt test_bkc_file.txt") else command("silent !ln -s test_bkc_file.txt test_bkc_link.txt") @@ -57,10 +57,10 @@ describe(':write', function() end) it('&backupcopy=no replaces symlink with new file', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) command('set backupcopy=no') write_file('test_bkc_file.txt', 'content0') - if iswin() then + if is_os('win') then command("silent !mklink test_bkc_link.txt test_bkc_file.txt") else command("silent !ln -s test_bkc_file.txt test_bkc_link.txt") @@ -79,7 +79,7 @@ describe(':write', function() it("appends FIFO file", function() -- mkfifo creates read-only .lnk files on Windows - if iswin() or eval("executable('mkfifo')") == 0 then + if is_os('win') or eval("executable('mkfifo')") == 0 then pending('missing "mkfifo" command') end @@ -112,7 +112,7 @@ describe(':write', function() eq(1, eval("filereadable('test/write/p_opt.txt')")) eq(('Vim(write):E32: No file name'), pcall_err(command, 'write ++p test_write/')) - if not iswin() then + if not is_os('win') then eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), pcall_err(command, 'write ++p .')) eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), @@ -121,11 +121,11 @@ describe(':write', function() end) it('errors out correctly', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) command('let $HOME=""') eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) -- Message from check_overwrite - if not iswin() then + if not is_os('win') then eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), pcall_err(command, 'write .')) end @@ -144,7 +144,7 @@ describe(':write', function() funcs.setfperm(fname, 'r--------') eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', pcall_err(command, 'write')) - if iswin() then + if is_os('win') then eq(0, os.execute('del /q/f ' .. fname)) eq(0, os.execute('rd /q/s ' .. fname_bak)) else @@ -152,7 +152,7 @@ describe(':write', function() eq(true, os.remove(fname_bak)) end write_file(fname_bak, 'TTYX') - skip(iswin(), [[FIXME: exc_exec('write!') outputs 0 in Windows]]) + skip(is_os('win'), [[FIXME: exc_exec('write!') outputs 0 in Windows]]) lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true) eq('Vim(write):E166: Can\'t open linked file for writing', pcall_err(command, 'write!')) diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index 7c00daf1d7..861a977ea6 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -3,14 +3,14 @@ local lfs = require('lfs') local clear = helpers.clear local command, eq, neq, write_file = helpers.command, helpers.eq, helpers.neq, helpers.write_file -local iswin = helpers.iswin local read_file = helpers.read_file +local is_os = helpers.is_os describe(':wshada', function() local shada_file = 'wshada_test' before_each(function() - clear{args={'-i', iswin() and 'nul' or '/dev/null', + clear{args={'-i', is_os('win') and 'nul' or '/dev/null', -- Need 'swapfile' for these tests. '--cmd', 'set swapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'}, args_rm={'-n', '-i', '--cmd'}} diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 1cd632f00b..ca59eb3182 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -54,7 +54,6 @@ if module.nvim_dir == module.nvim_prog then module.nvim_dir = "." end -local iswin = global_helpers.iswin local prepend_argv if os.getenv('VALGRIND') then @@ -557,7 +556,7 @@ function module.source(code) end function module.has_powershell() - return module.eval('executable("'..(iswin() and 'powershell' or 'pwsh')..'")') == 1 + return module.eval('executable("'..(is_os('win') and 'powershell' or 'pwsh')..'")') == 1 end --- Sets Nvim shell to powershell. @@ -570,9 +569,9 @@ function module.set_shell_powershell(fake) if not fake then assert(found) end - local shell = found and (iswin() and 'powershell' or 'pwsh') or module.testprg('pwsh-test') + local shell = found and (is_os('win') and 'powershell' or 'pwsh') or module.testprg('pwsh-test') local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();' - local cmd = set_encoding..'Remove-Item -Force '..table.concat(iswin() + local cmd = set_encoding..'Remove-Item -Force '..table.concat(is_os('win') and {'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort'} or {'alias:echo'}, ',')..';' module.exec([[ @@ -854,13 +853,13 @@ function module.exec_lua(code, ...) end function module.get_pathsep() - return iswin() and '\\' or '/' + return is_os('win') and '\\' or '/' end --- Gets the filesystem root dir, namely "/" or "C:/". function module.pathroot() local pathsep = package.config:sub(1,1) - return iswin() and (module.nvim_dir:sub(1,2)..pathsep) or '/' + return is_os('win') and (module.nvim_dir:sub(1,2)..pathsep) or '/' end --- Gets the full `…/build/bin/{name}` path of a test program produced by @@ -868,7 +867,7 @@ end --- --- @param name (string) Name of the test program. function module.testprg(name) - local ext = module.iswin() and '.exe' or '' + local ext = module.is_os('win') and '.exe' or '' return ('%s/%s%s'):format(module.nvim_dir, name, ext) end @@ -895,7 +894,7 @@ function module.missing_provider(provider) end function module.alter_slashes(obj) - if not iswin() then + if not is_os('win') then return obj end if type(obj) == 'string' then @@ -913,7 +912,7 @@ function module.alter_slashes(obj) end local load_factor = 1 -if global_helpers.isCI() then +if global_helpers.is_ci() then -- Compute load factor only once (but outside of any tests). module.clear() module.request('nvim_command', 'source src/nvim/testdir/load.vim') @@ -946,14 +945,14 @@ end -- Kill process with given pid function module.os_kill(pid) - return os.execute((iswin() + return os.execute((is_os('win') and 'taskkill /f /t /pid '..pid..' > nul' or 'kill -9 '..pid..' > /dev/null')) end -- Create folder with non existing parents function module.mkdir_p(path) - return os.execute((iswin() + return os.execute((is_os('win') and 'mkdir '..path or 'mkdir -p '..path)) end diff --git a/test/functional/legacy/011_autocommands_spec.lua b/test/functional/legacy/011_autocommands_spec.lua index 0fa9290f3c..7ae851467f 100644 --- a/test/functional/legacy/011_autocommands_spec.lua +++ b/test/functional/legacy/011_autocommands_spec.lua @@ -18,11 +18,11 @@ local clear, feed_command, expect, eq, neq, dedent, write_file, feed = helpers.clear, helpers.feed_command, helpers.expect, helpers.eq, helpers.neq, helpers.dedent, helpers.write_file, helpers.feed local command = helpers.command -local iswin = helpers.iswin local read_file = helpers.read_file +local is_os = helpers.is_os local function has_gzip() - local null = iswin() and 'nul' or '/dev/null' + local null = is_os('win') and 'nul' or '/dev/null' return os.execute('gzip --help >' .. null .. ' 2>&1') == 0 end diff --git a/test/functional/legacy/025_jump_tag_hidden_spec.lua b/test/functional/legacy/025_jump_tag_hidden_spec.lua index dd89a3680e..15bd56a601 100644 --- a/test/functional/legacy/025_jump_tag_hidden_spec.lua +++ b/test/functional/legacy/025_jump_tag_hidden_spec.lua @@ -23,7 +23,7 @@ describe('jump to a tag with hidden set', function() feed_command('set hidden') -- Create a link from test25.dir to the current directory. - if helpers.iswin() then + if helpers.is_os('win') then feed_command('!rd /q/s test25.dir') feed_command('!mklink /j test25.dir .') else @@ -33,7 +33,7 @@ describe('jump to a tag with hidden set', function() -- Create tags.text, with the current directory name inserted. feed_command('/tags line') - feed_command('r !' .. (helpers.iswin() and 'cd' or 'pwd')) + feed_command('r !' .. (helpers.is_os('win') and 'cd' or 'pwd')) feed('d$/test') feed('hP:.w! tags.test') @@ -44,7 +44,7 @@ describe('jump to a tag with hidden set', function() feed('G x:yank a') feed_command("call delete('tags.test')") feed_command("call delete('Xxx')") - if helpers.iswin() then + if helpers.is_os('win') then feed_command('!rd /q test25.dir') else feed_command('!rm -f test25.dir') diff --git a/test/functional/legacy/097_glob_path_spec.lua b/test/functional/legacy/097_glob_path_spec.lua index dd5a26ad3b..a62dc4d4c8 100644 --- a/test/functional/legacy/097_glob_path_spec.lua +++ b/test/functional/legacy/097_glob_path_spec.lua @@ -10,7 +10,7 @@ describe('glob() and globpath()', function() setup(clear) setup(function() - if helpers.iswin() then + if helpers.is_os('win') then os.execute("md sautest\\autoload") os.execute(".>sautest\\autoload\\Test104.vim 2>nul") os.execute(".>sautest\\autoload\\footest.vim 2>nul") @@ -28,7 +28,7 @@ describe('glob() and globpath()', function() -- Consistent sorting of file names command('set nofileignorecase') - if helpers.iswin() then + if helpers.is_os('win') then command([[$put =glob('Xxx{')]]) command([[$put =glob('Xxx$')]]) @@ -72,7 +72,7 @@ describe('glob() and globpath()', function() end) teardown(function() - if helpers.iswin() then + if helpers.is_os('win') then os.execute('del /q/f Xxx{ Xxx$') os.execute('rd /q /s sautest') else diff --git a/test/functional/legacy/delete_spec.lua b/test/functional/legacy/delete_spec.lua index 4ba4c8d356..cefcd6c6c4 100644 --- a/test/functional/legacy/delete_spec.lua +++ b/test/functional/legacy/delete_spec.lua @@ -48,7 +48,7 @@ describe('Test for delete()', function() it('symlink directory delete', function() command("call mkdir('Xdir1')") - if helpers.iswin() then + if helpers.is_os('win') then command("silent !mklink /j Xlink Xdir1") else command("silent !ln -s Xdir1 Xlink") diff --git a/test/functional/legacy/excmd_spec.lua b/test/functional/legacy/excmd_spec.lua index ece88d26bd..eb480a6689 100644 --- a/test/functional/legacy/excmd_spec.lua +++ b/test/functional/legacy/excmd_spec.lua @@ -7,12 +7,12 @@ local exec_lua = helpers.exec_lua local expect_exit = helpers.expect_exit local feed = helpers.feed local funcs = helpers.funcs -local iswin = helpers.iswin local meths = helpers.meths local read_file = helpers.read_file local source = helpers.source local eq = helpers.eq local write_file = helpers.write_file +local is_os = helpers.is_os local function sizeoflong() if not exec_lua('return pcall(require, "ffi")') then @@ -376,7 +376,7 @@ describe(':confirm command dialog', function() {3:(Y)es, [N]o: }^ | ]]) feed('Y') - if iswin() then + if is_os('win') then screen:expect([[ foobar | {0:~ }| @@ -416,7 +416,7 @@ describe(':confirm command dialog', function() {3:(Y)es, [N]o: }^ | ]]) feed('Y') - if iswin() then + if is_os('win') then screen:expect([[ foobar | {1: }| @@ -493,7 +493,7 @@ describe(':confirm command dialog', function() {3:(Y)es, [N]o: }^ | ]]) feed('Y') - if iswin() then + if is_os('win') then screen:expect([[ a | b | diff --git a/test/functional/legacy/filechanged_spec.lua b/test/functional/legacy/filechanged_spec.lua index 747eca1c45..cea1d6ac30 100644 --- a/test/functional/legacy/filechanged_spec.lua +++ b/test/functional/legacy/filechanged_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, source = helpers.clear, helpers.source local call, eq, meths = helpers.call, helpers.eq, helpers.meths -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip local function expected_empty() @@ -17,7 +17,7 @@ describe('file changed dialog', function() end) it('works', function() - skip(iswin()) + skip(is_os('win')) source([[ func Test_file_changed_dialog() au! FileChangedShell diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua index eec89aa919..8d9b28e1fc 100644 --- a/test/functional/legacy/memory_usage_spec.lua +++ b/test/functional/legacy/memory_usage_spec.lua @@ -3,15 +3,14 @@ local clear = helpers.clear local eval = helpers.eval local eq = helpers.eq local feed_command = helpers.feed_command -local iswin = helpers.iswin local retry = helpers.retry local ok = helpers.ok local source = helpers.source local poke_eventloop = helpers.poke_eventloop -local uname = helpers.uname local load_adjust = helpers.load_adjust local write_file = helpers.write_file -local isCI = helpers.isCI +local is_os = helpers.is_os +local is_ci = helpers.is_ci local function isasan() local version = eval('execute("version")') @@ -22,8 +21,8 @@ clear() if isasan() then pending('ASAN build is difficult to estimate memory usage', function() end) return -elseif iswin() then - if isCI('github') then +elseif is_os('win') then + if is_ci('github') then pending('Windows runners in Github Actions do not have a stable environment to estimate memory usage', function() end) return elseif eval("executable('wmic')") == 0 then @@ -38,7 +37,7 @@ end local monitor_memory_usage = { memory_usage = function(self) local handle - if iswin() then + if is_os('win') then handle = io.popen('wmic process where processid=' ..self.pid..' get WorkingSetSize') else handle = io.popen('ps -o rss= -p '..self.pid) @@ -169,7 +168,7 @@ describe('memory usage', function() -- Allow for 20% tolerance at the upper limit. That's very permissive, but -- otherwise the test fails sometimes. On Sourcehut CI with FreeBSD we need to -- be even much more permissive. - local upper_multiplier = uname() == 'freebsd' and 19 or 12 + local upper_multiplier = is_os('freebsd') and 19 or 12 local lower = before.last * 8 / 10 local upper = load_adjust((after.max + (after.last - before.last)) * upper_multiplier / 10) check_result({before=before, after=after, last=last}, @@ -179,7 +178,7 @@ describe('memory usage', function() end) it('releases memory when closing windows when folds exist', function() - if helpers.is_os('mac') then + if is_os('mac') then pending('macOS memory compression causes flakiness') end local pid = eval('getpid()') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 3123ec324c..fc228e54bc 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -7,10 +7,10 @@ local mkdir_p = helpers.mkdir_p local rmdir = helpers.rmdir local nvim_dir = helpers.nvim_dir local test_build_dir = helpers.test_build_dir -local iswin = helpers.iswin local nvim_prog = helpers.nvim_prog +local is_os = helpers.is_os -local nvim_prog_basename = iswin() and 'nvim.exe' or 'nvim' +local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim' before_each(clear) @@ -102,7 +102,7 @@ describe('vim.fs', function() eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]]) end) it('works with ~', function() - if iswin() then + if is_os('win') then pending([[$HOME does not exist on Windows ¯\_(ツ)_/¯]]) end eq(os.getenv('HOME') .. '/src/foo', exec_lua [[ return vim.fs.normalize('~/src/foo') ]]) diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 32c1615a45..3f107811ae 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -8,12 +8,12 @@ local feed = helpers.feed local clear = helpers.clear local funcs = helpers.funcs local meths = helpers.meths -local iswin = helpers.iswin local command = helpers.command local write_file = helpers.write_file local exec_capture = helpers.exec_capture local exec_lua = helpers.exec_lua local pcall_err = helpers.pcall_err +local is_os = helpers.is_os local screen @@ -135,7 +135,7 @@ describe('print', function() print("very slow") vim.api.nvim_command("sleep 1m") -- force deferred event processing end - ]], (iswin() and "timeout 1") or "sleep 0.1") + ]], (is_os('win') and "timeout 1") or "sleep 0.1") eq('very slow\nvery fast', exec_capture('lua test()')) end) end) diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua index c348526d65..a5eeee8494 100644 --- a/test/functional/lua/secure_spec.lua +++ b/test/functional/lua/secure_spec.lua @@ -5,7 +5,7 @@ local eq = helpers.eq local clear = helpers.clear local command = helpers.command local pathsep = helpers.get_pathsep() -local iswin = helpers.iswin() +local is_os = helpers.is_os local curbufmeths = helpers.curbufmeths local exec_lua = helpers.exec_lua local feed_command = helpers.feed_command @@ -18,7 +18,7 @@ describe('vim.secure', function() local xstate = 'Xstate' setup(function() - helpers.mkdir_p(xstate .. pathsep .. (iswin and 'nvim-data' or 'nvim')) + helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) end) teardown(function() diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua index 38c7801d55..416e9e1f02 100644 --- a/test/functional/lua/uri_spec.lua +++ b/test/functional/lua/uri_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip local write_file = require('test.helpers').write_file @@ -169,7 +169,7 @@ describe('URI methods', function() describe('uri from bufnr', function() it('Windows paths should not be treated as uris', function() - skip(not iswin(), "Not applicable on non-Windows") + skip(not is_os('win'), "Not applicable on non-Windows") local file = helpers.tmpname() write_file(file, 'Test content') diff --git a/test/functional/options/autochdir_spec.lua b/test/functional/options/autochdir_spec.lua index 74959a8e76..0b6fe9533c 100644 --- a/test/functional/options/autochdir_spec.lua +++ b/test/functional/options/autochdir_spec.lua @@ -16,7 +16,7 @@ describe("'autochdir'", function() -- With 'autochdir' on, we should get the directory of tty-test.c. clear('--cmd', 'set autochdir', targetdir..'/tty-test.c') - eq(helpers.iswin() and expected:gsub('/', '\\') or expected, funcs.getcwd()) + eq(helpers.is_os('win') and expected:gsub('/', '\\') or expected, funcs.getcwd()) end) it('is not overwritten by getwinvar() call #17609',function() diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 130ed73c34..c0d820f40e 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -12,13 +12,13 @@ local eq = helpers.eq local ok = helpers.ok local funcs = helpers.funcs local insert = helpers.insert -local iswin = helpers.iswin local neq = helpers.neq local mkdir = helpers.mkdir local rmdir = helpers.rmdir local alter_slashes = helpers.alter_slashes local tbl_contains = helpers.tbl_contains local expect_exit = helpers.expect_exit +local is_os = helpers.is_os describe('startup defaults', function() describe(':filetype', function() @@ -240,7 +240,7 @@ describe('startup defaults', function() describe('$NVIM_LOG_FILE', function() local xdgdir = 'Xtest-startup-xdg-logpath' - local xdgstatedir = iswin() and xdgdir..'/nvim-data' or xdgdir..'/nvim' + local xdgstatedir = is_os('win') and xdgdir..'/nvim-data' or xdgdir..'/nvim' after_each(function() os.remove('Xtest-logpath') rmdir(xdgdir) @@ -279,7 +279,7 @@ describe('XDG defaults', function() clear() local rtp = eval('split(&runtimepath, ",")') local rv = {} - local expected = (iswin() + local expected = (is_os('win') and { [[\nvim-data\site]], [[\nvim-data\site\after]], } or { '/nvim/site', '/nvim/site/after', }) @@ -327,10 +327,10 @@ describe('XDG defaults', function() return vimruntime, libdir end - local env_sep = iswin() and ';' or ':' - local data_dir = iswin() and 'nvim-data' or 'nvim' - local state_dir = iswin() and 'nvim-data' or 'nvim' - local root_path = iswin() and 'C:' or '' + local env_sep = is_os('win') and ';' or ':' + local data_dir = is_os('win') and 'nvim-data' or 'nvim' + local state_dir = is_os('win') and 'nvim-data' or 'nvim' + local root_path = is_os('win') and 'C:' or '' describe('with too long XDG variables', function() before_each(function() @@ -497,7 +497,7 @@ describe('XDG defaults', function() it('are escaped properly', function() local vimruntime, libdir = vimruntime_and_libdir() - local path_sep = iswin() and '\\' or '/' + local path_sep = is_os('win') and '\\' or '/' eq(('\\, \\, \\,' .. path_sep .. 'nvim' .. ',\\,-\\,-\\,' .. path_sep .. 'nvim' .. ',-\\,-\\,-' .. path_sep .. 'nvim' @@ -549,9 +549,9 @@ end) describe('stdpath()', function() -- Windows appends 'nvim-data' instead of just 'nvim' to prevent collisions -- due to XDG_CONFIG_HOME, XDG_DATA_HOME and XDG_STATE_HOME being the same. - local datadir = iswin() and 'nvim-data' or 'nvim' - local statedir = iswin() and 'nvim-data' or 'nvim' - local env_sep = iswin() and ';' or ':' + local datadir = is_os('win') and 'nvim-data' or 'nvim' + local statedir = is_os('win') and 'nvim-data' or 'nvim' + local env_sep = is_os('win') and ';' or ':' it('acceptance', function() clear() -- Do not explicitly set any env vars. @@ -704,7 +704,7 @@ describe('stdpath()', function() context('returns a List', function() -- Some OS specific variables the system would have set. local function base_env() - if iswin() then + if is_os('win') then return { HOME='C:\\Users\\docwhat', -- technically, is not a usual PATH HOMEDRIVE='C:', diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 2ab1e34de4..071791e702 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -17,9 +17,9 @@ local retry = helpers.retry local NIL = helpers.NIL local read_file = require('test.helpers').read_file local write_file = require('test.helpers').write_file -local isCI = helpers.isCI +local is_ci = helpers.is_ci local meths = helpers.meths -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip -- Use these to get access to a coroutine so that I can run async tests and use @@ -27,7 +27,7 @@ local skip = helpers.skip local run, stop = helpers.run, helpers.stop -- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837 -if skip(iswin()) then return end +if skip(is_os('win')) then return end -- Fake LSP server. local fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' @@ -318,7 +318,7 @@ describe('LSP', function() end) it('should succeed with manual shutdown', function() - if isCI() then + if is_ci() then pending('hangs the build on CI #14028, re-enable with freeze timeout #14204') return elseif helpers.skip_fragile(pending) then diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index c57f43c632..c6c7d2b03d 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -8,8 +8,8 @@ local nvim_prog = helpers.nvim_prog local matches = helpers.matches local write_file = helpers.write_file local tmpname = helpers.tmpname -local isCI = helpers.isCI local skip = helpers.skip +local is_ci = helpers.is_ci clear() if funcs.executable('man') == 0 then @@ -162,7 +162,7 @@ describe(':Man', function() end) it('reports non-existent man pages for absolute paths', function() - skip(isCI('cirrus')) + skip(is_ci('cirrus')) local actual_file = tmpname() -- actual_file must be an absolute path to an existent file for us to test against it matches('^/.+', actual_file) diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index dda8077f05..93cf6d2b77 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -2140,7 +2140,7 @@ end) describe('plugin/shada.vim', function() local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) - local eol = helpers.iswin() and '\r\n' or '\n' + local eol = helpers.is_os('win') and '\r\n' or '\n' before_each(function() -- Note: reset() is called explicitly in each test. os.remove(fname) diff --git a/test/functional/preload.lua b/test/functional/preload.lua index 74f03eaecf..43e2151f84 100644 --- a/test/functional/preload.lua +++ b/test/functional/preload.lua @@ -2,10 +2,10 @@ -- Busted started doing this to help provide more isolation. See issue #62 -- for more information about this. local helpers = require('test.functional.helpers')(nil) -local iswin = helpers.iswin local busted = require("busted") +local is_os = helpers.is_os -if iswin() then +if is_os('win') then local ffi = require('ffi') ffi.cdef[[ typedef int errno_t; diff --git a/test/functional/provider/perl_spec.lua b/test/functional/provider/perl_spec.lua index 4c5c3ece15..ce92831f4c 100644 --- a/test/functional/provider/perl_spec.lua +++ b/test/functional/provider/perl_spec.lua @@ -9,7 +9,7 @@ local curbufmeths = helpers.curbufmeths local insert = helpers.insert local expect = helpers.expect local feed = helpers.feed -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip do @@ -26,7 +26,7 @@ before_each(function() end) describe('legacy perl provider', function() - skip(iswin()) + skip(is_os('win')) it('feature test', function() eq(1, eval('has("perl")')) @@ -70,7 +70,7 @@ describe('legacy perl provider', function() end) describe('perl provider', function() - skip(iswin()) + skip(is_os('win')) teardown(function () os.remove('Xtest-perl-hello.pl') os.remove('Xtest-perl-hello-plugin.pl') diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index a5ef60d91f..fb656735dd 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -12,7 +12,7 @@ local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-compati local mock_file_path = '/a/b/' local mock_file_path2 = '/d/e/' -if helpers.iswin() then +if helpers.is_os('win') then mock_file_path = 'C:/a/' mock_file_path2 = 'C:/d/' end diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index 2d44b0a950..da2fbbe029 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -14,7 +14,7 @@ local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-merging.shada') local mock_file_path = '/a/b/' -if helpers.iswin() then +if helpers.is_os('win') then mock_file_path = 'C:/a/' end diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 210c09e187..88a99d9b55 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -5,7 +5,7 @@ local meths, nvim_command, funcs, eq = local write_file, spawn, set_session, nvim_prog, exc_exec = helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.exc_exec -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip local lfs = require('lfs') @@ -250,7 +250,7 @@ describe('ShaDa support code', function() end) it('does not crash when ShaDa file directory is not writable', function() - skip(iswin()) + skip(is_os('win')) funcs.mkdir(dirname, '', 0) eq(0, funcs.filewritable(dirname)) diff --git a/test/functional/terminal/altscreen_spec.lua b/test/functional/terminal/altscreen_spec.lua index 457a5aa18f..cbe5e06005 100644 --- a/test/functional/terminal/altscreen_spec.lua +++ b/test/functional/terminal/altscreen_spec.lua @@ -6,7 +6,7 @@ local feed_data = thelpers.feed_data local enter_altscreen = thelpers.enter_altscreen local exit_altscreen = thelpers.exit_altscreen -if helpers.skip(helpers.iswin()) then return end +if helpers.skip(helpers.is_os('win')) then return end describe(':terminal altscreen', function() local screen diff --git a/test/functional/terminal/api_spec.lua b/test/functional/terminal/api_spec.lua index b5697c4c6b..38ef7c2a61 100644 --- a/test/functional/terminal/api_spec.lua +++ b/test/functional/terminal/api_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local child_session = require('test.functional.terminal.helpers') local ok = helpers.ok -if helpers.skip(helpers.iswin()) then return end +if helpers.skip(helpers.is_os('win')) then return end describe('api', function() local screen diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 5a75af69c0..9c8b983ff7 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -15,7 +15,7 @@ local matches = helpers.matches local exec_lua = helpers.exec_lua local sleep = helpers.sleep local funcs = helpers.funcs -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip describe(':terminal buffer', function() @@ -202,7 +202,7 @@ describe(':terminal buffer', function() -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') - local exitcmd = helpers.iswin() + local exitcmd = helpers.is_os('win') and "['cmd', '/c', 'exit']" or "['sh', '-c', 'exit']" source([[ @@ -264,7 +264,7 @@ describe(':terminal buffer', function() end) it('it works with set rightleft #11438', function() - skip(iswin()) + skip(is_os('win')) local columns = eval('&columns') feed(string.rep('a', columns)) command('set rightleft') diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index fdd7b9407b..98ac03211a 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -9,7 +9,7 @@ local matches = helpers.matches local feed_command = helpers.feed_command local hide_cursor = thelpers.hide_cursor local show_cursor = thelpers.show_cursor -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip describe(':terminal cursor', function() @@ -90,7 +90,7 @@ describe(':terminal cursor', function() describe('when invisible', function() it('is not highlighted and is detached from screen cursor', function() - skip(iswin()) + skip(is_os('win')) hide_cursor() screen:expect([[ tty ready | @@ -363,7 +363,7 @@ describe('buffer cursor position is correct in terminal without number column', end) describe('in a line with single-cell composed multibyte characters and no trailing spaces,', function() - if skip(iswin(), "Encoding problem?") then return end + if skip(is_os('win'), "Encoding problem?") then return end before_each(function() setup_ex_register('µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳') @@ -446,7 +446,7 @@ describe('buffer cursor position is correct in terminal without number column', end) describe('in a line with double-cell multibyte characters and no trailing spaces,', function() - skip(iswin(), "Encoding problem?") + skip(is_os('win'), "Encoding problem?") before_each(function() setup_ex_register('哦哦哦哦哦哦哦哦') @@ -743,7 +743,7 @@ describe('buffer cursor position is correct in terminal with number column', fun end) describe('in a line with single-cell composed multibyte characters and no trailing spaces,', function() - if skip(iswin(), "Encoding problem?") then return end + if skip(is_os('win'), "Encoding problem?") then return end before_each(function() setup_ex_register('µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳') @@ -826,7 +826,7 @@ describe('buffer cursor position is correct in terminal with number column', fun end) describe('in a line with double-cell multibyte characters and no trailing spaces,', function() - skip(iswin(), "Encoding problem?") + skip(is_os('win'), "Encoding problem?") before_each(function() setup_ex_register('哦哦哦哦哦哦哦哦') diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index 95ee561d2b..80287bb3d0 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -36,7 +36,7 @@ describe(':edit term://*', function() end) it("runs TermOpen early enough to set buffer-local 'scrollback'", function() - if helpers.skip(helpers.iswin()) then return end + if helpers.skip(helpers.is_os('win')) then return end local columns, lines = 20, 4 local scr = get_screen(columns, lines) local rep = 97 diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 48254faa31..6b7e93a864 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -8,10 +8,10 @@ local feed_command, eval = helpers.feed_command, helpers.eval local funcs = helpers.funcs local retry = helpers.retry local ok = helpers.ok -local iswin = helpers.iswin local command = helpers.command -local isCI = helpers.isCI local skip = helpers.skip +local is_os = helpers.is_os +local is_ci = helpers.is_ci describe(':terminal', function() local screen @@ -47,8 +47,8 @@ describe(':terminal', function() end) it("reads output buffer on terminal reporting #4151", function() - skip(isCI('cirrus') or iswin()) - if iswin() then + skip(is_ci('cirrus') or is_os('win')) + if is_os('win') then feed_command([[terminal powershell -NoProfile -NoLogo -Command Write-Host -NoNewline "\"$([char]27)[6n\""; Start-Sleep -Milliseconds 500 ]]) else feed_command([[terminal printf '\e[6n'; sleep 0.5 ]]) @@ -57,7 +57,7 @@ describe(':terminal', function() end) it("in normal-mode :split does not move cursor", function() - if iswin() then + if is_os('win') then feed_command([[terminal for /L \\%I in (1,0,2) do ( echo foo & ping -w 100 -n 1 127.0.0.1 > nul )]]) else feed_command([[terminal while true; do echo foo; sleep .1; done]]) @@ -144,7 +144,7 @@ describe(':terminal (with fake shell)', function() end it('with no argument, acts like termopen()', function() - skip(iswin()) + skip(is_os('win')) terminal_with_fake_shell() retry(nil, 4 * screen.timeout, function() screen:expect([[ @@ -168,7 +168,7 @@ describe(':terminal (with fake shell)', function() end) it("with no argument, but 'shell' has arguments, acts like termopen()", function() - skip(iswin()) + skip(is_os('win')) nvim('set_option', 'shell', testprg('shell-test')..' -t jeff') terminal_with_fake_shell() screen:expect([[ @@ -180,7 +180,7 @@ describe(':terminal (with fake shell)', function() end) it('executes a given command through the shell', function() - skip(iswin()) + skip(is_os('win')) command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell('echo hi') screen:expect([[ @@ -192,7 +192,7 @@ describe(':terminal (with fake shell)', function() end) it("executes a given command through the shell, when 'shell' has arguments", function() - skip(iswin()) + skip(is_os('win')) nvim('set_option', 'shell', testprg('shell-test')..' -t jeff') command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell('echo hi') @@ -205,7 +205,7 @@ describe(':terminal (with fake shell)', function() end) it('allows quotes and slashes', function() - skip(iswin()) + skip(is_os('win')) command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell([[echo 'hello' \ "world"]]) screen:expect([[ @@ -242,7 +242,7 @@ describe(':terminal (with fake shell)', function() end) it('works with :find', function() - skip(iswin()) + skip(is_os('win')) terminal_with_fake_shell() screen:expect([[ ^ready $ | @@ -253,7 +253,7 @@ describe(':terminal (with fake shell)', function() eq('term://', string.match(eval('bufname("%")'), "^term://")) feed([[]]) feed_command([[find */shadacat.py]]) - if iswin() then + if is_os('win') then eq('scripts\\shadacat.py', eval('bufname("%")')) else eq('scripts/shadacat.py', eval('bufname("%")')) @@ -261,7 +261,7 @@ describe(':terminal (with fake shell)', function() end) it('works with gf', function() - skip(iswin()) + skip(is_os('win')) command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell([[echo "scripts/shadacat.py"]]) retry(nil, 4 * screen.timeout, function() diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index 3e121405d8..2ac45771d4 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -7,7 +7,7 @@ local nvim_prog_abs = helpers.nvim_prog_abs local eq, eval = helpers.eq, helpers.eval local funcs = helpers.funcs local nvim_set = helpers.nvim_set -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip describe(':terminal highlight', function() @@ -60,7 +60,7 @@ describe(':terminal highlight', function() end) local function pass_attrs() - skip(iswin()) + skip(is_os('win')) screen:expect(sub([[ tty ready | {NUM:text}text{10: } | @@ -75,7 +75,7 @@ describe(':terminal highlight', function() it('will pass the corresponding attributes', pass_attrs) it('will pass the corresponding attributes on scrollback', function() - skip(iswin()) + skip(is_os('win')) pass_attrs() local lines = {} for i = 1, 8 do @@ -199,7 +199,7 @@ describe(':terminal highlight forwarding', function() end) it('will handle cterm and rgb attributes', function() - skip(iswin()) + skip(is_os('win')) thelpers.set_fg(3) thelpers.feed_data('text') thelpers.feed_termcode('[38:2:255:128:0m') @@ -251,7 +251,7 @@ describe(':terminal highlight with custom palette', function() end) it('will use the custom color', function() - skip(iswin()) + skip(is_os('win')) thelpers.set_fg(3) thelpers.feed_data('text') thelpers.clear_attrs() diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index a062a77a14..899df0ac54 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -3,7 +3,7 @@ local thelpers = require('test.functional.terminal.helpers') local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval local feed, nvim, command = helpers.feed, helpers.nvim, helpers.command local feed_data = thelpers.feed_data -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip describe(':terminal mouse', function() @@ -68,7 +68,7 @@ describe(':terminal mouse', function() end) it('does not leave terminal mode on left-release', function() - skip(iswin()) + skip(is_os('win')) feed('') eq('t', eval('mode(1)')) end) @@ -89,7 +89,7 @@ describe(':terminal mouse', function() end) it('will forward mouse press, drag and release to the program', function() - skip(iswin()) + skip(is_os('win')) feed('<1,2>') screen:expect([[ line27 | @@ -133,7 +133,7 @@ describe(':terminal mouse', function() end) it('will forward mouse scroll to the program', function() - skip(iswin()) + skip(is_os('win')) feed('<0,0>') screen:expect([[ line27 | @@ -147,7 +147,7 @@ describe(':terminal mouse', function() end) it('dragging and scrolling do not interfere with each other', function() - skip(iswin()) + skip(is_os('win')) feed('<1,2>') screen:expect([[ line27 | @@ -201,7 +201,7 @@ describe(':terminal mouse', function() end) it('will forward mouse clicks to the program with the correct even if set nu', function() - skip(iswin()) + skip(is_os('win')) command('set number') -- When the display area such as a number is clicked, it returns to the -- normal mode. @@ -232,7 +232,7 @@ describe(':terminal mouse', function() end) describe('with a split window and other buffer', function() - skip(iswin()) + skip(is_os('win')) before_each(function() feed(':vsp') screen:expect([[ diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 873445f281..a4899c8219 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -3,7 +3,6 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local feed, testprg, feed_command = helpers.feed, helpers.testprg, helpers.feed_command -local iswin = helpers.iswin local eval = helpers.eval local command = helpers.command local matches = helpers.matches @@ -16,6 +15,7 @@ local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua local assert_alive = helpers.assert_alive local skip = helpers.skip +local is_os = helpers.is_os describe(':terminal scrollback', function() local screen @@ -140,7 +140,7 @@ describe(':terminal scrollback', function() describe('and height decreased by 1', function() - if skip(iswin()) then return end + if skip(is_os('win')) then return end local function will_hide_top_line() feed([[]]) screen:try_resize(screen._width - 2, screen._height - 1) @@ -186,7 +186,7 @@ describe(':terminal scrollback', function() -- XXX: Can't test this reliably on Windows unless the cursor is _moved_ -- by the resize. http://docs.libuv.org/en/v1.x/signal.html -- See also: https://github.com/rprichard/winpty/issues/110 - if skip(iswin()) then return end + if skip(is_os('win')) then return end describe('and the height is decreased by 2', function() before_each(function() @@ -265,7 +265,7 @@ describe(':terminal scrollback', function() -- XXX: Can't test this reliably on Windows unless the cursor is _moved_ -- by the resize. http://docs.libuv.org/en/v1.x/signal.html -- See also: https://github.com/rprichard/winpty/issues/110 - if skip(iswin()) then return end + if skip(is_os('win')) then return end local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) screen:expect([[ @@ -347,7 +347,7 @@ end) describe(':terminal prints more lines than the screen height and exits', function() it('will push extra lines to scrollback', function() - skip(iswin()) + skip(is_os('win')) clear() local screen = Screen.new(30, 7) screen:attach({rgb=false}) @@ -397,21 +397,21 @@ describe("'scrollback' option", function() it('set to 0 behaves as 1', function() local screen - if iswin() then + if is_os('win') then screen = thelpers.screen_setup(nil, "['cmd.exe']", 30) else screen = thelpers.screen_setup(nil, "['sh']", 30) end curbufmeths.set_option('scrollback', 0) - feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), iswin() and '\r' or '\n')) + feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n')) screen:expect{any='30: line '} retry(nil, nil, function() expect_lines(7) end) end) it('deletes lines (only) if necessary', function() local screen - if iswin() then + if is_os('win') then command([[let $PROMPT='$$']]) screen = thelpers.screen_setup(nil, "['cmd.exe']", 30) else @@ -424,7 +424,7 @@ describe("'scrollback' option", function() -- Wait for prompt. screen:expect{any='%$'} - feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), iswin() and '\r' or '\n')) + feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n')) screen:expect{any='30: line '} retry(nil, nil, function() expect_lines(33, 2) end) @@ -437,8 +437,8 @@ describe("'scrollback' option", function() -- 'scrollback' option is synchronized with the internal sb_buffer. command('sleep 100m') - feed_data(('%s REP 41 line%s'):format(testprg('shell-test'), iswin() and '\r' or '\n')) - if iswin() then + feed_data(('%s REP 41 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n')) + if is_os('win') then screen:expect{grid=[[ 37: line | 38: line | @@ -462,8 +462,8 @@ describe("'scrollback' option", function() expect_lines(58) -- Verify off-screen state - matches((iswin() and '^36: line[ ]*$' or '^35: line[ ]*$'), eval("getline(line('w0') - 1)")) - matches((iswin() and '^27: line[ ]*$' or '^26: line[ ]*$'), eval("getline(line('w0') - 10)")) + matches((is_os('win') and '^36: line[ ]*$' or '^35: line[ ]*$'), eval("getline(line('w0') - 1)")) + matches((is_os('win') and '^27: line[ ]*$' or '^26: line[ ]*$'), eval("getline(line('w0') - 10)")) end) it('deletes extra lines immediately', function() @@ -607,7 +607,7 @@ describe("pending scrollback line handling", function() end) it("does not crash after nvim_buf_call #14891", function() - skip(iswin()) + skip(is_os('win')) exec_lua [[ local a = vim.api local bufnr = a.nvim_create_buf(false, true) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 20c677c46c..b3d2625d78 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -5,7 +5,6 @@ -- http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode local helpers = require('test.functional.helpers')(after_each) -local uname = helpers.uname local thelpers = require('test.functional.terminal.helpers') local Screen = require('test.functional.ui.screen') local assert_alive = helpers.assert_alive @@ -22,9 +21,10 @@ local ok = helpers.ok local read_file = helpers.read_file local funcs = helpers.funcs local meths = helpers.meths -local isCI = helpers.isCI +local is_ci = helpers.is_ci +local is_os = helpers.is_os -if helpers.skip(helpers.iswin()) then return end +if helpers.skip(helpers.is_os('win')) then return end describe('TUI', function() local screen @@ -822,7 +822,7 @@ describe('TUI', function() end) it('paste: terminal mode', function() - if isCI('github') then + if is_ci('github') then pending("tty-test complains about not owning the terminal -- actions/runner#241") end child_exec_lua('vim.o.statusline="^^^^^^^"') @@ -1089,7 +1089,7 @@ describe('TUI', function() -- "bracketed paste" feed_data('\027[200~'..expected..'\027[201~') -- FIXME: Data race between the two feeds - if uname() == 'freebsd' then screen:sleep(1) end + if is_os('freebsd') then screen:sleep(1) end feed_data(' end') expected = expected..' end' screen:expect([[ @@ -1329,7 +1329,7 @@ describe('TUI', function() end) it('forwards :term palette colors with termguicolors', function() - if isCI('github') then + if is_ci('github') then pending("tty-test complains about not owning the terminal -- actions/runner#241") end screen:set_rgb_cterm(true) @@ -1668,7 +1668,6 @@ end) -- does not initialize the TUI. describe("TUI 't_Co' (terminal colors)", function() local screen - local is_freebsd = (uname() == 'freebsd') local function assert_term_colors(term, colorterm, maxcolors) helpers.clear({env={TERM=term}, args={}}) @@ -1771,7 +1770,7 @@ describe("TUI 't_Co' (terminal colors)", function() -- which is raised to 16 by COLORTERM. it("TERM=screen no COLORTERM uses 8/256 colors", function() - if is_freebsd then + if is_os('freebsd') then assert_term_colors("screen", nil, 256) else assert_term_colors("screen", nil, 8) @@ -1779,7 +1778,7 @@ describe("TUI 't_Co' (terminal colors)", function() end) it("TERM=screen COLORTERM=screen uses 16/256 colors", function() - if is_freebsd then + if is_os('freebsd') then assert_term_colors("screen", "screen", 256) else assert_term_colors("screen", "screen", 16) @@ -1942,8 +1941,6 @@ end) -- does not initialize the TUI. describe("TUI 'term' option", function() local screen - local is_bsd = not not string.find(uname(), 'bsd') - local is_macos = not not string.find(uname(), 'darwin') local function assert_term(term_envvar, term_expected) clear() @@ -1969,11 +1966,11 @@ describe("TUI 'term' option", function() end) it('gets system-provided term if $TERM is valid', function() - if uname() == "openbsd" then + if is_os('openbsd') then assert_term("xterm", "xterm") - elseif is_bsd then -- BSD lacks terminfo, builtin is always used. + elseif is_os('bsd') then -- BSD lacks terminfo, builtin is always used. assert_term("xterm", "builtin_xterm") - elseif is_macos then + elseif is_os('mac') then local status, _ = pcall(assert_term, "xterm", "xterm") if not status then pending("macOS: unibilium could not find terminfo") diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index 81cd1017db..80e9d78400 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -3,12 +3,12 @@ local thelpers = require('test.functional.terminal.helpers') local feed_data = thelpers.feed_data local feed, clear = helpers.feed, helpers.clear local poke_eventloop = helpers.poke_eventloop -local iswin = helpers.iswin local command = helpers.command local retry = helpers.retry local eq = helpers.eq local eval = helpers.eval local skip = helpers.skip +local is_os = helpers.is_os describe(':terminal window', function() local screen @@ -19,7 +19,7 @@ describe(':terminal window', function() end) it('sets topline correctly #8556', function() - skip(iswin()) + skip(is_os('win')) -- Test has hardcoded assumptions of dimensions. eq(7, eval('&lines')) feed_data('\n\n\n') -- Add blank lines. @@ -55,7 +55,7 @@ describe(':terminal window', function() {3:-- TERMINAL --} | ]]) - skip(iswin(), 'win: :terminal resize is unreliable #7007') + skip(is_os('win'), 'win: :terminal resize is unreliable #7007') -- numberwidth=9 feed([[]]) @@ -171,7 +171,7 @@ describe(':terminal with multigrid', function() ]]) screen:try_resize_grid(2, 20, 10) - if iswin() then + if is_os('win') then screen:expect{any="rows: 10, cols: 20"} else screen:expect([[ @@ -200,7 +200,7 @@ describe(':terminal with multigrid', function() end screen:try_resize_grid(2, 70, 3) - if iswin() then + if is_os('win') then screen:expect{any="rows: 3, cols: 70"} else screen:expect([[ @@ -222,7 +222,7 @@ describe(':terminal with multigrid', function() end screen:try_resize_grid(2, 0, 0) - if iswin() then + if is_os('win') then screen:expect{any="rows: 6, cols: 50"} else screen:expect([[ diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index b62d173cea..1d77e1e92e 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -8,9 +8,9 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local meths = helpers.meths -local iswin = helpers.iswin local sleep = helpers.sleep local retry = helpers.retry +local is_os = helpers.is_os describe(':terminal', function() local screen @@ -96,7 +96,7 @@ describe(':terminal', function() local w1, h1 = screen._width - 3, screen._height - 2 local w2, h2 = w1 - 6, h1 - 3 - if iswin() then + if is_os('win') then -- win: SIGWINCH is unreliable, use a weaker test. #7506 retry(3, 30000, function() screen:try_resize(w1, h1) diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua index c6ddf812be..f006ad4539 100644 --- a/test/functional/treesitter/parser_spec.lua +++ b/test/functional/treesitter/parser_spec.lua @@ -5,7 +5,7 @@ local eq = helpers.eq local insert = helpers.insert local exec_lua = helpers.exec_lua local feed = helpers.feed -local iswin = helpers.iswin +local is_os = helpers.is_os local skip = helpers.skip before_each(clear) @@ -684,7 +684,7 @@ int x = INT_MAX; end) it("should not inject bad languages", function() - skip(iswin()) + skip(is_os('win')) exec_lua([=[ vim.treesitter.add_directive("inject-bad!", function(match, _, _, pred, metadata) metadata.language = "{" diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 8003947078..c73c2d9f8a 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -4,10 +4,10 @@ local clear, feed = helpers.clear, helpers.feed local source = helpers.source local command = helpers.command local assert_alive = helpers.assert_alive -local uname = helpers.uname local exec = helpers.exec local eval = helpers.eval local eq = helpers.eq +local is_os = helpers.is_os local function new_screen(opt) local screen = Screen.new(25, 5) @@ -717,7 +717,7 @@ describe('cmdline redraw', function() end) it('with ', function() - if string.find(uname(), 'bsd') then + if is_os('bsd') then pending('FIXME #10804') end command('cmap a call sin(0)') -- no-op diff --git a/test/functional/ui/embed_spec.lua b/test/functional/ui/embed_spec.lua index e7addd1b85..cd2b48213d 100644 --- a/test/functional/ui/embed_spec.lua +++ b/test/functional/ui/embed_spec.lua @@ -51,7 +51,7 @@ local function test_embed(ext_linegrid) end) it("doesn't erase output when setting color scheme", function() - if 'openbsd' == helpers.uname() then + if helpers.is_os('openbsd') then pending('FIXME #10804') end startup('--cmd', 'echoerr "foo"', '--cmd', 'color default', '--cmd', 'echoerr "bar"') diff --git a/test/functional/ui/hlstate_spec.lua b/test/functional/ui/hlstate_spec.lua index a8b4c05747..55f873e827 100644 --- a/test/functional/ui/hlstate_spec.lua +++ b/test/functional/ui/hlstate_spec.lua @@ -4,10 +4,10 @@ local Screen = require('test.functional.ui.screen') local clear, insert = helpers.clear, helpers.insert local command = helpers.command local meths = helpers.meths -local iswin = helpers.iswin local testprg = helpers.testprg local thelpers = require('test.functional.terminal.helpers') local skip = helpers.skip +local is_os = helpers.is_os describe('ext_hlstate detailed highlights', function() local screen @@ -183,7 +183,7 @@ describe('ext_hlstate detailed highlights', function() end) it("work with :terminal", function() - skip(iswin()) + skip(is_os('win')) screen:set_default_attr_ids({ [1] = {{}, {{hi_name = "TermCursorNC", ui_name = "TermCursorNC", kind = "ui"}}}, @@ -212,7 +212,7 @@ describe('ext_hlstate detailed highlights', function() thelpers.set_bold() thelpers.feed_data('z\n') -- TODO(bfredl): check if this distinction makes sense - if iswin() then + if is_os('win') then screen:expect([[ ^tty ready | x {5:y z} | @@ -238,7 +238,7 @@ describe('ext_hlstate detailed highlights', function() thelpers.feed_termcode("[A") thelpers.feed_termcode("[2C") - if iswin() then + if is_os('win') then screen:expect([[ ^tty ready | x {6:y}{5: z} | diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 60b538eee5..f7ffe16bd6 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -9,12 +9,13 @@ local meths = helpers.meths local async_meths = helpers.async_meths local test_build_dir = helpers.test_build_dir local nvim_prog = helpers.nvim_prog -local iswin = helpers.iswin local exec = helpers.exec local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua local poke_eventloop = helpers.poke_eventloop local assert_alive = helpers.assert_alive +local is_os = helpers.is_os +local is_ci = helpers.is_ci describe('ui/ext_messages', function() local screen @@ -1496,7 +1497,7 @@ describe('ui/msg_puts_printf', function() screen = Screen.new(25, 5) screen:attach() - if iswin() then + if is_os('win') then if os.execute('chcp 932 > NUL 2>&1') ~= 0 then pending('missing japanese language features', function() end) return @@ -1507,7 +1508,7 @@ describe('ui/msg_puts_printf', function() if (exc_exec('lang ja_JP.UTF-8') ~= 0) then pending('Locale ja_JP.UTF-8 not supported', function() end) return - elseif helpers.isCI() then + elseif is_ci() then -- Fails non--Windows CI. Message catalog directory issue? pending('fails on unix CI', function() end) return diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua index 0825772d57..223844405e 100644 --- a/test/functional/ui/output_spec.lua +++ b/test/functional/ui/output_spec.lua @@ -6,7 +6,6 @@ local mkdir, write_file, rmdir = helpers.mkdir, helpers.write_file, helpers.rmdi local eq = helpers.eq local feed = helpers.feed local feed_command = helpers.feed_command -local iswin = helpers.iswin local clear = helpers.clear local command = helpers.command local testprg = helpers.testprg @@ -14,6 +13,7 @@ local nvim_dir = helpers.nvim_dir local has_powershell = helpers.has_powershell local set_shell_powershell = helpers.set_shell_powershell local skip = helpers.skip +local is_os = helpers.is_os describe("shell command :!", function() local screen @@ -37,7 +37,7 @@ describe("shell command :!", function() end) it("displays output without LF/EOF. #4646 #4569 #3772", function() - skip(iswin()) + skip(is_os('win')) -- NOTE: We use a child nvim (within a :term buffer) -- to avoid triggering a UI flush. child_session.feed_data(":!printf foo; sleep 200\n") @@ -53,7 +53,7 @@ describe("shell command :!", function() end) it("throttles shell-command output greater than ~10KB", function() - skip('openbsd' == helpers.uname(), 'FIXME #10804') + skip(is_os('openbsd'), 'FIXME #10804') child_session.feed_data((":!%s REP 30001 foo\n"):format(testprg('shell-test'))) -- If we observe any line starting with a dot, then throttling occurred. @@ -95,7 +95,7 @@ describe("shell command :!", function() end) it('handles control codes', function() - skip(iswin(), 'missing printf') + skip(is_os('win'), 'missing printf') local screen = Screen.new(50, 4) screen:set_default_attr_ids { [1] = {bold = true, reverse = true}; @@ -170,10 +170,10 @@ describe("shell command :!", function() end) it("doesn't truncate Last line of shell output #3269", function() - command(helpers.iswin() + command(is_os('win') and [[nnoremap \l :!dir /b bang_filter_spec]] or [[nnoremap \l :!ls bang_filter_spec]]) - local result = (helpers.iswin() + local result = (is_os('win') and [[:!dir /b bang_filter_spec]] or [[:!ls bang_filter_spec ]]) feed([[\l]]) @@ -212,7 +212,7 @@ describe("shell command :!", function() it('handles multibyte sequences split over buffer boundaries', function() command('cd '..nvim_dir) - local cmd = iswin() and '!shell-test UTF-8 ' or '!./shell-test UTF-8' + local cmd = is_os('win') and '!shell-test UTF-8 ' or '!./shell-test UTF-8' feed_command(cmd) -- Note: only the first example of split composed char works screen:expect([[ @@ -262,7 +262,7 @@ describe("shell command :!", function() | Press ENTER or type command to continue^ | ]]) - if iswin() then + if is_os('win') then feed_command([[!& 'cmd.exe' /c 'echo $a']]) screen:expect([[ :!& 'cmd.exe' /c 'echo $a' | diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 5aacdc95e2..3bd2289a73 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -5,8 +5,8 @@ local feed, command = helpers.feed, helpers.command local insert = helpers.insert local eq = helpers.eq local eval = helpers.eval -local iswin = helpers.iswin local funcs, meths, exec_lua = helpers.funcs, helpers.meths, helpers.exec_lua +local is_os = helpers.is_os describe('screen', function() local screen @@ -128,18 +128,18 @@ local function screen_tests(linegrid) end) it('has correct default title with named file', function() - local expected = (iswin() and 'myfile (C:\\mydir) - NVIM' or 'myfile (/mydir) - NVIM') + local expected = (is_os('win') and 'myfile (C:\\mydir) - NVIM' or 'myfile (/mydir) - NVIM') command('set title') - command(iswin() and 'file C:\\mydir\\myfile' or 'file /mydir/myfile') + command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile') screen:expect(function() eq(expected, screen.title) end) end) describe('is not changed by', function() - local file1 = iswin() and 'C:\\mydir\\myfile1' or '/mydir/myfile1' - local file2 = iswin() and 'C:\\mydir\\myfile2' or '/mydir/myfile2' - local expected = (iswin() and 'myfile1 (C:\\mydir) - NVIM' or 'myfile1 (/mydir) - NVIM') + local file1 = is_os('win') and 'C:\\mydir\\myfile1' or '/mydir/myfile1' + local file2 = is_os('win') and 'C:\\mydir\\myfile2' or '/mydir/myfile2' + local expected = (is_os('win') and 'myfile1 (C:\\mydir) - NVIM' or 'myfile1 (/mydir) - NVIM') local buf2 before_each(function() diff --git a/test/functional/ui/spell_spec.lua b/test/functional/ui/spell_spec.lua index 1aa73e7b13..425790dbf9 100644 --- a/test/functional/ui/spell_spec.lua +++ b/test/functional/ui/spell_spec.lua @@ -5,8 +5,8 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local feed = helpers.feed local insert = helpers.insert -local uname = helpers.uname local command = helpers.command +local is_os = helpers.is_os describe("'spell'", function() local screen @@ -27,7 +27,7 @@ describe("'spell'", function() end) it('joins long lines #7937', function() - if uname() == 'openbsd' then pending('FIXME #12104', function() end) return end + if is_os('openbsd') then pending('FIXME #12104', function() end) return end command('set spell') insert([[ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua index f1e818119e..50466c9473 100644 --- a/test/functional/ui/wildmode_spec.lua +++ b/test/functional/ui/wildmode_spec.lua @@ -1,13 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, feed, command = helpers.clear, helpers.feed, helpers.command -local iswin = helpers.iswin local funcs = helpers.funcs local meths = helpers.meths local eq = helpers.eq local eval = helpers.eval local retry = helpers.retry local testprg = helpers.testprg +local is_os = helpers.is_os describe("'wildmenu'", function() local screen @@ -159,7 +159,7 @@ describe("'wildmenu'", function() -- must wait the full timeout. So make it reasonable. screen.timeout = 1000 - if not iswin() then + if not is_os('win') then command('set shell=sh') -- Need a predictable "$" prompt. command('let $PS1 = "$"') end @@ -169,7 +169,7 @@ describe("'wildmenu'", function() -- Check for a shell prompt to verify that the terminal loaded. retry(nil, nil, function() - if iswin() then + if is_os('win') then eq('Microsoft', eval("matchstr(join(getline(1, '$')), 'Microsoft')")) else eq('$', eval([[matchstr(getline(1), '\$')]])) diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index d50c252569..a8a901042b 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -71,13 +71,13 @@ describe("backtick expansion", function() end) it("with default 'shell'", function() - if helpers.iswin() then + if helpers.is_os('win') then command(":silent args `dir /b *2`") else command(":silent args `echo ***2`") end eq({ "file2", }, eval("argv()")) - if helpers.iswin() then + if helpers.is_os('win') then command(":silent args `dir /s/b *4`") eq({ "subdir\\file4", }, eval("map(argv(), 'fnamemodify(v:val, \":.\")')")) else diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua index b49eb09512..43e4a29e1a 100644 --- a/test/functional/vimscript/executable_spec.lua +++ b/test/functional/vimscript/executable_spec.lua @@ -1,15 +1,16 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, call, iswin, write_file, command = - helpers.eq, helpers.clear, helpers.call, helpers.iswin, helpers.write_file, +local eq, clear, call, write_file, command = + helpers.eq, helpers.clear, helpers.call, helpers.write_file, helpers.command local exc_exec = helpers.exc_exec local eval = helpers.eval +local is_os = helpers.is_os describe('executable()', function() before_each(clear) it('returns 1 for commands in $PATH', function() - local exe = iswin() and 'ping' or 'ls' + local exe = is_os('win') and 'ping' or 'ls' eq(1, call('executable', exe)) command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') eq(1, call('executable', 'null')) @@ -17,7 +18,7 @@ describe('executable()', function() eq(1, call('executable', 'false')) end) - if iswin() then + if is_os('win') then it('exepath respects shellslash', function() command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') eq([[test\functional\fixtures\bin\null.CMD]], call('fnamemodify', call('exepath', 'null'), ':.')) @@ -56,8 +57,8 @@ describe('executable()', function() -- Some executable in build/bin/, *not* in $PATH nor CWD. local sibling_exe = 'printargs-test' -- Windows: siblings are in Nvim's "pseudo-$PATH". - local expected = iswin() and 1 or 0 - if iswin() then + local expected = is_os('win') and 1 or 0 + if is_os('win') then eq('arg1=lemon;arg2=sky;arg3=tree;', call('system', sibling_exe..' lemon sky tree')) end @@ -69,7 +70,7 @@ describe('executable()', function() clear() write_file('Xtest_not_executable', 'non-executable file') write_file('Xtest_executable', 'executable file (exec-bit set)') - if not iswin() then -- N/A for Windows. + if not is_os('win') then -- N/A for Windows. call('system', {'chmod', '-x', 'Xtest_not_executable'}) call('system', {'chmod', '+x', 'Xtest_executable'}) end @@ -90,14 +91,17 @@ describe('executable()', function() end) it('set, qualified as a path', function() - local expected = iswin() and 0 or 1 + local expected = is_os('win') and 0 or 1 eq(expected, call('executable', './Xtest_executable')) end) end) end) describe('executable() (Windows)', function() - if not iswin() then return end -- N/A for Unix. + if not is_os('win') then + pending('N/A for non-windows') + return + end local exts = {'bat', 'exe', 'com', 'cmd'} setup(function() diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index a733b098f5..5fe3d787cb 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -8,7 +8,7 @@ local funcs = helpers.funcs local Screen = require('test.functional.ui.screen') local command = helpers.command local feed = helpers.feed -local iswin = helpers.iswin +local is_os = helpers.is_os describe('execute()', function() before_each(clear) @@ -265,7 +265,7 @@ describe('execute()', function() -- This deviates from vim behavior, but is consistent -- with how nvim currently displays the output. it('captures shell-command output', function() - local win_lf = iswin() and '\13' or '' + local win_lf = is_os('win') and '\13' or '' eq('\n:!echo foo\r\n\nfoo'..win_lf..'\n', funcs.execute('!echo foo')) end) diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua index db96b79743..056f67e0ad 100644 --- a/test/functional/vimscript/exepath_spec.lua +++ b/test/functional/vimscript/exepath_spec.lua @@ -1,19 +1,20 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, call, iswin = - helpers.eq, helpers.clear, helpers.call, helpers.iswin +local eq, clear, call = + helpers.eq, helpers.clear, helpers.call local command = helpers.command local exc_exec = helpers.exc_exec local matches = helpers.matches +local is_os = helpers.is_os describe('exepath()', function() before_each(clear) it('returns 1 for commands in $PATH', function() - local exe = iswin() and 'ping' or 'ls' - local ext_pat = iswin() and '%.EXE$' or '$' + local exe = is_os('win') and 'ping' or 'ls' + local ext_pat = is_os('win') and '%.EXE$' or '$' matches(exe .. ext_pat, call('exepath', exe)) command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') - ext_pat = iswin() and '%.CMD$' or '$' + ext_pat = is_os('win') and '%.CMD$' or '$' matches('null' .. ext_pat, call('exepath', 'null')) matches('true' .. ext_pat, call('exepath', 'true')) matches('false' .. ext_pat, call('exepath', 'false')) @@ -30,7 +31,7 @@ describe('exepath()', function() end end) - if iswin() then + if is_os('win') then it('append extension if omitted', function() local filename = 'cmd' local pathext = '.exe' diff --git a/test/functional/vimscript/fnamemodify_spec.lua b/test/functional/vimscript/fnamemodify_spec.lua index d54a6db417..c3ecdd853c 100644 --- a/test/functional/vimscript/fnamemodify_spec.lua +++ b/test/functional/vimscript/fnamemodify_spec.lua @@ -1,12 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local iswin = helpers.iswin local fnamemodify = helpers.funcs.fnamemodify local getcwd = helpers.funcs.getcwd local command = helpers.command local write_file = helpers.write_file local alter_slashes = helpers.alter_slashes +local is_os = helpers.is_os local function eq_slashconvert(expected, got) eq(alter_slashes(expected), alter_slashes(got)) @@ -27,7 +27,7 @@ describe('fnamemodify()', function() local root = helpers.pathroot() eq(root, fnamemodify([[/]], ':p:h')) eq(root, fnamemodify([[/]], ':p')) - if iswin() then + if is_os('win') then eq(root, fnamemodify([[\]], ':p:h')) eq(root, fnamemodify([[\]], ':p')) command('set shellslash') @@ -114,7 +114,7 @@ describe('fnamemodify()', function() it('handles shell escape', function() local expected - if iswin() then + if is_os('win') then -- we expand with double-quotes on Windows expected = [["hello there! quote ' newline]] .. '\n' .. [["]] else diff --git a/test/functional/vimscript/functions_spec.lua b/test/functional/vimscript/functions_spec.lua index 20c1400030..09b3334989 100644 --- a/test/functional/vimscript/functions_spec.lua +++ b/test/functional/vimscript/functions_spec.lua @@ -9,12 +9,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eval = helpers.eval -local iswin = helpers.iswin local matches = helpers.matches +local is_os = helpers.is_os before_each(clear) it('windowsversion()', function() clear() - matches(iswin() and '^%d+%.%d+$' or '^$', eval('windowsversion()')) + matches(is_os('win') and '^%d+%.%d+$' or '^$', eval('windowsversion()')) end) diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua index 4d9b226434..2e26d603b3 100644 --- a/test/functional/vimscript/has_spec.lua +++ b/test/functional/vimscript/has_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local clear = helpers.clear local funcs = helpers.funcs -local iswin = helpers.iswin +local is_os = helpers.is_os describe('has()', function() before_each(clear) @@ -51,7 +51,7 @@ describe('has()', function() end) it('"unnamedplus"', function() - if (not iswin()) and funcs.has("clipboard") == 1 then + if (not is_os('win')) and funcs.has("clipboard") == 1 then eq(1, funcs.has("unnamedplus")) else eq(0, funcs.has("unnamedplus")) diff --git a/test/functional/vimscript/hostname_spec.lua b/test/functional/vimscript/hostname_spec.lua index 6112cf64e3..7d4baa7213 100644 --- a/test/functional/vimscript/hostname_spec.lua +++ b/test/functional/vimscript/hostname_spec.lua @@ -3,7 +3,7 @@ local eq = helpers.eq local ok = helpers.ok local call = helpers.call local clear = helpers.clear -local iswin = helpers.iswin +local is_os = helpers.is_os describe('hostname()', function() before_each(clear) @@ -13,8 +13,8 @@ describe('hostname()', function() ok(string.len(actual) > 0) if call('executable', 'hostname') == 1 then local expected = string.gsub(call('system', 'hostname'), '[\n\r]', '') - eq((iswin() and expected:upper() or expected), - (iswin() and actual:upper() or actual)) + eq((is_os('win') and expected:upper() or expected), + (is_os('win') and actual:upper() or actual)) end end) end) diff --git a/test/functional/vimscript/msgpack_functions_spec.lua b/test/functional/vimscript/msgpack_functions_spec.lua index cab67d77e4..de5a721efe 100644 --- a/test/functional/vimscript/msgpack_functions_spec.lua +++ b/test/functional/vimscript/msgpack_functions_spec.lua @@ -5,7 +5,7 @@ local eval, eq = helpers.eval, helpers.eq local command = helpers.command local nvim = helpers.nvim local exc_exec = helpers.exc_exec -local iswin = helpers.iswin +local is_os = helpers.is_os describe('msgpack*() functions', function() before_each(clear) @@ -467,7 +467,7 @@ describe('msgpackparse() function', function() eval(cmd) eval(cmd) -- do it again (try to force segfault) local api_info = eval(cmd) -- do it again - if iswin() then + if is_os('win') then helpers.assert_alive() pending('msgpackparse() has a bug on windows') return diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index 6e95459630..14c87d9d93 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths -local iswin = helpers.iswin local ok = helpers.ok local matches = helpers.matches local pcall_err = helpers.pcall_err local mkdir = helpers.mkdir +local is_os = helpers.is_os local function clear_serverlist() for _, server in pairs(funcs.serverlist()) do @@ -19,7 +19,7 @@ describe('server', function() mkdir(dir) clear({ env={ XDG_RUNTIME_DIR=dir } }) matches(dir, funcs.stdpath('run')) - if not iswin() then + if not is_os('win') then matches(dir, funcs.serverstart()) end end) @@ -65,7 +65,7 @@ describe('server', function() eq('', meths.get_vvar('servername')) -- v:servername and $NVIM take the next available server. - local servername = (iswin() and [[\\.\pipe\Xtest-functional-server-pipe]] + local servername = (is_os('win') and [[\\.\pipe\Xtest-functional-server-pipe]] or './Xtest-functional-server-socket') funcs.serverstart(servername) eq(servername, meths.get_vvar('servername')) @@ -130,7 +130,7 @@ describe('server', function() local n = eval('len(serverlist())') -- Add some servers. - local servs = (iswin() + local servs = (is_os('win') and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] } or { [[./Xtest-pipe0934]], [[./Xtest-pipe4324]] }) for _, s in ipairs(servs) do @@ -164,7 +164,7 @@ describe('startup --listen', function() end) it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function() - local addr = (iswin() and [[\\.\pipe\Xtest-listen-pipe]] + local addr = (is_os('win') and [[\\.\pipe\Xtest-listen-pipe]] or './Xtest-listen-pipe') clear({ env={ NVIM_LISTEN_ADDRESS='./Xtest-env-pipe' }, args={ '--listen', addr } }) diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index ed822add72..dbf734b51a 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -9,9 +9,9 @@ local command = helpers.command local insert = helpers.insert local expect = helpers.expect local exc_exec = helpers.exc_exec -local iswin = helpers.iswin local os_kill = helpers.os_kill local pcall_err = helpers.pcall_err +local is_os = helpers.is_os local Screen = require('test.functional.ui.screen') @@ -85,7 +85,7 @@ describe('system()', function() end) it('does NOT run in shell', function() - if iswin() then + if is_os('win') then eq("%PATH%\n", eval("system(['powershell', '-NoProfile', '-NoLogo', '-ExecutionPolicy', 'RemoteSigned', '-Command', 'Write-Output', '%PATH%'])")) else eq("* $PATH %PATH%\n", eval("system(['echo', '*', '$PATH', '%PATH%'])")) @@ -94,7 +94,7 @@ describe('system()', function() end) it('sets v:shell_error', function() - if iswin() then + if is_os('win') then eval([[system("cmd.exe /c exit")]]) eq(0, eval('v:shell_error')) eval([[system("cmd.exe /c exit 1")]]) @@ -123,7 +123,7 @@ describe('system()', function() screen:attach() end) - if iswin() then + if is_os('win') then local function test_more() eq('root = true', eval([[get(split(system('"more" ".editorconfig"'), "\n"), 0, '')]])) end @@ -184,7 +184,7 @@ describe('system()', function() -- * on Windows, expected to default to Western European enc -- * on Linux, expected to default to UTF8 command([[let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ']]) - eq(iswin() and '??\n' or 'ああ\n', eval([[system('Write-Output "ああ"')]])) + eq(is_os('win') and '??\n' or 'ああ\n', eval([[system('Write-Output "ああ"')]])) end) it('`echo` and waits for its return', function() @@ -213,7 +213,7 @@ describe('system()', function() screen:try_resize(72, 14) feed(':4verbose echo system("echo hi")') - if iswin() then + if is_os('win') then screen:expect{any=[[Executing command: "'fake_shell' 'cmdflag' '"echo hi"'"]]} else screen:expect{any=[[Executing command: "'fake_shell' 'cmdflag' 'echo hi'"]]} @@ -243,7 +243,7 @@ describe('system()', function() end) it('`yes` interrupted with CTRL-C', function() - feed(':call system("' .. (iswin() + feed(':call system("' .. (is_os('win') and 'for /L %I in (1,0,2) do @echo y' or 'yes') .. '")') screen:expect([[ @@ -260,7 +260,7 @@ describe('system()', function() ~ | ~ | ~ | -]] .. (iswin() +]] .. (is_os('win') and [[ :call system("for /L %I in (1,0,2) do @echo y") |]] or [[ @@ -286,7 +286,7 @@ describe('system()', function() it('`yes` interrupted with mapped CTRL-C', function() command('nnoremap i') - feed(':call system("' .. (iswin() + feed(':call system("' .. (is_os('win') and 'for /L %I in (1,0,2) do @echo y' or 'yes') .. '")') screen:expect([[ @@ -303,7 +303,7 @@ describe('system()', function() ~ | ~ | ~ | -]] .. (iswin() +]] .. (is_os('win') and [[ :call system("for /L %I in (1,0,2) do @echo y") |]] or [[ @@ -330,7 +330,7 @@ describe('system()', function() describe('passing no input', function() it('returns the program output', function() - if iswin() then + if is_os('win') then eq("echoed\n", eval('system("echo echoed")')) else eq("echoed", eval('system("echo -n echoed")')) @@ -438,7 +438,7 @@ describe('systemlist()', function() before_each(clear) it('sets v:shell_error', function() - if iswin() then + if is_os('win') then eval([[systemlist("cmd.exe /c exit")]]) eq(0, eval('v:shell_error')) eval([[systemlist("cmd.exe /c exit 1")]]) @@ -617,12 +617,12 @@ describe('systemlist()', function() return end helpers.set_shell_powershell() - eq({iswin() and 'あ\r' or 'あ'}, eval([[systemlist('Write-Output あ')]])) + eq({is_os('win') and 'あ\r' or 'あ'}, eval([[systemlist('Write-Output あ')]])) -- Sanity test w/ default encoding -- * on Windows, expected to default to Western European enc -- * on Linux, expected to default to UTF8 command([[let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ']]) - eq({iswin() and '?\r' or 'あ'}, eval([[systemlist('Write-Output あ')]])) + eq({is_os('win') and '?\r' or 'あ'}, eval([[systemlist('Write-Output あ')]])) end) end) @@ -639,7 +639,7 @@ describe('shell :!', function() 1 4 2]]) - if iswin() then + if is_os('win') then feed(':4verbose %!sort /R') screen:expect{ any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]] -- cgit From 4571ba4d0a5234408e544c3a98f107688a792f0d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 23 Nov 2022 09:54:48 +0800 Subject: vim-patch:partial:9.0.0917: the WinScrolled autocommand event is not enough (#21161) Problem: The WinScrolled autocommand event is not enough. Solution: Add WinResized and provide information about what changed. (closes vim/vim#11576) https://github.com/vim/vim/commit/35fc61cb5b5eba8bbb9d8f0700332fbab38f40ca Omit "func_name" comment in tv_dict_extend(): Vim9 script only. Skip layout locking and E1312. Skip list_alloc_with_items() and list_set_item(). Since this overrides remaining changes in patch 9.0.0913, that patch can now be marked as fully ported: vim-patch:9.0.0913: only change in current window triggers the WinScrolled event N/A patches for version.c: vim-patch:9.0.0919: build failure with tiny features Problem: Build failure with tiny features. Solution: Adjust #ifdef's. https://github.com/vim/vim/commit/9c5b7cb4cf67c64648a324e9dfd1e17d793335a4 Co-authored-by: Bram Moolenaar --- .../autocmd/win_scrolled_resized_spec.lua | 285 +++++++++++++++++++++ test/functional/autocmd/winscrolled_spec.lua | 162 ------------ 2 files changed, 285 insertions(+), 162 deletions(-) create mode 100644 test/functional/autocmd/win_scrolled_resized_spec.lua delete mode 100644 test/functional/autocmd/winscrolled_spec.lua (limited to 'test/functional') diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua new file mode 100644 index 0000000000..bebb21bc31 --- /dev/null +++ b/test/functional/autocmd/win_scrolled_resized_spec.lua @@ -0,0 +1,285 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local clear = helpers.clear +local eq = helpers.eq +local eval = helpers.eval +local exec = helpers.exec +local command = helpers.command +local feed = helpers.feed +local meths = helpers.meths +local assert_alive = helpers.assert_alive + +before_each(clear) + +describe('WinResized', function() + -- oldtest: Test_WinResized() + it('works', function() + exec([[ + set scrolloff=0 + call setline(1, ['111', '222']) + vnew + call setline(1, ['aaa', 'bbb']) + new + call setline(1, ['foo', 'bar']) + + let g:resized = 0 + au WinResized * let g:resized += 1 + au WinResized * let g:v_event = deepcopy(v:event) + ]]) + eq(0, eval('g:resized')) + + -- increase window height, two windows will be reported + feed('+') + eq(1, eval('g:resized')) + eq({windows = {1002, 1001}}, eval('g:v_event')) + + -- increase window width, three windows will be reported + feed('>') + eq(2, eval('g:resized')) + eq({windows = {1002, 1001, 1000}}, eval('g:v_event')) + end) +end) + +describe('WinScrolled', function() + local win_id + + before_each(function() + win_id = meths.get_current_win().id + command(string.format('autocmd WinScrolled %d let g:matched = v:true', win_id)) + exec([[ + let g:scrolled = 0 + au WinScrolled * let g:scrolled += 1 + au WinScrolled * let g:amatch = str2nr(expand('')) + au WinScrolled * let g:afile = str2nr(expand('')) + au WinScrolled * let g:v_event = deepcopy(v:event) + ]]) + end) + + after_each(function() + eq(true, eval('g:matched')) + eq(win_id, eval('g:amatch')) + eq(win_id, eval('g:afile')) + end) + + it('is triggered by scrolling vertically', function() + local lines = {'123', '123'} + meths.buf_set_lines(0, 0, -1, true, lines) + eq(0, eval('g:scrolled')) + + feed('') + eq(1, eval('g:scrolled')) + eq({ + all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('') + eq(2, eval('g:scrolled')) + eq({ + all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = -1, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + end) + + it('is triggered by scrolling horizontally', function() + command('set nowrap') + local width = meths.win_get_width(0) + local line = '123' .. ('*'):rep(width * 2) + local lines = {line, line} + meths.buf_set_lines(0, 0, -1, true, lines) + eq(0, eval('g:scrolled')) + + feed('zl') + eq(1, eval('g:scrolled')) + eq({ + all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('zh') + eq(2, eval('g:scrolled')) + eq({ + all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = -1, topline = 0, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + end) + + it('is triggered by horizontal scrolling from cursor move', function() + command('set nowrap') + local lines = {'', '', 'Foo'} + meths.buf_set_lines(0, 0, -1, true, lines) + meths.win_set_cursor(0, {3, 0}) + eq(0, eval('g:scrolled')) + + feed('zl') + eq(1, eval('g:scrolled')) + eq({ + all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('zl') + eq(2, eval('g:scrolled')) + eq({ + all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('h') + eq(3, eval('g:scrolled')) + eq({ + all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = -1, topline = 0, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('zh') + eq(4, eval('g:scrolled')) + eq({ + all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = -1, topline = 0, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + end) + + -- oldtest: Test_WinScrolled_long_wrapped() + it('is triggered by scrolling on a long wrapped line #19968', function() + local height = meths.win_get_height(0) + local width = meths.win_get_width(0) + meths.buf_set_lines(0, 0, -1, true, {('foo'):rep(height * width)}) + meths.win_set_cursor(0, {1, height * width - 1}) + eq(0, eval('g:scrolled')) + + feed('gj') + eq(1, eval('g:scrolled')) + eq({ + all = {leftcol = 0, topline = 0, width = 0, height = 0, skipcol = width}, + ['1000'] = {leftcol = 0, topline = 0, width = 0, height = 0, skipcol = width}, + }, eval('g:v_event')) + + feed('0') + eq(2, eval('g:scrolled')) + eq({ + all = {leftcol = 0, topline = 0, width = 0, height = 0, skipcol = width}, + ['1000'] = {leftcol = 0, topline = 0, width = 0, height = 0, skipcol = -width}, + }, eval('g:v_event')) + + feed('$') + eq(3, eval('g:scrolled')) + end) + + it('is triggered when the window scrolls in Insert mode', function() + local height = meths.win_get_height(0) + local lines = {} + for i = 1, height * 2 do + lines[i] = tostring(i) + end + meths.buf_set_lines(0, 0, -1, true, lines) + + feed('M') + eq(0, eval('g:scrolled')) + + feed('i') + eq(1, eval('g:scrolled')) + eq({ + all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('i') + eq(2, eval('g:scrolled')) + eq({ + all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = -1, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('L') + eq(2, eval('g:scrolled')) + + feed('A') + eq(3, eval('g:scrolled')) + eq({ + all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + end) +end) + +describe('WinScrolled', function() + -- oldtest: Test_WinScrolled_mouse() + it('is triggered by mouse scrolling in another window', function() + local screen = Screen.new(75, 10) + screen:attach() + exec([[ + set nowrap scrolloff=0 + set mouse=a + call setline(1, ['foo']->repeat(32)) + split + let g:scrolled = 0 + au WinScrolled * let g:scrolled += 1 + ]]) + eq(0, eval('g:scrolled')) + + -- With the upper split focused, send a scroll-down event to the unfocused one. + meths.input_mouse('wheel', 'down', '', 0, 6, 0) + eq(1, eval('g:scrolled')) + + -- Again, but this time while we're in insert mode. + feed('i') + meths.input_mouse('wheel', 'down', '', 0, 6, 0) + feed('') + eq(2, eval('g:scrolled')) + end) + + -- oldtest: Test_WinScrolled_close_curwin() + it('closing window does not cause use-after-free #13265', function() + exec([[ + set nowrap scrolloff=0 + call setline(1, ['aaa', 'bbb']) + vsplit + au WinScrolled * close + ]]) + + -- This was using freed memory + feed('') + assert_alive() + end) + + it('is triggered by mouse scrolling in unfocused floating window #18222', function() + local screen = Screen.new(80, 24) + screen:attach() + local buf = meths.create_buf(true, true) + meths.buf_set_lines(buf, 0, -1, false, {'a', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'}) + local win = meths.open_win(buf, false, { + height = 5, + width = 10, + col = 0, + row = 1, + relative = 'editor', + style = 'minimal' + }) + local winid_str = tostring(win.id) + exec([[ + let g:scrolled = 0 + autocmd WinScrolled * let g:scrolled += 1 + autocmd WinScrolled * let g:amatch = expand('') + autocmd WinScrolled * let g:v_event = deepcopy(v:event) + ]]) + eq(0, eval('g:scrolled')) + + meths.input_mouse('wheel', 'down', '', 0, 3, 3) + eq(1, eval('g:scrolled')) + eq(winid_str, eval('g:amatch')) + eq({ + all = {leftcol = 0, topline = 3, width = 0, height = 0, skipcol = 0}, + [winid_str] = {leftcol = 0, topline = 3, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + meths.input_mouse('wheel', 'up', '', 0, 3, 3) + eq(2, eval('g:scrolled')) + eq(tostring(win.id), eval('g:amatch')) + eq({ + all = {leftcol = 0, topline = 3, width = 0, height = 0, skipcol = 0}, + [winid_str] = {leftcol = 0, topline = -3, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + end) +end) diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua deleted file mode 100644 index 5a426fcfa1..0000000000 --- a/test/functional/autocmd/winscrolled_spec.lua +++ /dev/null @@ -1,162 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local Screen = require('test.functional.ui.screen') - -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local exec = helpers.exec -local command = helpers.command -local feed = helpers.feed -local meths = helpers.meths -local assert_alive = helpers.assert_alive - -before_each(clear) - -describe('WinScrolled', function() - local win_id - - before_each(function() - win_id = meths.get_current_win().id - command(string.format('autocmd WinScrolled %d let g:matched = v:true', win_id)) - command('let g:scrolled = 0') - command('autocmd WinScrolled * let g:scrolled += 1') - command([[autocmd WinScrolled * let g:amatch = str2nr(expand(''))]]) - command([[autocmd WinScrolled * let g:afile = str2nr(expand(''))]]) - end) - - after_each(function() - eq(true, eval('g:matched')) - eq(win_id, eval('g:amatch')) - eq(win_id, eval('g:afile')) - end) - - it('is triggered by scrolling vertically', function() - local lines = {'123', '123'} - meths.buf_set_lines(0, 0, -1, true, lines) - eq(0, eval('g:scrolled')) - feed('') - eq(1, eval('g:scrolled')) - end) - - it('is triggered by scrolling horizontally', function() - command('set nowrap') - local width = meths.win_get_width(0) - local line = '123' .. ('*'):rep(width * 2) - local lines = {line, line} - meths.buf_set_lines(0, 0, -1, true, lines) - eq(0, eval('g:scrolled')) - feed('zl') - eq(1, eval('g:scrolled')) - end) - - it('is triggered by horizontal scrolling from cursor move', function() - command('set nowrap') - local lines = {'', '', 'Foo'} - meths.buf_set_lines(0, 0, -1, true, lines) - meths.win_set_cursor(0, {3, 0}) - eq(0, eval('g:scrolled')) - feed('zl') - eq(1, eval('g:scrolled')) - feed('zl') - eq(2, eval('g:scrolled')) - feed('h') - eq(3, eval('g:scrolled')) - end) - - it('is triggered by scrolling on a long wrapped line #19968', function() - local height = meths.win_get_height(0) - local width = meths.win_get_width(0) - meths.buf_set_lines(0, 0, -1, true, {('foo'):rep(height * width)}) - meths.win_set_cursor(0, {1, height * width - 1}) - eq(0, eval('g:scrolled')) - feed('gj') - eq(1, eval('g:scrolled')) - feed('0') - eq(2, eval('g:scrolled')) - feed('$') - eq(3, eval('g:scrolled')) - end) - - it('is triggered when the window scrolls in Insert mode', function() - local height = meths.win_get_height(0) - local lines = {} - for i = 1, height * 2 do - lines[i] = tostring(i) - end - meths.buf_set_lines(0, 0, -1, true, lines) - feed('L') - eq(0, eval('g:scrolled')) - feed('A') - eq(1, eval('g:scrolled')) - end) -end) - -describe('WinScrolled', function() - -- oldtest: Test_WinScrolled_mouse() - it('is triggered by mouse scrolling in another window', function() - local screen = Screen.new(75, 10) - screen:attach() - exec([[ - set nowrap scrolloff=0 - set mouse=a - call setline(1, ['foo']->repeat(32)) - split - let g:scrolled = 0 - au WinScrolled * let g:scrolled += 1 - ]]) - eq(0, eval('g:scrolled')) - - -- With the upper split focused, send a scroll-down event to the unfocused one. - meths.input_mouse('wheel', 'down', '', 0, 6, 0) - eq(1, eval('g:scrolled')) - - -- Again, but this time while we're in insert mode. - feed('i') - meths.input_mouse('wheel', 'down', '', 0, 6, 0) - feed('') - eq(2, eval('g:scrolled')) - end) - - -- oldtest: Test_WinScrolled_close_curwin() - it('closing window does not cause use-after-free #13265', function() - exec([[ - set nowrap scrolloff=0 - call setline(1, ['aaa', 'bbb']) - vsplit - au WinScrolled * close - ]]) - - -- This was using freed memory - feed('') - assert_alive() - end) - - it('is triggered by mouse scrolling in unfocused floating window #18222', function() - local screen = Screen.new(80, 24) - screen:attach() - local buf = meths.create_buf(true, true) - meths.buf_set_lines(buf, 0, -1, false, {'a', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'}) - local win = meths.open_win(buf, false, { - height = 5, - width = 10, - col = 0, - row = 1, - relative = 'editor', - style = 'minimal' - }) - exec([[ - let g:scrolled = 0 - autocmd WinScrolled * let g:scrolled += 1 - autocmd WinScrolled * let g:amatch = expand('') - ]]) - eq(0, eval('g:scrolled')) - - meths.input_mouse('wheel', 'down', '', 0, 3, 3) - eq(1, eval('g:scrolled')) - eq(tostring(win.id), eval('g:amatch')) - - meths.input_mouse('wheel', 'down', '', 0, 3, 3) - eq(2, eval('g:scrolled')) - eq(tostring(win.id), eval('g:amatch')) - end) -end) -- cgit From f1b88ced07a5dcc62cd847cade2ed97e23fffbf9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 23 Nov 2022 12:14:16 +0800 Subject: fix(options): fix local 'sidescrolloff' doesn't work for mouse (#21162) Missing part of Vim patch 8.1.0864. --- test/functional/ui/mouse_spec.lua | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index b3ea0edb12..f705678bd5 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -968,6 +968,49 @@ describe('ui/mouse/input', function() ]]) end) + it("'sidescrolloff' applies to horizontal scrolling", function() + command('set nowrap') + command('set sidescrolloff=4') + + feed("I 020ib0") + screen:expect([[ + testing | + mouse | + ^bbbbbbbbbbbbbbbbbbbb supp| + {0:~ }| + | + ]]) + + meths.input_mouse('wheel', 'right', '', 0, 0, 27) + screen:expect([[ + g | + | + bbbb^bbbbbbbbbb support an| + {0:~ }| + | + ]]) + + -- window-local 'sidescrolloff' should override global value. #21162 + command('setlocal sidescrolloff=2') + feed('0') + screen:expect([[ + testing | + mouse | + ^bbbbbbbbbbbbbbbbbbbb supp| + {0:~ }| + | + ]]) + + meths.input_mouse('wheel', 'right', '', 0, 0, 27) + screen:expect([[ + g | + | + bb^bbbbbbbbbbbb support an| + {0:~ }| + | + ]]) + end) + describe('on concealed text', function() -- Helpful for reading the test expectations: -- :match Error /\^/ -- cgit From 81c87857f632d1afe147e9b77a97da38f8f3a887 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 24 Nov 2022 18:37:52 +0800 Subject: vim-patch:8.2.3698: match highlighting continues over breakindent Problem: Match highlighting continues over breakindent. Solution: Stop before the end column. (closes vim/vim#9242) https://github.com/vim/vim/commit/0c359af5c0fd106d3f57cc0bb7cef1c89b5e1e10 Cherry-pick Test_matchdelete_redraw() from patch 8.2.1077. Co-authored-by: Bram Moolenaar --- test/functional/legacy/match_spec.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/match_spec.lua b/test/functional/legacy/match_spec.lua index 271f844f9d..eab2bff70a 100644 --- a/test/functional/legacy/match_spec.lua +++ b/test/functional/legacy/match_spec.lua @@ -36,3 +36,32 @@ describe('matchaddpos()', function() ]]) end) end) + +describe('match highlighting', function() + -- oldtest: Test_match_in_linebreak() + it('does not continue in linebreak vim-patch:8.2.3698', function() + local screen = Screen.new(75, 10) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg + }) + screen:attach() + exec([=[ + set breakindent linebreak breakat+=] + call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1) + call matchaddpos('ErrorMsg', [[1, 51]]) + ]=]) + screen:expect([[ + ^xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx{1:]} | + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end) +end) -- cgit From e38ae3b74ff513d991f8212dfbba75fe8c66aad3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 24 Nov 2022 18:53:28 +0800 Subject: vim-patch:8.2.3940: match highlight disappears when doing incsearch for ":s/pat" Problem: Match highlight disappears when doing incsearch for ":s/pat". Solution: Only use line limit for incsearch highlighting. (closes vim/vim#9425) https://github.com/vim/vim/commit/94fb8274ca8c93a10102d41c8bcc848f75cb7334 Co-authored-by: Bram Moolenaar --- test/functional/legacy/match_spec.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/match_spec.lua b/test/functional/legacy/match_spec.lua index eab2bff70a..51cd60864e 100644 --- a/test/functional/legacy/match_spec.lua +++ b/test/functional/legacy/match_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local exec = helpers.exec +local feed = helpers.feed before_each(clear) @@ -64,4 +65,36 @@ describe('match highlighting', function() | ]]) end) + + it('is shown with incsearch vim-patch:8.2.3940', function() + local screen = Screen.new(75, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.Yellow}, -- Search + [2] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg + }) + screen:attach() + exec([[ + set incsearch + call setline(1, range(20)) + call matchaddpos('ErrorMsg', [3]) + ]]) + screen:expect([[ + ^0 | + 1 | + {2:2} | + 3 | + 4 | + | + ]]) + feed(':s/0') + screen:expect([[ + {1:0} | + 1 | + {2:2} | + 3 | + 4 | + :s/0^ | + ]]) + end) end) -- cgit From a98970219ddc90b6f599203f6bb24da79fc6bbeb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 24 Nov 2022 19:05:53 +0800 Subject: vim-patch:8.2.4062: match highlighting of tab too short Problem: Match highlighting of tab too short. Solution: Do not stop match highlighting if on a Tab. (Christian Brabandt, closes vim/vim#9507, closes vim/vim#9500) https://github.com/vim/vim/commit/0bbca540f7377889e2154aa5731f6eeffcb5c0cc Co-authored-by: Bram Moolenaar --- test/functional/legacy/match_spec.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/match_spec.lua b/test/functional/legacy/match_spec.lua index 51cd60864e..b6e45c396c 100644 --- a/test/functional/legacy/match_spec.lua +++ b/test/functional/legacy/match_spec.lua @@ -97,4 +97,30 @@ describe('match highlighting', function() :s/0^ | ]]) end) + + it('on a Tab vim-patch:8.2.4062', function() + local screen = Screen.new(75, 10) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg + }) + screen:attach() + exec([[ + set linebreak + call setline(1, "\tix") + call matchadd('ErrorMsg', '\t') + ]]) + screen:expect([[ + {1: ^ }ix | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end) end) -- cgit From ba360a26a294e0ed83ff8e401caabaf4a17c7c30 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 15:07:25 +0800 Subject: vim-patch:8.2.2684: not enough folding code is tested Problem: Not enough folding code is tested. Solution: Add more test cases. (Yegappan Lakshmanan, closes vim/vim#8046) https://github.com/vim/vim/commit/5c504f680e63120fea36becfabb8d939d4449e34 Reorder test_fold.vim to match upstream. Cherry-pick Test_fold_expr_error() from patch 8.2.0633. Cherry-pick syntax feature check from patch 8.2.1432. Cherry-pick a delete() call from patch 8.2.2112. --- test/functional/legacy/045_folding_spec.lua | 214 ------------------- test/functional/legacy/fold_spec.lua | 313 ++++++++++++++++++++++++++++ test/functional/legacy/source_spec.lua | 31 +++ test/functional/ui/fold_spec.lua | 50 +---- 4 files changed, 347 insertions(+), 261 deletions(-) delete mode 100644 test/functional/legacy/045_folding_spec.lua create mode 100644 test/functional/legacy/fold_spec.lua create mode 100644 test/functional/legacy/source_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/045_folding_spec.lua b/test/functional/legacy/045_folding_spec.lua deleted file mode 100644 index 7d7856fd37..0000000000 --- a/test/functional/legacy/045_folding_spec.lua +++ /dev/null @@ -1,214 +0,0 @@ --- Tests for folding. -local Screen = require('test.functional.ui.screen') - -local helpers = require('test.functional.helpers')(after_each) -local feed, insert, feed_command, expect_any = - helpers.feed, helpers.insert, helpers.feed_command, helpers.expect_any - -describe('folding', function() - local screen - - before_each(function() - helpers.clear() - - screen = Screen.new(20, 8) - screen:attach() - end) - - it('creation, opening, moving (to the end) and closing', function() - insert([[ - 1 aa - 2 bb - 3 cc - last - ]]) - - -- Basic test if a fold can be created, opened, moving to the end and - -- closed. - feed_command('1') - feed('zf2j') - feed_command('call append("$", "manual " . getline(foldclosed(".")))') - feed('zo') - feed_command('call append("$", foldclosed("."))') - feed(']z') - feed_command('call append("$", getline("."))') - feed('zc') - feed_command('call append("$", getline(foldclosed(".")))') - - expect_any([[ - manual 1 aa - -1 - 3 cc - 1 aa]]) - end) - - it("foldmethod=marker", function() - screen:try_resize(20, 10) - insert([[ - dd {{{ - ee {{{ }}} - ff }}} - ]]) - feed_command('set fdm=marker fdl=1') - feed_command('2') - feed_command('call append("$", "line 2 foldlevel=" . foldlevel("."))') - feed('[z') - feed_command('call append("$", foldlevel("."))') - feed('jo{{ r{jj') -- writes '{{{' and moves 2 lines bot - feed_command('call append("$", foldlevel("."))') - feed('kYpj') - feed_command('call append("$", foldlevel("."))') - - helpers.poke_eventloop() - screen:expect([[ - dd {{{ | - ee {{{ }}} | - {{{ | - ff }}} | - ff }}} | - ^ | - line 2 foldlevel=2 | - 1 | - 1 | - | - ]]) - - end) - - it("foldmethod=indent", function() - screen:try_resize(20, 8) - feed_command('set fdm=indent sw=2') - insert([[ - aa - bb - cc - last - ]]) - feed_command('call append("$", "foldlevel line3=" . foldlevel(3))') - feed_command('call append("$", foldlevel(2))') - feed('zR') - - helpers.poke_eventloop() - screen:expect([[ - aa | - bb | - cc | - last | - ^ | - foldlevel line3=2 | - 1 | - | - ]]) - end) - - it("foldmethod=syntax", function() - screen:try_resize(35, 15) - insert([[ - 1 aa - 2 bb - 3 cc - 4 dd {{{ - 5 ee {{{ }}} - 6 ff }}} - 7 gg - 8 hh - 9 ii - a jj - b kk - last]]) - feed_command('set fdm=syntax fdl=0') - feed_command('syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3') - feed_command('syn region Fd1 start="ee" end="ff" fold contained') - feed_command('syn region Fd2 start="gg" end="hh" fold contained') - feed_command('syn region Fd3 start="commentstart" end="commentend" fold contained') - feed('Gzk') - feed_command('call append("$", "folding " . getline("."))') - feed('k') - feed_command('call append("$", getline("."))') - feed('jAcommentstart Acommentend') - feed_command('set fdl=1') - feed('3j') - feed_command('call append("$", getline("."))') - feed_command('set fdl=0') - feed('zOj') -- redraws screen - feed_command('call append("$", getline("."))') - feed_command('set fdl=0') - expect_any([[ - folding 9 ii - 3 cc - 9 ii - a jj]]) - end) - - it("foldmethod=expression", function() - insert([[ - 1 aa - 2 bb - 3 cc - 4 dd {{{ - 5 ee {{{ }}} - 6 ff }}} - 7 gg - 8 hh - 9 ii - a jj - b kk - last ]]) - - feed_command([[ - fun Flvl() - let l = getline(v:lnum) - if l =~ "bb$" - return 2 - elseif l =~ "gg$" - return "s1" - elseif l =~ "ii$" - return ">2" - elseif l =~ "kk$" - return "0" - endif - return "=" - endfun - ]]) - feed_command('set fdm=expr fde=Flvl()') - feed_command('/bb$') - feed_command('call append("$", "expr " . foldlevel("."))') - feed_command('/hh$') - feed_command('call append("$", foldlevel("."))') - feed_command('/ii$') - feed_command('call append("$", foldlevel("."))') - feed_command('/kk$') - feed_command('call append("$", foldlevel("."))') - - expect_any([[ - expr 2 - 1 - 2 - 0]]) - end) - - it('can be opened after :move', function() - -- luacheck: ignore - screen:try_resize(35, 8) - insert([[ - Test fdm=indent and :move bug END - line2 - Test fdm=indent START - line3 - line4]]) - feed_command('set noai nosta ') - feed_command('set fdm=indent') - feed_command('1m1') - feed('2jzc') - feed_command('m0') - feed('zR') - - expect_any([[ - Test fdm=indent START - line3 - line4 - Test fdm=indent and :move bug END - line2]]) - end) -end) - diff --git a/test/functional/legacy/fold_spec.lua b/test/functional/legacy/fold_spec.lua new file mode 100644 index 0000000000..a1cfa50880 --- /dev/null +++ b/test/functional/legacy/fold_spec.lua @@ -0,0 +1,313 @@ +-- Tests for folding. +local Screen = require('test.functional.ui.screen') + +local helpers = require('test.functional.helpers')(after_each) +local feed, insert, feed_command, expect_any = + helpers.feed, helpers.insert, helpers.feed_command, helpers.expect_any +local command = helpers.command +local exec = helpers.exec + +describe('folding', function() + local screen + + before_each(function() + helpers.clear() + + screen = Screen.new(45, 8) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [2] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey}, -- Folded + [3] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.Grey}, -- FoldColumn + [4] = {foreground = Screen.colors.Brown}, -- LineNr + }) + screen:attach() + end) + + it('creation, opening, moving (to the end) and closing', function() + insert([[ + 1 aa + 2 bb + 3 cc + last + ]]) + + -- Basic test if a fold can be created, opened, moving to the end and + -- closed. + feed_command('1') + feed('zf2j') + feed_command('call append("$", "manual " . getline(foldclosed(".")))') + feed('zo') + feed_command('call append("$", foldclosed("."))') + feed(']z') + feed_command('call append("$", getline("."))') + feed('zc') + feed_command('call append("$", getline(foldclosed(".")))') + + expect_any([[ + manual 1 aa + -1 + 3 cc + 1 aa]]) + end) + + it("foldmethod=marker", function() + screen:try_resize(20, 10) + insert([[ + dd {{{ + ee {{{ }}} + ff }}} + ]]) + feed_command('set fdm=marker fdl=1') + feed_command('2') + feed_command('call append("$", "line 2 foldlevel=" . foldlevel("."))') + feed('[z') + feed_command('call append("$", foldlevel("."))') + feed('jo{{ r{jj') -- writes '{{{' and moves 2 lines bot + feed_command('call append("$", foldlevel("."))') + feed('kYpj') + feed_command('call append("$", foldlevel("."))') + + helpers.poke_eventloop() + screen:expect([[ + dd {{{ | + ee {{{ }}} | + {{{ | + ff }}} | + ff }}} | + ^ | + line 2 foldlevel=2 | + 1 | + 1 | + | + ]]) + + end) + + it("foldmethod=indent", function() + screen:try_resize(20, 8) + feed_command('set fdm=indent sw=2') + insert([[ + aa + bb + cc + last + ]]) + feed_command('call append("$", "foldlevel line3=" . foldlevel(3))') + feed_command('call append("$", foldlevel(2))') + feed('zR') + + helpers.poke_eventloop() + screen:expect([[ + aa | + bb | + cc | + last | + ^ | + foldlevel line3=2 | + 1 | + | + ]]) + end) + + it("foldmethod=syntax", function() + screen:try_resize(35, 15) + insert([[ + 1 aa + 2 bb + 3 cc + 4 dd {{{ + 5 ee {{{ }}} + 6 ff }}} + 7 gg + 8 hh + 9 ii + a jj + b kk + last]]) + feed_command('set fdm=syntax fdl=0') + feed_command('syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3') + feed_command('syn region Fd1 start="ee" end="ff" fold contained') + feed_command('syn region Fd2 start="gg" end="hh" fold contained') + feed_command('syn region Fd3 start="commentstart" end="commentend" fold contained') + feed('Gzk') + feed_command('call append("$", "folding " . getline("."))') + feed('k') + feed_command('call append("$", getline("."))') + feed('jAcommentstart Acommentend') + feed_command('set fdl=1') + feed('3j') + feed_command('call append("$", getline("."))') + feed_command('set fdl=0') + feed('zOj') -- redraws screen + feed_command('call append("$", getline("."))') + feed_command('set fdl=0') + expect_any([[ + folding 9 ii + 3 cc + 9 ii + a jj]]) + end) + + it("foldmethod=expression", function() + insert([[ + 1 aa + 2 bb + 3 cc + 4 dd {{{ + 5 ee {{{ }}} + 6 ff }}} + 7 gg + 8 hh + 9 ii + a jj + b kk + last ]]) + + feed_command([[ + fun Flvl() + let l = getline(v:lnum) + if l =~ "bb$" + return 2 + elseif l =~ "gg$" + return "s1" + elseif l =~ "ii$" + return ">2" + elseif l =~ "kk$" + return "0" + endif + return "=" + endfun + ]]) + feed_command('set fdm=expr fde=Flvl()') + feed_command('/bb$') + feed_command('call append("$", "expr " . foldlevel("."))') + feed_command('/hh$') + feed_command('call append("$", foldlevel("."))') + feed_command('/ii$') + feed_command('call append("$", foldlevel("."))') + feed_command('/kk$') + feed_command('call append("$", foldlevel("."))') + + expect_any([[ + expr 2 + 1 + 2 + 0]]) + end) + + it('can be opened after :move', function() + -- luacheck: ignore + screen:try_resize(35, 8) + insert([[ + Test fdm=indent and :move bug END + line2 + Test fdm=indent START + line3 + line4]]) + feed_command('set noai nosta ') + feed_command('set fdm=indent') + feed_command('1m1') + feed('2jzc') + feed_command('m0') + feed('zR') + + expect_any([[ + Test fdm=indent START + line3 + line4 + Test fdm=indent and :move bug END + line2]]) + end) + + -- oldtest: Test_folds_with_rnu() + it('with relative line numbers', function() + command('set fdm=marker rnu foldcolumn=2') + command('call setline(1, ["{{{1", "nline 1", "{{{1", "line 2"])') + + screen:expect([[ + {3:+ }{4: 0 }{2:^+-- 2 lines: ·························}| + {3:+ }{4: 1 }{2:+-- 2 lines: ·························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + feed("j") + screen:expect([[ + {3:+ }{4: 1 }{2:+-- 2 lines: ·························}| + {3:+ }{4: 0 }{2:^+-- 2 lines: ·························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + end) + + -- oldtest: Test_foldclose_opt() + it('foldclose=all', function() + exec([[ + set foldmethod=manual foldclose=all foldopen=all + call setline(1, ['one', 'two', 'three', 'four']) + 2,3fold + ]]) + + screen:expect([[ + ^one | + {2:+-- 2 lines: two····························}| + four | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + feed('2G') + screen:expect([[ + one | + ^two | + three | + four | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + feed('4G') + screen:expect([[ + one | + {2:+-- 2 lines: two····························}| + ^four | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + feed('3G') + screen:expect([[ + one | + two | + ^three | + four | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + feed('1G') + screen:expect([[ + ^one | + {2:+-- 2 lines: two····························}| + four | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + end) +end) diff --git a/test/functional/legacy/source_spec.lua b/test/functional/legacy/source_spec.lua new file mode 100644 index 0000000000..02e6385247 --- /dev/null +++ b/test/functional/legacy/source_spec.lua @@ -0,0 +1,31 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local feed = helpers.feed +local write_file = helpers.write_file + +before_each(clear) + +describe(':source!', function() + it('gives E22 when scripts nested too deep', function() + write_file('Xscript.vim', [[ + :source! Xscript.vim + ]]) + local screen = Screen.new(75, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg + }) + screen:attach() + feed(':source! Xscript.vim\n') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {1:E22: Scripts nested too deep} | + ]]) + os.remove('Xscript.vim') + end) +end) diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index 3c143d87ca..bfa7167100 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -7,7 +7,7 @@ local insert = helpers.insert local expect = helpers.expect local funcs = helpers.funcs local meths = helpers.meths -local source = helpers.source +local exec = helpers.exec local assert_alive = helpers.assert_alive @@ -199,50 +199,6 @@ describe("folded lines", function() end end) - it("highlighting with relative line numbers", function() - command("set relativenumber cursorline cursorlineopt=number foldmethod=marker") - feed_command("set foldcolumn=2") - funcs.setline(1, '{{{1') - funcs.setline(2, 'line 1') - funcs.setline(3, '{{{1') - funcs.setline(4, 'line 2') - feed("j") - if multigrid then - screen:expect([[ - ## grid 1 - [2:---------------------------------------------]| - [2:---------------------------------------------]| - [2:---------------------------------------------]| - [2:---------------------------------------------]| - [2:---------------------------------------------]| - [2:---------------------------------------------]| - [2:---------------------------------------------]| - [3:---------------------------------------------]| - ## grid 2 - {7:+ }{8: 1 }{5:+-- 2 lines: ·························}| - {7:+ }{9: 0 }{5:^+-- 2 lines: ·························}| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - ## grid 3 - :set foldcolumn=2 | - ]]) - else - screen:expect([[ - {7:+ }{8: 1 }{5:+-- 2 lines: ·························}| - {7:+ }{9: 0 }{5:^+-- 2 lines: ·························}| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - :set foldcolumn=2 | - ]]) - end - end) - it("work with spell", function() command("set spell") insert(content1) @@ -1714,7 +1670,7 @@ describe("folded lines", function() end) it('does not crash when foldtext is longer than columns #12988', function() - source([[ + exec([[ function! MyFoldText() abort return repeat('-', &columns + 100) endfunction @@ -1761,7 +1717,7 @@ describe("folded lines", function() it('work correctly with :move #18668', function() screen:try_resize(45, 12) - source([[ + exec([[ set foldmethod=expr foldexpr=indent(v:lnum) let content = ['', '', 'Line1', ' Line2', ' Line3', \ 'Line4', ' Line5', ' Line6', -- cgit From 84646b80f3adb14d8e7c052047e2cb30a16b1eca Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 15:50:54 +0800 Subject: vim-patch:8.2.2713: folding code not sufficiently tested Problem: Folding code not sufficiently tested. Solution: Add a few more test cases. (Yegappan Lakshmanan, closes vim/vim#8064) https://github.com/vim/vim/commit/68ffe8cade5e0c52680c00cb9f3f87104fbe653a --- test/functional/legacy/fold_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/fold_spec.lua b/test/functional/legacy/fold_spec.lua index a1cfa50880..83513a3f94 100644 --- a/test/functional/legacy/fold_spec.lua +++ b/test/functional/legacy/fold_spec.lua @@ -309,5 +309,27 @@ describe('folding', function() {1:~ }| | ]]) + feed('2G') + screen:expect([[ + one | + ^two | + three | + four | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + feed('k') + screen:expect([[ + ^one | + {2:+-- 2 lines: two····························}| + four | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) end) end) -- cgit From 9dfbbde240fc095b856d8e0e1c670b1912ec6640 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 26 Nov 2022 00:52:30 +0100 Subject: docs: fix typos (#21168) --- test/functional/ui/spell_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/spell_spec.lua b/test/functional/ui/spell_spec.lua index 425790dbf9..5b43edbad4 100644 --- a/test/functional/ui/spell_spec.lua +++ b/test/functional/ui/spell_spec.lua @@ -70,7 +70,7 @@ describe("'spell'", function() "with missing caps here.", | ^ | | - ]]) + ]]) end) it('"noplainbuffer" and syntax #20385', function() -- cgit From 3f478547cfec72b9d3eb53efde2df45d85c44c18 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Sat, 26 Nov 2022 01:50:52 +0100 Subject: fix(startup): support .exrc or .nvimrc with init.lua (#21181) --- test/functional/core/startup_spec.lua | 64 +++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index bab339e253..41596f5416 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -12,6 +12,7 @@ local eval = helpers.eval local exec_lua = helpers.exec_lua local feed = helpers.feed local funcs = helpers.funcs +local pesc = helpers.pesc local mkdir = helpers.mkdir local mkdir_p = helpers.mkdir_p local nvim_prog = helpers.nvim_prog @@ -576,7 +577,66 @@ describe('user config init', function() eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) end) - describe 'with explicitly provided config'(function() + describe('with existing .exrc in cwd', function() + local exrc_path = '.exrc' + local xstate = 'Xstate' + + before_each(function() + write_file(init_lua_path, [[ + vim.o.exrc = true + vim.g.from_exrc = 0 + ]]) + mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) + write_file(exrc_path, [[ + let g:from_exrc = 1 + ]]) + end) + + after_each(function() + os.remove(exrc_path) + rmdir(xstate) + end) + + it('loads .exrc #13501', function() + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The .exrc file is not trusted, and the prompt is skipped because there is no UI. + eq(0, eval('g:from_exrc')) + + local screen = Screen.new(50, 8) + screen:attach() + funcs.termopen({nvim_prog}) + screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) + -- `i` to enter Terminal mode, `a` to allow + feed('ia') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + | + -- TERMINAL -- | + ]]) + feed(':echo g:from_exrc') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + 1 | + -- TERMINAL -- | + ]]) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The .exrc file is now trusted. + eq(1, eval('g:from_exrc')) + end) + end) + + describe('with explicitly provided config', function() local custom_lua_path = table.concat({xhome, 'custom.lua'}, pathsep) before_each(function() write_file(custom_lua_path, [[ @@ -591,7 +651,7 @@ describe('user config init', function() end) end) - describe 'VIMRC also exists'(function() + describe('VIMRC also exists', function() before_each(function() write_file(table.concat({xconfig, 'nvim', 'init.vim'}, pathsep), [[ let g:vim_rc = 1 -- cgit From 942f26279d373fcdebcb41363e526a2871b09a71 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 27 Nov 2022 10:33:54 +0100 Subject: fix(tests): only get the color map once, even for multiple test files Problem: test/functional/ui/screen.lua would be reloaded for each *_spec.lua file, which causes an extra nvim session to be started to get the color map each time. solution: Mark screen.lua as a preloaded file, but defer the loading of the color map to the first time Screen object is initialised. --- test/functional/preload.lua | 1 + test/functional/ui/float_spec.lua | 62 +++++++++++++++++------------------ test/functional/ui/highlight_spec.lua | 2 +- test/functional/ui/screen.lua | 12 +++---- 4 files changed, 39 insertions(+), 38 deletions(-) (limited to 'test/functional') diff --git a/test/functional/preload.lua b/test/functional/preload.lua index 43e2151f84..e225854de3 100644 --- a/test/functional/preload.lua +++ b/test/functional/preload.lua @@ -2,6 +2,7 @@ -- Busted started doing this to help provide more isolation. See issue #62 -- for more information about this. local helpers = require('test.functional.helpers')(nil) +local screen = require('test.functional.ui.screen') local busted = require("busted") local is_os = helpers.is_os diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index c7ee4ee87d..bc05d9081d 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -25,36 +25,6 @@ describe('float window', function() clear() command('hi VertSplit gui=reverse') end) - local attrs = { - [0] = {bold=true, foreground=Screen.colors.Blue}, - [1] = {background = Screen.colors.LightMagenta}, - [2] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1}, - [3] = {bold = true}, - [4] = {bold = true, reverse = true}, - [5] = {reverse = true}, - [6] = {background = Screen.colors.LightMagenta, bold = true, reverse = true}, - [7] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [8] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [9] = {background = Screen.colors.LightGrey, underline = true}, - [10] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta}, - [11] = {bold = true, foreground = Screen.colors.Magenta}, - [12] = {background = Screen.colors.Red, bold = true, foreground = Screen.colors.Blue1}, - [13] = {background = Screen.colors.WebGray}, - [14] = {foreground = Screen.colors.Brown}, - [15] = {background = Screen.colors.Grey20}, - [16] = {background = Screen.colors.Grey20, bold = true, foreground = Screen.colors.Blue1}, - [17] = {background = Screen.colors.Yellow}, - [18] = {foreground = Screen.colors.Brown, background = Screen.colors.Grey20}, - [19] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray}, - [20] = {bold = true, foreground = Screen.colors.Brown}, - [21] = {background = Screen.colors.Gray90}, - [22] = {background = Screen.colors.LightRed}, - [23] = {foreground = Screen.colors.Black, background = Screen.colors.White}; - [24] = {foreground = Screen.colors.Black, background = Screen.colors.Grey80}; - [25] = {blend = 100, background = Screen.colors.Gray0}; - [26] = {blend = 80, background = Screen.colors.Gray0}; - [27] = {background = Screen.colors.LightGray}; - } it('behavior', function() -- Create three windows and test that ":wincmd " changes to the @@ -724,10 +694,40 @@ describe('float window', function() end) local function with_ext_multigrid(multigrid) - local screen + local screen, attrs before_each(function() screen = Screen.new(40,7) screen:attach {ext_multigrid=multigrid} + attrs = { + [0] = {bold=true, foreground=Screen.colors.Blue}, + [1] = {background = Screen.colors.LightMagenta}, + [2] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1}, + [3] = {bold = true}, + [4] = {bold = true, reverse = true}, + [5] = {reverse = true}, + [6] = {background = Screen.colors.LightMagenta, bold = true, reverse = true}, + [7] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + [8] = {bold = true, foreground = Screen.colors.SeaGreen4}, + [9] = {background = Screen.colors.LightGrey, underline = true}, + [10] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta}, + [11] = {bold = true, foreground = Screen.colors.Magenta}, + [12] = {background = Screen.colors.Red, bold = true, foreground = Screen.colors.Blue1}, + [13] = {background = Screen.colors.WebGray}, + [14] = {foreground = Screen.colors.Brown}, + [15] = {background = Screen.colors.Grey20}, + [16] = {background = Screen.colors.Grey20, bold = true, foreground = Screen.colors.Blue1}, + [17] = {background = Screen.colors.Yellow}, + [18] = {foreground = Screen.colors.Brown, background = Screen.colors.Grey20}, + [19] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray}, + [20] = {bold = true, foreground = Screen.colors.Brown}, + [21] = {background = Screen.colors.Gray90}, + [22] = {background = Screen.colors.LightRed}, + [23] = {foreground = Screen.colors.Black, background = Screen.colors.White}; + [24] = {foreground = Screen.colors.Black, background = Screen.colors.Grey80}; + [25] = {blend = 100, background = Screen.colors.Gray0}; + [26] = {blend = 80, background = Screen.colors.Gray0}; + [27] = {background = Screen.colors.LightGray}; + } screen:set_default_attr_ids(attrs) end) diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index bcb437a55d..8dd1091353 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -1403,7 +1403,7 @@ describe('ColorColumn highlight', function() before_each(function() clear() screen = Screen.new(40, 15) - Screen:set_default_attr_ids({ + screen:set_default_attr_ids({ [1] = {background = Screen.colors.LightRed}, -- ColorColumn [2] = {background = Screen.colors.Grey90}, -- CursorLine [3] = {foreground = Screen.colors.Brown}, -- LineNr diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index c44e147c4d..79927273a6 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -101,13 +101,10 @@ end local default_screen_timeout = default_timeout_factor * 3500 -do - local spawn, nvim_prog = helpers.spawn, helpers.nvim_prog - local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N', '--embed'}) +function Screen._init_colors(session) local status, rv = session:request('nvim_get_color_map') if not status then - print('failed to get color map') - os.exit(1) + error('failed to get color map') end local colors = rv local colornames = {} @@ -116,12 +113,15 @@ do -- this is just a helper to get any canonical name of a color colornames[rgb] = name end - session:close() Screen.colors = colors Screen.colornames = colornames end function Screen.new(width, height) + if not Screen.colors then + Screen._init_colors(get_session()) + end + if not width then width = 53 end -- cgit From f004812b338340e5f5157aa68d09d3f0e5605c6c Mon Sep 17 00:00:00 2001 From: Jlll1 Date: Mon, 28 Nov 2022 20:23:04 +0100 Subject: feat(secure): add `:trust` command and vim.secure.trust() (#21107) Introduce vim.secure.trust() to programmatically manage the trust database. Use this function in a new :trust ex command which can be used as a simple frontend. Resolves: https://github.com/neovim/neovim/issues/21092 Co-authored-by: Gregory Anders Co-authored-by: ii14 --- test/functional/ex_cmds/trust_spec.lua | 176 +++++++++++++++++++++++++++++++++ test/functional/lua/secure_spec.lua | 107 ++++++++++++++++++++ 2 files changed, 283 insertions(+) create mode 100644 test/functional/ex_cmds/trust_spec.lua (limited to 'test/functional') diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua new file mode 100644 index 0000000000..10ee02a790 --- /dev/null +++ b/test/functional/ex_cmds/trust_spec.lua @@ -0,0 +1,176 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local eq = helpers.eq +local clear = helpers.clear +local command = helpers.command +local pathsep = helpers.get_pathsep() +local is_os = helpers.is_os +local funcs = helpers.funcs + +describe(':trust', function() + local xstate = 'Xstate' + + setup(function() + helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) + end) + + teardown(function() + helpers.rmdir(xstate) + end) + + before_each(function() + helpers.write_file('test_file', 'test') + clear{env={XDG_STATE_HOME=xstate}} + end) + + after_each(function() + os.remove('test_file') + end) + + it('trust then deny then remove a file using current buffer', function() + local screen = Screen.new(80, 8) + screen:attach() + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}, + }) + + local cwd = funcs.getcwd() + local hash = funcs.sha256(helpers.read_file('test_file')) + + command('edit test_file') + command('trust') + screen:expect([[ + ^test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}| + ]]) + local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) + + command('trust ++deny') + screen:expect([[ + ^test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| + ]]) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) + + command('trust ++remove') + screen:expect([[ + ^test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| + ]]) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format(''), vim.trim(trust)) + end) + + it('deny then trust then remove a file using current buffer', function() + local screen = Screen.new(80, 8) + screen:attach() + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}, + }) + + local cwd = funcs.getcwd() + local hash = funcs.sha256(helpers.read_file('test_file')) + + command('edit test_file') + command('trust ++deny') + screen:expect([[ + ^test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| + ]]) + local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) + + command('trust') + screen:expect([[ + ^test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}| + ]]) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) + + command('trust ++remove') + screen:expect([[ + ^test | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| + ]]) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format(''), vim.trim(trust)) + end) + + it('deny then remove a file using file path', function() + local screen = Screen.new(80, 8) + screen:attach() + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}, + }) + + local cwd = funcs.getcwd() + + command('trust ++deny test_file') + screen:expect([[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}| + ]]) + local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) + + command('trust ++remove test_file') + screen:expect([[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}| + ]]) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format(''), vim.trim(trust)) + end) +end) diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua index a5eeee8494..46ca2bba8f 100644 --- a/test/functional/lua/secure_spec.lua +++ b/test/functional/lua/secure_spec.lua @@ -168,4 +168,111 @@ describe('vim.secure', function() eq(false, curbufmeths.get_option('modifiable')) end) end) + + describe('trust()', function() + local xstate = 'Xstate' + + setup(function() + helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) + end) + + teardown(function() + helpers.rmdir(xstate) + end) + + before_each(function() + helpers.write_file('test_file', 'test') + end) + + after_each(function() + os.remove('test_file') + end) + + it('returns error when passing both path and bufnr', function() + eq('path and bufnr are mutually exclusive', + pcall_err(exec_lua, [[vim.secure.trust({action='deny', bufnr=0, path='test_file'})]])) + end) + + it('trust then deny then remove a file using bufnr', function() + local cwd = funcs.getcwd() + local hash = funcs.sha256(helpers.read_file('test_file')) + local full_path = cwd .. pathsep .. 'test_file' + + command('edit test_file') + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('%s %s', hash, full_path), vim.trim(trust)) + + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('! %s', full_path), vim.trim(trust)) + + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]])) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq('', vim.trim(trust)) + end) + + it('deny then trust then remove a file using bufnr', function() + local cwd = funcs.getcwd() + local hash = funcs.sha256(helpers.read_file('test_file')) + local full_path = cwd .. pathsep .. 'test_file' + + command('edit test_file') + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) + local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('! %s', full_path), vim.trim(trust)) + + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('%s %s', hash, full_path), vim.trim(trust)) + + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]])) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq('', vim.trim(trust)) + end) + + it('trust using bufnr then deny then remove a file using path', function() + local cwd = funcs.getcwd() + local hash = funcs.sha256(helpers.read_file('test_file')) + local full_path = cwd .. pathsep .. 'test_file' + + command('edit test_file') + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('%s %s', hash, full_path), vim.trim(trust)) + + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]])) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('! %s', full_path), vim.trim(trust)) + + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]])) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq('', vim.trim(trust)) + end) + + it('deny then trust then remove a file using bufnr', function() + local cwd = funcs.getcwd() + local hash = funcs.sha256(helpers.read_file('test_file')) + local full_path = cwd .. pathsep .. 'test_file' + + command('edit test_file') + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]])) + local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('! %s', full_path), vim.trim(trust)) + + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq(string.format('%s %s', hash, full_path), vim.trim(trust)) + + eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]])) + trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + eq('', vim.trim(trust)) + end) + + it('trust returns error when buffer not associated to file', function() + command('new') + eq({false, 'buffer is not associated with a file'}, + exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + end) + end) end) -- cgit From bf0665b3f320cd183bd1f960cc8501fca60ced9e Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Mon, 28 Nov 2022 18:41:20 +0100 Subject: vim-patch:9.0.0964: status line not redrawn when 'splitkeep' is "screen" Problem: Status line of other window not redrawn when dragging it when 'splitkeep' is set to "screen". Solution: Set w_redr_status earlier. (Luuk van Baal, closes vim/vim#11635, closes vim/vim#11632) https://github.com/vim/vim/commit/74a694dbe20bb7dea4e06f474cf62e20f9c92f1d Co-authored-by: Luuk van Baal --- test/functional/legacy/window_cmd_spec.lua | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/legacy/window_cmd_spec.lua b/test/functional/legacy/window_cmd_spec.lua index 8b89c55f5b..0e9775060d 100644 --- a/test/functional/legacy/window_cmd_spec.lua +++ b/test/functional/legacy/window_cmd_spec.lua @@ -6,9 +6,11 @@ local exec_lua = helpers.exec_lua local feed = helpers.feed describe('splitkeep', function() - local screen = Screen.new() + local screen + before_each(function() clear('--cmd', 'set splitkeep=screen') + screen = Screen.new() screen:attach() end) @@ -193,4 +195,33 @@ describe('splitkeep', function() :quit | ]]) end) + + -- oldtest: Test_splitkeep_status() + it('does not scroll when split in callback', function() + exec([[ + call setline(1, ['a', 'b', 'c']) + set nomodified + set splitkeep=screen + let win = winnr() + wincmd s + wincmd j + ]]) + feed(':call win_move_statusline(win, 1)') + screen:expect([[ + a | + b | + c | + ~ | + ~ | + ~ | + ~ | + [No Name] | + ^a | + b | + c | + ~ | + [No Name] | + | + ]]) + end) end) -- cgit From 80b6edabe3e4203ee4bf50261af07a6a0495ef36 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Mon, 28 Nov 2022 15:40:50 -0700 Subject: refactor: rework parameter validation in vim.secure.trust() (#21223) --- test/functional/lua/secure_spec.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua index 46ca2bba8f..6885253998 100644 --- a/test/functional/lua/secure_spec.lua +++ b/test/functional/lua/secure_spec.lua @@ -12,6 +12,7 @@ local feed_command = helpers.feed_command local feed = helpers.feed local funcs = helpers.funcs local pcall_err = helpers.pcall_err +local matches = helpers.matches describe('vim.secure', function() describe('read()', function() @@ -189,10 +190,15 @@ describe('vim.secure', function() end) it('returns error when passing both path and bufnr', function() - eq('path and bufnr are mutually exclusive', + matches('"path" and "bufnr" are mutually exclusive', pcall_err(exec_lua, [[vim.secure.trust({action='deny', bufnr=0, path='test_file'})]])) end) + it('returns error when passing neither path or bufnr', function() + matches('one of "path" or "bufnr" is required', + pcall_err(exec_lua, [[vim.secure.trust({action='deny'})]])) + end) + it('trust then deny then remove a file using bufnr', function() local cwd = funcs.getcwd() local hash = funcs.sha256(helpers.read_file('test_file')) -- cgit From 0badfaa6d0a86904f67e1343e839c2f7966e4716 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 29 Nov 2022 08:56:41 +0800 Subject: test: adding/removing winbar should not cause win_pos events (#21226) --- test/functional/ui/multigrid_spec.lua | 89 +++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/multigrid_spec.lua b/test/functional/ui/multigrid_spec.lua index 78a1e8c677..71adeb42a4 100644 --- a/test/functional/ui/multigrid_spec.lua +++ b/test/functional/ui/multigrid_spec.lua @@ -2381,8 +2381,52 @@ describe('ext_multigrid', function() end) it('with winbar', function() - command 'split' - command 'setlocal winbar=very\\ bar' + command('split') + screen:expect{grid=[[ + ## grid 1 + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + {11:[No Name] }| + [2:-----------------------------------------------------]| + [2:-----------------------------------------------------]| + [2:-----------------------------------------------------]| + [2:-----------------------------------------------------]| + [2:-----------------------------------------------------]| + {12:[No Name] }| + [3:-----------------------------------------------------]| + ## grid 2 + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + | + ## grid 4 + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]], win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + + -- XXX: hack to get notifications. Could use next_msg() also. + local orig_handle_win_pos = screen._handle_win_pos + local win_pos = {} + function screen._handle_win_pos(self, grid, win, startrow, startcol, width, height) + table.insert(win_pos, {grid, win, startrow, startcol, width, height}) + orig_handle_win_pos(self, grid, win, startrow, startcol, width, height) + end + + command('setlocal winbar=very%=bar') screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]| @@ -2408,7 +2452,7 @@ describe('ext_multigrid', function() ## grid 3 | ## grid 4 - {7:very bar }| + {7:very bar}| ^ | {1:~ }| {1:~ }| @@ -2418,6 +2462,45 @@ describe('ext_multigrid', function() [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; }} + eq({}, win_pos) + + command('setlocal winbar=') + screen:expect{grid=[[ + ## grid 1 + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + [4:-----------------------------------------------------]| + {11:[No Name] }| + [2:-----------------------------------------------------]| + [2:-----------------------------------------------------]| + [2:-----------------------------------------------------]| + [2:-----------------------------------------------------]| + [2:-----------------------------------------------------]| + {12:[No Name] }| + [3:-----------------------------------------------------]| + ## grid 2 + | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + | + ## grid 4 + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]], win_viewport={ + [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + [4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; + }} + eq({}, win_pos) end) it('with winbar dragging statusline with mouse works correctly', function() -- cgit From 615f124003376c007442319b31a172360796974c Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 29 Nov 2022 02:45:48 +0100 Subject: docs: fix typos (#21196) Co-authored-by: zeertzjq Co-authored-by: Raphael Co-authored-by: Gregory Anders --- test/functional/api/buffer_updates_spec.lua | 2 +- test/functional/api/proc_spec.lua | 10 +++++----- test/functional/api/vim_spec.lua | 2 +- test/functional/core/fileio_spec.lua | 2 +- test/functional/lua/vim_spec.lua | 18 +++++++++--------- test/functional/ui/cmdline_highlight_spec.lua | 12 ++++++------ 6 files changed, 23 insertions(+), 23 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 3d257e9477..d5f06c8f1f 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -810,7 +810,7 @@ describe('API: buffer events:', function() local newlines = args[5] -- Size of the contained nvim instance is 23 lines, this might change - -- with the test setup. Note updates are continguous. + -- with the test setup. Note updates are contiguous. assert(#newlines <= 23) for i = 1,#newlines do diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua index 3af1791e43..2028a8fba5 100644 --- a/test/functional/api/proc_spec.lua +++ b/test/functional/api/proc_spec.lua @@ -19,26 +19,26 @@ describe('API', function() -- Might be non-zero already (left-over from some other test?), -- but this is not what is tested here. - local initial_childs = request('nvim_get_proc_children', this_pid) + local initial_children = request('nvim_get_proc_children', this_pid) local job1 = funcs.jobstart(nvim_argv) retry(nil, nil, function() - eq(#initial_childs + 1, #request('nvim_get_proc_children', this_pid)) + eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid)) end) local job2 = funcs.jobstart(nvim_argv) retry(nil, nil, function() - eq(#initial_childs + 2, #request('nvim_get_proc_children', this_pid)) + eq(#initial_children + 2, #request('nvim_get_proc_children', this_pid)) end) funcs.jobstop(job1) retry(nil, nil, function() - eq(#initial_childs + 1, #request('nvim_get_proc_children', this_pid)) + eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid)) end) funcs.jobstop(job2) retry(nil, nil, function() - eq(#initial_childs, #request('nvim_get_proc_children', this_pid)) + eq(#initial_children, #request('nvim_get_proc_children', this_pid)) end) end) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 3e1aab28ce..5677990525 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3042,7 +3042,7 @@ describe('API', function() meths.buf_set_mark(buf, 'F', 2, 2, {}) meths.buf_set_name(buf, "mybuf") local mark = meths.get_mark('F', {}) - -- Compare the path tail ony + -- Compare the path tail only assert(string.find(mark[4], "mybuf$")) eq({2, 2, buf.id, mark[4]}, mark) end) diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 51189b7c32..ed37032f25 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -153,7 +153,7 @@ describe('fileio', function() end) - it('backup symlinked files in first avialable backupdir #11349', function() + it('backup symlinked files in first available backupdir #11349', function() skip(is_ci('cirrus')) clear() diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 21f2c19fbb..4266d30e73 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -160,25 +160,25 @@ describe('lua stdlib', function() it("vim.str_utfindex/str_byteindex", function() exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ\000ъ"]]) - local indicies32 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,29,33,34,35,37,38,40,42,44,46,48,49,51} - local indicies16 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,28,29,33,33,34,35,37,38,40,42,44,46,48,49,51} - for i,k in pairs(indicies32) do + local indices32 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,29,33,34,35,37,38,40,42,44,46,48,49,51} + local indices16 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,28,29,33,33,34,35,37,38,40,42,44,46,48,49,51} + for i,k in pairs(indices32) do eq(k, exec_lua("return vim.str_byteindex(_G.test_text, ...)", i), i) end - for i,k in pairs(indicies16) do + for i,k in pairs(indices16) do eq(k, exec_lua("return vim.str_byteindex(_G.test_text, ..., true)", i), i) end - eq("index out of range", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ...)", #indicies32 + 1)) - eq("index out of range", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ..., true)", #indicies16 + 1)) + eq("index out of range", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ...)", #indices32 + 1)) + eq("index out of range", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ..., true)", #indices16 + 1)) local i32, i16 = 0, 0 local len = 51 for k = 0,len do - if indicies32[i32] < k then + if indices32[i32] < k then i32 = i32 + 1 end - if indicies16[i16] < k then + if indices16[i16] < k then i16 = i16 + 1 - if indicies16[i16+1] == indicies16[i16] then + if indices16[i16+1] == indices16[i16] then i16 = i16 + 1 end end diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index fa5771a8b3..33e375760e 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -61,7 +61,7 @@ before_each(function() endwhile return ret endfunction - function SplittedMultibyteStart(cmdline) + function SplitMultibyteStart(cmdline) let ret = [] let i = 0 while i < len(a:cmdline) @@ -77,7 +77,7 @@ before_each(function() endwhile return ret endfunction - function SplittedMultibyteEnd(cmdline) + function SplitMultibyteEnd(cmdline) let ret = [] let i = 0 while i < len(a:cmdline) @@ -296,7 +296,7 @@ describe('Command-line coloring', function() end it('does the right thing when hl start appears to split multibyte char', function() - set_color_cb('SplittedMultibyteStart') + set_color_cb('SplitMultibyteStart') start_prompt('echo "«') screen:expect{grid=[[ | @@ -322,7 +322,7 @@ describe('Command-line coloring', function() end) it('does the right thing when hl end appears to split multibyte char', function() - set_color_cb('SplittedMultibyteEnd') + set_color_cb('SplitMultibyteEnd') start_prompt('echo "«') screen:expect([[ | @@ -409,7 +409,7 @@ describe('Command-line coloring', function() ]]) end) it('stops executing callback after a number of errors', function() - set_color_cb('SplittedMultibyteStart') + set_color_cb('SplitMultibyteStart') start_prompt('let x = "«»«»«»«»«»"') screen:expect([[ | @@ -772,7 +772,7 @@ describe('Ex commands coloring', function() ]]) end) it('still executes command-line even if errored out', function() - meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') + meths.set_var('Nvim_color_cmdline', 'SplitMultibyteStart') feed(':let x = "«"\n') eq('«', meths.get_var('x')) local msg = 'E5405: Chunk 0 start 10 splits multibyte character' -- cgit From 65e8ed45de98bf93491c6740772f0a42834696ab Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 29 Nov 2022 10:17:57 +0800 Subject: vim-patch:9.0.0969: matchparen highlight is not updated when switching buffers (#21227) Problem: Matchparen highlight is not updated when switching buffers. Solution: Listen to the BufLeave and the BufWinEnter autocmd events. (closes vim/vim#11626) https://github.com/vim/vim/commit/28a896f54d4b2f2b4bef8ef4144dde1673c9d6e7 Co-authored-by: Bram Moolenaar --- test/functional/editor/completion_spec.lua | 3 +- test/functional/legacy/display_spec.lua | 45 +++++++++++++++++++++++++++++ test/functional/legacy/source_spec.lua | 1 + test/functional/legacy/visual_mode_spec.lua | 25 +++++++--------- test/functional/ui/spell_spec.lua | 1 + 5 files changed, 60 insertions(+), 15 deletions(-) (limited to 'test/functional') diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 1b9899174b..c503d7ebfb 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -1029,7 +1029,8 @@ describe('completion', function() ]]) end) - it('TextChangedP autocommand', function() + -- oldtest: Test_ChangedP() + it('TextChangedI and TextChangedP autocommands', function() curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar'}) source([[ set complete=. completeopt=menuone diff --git a/test/functional/legacy/display_spec.lua b/test/functional/legacy/display_spec.lua index 9160129a02..f9b78f5dcd 100644 --- a/test/functional/legacy/display_spec.lua +++ b/test/functional/legacy/display_spec.lua @@ -58,6 +58,51 @@ describe('display', function() ]]) end) + -- oldtest: Test_matchparen_clear_highlight() + it('matchparen highlight is cleared when switching buffer', function() + local screen = Screen.new(20, 5) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, + [1] = {background = Screen.colors.Cyan}, + }) + screen:attach() + + local screen1 = [[ + {1:^()} | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]] + local screen2 = [[ + ^aa | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]] + + exec([[ + source $VIMRUNTIME/plugin/matchparen.vim + set hidden + call setline(1, ['()']) + normal 0 + ]]) + screen:expect(screen1) + + exec([[ + enew + exe "normal iaa\0" + ]]) + screen:expect(screen2) + + feed('') + screen:expect(screen1) + + feed('') + screen:expect(screen2) + end) + local function run_test_display_lastline(euro) local screen = Screen.new(75, 10) screen:set_default_attr_ids({ diff --git a/test/functional/legacy/source_spec.lua b/test/functional/legacy/source_spec.lua index 02e6385247..f31521607d 100644 --- a/test/functional/legacy/source_spec.lua +++ b/test/functional/legacy/source_spec.lua @@ -7,6 +7,7 @@ local write_file = helpers.write_file before_each(clear) describe(':source!', function() + -- oldtest: Test_nested_script() it('gives E22 when scripts nested too deep', function() write_file('Xscript.vim', [[ :source! Xscript.vim diff --git a/test/functional/legacy/visual_mode_spec.lua b/test/functional/legacy/visual_mode_spec.lua index 8b5dd0c2dc..1a08fb4c0e 100644 --- a/test/functional/legacy/visual_mode_spec.lua +++ b/test/functional/legacy/visual_mode_spec.lua @@ -1,31 +1,28 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local call = helpers.call local clear = helpers.clear local feed = helpers.feed -local feed_command = helpers.feed_command -local funcs = helpers.funcs -local meths = helpers.meths -local eq = helpers.eq local exec = helpers.exec -describe('visual line mode', function() - local screen +before_each(clear) +describe('visual line mode', function() + -- oldtest: Test_visual_block_scroll() it('redraws properly after scrolling with matchparen loaded and scrolloff=1', function() - clear{args={'-u', 'NORC'}} - screen = Screen.new(30, 7) + local screen = Screen.new(30, 7) screen:attach() screen:set_default_attr_ids({ [1] = {bold = true}, [2] = {background = Screen.colors.LightGrey}, }) - eq(1, meths.get_var('loaded_matchparen')) - feed_command('set scrolloff=1') - funcs.setline(1, {'a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'}) - call('cursor', 5, 1) + exec([[ + source $VIMRUNTIME/plugin/matchparen.vim + set scrolloff=1 + call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}']) + call cursor(5, 1) + ]]) feed('V') screen:expect([[ @@ -41,8 +38,8 @@ describe('visual line mode', function() end) describe('visual block mode', function() + -- oldtest: Test_visual_block_with_virtualedit() it('shows selection correctly with virtualedit=block', function() - clear() local screen = Screen.new(30, 7) screen:set_default_attr_ids({ [1] = {bold = true}, -- ModeMsg diff --git a/test/functional/ui/spell_spec.lua b/test/functional/ui/spell_spec.lua index 5b43edbad4..361f83d1ce 100644 --- a/test/functional/ui/spell_spec.lua +++ b/test/functional/ui/spell_spec.lua @@ -51,6 +51,7 @@ describe("'spell'", function() end) + -- oldtest: Test_spell_screendump() it('has correct highlight at start of line', function() insert([[ "This is some text without any spell errors. Everything", -- cgit From 61e99217e68498e757b9f8b0c70978a9635ccbfa Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 1 Dec 2022 09:15:05 -0600 Subject: refactor(fs): replace vim.fn/vim.env in vim.fs (#20379) Avoid using vim.env and vim.fn in vim.fs functions so that they can be used in "fast" contexts. --- test/functional/lua/fs_spec.lua | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index fc228e54bc..88ad6ba24a 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -12,6 +12,39 @@ local is_os = helpers.is_os local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim' +local test_basename_dirname_eq = { + '~/foo/', + '~/foo', + '~/foo/bar.lua', + 'foo.lua', + ' ', + '', + '.', + '..', + '../', + '~', + '/usr/bin', + '/usr/bin/gcc', + '/', + '/usr/', + '/usr', + 'c:/usr', + 'c:/', + 'c:', + 'c:/users/foo', + 'c:/users/foo/bar.lua', + 'c:/users/foo/bar/../', +} + +local tests_windows_paths = { + 'c:\\usr', + 'c:\\', + 'c:', + 'c:\\users\\foo', + 'c:\\users\\foo\\bar.lua', + 'c:\\users\\foo\\bar\\..\\', +} + before_each(clear) describe('vim.fs', function() @@ -41,15 +74,58 @@ describe('vim.fs', function() local nvim_dir = ... return vim.fs.dirname(nvim_dir) ]], nvim_dir)) + + local function test_paths(paths) + for _, path in ipairs(paths) do + eq( + exec_lua([[ + local path = ... + return vim.fn.fnamemodify(path,':h'):gsub('\\', '/') + ]], path), + exec_lua([[ + local path = ... + return vim.fs.dirname(path) + ]], path), + path + ) + end + end + + test_paths(test_basename_dirname_eq) + if is_os('win') then + test_paths(tests_windows_paths) + end end) end) describe('basename()', function() it('works', function() + eq(nvim_prog_basename, exec_lua([[ local nvim_prog = ... return vim.fs.basename(nvim_prog) ]], nvim_prog)) + + local function test_paths(paths) + for _, path in ipairs(paths) do + eq( + exec_lua([[ + local path = ... + return vim.fn.fnamemodify(path,':t'):gsub('\\', '/') + ]], path), + exec_lua([[ + local path = ... + return vim.fs.basename(path) + ]], path), + path + ) + end + end + + test_paths(test_basename_dirname_eq) + if is_os('win') then + test_paths(tests_windows_paths) + end end) end) -- cgit From 982c0053f4059fb4558ce83a0b8d250be1058980 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 10:30:50 +0800 Subject: fix(float): make closing float in another tab return to correct window --- test/functional/api/window_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 48431ccfc7..774ec406a8 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -490,6 +490,8 @@ describe('API/win', function() it('closing current (float) window of another tabpage #15313', function() command('tabedit') + command('botright split') + local prevwin = curwin().id eq(2, eval('tabpagenr()')) local win = meths.open_win(0, true, { relative='editor', row=10, col=10, width=50, height=10 @@ -499,7 +501,7 @@ describe('API/win', function() eq(1, eval('tabpagenr()')) meths.win_close(win, false) - eq(1001, meths.tabpage_get_win(tab).id) + eq(prevwin, meths.tabpage_get_win(tab).id) assert_alive() end) end) -- cgit From 1145a9b2485a4e5072cffe28a958da983cd59e84 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 20:39:24 +0800 Subject: feat(aucmd_win): allow crazy things with hidden buffers (#21250) Problem: Crash when doing crazy things with hidden buffers. Solution: Dynamically allocate the list of autocommand windows. --- test/functional/lua/vim_spec.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 4266d30e73..c74e88f55d 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2679,6 +2679,46 @@ describe('lua stdlib', function() a.nvim_buf_call(a.nvim_create_buf(false, true), function() vim.cmd "redraw" end) ]] end) + + it('can be nested crazily with hidden buffers', function() + eq(true, exec_lua([[ + local function scratch_buf_call(fn) + local buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_option(buf, 'cindent', true) + return vim.api.nvim_buf_call(buf, function() + return vim.api.nvim_get_current_buf() == buf + and vim.api.nvim_buf_get_option(buf, 'cindent') + and fn() + end) and vim.api.nvim_buf_delete(buf, {}) == nil + end + + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return scratch_buf_call(function() + return true + end) + end) + end) + end) + end) + end) + end) + end) + end) + end) + end) + end) + ]])) + end) end) describe('vim.api.nvim_win_call', function() -- cgit From 46e4be0fd0002233bde613295607ce5eeb498567 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 09:09:00 +0800 Subject: vim-patch:8.2.2295: incsearch does not detect empty pattern properly Problem: Incsearch does not detect empty pattern properly. Solution: Return magic state when skipping over a pattern. (Christian Brabandt, closes vim/vim#7612, closes vim/vim#6420) https://github.com/vim/vim/commit/d93a7fc1a98a58f8101ee780d4735079ad99ae35 --- test/functional/legacy/search_spec.lua | 43 ++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua index 5a94fca794..3f1f85cf28 100644 --- a/test/functional/legacy/search_spec.lua +++ b/test/functional/legacy/search_spec.lua @@ -14,7 +14,7 @@ describe('search cmdline', function() before_each(function() clear() - command('set nohlsearch') + command('set nohlsearch inccommand=') screen = Screen.new(20, 3) screen:attach() screen:set_default_attr_ids({ @@ -472,8 +472,8 @@ describe('search cmdline', function() funcs.winsaveview()) end) + -- oldtest: Test_search_cmdline4(). it("CTRL-G with 'incsearch' and ? goes in the right direction", function() - -- oldtest: Test_search_cmdline4(). screen:try_resize(40, 4) command('enew!') funcs.setline(1, {' 1 the first', ' 2 the second', ' 3 the third'}) @@ -573,8 +573,8 @@ describe('search cmdline', function() ]]) end) + -- oldtest: Test_incsearch_sort_dump(). it('incsearch works with :sort', function() - -- oldtest: Test_incsearch_sort_dump(). screen:try_resize(20, 4) command('set incsearch hlsearch scrolloff=0') funcs.setline(1, {'another one 2', 'that one 3', 'the one 1'}) @@ -589,8 +589,8 @@ describe('search cmdline', function() feed('') end) + -- oldtest: Test_incsearch_vimgrep_dump(). it('incsearch works with :vimgrep family', function() - -- oldtest: Test_incsearch_vimgrep_dump(). screen:try_resize(30, 4) command('set incsearch hlsearch scrolloff=0') funcs.setline(1, {'another one 2', 'that one 3', 'the one 1'}) @@ -640,6 +640,41 @@ describe('search cmdline', function() ]]) feed('') end) + + -- oldtest: Test_incsearch_substitute_dump2() + it('detects empty pattern properly vim-patch:8.2.2295', function() + screen:try_resize(70, 6) + exec([[ + set incsearch hlsearch scrolloff=0 + for n in range(1, 4) + call setline(n, "foo " . n) + endfor + call setline(5, "abc|def") + 3 + ]]) + + feed([[:%s/\vabc|]]) + screen:expect([[ + foo 1 | + foo 2 | + foo 3 | + foo 4 | + abc|def | + :%s/\vabc|^ | + ]]) + feed('') + + -- The following should not be highlighted + feed([[:1,5s/\v|]]) + screen:expect([[ + foo 1 | + foo 2 | + foo 3 | + foo 4 | + abc|def | + :1,5s/\v|^ | + ]]) + end) end) describe('Search highlight', function() -- cgit From 48b84d6d6e795d4c4b73ed1ed11967435f11267b Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Sun, 4 Dec 2022 15:39:22 +0100 Subject: refactor(lsp): extract a _create_server method in lsp_spec --- test/functional/plugin/lsp_spec.lua | 105 ++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 45 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 071791e702..90bd4290ed 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -47,6 +47,56 @@ local function clear_notrace() end +local create_server_definition = [[ + function _create_server(opts) + opts = opts or {} + local server = {} + server.messages = {} + + function server.cmd(dispatchers) + local closing = false + local handlers = opts.handlers or {} + local srv = {} + + function srv.request(method, params, callback) + table.insert(server.messages, { + method = method, + params = params, + }) + local handler = handlers[method] + if handler then + local response = handler(method, params) + if response then + callback(nill, response) + end + elseif method == 'initialize' then + callback(nil, { + capabilities = opts.capabilities or {} + }) + elseif method == 'shutdown' then + callback(nil, nil) + end + end + + function srv.notify(method, params) + end + + function srv.is_closing() + return closing + end + + function srv.terminate() + closing = true + end + + return srv + end + + return server + end +]] + + local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) exec_lua([=[ lsp = require('vim.lsp') @@ -422,24 +472,12 @@ describe('LSP', function() it('should detach buffer on bufwipe', function() clear() + exec_lua(create_server_definition) local result = exec_lua([[ - local server = function(dispatchers) - local closing = false - return { - request = function(method, params, callback) - if method == 'initialize' then - callback(nil, { capabilities = {} }) - end - end, - notify = function(...) - end, - is_closing = function() return closing end, - terminate = function() closing = true end - } - end + local server = _create_server() local bufnr = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_current_buf(bufnr) - local client_id = vim.lsp.start({ name = 'detach-dummy', cmd = server }) + local client_id = vim.lsp.start({ name = 'detach-dummy', cmd = server.cmd }) assert(client_id, "lsp.start must return client_id") local client = vim.lsp.get_client_by_id(client_id) local num_attached_before = vim.tbl_count(client.attached_buffers) @@ -3436,44 +3474,21 @@ describe('LSP', function() } end) it('format formats range in visual mode', function() + exec_lua(create_server_definition) local result = exec_lua([[ - local messages = {} - local server = function(dispatchers) - local closing = false - return { - request = function(method, params, callback) - table.insert(messages, { - method = method, - params = params, - }) - if method == 'initialize' then - callback(nil, { - capabilities = { - documentFormattingProvider = true, - documentRangeFormattingProvider = true, - } - }) - end - end, - notify = function(...) - end, - is_closing = function() - return closing - end, - terminate = function() - closing = true - end - } - end + local server = _create_server({ capabilities = { + documentFormattingProvider = true, + documentRangeFormattingProvider = true, + }}) local bufnr = vim.api.nvim_get_current_buf() - local client_id = vim.lsp.start({ name = 'dummy', cmd = server }) + local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) vim.api.nvim_win_set_buf(0, bufnr) vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, {'foo', 'bar'}) vim.api.nvim_win_set_cursor(0, { 1, 0 }) vim.cmd.normal('v') vim.api.nvim_win_set_cursor(0, { 2, 3 }) vim.lsp.buf.format({ bufnr = bufnr, false }) - return messages + return server.messages ]]) eq("textDocument/rangeFormatting", result[2].method) local expected_range = { -- cgit From 67e1390dc8eb584d26ae9c9634c05acb3b7e37ca Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Sun, 4 Dec 2022 15:57:46 +0100 Subject: fix(lsp): call show_document with correct args Closes https://github.com/neovim/neovim/issues/21177 --- test/functional/plugin/lsp_spec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 90bd4290ed..79c83af5d9 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2689,6 +2689,33 @@ describe('LSP', function() eq(10, pos.col) end) + it('jumps to a Location if focus is true via handler', function() + exec_lua(create_server_definition) + local result = exec_lua([[ + local server = _create_server() + local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + local result = { + uri = 'file:///fake/uri', + selection = { + start = { line = 0, character = 9 }, + ['end'] = { line = 0, character = 9 } + }, + takeFocus = true, + } + local ctx = { + client_id = client_id, + method = 'window/showDocument', + } + vim.lsp.handlers['window/showDocument'](nil, result, ctx) + vim.lsp.stop_client(client_id) + return { + cursor = vim.api.nvim_win_get_cursor(0) + } + ]]) + eq(1, result.cursor[1]) + eq(9, result.cursor[2]) + end) + it('jumps to a Location if focus not set', function() local pos = show_document(location(0, 9, 0, 9), nil, true) eq(1, pos.line) -- cgit From f3bf1fbf600050fde155e6a1a766b6f848012208 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Mon, 5 Dec 2022 19:59:04 +0100 Subject: fix(secure): crash when hitting escape in prompt (#21283) - use pcall when calling vim.secure.read from C - catch keyboard interrupts in vim.secure.read, rethrow other errors - selecting "view" in prompt runs :view command - simplify lua stack cleanup with lua_gettop and lua_settop Co-authored-by: ii14 --- test/functional/lua/secure_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua index 6885253998..2647b2be46 100644 --- a/test/functional/lua/secure_spec.lua +++ b/test/functional/lua/secure_spec.lua @@ -150,10 +150,10 @@ describe('vim.secure', function() ]]} feed('v') screen:expect{grid=[[ - ^ let g:foobar = 42 | + ^let g:foobar = 42 | {1:~ }| {1:~ }| - {2:]] .. cwd .. pathsep .. [[Xfile [RO]{MATCH:%s+}| + {2:]] .. funcs.fnamemodify(cwd, ':~') .. pathsep .. [[Xfile [RO]{MATCH:%s+}| | {1:~ }| {4:[No Name] }| @@ -166,7 +166,7 @@ describe('vim.secure', function() -- Cannot write file pcall_err(command, 'write') - eq(false, curbufmeths.get_option('modifiable')) + eq(true, curbufmeths.get_option('readonly')) end) end) -- cgit From ad244a865be5332471ec07875603c3dd4a7af0ae Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Dec 2022 08:57:29 +0800 Subject: fix(events): save v:event for cmdline autocommands separately (#21316) --- test/functional/autocmd/cmdline_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional') diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua index 8ec06dc148..c96501ead4 100644 --- a/test/functional/autocmd/cmdline_spec.lua +++ b/test/functional/autocmd/cmdline_spec.lua @@ -185,6 +185,14 @@ describe('cmdline autocommands', function() eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg()) end) + it('no crash with recursive use of v:event #19484', function() + command('autocmd CmdlineEnter * normal :') + feed(':') + eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + feed('') + eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) + end) + it('supports CmdlineChanged' ,function() command("autocmd CmdlineChanged * call rpcnotify(g:channel, 'CmdlineChanged', v:event, getcmdline())") feed(':') -- cgit From eab71e7875782144ca6c62269fc6f333bc061001 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Dec 2022 10:18:12 +0800 Subject: test: add more tests for float window bufpos (#21318) --- test/functional/ui/float_spec.lua | 109 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index bc05d9081d..dbf31ad753 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -727,6 +727,7 @@ describe('float window', function() [25] = {blend = 100, background = Screen.colors.Gray0}; [26] = {blend = 80, background = Screen.colors.Gray0}; [27] = {background = Screen.colors.LightGray}; + [28] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGray}; } screen:set_default_attr_ids(attrs) end) @@ -3068,6 +3069,66 @@ describe('float window', function() ]]} end + command('set laststatus=0') + command('botright vnew') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----]{5:│}[6:--------------------]| + [2:----]{5:│}[6:--------------------]| + [2:----]{5:│}[6:--------------------]| + [2:----]{5:│}[6:--------------------]| + [2:----]{5:│}[6:--------------------]| + [2:----]{5:│}[6:--------------------]| + [2:----]{5:│}[6:--------------------]| + [2:----]{5:│}[6:--------------------]| + [2:----]{5:│}[6:--------------------]| + [3:-------------------------]| + ## grid 2 + exam| + ple | + text| + tha| + t is| + wid| + er t| + han | + the | + ## grid 3 + | + ## grid 5 + {1:some info! }| + ## grid 6 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ]], float_pos={ + [5] = { { + id = 1002 + }, "SW", 2, 8, 0, true } + }} + else + screen:expect{grid=[[ + exam{5:│}^ | + ple {5:│}{0:~ }| + text{5:│}{0:~ }| + tha{5:│}{0:~ }| + t is{5:│}{0:~ }| + wid{5:│}{0:~ }| + er t{5:│}{0:~ }| + {1:some info! }{0: }| + the {5:│}{0:~ }| + | + ]]} + end + command('close') + meths.win_set_config(win, {relative='win', bufpos={1,32}, anchor='NW', col=-2}) if multigrid then screen:expect{grid=[[ @@ -3163,6 +3224,54 @@ describe('float window', function() | ]]} end + + command('%fold') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [3:-------------------------]| + ## grid 2 + {28:^+-- 5 lines: just some··}| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 5 + {1:some info! }| + ]], float_pos={ + [5] = { { + id = 1002 + }, "NW", 2, 2, 0, true } + }} + else + screen:expect{grid=[[ + {28:^+-- 5 lines: just some··}| + {0:~ }| + {1:some info! }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + end end) it('validates cursor even when window is not entered', function() -- cgit From ed23cd3e50e778604e45e85bc939271a7759ca1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Dec 2022 11:36:34 +0800 Subject: fix(float): fix crash with bufpos and non-existent window (#21319) --- test/functional/ui/float_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index dbf31ad753..bb09cfd504 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -391,6 +391,15 @@ describe('float window', function() eq(winids, eval('winids')) end) + it('no crash with bufpos and non-existent window', function() + command('new') + local closed_win = meths.get_current_win().id + command('close') + local buf = meths.create_buf(false,false) + meths.open_win(buf, true, {relative='win', win=closed_win, width=1, height=1, bufpos={0,0}}) + assert_alive() + end) + it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function() local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1} local float_win = meths.open_win(0, true, float_opts) -- cgit From f92aab5f704f6e94e80f2fcbab42acc272a66a29 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Dec 2022 18:34:39 +0800 Subject: vim-patch:9.0.1025: WinScrolled is not triggered when filler lines change (#21325) Problem: WinScrolled is not triggered when filler lines change. Solution: Add "topfill" to the values that WinScrolled triggers on. (closes vim/vim#11668) https://github.com/vim/vim/commit/3fc84dc2c7efecd7c14ce341cd777475058936fd Cherry-pick StopVimInTerminal() from patch 9.0.1010. --- .../autocmd/win_scrolled_resized_spec.lua | 100 ++++++++++++++------- 1 file changed, 70 insertions(+), 30 deletions(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua index bebb21bc31..4a2e27931a 100644 --- a/test/functional/autocmd/win_scrolled_resized_spec.lua +++ b/test/functional/autocmd/win_scrolled_resized_spec.lua @@ -70,15 +70,15 @@ describe('WinScrolled', function() feed('') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) feed('') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = -1, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) end) @@ -93,15 +93,15 @@ describe('WinScrolled', function() feed('zl') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) feed('zh') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = -1, topline = 0, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) end) @@ -115,29 +115,29 @@ describe('WinScrolled', function() feed('zl') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) feed('zl') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) feed('h') eq(3, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = -1, topline = 0, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) feed('zh') eq(4, eval('g:scrolled')) eq({ - all = {leftcol = 1, topline = 0, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = -1, topline = 0, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) end) @@ -152,15 +152,15 @@ describe('WinScrolled', function() feed('gj') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 0, width = 0, height = 0, skipcol = width}, - ['1000'] = {leftcol = 0, topline = 0, width = 0, height = 0, skipcol = width}, + all = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width}, + ['1000'] = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width}, }, eval('g:v_event')) feed('0') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 0, width = 0, height = 0, skipcol = width}, - ['1000'] = {leftcol = 0, topline = 0, width = 0, height = 0, skipcol = -width}, + all = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width}, + ['1000'] = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = -width}, }, eval('g:v_event')) feed('$') @@ -181,15 +181,15 @@ describe('WinScrolled', function() feed('i') eq(1, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) feed('i') eq(2, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = -1, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) feed('L') @@ -198,8 +198,8 @@ describe('WinScrolled', function() feed('A') eq(3, eval('g:scrolled')) eq({ - all = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, - ['1000'] = {leftcol = 0, topline = 1, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) end) end) @@ -244,6 +244,46 @@ describe('WinScrolled', function() assert_alive() end) + -- oldtest: Test_WinScrolled_diff() + it('is triggered for both windows when scrolling in diff mode', function() + exec([[ + set diffopt+=foldcolumn:0 + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + vnew + call setline(1, ['d', 'e', 'f', 'g', 'h', 'i']) + windo diffthis + au WinScrolled * let g:v_event = deepcopy(v:event) + ]]) + + feed('') + eq({ + all = {leftcol = 0, topline = 1, topfill = 1, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1001'] = {leftcol = 0, topline = 0, topfill = -1, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('2') + eq({ + all = {leftcol = 0, topline = 2, topfill = 2, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1001'] = {leftcol = 0, topline = 0, topfill = -2, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('') + eq({ + all = {leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1001'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + + feed('2') + eq({ + all = {leftcol = 0, topline = 3, topfill = 1, width = 0, height = 0, skipcol = 0}, + ['1000'] = {leftcol = 0, topline = -2, topfill = 0, width = 0, height = 0, skipcol = 0}, + ['1001'] = {leftcol = 0, topline = -1, topfill = 1, width = 0, height = 0, skipcol = 0}, + }, eval('g:v_event')) + end) + it('is triggered by mouse scrolling in unfocused floating window #18222', function() local screen = Screen.new(80, 24) screen:attach() @@ -270,16 +310,16 @@ describe('WinScrolled', function() eq(1, eval('g:scrolled')) eq(winid_str, eval('g:amatch')) eq({ - all = {leftcol = 0, topline = 3, width = 0, height = 0, skipcol = 0}, - [winid_str] = {leftcol = 0, topline = 3, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0}, + [winid_str] = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) meths.input_mouse('wheel', 'up', '', 0, 3, 3) eq(2, eval('g:scrolled')) eq(tostring(win.id), eval('g:amatch')) eq({ - all = {leftcol = 0, topline = 3, width = 0, height = 0, skipcol = 0}, - [winid_str] = {leftcol = 0, topline = -3, width = 0, height = 0, skipcol = 0}, + all = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0}, + [winid_str] = {leftcol = 0, topline = -3, topfill = 0, width = 0, height = 0, skipcol = 0}, }, eval('g:v_event')) end) end) -- cgit From 54305443b9cd5ac2c2220f12e01a653e8064c3a4 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Thu, 8 Dec 2022 10:55:01 +0100 Subject: feat(lsp): support willSave & willSaveWaitUntil capability (#21315) `willSaveWaitUntil` allows servers to respond with text edits before saving a document. That is used by some language servers to format a document or apply quick fixes like removing unused imports. --- test/functional/plugin/lsp_spec.lua | 78 +++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 79c83af5d9..f38a7ad044 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -65,9 +65,9 @@ local create_server_definition = [[ }) local handler = handlers[method] if handler then - local response = handler(method, params) + local response, err = handler(params) if response then - callback(nill, response) + callback(err, response) end elseif method == 'initialize' then callback(nil, { @@ -76,9 +76,18 @@ local create_server_definition = [[ elseif method == 'shutdown' then callback(nil, nil) end + local request_id = #server.messages + return true, request_id end function srv.notify(method, params) + table.insert(server.messages, { + method = method, + params = params + }) + if method == 'exit' then + dispatchers.on_exit(0, 15) + end end function srv.is_closing() @@ -612,6 +621,67 @@ describe('LSP', function() } end) + it('BufWritePre does not send notifications if server lacks willSave capabilities', function() + exec_lua(create_server_definition) + local messages = exec_lua([[ + local server = _create_server({ + capabilities = { + textDocumentSync = { + willSave = false, + willSaveWaitUntil = false, + } + }, + }) + local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + local buf = vim.api.nvim_get_current_buf() + vim.api.nvim_exec_autocmds('BufWritePre', { buffer = buf, modeline = false }) + vim.lsp.stop_client(client_id) + return server.messages + ]]) + eq(#messages, 4) + eq(messages[1].method, 'initialize') + eq(messages[2].method, 'initialized') + eq(messages[3].method, 'shutdown') + eq(messages[4].method, 'exit') + end) + it('BufWritePre sends willSave / willSaveWaitUntil, applies textEdits', function() + exec_lua(create_server_definition) + local result = exec_lua([[ + local server = _create_server({ + capabilities = { + textDocumentSync = { + willSave = true, + willSaveWaitUntil = true, + } + }, + handlers = { + ['textDocument/willSaveWaitUntil'] = function() + local text_edit = { + range = { + start = { line = 0, character = 0 }, + ['end'] = { line = 0, character = 0 }, + }, + newText = 'Hello' + } + return { text_edit, } + end + }, + }) + local buf = vim.api.nvim_get_current_buf() + local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + vim.api.nvim_exec_autocmds('BufWritePre', { buffer = buf, modeline = false }) + vim.lsp.stop_client(client_id) + return { + messages = server.messages, + lines = vim.api.nvim_buf_get_lines(buf, 0, -1, true) + } + ]]) + local messages = result.messages + eq('textDocument/willSave', messages[3].method) + eq('textDocument/willSaveWaitUntil', messages[4].method) + eq({'Hello'}, result.lines) + end) + it('saveas sends didOpen if filename changed', function() local expected_handlers = { { NIL, {}, { method = 'shutdown', client_id = 1 } }, @@ -3517,12 +3587,12 @@ describe('LSP', function() vim.lsp.buf.format({ bufnr = bufnr, false }) return server.messages ]]) - eq("textDocument/rangeFormatting", result[2].method) + eq("textDocument/rangeFormatting", result[3].method) local expected_range = { start = { line = 0, character = 0 }, ['end'] = { line = 1, character = 4 }, } - eq(expected_range, result[2].params.range) + eq(expected_range, result[3].params.range) end) end) describe('cmd', function() -- cgit From e2c5b21e18475f87f4d73eaa471662ce5659d4bd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 8 Dec 2022 19:22:40 +0800 Subject: test(lsp): call clear() before willSave tests (#21336) Otherwise these two tests cannot run alone and may fail on CI. --- test/functional/plugin/lsp_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index f38a7ad044..163667d5f3 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -622,6 +622,7 @@ describe('LSP', function() end) it('BufWritePre does not send notifications if server lacks willSave capabilities', function() + clear() exec_lua(create_server_definition) local messages = exec_lua([[ local server = _create_server({ @@ -644,7 +645,9 @@ describe('LSP', function() eq(messages[3].method, 'shutdown') eq(messages[4].method, 'exit') end) + it('BufWritePre sends willSave / willSaveWaitUntil, applies textEdits', function() + clear() exec_lua(create_server_definition) local result = exec_lua([[ local server = _create_server({ -- cgit From 5e0c74cd82ce75510b15e63a1b0b51cf70cdf47f Mon Sep 17 00:00:00 2001 From: John Drouhard Date: Thu, 8 Dec 2022 08:54:19 -0600 Subject: refactor(test): create an lsp-specific helpers.lua file * move the code for creating fake rpc servers there --- test/functional/plugin/lsp/helpers.lua | 178 ++++++++++++++++++++++++++++++++ test/functional/plugin/lsp_spec.lua | 181 ++------------------------------- 2 files changed, 186 insertions(+), 173 deletions(-) create mode 100644 test/functional/plugin/lsp/helpers.lua (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua new file mode 100644 index 0000000000..41b4db75cf --- /dev/null +++ b/test/functional/plugin/lsp/helpers.lua @@ -0,0 +1,178 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local exec_lua = helpers.exec_lua +local run = helpers.run +local stop = helpers.stop +local NIL = helpers.NIL + +local M = {} + +function M.clear_notrace() + -- problem: here be dragons + -- solution: don't look too closely for dragons + clear {env={ + NVIM_LUA_NOTRACK="1"; + VIMRUNTIME=os.getenv"VIMRUNTIME"; + }} +end + +M.create_server_definition = [[ + function _create_server(opts) + opts = opts or {} + local server = {} + server.messages = {} + + function server.cmd(dispatchers) + local closing = false + local handlers = opts.handlers or {} + local srv = {} + + function srv.request(method, params, callback) + table.insert(server.messages, { + method = method, + params = params, + }) + local handler = handlers[method] + if handler then + local response, err = handler(method, params) + if response then + callback(err, response) + end + elseif method == 'initialize' then + callback(nil, { + capabilities = opts.capabilities or {} + }) + elseif method == 'shutdown' then + callback(nil, nil) + end + local request_id = #server.messages + return true, request_id + end + + function srv.notify(method, params) + table.insert(server.messages, { + method = method, + params = params + }) + if method == 'exit' then + dispatchers.on_exit(0, 15) + end + end + + function srv.is_closing() + return closing + end + + function srv.terminate() + closing = true + end + + return srv + end + + return server + end +]] + +-- Fake LSP server. +M.fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' +M.fake_lsp_logfile = 'Xtest-fake-lsp.log' + +local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) + exec_lua([=[ + lsp = require('vim.lsp') + local test_name, fixture_filename, logfile, timeout, options, settings = ... + TEST_RPC_CLIENT_ID = lsp.start_client { + cmd_env = { + NVIM_LOG_FILE = logfile; + NVIM_LUA_NOTRACK = "1"; + }; + cmd = { + vim.v.progpath, '-Es', '-u', 'NONE', '--headless', + "-c", string.format("lua TEST_NAME = %q", test_name), + "-c", string.format("lua TIMEOUT = %d", timeout), + "-c", "luafile "..fixture_filename, + }; + handlers = setmetatable({}, { + __index = function(t, method) + return function(...) + return vim.rpcrequest(1, 'handler', ...) + end + end; + }); + workspace_folders = {{ + uri = 'file://' .. vim.loop.cwd(), + name = 'test_folder', + }}; + on_init = function(client, result) + TEST_RPC_CLIENT = client + vim.rpcrequest(1, "init", result) + end; + flags = { + allow_incremental_sync = options.allow_incremental_sync or false; + debounce_text_changes = options.debounce_text_changes or 0; + }; + settings = settings; + on_exit = function(...) + vim.rpcnotify(1, "exit", ...) + end; + } + ]=], test_name, M.fake_lsp_code, M.fake_lsp_logfile, timeout_ms or 1e3, options or {}, settings or {}) +end + +function M.test_rpc_server(config) + if config.test_name then + M.clear_notrace() + fake_lsp_server_setup(config.test_name, config.timeout_ms or 1e3, config.options, config.settings) + end + local client = setmetatable({}, { + __index = function(_, name) + -- Workaround for not being able to yield() inside __index for Lua 5.1 :( + -- Otherwise I would just return the value here. + return function(...) + return exec_lua([=[ + local name = ... + if type(TEST_RPC_CLIENT[name]) == 'function' then + return TEST_RPC_CLIENT[name](select(2, ...)) + else + return TEST_RPC_CLIENT[name] + end + ]=], name, ...) + end + end; + }) + local code, signal + local function on_request(method, args) + if method == "init" then + if config.on_init then + config.on_init(client, unpack(args)) + end + return NIL + end + if method == 'handler' then + if config.on_handler then + config.on_handler(unpack(args)) + end + end + return NIL + end + local function on_notify(method, args) + if method == 'exit' then + code, signal = unpack(args) + return stop() + end + end + -- TODO specify timeout? + -- run(on_request, on_notify, config.on_setup, 1000) + run(on_request, on_notify, config.on_setup) + if config.on_exit then + config.on_exit(code, signal) + end + stop() + if config.test_name then + exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") + end +end + +return M diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 163667d5f3..93fada8a50 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1,8 +1,9 @@ local helpers = require('test.functional.helpers')(after_each) +local lsp_helpers = require('test.functional.plugin.lsp.helpers') local assert_log = helpers.assert_log -local clear = helpers.clear local buf_lines = helpers.buf_lines +local clear = helpers.clear local command = helpers.command local dedent = helpers.dedent local exec_lua = helpers.exec_lua @@ -14,6 +15,7 @@ local pesc = helpers.pesc local insert = helpers.insert local funcs = helpers.funcs local retry = helpers.retry +local stop = helpers.stop local NIL = helpers.NIL local read_file = require('test.helpers').read_file local write_file = require('test.helpers').write_file @@ -22,186 +24,19 @@ local meths = helpers.meths local is_os = helpers.is_os local skip = helpers.skip --- Use these to get access to a coroutine so that I can run async tests and use --- yield. -local run, stop = helpers.run, helpers.stop +local clear_notrace = lsp_helpers.clear_notrace +local create_server_definition = lsp_helpers.create_server_definition +local fake_lsp_code = lsp_helpers.fake_lsp_code +local fake_lsp_logfile = lsp_helpers.fake_lsp_logfile +local test_rpc_server = lsp_helpers.test_rpc_server -- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837 if skip(is_os('win')) then return end --- Fake LSP server. -local fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' -local fake_lsp_logfile = 'Xtest-fake-lsp.log' - teardown(function() os.remove(fake_lsp_logfile) end) -local function clear_notrace() - -- problem: here be dragons - -- solution: don't look for dragons to closely - clear {env={ - NVIM_LUA_NOTRACK="1"; - VIMRUNTIME=os.getenv"VIMRUNTIME"; - }} -end - - -local create_server_definition = [[ - function _create_server(opts) - opts = opts or {} - local server = {} - server.messages = {} - - function server.cmd(dispatchers) - local closing = false - local handlers = opts.handlers or {} - local srv = {} - - function srv.request(method, params, callback) - table.insert(server.messages, { - method = method, - params = params, - }) - local handler = handlers[method] - if handler then - local response, err = handler(params) - if response then - callback(err, response) - end - elseif method == 'initialize' then - callback(nil, { - capabilities = opts.capabilities or {} - }) - elseif method == 'shutdown' then - callback(nil, nil) - end - local request_id = #server.messages - return true, request_id - end - - function srv.notify(method, params) - table.insert(server.messages, { - method = method, - params = params - }) - if method == 'exit' then - dispatchers.on_exit(0, 15) - end - end - - function srv.is_closing() - return closing - end - - function srv.terminate() - closing = true - end - - return srv - end - - return server - end -]] - - -local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) - exec_lua([=[ - lsp = require('vim.lsp') - local test_name, fixture_filename, logfile, timeout, options, settings = ... - TEST_RPC_CLIENT_ID = lsp.start_client { - cmd_env = { - NVIM_LOG_FILE = logfile; - NVIM_LUA_NOTRACK = "1"; - }; - cmd = { - vim.v.progpath, '-Es', '-u', 'NONE', '--headless', - "-c", string.format("lua TEST_NAME = %q", test_name), - "-c", string.format("lua TIMEOUT = %d", timeout), - "-c", "luafile "..fixture_filename, - }; - handlers = setmetatable({}, { - __index = function(t, method) - return function(...) - return vim.rpcrequest(1, 'handler', ...) - end - end; - }); - workspace_folders = {{ - uri = 'file://' .. vim.loop.cwd(), - name = 'test_folder', - }}; - on_init = function(client, result) - TEST_RPC_CLIENT = client - vim.rpcrequest(1, "init", result) - end; - flags = { - allow_incremental_sync = options.allow_incremental_sync or false; - debounce_text_changes = options.debounce_text_changes or 0; - }; - settings = settings; - on_exit = function(...) - vim.rpcnotify(1, "exit", ...) - end; - } - ]=], test_name, fake_lsp_code, fake_lsp_logfile, timeout_ms or 1e3, options or {}, settings or {}) -end - -local function test_rpc_server(config) - if config.test_name then - clear_notrace() - fake_lsp_server_setup(config.test_name, config.timeout_ms or 1e3, config.options, config.settings) - end - local client = setmetatable({}, { - __index = function(_, name) - -- Workaround for not being able to yield() inside __index for Lua 5.1 :( - -- Otherwise I would just return the value here. - return function(...) - return exec_lua([=[ - local name = ... - if type(TEST_RPC_CLIENT[name]) == 'function' then - return TEST_RPC_CLIENT[name](select(2, ...)) - else - return TEST_RPC_CLIENT[name] - end - ]=], name, ...) - end - end; - }) - local code, signal - local function on_request(method, args) - if method == "init" then - if config.on_init then - config.on_init(client, unpack(args)) - end - return NIL - end - if method == 'handler' then - if config.on_handler then - config.on_handler(unpack(args)) - end - end - return NIL - end - local function on_notify(method, args) - if method == 'exit' then - code, signal = unpack(args) - return stop() - end - end - -- TODO specify timeout? - -- run(on_request, on_notify, config.on_setup, 1000) - run(on_request, on_notify, config.on_setup) - if config.on_exit then - config.on_exit(code, signal) - end - stop() - if config.test_name then - exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") - end -end - describe('LSP', function() before_each(function() clear_notrace() -- cgit From 9f035559defd9d575f37fd825954610065d9cf96 Mon Sep 17 00:00:00 2001 From: John Drouhard Date: Wed, 23 Nov 2022 10:06:36 -0600 Subject: feat(lsp): initial support for semantic token highlighting * credit to @smolck and @theHamsta for their contributions in laying the groundwork for this feature and for their work on some of the helper utility functions and tests --- test/functional/plugin/lsp/helpers.lua | 2 +- .../functional/plugin/lsp/semantic_tokens_spec.lua | 910 +++++++++++++++++++++ 2 files changed, 911 insertions(+), 1 deletion(-) create mode 100644 test/functional/plugin/lsp/semantic_tokens_spec.lua (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index 41b4db75cf..1363ab894d 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -1,4 +1,4 @@ -local helpers = require('test.functional.helpers')(after_each) +local helpers = require('test.functional.helpers')(nil) local clear = helpers.clear local exec_lua = helpers.exec_lua diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua new file mode 100644 index 0000000000..1646108416 --- /dev/null +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -0,0 +1,910 @@ +local helpers = require('test.functional.helpers')(after_each) +local lsp_helpers = require('test.functional.plugin.lsp.helpers') +local Screen = require('test.functional.ui.screen') + +local command = helpers.command +local dedent = helpers.dedent +local eq = helpers.eq +local exec_lua = helpers.exec_lua +local feed = helpers.feed +local feed_command = helpers.feed_command +local insert = helpers.insert +local matches = helpers.matches + +local clear_notrace = lsp_helpers.clear_notrace +local create_server_definition = lsp_helpers.create_server_definition + +before_each(function() + clear_notrace() +end) + +after_each(function() + exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") +end) + +describe('semantic token highlighting', function() + + describe('general', function() + local text = dedent([[ + #include + + int main() + { + int x; + #ifdef __cplusplus + std::cout << x << "\n"; + #else + printf("%d\n", x); + #endif + } + }]]) + + local legend = [[{ + "tokenTypes": [ + "variable", "variable", "parameter", "function", "method", "function", "property", "variable", "class", "interface", "enum", "enumMember", "type", "type", "unknown", "namespace", "typeParameter", "concept", "type", "macro", "comment" + ], + "tokenModifiers": [ + "declaration", "deprecated", "deduced", "readonly", "static", "abstract", "virtual", "dependentName", "defaultLibrary", "usedAsMutableReference", "functionScope", "classScope", "fileScope", "globalScope" + ] + }]] + + local response = [[{ + "data": [ 2, 4, 4, 3, 8193, 2, 8, 1, 1, 1025, 1, 7, 11, 19, 8192, 1, 4, 3, 15, 8448, 0, 5, 4, 0, 8448, 0, 8, 1, 1, 1024, 1, 0, 5, 20, 0, 1, 0, 22, 20, 0, 1, 0, 6, 20, 0 ], + "resultId": 1 + }]] + + local edit_response = [[{ + "edits": [ {"data": [ 2, 8, 1, 3, 8193, 1, 7, 11, 19, 8192, 1, 4, 3, 15, 8448, 0, 5, 4, 0, 8448, 0, 8, 1, 3, 8192 ], "deleteCount": 25, "start": 5 } ], + "resultId":"2" + }]] + + local screen + before_each(function() + screen = Screen.new(40, 16) + screen:attach() + screen:set_default_attr_ids { + [1] = { bold = true, foreground = Screen.colors.Blue1 }; + [2] = { foreground = Screen.colors.DarkCyan }; + [3] = { foreground = Screen.colors.SlateBlue }; + [4] = { bold = true, foreground = Screen.colors.SeaGreen }; + [5] = { foreground = tonumber('0x6a0dad') }; + [6] = { foreground = Screen.colors.Blue1 }; + } + command([[ hi link @namespace Type ]]) + command([[ hi link @function Special ]]) + + exec_lua(create_server_definition) + exec_lua([[ + local legend, response, edit_response = ... + server = _create_server({ + capabilities = { + semanticTokensProvider = { + full = { delta = true }, + legend = vim.fn.json_decode(legend), + }, + }, + handlers = { + ['textDocument/semanticTokens/full'] = function() + return vim.fn.json_decode(response) + end, + ['textDocument/semanticTokens/full/delta'] = function() + return vim.fn.json_decode(edit_response) + end, + } + }) + ]], legend, response, edit_response) + end) + + it('buffer is highlighted when attached', function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + + insert(text) + + screen:expect { grid = [[ + #include | + | + int {3:main}() | + { | + int {2:x}; | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + end) + + it('buffer is unhighlighted when client is detached', function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + + insert(text) + + exec_lua([[ + vim.notify = function() end + vim.lsp.buf_detach_client(bufnr, client_id) + ]]) + + screen:expect { grid = [[ + #include | + | + int main() | + { | + int x; | + #ifdef __cplusplus | + std::cout << x << "\n"; | + #else | + printf("%d\n", x); | + #endif | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + end) + + it('buffer is highlighted and unhighlighted when semantic token highlighting is started and stopped' + , function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + + insert(text) + + exec_lua([[ + vim.notify = function() end + vim.lsp.semantic_tokens.stop(bufnr, client_id) + ]]) + + screen:expect { grid = [[ + #include | + | + int main() | + { | + int x; | + #ifdef __cplusplus | + std::cout << x << "\n"; | + #else | + printf("%d\n", x); | + #endif | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + + exec_lua([[ + vim.lsp.semantic_tokens.start(bufnr, client_id) + ]]) + + screen:expect { grid = [[ + #include | + | + int {3:main}() | + { | + int {2:x}; | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + end) + + it('buffer is re-highlighted when force refreshed', function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + + insert(text) + + screen:expect { grid = [[ + #include | + | + int {3:main}() | + { | + int {2:x}; | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + + exec_lua([[ + vim.lsp.semantic_tokens.force_refresh(bufnr) + ]]) + + screen:expect { grid = [[ + #include | + | + int {3:main}() | + { | + int {2:x}; | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]], unchanged = true } + + local messages = exec_lua('return server.messages') + local token_request_count = 0 + for _, message in ipairs(messages) do + assert(message.method ~= 'textDocument/semanticTokens/full/delta', 'delta request received') + if message.method == 'textDocument/semanticTokens/full' then + token_request_count = token_request_count + 1 + end + end + eq(2, token_request_count) + end) + + it('destroys the highlighter if the buffer is deleted', function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + + insert(text) + + local highlighters = exec_lua([[ + vim.api.nvim_buf_delete(bufnr, { force = true }) + local semantic_tokens = vim.lsp.semantic_tokens + return semantic_tokens.__STHighlighter.active + ]]) + + eq({}, highlighters) + end) + + it('updates highlights with delta request on buffer change', function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + + insert(text) + feed_command('%s/int x/int x()/') + feed_command('noh') + screen:expect { grid = [[ + #include | + | + int {3:main}() | + { | + ^int {3:x}(); | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {3:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + } | + {1:~ }| + {1:~ }| + {1:~ }| + :noh | + ]] } + end) + + it('prevents starting semantic token highlighting with invalid conditions', function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start_client({ name = 'dummy', cmd = server.cmd }) + notifications = {} + vim.notify = function(...) table.insert(notifications, 1, {...}) end + ]]) + eq(false, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)")) + + insert(text) + + local notifications = exec_lua([[ + vim.lsp.semantic_tokens.start(bufnr, client_id) + return notifications + ]]) + matches('%[LSP%] Client with id %d not attached to buffer %d', notifications[1][1]) + + notifications = exec_lua([[ + vim.lsp.semantic_tokens.start(bufnr, client_id + 1) + return notifications + ]]) + matches('%[LSP%] No client with id %d', notifications[1][1]) + end) + + it('opt-out: does not activate semantic token highlighting if disabled in client attach', + function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ + name = 'dummy', + cmd = server.cmd, + on_attach = function(client, bufnr) + client.server_capabilities.semanticTokensProvider = nil + end, + }) + ]]) + eq(true, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)")) + + insert(text) + + screen:expect { grid = [[ + #include | + | + int main() | + { | + int x; | + #ifdef __cplusplus | + std::cout << x << "\n"; | + #else | + printf("%d\n", x); | + #endif | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + + local notifications = exec_lua([[ + local notifications = {} + vim.notify = function(...) table.insert(notifications, 1, {...}) end + vim.lsp.semantic_tokens.start(bufnr, client_id) + return notifications + ]]) + eq('[LSP] Server does not support semantic tokens', notifications[1][1]) + + screen:expect { grid = [[ + #include | + | + int main() | + { | + int x; | + #ifdef __cplusplus | + std::cout << x << "\n"; | + #else | + printf("%d\n", x); | + #endif | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]], unchanged = true } + end) + + it('does not send delta requests if not supported by server', function() + exec_lua([[ + local legend, response, edit_response = ... + server2 = _create_server({ + capabilities = { + semanticTokensProvider = { + full = { delta = false }, + legend = vim.fn.json_decode(legend), + }, + }, + handlers = { + ['textDocument/semanticTokens/full'] = function() + return vim.fn.json_decode(response) + end, + ['textDocument/semanticTokens/full/delta'] = function() + return vim.fn.json_decode(edit_response) + end, + } + }) + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server2.cmd }) + ]], legend, response, edit_response) + + insert(text) + screen:expect { grid = [[ + #include | + | + int {3:main}() | + { | + int {2:x}; | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + feed_command('%s/int x/int x()/') + feed_command('noh') + + -- the highlights don't change because our fake server sent the exact + -- same result for the same method (the full request). "x" would have + -- changed to highlight index 3 had we sent a delta request + screen:expect { grid = [[ + #include | + | + int {3:main}() | + { | + ^int {2:x}(); | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + } | + {1:~ }| + {1:~ }| + {1:~ }| + :noh | + ]] } + local messages = exec_lua('return server2.messages') + local token_request_count = 0 + for _, message in ipairs(messages) do + assert(message.method ~= 'textDocument/semanticTokens/full/delta', 'delta request received') + if message.method == 'textDocument/semanticTokens/full' then + token_request_count = token_request_count + 1 + end + end + eq(2, token_request_count) + end) + end) + + describe('token array decoding', function() + for _, test in ipairs({ + { + it = 'clangd-15 on C', + text = [[char* foo = "\n";]], + response = [[{"data": [0, 6, 3, 0, 8193], "resultId": "1"}]], + legend = [[{ + "tokenTypes": [ + "variable", "variable", "parameter", "function", "method", "function", "property", "variable", "class", "interface", "enum", "enumMember", "type", "type", "unknown", "namespace", "typeParameter", "concept", "type", "macro", "comment" + ], + "tokenModifiers": [ + "declaration", "deprecated", "deduced", "readonly", "static", "abstract", "virtual", "dependentName", "defaultLibrary", "usedAsMutableReference", "functionScope", "classScope", "fileScope", "globalScope" + ] + }]], + expected = { + { + line = 0, + modifiers = { + 'declaration', + 'globalScope', + }, + start_col = 6, + end_col = 9, + type = 'variable', + extmark_added = true, + }, + }, + }, + { + it = 'clangd-15 on C++', + text = [[#include +int main() +{ + #ifdef __cplusplus + const int x = 1; + std::cout << x << std::endl; + #else + comment + #endif +}]] , + response = [[{"data": [1, 4, 4, 3, 8193, 2, 9, 11, 19, 8192, 1, 12, 1, 1, 1033, 1, 2, 3, 15, 8448, 0, 5, 4, 0, 8448, 0, 8, 1, 1, 1032, 0, 5, 3, 15, 8448, 0, 5, 4, 3, 8448, 1, 0, 7, 20, 0, 1, 0, 11, 20, 0, 1, 0, 8, 20, 0], "resultId": "1"}]], + legend = [[{ + "tokenTypes": [ + "variable", "variable", "parameter", "function", "method", "function", "property", "variable", "class", "interface", "enum", "enumMember", "type", "type", "unknown", "namespace", "typeParameter", "concept", "type", "macro", "comment" + ], + "tokenModifiers": [ + "declaration", "deprecated", "deduced", "readonly", "static", "abstract", "virtual", "dependentName", "defaultLibrary", "usedAsMutableReference", "functionScope", "classScope", "fileScope", "globalScope" + ] + }]], + expected = { + { -- main + line = 1, + modifiers = { 'declaration', 'globalScope' }, + start_col = 4, + end_col = 8, + type = 'function', + extmark_added = true, + }, + { -- __cplusplus + line = 3, + modifiers = { 'globalScope' }, + start_col = 9, + end_col = 20, + type = 'macro', + extmark_added = true, + }, + { -- x + line = 4, + modifiers = { 'declaration', 'readonly', 'functionScope' }, + start_col = 12, + end_col = 13, + type = 'variable', + extmark_added = true, + }, + { -- std + line = 5, + modifiers = { 'defaultLibrary', 'globalScope' }, + start_col = 2, + end_col = 5, + type = 'namespace', + extmark_added = true, + }, + { -- cout + line = 5, + modifiers = { 'defaultLibrary', 'globalScope' }, + start_col = 7, + end_col = 11, + type = 'variable', + extmark_added = true, + }, + { -- x + line = 5, + modifiers = { 'readonly', 'functionScope' }, + start_col = 15, + end_col = 16, + type = 'variable', + extmark_added = true, + }, + { -- std + line = 5, + modifiers = { 'defaultLibrary', 'globalScope' }, + start_col = 20, + end_col = 23, + type = 'namespace', + extmark_added = true, + }, + { -- endl + line = 5, + modifiers = { 'defaultLibrary', 'globalScope' }, + start_col = 25, + end_col = 29, + type = 'function', + extmark_added = true, + }, + { -- #else comment #endif + line = 6, + modifiers = {}, + start_col = 0, + end_col = 7, + type = 'comment', + extmark_added = true, + }, + { + line = 7, + modifiers = {}, + start_col = 0, + end_col = 11, + type = 'comment', + extmark_added = true, + }, + { + line = 8, + modifiers = {}, + start_col = 0, + end_col = 8, + type = 'comment', + extmark_added = true, + }, + }, + }, + { + it = 'sumneko_lua', + text = [[-- comment +local a = 1 +b = "as"]], + response = [[{"data": [0, 0, 10, 17, 0, 1, 6, 1, 8, 1, 1, 0, 1, 8, 8]}]], + legend = [[{ + "tokenTypes": [ + "namespace", "type", "class", "enum", "interface", "struct", "typeParameter", "parameter", "variable", "property", "enumMember", "event", "function", "method", "macro", "keyword", "modifier", "comment", "string", "number", "regexp", "operator" + ], + "tokenModifiers": [ + "declaration", "definition", "readonly", "static", "deprecated", "abstract", "async", "modification", "documentation", "defaultLibrary" + ] + }]], + expected = { + { + line = 0, + modifiers = {}, + start_col = 0, + end_col = 10, + type = 'comment', -- comment + extmark_added = true, + }, + { + line = 1, + modifiers = { 'declaration' }, -- a + start_col = 6, + end_col = 7, + type = 'variable', + extmark_added = true, + }, + { + line = 2, + modifiers = { 'static' }, -- b (global) + start_col = 0, + end_col = 1, + type = 'variable', + extmark_added = true, + }, + }, + }, + { + it = 'rust-analyzer', + text = [[pub fn main() { + break rust; + /// what? +} +]] , + response = [[{"data": [0, 0, 3, 1, 0, 0, 4, 2, 1, 0, 0, 3, 4, 14, 524290, 0, 4, 1, 45, 0, 0, 1, 1, 45, 0, 0, 2, 1, 26, 0, 1, 4, 5, 1, 8192, 0, 6, 4, 52, 0, 0, 4, 1, 48, 0, 1, 4, 9, 0, 1, 1, 0, 1, 26, 0], "resultId": "1"}]], + legend = [[{ + "tokenTypes": [ + "comment", "keyword", "string", "number", "regexp", "operator", "namespace", "type", "struct", "class", "interface", "enum", "enumMember", "typeParameter", "function", "method", "property", "macro", "variable", + "parameter", "angle", "arithmetic", "attribute", "attributeBracket", "bitwise", "boolean", "brace", "bracket", "builtinAttribute", "builtinType", "character", "colon", "comma", "comparison", "constParameter", "derive", + "dot", "escapeSequence", "formatSpecifier", "generic", "label", "lifetime", "logical", "macroBang", "operator", "parenthesis", "punctuation", "selfKeyword", "semicolon", "typeAlias", "toolModule", "union", "unresolvedReference" + ], + "tokenModifiers": [ + "documentation", "declaration", "definition", "static", "abstract", "deprecated", "readonly", "defaultLibrary", "async", "attribute", "callable", "constant", "consuming", "controlFlow", "crateRoot", "injected", "intraDocLink", + "library", "mutable", "public", "reference", "trait", "unsafe" + ] + }]], + expected = { + { + line = 0, + modifiers = {}, + start_col = 0, + end_col = 3, -- pub + type = 'keyword', + extmark_added = true, + }, + { + line = 0, + modifiers = {}, + start_col = 4, + end_col = 6, -- fn + type = 'keyword', + extmark_added = true, + }, + { + line = 0, + modifiers = { 'declaration', 'public' }, + start_col = 7, + end_col = 11, -- main + type = 'function', + extmark_added = true, + }, + { + line = 0, + modifiers = {}, + start_col = 11, + end_col = 12, + type = 'parenthesis', + extmark_added = true, + }, + { + line = 0, + modifiers = {}, + start_col = 12, + end_col = 13, + type = 'parenthesis', + extmark_added = true, + }, + { + line = 0, + modifiers = {}, + start_col = 14, + end_col = 15, + type = 'brace', + extmark_added = true, + }, + { + line = 1, + modifiers = { 'controlFlow' }, + start_col = 4, + end_col = 9, -- break + type = 'keyword', + extmark_added = true, + }, + { + line = 1, + modifiers = {}, + start_col = 10, + end_col = 13, -- rust + type = 'unresolvedReference', + extmark_added = true, + }, + { + line = 1, + modifiers = {}, + start_col = 13, + end_col = 13, + type = 'semicolon', + extmark_added = true, + }, + { + line = 2, + modifiers = { 'documentation' }, + start_col = 4, + end_col = 11, + type = 'comment', -- /// what? + extmark_added = true, + }, + { + line = 3, + modifiers = {}, + start_col = 0, + end_col = 1, + type = 'brace', + extmark_added = true, + }, + }, + }, + }) do + it(test.it, function() + exec_lua(create_server_definition) + exec_lua([[ + local legend, resp = ... + server = _create_server({ + capabilities = { + semanticTokensProvider = { + full = { delta = false }, + legend = vim.fn.json_decode(legend), + }, + }, + handlers = { + ['textDocument/semanticTokens/full'] = function() + return vim.fn.json_decode(resp) + end, + } + }) + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]], test.legend, test.response) + + insert(test.text) + + local highlights = exec_lua([[ + local semantic_tokens = vim.lsp.semantic_tokens + return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights + ]]) + eq(test.expected, highlights) + end) + end + end) + describe('token decoding with deltas', function() + for _, test in ipairs({ + { + it = 'semantic_tokens_delta: clangd-15 on C', + name = 'semantic_tokens_delta', + legend = [[{ + "tokenTypes": [ + "variable", "variable", "parameter", "function", "method", "function", "property", "variable", "class", "interface", "enum", "enumMember", "type", "type", "unknown", "namespace", "typeParameter", "concept", "type", "macro", "comment" + ], + "tokenModifiers": [ + "declaration", "deprecated", "deduced", "readonly", "static", "abstract", "virtual", "dependentName", "defaultLibrary", "usedAsMutableReference", "functionScope", "classScope", "fileScope", "globalScope" + ] + }]], + text = [[char* foo = "\n";]], + edit = [[ggO]], + response1 = [[{"data": [0, 6, 3, 0, 8193], "resultId": "1"}]], + response2 = [[{"edits": [{ "start": 0, "deleteCount": 1, "data": [1] }], "resultId": "2"}]], + expected1 = { + { + line = 0, + modifiers = { + 'declaration', + 'globalScope', + }, + start_col = 6, + end_col = 9, + type = 'variable', + extmark_added = true, + } + }, + expected2 = { + { + line = 1, + modifiers = { + 'declaration', + 'globalScope', + }, + start_col = 6, + end_col = 9, + type = 'variable', + extmark_added = true, + } + }, + } + }) do + it(test.it, function() + exec_lua(create_server_definition) + exec_lua([[ + local legend, resp1, resp2 = ... + server = _create_server({ + capabilities = { + semanticTokensProvider = { + full = { delta = true }, + legend = vim.fn.json_decode(legend), + }, + }, + handlers = { + ['textDocument/semanticTokens/full'] = function() + return vim.fn.json_decode(resp1) + end, + ['textDocument/semanticTokens/full/delta'] = function() + return vim.fn.json_decode(resp2) + end, + } + }) + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + semantic_tokens = vim.lsp.semantic_tokens + ]], test.legend, test.response1, test.response2) + + insert(test.text) + + local highlights = exec_lua([[ + return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights + ]]) + + eq(test.expected1, highlights) + + feed(test.edit) + + highlights = exec_lua([[ + return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights + ]]) + + eq(test.expected2, highlights) + end) + end + end) +end) -- cgit From 4d22424d9ecdb7c2485a1d7272e1b75e69386891 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 8 Dec 2022 20:11:39 +0800 Subject: vim-patch:9.0.1030: using freed memory with the cmdline popup menu Problem: Using freed memory with the cmdline popup menu. Solution: Clear the popup menu when clearing the matches. (closes vim/vim#11677) https://github.com/vim/vim/commit/038e6d20e680ce8c850d07f6b035c4e1904c1201 Co-authored-by: Bram Moolenaar --- test/functional/ui/popupmenu_spec.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 7e81d1a577..c1f30140e2 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -2583,6 +2583,29 @@ describe('builtin popupmenu', function() ]]} end) + -- oldtest: Test_wildmenu_pum_clear_entries() + it('wildoptions=pum when using Ctrl-E as wildchar vim-patch:9.0.1030', function() + screen:try_resize(30, 10) + exec([[ + set wildoptions=pum + set wildchar= + ]]) + feed(':sign ') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{s: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{n: unplace }{1: }| + :sign define^ | + ]]) + assert_alive() + end) + it("'pumblend' RGB-color", function() screen:try_resize(60,14) screen:set_default_attr_ids({ -- cgit From 1e2cc688891c789f02699f9c7e0bffd435794310 Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Fri, 9 Dec 2022 02:55:50 +0600 Subject: fix(chansend): sending lines to terminal in reverse order on Windows #19315 Problem: `chansend()` on Windows sends lines in reverse order. Cause: Using \n instead of \r\n for newlines on Windows. Solution: on Windows, use CRLF newline characters. Fixes #18501 --- test/functional/terminal/channel_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional') diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua index b5f3c2bd31..2ca7cdb0a2 100644 --- a/test/functional/terminal/channel_spec.lua +++ b/test/functional/terminal/channel_spec.lua @@ -7,6 +7,7 @@ local command = helpers.command local pcall_err = helpers.pcall_err local feed = helpers.feed local poke_eventloop = helpers.poke_eventloop +local is_os = helpers.is_os describe('terminal channel is closed and later released if', function() local screen @@ -92,3 +93,17 @@ describe('terminal channel is closed and later released if', function() eq(chans - 1, eval('len(nvim_list_chans())')) end) end) + +it('chansend sends lines to terminal channel in proper order', function() + clear() + local screen = Screen.new(100, 20) + screen:attach() + local shells = is_os('win') and {'cmd.exe', 'pwsh.exe -nop', 'powershell.exe -nop'} or {'sh'} + for _, sh in ipairs(shells) do + command([[bdelete! | let id = termopen(']] .. sh .. [[')]]) + command([[call chansend(id, ['echo "hello"', 'echo "world"', ''])]]) + screen:expect{ + any=[[echo "hello".*echo "world"]] + } + end +end) -- cgit From 70d6c335b17cf166760457e3673aa61098ef0e66 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 06:35:29 +0800 Subject: vim-patch:9.0.1036: undo misbehaves when writing from an insert mode mapping Problem: Undo misbehaves when writing from an insert mode mapping. Solution: Sync undo when writing. (closes vim/vim#11674) https://github.com/vim/vim/commit/3f8f82772313af9f2417b06651f30988b63e1c96 Co-authored-by: Bram Moolenaar --- test/functional/editor/undo_spec.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/functional') diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index a041428cdc..6f9c4506fc 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -9,6 +9,7 @@ local feed = helpers.feed local feed_command = helpers.feed_command local insert = helpers.insert local funcs = helpers.funcs +local exec = helpers.exec local function lastmessage() local messages = funcs.split(funcs.execute('messages'), '\n') @@ -67,6 +68,40 @@ describe('u CTRL-R g- g+', function() undo_and_redo(4, 'u', '', '1') undo_and_redo(4, 'g-', 'g+', '1') end) + + describe('undo works correctly when writing in Insert mode', function() + before_each(function() + exec([[ + edit Xtestfile.txt + set undolevels=100 undofile + write + ]]) + end) + + after_each(function() + command('bwipe!') + os.remove('Xtestfile.txt') + os.remove('Xtestfile.txt.un~') + end) + + -- oldtest: Test_undo_after_write() + it('using mapping', function() + command('imap . write') + feed('Otest.boo!!!') + expect([[ + test + boo!!! + ]]) + + feed('u') + expect([[ + test + ]]) + + feed('u') + expect('') + end) + end) end) describe(':undo! command', function() -- cgit From 95044991e618827924ac47aeae8bd0eacc775f58 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 06:57:18 +0800 Subject: test(undo_spec): add more tests for writing in Insert mode --- test/functional/editor/undo_spec.lua | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/functional') diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index 6f9c4506fc..d66ab352ef 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -10,6 +10,7 @@ local feed_command = helpers.feed_command local insert = helpers.insert local funcs = helpers.funcs local exec = helpers.exec +local exec_lua = helpers.exec_lua local function lastmessage() local messages = funcs.split(funcs.execute('messages'), '\n') @@ -101,6 +102,45 @@ describe('u CTRL-R g- g+', function() feed('u') expect('') end) + + it('using Lua mapping', function() + exec_lua([[ + vim.api.nvim_set_keymap('i', '.', '', {callback = function() + vim.cmd('write') + end}) + ]]) + feed('Otest.boo!!!') + expect([[ + test + boo!!! + ]]) + + feed('u') + expect([[ + test + ]]) + + feed('u') + expect('') + end) + + it('using RPC call', function() + feed('Otest') + command('write') + feed('boo!!!') + expect([[ + test + boo!!! + ]]) + + feed('u') + expect([[ + test + ]]) + + feed('u') + expect('') + end) end) end) -- cgit From f69d531d84c52ed71b6b9dd9b05a077ca8896ff6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 10:37:53 +0800 Subject: test: convert another test in test_matchadd_conceal.vim to Lua (#21353) --- test/functional/ui/syntax_conceal_spec.lua | 78 ++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 21 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/syntax_conceal_spec.lua b/test/functional/ui/syntax_conceal_spec.lua index e8798ddd93..1391985823 100644 --- a/test/functional/ui/syntax_conceal_spec.lua +++ b/test/functional/ui/syntax_conceal_spec.lua @@ -4,7 +4,7 @@ local clear, feed, command = helpers.clear, helpers.feed, helpers.command local eq = helpers.eq local insert = helpers.insert local poke_eventloop = helpers.poke_eventloop -local expect_exit = helpers.expect_exit +local exec = helpers.exec describe('Screen', function() local screen @@ -1001,25 +1001,32 @@ describe('Screen', function() eq({}, grid_lines) -- no redraw was done end) - -- Copy of Test_cursor_column_in_concealed_line_after_window_scroll in - -- test/functional/ui/syntax_conceal_spec.lua. - describe('concealed line after window scroll', function() - after_each(function() - expect_exit(command, ':qall!') - os.remove('Xcolesearch') - end) - - it('has the correct cursor column', function() + describe('concealed line has the correct cursor column', function() + -- oldtest: Test_cursor_column_in_concealed_line_after_window_scroll() + it('after window scroll', function() insert([[ - 3split - let m = matchadd('Conceal', '=') - setl conceallevel=2 concealcursor=nc - normal gg - "==expr== - ]]) + 3split + let m = matchadd('Conceal', '=') + setl conceallevel=2 concealcursor=nc + normal gg + "==expr==]]) + feed('gg') + command('file Xcolesearch') + command('set nomodified') - command('write Xcolesearch') - feed(":so %") + command('so') + screen:expect{grid=[[ + ^3split | + let m matchadd('Conceal', '') | + setl conceallevel2 concealcursornc | + {2:Xcolesearch }| + 3split | + let m = matchadd('Conceal', '=') | + setl conceallevel=2 concealcursor=nc | + normal gg | + {3:Xcolesearch }| + | + ]]} -- Jump to something that is beyond the bottom of the window, -- so there's a scroll down. @@ -1033,13 +1040,42 @@ describe('Screen', function() normal gg | "{5:^expr} | {2:Xcolesearch }| + 3split | + let m = matchadd('Conceal', '=') | + setl conceallevel=2 concealcursor=nc | normal gg | - "=={5:expr}== | - | - {0:~ }| {3:Xcolesearch }| /expr | ]]} end) + + -- oldtest: Test_cursor_column_in_concealed_line_after_leftcol_change() + it('after leftcol change', function() + exec([[ + 0put = 'ab' .. repeat('-', &columns) .. 'c' + call matchadd('Conceal', '-') + set nowrap ss=0 cole=3 cocu=n + ]]) + + -- Go to the end of the line (3 columns beyond the end of the screen). + -- Horizontal scroll would center the cursor in the screen line, but conceal + -- makes it go to screen column 1. + feed('$') + + -- Are the concealed parts of the current line really hidden? + -- Is the window's cursor column properly updated for conceal? + screen:expect{grid=[[ + ^c | + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + end) end) end) -- cgit From 5e6a288ce7ee079e7695525f2e9e99d071ccdfbf Mon Sep 17 00:00:00 2001 From: jdrouhard Date: Fri, 9 Dec 2022 04:54:09 -0600 Subject: fix(lsp): followup fixes for semantic tokens support (#21357) 1. The algorithm for applying edits was slightly incorrect. It needs to preserve the original token list as the edits are applied instead of mutating it as it iterates. From the spec: Semantic token edits behave conceptually like text edits on documents: if an edit description consists of n edits all n edits are based on the same state Sm of the number array. They will move the number array from state Sm to Sm+1. 2. Schedule the semantic token engine start() call in the client._on_attach() function so that users who schedule_wrap() their config.on_attach() functions (like nvim-lspconfig does) can still disable semantic tokens by deleting the semanticTokensProvider from their server capabilities. --- .../functional/plugin/lsp/semantic_tokens_spec.lua | 231 ++++++++++++++++++++- 1 file changed, 222 insertions(+), 9 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 1646108416..3aeb4b264b 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -359,9 +359,9 @@ describe('semantic token highlighting', function() client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd, - on_attach = function(client, bufnr) + on_attach = vim.schedule_wrap(function(client, bufnr) client.server_capabilities.semanticTokensProvider = nil - end, + end), }) ]]) eq(true, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)")) @@ -533,7 +533,7 @@ int main() #else comment #endif -}]] , +}]], response = [[{"data": [1, 4, 4, 3, 8193, 2, 9, 11, 19, 8192, 1, 12, 1, 1, 1033, 1, 2, 3, 15, 8448, 0, 5, 4, 0, 8448, 0, 8, 1, 1, 1032, 0, 5, 3, 15, 8448, 0, 5, 4, 3, 8448, 1, 0, 7, 20, 0, 1, 0, 11, 20, 0, 1, 0, 8, 20, 0], "resultId": "1"}]], legend = [[{ "tokenTypes": [ @@ -681,7 +681,7 @@ b = "as"]], break rust; /// what? } -]] , +]], response = [[{"data": [0, 0, 3, 1, 0, 0, 4, 2, 1, 0, 0, 3, 4, 14, 524290, 0, 4, 1, 45, 0, 0, 1, 1, 45, 0, 0, 2, 1, 26, 0, 1, 4, 5, 1, 8192, 0, 6, 4, 52, 0, 0, 4, 1, 48, 0, 1, 4, 9, 0, 1, 1, 0, 1, 26, 0], "resultId": "1"}]], legend = [[{ "tokenTypes": [ @@ -693,7 +693,7 @@ b = "as"]], "documentation", "declaration", "definition", "static", "abstract", "deprecated", "readonly", "defaultLibrary", "async", "attribute", "callable", "constant", "consuming", "controlFlow", "crateRoot", "injected", "intraDocLink", "library", "mutable", "public", "reference", "trait", "unsafe" ] - }]], + }]], expected = { { line = 0, @@ -818,11 +818,11 @@ b = "as"]], end) end end) + describe('token decoding with deltas', function() for _, test in ipairs({ { it = 'semantic_tokens_delta: clangd-15 on C', - name = 'semantic_tokens_delta', legend = [[{ "tokenTypes": [ "variable", "variable", "parameter", "function", "method", "function", "property", "variable", "class", "interface", "enum", "enumMember", "type", "type", "unknown", "namespace", "typeParameter", "concept", "type", "macro", "comment" @@ -831,7 +831,7 @@ b = "as"]], "declaration", "deprecated", "deduced", "readonly", "static", "abstract", "virtual", "dependentName", "defaultLibrary", "usedAsMutableReference", "functionScope", "classScope", "fileScope", "globalScope" ] }]], - text = [[char* foo = "\n";]], + text1 = [[char* foo = "\n";]], edit = [[ggO]], response1 = [[{"data": [0, 6, 3, 0, 8193], "resultId": "1"}]], response2 = [[{"edits": [{ "start": 0, "deleteCount": 1, "data": [1] }], "resultId": "2"}]], @@ -861,6 +861,205 @@ b = "as"]], extmark_added = true, } }, + }, + { + it = 'response with multiple delta edits', + legend = [[{ + "tokenTypes": [ + "variable", "variable", "parameter", "function", "method", "function", "property", "variable", "class", "interface", "enum", "enumMember", "type", "type", "unknown", "namespace", "typeParameter", "concept", "type", "macro", "comment" + ], + "tokenModifiers": [ + "declaration", "deprecated", "deduced", "readonly", "static", "abstract", "virtual", "dependentName", "defaultLibrary", "usedAsMutableReference", "functionScope", "classScope", "fileScope", "globalScope" + ] + }]], + text1 = dedent([[ + #include + + int main() + { + int x; + #ifdef __cplusplus + std::cout << x << "\n"; + #else + printf("%d\n", x); + #endif + }]]), + text2 = [[#include + +int main() +{ + int x(); + double y; +#ifdef __cplusplus + std::cout << x << "\n"; +#else + printf("%d\n", x); +#endif +}]], + response1 = [[{ + "data": [ 2, 4, 4, 3, 8193, 2, 8, 1, 1, 1025, 1, 7, 11, 19, 8192, 1, 4, 3, 15, 8448, 0, 5, 4, 0, 8448, 0, 8, 1, 1, 1024, 1, 0, 5, 20, 0, 1, 0, 22, 20, 0, 1, 0, 6, 20, 0 ], + "resultId": 1 + }]], + response2 = [[{ + "edits": [ {"data": [ 2, 8, 1, 3, 8193, 1, 11, 1, 1, 1025 ], "deleteCount": 5, "start": 5}, {"data": [ 0, 8, 1, 3, 8192 ], "deleteCount": 5, "start": 25 } ], + "resultId":"2" + }]], + expected1 = { + { + line = 2, + start_col = 4, + end_col = 8, + modifiers = { 'declaration', 'globalScope' }, + type = 'function', + extmark_added = true, + }, + { + line = 4, + start_col = 8, + end_col = 9, + modifiers = { 'declaration', 'functionScope' }, + type = 'variable', + extmark_added = true, + }, + { + line = 5, + start_col = 7, + end_col = 18, + modifiers = { 'globalScope' }, + type = 'macro', + extmark_added = true, + }, + { + line = 6, + start_col = 4, + end_col = 7, + modifiers = { 'defaultLibrary', 'globalScope' }, + type = 'namespace', + extmark_added = true, + }, + { + line = 6, + start_col = 9, + end_col = 13, + modifiers = { 'defaultLibrary', 'globalScope' }, + type = 'variable', + extmark_added = true, + }, + { + line = 6, + start_col = 17, + end_col = 18, + extmark_added = true, + modifiers = { 'functionScope' }, + type = 'variable', + }, + { + line = 7, + start_col = 0, + end_col = 5, + extmark_added = true, + modifiers = {}, + type = 'comment', + }, + { + line = 8, + end_col = 22, + modifiers = {}, + start_col = 0, + type = 'comment', + extmark_added = true, + }, + { + line = 9, + start_col = 0, + end_col = 6, + modifiers = {}, + type = 'comment', + extmark_added = true, + } + }, + expected2 = { + { + line = 2, + start_col = 4, + end_col = 8, + modifiers = { 'declaration', 'globalScope' }, + type = 'function', + extmark_added = true, + }, + { + line = 4, + start_col = 8, + end_col = 9, + modifiers = { 'declaration', 'globalScope' }, + type = 'function', + extmark_added = true, + }, + { + line = 5, + end_col = 12, + start_col = 11, + modifiers = { 'declaration', 'functionScope' }, + type = 'variable', + extmark_added = true, + }, + { + line = 6, + start_col = 7, + end_col = 18, + modifiers = { 'globalScope' }, + type = 'macro', + extmark_added = true, + }, + { + line = 7, + start_col = 4, + end_col = 7, + modifiers = { 'defaultLibrary', 'globalScope' }, + type = 'namespace', + extmark_added = true, + }, + { + line = 7, + start_col = 9, + end_col = 13, + modifiers = { 'defaultLibrary', 'globalScope' }, + type = 'variable', + extmark_added = true, + }, + { + line = 7, + start_col = 17, + end_col = 18, + extmark_added = true, + modifiers = { 'globalScope' }, + type = 'function', + }, + { + line = 8, + start_col = 0, + end_col = 5, + extmark_added = true, + modifiers = {}, + type = 'comment', + }, + { + line = 9, + end_col = 22, + modifiers = {}, + start_col = 0, + type = 'comment', + extmark_added = true, + }, + { + line = 10, + start_col = 0, + end_col = 6, + modifiers = {}, + type = 'comment', + extmark_added = true, + } + }, } }) do it(test.it, function() @@ -886,10 +1085,16 @@ b = "as"]], bufnr = vim.api.nvim_get_current_buf() vim.api.nvim_win_set_buf(0, bufnr) client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + + -- speed up vim.api.nvim_buf_set_lines calls by changing debounce to 10 for these tests semantic_tokens = vim.lsp.semantic_tokens + vim.schedule(function() + semantic_tokens.stop(bufnr, client_id) + semantic_tokens.start(bufnr, client_id, { debounce = 10 }) + end) ]], test.legend, test.response1, test.response2) - insert(test.text) + insert(test.text1) local highlights = exec_lua([[ return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights @@ -897,7 +1102,15 @@ b = "as"]], eq(test.expected1, highlights) - feed(test.edit) + if test.edit then + feed(test.edit) + else + exec_lua([[ + local text = ... + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, vim.fn.split(text, "\n")) + vim.wait(15) -- wait fot debounce + ]], test.text2) + end highlights = exec_lua([[ return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights -- cgit From 7faf8a45e8c48d5ab1b6096d6b3e23c84bb3d7c6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 10 Dec 2022 06:50:03 +0800 Subject: fix(events): skip WinScrolled for newly-created float windows (#21333) Unlike split windows, creating a new floating window does not cause other windows to resize, so it doesn't make much sense to trigger WinScrolled or WinResized when creating a new floating window. --- test/functional/autocmd/win_scrolled_resized_spec.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua index 4a2e27931a..4957f56dd4 100644 --- a/test/functional/autocmd/win_scrolled_resized_spec.lua +++ b/test/functional/autocmd/win_scrolled_resized_spec.lua @@ -287,6 +287,15 @@ describe('WinScrolled', function() it('is triggered by mouse scrolling in unfocused floating window #18222', function() local screen = Screen.new(80, 24) screen:attach() + + exec([[ + let g:scrolled = 0 + autocmd WinScrolled * let g:scrolled += 1 + autocmd WinScrolled * let g:amatch = expand('') + autocmd WinScrolled * let g:v_event = deepcopy(v:event) + ]]) + eq(0, eval('g:scrolled')) + local buf = meths.create_buf(true, true) meths.buf_set_lines(buf, 0, -1, false, {'a', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'}) local win = meths.open_win(buf, false, { @@ -298,12 +307,7 @@ describe('WinScrolled', function() style = 'minimal' }) local winid_str = tostring(win.id) - exec([[ - let g:scrolled = 0 - autocmd WinScrolled * let g:scrolled += 1 - autocmd WinScrolled * let g:amatch = expand('') - autocmd WinScrolled * let g:v_event = deepcopy(v:event) - ]]) + -- WinScrolled should not be triggered when creating a new floating window eq(0, eval('g:scrolled')) meths.input_mouse('wheel', 'down', '', 0, 3, 3) -- cgit From 6d37d8cb17390419360c1459607beac2d93183b6 Mon Sep 17 00:00:00 2001 From: fsouza <108725+fsouza@users.noreply.github.com> Date: Sat, 10 Dec 2022 06:16:33 -0500 Subject: fix(lsp): ignore null responses for semanticTokens request (#21364) The spec indicates that the response may be `null`, but it doesn't really say what a `null` response means. Since neovim raises an error if the response is `null`, I figured that ignoring it would be the safest bet. Co-authored-by: Mathias Fussenegger --- test/functional/plugin/lsp/helpers.lua | 4 +- .../functional/plugin/lsp/semantic_tokens_spec.lua | 69 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index 1363ab894d..028ccb9e2c 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -36,9 +36,7 @@ M.create_server_definition = [[ local handler = handlers[method] if handler then local response, err = handler(method, params) - if response then - callback(err, response) - end + callback(err, response) elseif method == 'initialize' then callback(nil, { capabilities = opts.capabilities or {} diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 3aeb4b264b..7a5494e9a5 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -415,6 +415,75 @@ describe('semantic token highlighting', function() ]], unchanged = true } end) + it('ignores null responses from the server', function() + exec_lua([[ + local legend, response, edit_response = ... + server2 = _create_server({ + capabilities = { + semanticTokensProvider = { + full = { delta = false }, + }, + }, + handlers = { + ['textDocument/semanticTokens/full'] = function() + return nil + end, + ['textDocument/semanticTokens/full/delta'] = function() + return nil + end, + } + }) + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server2.cmd }) + ]]) + eq(true, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)")) + + insert(text) + + screen:expect { grid = [[ + #include | + | + int main() | + { | + int x; | + #ifdef __cplusplus | + std::cout << x << "\n"; | + #else | + printf("%d\n", x); | + #endif | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + + exec_lua([[ + vim.lsp.semantic_tokens.start(bufnr, client_id) + ]]) + + screen:expect { grid = [[ + #include | + | + int main() | + { | + int x; | + #ifdef __cplusplus | + std::cout << x << "\n"; | + #else | + printf("%d\n", x); | + #endif | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]], unchanged = true } + end) + it('does not send delta requests if not supported by server', function() exec_lua([[ local legend, response, edit_response = ... -- cgit From 224473546c95f17c45afc54fe8b4ef5f0e000974 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 10 Dec 2022 20:13:40 +0800 Subject: fix(api): set correct curbuf when temporarily changing curwin (#21371) This is the same code change as https://github.com/vim/vim/commit/6c87bbb4e45515e70ac1728cabd1451063bf427d --- test/functional/api/window_spec.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 774ec406a8..ecab6a4713 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -7,6 +7,7 @@ local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, helpers.tabpage local poke_eventloop = helpers.poke_eventloop local curwinmeths = helpers.curwinmeths +local exec = helpers.exec local funcs = helpers.funcs local request = helpers.request local NIL = helpers.NIL @@ -283,6 +284,22 @@ describe('API/win', function() window('set_height', nvim('list_wins')[2], 2) eq(2, window('get_height', nvim('list_wins')[2])) end) + + it('do not cause ml_get errors with foldmethod=expr #19989', function() + insert([[ + aaaaa + bbbbb + ccccc]]) + command('set foldmethod=expr') + exec([[ + new + let w = nvim_get_current_win() + wincmd w + call nvim_win_set_height(w, 5) + ]]) + feed('l') + eq('', meths.get_vvar('errmsg')) + end) end) describe('{get,set}_width', function() @@ -297,6 +314,22 @@ describe('API/win', function() window('set_width', nvim('list_wins')[2], 2) eq(2, window('get_width', nvim('list_wins')[2])) end) + + it('do not cause ml_get errors with foldmethod=expr #19989', function() + insert([[ + aaaaa + bbbbb + ccccc]]) + command('set foldmethod=expr') + exec([[ + vnew + let w = nvim_get_current_win() + wincmd w + call nvim_win_set_width(w, 5) + ]]) + feed('l') + eq('', meths.get_vvar('errmsg')) + end) end) describe('{get,set,del}_var', function() -- cgit From ea8b82890179be4243902d88a5241bbc33122aad Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Sat, 10 Dec 2022 15:46:34 -0600 Subject: fix(tests): initialize Screen.colors in API highlight tests --- test/functional/api/highlight_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 3b36563d21..541ac0ab63 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -11,6 +11,9 @@ local ok = helpers.ok local assert_alive = helpers.assert_alive describe('API: highlight',function() + clear() + Screen.new() -- initialize Screen.colors + local expected_rgb = { background = Screen.colors.Yellow, foreground = Screen.colors.Red, -- cgit From 3dadd3aca5af4d09d0acbb027098b1a2c889e433 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 11 Dec 2022 08:48:00 +0800 Subject: vim-patch:8.2.2870: CmdlineChange event triggered twice for CTRL-R (#21361) Problem: CmdlineChange event triggered twice for CTRL-R. Solution: Return CMDLINE_NOT_CHANGED from cmdline_insert_reg(). (closes vim/vim#8219) https://github.com/vim/vim/commit/796139ae3ac89e27ee96dce3c7fdb87d8c839f53 Cherry-pick Test_cmdline_map_cmdlineChanged() from patch 8.2.2851. Co-authored-by: Bram Moolenaar --- test/functional/autocmd/cmdline_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua index c96501ead4..60c29170e2 100644 --- a/test/functional/autocmd/cmdline_spec.lua +++ b/test/functional/autocmd/cmdline_spec.lua @@ -223,7 +223,6 @@ describe('cmdline autocommands', function() eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+1"}}, next_msg()) feed('') eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg()) - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x = "}}, next_msg()) eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x = 2"}}, next_msg()) feed('') eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) -- cgit From 1c324cb1927e03b5a3584a8982e3d5029498f14e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 11 Dec 2022 21:41:26 -0500 Subject: docs #20986 - https://github.com/neovim/tree-sitter-vimdoc v1.2.4 eliminates most errors in pi_netrw.txt, so we can remove that workaround from ignore_parse_error(). - improved codeblock --- test/functional/api/autocmd_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index a923f5df0e..7fb52b097b 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -14,14 +14,14 @@ before_each(clear) describe('autocmd api', function() describe('nvim_create_autocmd', function() - it('does not allow "command" and "callback" in the same autocmd', function() - local ok, _ = pcall(meths.create_autocmd, "BufReadPost", { + it('"command" and "callback" are mutually exclusive', function() + local rv = pcall_err(meths.create_autocmd, "BufReadPost", { pattern = "*.py,*.pyi", command = "echo 'Should Have Errored", - callback = "not allowed", + callback = "NotAllowed", }) - eq(false, ok) + eq("specify either 'callback' or 'command', not both", rv) end) it('doesnt leak when you use ++once', function() @@ -60,13 +60,13 @@ describe('autocmd api', function() end) it('does not allow passing buffer and patterns', function() - local ok = pcall(meths.create_autocmd, "Filetype", { + local rv = pcall_err(meths.create_autocmd, "Filetype", { command = "let g:called = g:called + 1", buffer = 0, pattern = "*.py", }) - eq(false, ok) + eq("cannot pass both: 'pattern' and 'buffer' for the same autocmd", rv) end) it('does not allow passing invalid buffers', function() -- cgit From 8b9bf3e3b997f033dcf73d506cceb12231501a22 Mon Sep 17 00:00:00 2001 From: Phelipe Teles <39670535+phelipetls@users.noreply.github.com> Date: Mon, 12 Dec 2022 12:14:50 -0300 Subject: fix: vim.opt_local:append ignoring global option value (#21382) Closes https://github.com/neovim/neovim/issues/18225 --- test/functional/lua/vim_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index c74e88f55d..e390619a5a 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2187,6 +2187,22 @@ describe('lua stdlib', function() end) end) -- vim.opt + describe('opt_local', function() + it('should be able to append to an array list type option', function() + eq({ "foo,bar,baz,qux" }, exec_lua [[ + local result = {} + + vim.opt.tags = "foo,bar" + vim.opt_local.tags:append("baz") + vim.opt_local.tags:append("qux") + + table.insert(result, vim.bo.tags) + + return result + ]]) + end) + end) + it('vim.cmd', function() exec_lua [[ vim.cmd "autocmd BufNew * ++once lua BUF = vim.fn.expand('')" -- cgit From d40d34aaa5720b67da629b4ca74674dfd4b9221c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 12 Dec 2022 16:44:11 +0000 Subject: fix(diff): handle long lines without crashing (#21389) Fixes https://github.com/neovim/neovim/issues/21388 --- test/functional/ui/linematch_spec.lua | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/linematch_spec.lua b/test/functional/ui/linematch_spec.lua index 5601908929..697677aa67 100644 --- a/test/functional/ui/linematch_spec.lua +++ b/test/functional/ui/linematch_spec.lua @@ -49,12 +49,11 @@ describe('Diff mode screen with 3 diffs open', function() [8] = {background = Screen.colors.Red1, bold = true}; [10] = {foreground = Screen.colors.Brown}; [9] = {background = Screen.colors.Plum1}; -}) + }) feed('=') feed(':windo set nu!') - - end) + describe('setup the diff screen to look like a merge conflict with 3 files in diff mode', function() before_each(function() @@ -249,12 +248,11 @@ describe('Diff mode screen with 2 diffs open', function() [8] = {background = Screen.colors.Red1, bold = true}; [10] = {foreground = Screen.colors.Brown}; [9] = {background = Screen.colors.Plum1}; -}) + }) feed('=') feed(':windo set nu!') - - end) + describe('setup a diff with 2 files and set linematch:30', function() before_each(function() feed(':set diffopt+=linematch:30') @@ -979,3 +977,19 @@ something end) end) end) + +describe('regressions', function() + local screen + + it("doesn't crash with long lines", function() + clear() + feed(':set diffopt+=linematch:30') + screen = Screen.new(100, 20) + screen:attach() + -- line must be greater than MATCH_CHAR_MAX_LEN + helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1000)..'hello' }) + helpers.exec 'vnew' + helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1010)..'world' }) + helpers.exec 'windo diffthis' + end) +end) -- cgit From 3869a2e0cf25323a8e5235840678b147ca908517 Mon Sep 17 00:00:00 2001 From: jdrouhard Date: Mon, 12 Dec 2022 11:42:37 -0600 Subject: perf(lsp): update semantic tokens algorithm for parsing modifiers (#21383) Instead of testing for every possible modifier type, only test bits up to the highest set in the token array. Saves many bit ops and comparisons when there are no modifiers or when the highest set bit is a lower bit than the highest possible in the legend on average. Can be further simplified when non-luaJIT gets the full bit module (see #21222) --- .../functional/plugin/lsp/semantic_tokens_spec.lua | 23 ---------------------- 1 file changed, 23 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 7a5494e9a5..e87e2a3334 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -459,29 +459,6 @@ describe('semantic token highlighting', function() {1:~ }| | ]] } - - exec_lua([[ - vim.lsp.semantic_tokens.start(bufnr, client_id) - ]]) - - screen:expect { grid = [[ - #include | - | - int main() | - { | - int x; | - #ifdef __cplusplus | - std::cout << x << "\n"; | - #else | - printf("%d\n", x); | - #endif | - } | - ^} | - {1:~ }| - {1:~ }| - {1:~ }| - | - ]], unchanged = true } end) it('does not send delta requests if not supported by server', function() -- cgit From 54d6a32fbdcbd5b26b72f4dca8906e60f5186d2c Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 12 Dec 2022 20:43:14 +0100 Subject: feat(lsp): highlight semantic token modifiers (#21390) Apply semantic token modifiers as separate extmarks with corresponding highlight groups (e.g., `@readonly`). This is a low-effort PR to enable the most common use cases (applying, e.g., italics or backgrounds on top of type highlights; language-specific fallbacks like `@global.lua` are also available). This can be replaced by more complicated selector-style themes later on. --- .../functional/plugin/lsp/semantic_tokens_spec.lua | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index e87e2a3334..e62a6f7086 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -69,9 +69,12 @@ describe('semantic token highlighting', function() [4] = { bold = true, foreground = Screen.colors.SeaGreen }; [5] = { foreground = tonumber('0x6a0dad') }; [6] = { foreground = Screen.colors.Blue1 }; + [7] = { bold = true, foreground = Screen.colors.DarkCyan }; + [8] = { bold = true, foreground = Screen.colors.SlateBlue }; } command([[ hi link @namespace Type ]]) command([[ hi link @function Special ]]) + command([[ hi @declaration gui=bold ]]) exec_lua(create_server_definition) exec_lua([[ @@ -107,9 +110,9 @@ describe('semantic token highlighting', function() screen:expect { grid = [[ #include | | - int {3:main}() | + int {8:main}() | { | - int {2:x}; | + int {7:x}; | #ifdef {5:__cplusplus} | {4:std}::{2:cout} << {2:x} << "\n"; | {6:#else} | @@ -199,9 +202,9 @@ describe('semantic token highlighting', function() screen:expect { grid = [[ #include | | - int {3:main}() | + int {8:main}() | { | - int {2:x}; | + int {7:x}; | #ifdef {5:__cplusplus} | {4:std}::{2:cout} << {2:x} << "\n"; | {6:#else} | @@ -228,9 +231,9 @@ describe('semantic token highlighting', function() screen:expect { grid = [[ #include | | - int {3:main}() | + int {8:main}() | { | - int {2:x}; | + int {7:x}; | #ifdef {5:__cplusplus} | {4:std}::{2:cout} << {2:x} << "\n"; | {6:#else} | @@ -251,9 +254,9 @@ describe('semantic token highlighting', function() screen:expect { grid = [[ #include | | - int {3:main}() | + int {8:main}() | { | - int {2:x}; | + int {7:x}; | #ifdef {5:__cplusplus} | {4:std}::{2:cout} << {2:x} << "\n"; | {6:#else} | @@ -309,9 +312,9 @@ describe('semantic token highlighting', function() screen:expect { grid = [[ #include | | - int {3:main}() | + int {8:main}() | { | - ^int {3:x}(); | + ^int {8:x}(); | #ifdef {5:__cplusplus} | {4:std}::{2:cout} << {3:x} << "\n"; | {6:#else} | @@ -489,9 +492,9 @@ describe('semantic token highlighting', function() screen:expect { grid = [[ #include | | - int {3:main}() | + int {8:main}() | { | - int {2:x}; | + int {7:x}; | #ifdef {5:__cplusplus} | {4:std}::{2:cout} << {2:x} << "\n"; | {6:#else} | @@ -513,9 +516,9 @@ describe('semantic token highlighting', function() screen:expect { grid = [[ #include | | - int {3:main}() | + int {8:main}() | { | - ^int {2:x}(); | + ^int {7:x}(); | #ifdef {5:__cplusplus} | {4:std}::{2:cout} << {2:x} << "\n"; | {6:#else} | -- cgit From 6631df9107ff0d778ca03731867c477c8591f1fc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 14 Dec 2022 23:45:31 +0800 Subject: fix(terminal): fix 'mousescroll' not respected in terminal mode (#21415) --- test/functional/terminal/mouse_spec.lua | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 899df0ac54..50c8f5e7df 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -289,7 +289,7 @@ describe(':terminal mouse', function() ]]) end) - it('wont lose focus if another window is scrolled', function() + it("won't lose focus if another window is scrolled", function() feed('<4,0><4,0>') screen:expect([[ {7: 21 }line │line30 | @@ -312,6 +312,34 @@ describe(':terminal mouse', function() ]]) end) + it("scrolling another window respects 'mousescroll'", function() + command('set mousescroll=ver:1') + feed('<4,0>') + screen:expect([[ + {7: 26 }line │line30 | + {7: 27 }line │rows: 5, cols: 25 | + {7: 28 }line │rows: 5, cols: 24 | + {7: 29 }line │mouse enabled | + {7: 30 }line │{1: } | + ========== ========== | + {3:-- TERMINAL --} | + ]]) + command('set mousescroll=ver:10') + feed('<4,0>') + screen:expect([[ + {7: 16 }line │line30 | + {7: 17 }line │rows: 5, cols: 25 | + {7: 18 }line │rows: 5, cols: 24 | + {7: 19 }line │mouse enabled | + {7: 20 }line │{1: } | + ========== ========== | + {3:-- TERMINAL --} | + ]]) + command('set mousescroll=ver:0') + feed('<4,0>') + screen:expect_unchanged() + end) + it('will lose focus if another window is clicked', function() feed('<5,1>') screen:expect([[ -- cgit From 26c918d03f5b38df900316c0601065ec1ea96264 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 15 Dec 2022 02:27:23 +0100 Subject: fix(lua): always return nil values in vim.tbl_get when no results While `return` and `return nil` are for most intents and purposes identical, there are situations where they're not. For example, calculating the amount of values via the `select()` function will yield varying results: ```lua local function nothing() return end local function null() return nil end select('#', nothing()) -- 0 select('#', null()) -- 1 ``` `vim.tbl_get` currently returns both nil and no results, which makes it unreliable to use in certain situations without manually accounting for these discrepancies. --- test/functional/lua/vim_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index e390619a5a..90eccc49c8 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -512,6 +512,8 @@ describe('lua stdlib', function() eq(NIL, exec_lua("return vim.tbl_get({ unindexable = function () end }, 'unindexable', 'missing_key')")) eq(NIL, exec_lua("return vim.tbl_get({}, 'missing_key')")) eq(NIL, exec_lua("return vim.tbl_get({})")) + eq(1, exec_lua("return select('#', vim.tbl_get({}))")) + eq(1, exec_lua("return select('#', vim.tbl_get({ nested = {} }, 'nested', 'missing_key'))")) end) it('vim.tbl_extend', function() -- cgit From 72a19b2ffe93ab20f6ff1825e11b43da4e44842a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 16 Dec 2022 08:54:13 +0800 Subject: fix(api): "emsg_silent" should imply "silent" in nvim_cmd (#21438) --- test/functional/api/vim_spec.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 5677990525..531b9cc2c1 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3853,14 +3853,16 @@ describe('API', function() eq("", meths.cmd({ cmd = "Foo", bang = false }, { output = true })) end) it('works with modifiers', function() - -- with :silent output is still captured + -- with silent = true output is still captured eq('1', meths.cmd({ cmd = 'echomsg', args = { '1' }, mods = { silent = true } }, { output = true })) -- but message isn't added to message history eq('', meths.cmd({ cmd = 'messages' }, { output = true })) + meths.create_user_command("Foo", 'set verbose', {}) eq(" verbose=1", meths.cmd({ cmd = "Foo", mods = { verbose = 1 } }, { output = true })) + meths.create_user_command("Mods", "echo ''", {}) eq('keepmarks keeppatterns silent 3verbose aboveleft horizontal', meths.cmd({ cmd = "Mods", mods = { @@ -3872,6 +3874,7 @@ describe('API', function() verbose = 3, } }, { output = true })) eq(0, meths.get_option_value("verbose", {})) + command('edit foo.txt | edit bar.txt') eq(' 1 #h "foo.txt" line 1', meths.cmd({ cmd = "buffers", mods = { filter = { pattern = "foo", force = false } } }, @@ -3879,6 +3882,13 @@ describe('API', function() eq(' 2 %a "bar.txt" line 1', meths.cmd({ cmd = "buffers", mods = { filter = { pattern = "foo", force = true } } }, { output = true })) + + -- with emsg_silent = true error is suppresed + 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 + feed(':call') + eq('E471: Argument required', meths.cmd({ cmd = 'messages' }, { output = true })) end) it('works with magic.file', function() exec_lua([[ -- cgit From ef91146efcece1b6d97152251e7137d301146189 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 14 Dec 2022 10:46:54 +0100 Subject: feat: `vim.inspect_pos`, `vim.show_pos`, `:Inspect` --- test/functional/lua/inspector_spec.lua | 56 +++++++++++++++++++++++++++ test/functional/treesitter/highlight_spec.lua | 4 +- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 test/functional/lua/inspector_spec.lua (limited to 'test/functional') diff --git a/test/functional/lua/inspector_spec.lua b/test/functional/lua/inspector_spec.lua new file mode 100644 index 0000000000..5e488bb082 --- /dev/null +++ b/test/functional/lua/inspector_spec.lua @@ -0,0 +1,56 @@ +local helpers = require('test.functional.helpers')(after_each) +local exec_lua = helpers.exec_lua +local eq = helpers.eq +local eval = helpers.eval +local clear = helpers.clear + +describe('vim.inspect_pos', function() + before_each(function() + clear() + end) + + it('it returns items', function() + local ret = exec_lua([[ + local buf = vim.api.nvim_create_buf(true, false) + vim.api.nvim_set_current_buf(buf) + vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"}) + vim.api.nvim_buf_set_option(buf, "filetype", "lua") + vim.cmd("syntax on") + return {buf, vim.inspect_pos(0, 0, 10)} + ]]) + local buf, items = unpack(ret) + eq('', eval('v:errmsg')) + eq({ + buffer = buf, + col = 10, + row = 0, + extmarks = {}, + treesitter = {}, + semantic_tokens = {}, + syntax = { + { + hl_group = 'luaNumber', + hl_group_link = 'Constant', + }, + }, + }, items) + end) +end) + +describe('vim.show_pos', function() + before_each(function() + clear() + end) + + it('it does not error', function() + exec_lua([[ + local buf = vim.api.nvim_create_buf(true, false) + vim.api.nvim_set_current_buf(buf) + vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"}) + vim.api.nvim_buf_set_option(buf, "filetype", "lua") + vim.cmd("syntax on") + return {buf, vim.show_pos(0, 0, 10)} + ]]) + eq('', eval('v:errmsg')) + end) +end) diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index ae3f42ff0a..2a2311c0fa 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -605,8 +605,8 @@ describe('treesitter highlighting', function() }} eq({ - {capture='Error', metadata = { priority='101' }}; - {capture='type', metadata = { } }; + {capture='Error', metadata = { priority='101' }, lang='c' }; + {capture='type', metadata = { }, lang='c' }; }, exec_lua [[ return vim.treesitter.get_captures_at_pos(0, 0, 2) ]]) end) -- cgit From 1743359235206cbd9da2e0589f1caba37cce3b8c Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Sun, 18 Dec 2022 03:19:15 +0100 Subject: fix(diagnostic): clear stale cache on reset (#21454) The BufWipeout autocmd is not 100% reliable and may leave stale entries in the cache. This is sort of a hack/workaround to ensure `vim.diagnostic.reset` calls don't fail if there are stale cache entries but instead clears them Fixes errors like Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/diagnostic.lua:1458: Invalid buffer id: 22 stack traceback: [C]: in function 'nvim_exec_autocmds' /usr/share/nvim/runtime/lua/vim/diagnostic.lua:1458: in function 'reset' --- test/functional/lua/diagnostic_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index b7fe39cc91..4e80231747 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -160,6 +160,24 @@ describe('vim.diagnostic', function() ]]) end) + it('removes diagnostic from stale cache on reset', function() + local diagnostics = exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Diagnostic #1', 1, 1, 1, 1), + make_error('Diagnostic #2', 2, 1, 2, 1), + }) + local other_bufnr = vim.fn.bufadd('test | test') + vim.cmd('noautocmd bwipeout! ' .. diagnostic_bufnr) + return vim.diagnostic.get(diagnostic_bufnr) + ]] + eq(2, #diagnostics) + diagnostics = exec_lua [[ + vim.diagnostic.reset() + return vim.diagnostic.get() + ]] + eq(0, #diagnostics) + end) + it('resolves buffer number 0 to the current buffer', function() eq(2, exec_lua [[ vim.api.nvim_set_current_buf(diagnostic_bufnr) -- cgit From f4d8e992bfcd6e9d0097b9d7a022060bd32f2069 Mon Sep 17 00:00:00 2001 From: tiagovla <30515389+tiagovla@users.noreply.github.com> Date: Mon, 19 Dec 2022 05:24:27 -0300 Subject: fix(lsp): token_edit.data might be null on deletion (#21462) --- .../functional/plugin/lsp/semantic_tokens_spec.lua | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index e62a6f7086..547e34d12a 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -1109,7 +1109,36 @@ int main() extmark_added = true, } }, - } + }, + { + it = 'optional token_edit.data on deletion', + legend = [[{ + "tokenTypes": [ + "comment", "keyword", "operator", "string", "number", "regexp", "type", "class", "interface", "enum", "enumMember", "typeParameter", "function", "method", "property", "variable", "parameter", "module", "intrinsic", "selfParameter", "clsParameter", "magicFunction", "builtinConstant", "parenthesis", "curlybrace", "bracket", "colon", "semicolon", "arrow" + ], + "tokenModifiers": [ + "declaration", "static", "abstract", "async", "documentation", "typeHint", "typeHintComment", "readonly", "decorator", "builtin" + ] + }]], + text1 = [[string = "test"]], + text2 = [[]], + response1 = [[{"data": [0, 0, 6, 15, 1], "resultId": "1"}]], + response2 = [[{"edits": [{ "start": 0, "deleteCount": 5 }], "resultId": "2"}]], + expected1 = { + { + line = 0, + modifiers = { + 'declaration', + }, + start_col = 0, + end_col = 6, + type = 'variable', + extmark_added = true, + } + }, + expected2 = { + }, + }, }) do it(test.it, function() exec_lua(create_server_definition) -- cgit From 03166838abf23e3c2de55333fb2b9b0af34a2c56 Mon Sep 17 00:00:00 2001 From: Munif Tanjim Date: Tue, 20 Dec 2022 06:38:24 +0600 Subject: test(exrc): add tests for .nvimrc and .nvim.lua (#21478) --- test/functional/core/startup_spec.lua | 97 ++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 41 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 41596f5416..7664401824 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -581,15 +581,26 @@ describe('user config init', function() local exrc_path = '.exrc' local xstate = 'Xstate' + local function setup_exrc_file(filename) + exrc_path = filename + + if string.find(exrc_path, "%.lua$") then + write_file(exrc_path, string.format([[ + vim.g.exrc_file = "%s" + ]], exrc_path)) + else + write_file(exrc_path, string.format([[ + let g:exrc_file = "%s" + ]], exrc_path)) + end + end + before_each(function() write_file(init_lua_path, [[ vim.o.exrc = true - vim.g.from_exrc = 0 + vim.g.exrc_file = '---' ]]) mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) - write_file(exrc_path, [[ - let g:from_exrc = 1 - ]]) end) after_each(function() @@ -597,43 +608,47 @@ describe('user config init', function() rmdir(xstate) end) - it('loads .exrc #13501', function() - clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } - -- The .exrc file is not trusted, and the prompt is skipped because there is no UI. - eq(0, eval('g:from_exrc')) - - local screen = Screen.new(50, 8) - screen:attach() - funcs.termopen({nvim_prog}) - screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) - -- `i` to enter Terminal mode, `a` to allow - feed('ia') - screen:expect([[ - | - ~ | - ~ | - ~ | - ~ | - [No Name] 0,0-1 All| - | - -- TERMINAL -- | - ]]) - feed(':echo g:from_exrc') - screen:expect([[ - | - ~ | - ~ | - ~ | - ~ | - [No Name] 0,0-1 All| - 1 | - -- TERMINAL -- | - ]]) - - clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } - -- The .exrc file is now trusted. - eq(1, eval('g:from_exrc')) - end) + for _, filename in ipairs({ '.exrc', '.nvimrc', '.nvim.lua' }) do + it('loads ' .. filename, function () + setup_exrc_file(filename) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The 'exrc' file is not trusted, and the prompt is skipped because there is no UI. + eq('---', eval('g:exrc_file')) + + local screen = Screen.new(50, 8) + screen:attach() + funcs.termopen({nvim_prog}) + screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') }) + -- `i` to enter Terminal mode, `a` to allow + feed('ia') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + | + -- TERMINAL -- | + ]]) + feed(':echo g:exrc_file') + screen:expect(string.format([[ + | + ~ | + ~ | + ~ | + ~ | + [No Name] 0,0-1 All| + %s%s| + -- TERMINAL -- | + ]], filename, string.rep(' ', 50 - #filename))) + + clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } } + -- The 'exrc' file is now trusted. + eq(filename, eval('g:exrc_file')) + end) + end end) describe('with explicitly provided config', function() -- cgit From fb5576c2d36464b55c2c639aec9259a6f2461970 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 13 Dec 2022 13:59:31 +0000 Subject: feat(fs): add opts argument to vim.fs.dir() Added option depth to allow recursively searching a directory tree. --- test/functional/lua/fs_spec.lua | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 88ad6ba24a..5db92ca174 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -141,6 +141,74 @@ describe('vim.fs', function() return false ]], nvim_dir, nvim_prog_basename)) end) + + it('works with opts.depth and opts.skip', function() + helpers.funcs.system 'mkdir -p testd/a/b/c' + helpers.funcs.system('touch '..table.concat({ + 'testd/a1', + 'testd/b1', + 'testd/c1', + 'testd/a/a2', + 'testd/a/b2', + 'testd/a/c2', + 'testd/a/b/a3', + 'testd/a/b/b3', + 'testd/a/b/c3', + 'testd/a/b/c/a4', + 'testd/a/b/c/b4', + 'testd/a/b/c/c4', + }, ' ')) + + local function run(dir, depth, skip) + local r = exec_lua([[ + local dir, depth, skip = ... + local r = {} + local skip_f + if skip then + skip_f = function(n) + if vim.tbl_contains(skip or {}, n) then + return false + end + end + end + for name, type_ in vim.fs.dir(dir, { depth = depth, skip = skip_f }) do + r[name] = type_ + end + return r + ]], dir, depth, skip) + return r + end + + local exp = {} + + exp['a1'] = 'file' + exp['b1'] = 'file' + exp['c1'] = 'file' + exp['a'] = 'directory' + + eq(exp, run('testd', 1)) + + exp['a/a2'] = 'file' + exp['a/b2'] = 'file' + exp['a/c2'] = 'file' + exp['a/b'] = 'directory' + + eq(exp, run('testd', 2)) + + exp['a/b/a3'] = 'file' + exp['a/b/b3'] = 'file' + exp['a/b/c3'] = 'file' + exp['a/b/c'] = 'directory' + + eq(exp, run('testd', 3)) + eq(exp, run('testd', 999, {'a/b/c'})) + + exp['a/b/c/a4'] = 'file' + exp['a/b/c/b4'] = 'file' + exp['a/b/c/c4'] = 'file' + + eq(exp, run('testd', 999)) + end) end) describe('find()', function() -- cgit From b42d8a43b9f1b3316e73108ebefc4850b1a2c65b Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 16 Dec 2022 13:50:12 +0100 Subject: refactor(tui): use nvim_echo() for verbose terminfo This is needed for #18375 for the obvious reasons. note: verbose_terminfo_event is only temporarily needed until the full TUI process refactor is merged. --- test/functional/ui/options_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional') diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua index 6f9cea8f24..9d20229ce1 100644 --- a/test/functional/ui/options_spec.lua +++ b/test/functional/ui/options_spec.lua @@ -24,6 +24,7 @@ describe('UI receives option updates', function() termguicolors=false, ttimeout=true, ttimeoutlen=50, + verbose=0, ext_cmdline=false, ext_popupmenu=false, ext_tabline=false, -- cgit From 6e0082b356821825faef643b96f4d21684ce2f6c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 22 Dec 2022 14:19:35 +0000 Subject: fix(ci): skip test on windows (#21502) --- test/functional/lua/fs_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 5db92ca174..02b1b6f027 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -143,6 +143,9 @@ describe('vim.fs', function() end) it('works with opts.depth and opts.skip', function() + if is_os('win') then + pending() + end helpers.funcs.system 'mkdir -p testd/a/b/c' helpers.funcs.system('touch '..table.concat({ 'testd/a1', -- cgit From 98daaa798e018071876d026a60840991be8d8069 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Dec 2022 22:46:07 +0800 Subject: test(lua/fs_spec): fix vim.fs.dir() test (#21503) --- test/functional/lua/fs_spec.lua | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'test/functional') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 02b1b6f027..20a1660b0e 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local lfs = require('lfs') local clear = helpers.clear local exec_lua = helpers.exec_lua @@ -130,6 +131,17 @@ describe('vim.fs', function() end) describe('dir()', function() + before_each(function() + lfs.mkdir('testd') + lfs.mkdir('testd/a') + lfs.mkdir('testd/a/b') + lfs.mkdir('testd/a/b/c') + end) + + after_each(function() + rmdir('testd') + end) + it('works', function() eq(true, exec_lua([[ local dir, nvim = ... @@ -143,24 +155,18 @@ describe('vim.fs', function() end) it('works with opts.depth and opts.skip', function() - if is_os('win') then - pending() - end - helpers.funcs.system 'mkdir -p testd/a/b/c' - helpers.funcs.system('touch '..table.concat({ - 'testd/a1', - 'testd/b1', - 'testd/c1', - 'testd/a/a2', - 'testd/a/b2', - 'testd/a/c2', - 'testd/a/b/a3', - 'testd/a/b/b3', - 'testd/a/b/c3', - 'testd/a/b/c/a4', - 'testd/a/b/c/b4', - 'testd/a/b/c/c4', - }, ' ')) + io.open('testd/a1', 'w'):close() + io.open('testd/b1', 'w'):close() + io.open('testd/c1', 'w'):close() + io.open('testd/a/a2', 'w'):close() + io.open('testd/a/b2', 'w'):close() + io.open('testd/a/c2', 'w'):close() + io.open('testd/a/b/a3', 'w'):close() + io.open('testd/a/b/b3', 'w'):close() + io.open('testd/a/b/c3', 'w'):close() + io.open('testd/a/b/c/a4', 'w'):close() + io.open('testd/a/b/c/b4', 'w'):close() + io.open('testd/a/b/c/c4', 'w'):close() local function run(dir, depth, skip) local r = exec_lua([[ -- cgit From 30f606fc602f835fbed869140d3d658e24129c22 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 23 Dec 2022 13:56:32 +0800 Subject: fix(options): restore exists() behavior for options (#21510) Duplicating get_option_value() logic for an obscure future refactor isn't really worthwhile, and findoption() isn't used anywhere else outside the options code. --- test/functional/ui/highlight_spec.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 8dd1091353..288c2a214f 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -6,6 +6,7 @@ local command, exec = helpers.command, helpers.exec local eval = helpers.eval local feed_command, eq = helpers.feed_command, helpers.eq local curbufmeths = helpers.curbufmeths +local funcs = helpers.funcs local meths = helpers.meths describe('colorscheme compatibility', function() @@ -13,7 +14,9 @@ describe('colorscheme compatibility', function() clear() end) - it('t_Co is set to 256 by default', function() + it('&t_Co exists and is set to 256 by default', function() + eq(1, funcs.exists('&t_Co')) + eq(1, funcs.exists('+t_Co')) eq('256', eval('&t_Co')) end) end) -- cgit From 357aab4c65c49a924481a67e17a10bd04c334ab9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Dec 2022 11:20:37 +0800 Subject: fix(mappings): use all buckets in second round of unmap (#21534) --- test/functional/ex_cmds/map_spec.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index dd9f7027cf..ec912053b2 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local eq = helpers.eq local exec = helpers.exec +local exec_capture = helpers.exec_capture local feed = helpers.feed local meths = helpers.meths local clear = helpers.clear @@ -30,12 +31,12 @@ describe(':*map', function() expect('-foo-') end) - it('shows as mapping rhs', function() + it('shows as mapping rhs', function() command('nmap asdf ') eq([[ n asdf ]], - helpers.exec_capture('nmap asdf')) + exec_capture('nmap asdf')) end) it('mappings with description can be filtered', function() @@ -48,7 +49,7 @@ n asdf3 qwert do the other thing n asdf1 qwert do the one thing]], - helpers.exec_capture('filter the nmap')) + exec_capture('filter the nmap')) end) it(' mappings ignore nore', function() @@ -84,6 +85,12 @@ n asdf1 qwert eq(2, meths.eval('x')) eq('Some te', eval("getline('.')")) end) + + it(':unmap with rhs works when lhs is in another bucket #21530', function() + command('map F Foo') + command('unmap Foo') + eq('\nNo mapping found', exec_capture('map F')) + end) end) describe('Screen', function() -- cgit From 5b89d480e30367259f82680945572b1406219da5 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 15 Dec 2022 21:23:28 +0100 Subject: vim-patch:9.0.1061: cannot display 'showcmd' somewhere else Problem: Cannot display 'showcmd' somewhere else. Solution: Add the 'showcmdloc' option. (Luuk van Baal, closes vim/vim#11684) https://github.com/vim/vim/commit/ba936f6f4e85cc1408bc3967f9fd7665d948909b Co-authored-by: Luuk van Baal --- test/functional/legacy/statusline_spec.lua | 47 ++++++++++++++++++++++++++ test/functional/legacy/tabline_spec.lua | 53 ++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 test/functional/legacy/tabline_spec.lua (limited to 'test/functional') diff --git a/test/functional/legacy/statusline_spec.lua b/test/functional/legacy/statusline_spec.lua index e2b30a7c82..056209154e 100644 --- a/test/functional/legacy/statusline_spec.lua +++ b/test/functional/legacy/statusline_spec.lua @@ -68,4 +68,51 @@ describe('statusline', function() | ]]) end) + + -- oldtest: Test_statusline_showcmd() + it('showcmdloc=statusline works', function() + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.LightGrey}, -- Visual + [2] = {bold = true}, -- MoreMsg + [3] = {bold = true, reverse = true}, -- StatusLine + }) + exec([[ + set showcmd + set laststatus=2 + set statusline=%S + set showcmdloc=statusline + call setline(1, ['a', 'b', 'c']) + ]]) + feed('Gl') + screen:expect([[ + {1:a} | + {1:b} | + {1:c}^ | + {0:~ }| + {0:~ }| + {3:3x2 }| + {2:-- VISUAL BLOCK --} | + ]]) + feed('1234') + screen:expect([[ + a | + b | + ^c | + {0:~ }| + {0:~ }| + {3:1234 }| + | + ]]) + feed(':set statusline=:1234') + screen:expect([[ + a | + b | + ^c | + {0:~ }| + {0:~ }| + {3:[No Name] [+] 1234 }| + : | + ]]) + end) end) diff --git a/test/functional/legacy/tabline_spec.lua b/test/functional/legacy/tabline_spec.lua new file mode 100644 index 0000000000..d858f137c5 --- /dev/null +++ b/test/functional/legacy/tabline_spec.lua @@ -0,0 +1,53 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local exec = helpers.exec +local feed = helpers.feed + +before_each(clear) + +describe('tabline', function() + local screen + + before_each(function() + screen = Screen.new(50, 7) + screen:attach() + end) + + -- oldtest: Test_tabline_showcmd() + it('showcmdloc=tabline works', function() + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.LightGrey}, -- Visual + [2] = {bold = true}, -- MoreMsg, TabLineSel + [3] = {reverse = true}, -- TabLineFill + [4] = {background = Screen.colors.LightGrey, underline = true}, -- TabLine + }) + exec([[ + set showcmd + set showtabline=2 + set showcmdloc=tabline + call setline(1, ['a', 'b', 'c']) + ]]) + feed('Gl') + screen:expect([[ + {2: + [No Name] }{3: }{4:3x2}{3: }| + {1:a} | + {1:b} | + {1:c}^ | + {0:~ }| + {0:~ }| + {2:-- VISUAL BLOCK --} | + ]]) + feed('1234') + screen:expect([[ + {2: + [No Name] }{3: }{4:1234}{3: }| + a | + b | + ^c | + {0:~ }| + {0:~ }| + | + ]]) + end) +end) -- cgit From 94ce25065bb709794904b8ee96c1144006520750 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Dec 2022 14:04:46 +0800 Subject: fix(showcmd): assert failure with cmdheight=0 (#21536) --- test/functional/ui/cmdline_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index c73c2d9f8a..1bdd55d66b 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1351,4 +1351,17 @@ describe('cmdheight=0', function() {1:~ }│{1:~ }| ]]) end) + + it('no assert failure with showcmd', function() + command('set showcmd cmdheight=0') + feed('d') + screen:expect([[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]) + assert_alive() + end) end) -- cgit From d4af8c6202e8734ef4a3a3dfe249353f8d5ba551 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Dec 2022 11:13:58 +0800 Subject: fix(statusline): don't show showcmd when not enough space (#21550) --- test/functional/ui/statusline_spec.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua index 18391a575d..549ebbde06 100644 --- a/test/functional/ui/statusline_spec.lua +++ b/test/functional/ui/statusline_spec.lua @@ -545,3 +545,29 @@ it('statusline is redrawn with :resize from mapping #19629', function() | ]]) end) + +it('showcmdloc=statusline does not show if statusline is too narrow', function() + clear() + local screen = Screen.new(40, 8) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {bold = true, reverse = true}, -- StatusLine + [2] = {reverse = true}, -- StatusLineNC + }) + screen:attach() + command('set showcmd') + command('set showcmdloc=statusline') + command('1vsplit') + screen:expect([[ + ^ │ | + {0:~}│{0:~ }| + {0:~}│{0:~ }| + {0:~}│{0:~ }| + {0:~}│{0:~ }| + {0:~}│{0:~ }| + {1:< }{2:[No Name] }| + | + ]]) + feed('1234') + screen:expect_unchanged() +end) -- cgit From cd6ec1db068f9f4c1900a00b5392e39e59f0a7cb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Dec 2022 17:29:05 +0800 Subject: fix(win_close): remove float grid after closing buffer (#21551) It is not safe to remove the float grid when autocommands can still be triggered, as autocommands may use the float grid. --- test/functional/ui/float_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index bb09cfd504..ab87384194 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -8831,6 +8831,34 @@ describe('float window', function() ]]} end end) + + describe('no crash after moving and closing float window #21547', function() + local function test_float_move_close(cmd) + local float_opts = {relative = 'editor', row = 1, col = 1, width = 10, height = 10} + meths.open_win(meths.create_buf(false, false), true, float_opts) + if multigrid then + screen:expect({float_pos = {[4] = {{id = 1001}, 'NW', 1, 1, 1, true}}}) + end + command(cmd) + exec_lua([[ + vim.api.nvim_win_set_config(0, {relative = 'editor', row = 2, col = 2}) + vim.api.nvim_win_close(0, {}) + vim.api.nvim_echo({{''}}, false, {}) + ]]) + if multigrid then + screen:expect({float_pos = {}}) + end + assert_alive() + end + + it('if WinClosed autocommand flushes UI', function() + test_float_move_close('autocmd WinClosed * ++once redraw') + end) + + it('if closing buffer flushes UI', function() + test_float_move_close('autocmd BufWinLeave * ++once redraw') + end) + end) end describe('with ext_multigrid', function() -- cgit From 146c428a533b649adbc95fc29b41af42624b6ece Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Dec 2022 18:04:42 +0800 Subject: fix(statusline): make nvim_eval_statusline() work with %S (#21553) --- test/functional/api/vim_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 531b9cc2c1..98bfb83dbd 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3126,6 +3126,19 @@ describe('API', function() eq('E539: Illegal character <}>', pcall_err(meths.eval_statusline, '%{%}', {})) end) + it('supports %S item', function() + local screen = Screen.new(80, 24) + screen:attach() + command('set showcmd') + feed('1234') + screen:expect({any = '1234'}) + eq({ str = '1234', width = 4 }, + meths.eval_statusline('%S', { maxwidth = 5 })) + feed('56') + screen:expect({any = '123456'}) + eq({ str = '<3456', width = 5 }, + meths.eval_statusline('%S', { maxwidth = 5 })) + end) describe('highlight parsing', function() it('works', function() eq({ -- cgit From e6cae44cbf44d623bc89eb3323da043249c0f052 Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Thu, 29 Dec 2022 03:01:40 +1100 Subject: feat(highlight): add DiagnosticOk (and associated) highlight groups (#21286) The existing groups, Error, Hint, Info, Warn cover many use cases, but neglect the occasion where a diagnostic message should communicate a non-informative (not a Hint or Info) event. DiagnosticOk covers this with a generic green colorscheme. --- test/functional/lua/diagnostic_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 4e80231747..946994fd97 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -90,20 +90,25 @@ describe('vim.diagnostic', function() 'DiagnosticFloatingError', 'DiagnosticFloatingHint', 'DiagnosticFloatingInfo', + 'DiagnosticFloatingOk', 'DiagnosticFloatingWarn', 'DiagnosticHint', 'DiagnosticInfo', + 'DiagnosticOk', 'DiagnosticSignError', 'DiagnosticSignHint', 'DiagnosticSignInfo', + 'DiagnosticSignOk', 'DiagnosticSignWarn', 'DiagnosticUnderlineError', 'DiagnosticUnderlineHint', 'DiagnosticUnderlineInfo', + 'DiagnosticUnderlineOk', 'DiagnosticUnderlineWarn', 'DiagnosticVirtualTextError', 'DiagnosticVirtualTextHint', 'DiagnosticVirtualTextInfo', + 'DiagnosticVirtualTextOk', 'DiagnosticVirtualTextWarn', 'DiagnosticWarn', }, exec_lua([[return vim.fn.getcompletion('Diagnostic', 'highlight')]])) -- cgit From d0dd8d11bf596b9310afd465a723696ac348d83a Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 29 Dec 2022 07:20:42 +0800 Subject: test: remove unused variable (#21552) --- test/functional/preload.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/preload.lua b/test/functional/preload.lua index e225854de3..6a5a2e907e 100644 --- a/test/functional/preload.lua +++ b/test/functional/preload.lua @@ -2,7 +2,7 @@ -- Busted started doing this to help provide more isolation. See issue #62 -- for more information about this. local helpers = require('test.functional.helpers')(nil) -local screen = require('test.functional.ui.screen') +require('test.functional.ui.screen') local busted = require("busted") local is_os = helpers.is_os -- cgit From 05b6dd6e5f543083ebca581506398a8c263a2db6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 29 Dec 2022 07:55:26 +0800 Subject: test(lsp): add a screen:expect() between insert() and feed_command() (#21577) The insert() and feed_command() type a lot of text, with only one screen:expect() call after the feed_command() it may time out. --- test/functional/plugin/lsp/semantic_tokens_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 547e34d12a..9c1ba86fe1 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -307,6 +307,24 @@ describe('semantic token highlighting', function() ]]) insert(text) + screen:expect { grid = [[ + #include | + | + int {8:main}() | + { | + int {7:x}; | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } feed_command('%s/int x/int x()/') feed_command('noh') screen:expect { grid = [[ -- cgit From b640161a694037299f44c26893bba22d17b6853f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 29 Dec 2022 14:13:54 +0800 Subject: test(tui_spec): don't use nested terminal for resize at startup (#21583) --- test/functional/terminal/tui_spec.lua | 48 ++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index b3d2625d78..1807001842 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -13,6 +13,7 @@ local feed_command = helpers.feed_command local feed_data = thelpers.feed_data local clear = helpers.clear local command = helpers.command +local exec = helpers.exec local testprg = helpers.testprg local retry = helpers.retry local nvim_prog = helpers.nvim_prog @@ -90,24 +91,6 @@ describe('TUI', function() assert_alive() end) - it('resize at startup', function() - -- Issues: #17285 #15044 #11330 - screen:try_resize(50, 10) - feed_command([[call termopen([v:progpath, '--clean', '--cmd', 'let start = reltime() | while v:true | if reltimefloat(reltime(start)) > 2 | break | endif | endwhile']) | sleep 500m | vs new]]) - screen:expect([[ - {1: } │ | - {4:~ }│{4:~ }| - {4:~ }│{4:~ }| - {4:~ }│{4:~ }| - {4:~ }│{4:~ }| - {4:~ }│{5:[No Name] 0,0-1 All}| - {4:~ }│ | - {5:new }{MATCH:<.*[/\]nvim }| - | - {3:-- TERMINAL --} | - ]]) - end) - it('accepts resize while pager is active', function() child_session:request("nvim_command", [[ set more @@ -1437,6 +1420,35 @@ describe('TUI', function() os.remove('testF') end) + it('resize at startup #17285 #15044 #11330', function() + local screen = Screen.new(50, 10) + screen:set_default_attr_ids({ + [1] = {reverse = true}, + [2] = {bold = true, foreground = Screen.colors.Blue}, + [3] = {bold = true}, + [4] = {foreground = tonumber('0x4040ff'), fg_indexed = true}, + [5] = {bold = true, reverse = true}, + }) + screen:attach() + exec([[ + call termopen([v:progpath, '--clean', '--cmd', 'let start = reltime() | while v:true | if reltimefloat(reltime(start)) > 2 | break | endif | endwhile']) + sleep 500m + vs new + ]]) + screen:expect([[ + ^ │ | + {2:~ }│{4:~ }| + {2:~ }│{4:~ }| + {2:~ }│{4:~ }| + {2:~ }│{4:~ }| + {2:~ }│{4:~ }| + {2:~ }│{5:[No Name] 0,0-1 All}| + {2:~ }│ | + {5:new }{MATCH:<.*[/\]nvim }| + | + ]]) + end) + it('with non-tty (pipe) stdout/stderr', function() local screen = thelpers.screen_setup(0, '"'..nvim_prog ..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"') -- cgit From d7855caa183f9eacc7cfd3f2ab7f071063ff84af Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 30 Dec 2022 15:06:47 +0800 Subject: test: add test for setting &columns from modeline with tabpages --- test/functional/core/startup_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 7664401824..9e22efa545 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -465,6 +465,19 @@ describe('startup', function() clear{args={'--cmd', 'set packpath^=test/functional/fixtures', '--cmd', [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]]}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}} eq({'ordinary', 'FANCY', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) end) + + it('window widths are correct when modelines set &columns with tabpages', function() + write_file('tab1.noft', 'vim: columns=81') + write_file('tab2.noft', 'vim: columns=81') + finally(function() + os.remove('tab1.noft') + os.remove('tab2.noft') + end) + clear({args = {'-p', 'tab1.noft', 'tab2.noft'}}) + eq(81, meths.win_get_width(0)) + command('tabnext') + eq(81, meths.win_get_width(0)) + end) end) describe('sysinit', function() -- cgit From 69163727e93e5388d6cba9e6c7e1a6e64b9268b7 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sat, 31 Dec 2022 01:30:05 +0100 Subject: test: add test cases for command line issues --- test/functional/ui/cmdline_spec.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 1bdd55d66b..8e689fb378 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1364,4 +1364,40 @@ describe('cmdheight=0', function() ]]) assert_alive() end) + + it('can only be resized to 0 if set explicitly', function() + command('set laststatus=2') + command('resize +1') + screen:expect([[ + ^ | + {1:~ }| + {1:~ }| + {2:[No Name] }| + | + ]]) + command('set cmdheight=0') + command('resize -1') + command('resize +1') + screen:expect([[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {2:[No Name] }| + ]]) + end) + + it("clears cmdline area when resized with external messages", function() + clear() + screen = new_screen({rgb=true, ext_messages=true}) + command('set laststatus=2 cmdheight=0') + command('resize -1') + screen:expect([[ + ^ | + {1:~ }| + {1:~ }| + {3:[No Name] }| + | + ]]) + end) end) -- cgit From 24488169564c39a506c235bf6a33b8e23a8cb528 Mon Sep 17 00:00:00 2001 From: hlpr98 Date: Mon, 27 May 2019 22:04:24 +0530 Subject: feat(tui): run TUI as external process --- test/functional/terminal/tui_spec.lua | 170 +++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 1807001842..0ede6c9978 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -24,6 +24,8 @@ local funcs = helpers.funcs local meths = helpers.meths local is_ci = helpers.is_ci local is_os = helpers.is_os +local spawn = helpers.spawn +local set_session = helpers.set_session if helpers.skip(helpers.is_os('win')) then return end @@ -1365,7 +1367,7 @@ describe('TUI', function() | {4:~ }| {5: }| - [[['chan', 0], ['height', 6], ['override', v:false| + [[['chan', 1], ['height', 6], ['override', v:false| ], ['rgb', v:false], ['width', 50]]] | {10:Press ENTER or type command to continue}{1: } | {3:-- TERMINAL --} | @@ -2164,3 +2166,169 @@ describe('TUI bg color', function() screen:expect{any='new_bg=dark'} end) end) + +-- These tests require `thelpers` because --headless/--embed +-- does not initialize the TUI. +describe("TUI as a client", function() + + it("connects to remote instance (full)", function() + clear() + local server_super = spawn(helpers.nvim_argv) + local client_super = spawn(helpers.nvim_argv) + + set_session(server_super, true) + screen_server = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--listen", "127.0.0.1:7777"]') + + helpers.feed("iHello, World") + + set_session(client_super, true) + screen = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.1:7777"]') + + screen.timeout = 1000 + screen:expect([[ + Hello, Worl{1:d} | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] 1,12 All}| + | + {3:-- TERMINAL --} | + ]]) + + feed_data(":q!\n") + + -- tear down + helpers.feed(":q!") + set_session(server_super, true) + helpers.feed(":q!") + server_super:close() + client_super:close() + end) + + it("connects to remote instance (--headless)", function() + local server = spawn({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--listen', '127.0.0.1:7777', '-c', ":%! echo 'Hello, World'" }) + -- wait till the server session starts + helpers.sleep(1000) + + clear() + screen = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.1:7777"]') + + screen.timeout = 1000 + screen:expect([[ + {1:H}ello, World | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] 1,1 All}| + | + {3:-- TERMINAL --} | + ]]) + + feed_data(":q!\n") + server:close() + end) + + it("connects to remote instance (pipe)", function() + clear() + local server_super = spawn(helpers.nvim_argv) + local client_super = spawn(helpers.nvim_argv) + + set_session(server_super, true) + screen_server = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--listen", "127.0.0.119"]') + + helpers.feed("iHello, World") + + set_session(client_super, true) + screen = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.119"]') + + screen.timeout = 1000 + screen:expect([[ + Hello, Worl{1:d} | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] 1,12 All}| + | + {3:-- TERMINAL --} | + ]]) + + feed_data(":q!\n") + + -- tear down + helpers.feed(":q!") + set_session(server_super, true) + helpers.feed(":q!") + server_super:close() + client_super:close() + end) + + it("throws error when no server exists", function() + clear() + screen = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.1:7777"]') + + screen.timeout = 1000 + screen:expect([[ + Could not establish connection with remote server | + | + [Process exited 1]{1: } | + | + | + | + {3:-- TERMINAL --} | + ]]) + end) + + it("exits when server quits", function() + clear() + local server_super = spawn(helpers.nvim_argv) + local client_super = spawn(helpers.nvim_argv) + + set_session(server_super, true) + screen_server = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--listen", "127.0.0.1:7777"]') + + helpers.feed("iHello, World") + + set_session(client_super, true) + screen_client = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.1:7777"]') + + -- assert that client has connected to server + screen_client.timeout = 1000 + screen_client:expect([[ + Hello, Worl{1:d} | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] 1,12 All}| + | + {3:-- TERMINAL --} | + ]]) + + -- quitting the server + set_session(server_super, true) + feed_data(":q!\n") + screen_server.timeout = 1000 + screen_server:expect({any="Process exited 0"}) + + -- assert that client has exited + set_session(client_super, true) + screen_client:expect({any="Process exited 0"}) + + -- tear down + helpers.feed(":q!") + set_session(server_super, true) + helpers.feed(":q!") + server_super:close() + client_super:close() + + -- Restore the original session + set_session(spawn(helpers.nvim_argv), true) + end) +end) -- cgit From 43e8ec92de9e0850e7d202cb7ff9051bc408447e Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 2 May 2022 21:10:01 +0200 Subject: fix(tui): more work in the TUI --- test/functional/autocmd/focus_spec.lua | 23 ++- test/functional/core/main_spec.lua | 2 +- test/functional/core/startup_spec.lua | 2 +- test/functional/helpers.lua | 12 +- test/functional/terminal/api_spec.lua | 10 + test/functional/terminal/tui_spec.lua | 365 ++++++++++++++++++++------------- test/functional/ui/screen.lua | 3 +- 7 files changed, 271 insertions(+), 146 deletions(-) (limited to 'test/functional') diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua index 024dccbe8e..d7a87e17ed 100644 --- a/test/functional/autocmd/focus_spec.lua +++ b/test/functional/autocmd/focus_spec.lua @@ -33,9 +33,17 @@ describe('autoread TUI FocusGained/FocusLost', function() helpers.write_file(path, '') lfs.touch(path, os.time() - 10) - feed_command('edit '..path) - feed_data('\027[O') + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + | + {3:-- TERMINAL --} | + ]]} + feed_command('edit '..path) screen:expect{grid=[[ {1: } | {4:~ }| @@ -45,6 +53,17 @@ describe('autoread TUI FocusGained/FocusLost', function() :edit xtest-foo | {3:-- TERMINAL --} | ]]} + feed_data('\027[O') + feed_data('\027[O') + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:xtest-foo }| + :edit xtest-foo | + {3:-- TERMINAL --} | + ]], unchanged=true} helpers.write_file(path, expected_addition) diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 53461f505a..ab11e14a67 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -56,7 +56,7 @@ describe('Command-line option', function() screen:attach() local args = { nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', - '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix', + '--cmd', '"set noswapfile shortmess+=IFW fileformats=unix"', '-s', '-' } diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 9e22efa545..72d8f3a103 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -544,7 +544,7 @@ describe('sysinit', function() nvim_exec() | cmd: aunmenu * | > | - <" -u NONE -i NONE --cmd "set noruler" -D 1,1 All| + <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| | ]]) command([[call chansend(g:id, "cont\n")]]) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index ca59eb3182..a14bedbbbd 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -243,7 +243,7 @@ function module.run_session(lsession, request_cb, notification_cb, setup_cb, tim end loop_running = true - session:run(on_request, on_notification, on_setup, timeout) + lsession:run(on_request, on_notification, on_setup, timeout) loop_running = false if last_error then local err = last_error @@ -251,7 +251,7 @@ function module.run_session(lsession, request_cb, notification_cb, setup_cb, tim error(err) end - return session.eof_err + return lsession.eof_err end function module.run(request_cb, notification_cb, setup_cb, timeout) @@ -465,8 +465,14 @@ end -- clear('-e') -- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}} function module.clear(...) + module.set_session(module.spawn_argv(false, ...)) +end + +-- same params as clear, but does returns the session instead +-- of replacing the default session +function module.spawn_argv(keep, ...) local argv, env, io_extra = module.new_argv(...) - module.set_session(module.spawn(argv, nil, env, nil, io_extra)) + return module.spawn(argv, nil, env, keep, io_extra) end -- Builds an argument list for use in clear(). diff --git a/test/functional/terminal/api_spec.lua b/test/functional/terminal/api_spec.lua index 38ef7c2a61..724791343d 100644 --- a/test/functional/terminal/api_spec.lua +++ b/test/functional/terminal/api_spec.lua @@ -19,6 +19,16 @@ describe('api', function() end) it("qa! RPC request during insert-mode", function() + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {4:~ }| + | + {3:-- TERMINAL --} | + ]]} + -- Start the socket from the child nvim. child_session.feed_data(":echo serverstart('"..socket_name.."')\n") diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 0ede6c9978..964fc8941d 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -24,8 +24,11 @@ local funcs = helpers.funcs local meths = helpers.meths local is_ci = helpers.is_ci local is_os = helpers.is_os -local spawn = helpers.spawn +local new_pipename = helpers.new_pipename +local spawn_argv = helpers.spawn_argv local set_session = helpers.set_session +local feed = helpers.feed +local eval = helpers.eval if helpers.skip(helpers.is_os('win')) then return end @@ -36,7 +39,7 @@ describe('TUI', function() before_each(function() clear() - local child_server = helpers.new_pipename() + local child_server = new_pipename() screen = thelpers.screen_setup(0, string.format([=[["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "%s laststatus=2 background=dark"]]=], nvim_prog, child_server, nvim_set)) @@ -1193,6 +1196,15 @@ describe('TUI', function() it('paste: split "start paste" code', function() feed_data('i') + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]} -- Send split "start paste" sequence. feed_data('\027[2') feed_data('00~pasted from terminal\027[201~') @@ -1209,6 +1221,15 @@ describe('TUI', function() it('paste: split "stop paste" code', function() feed_data('i') + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]} -- Send split "stop paste" sequence. feed_data('\027[200~pasted from terminal\027[20') feed_data('1~') @@ -1234,6 +1255,15 @@ describe('TUI', function() end)(vim.paste) ]], {}) feed_data('i') + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]} feed_data('\027[200~pasted') -- phase 1 screen:expect([[ pasted{1: } | @@ -1469,6 +1499,15 @@ describe('TUI', function() it(' #10134', function() local screen = thelpers.screen_setup(0, '["'..nvim_prog ..[[", "-u", "NONE", "-i", "NONE", "--cmd", "set noruler", "--cmd", ':nnoremap :echomsg "\"']]..']') + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + | + {3:-- TERMINAL --} | + ]]} command([[call chansend(b:terminal_job_id, "\")]]) screen:expect([[ @@ -1495,6 +1534,15 @@ describe('TUI UIEnter/UILeave', function() ..[[, "--cmd", "autocmd VimEnter * :call add(g:evs, 'VimEnter')"]] ..']' ) + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + | + {3:-- TERMINAL --} | + ]]} feed_data(":echo g:evs\n") screen:expect{grid=[[ {1: } | @@ -1515,61 +1563,88 @@ describe('TUI FocusGained/FocusLost', function() clear() screen = thelpers.screen_setup(0, '["'..nvim_prog ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]') - feed_data(":autocmd FocusGained * echo 'gained'\n") - feed_data(":autocmd FocusLost * echo 'lost'\n") - feed_data("\034\016") -- CTRL-\ CTRL-N - end) - - it('in normal-mode', function() - retry(2, 3 * screen.timeout, function() - feed_data('\027[I') - screen:expect([[ + screen:expect{grid=[[ {1: } | {4:~ }| {4:~ }| {4:~ }| {5:[No Name] }| - gained | + | {3:-- TERMINAL --} | - ]]) + ]]} + feed_data(":autocmd FocusGained * echo 'gained'\n") + feed_data(":autocmd FocusLost * echo 'lost'\n") + feed_data("\034\016") -- CTRL-\ CTRL-N + end) - feed_data('\027[O') - screen:expect([[ + it('in normal-mode', function() + screen:expect{grid=[[ {1: } | {4:~ }| {4:~ }| {4:~ }| {5:[No Name] }| - lost | + :autocmd FocusLost * echo 'lost' | {3:-- TERMINAL --} | - ]]) + ]]} + retry(2, 3 * screen.timeout, function() + feed_data('\027[I') + screen:expect([[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + gained | + {3:-- TERMINAL --} | + ]]) + + feed_data('\027[O') + screen:expect([[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + lost | + {3:-- TERMINAL --} | + ]]) end) end) it('in insert-mode', function() feed_command('set noshowmode') feed_data('i') - retry(2, 3 * screen.timeout, function() - feed_data('\027[I') - screen:expect([[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] }| - gained | - {3:-- TERMINAL --} | - ]]) - feed_data('\027[O') - screen:expect([[ + screen:expect{grid=[[ {1: } | {4:~ }| {4:~ }| {4:~ }| {5:[No Name] }| - lost | + :set noshowmode | {3:-- TERMINAL --} | - ]]) + ]]} + retry(2, 3 * screen.timeout, function() + feed_data('\027[I') + screen:expect([[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + gained | + {3:-- TERMINAL --} | + ]]) + feed_data('\027[O') + screen:expect([[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + lost | + {3:-- TERMINAL --} | + ]]) end) end) @@ -1606,6 +1681,15 @@ describe('TUI FocusGained/FocusLost', function() feed_data(":autocmd!\n") feed_data(":autocmd FocusLost * call append(line('$'), 'lost')\n") feed_data(":autocmd FocusGained * call append(line('$'), 'gained')\n") + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + | + {3:-- TERMINAL --} | + ]]} retry(2, 3 * screen.timeout, function() -- Enter cmdline-mode. feed_data(':') @@ -1664,9 +1748,18 @@ describe('TUI FocusGained/FocusLost', function() feed_data(":echom 'msg1'|echom 'msg2'|echom 'msg3'|echom 'msg4'|echom 'msg5'\n") -- Execute :messages to provoke the press-enter prompt. feed_data(":messages\n") + screen:expect{grid=[[ + msg1 | + msg2 | + msg3 | + msg4 | + msg5 | + {10:Press ENTER or type command to continue}{1: } | + {3:-- TERMINAL --} | + ]]} feed_data('\027[I') feed_data('\027[I') - screen:expect([[ + screen:expect{grid=[[ msg1 | msg2 | msg3 | @@ -1674,7 +1767,7 @@ describe('TUI FocusGained/FocusLost', function() msg5 | {10:Press ENTER or type command to continue}{1: } | {3:-- TERMINAL --} | - ]]) + ]], unchanged=true} end) end) @@ -2042,7 +2135,7 @@ describe("TUI", function() retry(nil, 3000, function() -- Wait for log file to be flushed. local log = read_file('Xtest_tui_verbose_log') or '' - eq('--- Terminal info --- {{{\n', string.match(log, '%-%-%- Terminal.-\n')) + eq('--- Terminal info --- {{{\n', string.match(log, '%-%-%- Terminal.-\n')) -- }}} ok(#log > 50) end) end) @@ -2171,164 +2264,160 @@ end) -- does not initialize the TUI. describe("TUI as a client", function() - it("connects to remote instance (full)", function() - clear() - local server_super = spawn(helpers.nvim_argv) - local client_super = spawn(helpers.nvim_argv) - - set_session(server_super, true) - screen_server = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--listen", "127.0.0.1:7777"]') - - helpers.feed("iHello, World") + it("connects to remote instance (with its own TUI)", function() + local server_super = spawn_argv(false) -- equivalent to clear() + local client_super = spawn_argv(true) - set_session(client_super, true) - screen = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.1:7777"]') + set_session(server_super) + local server_pipe = new_pipename() + local screen_server = thelpers.screen_setup(0, + string.format([=[["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "%s laststatus=2 background=dark"]]=], + nvim_prog, server_pipe, nvim_set)) - screen.timeout = 1000 - screen:expect([[ + feed_data("iHello, World") + screen_server:expect{grid=[[ + Hello, World{1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]} + feed_data("\027") + screen_server:expect{grid=[[ Hello, Worl{1:d} | {4:~ }| {4:~ }| {4:~ }| - {5:[No Name] [+] 1,12 All}| + {5:[No Name] [+] }| | {3:-- TERMINAL --} | - ]]) + ]]} + + set_session(client_super) + local screen_client = thelpers.screen_setup(0, + string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=], + nvim_prog, server_pipe)) + + screen_client:expect{grid=[[ + Hello, Worl{1:d} | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} | + ]]} feed_data(":q!\n") - -- tear down - helpers.feed(":q!") - set_session(server_super, true) - helpers.feed(":q!") server_super:close() client_super:close() end) it("connects to remote instance (--headless)", function() - local server = spawn({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--listen', '127.0.0.1:7777', '-c', ":%! echo 'Hello, World'" }) - -- wait till the server session starts - helpers.sleep(1000) + local server = helpers.spawn_argv(false) -- equivalent to clear() + local client_super = spawn_argv(true) - clear() - screen = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.1:7777"]') + set_session(server) + local server_pipe = eval'v:servername' + feed'iHalloj!' - screen.timeout = 1000 - screen:expect([[ - {1:H}ello, World | + set_session(client_super) + local screen = thelpers.screen_setup(0, + string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=], + nvim_prog, server_pipe)) + + screen:expect{grid=[[ + Halloj{1:!} | + {4:~ }| {4:~ }| {4:~ }| {4:~ }| - {5:[No Name] [+] 1,1 All}| | {3:-- TERMINAL --} | - ]]) + ]]} - feed_data(":q!\n") + client_super:close() server:close() end) - it("connects to remote instance (pipe)", function() + + it("throws error when no server exists", function() clear() - local server_super = spawn(helpers.nvim_argv) - local client_super = spawn(helpers.nvim_argv) + local screen = thelpers.screen_setup(0, + string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "127.0.0.1:2436546", "--remote-ui"]]=], + nvim_prog)) - set_session(server_super, true) - screen_server = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--listen", "127.0.0.119"]') + screen:try_resize(60, 7) - helpers.feed("iHello, World") + screen:expect([[ + Remote ui failed to start: {MATCH:.*}| + | + [Process exited 1]{1: } | + | + | + | + {3:-- TERMINAL --} | + ]]) + end) - set_session(client_super, true) - screen = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.119"]') + it("exits when server quits", function() + local server_super = spawn_argv(false) -- equivalent to clear() + local client_super = spawn_argv(true) - screen.timeout = 1000 - screen:expect([[ + set_session(server_super) + local server_pipe = new_pipename() + local screen_server = thelpers.screen_setup(0, + string.format([=[["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "%s laststatus=2 background=dark"]]=], + nvim_prog, server_pipe, nvim_set)) + + feed_data("iHello, World") + screen_server:expect{grid=[[ + Hello, World{1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]} + feed_data("\027") + screen_server:expect{grid=[[ Hello, Worl{1:d} | {4:~ }| {4:~ }| {4:~ }| - {5:[No Name] [+] 1,12 All}| + {5:[No Name] [+] }| | {3:-- TERMINAL --} | - ]]) - - feed_data(":q!\n") - - -- tear down - helpers.feed(":q!") - set_session(server_super, true) - helpers.feed(":q!") - server_super:close() - client_super:close() - end) - - it("throws error when no server exists", function() - clear() - screen = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.1:7777"]') + ]]} - screen.timeout = 1000 - screen:expect([[ - Could not establish connection with remote server | - | - [Process exited 1]{1: } | - | - | - | - {3:-- TERMINAL --} | - ]]) - end) + set_session(client_super) + local screen_client = thelpers.screen_setup(0, + string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=], + nvim_prog, server_pipe)) - it("exits when server quits", function() - clear() - local server_super = spawn(helpers.nvim_argv) - local client_super = spawn(helpers.nvim_argv) - - set_session(server_super, true) - screen_server = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--listen", "127.0.0.1:7777"]') - - helpers.feed("iHello, World") - - set_session(client_super, true) - screen_client = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--connect", "127.0.0.1:7777"]') - - -- assert that client has connected to server - screen_client.timeout = 1000 - screen_client:expect([[ + screen_client:expect{grid=[[ Hello, Worl{1:d} | {4:~ }| {4:~ }| {4:~ }| - {5:[No Name] [+] 1,12 All}| + {5:[No Name] [+] }| | {3:-- TERMINAL --} | - ]]) + ]]} -- quitting the server - set_session(server_super, true) + set_session(server_super) feed_data(":q!\n") - screen_server.timeout = 1000 screen_server:expect({any="Process exited 0"}) -- assert that client has exited - set_session(client_super, true) screen_client:expect({any="Process exited 0"}) - -- tear down - helpers.feed(":q!") - set_session(server_super, true) - helpers.feed(":q!") server_super:close() client_super:close() - - -- Restore the original session - set_session(spawn(helpers.nvim_argv), true) end) end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 79927273a6..3b9cce0e6f 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -1550,7 +1550,8 @@ function Screen:_get_attr_id(attr_state, attrs, hl_id) attr_state.modified = true return id end - return "UNEXPECTED "..self:_pprint_attrs(self._attr_table[hl_id][1]) + local kind = self._options.rgb and 1 or 2 + return "UNEXPECTED "..self:_pprint_attrs(self._attr_table[hl_id][kind]) else if self:_equal_attrs(attrs, {}) then -- ignore this attrs -- cgit From 6ba34e21fee2a81677e8261dfeaf24c8cd320500 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Sat, 31 Dec 2022 16:16:21 +0100 Subject: feat(lsp): add function to clear codelens (#21504) Currently once you retrieve the lenses you're pretty much stuck with them as saving new lenses is additive. Adding a dedicated method to reset lenses allows users to toggle lenses on/off which can be useful for language servers where they are noisy or expensive and you only want to see them temporary. --- test/functional/plugin/lsp/codelens_spec.lua | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua index ecc2f579b8..3d7a15a191 100644 --- a/test/functional/plugin/lsp/codelens_spec.lua +++ b/test/functional/plugin/lsp/codelens_spec.lua @@ -58,6 +58,41 @@ describe('vim.lsp.codelens', function() ]], bufnr) eq({[1] = {'Lens1', 'LspCodeLens'}}, virtual_text_chunks) + end) + + it('can clear all lens', function() + local fake_uri = "file:///fake/uri" + local bufnr = exec_lua([[ + fake_uri = ... + local bufnr = vim.uri_to_bufnr(fake_uri) + local lines = {'So', 'many', 'lines'} + vim.fn.bufload(bufnr) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) + return bufnr + ]], fake_uri) + + exec_lua([[ + local bufnr = ... + local lenses = { + { + range = { + start = { line = 0, character = 0, }, + ['end'] = { line = 0, character = 0 } + }, + command = { title = 'Lens1', command = 'Dummy' } + }, + } + vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr}) + ]], bufnr) + + local stored_lenses = exec_lua('return vim.lsp.codelens.get(...)', bufnr) + eq(1, #stored_lenses) + + exec_lua([[ + vim.lsp.codelens.clear() + ]]) + stored_lenses = exec_lua('return vim.lsp.codelens.get(...)', bufnr) + eq(0, #stored_lenses) end) end) -- cgit From 1b3c255f608a6c1a4a31bcd4a640ea6696403341 Mon Sep 17 00:00:00 2001 From: Eric Haynes Date: Tue, 3 Jan 2023 12:24:14 -0500 Subject: fix(fs): duplicate path separator #21509 Fixes #21497 --- test/functional/lua/fs_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 20a1660b0e..642d36f63a 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -230,6 +230,11 @@ describe('vim.fs', function() local dir, nvim = ... return vim.fs.find(nvim, { path = dir, type = 'file' }) ]], test_build_dir, nvim_prog_basename)) + eq({nvim_dir}, exec_lua([[ + local dir = ... + local parent, name = dir:match('^(.*/)([^/]+)$') + return vim.fs.find(name, { path = parent, upward = true, type = 'directory' }) + ]], nvim_dir)) end) it('accepts predicate as names', function() -- cgit From e88cdc9a0f9ecfa2636b04f41354f234251dd57e Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 3 Jan 2023 09:53:53 -0700 Subject: test(editorconfig): add editorconfig tests --- test/functional/plugin/editorconfig_spec.lua | 194 +++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 test/functional/plugin/editorconfig_spec.lua (limited to 'test/functional') diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua new file mode 100644 index 0000000000..f71b8088ed --- /dev/null +++ b/test/functional/plugin/editorconfig_spec.lua @@ -0,0 +1,194 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local pathsep = helpers.get_pathsep() +local curbufmeths = helpers.curbufmeths + +local testdir = 'Xtest-editorconfig' + +local function test_case(name, expected) + local filename = testdir .. pathsep .. name + command('edit ' .. filename) + for opt, val in pairs(expected) do + eq(val, curbufmeths.get_option(opt), name) + end +end + +setup(function() + helpers.mkdir_p(testdir) + helpers.write_file( + testdir .. pathsep .. '.editorconfig', + [[ + root = true + + [3_space.txt] + indent_style = space + indent_size = 3 + tab_width = 3 + + [4_space.py] + indent_style = space + indent_size = 4 + tab_width = 8 + + [space.txt] + indent_style = space + indent_size = tab + + [tab.txt] + indent_style = tab + + [4_tab.txt] + indent_style = tab + indent_size = 4 + tab_width = 4 + + [4_tab_width_of_8.txt] + indent_style = tab + indent_size = 4 + tab_width = 8 + + [lf.txt] + end_of_line = lf + + [crlf.txt] + end_of_line = crlf + + [cr.txt] + end_of_line = cr + + [utf-8.txt] + charset = utf-8 + + [utf-8-bom.txt] + charset = utf-8-bom + + [utf-16be.txt] + charset = utf-16be + + [utf-16le.txt] + charset = utf-16le + + [latin1.txt] + charset = latin1 + + [with_newline.txt] + insert_final_newline = true + + [without_newline.txt] + insert_final_newline = false + + [trim.txt] + trim_trailing_whitespace = true + + [no_trim.txt] + trim_trailing_whitespace = false + + [max_line_length.txt] + max_line_length = 42 + ]] + ) +end) + +teardown(function() + helpers.rmdir(testdir) +end) + +describe('editorconfig', function() + before_each(function() + -- Remove -u NONE so that plugins (i.e. editorconfig.lua) are loaded + clear({ args_rm = { '-u' } }) + end) + + it('sets indent options', function() + test_case('3_space.txt', { + expandtab = true, + shiftwidth = 3, + softtabstop = -1, + tabstop = 3, + }) + + test_case('4_space.py', { + expandtab = true, + shiftwidth = 4, + softtabstop = -1, + tabstop = 8, + }) + + test_case('space.txt', { + expandtab = true, + shiftwidth = 0, + softtabstop = 0, + }) + + test_case('tab.txt', { + expandtab = false, + shiftwidth = 0, + softtabstop = 0, + }) + + test_case('4_tab.txt', { + expandtab = false, + shiftwidth = 4, + softtabstop = -1, + tabstop = 4, + }) + + test_case('4_tab_width_of_8.txt', { + expandtab = false, + shiftwidth = 4, + softtabstop = -1, + tabstop = 8, + }) + end) + + it('sets end-of-line options', function() + test_case('lf.txt', { fileformat = 'unix' }) + test_case('crlf.txt', { fileformat = 'dos' }) + test_case('cr.txt', { fileformat = 'mac' }) + end) + + it('sets encoding options', function() + test_case('utf-8.txt', { fileencoding = 'utf-8', bomb = false }) + test_case('utf-8-bom.txt', { fileencoding = 'utf-8', bomb = true }) + test_case('utf-16be.txt', { fileencoding = 'utf-16', bomb = false }) + test_case('utf-16le.txt', { fileencoding = 'utf-16le', bomb = false }) + test_case('latin1.txt', { fileencoding = 'latin1', bomb = false }) + end) + + it('sets newline options', function() + test_case('with_newline.txt', { fixendofline = true, endofline = true }) + test_case('without_newline.txt', { fixendofline = false, endofline = false }) + end) + + it('respects trim_trailing_whitespace', function() + local filename = testdir .. pathsep .. 'trim.txt' + -- luacheck: push ignore 613 + local untrimmed = [[ +This line ends in whitespace +So does this one +And this one +But not this one +]] + -- luacheck: pop + local trimmed = untrimmed:gsub('%s+\n', '\n') + + helpers.write_file(filename, untrimmed) + command('edit ' .. filename) + command('write') + command('bdelete') + eq(trimmed, helpers.read_file(filename)) + + filename = testdir .. pathsep .. 'no_trim.txt' + helpers.write_file(filename, untrimmed) + command('edit ' .. filename) + command('write') + command('bdelete') + eq(untrimmed, helpers.read_file(filename)) + end) + + it('sets textwidth', function() + test_case('max_line_length.txt', { textwidth = 42 }) + end) +end) -- cgit From 5529b07316b75913188c44698aed6c0f866c5da9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 4 Jan 2023 07:17:54 +0800 Subject: fix(clipboard): show provider warning when not during batch changes #21451 It is strange that Ex commands that explicitly interact with the clipboard show provider warning, but Normal mode commands do not. --- test/functional/provider/clipboard_spec.lua | 52 ++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua index 401dc84ccc..2c5185a974 100644 --- a/test/functional/provider/clipboard_spec.lua +++ b/test/functional/provider/clipboard_spec.lua @@ -106,8 +106,53 @@ describe('clipboard', function() basic_register_test() end) - it('`:redir @+>` with invalid g:clipboard shows exactly one error #7184', - function() + it('using "+ in Normal mode with invalid g:clipboard always shows error', function() + insert('a') + command("let g:clipboard = 'bogus'") + feed('"+yl') + screen:expect([[ + ^a | + {0:~ }| + {0:~ }| + clipboard: No provider. Try ":checkhealth" or ":h clipboard". | + ]]) + feed('"+p') + screen:expect([[ + a^a | + {0:~ }| + {0:~ }| + clipboard: No provider. Try ":checkhealth" or ":h clipboard". | + ]]) + end) + + it('using clipboard=unnamedplus with invalid g:clipboard shows error once', function() + insert('a') + command("let g:clipboard = 'bogus'") + command('set clipboard=unnamedplus') + feed('yl') + screen:expect([[ + ^a | + {0:~ }| + {0:~ }| + clipboard: No provider. Try ":checkhealth" or ":h clipboard". | + ]]) + feed(':') + screen:expect([[ + ^a | + {0:~ }| + {0:~ }| + : | + ]]) + feed('p') + screen:expect([[ + a^a | + {0:~ }| + {0:~ }| + : | + ]]) + end) + + it('`:redir @+>` with invalid g:clipboard shows exactly one error #7184', function() command("let g:clipboard = 'bogus'") feed_command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END') screen:expect([[ @@ -118,8 +163,7 @@ describe('clipboard', function() ]]) end) - it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184', - function() + it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184', function() command("let g:clipboard = 'bogus'") feed_command('redir @+> | bogus_cmd | redir END') screen:expect{grid=[[ -- cgit From 936e191fef9865600af211c29ea4959ffbce81dd Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 4 Jan 2023 00:38:48 +0100 Subject: docs: fix typos (#21427) Co-authored-by: Gustavo Sampaio Co-authored-by: C.D. MacEachern Co-authored-by: Sean Dewar Co-authored-by: Tomas Nemec --- test/functional/legacy/memory_usage_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua index 8d9b28e1fc..59839157ea 100644 --- a/test/functional/legacy/memory_usage_spec.lua +++ b/test/functional/legacy/memory_usage_spec.lua @@ -166,8 +166,8 @@ describe('memory usage', function() local last = monitor_memory_usage(pid) -- The usage may be a bit less than the last value, use 80%. -- Allow for 20% tolerance at the upper limit. That's very permissive, but - -- otherwise the test fails sometimes. On Sourcehut CI with FreeBSD we need to - -- be even much more permissive. + -- otherwise the test fails sometimes. On FreeBSD we need to be even much + -- more permissive. local upper_multiplier = is_os('freebsd') and 19 or 12 local lower = before.last * 8 / 10 local upper = load_adjust((after.max + (after.last - before.last)) * upper_multiplier / 10) -- cgit From ef18c9f9b05caf1f39ed32762f53802e378f143b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 4 Jan 2023 08:39:20 +0800 Subject: test(tui_spec): avoid race between nvim_paste and nvim_input (#21639) Now that the TUI calls nvim_paste and nvim_input through RPC, the data race is much more likely, as nvim_paste is deferred while nvim_input is not. Add an expect_child_buf_lines() call to avoid the race. --- test/functional/terminal/tui_spec.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 964fc8941d..7c2269e453 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1076,8 +1076,7 @@ describe('TUI', function() wait_for_mode('i') -- "bracketed paste" feed_data('\027[200~'..expected..'\027[201~') - -- FIXME: Data race between the two feeds - if is_os('freebsd') then screen:sleep(1) end + expect_child_buf_lines({expected}) feed_data(' end') expected = expected..' end' screen:expect([[ -- cgit From 89232b8b4890824f93121483626af582f13758fe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 5 Jan 2023 00:25:25 +0800 Subject: fix(tui): make a copy of data->params before unibi_format() (#21643) Problem: When unibi_format() modifies params and data->buf overflows, unibi_format() is called again, causing the params to be modified twice. This can happen for escapes sequences that use the %i terminfo format specifier (e.g. cursor_address), which makes unibi_format() increase the param by 1. Solution: Make a copy of data->params before calling unibi_format(). --- test/functional/terminal/tui_spec.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 7c2269e453..e31f76a444 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -13,6 +13,7 @@ local feed_command = helpers.feed_command local feed_data = thelpers.feed_data local clear = helpers.clear local command = helpers.command +local dedent = helpers.dedent local exec = helpers.exec local testprg = helpers.testprg local retry = helpers.retry @@ -1443,6 +1444,31 @@ describe('TUI', function() child_session:request('nvim_call_function', 'setcellwidths', {{{0x2103, 0x2103, 1}}}) screen:expect(singlewidth_screen, attrs) end) + + it('draws correctly when cursor_address overflows #21643', function() + helpers.skip(helpers.is_ci('github'), 'FIXME: flaky on GitHub CI') + screen:try_resize(75, 60) + -- The composing character takes 3 bytes. + local composing = ('a︠'):sub(2) + -- The composed character takes 1 + 5 * 3 = 16 bytes. + local c = 'a' .. composing:rep(5) + -- Going to top-left corner needs 3 bytes. + -- With screen width 75, 4088 characters need 54 full screen lines. + -- Drawing each full screen line needs 75 * 16 + 2 = 1202 bytes (2 bytes for CR LF). + -- The incomplete screen line needs 38 * 16 + 8 + 3 = 619 bytes. + -- The whole line needs 3 + 54 * 1202 + 619 = 65530 bytes. + -- The cursor_address that comes after will overflow the 65535-byte buffer. + local line = c:rep(4088) .. ('b'):rep(8) .. '℃' + child_session:request('nvim_buf_set_lines', 0, 0, -1, true, {line, 'c'}) + screen:expect( + '{1:' .. c .. '}' .. c:rep(74) .. '|\n' .. (c:rep(75) .. '|\n'):rep(53) + .. c:rep(38) .. ('b'):rep(8) .. '℃' .. (' '):rep(28) .. '|\n' .. dedent([[ + c | + {4:~ }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} |]])) + end) end) describe('TUI', function() -- cgit From ae64772a88125153a438a0e9e43d5f6bcb4eeb28 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 5 Jan 2023 07:12:02 +0800 Subject: fix(diff): avoid restoring invalid 'foldcolumn' value (#21650) Use "0" for 'foldcolumn' when w_p_fdc_save is empty, like how "manual" is used for 'foldmethod' when w_p_fdm_save is empty. --- test/functional/ui/diff_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua index dd35f47ca1..dbdf3823ec 100644 --- a/test/functional/ui/diff_spec.lua +++ b/test/functional/ui/diff_spec.lua @@ -8,6 +8,8 @@ local insert = helpers.insert local write_file = helpers.write_file local dedent = helpers.dedent local exec = helpers.exec +local eq = helpers.eq +local meths = helpers.meths describe('Diff mode screen', function() local fname = 'Xtest-functional-diff-screen-1' @@ -1491,6 +1493,26 @@ it('Align the filler lines when changing text in diff mode', function() ]]} end) +it("diff mode doesn't restore invalid 'foldcolumn' value #21647", function() + clear() + local screen = Screen.new(60, 6) + screen:set_default_attr_ids({ + [0] = {foreground = Screen.colors.Blue, bold = true}; + }) + screen:attach() + eq('0', meths.get_option_value('foldcolumn', {})) + command('diffsplit | bd') + screen:expect([[ + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + eq('0', meths.get_option_value('foldcolumn', {})) +end) + -- oldtest: Test_diff_binary() it('diff mode works properly if file contains NUL bytes vim-patch:8.2.3925', function() clear() -- cgit From 39d70fcafd6efa9d01b88bb90cab81c393040453 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 5 Jan 2023 11:00:32 -0500 Subject: dist: generated version of ccomplete.vim (#21623) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the first PR featuring a conversion of an upstream vim9script file into a Lua file. The generated file can be found in `runtime/autoload/ccomplete.vim` in the vim repository. Below is a limited history of the changes of that file at the time of conversion. ``` ❯ git log --format=oneline runtime/autoload/ccomplete.vim c4573eb12dba6a062af28ee0b8938d1521934ce4 Update runtime files a4d131d11052cafcc5baad2273ef48e0dd4d09c5 Update runtime files 4466ad6baa22485abb1147aca3340cced4778a66 Update runtime files d1caa941d876181aae0ebebc6ea954045bf0da24 Update runtime files 20aac6c1126988339611576d425965a25a777658 Update runtime files. 30b658179962cc3c9f0a98f071b36b09a36c2b94 Updated runtime files. b6b046b281fac168a78b3eafdea9274bef06882f Updated runtime files. 00a927d62b68a3523cb1c4f9aa3f7683345c8182 Updated runtime files. 8c8de839325eda0bed68917d18179d2003b344d1 (tag: v7.2a) updated for version 7.2a ... ``` The file runtime/lua/_vim9script.lua only needs to be updated when vim9jit is updated (for any bug fixes or new features, like implementing class and interface, the latest in vim9script). Further PRs will improve the DX of generated the converted lua and tracking which files in the neovim's code base have been generated. --- test/functional/plugin/ccomplete_spec.lua | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/functional/plugin/ccomplete_spec.lua (limited to 'test/functional') diff --git a/test/functional/plugin/ccomplete_spec.lua b/test/functional/plugin/ccomplete_spec.lua new file mode 100644 index 0000000000..903f16fc73 --- /dev/null +++ b/test/functional/plugin/ccomplete_spec.lua @@ -0,0 +1,61 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local eval = helpers.eval +local feed = helpers.feed +local write_file = helpers.write_file + +describe('ccomplete#Complete', function() + setup(function() + -- Realistic tags generated from neovim source tree using `ctags -R *` + write_file( + 'Xtags', + [[ +augroup_del src/nvim/autocmd.c /^void augroup_del(char *name, bool stupid_legacy_mode)$/;" f typeref:typename:void +augroup_exists src/nvim/autocmd.c /^bool augroup_exists(const char *name)$/;" f typeref:typename:bool +augroup_find src/nvim/autocmd.c /^int augroup_find(const char *name)$/;" f typeref:typename:int +aupat_get_buflocal_nr src/nvim/autocmd.c /^int aupat_get_buflocal_nr(char *pat, int patlen)$/;" f typeref:typename:int +aupat_is_buflocal src/nvim/autocmd.c /^bool aupat_is_buflocal(char *pat, int patlen)$/;" f typeref:typename:bool +expand_get_augroup_name src/nvim/autocmd.c /^char *expand_get_augroup_name(expand_T *xp, int idx)$/;" f typeref:typename:char * +expand_get_event_name src/nvim/autocmd.c /^char *expand_get_event_name(expand_T *xp, int idx)$/;" f typeref:typename:char * +]] + ) + end) + + before_each(function() + clear() + command('set tags=Xtags') + end) + + teardown(function() + os.remove('Xtags') + end) + + it('can complete from Xtags', function() + local completed = eval('ccomplete#Complete(0, "a")') + eq(5, #completed) + eq('augroup_del(', completed[1].word) + eq('f', completed[1].kind) + + local aupat = eval('ccomplete#Complete(0, "aupat")') + eq(2, #aupat) + eq('aupat_get_buflocal_nr(', aupat[1].word) + eq('f', aupat[1].kind) + end) + + it('does not error when returning no matches', function() + local completed = eval('ccomplete#Complete(0, "doesnotmatch")') + eq({}, completed) + end) + + it('can find the beginning of a word for C', function() + command('set filetype=c') + feed('i int something = augroup') + local result = eval('ccomplete#Complete(1, "")') + eq(#' int something = ', result) + + local completed = eval('ccomplete#Complete(0, "augroup")') + eq(3, #completed) + end) +end) -- cgit From 7c94bcd2d77e2e54b8836ab8325460a367b79eae Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 20 Sep 2021 19:00:50 -0700 Subject: feat(lua)!: execute Lua with "nvim -l" Problem: Nvim has Lua but the "nvim" CLI can't easily be used to execute Lua scripts, especially scripts that take arguments or produce output. Solution: - support "nvim -l [args...]" for running scripts. closes #15749 - exit without +q - remove lua2dox_filter - remove Doxyfile. This wasn't used anyway, because the doxygen config is inlined in gen_vimdoc.py (`Doxyfile` variable). - use "nvim -l" in docs-gen CI job Examples: $ nvim -l scripts/lua2dox.lua --help Lua2DoX (0.2 20130128) ... $ echo "print(vim.inspect(_G.arg))" | nvim -l - --arg1 --arg2 $ echo 'print(vim.inspect(vim.api.nvim_buf_get_text(1,0,0,-1,-1,{})))' | nvim +"put ='text'" -l - TODO? -e executes Lua code -l loads a module -i enters REPL _after running the other arguments_. --- test/functional/core/startup_spec.lua | 149 ++++++++++++++++++++++++++++------ test/functional/fixtures/startup.lua | 34 ++++++++ 2 files changed, 157 insertions(+), 26 deletions(-) create mode 100644 test/functional/fixtures/startup.lua (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 72d8f3a103..1df8d76c97 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -26,6 +26,7 @@ local write_file = helpers.write_file local meths = helpers.meths local alter_slashes = helpers.alter_slashes local is_os = helpers.is_os +local dedent = helpers.dedent local testfile = 'Xtest_startuptime' after_each(function() @@ -47,6 +48,34 @@ describe('startup', function() assert_log("require%('vim%._editor'%)", testfile, 100) end) end) + + it('-D does not hang #12647', function() + clear() + local screen + screen = Screen.new(60, 7) + screen:attach() + command([[let g:id = termopen('"]]..nvim_prog.. + [[" -u NONE -i NONE --cmd "set noruler" -D')]]) + screen:expect([[ + ^ | + | + Entering Debug mode. Type "cont" to continue. | + nvim_exec() | + cmd: aunmenu * | + > | + | + ]]) + command([[call chansend(g:id, "cont\n")]]) + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + [No Name] | + | + | + ]]) + end) end) describe('startup', function() @@ -58,6 +87,94 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) + describe('-l Lua', function() + local function assert_l_out(expected, args_before, args_after) + local args = { nvim_prog, '--clean' } + vim.list_extend(args, args_before or {}) + vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) + vim.list_extend(args, args_after or {}) + local out = funcs.system(args):gsub('\r\n', '\n') + return eq(dedent(expected), out) + end + + it('failure modes', function() + -- nvim -l + matches('nvim: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) + eq(1, eval('v:shell_error')) + end) + + it('os.exit() sets Nvim exitcode', function() + -- nvim -l foo.lua -arg1 -- a b c + assert_l_out([[ + bufs: + args: { "-arg1", "--exitcode", "73", "--arg2" }]], + {}, + { '-arg1', "--exitcode", "73", '--arg2' } + ) + eq(73, eval('v:shell_error')) + end) + + it('sets _G.arg', function() + -- nvim -l foo.lua -arg1 -- a b c + assert_l_out([[ + bufs: + args: { "-arg1", "--arg2", "arg3" }]], + {}, + { '-arg1', '--arg2', 'arg3' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua -- + assert_l_out([[ + bufs: + args: {}]], + {}, + { '--' } + ) + eq(0, eval('v:shell_error')) + + -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 + assert_l_out([[ + bufs: file1 file2 file3 file4 + args: { "-arg1", "arg 2" }]], + { 'file1', 'file2', }, + { '-arg1', 'arg 2', '--', 'file3', 'file4' } + ) + eq(0, eval('v:shell_error')) + + -- nvim file1 file2 -l foo.lua -arg1 -- + assert_l_out([[ + bufs: file1 file2 + args: { "-arg1" }]], + { 'file1', 'file2', }, + { '-arg1', '--' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua + assert_l_out([[ + bufs: + args: { "-c", "set wrap?" }]], + {}, + { '-c', 'set wrap?' } + ) + eq(0, eval('v:shell_error')) + + -- nvim -l foo.lua + assert_l_out( + -- luacheck: ignore 611 (Line contains only whitespaces) + [[ + wrap + + bufs: + args: { "-c", "set wrap?" }]], + { '-c', 'set wrap?' }, + { '-c', 'set wrap?' } + ) + eq(0, eval('v:shell_error')) + end) + end) + it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() -- system() puts a pipe at both ends. local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', @@ -66,6 +183,7 @@ describe('startup', function() '+q' }) eq('0 0', out) end) + it('with --embed: has("ttyin")==0 has("ttyout")==0', function() local screen = Screen.new(25, 3) -- Remote UI connected by --embed. @@ -77,6 +195,7 @@ describe('startup', function() 0 0 | ]]) end) + it('in a TTY: has("ttyin")==1 has("ttyout")==1', function() local screen = Screen.new(25, 4) screen:attach() @@ -95,6 +214,7 @@ describe('startup', function() | ]]) end) + it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) @@ -111,6 +231,7 @@ describe('startup', function() read_file('Xtest_startup_ttyout')) end) end) + it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() if is_os('win') then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) @@ -128,6 +249,7 @@ describe('startup', function() read_file('Xtest_startup_ttyout')) end) end) + it('input from pipe (implicit) #7679', function() local screen = Screen.new(25, 4) screen:attach() @@ -147,6 +269,7 @@ describe('startup', function() | ]]) end) + it('input from pipe + file args #7679', function() eq('ohyeah\r\n0 0 bufs=3', funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless', @@ -532,32 +655,6 @@ describe('sysinit', function() eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))')) end) - it('fixed hang issue with -D (#12647)', function() - local screen - screen = Screen.new(60, 7) - screen:attach() - command([[let g:id = termopen('"]]..nvim_prog.. - [[" -u NONE -i NONE --cmd "set noruler" -D')]]) - screen:expect([[ - ^ | - Entering Debug mode. Type "cont" to continue. | - nvim_exec() | - cmd: aunmenu * | - > | - <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| - | - ]]) - command([[call chansend(g:id, "cont\n")]]) - screen:expect([[ - ^ | - ~ | - ~ | - [No Name] | - | - <" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All| - | - ]]) - end) end) describe('user config init', function() diff --git a/test/functional/fixtures/startup.lua b/test/functional/fixtures/startup.lua new file mode 100644 index 0000000000..37e738c75e --- /dev/null +++ b/test/functional/fixtures/startup.lua @@ -0,0 +1,34 @@ +-- Test "nvim -l foo.lua …" + +local function printbufs() + local bufs = '' + for _, v in ipairs(vim.api.nvim_list_bufs()) do + local b = vim.fn.bufname(v) + if b:len() > 0 then + bufs = ('%s %s'):format(bufs, b) + end + end + print(('bufs:%s'):format(bufs)) +end + +local function parseargs(args) + local exitcode = nil + for i = 1, #args do + if args[i] == '--exitcode' then + exitcode = tonumber(args[i + 1]) + end + end + return exitcode +end + +local function main() + printbufs() + print('args:', vim.inspect(_G.arg)) + + local exitcode = parseargs(_G.arg) + if type(exitcode) == 'number' then + os.exit(exitcode) + end +end + +main() -- cgit From 45549f031ee52a01601c33acc411f3111cfc4e95 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 1 Jan 2023 03:14:13 +0100 Subject: feat(lua): send "--" literally to Lua "-l" script Problem: When "-l" is followed by "--", we stop sending args to the Lua script and treat "--" in the usual way. This was for flexibility but didn't have a strong use-case, and has these problems: - prevents Lua "-l" scripts from handling "--" in their own way. - complicates the startup logic (must call nlua_init before command_line_scan) Solution: Don't treat "--" specially if it follows "-l". --- test/functional/core/startup_spec.lua | 23 +++++++++++++++-------- test/functional/fixtures/startup.lua | 3 ++- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 1df8d76c97..dbd517995c 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -107,7 +107,8 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - args: { "-arg1", "--exitcode", "73", "--arg2" }]], + nvim args: 8 + lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } ) @@ -118,7 +119,8 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - args: { "-arg1", "--arg2", "arg3" }]], + nvim args: 7 + lua args: { "-arg1", "--arg2", "arg3" }]], {}, { '-arg1', '--arg2', 'arg3' } ) @@ -127,7 +129,8 @@ describe('startup', function() -- nvim -l foo.lua -- assert_l_out([[ bufs: - args: {}]], + nvim args: 5 + lua args: { "--" }]], {}, { '--' } ) @@ -135,8 +138,9 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 assert_l_out([[ - bufs: file1 file2 file3 file4 - args: { "-arg1", "arg 2" }]], + bufs: file1 file2 + nvim args: 11 + lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } ) @@ -145,7 +149,8 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- assert_l_out([[ bufs: file1 file2 - args: { "-arg1" }]], + nvim args: 8 + lua args: { "-arg1", "--" }]], { 'file1', 'file2', }, { '-arg1', '--' } ) @@ -154,7 +159,8 @@ describe('startup', function() -- nvim -l foo.lua assert_l_out([[ bufs: - args: { "-c", "set wrap?" }]], + nvim args: 6 + lua args: { "-c", "set wrap?" }]], {}, { '-c', 'set wrap?' } ) @@ -167,7 +173,8 @@ describe('startup', function() wrap bufs: - args: { "-c", "set wrap?" }]], + nvim args: 8 + lua args: { "-c", "set wrap?" }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) diff --git a/test/functional/fixtures/startup.lua b/test/functional/fixtures/startup.lua index 37e738c75e..d0e60309bd 100644 --- a/test/functional/fixtures/startup.lua +++ b/test/functional/fixtures/startup.lua @@ -23,7 +23,8 @@ end local function main() printbufs() - print('args:', vim.inspect(_G.arg)) + print('nvim args:', #vim.v.argv) + print('lua args:', vim.inspect(_G.arg)) local exitcode = parseargs(_G.arg) if type(exitcode) == 'number' then -- cgit From adef308a5925a3b967af3bd7c598074e5b6cae18 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 2 Jan 2023 15:34:14 +0100 Subject: feat(lua): exit 1 on Lua "-l" script error --- test/functional/core/startup_spec.lua | 21 +++++++++++++++------ test/functional/fixtures/startup-fail.lua | 7 +++++++ test/functional/vimscript/system_spec.lua | 2 ++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 test/functional/fixtures/startup-fail.lua (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index dbd517995c..455de08548 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -88,11 +88,11 @@ describe('startup', function() end) describe('-l Lua', function() - local function assert_l_out(expected, args_before, args_after) + local function assert_l_out(expected, nvim_args, lua_args) local args = { nvim_prog, '--clean' } - vim.list_extend(args, args_before or {}) + vim.list_extend(args, nvim_args or {}) vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) - vim.list_extend(args, args_after or {}) + vim.list_extend(args, lua_args or {}) local out = funcs.system(args):gsub('\r\n', '\n') return eq(dedent(expected), out) end @@ -115,6 +115,13 @@ describe('startup', function() eq(73, eval('v:shell_error')) end) + it('Lua error sets Nvim exitcode', function() + eq(0, eval('v:shell_error')) + matches('E5113: .* my pearls!!', + funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })) + eq(1, eval('v:shell_error')) + end) + it('sets _G.arg', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ @@ -396,11 +403,13 @@ describe('startup', function() { 'put =mode(1)', 'print', '' })) end) - it('fails on --embed with -es/-Es', function() - matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es', + it('fails on --embed with -es/-Es/-l', function() + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', funcs.system({nvim_prog, '--embed', '-es' })) - matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es', + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', funcs.system({nvim_prog, '--embed', '-Es' })) + matches('nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', + funcs.system({nvim_prog, '--embed', '-l', 'foo.lua' })) end) it('does not crash if --embed is given twice', function() diff --git a/test/functional/fixtures/startup-fail.lua b/test/functional/fixtures/startup-fail.lua new file mode 100644 index 0000000000..adcfe2a201 --- /dev/null +++ b/test/functional/fixtures/startup-fail.lua @@ -0,0 +1,7 @@ +-- Test "nvim -l foo.lua …" with a Lua error. + +local function main() + error('my pearls!!') +end + +main() diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index dbf734b51a..f099b4a36e 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -1,3 +1,5 @@ +-- Tests for system() and :! shell. + local helpers = require('test.functional.helpers')(after_each) local assert_alive = helpers.assert_alive -- cgit From f43de742e881e54a3602e00c8c247cecca65a266 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 3 Jan 2023 02:54:53 +0100 Subject: feat(lua): execute stdin ("-") as Lua --- test/functional/core/startup_spec.lua | 58 +++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 455de08548..d7e64c6b54 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -88,18 +88,18 @@ describe('startup', function() end) describe('-l Lua', function() - local function assert_l_out(expected, nvim_args, lua_args) - local args = { nvim_prog, '--clean' } + local function assert_l_out(expected, nvim_args, lua_args, script, input) + local args = { nvim_prog } vim.list_extend(args, nvim_args or {}) - vim.list_extend(args, { '-l', 'test/functional/fixtures/startup.lua' }) + vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') }) vim.list_extend(args, lua_args or {}) - local out = funcs.system(args):gsub('\r\n', '\n') + local out = funcs.system(args, input):gsub('\r\n', '\n') return eq(dedent(expected), out) end it('failure modes', function() - -- nvim -l - matches('nvim: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) + -- nvim -l + matches('nvim%.?e?x?e?: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) eq(1, eval('v:shell_error')) end) @@ -107,7 +107,7 @@ describe('startup', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - nvim args: 8 + nvim args: 7 lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } @@ -115,18 +115,35 @@ describe('startup', function() eq(73, eval('v:shell_error')) end) - it('Lua error sets Nvim exitcode', function() + it('Lua-error sets Nvim exitcode', function() eq(0, eval('v:shell_error')) matches('E5113: .* my pearls!!', funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })) eq(1, eval('v:shell_error')) + matches('E5113: .* %[string "error%("whoa"%)"%]:1: whoa', + funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")')) + eq(1, eval('v:shell_error')) + end) + + it('executes stdin "-"', function() + assert_l_out('args=2 whoa', + nil, + { 'arg1', 'arg 2' }, + '-', + "print(('args=%d %s'):format(#_G.arg, 'whoa'))") + assert_l_out('biiig input: 1000042', + nil, + nil, + '-', + ('print("biiig input: "..("%s"):len())'):format(string.rep('x', (1000 * 1000) + 42))) + eq(0, eval('v:shell_error')) end) it('sets _G.arg', function() -- nvim -l foo.lua -arg1 -- a b c assert_l_out([[ bufs: - nvim args: 7 + nvim args: 6 lua args: { "-arg1", "--arg2", "arg3" }]], {}, { '-arg1', '--arg2', 'arg3' } @@ -136,7 +153,7 @@ describe('startup', function() -- nvim -l foo.lua -- assert_l_out([[ bufs: - nvim args: 5 + nvim args: 4 lua args: { "--" }]], {}, { '--' } @@ -146,7 +163,7 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- file3 file4 assert_l_out([[ bufs: file1 file2 - nvim args: 11 + nvim args: 10 lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } @@ -156,7 +173,7 @@ describe('startup', function() -- nvim file1 file2 -l foo.lua -arg1 -- assert_l_out([[ bufs: file1 file2 - nvim args: 8 + nvim args: 7 lua args: { "-arg1", "--" }]], { 'file1', 'file2', }, { '-arg1', '--' } @@ -166,7 +183,7 @@ describe('startup', function() -- nvim -l foo.lua assert_l_out([[ bufs: - nvim args: 6 + nvim args: 5 lua args: { "-c", "set wrap?" }]], {}, { '-c', 'set wrap?' } @@ -180,13 +197,22 @@ describe('startup', function() wrap bufs: - nvim args: 8 + nvim args: 7 lua args: { "-c", "set wrap?" }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) eq(0, eval('v:shell_error')) end) + + it('disables swapfile/shada/config/plugins', function() + assert_l_out('updatecount=0 shadafile=NONE loadplugins=false scriptnames=1', + nil, + nil, + '-', + [[print(('updatecount=%d shadafile=%s loadplugins=%s scriptnames=%d'):format( + vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.split(vim.fn.execute('scriptnames'),'\n'))))]]) + end) end) it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() @@ -375,11 +401,11 @@ describe('startup', function() it('-es/-Es disables swapfile, user config #8540', function() for _,arg in ipairs({'-es', '-Es'}) do local out = funcs.system({nvim_prog, arg, - '+set swapfile? updatecount? shada?', + '+set swapfile? updatecount? shadafile?', "+put =execute('scriptnames')", '+%print'}) local line1 = string.match(out, '^.-\n') -- updatecount=0 means swapfile was disabled. - eq(" swapfile updatecount=0 shada=!,'100,<50,s10,h\n", line1) + eq(" swapfile updatecount=0 shadafile=\n", line1) -- Standard plugins were loaded, but not user config. eq('health.vim', string.match(out, 'health.vim')) eq(nil, string.match(out, 'init.vim')) -- cgit From b303ab9a7d5f695e53c3f261b000e0e748ed8654 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 6 Jan 2023 10:40:56 +0100 Subject: fix(tui): do not invoke loop recursively for pad() fixes #21610 --- test/functional/terminal/tui_spec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index e31f76a444..d071c2f091 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1469,6 +1469,33 @@ describe('TUI', function() | {3:-- TERMINAL --} |]])) end) + + it('visual bell (padding) does not crash #21610', function() + feed_data ':set visualbell\n' + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + :set visualbell | + {3:-- TERMINAL --} | + ]]} + + -- move left is enough to invoke the bell + feed_data 'h' + -- visual change to show we process events after this + feed_data 'i' + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]} + end) end) describe('TUI', function() -- cgit From e17430c1cd97db5624e27515a4f5da17f9d926d6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 7 Jan 2023 02:12:54 +0100 Subject: feat(lua): store "nvim -l" scriptname in _G.arg[0] --- test/functional/core/startup_spec.lua | 50 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 30 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index d7e64c6b54..9dabcd28b3 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -108,7 +108,9 @@ describe('startup', function() assert_l_out([[ bufs: nvim args: 7 - lua args: { "-arg1", "--exitcode", "73", "--arg2" }]], + lua args: { "-arg1", "--exitcode", "73", "--arg2", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, { '-arg1', "--exitcode", "73", '--arg2' } ) @@ -126,11 +128,11 @@ describe('startup', function() end) it('executes stdin "-"', function() - assert_l_out('args=2 whoa', + assert_l_out('arg0=- args=2 whoa', nil, { 'arg1', 'arg 2' }, '-', - "print(('args=%d %s'):format(#_G.arg, 'whoa'))") + "print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))") assert_l_out('biiig input: 1000042', nil, nil, @@ -140,23 +142,15 @@ describe('startup', function() end) it('sets _G.arg', function() - -- nvim -l foo.lua -arg1 -- a b c - assert_l_out([[ - bufs: - nvim args: 6 - lua args: { "-arg1", "--arg2", "arg3" }]], - {}, - { '-arg1', '--arg2', 'arg3' } - ) - eq(0, eval('v:shell_error')) - - -- nvim -l foo.lua -- + -- nvim -l foo.lua [args] assert_l_out([[ bufs: - nvim args: 4 - lua args: { "--" }]], + nvim args: 7 + lua args: { "-arg1", "--arg2", "--", "arg3", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, - { '--' } + { '-arg1', '--arg2', '--', 'arg3' } ) eq(0, eval('v:shell_error')) @@ -164,27 +158,21 @@ describe('startup', function() assert_l_out([[ bufs: file1 file2 nvim args: 10 - lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]], + lua args: { "-arg1", "arg 2", "--", "file3", "file4", + [0] = "test/functional/fixtures/startup.lua" + }]], { 'file1', 'file2', }, { '-arg1', 'arg 2', '--', 'file3', 'file4' } ) eq(0, eval('v:shell_error')) - -- nvim file1 file2 -l foo.lua -arg1 -- - assert_l_out([[ - bufs: file1 file2 - nvim args: 7 - lua args: { "-arg1", "--" }]], - { 'file1', 'file2', }, - { '-arg1', '--' } - ) - eq(0, eval('v:shell_error')) - -- nvim -l foo.lua assert_l_out([[ bufs: nvim args: 5 - lua args: { "-c", "set wrap?" }]], + lua args: { "-c", "set wrap?", + [0] = "test/functional/fixtures/startup.lua" + }]], {}, { '-c', 'set wrap?' } ) @@ -198,7 +186,9 @@ describe('startup', function() bufs: nvim args: 7 - lua args: { "-c", "set wrap?" }]], + lua args: { "-c", "set wrap?", + [0] = "test/functional/fixtures/startup.lua" + }]], { '-c', 'set wrap?' }, { '-c', 'set wrap?' } ) -- cgit From 34d1eaa792fa332cea190568967a489e324fca6f Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 4 Jan 2023 14:36:18 -0700 Subject: feat(editorconfig): allow editorconfig to be toggled dynamically Rather than only check `editorconfig_enable` when the plugin is loaded, check it each time the autocommand fires, so that users may enable or disable it dynamically. Also check for a buffer local version of the variable, so that editorconfig can be enabled or disabled per-buffer. --- test/functional/plugin/editorconfig_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional') diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index f71b8088ed..ad95b9a07e 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -4,6 +4,8 @@ local command = helpers.command local eq = helpers.eq local pathsep = helpers.get_pathsep() local curbufmeths = helpers.curbufmeths +local funcs = helpers.funcs +local meths = helpers.meths local testdir = 'Xtest-editorconfig' @@ -191,4 +193,18 @@ But not this one it('sets textwidth', function() test_case('max_line_length.txt', { textwidth = 42 }) end) + + it('can be disabled globally', function() + meths.set_var('editorconfig_enable', false) + meths.set_option_value('shiftwidth', 42, {}) + test_case('3_space.txt', { shiftwidth = 42 }) + end) + + it('can be disabled per-buffer', function() + meths.set_option_value('shiftwidth', 42, {}) + local bufnr = funcs.bufadd(testdir .. pathsep .. '3_space.txt') + meths.buf_set_var(bufnr, 'editorconfig_enable', false) + test_case('3_space.txt', { shiftwidth = 42 }) + test_case('4_space.py', { shiftwidth = 4 }) + end) end) -- cgit From 6ffa434f0b1c6e82fb6c1445d5d7382e0ef22e07 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 4 Jan 2023 15:10:19 -0700 Subject: refactor(editorconfig)!: change editorconfig_enable to editorconfig --- test/functional/plugin/editorconfig_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional') diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index ad95b9a07e..e6a2550aba 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -195,7 +195,7 @@ But not this one end) it('can be disabled globally', function() - meths.set_var('editorconfig_enable', false) + meths.set_var('editorconfig', false) meths.set_option_value('shiftwidth', 42, {}) test_case('3_space.txt', { shiftwidth = 42 }) end) @@ -203,7 +203,7 @@ But not this one it('can be disabled per-buffer', function() meths.set_option_value('shiftwidth', 42, {}) local bufnr = funcs.bufadd(testdir .. pathsep .. '3_space.txt') - meths.buf_set_var(bufnr, 'editorconfig_enable', false) + meths.buf_set_var(bufnr, 'editorconfig', false) test_case('3_space.txt', { shiftwidth = 42 }) test_case('4_space.py', { shiftwidth = 4 }) end) -- cgit From 904c13e6b572552a676efcaec640dfa8bd199e59 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Sun, 8 Jan 2023 15:31:38 -0500 Subject: dist: transpile cfilter.vim => cfilter.lua #21662 Vim has changed cfilter.vim from vimscript to vim9script. Nvim supports only vimscript, not vim9script. --- test/functional/plugin/cfilter_spec.lua | 106 ++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/functional/plugin/cfilter_spec.lua (limited to 'test/functional') diff --git a/test/functional/plugin/cfilter_spec.lua b/test/functional/plugin/cfilter_spec.lua new file mode 100644 index 0000000000..8b1e75b495 --- /dev/null +++ b/test/functional/plugin/cfilter_spec.lua @@ -0,0 +1,106 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local funcs = helpers.funcs + +describe('cfilter.lua', function() + before_each(function() + clear() + command('packadd cfilter') + end) + + for _, list in ipairs({ + { + name = 'Cfilter', + get = funcs.getqflist, + set = funcs.setqflist, + }, + { + name = 'Lfilter', + get = function() + return funcs.getloclist(0) + end, + set = function(items) + return funcs.setloclist(0, items) + end, + }, + }) do + local filter = function(s, bang) + if not bang then + bang = '' + else + bang = '!' + end + + command(string.format('%s%s %s', list.name, bang, s)) + end + + describe((':%s'):format(list.name), function() + it('does not error on empty list', function() + filter('nothing') + eq({}, funcs.getqflist()) + end) + + it('requires an argument', function() + local ok = pcall(filter, '') + eq(false, ok) + end) + + local test = function(name, s, res, map, bang) + it(('%s (%s)'):format(name, s), function() + list.set({ + { filename = 'foo', lnum = 1, text = 'bar' }, + { filename = 'foo', lnum = 2, text = 'baz' }, + { filename = 'foo', lnum = 3, text = 'zed' }, + }) + + filter(s, bang) + + local got = list.get() + if map then + got = map(got) + end + eq(res, got) + end) + end + + local toname = function(qflist) + return funcs.map(qflist, 'v:val.text') + end + + test('filters with no matches', 'does not match', {}) + + test('filters with matches', 'ba', { 'bar', 'baz' }, toname) + test('filters with matches', 'z', { 'baz', 'zed' }, toname) + test('filters with matches', '^z', { 'zed' }, toname) + test('filters with not matches', '^z', { 'bar', 'baz' }, toname, true) + + it('also supports using the / register', function() + list.set({ + { filename = 'foo', lnum = 1, text = 'bar' }, + { filename = 'foo', lnum = 2, text = 'baz' }, + { filename = 'foo', lnum = 3, text = 'zed' }, + }) + + funcs.setreg('/', 'ba') + filter('/') + + eq({ 'bar', 'baz' }, toname(list.get())) + end) + + it('also supports using the / register with bang', function() + list.set({ + { filename = 'foo', lnum = 1, text = 'bar' }, + { filename = 'foo', lnum = 2, text = 'baz' }, + { filename = 'foo', lnum = 3, text = 'zed' }, + }) + + funcs.setreg('/', 'ba') + filter('/', true) + + eq({ 'zed' }, toname(list.get())) + end) + end) + end +end) -- cgit From c19bd47c0a2e3cc77d7f5e41ed184edb41685bd3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 9 Jan 2023 12:20:50 +0800 Subject: test(tui_spec): improve cursor_address test (#21700) --- test/functional/terminal/helpers.lua | 5 ++- test/functional/terminal/tui_spec.lua | 81 +++++++++++++++++------------------ 2 files changed, 44 insertions(+), 42 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index 841c92387f..7247361649 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -74,7 +74,10 @@ local function screen_setup(extra_rows, command, cols, opts) [9] = {foreground = 4}, [10] = {foreground = 121}, -- "Press ENTER" in embedded :terminal session. [11] = {foreground = tonumber('0x00000b')}, - [12] = {reverse = true, foreground = tonumber('0x000079')}, + [12] = {underline = true}, + [13] = {underline = true, reverse = true}, + [14] = {underline = true, reverse = true, bold = true}, + [15] = {underline = true, foreground = 12}, }) screen:attach(opts or {rgb=false}) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index d071c2f091..b8db882b36 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -626,37 +626,35 @@ describe('TUI', function() tabnew highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline ]]) - local attrs = screen:get_default_attr_ids() - attrs[11] = {underline = true} screen:expect([[ - {11: + [No Name] + [No Name] }{3: [No Name] }{1: }{11:X}| + {12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}| {1: } | {4:~ }| {4:~ }| {5:[No Name] }| | {3:-- TERMINAL --} | - ]], attrs) + ]]) feed_data('\027[57421;5u') -- CTRL + KP_PAGE_UP screen:expect([[ - {11: + [No Name] }{3: + [No Name] }{11: [No Name] }{1: }{11:X}| + {12: + [No Name] }{3: + [No Name] }{12: [No Name] }{1: }{12:X}| 0123456789/*-{1:+} | = | {4:~ }| {5:[No Name] [+] }| | {3:-- TERMINAL --} | - ]], attrs) + ]]) feed_data('\027[57422;5u') -- CTRL + KP_PAGE_DOWN screen:expect([[ - {11: + [No Name] + [No Name] }{3: [No Name] }{1: }{11:X}| + {12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}| {1: } | {4:~ }| {4:~ }| {5:[No Name] }| | {3:-- TERMINAL --} | - ]], attrs) + ]]) end) it('mouse events work with right-click menu', function() @@ -671,31 +669,28 @@ describe('TUI', function() highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold ]]) - local attrs = screen:get_default_attr_ids() - attrs[11] = {underline = true, reverse = true} - attrs[12] = {underline = true, reverse = true, bold = true} meths.input_mouse('right', 'press', '', 0, 0, 4) screen:expect([[ {1:p}opup menu test | - {4:~ }{11: foo }{4: }| - {4:~ }{11: bar }{4: }| - {4:~ }{11: baz }{4: }| + {4:~ }{13: foo }{4: }| + {4:~ }{13: bar }{4: }| + {4:~ }{13: baz }{4: }| {5:[No Name] [+] }| | {3:-- TERMINAL --} | - ]], attrs) + ]]) meths.input_mouse('right', 'release', '', 0, 0, 4) screen:expect_unchanged() meths.input_mouse('move', '', '', 0, 3, 6) screen:expect([[ {1:p}opup menu test | - {4:~ }{11: foo }{4: }| - {4:~ }{11: bar }{4: }| - {4:~ }{12: baz }{4: }| + {4:~ }{13: foo }{4: }| + {4:~ }{13: bar }{4: }| + {4:~ }{14: baz }{4: }| {5:[No Name] [+] }| | {3:-- TERMINAL --} | - ]], attrs) + ]]) meths.input_mouse('left', 'press', '', 0, 2, 6) screen:expect([[ {1:p}opup menu test | @@ -705,7 +700,7 @@ describe('TUI', function() {5:[No Name] [+] }| :let g:menustr = 'bar' | {3:-- TERMINAL --} | - ]], attrs) + ]]) meths.input_mouse('left', 'release', '', 0, 2, 6) screen:expect_unchanged() end) @@ -1405,18 +1400,14 @@ describe('TUI', function() end) it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function() - child_session:request('nvim_buf_set_lines', 0, 0, 0, true, { ('℃'):rep(60), ('℃'):rep(60) }) + child_session:request('nvim_buf_set_lines', 0, 0, -1, true, { ('℃'):rep(60), ('℃'):rep(60) }) child_session:request('nvim_win_set_option', 0, 'cursorline', true) child_session:request('nvim_win_set_option', 0, 'list', true) child_session:request('nvim_win_set_option', 0, 'listchars', 'eol:$') - local attrs = screen:get_default_attr_ids() - attrs[11] = {underline = true} -- CursorLine - attrs[12] = {underline = true, reverse = true} -- CursorLine and TermCursor - attrs[13] = {underline = true, foreground = 12} -- CursorLine and NonText feed_data('gg') local singlewidth_screen = [[ - {12:℃}{11:℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃}| - {11:℃℃℃℃℃℃℃℃℃℃}{13:$}{11: }| + {13:℃}{12:℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃}| + {12:℃℃℃℃℃℃℃℃℃℃}{15:$}{12: }| ℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃| ℃℃℃℃℃℃℃℃℃℃{4:$} | {5:[No Name] [+] }| @@ -1426,43 +1417,51 @@ describe('TUI', function() -- When grid assumes "℃" to be double-width but host terminal assumes it to be single-width, the -- second cell of "℃" is a space and the attributes of the "℃" are applied to it. local doublewidth_screen = [[ - {12:℃}{11: ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| - {11:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| - {11:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }{13:$}{11: }| + {13:℃}{12: ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| + {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| + {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }{15:$}{12: }| ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ >{4:@@@}| {5:[No Name] [+] }| | {3:-- TERMINAL --} | ]] - screen:expect(singlewidth_screen, attrs) + screen:expect(singlewidth_screen) child_session:request('nvim_set_option', 'ambiwidth', 'double') - screen:expect(doublewidth_screen, attrs) + screen:expect(doublewidth_screen) child_session:request('nvim_set_option', 'ambiwidth', 'single') - screen:expect(singlewidth_screen, attrs) + screen:expect(singlewidth_screen) child_session:request('nvim_call_function', 'setcellwidths', {{{0x2103, 0x2103, 2}}}) - screen:expect(doublewidth_screen, attrs) + screen:expect(doublewidth_screen) child_session:request('nvim_call_function', 'setcellwidths', {{{0x2103, 0x2103, 1}}}) - screen:expect(singlewidth_screen, attrs) + screen:expect(singlewidth_screen) end) it('draws correctly when cursor_address overflows #21643', function() helpers.skip(helpers.is_ci('github'), 'FIXME: flaky on GitHub CI') screen:try_resize(75, 60) + retry(nil, nil, function() + eq({true, 57}, {child_session:request('nvim_win_get_height', 0)}) + end) -- The composing character takes 3 bytes. local composing = ('a︠'):sub(2) -- The composed character takes 1 + 5 * 3 = 16 bytes. local c = 'a' .. composing:rep(5) -- Going to top-left corner needs 3 bytes. + -- Setting underline attribute needs 9 bytes. -- With screen width 75, 4088 characters need 54 full screen lines. -- Drawing each full screen line needs 75 * 16 + 2 = 1202 bytes (2 bytes for CR LF). - -- The incomplete screen line needs 38 * 16 + 8 + 3 = 619 bytes. - -- The whole line needs 3 + 54 * 1202 + 619 = 65530 bytes. + -- The incomplete screen line needs 38 * 16 + 1 + 3 = 612 bytes. + -- The whole line needs 3 + 9 + 54 * 1202 + 612 = 65532 bytes. -- The cursor_address that comes after will overflow the 65535-byte buffer. - local line = c:rep(4088) .. ('b'):rep(8) .. '℃' - child_session:request('nvim_buf_set_lines', 0, 0, -1, true, {line, 'c'}) + local line = c:rep(4088) .. 'b℃' + child_session:request('nvim_exec_lua', [[ + vim.api.nvim_buf_set_lines(0, 0, -1, true, {...}) + vim.o.cursorline = true + ]], {line, 'c'}) screen:expect( - '{1:' .. c .. '}' .. c:rep(74) .. '|\n' .. (c:rep(75) .. '|\n'):rep(53) - .. c:rep(38) .. ('b'):rep(8) .. '℃' .. (' '):rep(28) .. '|\n' .. dedent([[ + '{13:' .. c .. '}{12:' .. c:rep(74) .. '}|\n' + .. ('{12:' .. c:rep(75) .. '}|\n'):rep(53) + .. '{12:' .. c:rep(38) .. 'b℃' .. (' '):rep(35) .. '}|\n' .. dedent([[ c | {4:~ }| {5:[No Name] [+] }| -- cgit From e351ab179b3f4dbedd8e959dfcd972178d6a9e16 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 9 Jan 2023 14:17:32 +0800 Subject: fix(ui): add test case --- test/functional/ui/float_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index ab87384194..61143e953c 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1739,6 +1739,28 @@ describe('float window', function() })) end) + it('validate title_pos in nvim_win_get_config', function() + local title_pos = exec_lua([[ + local bufnr = vim.api.nvim_create_buf(false, false) + local opts = { + relative = 'editor', + col = 2, + row = 5, + height = 2, + width = 9, + border = 'double', + title = 'Test', + title_pos = 'center' + } + + local win_id = vim.api.nvim_open_win(bufnr, true, opts) + return vim.api.nvim_win_get_config(win_id).title_pos + ]]) + + eq('center', title_pos) + end) + + it('border with title', function() local buf = meths.create_buf(false, false) meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', -- cgit From 53adccb6e0292f7ba5524121c0200a73aec977a6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 9 Jan 2023 17:02:45 +0800 Subject: test(tui_spec): doesn't use Unicode in cursor_address test (#21703) Using Unicode makes the test flaky because of #16245. --- test/functional/terminal/tui_spec.lua | 44 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index b8db882b36..228aaa6b23 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1437,36 +1437,36 @@ describe('TUI', function() end) it('draws correctly when cursor_address overflows #21643', function() - helpers.skip(helpers.is_ci('github'), 'FIXME: flaky on GitHub CI') - screen:try_resize(75, 60) + helpers.skip(helpers.is_os('mac'), 'FIXME: crashes/errors on macOS') + screen:try_resize(77, 834) retry(nil, nil, function() - eq({true, 57}, {child_session:request('nvim_win_get_height', 0)}) + eq({true, 831}, {child_session:request('nvim_win_get_height', 0)}) end) - -- The composing character takes 3 bytes. - local composing = ('a︠'):sub(2) - -- The composed character takes 1 + 5 * 3 = 16 bytes. - local c = 'a' .. composing:rep(5) + -- Use full screen message so that redrawing afterwards is more deterministic. + child_session:notify('nvim_command', 'intro') + screen:expect({any = 'Nvim'}) -- Going to top-left corner needs 3 bytes. -- Setting underline attribute needs 9 bytes. - -- With screen width 75, 4088 characters need 54 full screen lines. - -- Drawing each full screen line needs 75 * 16 + 2 = 1202 bytes (2 bytes for CR LF). - -- The incomplete screen line needs 38 * 16 + 1 + 3 = 612 bytes. - -- The whole line needs 3 + 9 + 54 * 1202 + 612 = 65532 bytes. + -- With screen width 77, 63857 characters need 829 full screen lines. + -- Drawing each full screen line needs 77 + 2 = 79 bytes (2 bytes for CR LF). + -- The incomplete screen line needs 24 + 3 = 27 bytes. + -- The whole line needs 3 + 9 + 79 * 829 + 27 = 65530 bytes. -- The cursor_address that comes after will overflow the 65535-byte buffer. - local line = c:rep(4088) .. 'b℃' - child_session:request('nvim_exec_lua', [[ + local line = ('a'):rep(63857) .. '℃' + child_session:notify('nvim_exec_lua', [[ vim.api.nvim_buf_set_lines(0, 0, -1, true, {...}) vim.o.cursorline = true - ]], {line, 'c'}) + ]], {line, 'b'}) + -- Close the :intro message and redraw the lines. + feed_data('\n') screen:expect( - '{13:' .. c .. '}{12:' .. c:rep(74) .. '}|\n' - .. ('{12:' .. c:rep(75) .. '}|\n'):rep(53) - .. '{12:' .. c:rep(38) .. 'b℃' .. (' '):rep(35) .. '}|\n' .. dedent([[ - c | - {4:~ }| - {5:[No Name] [+] }| - | - {3:-- TERMINAL --} |]])) + '{13:a}{12:' .. ('a'):rep(76) .. '}|\n' + .. ('{12:' .. ('a'):rep(77) .. '}|\n'):rep(828) + .. '{12:' .. ('a'):rep(24) .. '℃' .. (' '):rep(52) .. '}|\n' .. dedent([[ + b | + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} |]])) end) it('visual bell (padding) does not crash #21610', function() -- cgit From 7ba39b4378743ceefdd52186e64acd6af6f8e5a2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 9 Jan 2023 16:27:43 +0800 Subject: test: add more tests for Unicode --- test/functional/ex_cmds/quickfix_commands_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ex_cmds/quickfix_commands_spec.lua b/test/functional/ex_cmds/quickfix_commands_spec.lua index 94b7fa1a84..4d9d8eeb90 100644 --- a/test/functional/ex_cmds/quickfix_commands_spec.lua +++ b/test/functional/ex_cmds/quickfix_commands_spec.lua @@ -1,5 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local feed = helpers.feed local eq = helpers.eq local clear = helpers.clear local funcs = helpers.funcs @@ -123,3 +125,22 @@ describe('quickfix', function() os.remove(file) end) end) + +it(':vimgrep can specify Unicode pattern without delimiters', function() + eq('Vim(vimgrep):E480: No match: →', exc_exec('vimgrep → test/functional/fixtures/tty-test.c')) + local screen = Screen.new(40, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {reverse = true}, -- IncSearch + }) + screen:attach() + feed('i→:vimgrep →') + screen:expect([[ + {1:→} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + :vimgrep →^ | + ]]) +end) -- cgit From 364b131f42509326c912c9b0fef5dfc94ed23b41 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:12:06 +0100 Subject: feat(ui): add 'statuscolumn' option Problem: Unable to customize the column next to a window ('gutter'). Solution: Add 'statuscolumn' option that follows the 'statusline' syntax, allowing to customize the status column. Also supporting the %@ click execute function label. Adds new items @C and @s which will print the fold and sign columns. Line numbers and signs can be clicked, highlighted, aligned, transformed, margined etc. --- test/functional/lua/ffi_spec.lua | 5 +- test/functional/ui/statuscolumn_spec.lua | 273 +++++++++++++++++++++++++++++++ 2 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 test/functional/ui/statuscolumn_spec.lua (limited to 'test/functional') diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua index 3969a7a478..18b13a8959 100644 --- a/test/functional/lua/ffi_spec.lua +++ b/test/functional/lua/ffi_spec.lua @@ -29,6 +29,7 @@ describe('ffi.cdef', function() typedef struct window_S win_T; typedef struct {} stl_hlrec_t; typedef struct {} StlClickRecord; + typedef struct {} statuscol_T; typedef struct {} Error; win_T *find_window_by_handle(int Window, Error *err); @@ -43,7 +44,8 @@ describe('ffi.cdef', function() int fillchar, int maxwidth, stl_hlrec_t **hltab, - StlClickRecord **tabtab + StlClickRecord **tabtab, + statuscol_T *scp ); ]] @@ -57,6 +59,7 @@ describe('ffi.cdef', function() 0, 0, nil, + nil, nil ) ]=]) diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua new file mode 100644 index 0000000000..1ee96ed625 --- /dev/null +++ b/test/functional/ui/statuscolumn_spec.lua @@ -0,0 +1,273 @@ +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 meths = helpers.meths +local pcall_err = helpers.pcall_err + +describe('statuscolumn', function() + local screen + before_each(function() + clear('--cmd', 'set number nuw=1 | call setline(1, repeat(["aaaaa"], 16)) | norm GM') + screen = Screen.new() + screen:attach() + end) + + it('fails with invalid \'statuscolumn\'', function() + command('set stc=%{v:relnum?v:relnum:(v:lnum==5?invalid:v:lnum)}\\ ') + screen:expect([[ + 4 aaaaa | + 3 aaaaa | + 2 aaaaa | + 1 aaaaa | + 8 ^aaaaa | + 1 aaaaa | + 2 aaaaa | + 3 aaaaa | + 4 aaaaa | + 5 aaaaa | + 6 aaaaa | + 7 aaaaa | + 8 aaaaa | + | + ]]) + command('norm 5G') + eq('Vim(redraw):E121: Undefined variable: invalid', pcall_err(command, 'redraw!')) + eq('', eval('&statuscolumn')) + end) + + it('widens with irregular \'statuscolumn\' width', function() + command('set stc=%{v:relnum?v:relnum:(v:lnum==5?\'bbbbb\':v:lnum)}') + command('norm 5G | redraw!') + screen:expect([[ + 1 aaaaa | + bbbbba^eaaa | + 1 aaaaa | + 2 aaaaa | + 3 aaaaa | + 4 aaaaa | + 5 aaaaa | + 6 aaaaa | + 7 aaaaa | + 8 aaaaa | + 9 aaaaa | + 10 aaaaa | + 11 aaaaa | + | + ]]) + end) + + it('works with \'statuscolumn\'', function() + command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]]) + screen:expect([[ + 4 │aaaaa | + 5 │aaaaa | + 6 │aaaaa | + 7 │aaaaa | + 8 │^aaaaa | + 9 │aaaaa | + 10│aaaaa | + 11│aaaaa | + 12│aaaaa | + 13│aaaaa | + 14│aaaaa | + 15│aaaaa | + 16│aaaaa | + | + ]]) + command('set relativenumber') + screen:expect([[ + 4 4│aaaaa | + 5 3│aaaaa | + 6 2│aaaaa | + 7 1│aaaaa | + 8 0│^aaaaa | + 9 1│aaaaa | + 10 2│aaaaa | + 11 3│aaaaa | + 12 4│aaaaa | + 13 5│aaaaa | + 14 6│aaaaa | + 15 7│aaaaa | + 16 8│aaaaa | + | + ]]) + command('norm 12GH') + screen:expect([[ + 4 0│^aaaaa | + 5 1│aaaaa | + 6 2│aaaaa | + 7 3│aaaaa | + 8 4│aaaaa | + 9 5│aaaaa | + 10 6│aaaaa | + 11 7│aaaaa | + 12 8│aaaaa | + 13 9│aaaaa | + 14 10│aaaaa | + 15 11│aaaaa | + 16 12│aaaaa | + | + ]]) + end) + + it('works with highlighted \'statuscolumn\'', function() + command([[set stc=%#NonText#%{&nu?v:lnum:''}]] .. + [[%=%{&rnu&&(v:lnum%2)?'\ '.v:relnum:''}]] .. + [[%#LineNr#%{&rnu&&!(v:lnum%2)?'\ '.v:relnum:''}│]]) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, + [1] = {foreground = Screen.colors.Brown}, + }) + screen:expect([[ + {0:4 }{1:│}aaaaa | + {0:5 }{1:│}aaaaa | + {0:6 }{1:│}aaaaa | + {0:7 }{1:│}aaaaa | + {0:8 }{1:│}^aaaaa | + {0:9 }{1:│}aaaaa | + {0:10}{1:│}aaaaa | + {0:11}{1:│}aaaaa | + {0:12}{1:│}aaaaa | + {0:13}{1:│}aaaaa | + {0:14}{1:│}aaaaa | + {0:15}{1:│}aaaaa | + {0:16}{1:│}aaaaa | + | + ]]) + command('set relativenumber') + screen:expect([[ + {0:4 }{1: 4│}aaaaa | + {0:5 3}{1:│}aaaaa | + {0:6 }{1: 2│}aaaaa | + {0:7 1}{1:│}aaaaa | + {0:8 }{1: 0│}^aaaaa | + {0:9 1}{1:│}aaaaa | + {0:10}{1: 2│}aaaaa | + {0:11 3}{1:│}aaaaa | + {0:12}{1: 4│}aaaaa | + {0:13 5}{1:│}aaaaa | + {0:14}{1: 6│}aaaaa | + {0:15 7}{1:│}aaaaa | + {0:16}{1: 8│}aaaaa | + | + ]]) + command('set nonumber') + screen:expect([[ + {1:4│}aaaaa | + {0:3}{1:│}aaaaa | + {1:2│}aaaaa | + {0:1}{1:│}aaaaa | + {1:0│}^aaaaa | + {0:1}{1:│}aaaaa | + {1:2│}aaaaa | + {0:3}{1:│}aaaaa | + {1:4│}aaaaa | + {0:5}{1:│}aaaaa | + {1:6│}aaaaa | + {0:7}{1:│}aaaaa | + {1:8│}aaaaa | + | + ]]) + end) + + it('works with wrapped lines, signs and folds', function() + command("set stc=%C%s%=%{v:wrap?'':v:lnum}│\\ ") + command("call setline(1,repeat([repeat('aaaaa',10)],16))") + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, + [1] = {foreground = Screen.colors.Brown}, + [2] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGrey}, + [3] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey}, + }) + screen:expect([[ + {1: 4│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }a | + {1: 5│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }a | + {1: 6│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }a | + {1: 7│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }a | + {1: 8│ }^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }a | + {1: 9│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }a | + {1:10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{0:@@@}| + | + ]]) + command('set signcolumn=auto:2 foldcolumn=auto') + command('sign define piet1 text=>> texthl=LineNr') + command('sign define piet2 text=>! texthl=NonText') + command('sign place 1 line=4 name=piet1 buffer=1') + command('sign place 2 line=5 name=piet2 buffer=1') + command('sign place 3 line=6 name=piet1 buffer=1') + command('sign place 4 line=6 name=piet2 buffer=1') + screen:expect([[ + {1:>> 4│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }aaaaa | + {0:>!}{1: 5│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }aaaaa | + {1:>>}{0:>!}{1: 6│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }aaaaa | + {1: 7│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }aaaaa | + {1: 8│ }^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }aaaaa | + {1: 9│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1: │ }aaaaa | + {1: 10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{0:@@@}| + | + ]]) + command('norm zf$') + -- Check that alignment works properly with signs after %= + command("set stc=%C%=%{v:wrap?'':v:lnum}│%s\\ ") + screen:expect([[ + {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2: }{1: 5│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2: }{1: 6│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2: }{1: 7│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2:+}{1: 8│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 9│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2: }{1:10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + | + ]]) + end) + + it('works with \'statuscolumn\' clicks', function() + command('set mousemodel=extend') + command([[ + function! MyClickFunc(minwid, clicks, button, mods) + let g:testvar = printf("%d %d %s %d", a:minwid, a:clicks, a:button, getmousepos().line) + if a:mods !=# ' ' + let g:testvar ..= '(' .. a:mods .. ')' + endif + endfunction + set stc=%0@MyClickFunc@%=%l%T + ]]) + meths.input_mouse('left', 'press', '', 0, 0, 0) + eq('0 1 l 4', eval("g:testvar")) + meths.input_mouse('left', 'press', '', 0, 0, 0) + eq('0 2 l 4', eval("g:testvar")) + meths.input_mouse('left', 'press', '', 0, 0, 0) + eq('0 3 l 4', eval("g:testvar")) + meths.input_mouse('left', 'press', '', 0, 0, 0) + eq('0 4 l 4', eval("g:testvar")) + meths.input_mouse('right', 'press', '', 0, 3, 0) + eq('0 1 r 7', eval("g:testvar")) + meths.input_mouse('right', 'press', '', 0, 3, 0) + eq('0 2 r 7', eval("g:testvar")) + meths.input_mouse('right', 'press', '', 0, 3, 0) + eq('0 3 r 7', eval("g:testvar")) + meths.input_mouse('right', 'press', '', 0, 3, 0) + eq('0 4 r 7', eval("g:testvar")) + end) +end) -- cgit From 1df2db0bc4dfa2e4f632f9b3dbae00b8b29f2d9f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 10 Jan 2023 11:30:45 +0800 Subject: test(statuscolumn): add more tests for wrapped lines (#21718) test(statuscolumn): add more tests more wrapped lines Also initialize a "relnum" variable to suppress a Coverity warning. The uninitialized value wasn't actually used by build_statuscol_str(). --- test/functional/ui/statuscolumn_spec.lua | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index 1ee96ed625..cdc2cb8746 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -240,6 +240,59 @@ describe('statuscolumn', function() {2: }{1: │ }aaaaaa | | ]]) + -- v:lnum is the same value on wrapped lines + command("set stc=%C%=%{v:lnum}│%s\\ ") + screen:expect([[ + {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 4│ }aaaaaa | + {2: }{1: 5│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 5│ }aaaaaa | + {2: }{1: 6│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 6│ }aaaaaa | + {2: }{1: 7│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 7│ }aaaaaa | + {2:+}{1: 8│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 9│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 9│ }aaaaaa | + {2: }{1:10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1:10│ }aaaaaa | + | + ]]) + -- v:relnum is the same value on wrapped lines + command("set stc=%C%=\\ %{v:relnum}│%s\\ ") + screen:expect([[ + {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 4│ }aaaaaa | + {2: }{1: 3│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 3│ }aaaaaa | + {2: }{1: 2│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 2│ }aaaaaa | + {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 1│ }aaaaaa | + {2:+}{1: 0│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 1│ }aaaaaa | + {2: }{1: 2│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 2│ }aaaaaa | + | + ]]) + command("set stc=%C%=\\ %{v:wrap?'':v:relnum}│%s\\ ") + screen:expect([[ + {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2: }{1: 3│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2: }{1: 2│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2:+}{1: 0│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + {2: }{1: 2│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaa | + | + ]]) end) it('works with \'statuscolumn\' clicks', function() -- cgit From 87cfe50944ef2c84de98eb6b124fe312eef31313 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 10 Jan 2023 17:36:48 +0800 Subject: fix(ui): set stc to empty in floatwin with minimal style (#21720) fix(ui): set stc to emtpy in floatwin with minimal style --- test/functional/ui/float_spec.lua | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 61143e953c..f0950959ff 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1329,6 +1329,54 @@ describe('float window', function() end end) + it("would not break 'minimal' style with statuscolumn set", function() + command('set number') + command('set signcolumn=yes') + command('set colorcolumn=1') + command('set cursorline') + command('set foldcolumn=1') + command('set statuscolumn=%l%s%C') + command('hi NormalFloat guibg=#333333') + feed('ixygg') + meths.open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10, style='minimal'}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + {20:1}{21: }{19: }{20: }{22:^x}{21: }| + {14:2 }{19: }{14: }{22:y} | + {14:3 }{19: }{14: }{22: } | + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 4 + {15:x }| + {15:y }| + {15: }| + {15: }| + ]], float_pos={[4] = {{id = 1001}, "NW", 1, 4, 10, true}}} + else + screen:expect{grid=[[ + {20:1}{21: }{19: }{20: }{22:^x}{21: }| + {14:2 }{19: }{14: }{22:y} | + {14:3 }{19: }{14: }{22: } {15:x } | + {0:~ }{15:y }{0: }| + {0:~ }{15: }{0: }| + {0:~ }{15: }{0: }| + | + ]]} + end + end) + it('can have border', function() local buf = meths.create_buf(false, false) meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', -- cgit From 870ca1de52b240926b88f01afa697cd9b119bdac Mon Sep 17 00:00:00 2001 From: Sebastian Lyng Johansen Date: Tue, 10 Jan 2023 11:22:41 +0100 Subject: feat(float): open float relative to mouse #21531 Problem: No easy way to position a LSP hover window relative to mouse. Solution: Introduce another option to the `relative` key in `nvim_open_win()`. With this PR it should be possible to override the handler and do something similar to this https://github.com/neovim/neovim/pull/19481#issuecomment-1193248674 to have hover information displayed from the mouse. Test case: ```lua local util = require('vim.lsp.util') local function make_position_param(window, offset_encoding) window = window or 0 local buf = vim.api.nvim_win_get_buf(window) local row, col local mouse = vim.fn.getmousepos() row = mouse.line col = mouse.column offset_encoding = offset_encoding or util._get_offset_encoding(buf) row = row - 1 local line = vim.api.nvim_buf_get_lines(buf, row, row + 1, true)[1] if not line then return { line = 0, character = 0 } end if #line < col then return { line = 0, character = 0 } end col = util._str_utfindex_enc(line, col, offset_encoding) return { line = row, character = col } end local make_params = function(window, offset_encoding) window = window or 0 local buf = vim.api.nvim_win_get_buf(window) offset_encoding = offset_encoding or util._get_offset_encoding(buf) return { textDocument = util.make_text_document_params(buf), position = make_position_param(window, offset_encoding), } end local hover_timer = nil vim.o.mousemoveevent = true vim.keymap.set({ '', 'i' }, '', function() if hover_timer then hover_timer:close() end hover_timer = vim.defer_fn(function() hover_timer = nil local params = make_params() vim.lsp.buf_request( 0, 'textDocument/hover', params, vim.lsp.with(vim.lsp.handlers.hover, { silent = true, focusable = false, relative = 'mouse', }) ) end, 500) return '' end, { expr = true }) ``` --- test/functional/ui/float_spec.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index f0950959ff..038b9739a5 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -168,6 +168,29 @@ describe('float window', function() eq(7, pos[2]) end) + it('opened with correct position relative to the mouse', function() + meths.input_mouse('left', 'press', '', 0, 10, 10) + local pos = exec_lua([[ + local bufnr = vim.api.nvim_create_buf(false, true) + + local opts = { + width = 10, + height = 10, + col = 1, + row = 2, + relative = 'mouse', + style = 'minimal' + } + + local win_id = vim.api.nvim_open_win(bufnr, false, opts) + + return vim.api.nvim_win_get_position(win_id) + ]]) + + eq(12, pos[1]) + eq(11, pos[2]) + end) + it('opened with correct position relative to the cursor', function() local pos = exec_lua([[ local bufnr = vim.api.nvim_create_buf(false, true) -- cgit From 9b1112cf48238260b170b8763b18a02a58159c2a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 10 Jan 2023 21:18:12 +0800 Subject: fix(statuscolumn): fix crashes and clang/PVS warnings (#21725) --- test/functional/api/vim_spec.lua | 7 ++++++- test/functional/ui/statuscolumn_spec.lua | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 98bfb83dbd..aa2f46bb59 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3126,7 +3126,12 @@ describe('API', function() eq('E539: Illegal character <}>', pcall_err(meths.eval_statusline, '%{%}', {})) end) - it('supports %S item', function() + it('supports various items', function() + eq({ str = '0', width = 1 }, + meths.eval_statusline('%l', { maxwidth = 5 })) + command('set readonly') + eq({ str = '[RO]', width = 4 }, + meths.eval_statusline('%r', { maxwidth = 5 })) local screen = Screen.new(80, 24) screen:attach() command('set showcmd') diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index cdc2cb8746..912c139ae4 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -293,6 +293,31 @@ describe('statuscolumn', function() {2: }{1: │ }aaaaaa | | ]]) + -- Up to 9 signs in a line + command('set signcolumn=auto:9 foldcolumn=auto') + command('sign place 5 line=6 name=piet1 buffer=1') + command('sign place 6 line=6 name=piet2 buffer=1') + command('sign place 7 line=6 name=piet1 buffer=1') + command('sign place 8 line=6 name=piet2 buffer=1') + command('sign place 9 line=6 name=piet1 buffer=1') + command('sign place 10 line=6 name=piet2 buffer=1') + command('sign place 11 line=6 name=piet1 buffer=1') + screen:expect([[ + {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: 3│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: 2│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | + {2:+}{1: 0│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaa}| + {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: 2│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | + | + ]]) end) it('works with \'statuscolumn\' clicks', function() -- cgit From 438b4361cc761a2950689668f008cfe06c1510f7 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 10 Jan 2023 18:49:57 +0100 Subject: build: use modern cmake (#21589) Replace old-school cmake with the so-called "Modern CMake", meaning preferring using targets and properties over directory settings and variables. This allows greater flexibility, robustness and clarity over how the code works. The following deprecated commands will be replaced with their modern alternatives that operates on a specific target, rather than all targets in the current directory: - add_compile_options -> target_compile_options - include_directories -> target_include_directories - link_libraries -> target_link_libraries - add_definitions -> target_compile_definitions There are mainly four main targets that we currently use: nvim, libnvim, nvim-test (used by unittests) and ${texe} (used by check-single-includes). The goal is to explicitly define the dependencies of each target fully, rather than having everything be dependent on everything else. --- test/functional/fixtures/CMakeLists.txt | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'test/functional') diff --git a/test/functional/fixtures/CMakeLists.txt b/test/functional/fixtures/CMakeLists.txt index a5410c2f8c..6e64b1e4dc 100644 --- a/test/functional/fixtures/CMakeLists.txt +++ b/test/functional/fixtures/CMakeLists.txt @@ -1,14 +1,23 @@ -add_executable(tty-test EXCLUDE_FROM_ALL tty-test.c) -target_link_libraries(tty-test ${LIBUV_LIBRARIES}) +add_library(test_lib INTERFACE) +if(MINGW) + target_link_libraries(test_lib INTERFACE -municode) +endif() +if(WIN32) + target_compile_definitions(test_lib INTERFACE MSWIN) +endif() +target_link_libraries(test_lib INTERFACE nvim) +add_executable(tty-test EXCLUDE_FROM_ALL tty-test.c) add_executable(shell-test EXCLUDE_FROM_ALL shell-test.c) # Fake pwsh (powershell) for testing make_filter_cmd(). #16271 add_executable(pwsh-test EXCLUDE_FROM_ALL shell-test.c) add_executable(printargs-test EXCLUDE_FROM_ALL printargs-test.c) add_executable(printenv-test EXCLUDE_FROM_ALL printenv-test.c) -if(MINGW) - set_target_properties(printenv-test PROPERTIES LINK_FLAGS -municode) -endif() - add_executable(streams-test EXCLUDE_FROM_ALL streams-test.c) -target_link_libraries(streams-test ${LIBUV_LIBRARIES}) + +target_link_libraries(tty-test PRIVATE test_lib) +target_link_libraries(shell-test PRIVATE test_lib) +target_link_libraries(pwsh-test PRIVATE test_lib) +target_link_libraries(printargs-test PRIVATE test_lib) +target_link_libraries(printenv-test PRIVATE test_lib) +target_link_libraries(streams-test PRIVATE test_lib) -- cgit From 93d99aefd314bc4abfc54c0c29a4de84b6fcc823 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Wed, 11 Jan 2023 02:52:11 +0100 Subject: fix(statuscolumn): fix sign column highlights (#21727) Resolve #21726. --- test/functional/ui/float_spec.lua | 12 +-- test/functional/ui/sign_spec.lua | 10 +- test/functional/ui/statuscolumn_spec.lua | 163 +++++++++++++++++-------------- 3 files changed, 106 insertions(+), 79 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 038b9739a5..6759510ad1 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1373,9 +1373,9 @@ describe('float window', function() [2:----------------------------------------]| [3:----------------------------------------]| ## grid 2 - {20:1}{21: }{19: }{20: }{22:^x}{21: }| - {14:2 }{19: }{14: }{22:y} | - {14:3 }{19: }{14: }{22: } | + {20:1}{19: }{20: }{22:^x}{21: }| + {14:2}{19: }{14: }{22:y} | + {14:3}{19: }{14: }{22: } | {0:~ }| {0:~ }| {0:~ }| @@ -1389,9 +1389,9 @@ describe('float window', function() ]], float_pos={[4] = {{id = 1001}, "NW", 1, 4, 10, true}}} else screen:expect{grid=[[ - {20:1}{21: }{19: }{20: }{22:^x}{21: }| - {14:2 }{19: }{14: }{22:y} | - {14:3 }{19: }{14: }{22: } {15:x } | + {20:1}{19: }{20: }{22:^x}{21: }| + {14:2}{19: }{14: }{22:y} | + {14:3}{19: }{14: }{22: } {15:x } | {0:~ }{15:y }{0: }| {0:~ }{15: }{0: }| {0:~ }{15: }{0: }| diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua index a1683a32c9..7dcd4cff25 100644 --- a/test/functional/ui/sign_spec.lua +++ b/test/functional/ui/sign_spec.lua @@ -156,6 +156,9 @@ describe('Signs', function() {0:~ }| | ]]) + -- Check that 'statuscolumn' correctly applies numhl + command('set statuscolumn=%s%=%l\\ ') + screen:expect_unchanged() end) it('highlights the cursorline sign with culhl', function() @@ -233,11 +236,13 @@ describe('Signs', function() | ]]) command('set cursorlineopt=number') + command('hi! link SignColumn IncSearch') + feed('Go2G') screen:expect([[ {1:>>}a | {8:>>}^b | {1:>>}c | - {0:~ }| + {5: } | {0:~ }| {0:~ }| {0:~ }| @@ -249,6 +254,9 @@ describe('Signs', function() {0:~ }| | ]]) + -- Check that 'statuscolumn' cursorline/signcolumn highlights are the same (#21726) + command('set statuscolumn=%s') + screen:expect_unchanged() end) it('multiple signs #9295', function() diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index 912c139ae4..ca7d8af7f4 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -181,6 +181,8 @@ describe('statuscolumn', function() [1] = {foreground = Screen.colors.Brown}, [2] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGrey}, [3] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey}, + [4] = {bold = true, foreground = Screen.colors.Brown}, + [5] = {background = Screen.colors.Grey90}, }) screen:expect([[ {1: 4│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| @@ -206,91 +208,108 @@ describe('statuscolumn', function() command('sign place 3 line=6 name=piet1 buffer=1') command('sign place 4 line=6 name=piet2 buffer=1') screen:expect([[ - {1:>> 4│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {1: │ }aaaaa | - {0:>!}{1: 5│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {1: │ }aaaaa | + {1:>>}{2: }{1: 4│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaa | + {0:>!}{2: }{1: 5│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaa | {1:>>}{0:>!}{1: 6│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {1: │ }aaaaa | - {1: 7│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {1: │ }aaaaa | - {1: 8│ }^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {1: │ }aaaaa | - {1: 9│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {1: │ }aaaaa | - {1: 10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{0:@@@}| + {2: }{1: │ }aaaaa | + {2: }{1: 7│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaa | + {2: }{1: 8│ }^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaa | + {2: }{1: 9│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │ }aaaaa | + {2: }{1:10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{0:@@@}| | ]]) command('norm zf$') -- Check that alignment works properly with signs after %= command("set stc=%C%=%{v:wrap?'':v:lnum}│%s\\ ") screen:expect([[ - {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | - {2: }{1: 5│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | + {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1: 5│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | {2: }{1: 6│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | - {2: }{1: 7│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | - {2:+}{1: 8│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| - {2: }{1: 9│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | - {2: }{1:10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1: 7│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2:+}{1: 8│}{2: }{1: }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 9│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1:10│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + | + ]]) + command('set cursorline') + screen:expect([[ + {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1: 5│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1: 6│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1: 7│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2:+}{4: 8│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 9│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1:10│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | | ]]) -- v:lnum is the same value on wrapped lines command("set stc=%C%=%{v:lnum}│%s\\ ") screen:expect([[ - {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 4│ }aaaaaa | - {2: }{1: 5│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 5│ }aaaaaa | + {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 4│}{2: }{1: }aaaaaa | + {2: }{1: 5│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 5│}{2: }{1: }aaaaaa | {2: }{1: 6│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 6│ }aaaaaa | - {2: }{1: 7│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 7│ }aaaaaa | - {2:+}{1: 8│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| - {2: }{1: 9│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 9│ }aaaaaa | - {2: }{1:10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1:10│ }aaaaaa | + {2: }{1: 6│}{2: }{1: }aaaaaa | + {2: }{1: 7│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 7│}{2: }{1: }aaaaaa | + {2:+}{4: 8│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 9│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 9│}{2: }{1: }aaaaaa | + {2: }{1:10│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1:10│}{2: }{1: }aaaaaa | | ]]) -- v:relnum is the same value on wrapped lines command("set stc=%C%=\\ %{v:relnum}│%s\\ ") screen:expect([[ - {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 4│ }aaaaaa | - {2: }{1: 3│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 3│ }aaaaaa | + {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 4│}{2: }{1: }aaaaaa | + {2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 3│}{2: }{1: }aaaaaa | {2: }{1: 2│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 2│ }aaaaaa | - {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 1│ }aaaaaa | - {2:+}{1: 0│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| - {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 1│ }aaaaaa | - {2: }{1: 2│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: 2│ }aaaaaa | + {2: }{1: 2│}{2: }{1: }aaaaaa | + {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 1│}{2: }{1: }aaaaaa | + {2:+}{4: 0│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 1│}{2: }{1: }aaaaaa | + {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: 2│}{2: }{1: }aaaaaa | | ]]) command("set stc=%C%=\\ %{v:wrap?'':v:relnum}│%s\\ ") screen:expect([[ - {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | - {2: }{1: 3│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | + {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | {2: }{1: 2│>>}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | - {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | - {2:+}{1: 0│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| - {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | - {2: }{1: 2│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaa | + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2:+}{4: 0│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | + {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaa | | ]]) -- Up to 9 signs in a line @@ -303,19 +322,19 @@ describe('statuscolumn', function() command('sign place 10 line=6 name=piet2 buffer=1') command('sign place 11 line=6 name=piet1 buffer=1') screen:expect([[ - {2: }{1: 4│>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | - {2: }{1: 3│}{0:>!}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | {2: }{1: 2│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | - {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | - {2:+}{1: 0│ }{3:^+-- 1 line: aaaaaaaaaaaaaaaaa}| - {2: }{1: 1│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | - {2: }{1: 2│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - {2: }{1: │ }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | + {2:+}{4: 0│}{2: }{4: }{5:^+-- 1 line: aaaaaaaaaaaaaaaaa}| + {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | + {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | | ]]) end) -- cgit From 0fd59f0121bbf8906203689c790eeba6f501600e Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Thu, 12 Jan 2023 16:04:43 +0100 Subject: fix(statuscolumn): foldcolumn buffer is too small (#21761) Resolve https://github.com/neovim/neovim/issues/21759. --- test/functional/ui/statuscolumn_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index ca7d8af7f4..2905f1d64c 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -367,4 +367,26 @@ describe('statuscolumn', function() meths.input_mouse('right', 'press', '', 0, 3, 0) eq('0 4 r 7', eval("g:testvar")) end) + + it('fits maximum multibyte foldcolumn #21759', function() + command('set stc=%C fdc=9 fillchars=foldsep:𒀀') + for _ = 0,8 do command('norm zfjzo') end + screen:expect([[ + aaaaa | + aaaaa | + aaaaa | + aaaaa | + --------- ^aaaaa | + 𒀀𒀀𒀀𒀀𒀀𒀀𒀀𒀀𒀀 aaaaa | + aaaaa | + aaaaa | + aaaaa | + aaaaa | + aaaaa | + aaaaa | + aaaaa | + | + ]]) + end) + end) -- cgit From 921e634119c14b03f9611f1602df171c9ffc9559 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 12 Jan 2023 16:25:44 +0100 Subject: fix(api): nvim_create_autocmd crash on invalid types inside pattern array Co-authored-by: ii14 --- test/functional/api/autocmd_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 7fb52b097b..22a1311ee9 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -613,6 +613,20 @@ describe('autocmd api', function() eq(false, success) matches("'group' must be a string or an integer", code) end) + + it('raises error for invalid pattern array', function() + local success, code = unpack(meths.exec_lua([[ + return {pcall(function() + vim.api.nvim_create_autocmd("FileType", { + pattern = {{}}, + command = "echo 'hello'", + }) + end)} + ]], {})) + + eq(false, success) + matches("All entries in 'pattern' must be strings", code) + end) end) describe('patterns', function() -- cgit From 572cd8031dd7c91ac9e17cbdfab16d87f1fed6b7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 13 Jan 2023 00:57:39 +0800 Subject: feat(diagnostic): vim.diagnostic.is_disabled() #21527 --- test/functional/lua/diagnostic_spec.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 946994fd97..d364986ad7 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -2124,5 +2124,31 @@ end) return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr ]]) end) + + it("checks if diagnostics are disabled in a buffer", function() + eq({true, true, true , true}, exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Diagnostic #1', 1, 1, 1, 1), + }) + vim.api.nvim_set_current_buf(diagnostic_bufnr) + vim.diagnostic.disable() + return { + vim.diagnostic.is_disabled(), + vim.diagnostic.is_disabled(diagnostic_bufnr), + vim.diagnostic.is_disabled(diagnostic_bufnr, diagnostic_ns), + vim.diagnostic.is_disabled(_, diagnostic_ns), + } + ]]) + + eq({false, false, false , false}, exec_lua [[ + vim.diagnostic.enable() + return { + vim.diagnostic.is_disabled(), + vim.diagnostic.is_disabled(diagnostic_bufnr), + vim.diagnostic.is_disabled(diagnostic_bufnr, diagnostic_ns), + vim.diagnostic.is_disabled(_, diagnostic_ns), + } + ]]) + end) end) end) -- cgit From 2f1fd15554921dc2375c2ad136e727229e72348a Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Thu, 12 Jan 2023 23:25:29 +0600 Subject: fix(powershell): wrong length allocation for ":%w !" #20530 Problem: The calculation of `len` in `make_filter_cmd` for powershell falls short by one character for the following ex command: :%w !sort This command satisfies these conditions: - `itmp` is not null - `otmp` is null __NOTE__ that other shells circumvent this bug only because of `len` allocation for six extra characters: a pair of curly braces and four spaces: https://github.com/neovim/neovim/blob/cfdb4cbada8c65aa57e69776bcc0f7b8b298317a/src/nvim/ex_cmds.c#L1551-L1554 If allocation for these six characters are removed, then bash also faces the same bug. Solution: Add allocation for 6 extra bytes. 1 would do, but let's keep powershell in sync with other shells as much as possible. --- test/functional/vimscript/system_spec.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/functional') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index f099b4a36e..7ada1c4bea 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -662,4 +662,33 @@ describe('shell :!', function() 1]]) end end) + + it(':{range}! without redirecting to buffer', function() + local screen = Screen.new(500, 10) + screen:attach() + insert([[ + 3 + 1 + 4 + 2]]) + feed(':4verbose %w !sort') + if is_os('win') then + screen:expect{ + any=[[Executing command: .?sort %< .*]] + } + else + screen:expect{ + any=[[Executing command: .?%(sort%) %< .*]] + + } + end + feed('') + helpers.set_shell_powershell(true) + feed(':4verbose %w !sort') + screen:expect{ + any=[[Executing command: .?& { Get%-Content .* | & sort }]] + } + feed('') + helpers.expect_exit(command, 'qall!') + end) end) -- cgit From 4876654d4cc9bb43f266c7c9d412f36ab57fa571 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:36:59 +0100 Subject: fix(mouse): statusline click registered as statuscolumn (#21748) fix(statuscolumn): statusline click registered as statuscolumn Problem: Status line click is registered as status status column click. Solution: Check that mouse is not on the status line. Resolve https://github.com/luukvbaal/statuscol.nvim/issues/4. --- test/functional/ui/statuscolumn_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index 2905f1d64c..74e6d61ff3 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -366,6 +366,14 @@ describe('statuscolumn', function() eq('0 3 r 7', eval("g:testvar")) meths.input_mouse('right', 'press', '', 0, 3, 0) eq('0 4 r 7', eval("g:testvar")) + command('set laststatus=2 winbar=%f') + command('let g:testvar=""') + -- Check that winbar click doesn't register as statuscolumn click + meths.input_mouse('right', 'press', '', 0, 0, 0) + eq('', eval("g:testvar")) + -- Check that statusline click doesn't register as statuscolumn click + meths.input_mouse('right', 'press', '', 0, 12, 0) + eq('', eval("g:testvar")) end) it('fits maximum multibyte foldcolumn #21759', function() -- cgit From 1097d239c307a10a87fa995c4cfbe5987939e177 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Fri, 13 Jan 2023 04:47:55 +0100 Subject: fix(ui): command line issues with external messages (#21709) * fix: don't truncate external messages * fix: avoid resizing command line with external messages --- test/functional/ui/cmdline_spec.lua | 10 +++++++--- test/functional/ui/messages_spec.lua | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 8e689fb378..0fa6929df0 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -8,6 +8,7 @@ local exec = helpers.exec local eval = helpers.eval local eq = helpers.eq local is_os = helpers.is_os +local meths = helpers.meths local function new_screen(opt) local screen = Screen.new(25, 5) @@ -1387,17 +1388,20 @@ describe('cmdheight=0', function() ]]) end) - it("clears cmdline area when resized with external messages", function() + it("cannot be resized at all with external messages", function() clear() screen = new_screen({rgb=true, ext_messages=true}) - command('set laststatus=2 cmdheight=0') + command('set laststatus=2 mouse=a') command('resize -1') screen:expect([[ ^ | {1:~ }| {1:~ }| + {1:~ }| {3:[No Name] }| - | ]]) + meths.input_mouse('left', 'press', '', 0, 6, 10) + meths.input_mouse('left', 'drag', '', 0, 5, 10) + screen:expect_unchanged() end) end) diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index f7ffe16bd6..8320db2804 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -908,6 +908,13 @@ stack traceback: {1:~ }| ]]} end) + + it('does not truncate messages', function() + command('write Xtest') + screen:expect({messages={ + {content = { { '"Xtest" [New] 0L, 0B written' } }, kind = "" } + }}) + end) end) describe('ui/builtin messages', function() -- cgit From 449c0762d351bca94438813f9226b8906b46adb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 13 Jan 2023 12:25:19 +0800 Subject: test: avoid consecutive mouse input at different positions (#21781) The seconds call's position may override the first call if the first call isn't processed yet, defeating the purpose of the first call. --- test/functional/ui/cmdline_spec.lua | 2 ++ test/functional/ui/messages_spec.lua | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 0fa6929df0..1c9ac7f7ba 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -4,6 +4,7 @@ local clear, feed = helpers.clear, helpers.feed local source = helpers.source local command = helpers.command local assert_alive = helpers.assert_alive +local poke_eventloop = helpers.poke_eventloop local exec = helpers.exec local eval = helpers.eval local eq = helpers.eq @@ -1401,6 +1402,7 @@ describe('cmdheight=0', function() {3:[No Name] }| ]]) meths.input_mouse('left', 'press', '', 0, 6, 10) + poke_eventloop() meths.input_mouse('left', 'drag', '', 0, 5, 10) screen:expect_unchanged() end) diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 8320db2804..3052a74f38 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -1459,7 +1459,6 @@ describe('ui/ext_messages', function() feed(":set mouse=a") meths.input_mouse('left', 'press', '', 0, 12, 10) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 12, 10) meths.input_mouse('left', 'drag', '', 0, 11, 10) feed("") feed(":set cmdheight") -- cgit From 4a12372ccf70236c1c23144129984a3629cc45f3 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Fri, 13 Jan 2023 10:41:19 +0100 Subject: fix(statuscolumn): make %l/%r respect 'number'/'relativenumber' (#21747) Resolve https://github.com/neovim/neovim/issues/21745. --- test/functional/ui/statuscolumn_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional') diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index 74e6d61ff3..a9d796c10b 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -77,6 +77,9 @@ describe('statuscolumn', function() 16│aaaaa | | ]]) + command([[set stc=%l%=%{&rnu?'\ ':''}%r│]]) + screen:expect_unchanged() + command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]]) command('set relativenumber') screen:expect([[ 4 4│aaaaa | @@ -94,6 +97,9 @@ describe('statuscolumn', function() 16 8│aaaaa | | ]]) + command([[set stc=%l%=%{&rnu?'\ ':''}%r│]]) + screen:expect_unchanged() + command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]]) command('norm 12GH') screen:expect([[ 4 0│^aaaaa | @@ -111,6 +117,9 @@ describe('statuscolumn', function() 16 12│aaaaa | | ]]) + command([[set stc=%l%=%{&rnu?'\ ':''}%r│]]) + screen:expect_unchanged() + command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]]) end) it('works with highlighted \'statuscolumn\'', function() -- cgit From d1183b48ad4901a166dcb296170fb066c78512ef Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Jan 2023 18:36:59 +0800 Subject: vim-patch:8.2.4341: command line not redrawn when finishing popup menu (#21792) Problem: Command line not redrawn when finishing popup menu and the screen has scrolled up. Solution: Redraw the command line after updating the screen. (closes vim/vim#9722) https://github.com/vim/vim/commit/414acd342f4a66d930da34d419929985b48bd301 Code change is N/A as Nvim doesn't call update_screen() here. Co-authored-by: Bram Moolenaar --- test/functional/ui/popupmenu_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index c1f30140e2..78b2f52c1f 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -2486,7 +2486,7 @@ describe('builtin popupmenu', function() ]]) end) - it('wildoptions=pum with scrolled messages ', function() + it('wildoptions=pum with scrolled messages', function() screen:try_resize(40,10) command('set wildmenu') command('set wildoptions=pum') -- cgit From d98e4e4b2ecd84162635a5f354dc4ddc6a49abc5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Jan 2023 19:52:44 +0800 Subject: vim-patch:9.0.1195: restoring KeyTyped when building statusline not tested Problem: Restoring KeyTyped when building statusline not tested. Solution: Add a test. Clean up and fix other tests. (closes vim/vim#11815) https://github.com/vim/vim/commit/378e6c03f98efc88e8c2675e05a548f9bb7889a1 --- test/functional/legacy/statusline_spec.lua | 38 +++++++++++++++++++++- test/functional/legacy/tabline_spec.lua | 51 ++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/legacy/statusline_spec.lua b/test/functional/legacy/statusline_spec.lua index 056209154e..c5b17f8749 100644 --- a/test/functional/legacy/statusline_spec.lua +++ b/test/functional/legacy/statusline_spec.lua @@ -76,14 +76,46 @@ describe('statusline', function() [1] = {background = Screen.colors.LightGrey}, -- Visual [2] = {bold = true}, -- MoreMsg [3] = {bold = true, reverse = true}, -- StatusLine + [5] = {background = Screen.colors.LightGrey, foreground = Screen.colors.DarkBlue}, -- Folded }) exec([[ + func MyStatusLine() + return '%S' + endfunc + set showcmd set laststatus=2 set statusline=%S set showcmdloc=statusline call setline(1, ['a', 'b', 'c']) + set foldopen+=jump + 1,2fold + 3 + ]]) + + feed('g') + screen:expect([[ + {5:+-- 2 lines: a···································}| + ^c | + {0:~ }| + {0:~ }| + {0:~ }| + {3:g }| + | ]]) + + -- typing "gg" should open the fold + feed('g') + screen:expect([[ + ^a | + b | + c | + {0:~ }| + {0:~ }| + {3: }| + | + ]]) + feed('Gl') screen:expect([[ {1:a} | @@ -94,6 +126,7 @@ describe('statusline', function() {3:3x2 }| {2:-- VISUAL BLOCK --} | ]]) + feed('1234') screen:expect([[ a | @@ -104,7 +137,10 @@ describe('statusline', function() {3:1234 }| | ]]) - feed(':set statusline=:1234') + + feed(':set statusline=') + feed(':') + feed('1234') screen:expect([[ a | b | diff --git a/test/functional/legacy/tabline_spec.lua b/test/functional/legacy/tabline_spec.lua index d858f137c5..6b368d1857 100644 --- a/test/functional/legacy/tabline_spec.lua +++ b/test/functional/legacy/tabline_spec.lua @@ -22,16 +22,49 @@ describe('tabline', function() [2] = {bold = true}, -- MoreMsg, TabLineSel [3] = {reverse = true}, -- TabLineFill [4] = {background = Screen.colors.LightGrey, underline = true}, -- TabLine + [5] = {background = Screen.colors.LightGrey, foreground = Screen.colors.DarkBlue}, -- Folded }) exec([[ + func MyTabLine() + return '%S' + endfunc + set showcmd set showtabline=2 + set tabline=%!MyTabLine() set showcmdloc=tabline call setline(1, ['a', 'b', 'c']) + set foldopen+=jump + 1,2fold + 3 + ]]) + + feed('g') + screen:expect([[ + {3:g }| + {5:+-- 2 lines: a···································}| + ^c | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + + -- typing "gg" should open the fold + feed('g') + screen:expect([[ + {3: }| + ^a | + b | + c | + {0:~ }| + {0:~ }| + | ]]) + feed('Gl') screen:expect([[ - {2: + [No Name] }{3: }{4:3x2}{3: }| + {3:3x2 }| {1:a} | {1:b} | {1:c}^ | @@ -39,9 +72,10 @@ describe('tabline', function() {0:~ }| {2:-- VISUAL BLOCK --} | ]]) + feed('1234') screen:expect([[ - {2: + [No Name] }{3: }{4:1234}{3: }| + {3:1234 }| a | b | ^c | @@ -49,5 +83,18 @@ describe('tabline', function() {0:~ }| | ]]) + + feed(':set tabline=') + feed(':') + feed('1234') + screen:expect([[ + {2: + [No Name] }{3: }{4:1234}{3: }| + a | + b | + ^c | + {0:~ }| + {0:~ }| + : | + ]]) end) end) -- cgit From 066a1a069b2b0d97308ed2bdb18fbef488051e12 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 15 Jan 2023 07:01:14 +0800 Subject: vim-patch:8.2.4579: cannot use page-up and page-down in the cmdline popup menu Problem: Cannot use page-up and page-down in the command line completion popup menu. Solution: Check for to page-up and page-down keys. (Yegappan Lakshmanan, closes vim/vim#9960) https://github.com/vim/vim/commit/5cffa8df7e3c28681b9e5deef6df395784359b6b Co-authored-by: Yegappan Lakshmanan --- test/functional/ui/popupmenu_spec.lua | 124 +++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 78b2f52c1f..85e6a03872 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -2388,8 +2388,130 @@ describe('builtin popupmenu', function() {1:~ }{n: xyz }{1: }| :e あいう/123^ | ]]) + feed('') - feed('') + -- Pressing should scroll the menu downward + feed(':sign ') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{n: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{s: undefine }{1: }| + {1:~ }{n: unplace }{1: }| + :sign undefine^ | + ]]) + feed('') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{n: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{s: unplace }{1: }| + :sign unplace^ | + ]]) + feed('') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{n: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{n: unplace }{1: }| + :sign ^ | + ]]) + feed('') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{s: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{n: unplace }{1: }| + :sign define^ | + ]]) + feed('sign ') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{n: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{s: unplace }{1: }| + :sign unplace^ | + ]]) + + -- Pressing should scroll the menu upward + feed('sign ') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{n: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{n: unplace }{1: }| + :sign ^ | + ]]) + feed('') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{n: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{s: unplace }{1: }| + :sign unplace^ | + ]]) + feed('') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{n: define }{1: }| + {1:~ }{s: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{n: unplace }{1: }| + :sign jump^ | + ]]) + feed('') + screen:expect([[ + | + {1:~ }| + {1:~ }| + {1:~ }{s: define }{1: }| + {1:~ }{n: jump }{1: }| + {1:~ }{n: list }{1: }| + {1:~ }{n: place }{1: }| + {1:~ }{n: undefine }{1: }| + {1:~ }{n: unplace }{1: }| + :sign define^ | + ]]) + + feed('') -- check positioning with multibyte char in pattern command("e långfile1") -- cgit From 6134c1e8a39a5e61d0593613343a5923a86e3545 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 15 Jan 2023 09:34:21 +0800 Subject: test(fileio_spec): avoid expect_exit() without calling clear() (#21810) Since before_each() doesn't call clear() in these tests, after_each() may call expect_exit() without calling clear() if a test is skipped, causing frequent test failures on Cirrus CI. Close the session instead. --- test/functional/core/fileio_spec.lua | 5 +++-- test/functional/helpers.lua | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index ed37032f25..bbf2202f0d 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -22,6 +22,7 @@ local tmpname = helpers.tmpname local trim = helpers.trim local currentdir = helpers.funcs.getcwd local assert_alive = helpers.assert_alive +local check_close = helpers.check_close local expect_exit = helpers.expect_exit local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') @@ -34,7 +35,7 @@ describe('fileio', function() before_each(function() end) after_each(function() - expect_exit(command, ':qall!') + check_close() os.remove('Xtest_startup_shada') os.remove('Xtest_startup_file1') os.remove('Xtest_startup_file1~') @@ -270,7 +271,7 @@ describe('tmpdir', function() end) after_each(function() - expect_exit(command, ':qall!') + check_close() os.remove(testlog) end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index a14bedbbbd..4e8bf1a323 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -397,9 +397,12 @@ local function remove_args(args, args_rm) return new_args end -function module.check_close(old_session) +function module.check_close() + if not session then + return + end local start_time = luv.now() - old_session:close() + session:close() luv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). local end_time = luv.now() local delta = end_time - start_time @@ -408,12 +411,13 @@ function module.check_close(old_session) "This indicates a likely problem with the test even if it passed!\n") io.stdout:flush() end + session = nil end --- @param io_extra used for stdin_fd, see :help ui-option function module.spawn(argv, merge, env, keep, io_extra) - if session and not keep then - module.check_close(session) + if not keep then + module.check_close() end local child_stream = ChildProcessStream.spawn( -- cgit