From d4d27c41b3298c25ae62bc067472bef37bc61c99 Mon Sep 17 00:00:00 2001 From: Axel Forsman Date: Mon, 22 Aug 2022 06:48:18 +0200 Subject: fix(edit.c): indentkeys double indent after "!" #12894 which is both unexpected and different from the Vim behaviour. Indent was triggered once by the '!' check in insert_execute(), and inserting the char was correctly skipped, but then triggered again in insert_check() (provided that cindent was not being ignored after manual indentation, i.e. `can_cindent == true`). While this is the smallest fix, another solution would be to remove VimState#check and instead move that to *_enter()/-_execute(), since the control flow is pretty unnecessarily convoluted as is. That would also have the benefit of differing less from the Vim source code. --- test/functional/editor/mode_insert_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/editor') diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua index e3d3cdbd85..cd51a65be3 100644 --- a/test/functional/editor/mode_insert_spec.lua +++ b/test/functional/editor/mode_insert_spec.lua @@ -6,12 +6,20 @@ local expect = helpers.expect local command = helpers.command local eq = helpers.eq local eval = helpers.eval +local curbuf_contents = helpers.curbuf_contents describe('insert-mode', function() before_each(function() clear() end) + it('indents only once after "!" keys #12894', function() + command('let counter = []') + command('set indentexpr=len(add(counter,0))') + feed('ix') + eq(' x', curbuf_contents()) + end) + it('CTRL-@', function() -- Inserts last-inserted text, leaves insert-mode. insert('hello') -- cgit From b21980bd607e952fe52957aec3214367bd48527b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 29 Aug 2022 05:58:32 +0800 Subject: fix(keywordprg): default to :help if set to empty string (#19983) --- test/functional/editor/K_spec.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'test/functional/editor') diff --git a/test/functional/editor/K_spec.lua b/test/functional/editor/K_spec.lua index 8ad81ac3d6..3b5580540f 100644 --- a/test/functional/editor/K_spec.lua +++ b/test/functional/editor/K_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, eval, feed, retry = - helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.retry +local eq, clear, eval, feed, meths, retry = + helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.meths, helpers.retry describe('K', function() local test_file = 'K_spec_out' @@ -58,4 +58,11 @@ describe('K', function() helpers.neq(bufnr, eval('bufnr()')) end) + it('empty string falls back to :help #19298', function() + meths.set_option('keywordprg', '') + meths.buf_set_lines(0, 0, -1, true, {'doesnotexist'}) + feed('K') + eq('E149: Sorry, no help for doesnotexist', meths.get_vvar('errmsg')) + 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 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/functional/editor') 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({ -- 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/editor') 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 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/editor') 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 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/editor') 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 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/editor') 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 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/editor') 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 -- 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/editor') 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/editor') 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 61d5bd561addfd4cc9917712bdf983e77137089e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 16 Jan 2023 06:38:50 +0800 Subject: refactor: remove E5500, adjust tests Now with try_end() including more exception info, E5500 looks like redundant information. Adjust tests for more exception information. --- test/functional/editor/mark_spec.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/functional/editor') diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index f300fea3a0..b3b190ef79 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -40,59 +40,59 @@ describe('named marks', function() it("errors when set out of range with :mark", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "1000mark x") - eq("Vim(mark):E16: Invalid range: 1000mark x", err) + eq("nvim_exec(): Vim(mark):E16: Invalid range: 1000mark x", err) end) it("errors when set out of range with :k", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "1000kx") - eq("Vim(k):E16: Invalid range: 1000kx", err) + eq("nvim_exec(): Vim(k):E16: Invalid range: 1000kx", err) end) it("errors on unknown mark name with :mark", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "mark #") - eq("Vim(mark):E191: Argument must be a letter or forward/backward quote", err) + eq("nvim_exec(): Vim(mark):E191: Argument must be a letter or forward/backward quote", err) end) it("errors on unknown mark name with '", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "normal! '#") - eq("Vim(normal):E78: Unknown mark", err) + eq("nvim_exec(): Vim(normal):E78: Unknown mark", err) end) it("errors on unknown mark name with `", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "normal! `#") - eq("Vim(normal):E78: Unknown mark", err) + eq("nvim_exec(): Vim(normal):E78: Unknown mark", err) end) it("errors when moving to a mark that is not set with '", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "normal! 'z") - eq("Vim(normal):E20: Mark not set", err) + eq("nvim_exec(): Vim(normal):E20: Mark not set", err) err = pcall_err(helpers.exec_capture, "normal! '.") - eq("Vim(normal):E20: Mark not set", err) + eq("nvim_exec(): Vim(normal):E20: Mark not set", err) end) it("errors when moving to a mark that is not set with `", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "normal! `z") - eq("Vim(normal):E20: Mark not set", err) + eq("nvim_exec(): Vim(normal):E20: Mark not set", err) err = pcall_err(helpers.exec_capture, "normal! `>") - eq("Vim(normal):E20: Mark not set", err) + eq("nvim_exec(): Vim(normal):E20: Mark not set", err) end) it("errors when moving to a global mark that is not set with '", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "normal! 'Z") - eq("Vim(normal):E20: Mark not set", err) + eq("nvim_exec(): Vim(normal):E20: Mark not set", err) end) it("errors when moving to a global mark that is not set with `", function() command("edit " .. file1) local err = pcall_err(helpers.exec_capture, "normal! `Z") - eq("Vim(normal):E20: Mark not set", err) + eq("nvim_exec(): Vim(normal):E20: Mark not set", err) end) it("can move to them using '", function() @@ -153,7 +153,7 @@ describe('named marks', function() command("next") command("bw! " .. file1 ) local err = pcall_err(helpers.exec_capture, "normal! 'A") - eq("Vim(normal):E92: Buffer 1 not found", err) + eq("nvim_exec(): Vim(normal):E92: Buffer 1 not found", err) os.remove(file1) end) -- cgit From d5126787393075f07d4be9dc37f5d7a3cec9e177 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 Jan 2023 15:42:18 +0800 Subject: fix(completion): correct what modes support fuzzy completion --- test/functional/editor/completion_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional/editor') diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index c503d7ebfb..22857efe5b 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -935,6 +935,9 @@ describe('completion', function() eq({'api'}, funcs.getcompletion('vim.ap', 'lua')) eq({'tbl_filter'}, funcs.getcompletion('vim.tbl_fil', 'lua')) eq({'vim'}, funcs.getcompletion('print(vi', 'lua')) + -- fuzzy completion is not supported, so the result should be the same + command('set wildoptions+=fuzzy') + eq({'vim'}, funcs.getcompletion('vi', 'lua')) end) end) -- cgit