diff options
Diffstat (limited to 'test/functional/ui/inccommand_spec.lua')
-rw-r--r-- | test/functional/ui/inccommand_spec.lua | 151 |
1 files changed, 117 insertions, 34 deletions
diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index 6fbf9b72c8..3ee67a710c 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -2,7 +2,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command -local curbufmeths = helpers.curbufmeths local eq = helpers.eq local eval = helpers.eval local feed_command = helpers.feed_command @@ -175,11 +174,14 @@ describe(":substitute, 'inccommand' preserves", function() it("'undolevels' (inccommand="..case..")", function() feed_command("set undolevels=139") feed_command("setlocal undolevels=34") + feed_command("split") -- Show the buffer in multiple windows feed_command("set inccommand=" .. case) insert("as") - feed(":%s/as/glork/<enter>") - eq(meths.get_option('undolevels'), 139) - eq(curbufmeths.get_option('undolevels'), 34) + feed(":%s/as/glork/") + poke_eventloop() + feed("<enter>") + eq(meths.get_option_value('undolevels', {scope='global'}), 139) + eq(meths.get_option_value('undolevels', {buf=0}), 34) end) end @@ -745,10 +747,11 @@ describe(":substitute, 'inccommand' preserves undo", function() end) describe(":substitute, inccommand=split", function() - local screen = Screen.new(30,15) + local screen before_each(function() clear() + screen = Screen.new(30,15) common_setup(screen, "split", default_text .. default_text) end) @@ -1191,7 +1194,7 @@ describe(":substitute, inccommand=split", function() it("deactivates if 'redrawtime' is exceeded #5602", function() -- prevent redraws from 'incsearch' - meths.set_option('incsearch', false) + meths.set_option_value('incsearch', false, {}) -- Assert that 'inccommand' is ENABLED initially. eq("split", eval("&inccommand")) -- Set 'redrawtime' to minimal value, to ensure timeout is triggered. @@ -1413,10 +1416,11 @@ describe(":substitute, inccommand=split", function() end) describe("inccommand=nosplit", function() - local screen = Screen.new(20,10) + local screen before_each(function() clear() + screen = Screen.new(20,10) common_setup(screen, "nosplit", default_text .. default_text) end) @@ -1644,11 +1648,12 @@ describe("inccommand=nosplit", function() end) describe(":substitute, 'inccommand' with a failing expression", function() - local screen = Screen.new(20,10) + local screen local cases = { "", "split", "nosplit" } local function refresh(case) clear() + screen = Screen.new(20,10) common_setup(screen, case, default_text) end @@ -1717,7 +1722,7 @@ describe("'inccommand' and :cnoremap", function() local function refresh(case, visual) clear() - screen = visual and Screen.new(50,10) or nil + screen = visual and Screen.new(80,10) or nil common_setup(screen, case, default_text) end @@ -2127,9 +2132,10 @@ describe("'inccommand' with 'gdefault'", function() end) describe(":substitute", function() - local screen = Screen.new(30,15) + local screen before_each(function() clear() + screen = Screen.new(30,15) end) it("inccommand=split, highlights multiline substitutions", function() @@ -2335,8 +2341,7 @@ describe(":substitute", function() ]]) end) - it("inccommand=split, substitutions of different length", - function() + it("inccommand=split, substitutions of different length", function() common_setup(screen, "split", "T T123 T2T TTT T090804\nx") feed(":%s/T\\([0-9]\\+\\)/\\1\\1/g") @@ -2462,16 +2467,14 @@ describe(":substitute", function() end) it("inccommand=split, contraction of two subsequent NL chars", function() - -- luacheck: push ignore 611 local text = [[ AAA AA - + BBB BB - + CCC CC - + ]] - -- luacheck: pop -- This used to crash, but more than 20 highlight entries are required -- to reproduce it (so that the marktree has multiple nodes) @@ -2498,16 +2501,14 @@ describe(":substitute", function() end) it("inccommand=nosplit, contraction of two subsequent NL chars", function() - -- luacheck: push ignore 611 local text = [[ AAA AA - + BBB BB - + CCC CC - + ]] - -- luacheck: pop common_setup(screen, "nosplit", string.rep(text,10)) feed(":%s/\\n\\n/<c-v><c-m>/g") @@ -2872,8 +2873,8 @@ it(':substitute with inccommand during :terminal activity', function() return end retry(2, 40000, function() - local screen = Screen.new(30,15) clear() + local screen = Screen.new(30,15) command("set cmdwinheight=3") feed(([[:terminal "%s" REP 5000 xxx<cr>]]):format(testprg('shell-test'))) @@ -2886,14 +2887,15 @@ it(':substitute with inccommand during :terminal activity', function() feed('gg') feed(':%s/foo/ZZZ') sleep(20) -- Allow some terminal activity. - helpers.poke_eventloop() + poke_eventloop() + screen:sleep(0) screen:expect_unchanged() end) end) it(':substitute with inccommand, timer-induced :redraw #9777', function() - local screen = Screen.new(30,12) clear() + local screen = Screen.new(30,12) command('set cmdwinheight=3') command('call timer_start(10, {-> execute("redraw")}, {"repeat":-1})') command('call timer_start(10, {-> execute("redrawstatus")}, {"repeat":-1})') @@ -2919,15 +2921,24 @@ it(':substitute with inccommand, timer-induced :redraw #9777', function() end) it(':substitute with inccommand, allows :redraw before first separator is typed #18857', function() - local screen = Screen.new(30,6) clear() + local screen = Screen.new(30,6) common_setup(screen, 'split', 'foo bar baz\nbar baz fox\nbar foo baz') command('hi! link NormalFloat CursorLine') local float_buf = meths.create_buf(false, true) meths.open_win(float_buf, false, { relative = 'editor', height = 1, width = 5, row = 3, col = 0, focusable = false, }) - feed(':%s') + feed(':') + screen:expect([[ + foo bar baz | + bar baz fox | + bar foo baz | + {16: }{15: }| + {15:~ }| + :^ | + ]]) + feed('%s') screen:expect([[ foo bar baz | bar baz fox | @@ -2949,8 +2960,8 @@ it(':substitute with inccommand, allows :redraw before first separator is typed end) it(':substitute with inccommand, does not crash if range contains invalid marks', function() - local screen = Screen.new(30, 6) clear() + local screen = Screen.new(30, 6) common_setup(screen, 'split', 'test') feed([[:'a,'bs]]) screen:expect([[ @@ -2975,8 +2986,8 @@ 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() + local screen = Screen.new(60, 6) common_setup(screen, 'split', 'test') feed(':ls<CR>') screen:expect([[ @@ -3028,8 +3039,8 @@ it(':substitute with inccommand, no unnecessary redraw if preview is not shown', end) it(":substitute doesn't crash with inccommand, if undo is empty #12932", function() - local screen = Screen.new(10,5) clear() + local screen = Screen.new(10,5) command('set undolevels=-1') common_setup(screen, 'split', 'test') feed(':%s/test') @@ -3048,8 +3059,8 @@ it(":substitute doesn't crash with inccommand, if undo is empty #12932", functio end) it(':substitute with inccommand works properly if undo is not synced #20029', function() - local screen = Screen.new(30, 6) clear() + local screen = Screen.new(30, 6) common_setup(screen, 'nosplit', 'foo\nbar\nbaz') meths.set_keymap('x', '<F2>', '<Esc>`<Oaaaaa asdf<Esc>`>obbbbb asdf<Esc>V`<k:s/asdf/', {}) feed('gg0<C-V>lljj<F2>') @@ -3084,11 +3095,40 @@ it(':substitute with inccommand works properly if undo is not synced #20029', fu baz]]) end) +it(':substitute with inccommand does not unexpectedly change viewport #25697', function() + clear() + local screen = Screen.new(45, 5) + common_setup(screen, 'nosplit', long_multiline_text) + command('vnew | tabnew | tabclose') + screen:expect([[ + ^ │£ m n | + {15:~ }│t œ ¥ | + {15:~ }│ | + {11:[No Name] }{10:[No Name] [+] }| + | + ]]) + feed(':s/') + screen:expect([[ + │£ m n | + {15:~ }│t œ ¥ | + {15:~ }│ | + {11:[No Name] }{10:[No Name] [+] }| + :s/^ | + ]]) + feed('<Esc>') + screen:expect([[ + ^ │£ m n | + {15:~ }│t œ ¥ | + {15:~ }│ | + {11:[No Name] }{10:[No Name] [+] }| + | + ]]) +end) + it('long :%s/ with inccommand does not collapse cmdline', function() - local screen = Screen.new(10,5) clear() - common_setup(screen) - command('set inccommand=nosplit') + local screen = Screen.new(10,5) + common_setup(screen, 'nosplit') feed(':%s/AAAAAAA', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A') screen:expect([[ @@ -3100,6 +3140,21 @@ it('long :%s/ with inccommand does not collapse cmdline', function() ]]) end) +it("with 'inccommand' typing invalid `={expr}` does not show error", function() + clear() + local screen = Screen.new(30, 6) + common_setup(screen, 'nosplit') + feed(':edit `=`') + screen:expect([[ + | + {15:~ }| + {15:~ }| + {15:~ }| + {15:~ }| + :edit `=`^ | + ]]) +end) + it("with 'inccommand' typing :filter doesn't segfault or leak memory #19057", function() clear() common_setup(nil, 'nosplit') @@ -3112,3 +3167,31 @@ it("with 'inccommand' typing :filter doesn't segfault or leak memory #19057", fu feed('i') assert_alive() end) + +it("'inccommand' cannot be changed during preview #23136", function() + clear() + local screen = Screen.new(30, 6) + common_setup(screen, 'nosplit', 'foo\nbar\nbaz') + source([[ + function! IncCommandToggle() + let prev = &inccommand + + if &inccommand ==# 'split' + set inccommand=nosplit + elseif &inccommand ==# 'nosplit' + set inccommand=split + elseif &inccommand ==# '' + set inccommand=nosplit + else + throw 'unknown inccommand' + endif + + return " \<BS>" + endfun + + cnoremap <expr> <C-E> IncCommandToggle() + ]]) + + feed(':%s/foo/bar<C-E><C-E><C-E>') + assert_alive() +end) |