diff options
Diffstat (limited to 'test/functional/autocmd')
-rw-r--r-- | test/functional/autocmd/autocmd_spec.lua | 42 | ||||
-rw-r--r-- | test/functional/autocmd/cmdline_spec.lua | 35 | ||||
-rw-r--r-- | test/functional/autocmd/cursorhold_spec.lua | 74 | ||||
-rw-r--r-- | test/functional/autocmd/dirchanged_spec.lua | 28 | ||||
-rw-r--r-- | test/functional/autocmd/focus_spec.lua | 25 | ||||
-rw-r--r-- | test/functional/autocmd/signal_spec.lua | 7 | ||||
-rw-r--r-- | test/functional/autocmd/termxx_spec.lua | 13 | ||||
-rw-r--r-- | test/functional/autocmd/win_scrolled_resized_spec.lua | 329 | ||||
-rw-r--r-- | test/functional/autocmd/winscrolled_spec.lua | 85 |
9 files changed, 498 insertions, 140 deletions
diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 90254b7415..fb5bab445c 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -9,6 +9,7 @@ local neq = helpers.neq local eval = helpers.eval local feed = helpers.feed local clear = helpers.clear +local matches = helpers.matches local meths = helpers.meths local pcall_err = helpers.pcall_err local funcs = helpers.funcs @@ -424,17 +425,50 @@ describe('autocmd', function() end) it('gives E814 when there are no other floating windows', function() - eq('Vim(close):E814: Cannot close window, only autocmd window would remain', + eq('BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', pcall_err(command, 'doautoall BufAdd')) end) it('gives E814 when there are other floating windows', function() meths.open_win(0, true, {width = 10, height = 10, relative = 'editor', row = 10, col = 10}) - eq('Vim(close):E814: Cannot close window, only autocmd window would remain', + eq('BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', pcall_err(command, 'doautoall BufAdd')) end) end) + it('closing `aucmd_win` using API gives E813', function() + exec_lua([[ + vim.cmd('tabnew') + _G.buf = vim.api.nvim_create_buf(true, true) + ]]) + matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + vim.api.nvim_buf_call(_G.buf, function() + local win = vim.api.nvim_get_current_win() + vim.api.nvim_win_close(win, true) + end) + ]])) + matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + vim.api.nvim_buf_call(_G.buf, function() + local win = vim.api.nvim_get_current_win() + vim.cmd('tabnext') + vim.api.nvim_win_close(win, true) + end) + ]])) + matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + vim.api.nvim_buf_call(_G.buf, function() + local win = vim.api.nvim_get_current_win() + vim.api.nvim_win_hide(win) + end) + ]])) + matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + vim.api.nvim_buf_call(_G.buf, function() + local win = vim.api.nvim_get_current_win() + vim.cmd('tabnext') + vim.api.nvim_win_hide(win) + end) + ]])) + end) + it(':doautocmd does not warn "No matching autocommands" #10689', function() local screen = Screen.new(32, 3) screen:attach() @@ -476,14 +510,14 @@ describe('autocmd', function() it('during RecordingLeave event', function() command([[autocmd RecordingLeave * let v:event.regname = '']]) - eq('Vim(let):E46: Cannot change read-only variable "v:event.regname"', + eq('RecordingLeave Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.regname"', pcall_err(command, 'normal! qqq')) end) it('during TermClose event', function() command('autocmd TermClose * let v:event.status = 0') command('terminal') - eq('Vim(let):E46: Cannot change read-only variable "v:event.status"', + eq('TermClose Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.status"', pcall_err(command, 'bdelete!')) end) end) diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua index 8ec06dc148..82fb9b9444 100644 --- a/test/functional/autocmd/cmdline_spec.lua +++ b/test/functional/autocmd/cmdline_spec.lua @@ -73,7 +73,7 @@ describe('cmdline autocommands', function() {1:~ }| {4: }| : | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} | + {2:CmdlineEnter Autocommands for "*": Vim(echoerr):FAIL} | :^ | ]]) @@ -82,9 +82,9 @@ describe('cmdline autocommands', function() | {4: }| : | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} | + {2:CmdlineEnter Autocommands for "*": Vim(echoerr):FAIL} | :put ='lorem ipsum' | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):very error} | + {2:CmdlineLeave Autocommands for "*": Vim(echoerr):very error} | | {3:Press ENTER or type command to continue}^ | ]]) @@ -111,9 +111,9 @@ describe('cmdline autocommands', function() lorem ipsum | {4: }| : | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} | + {2:CmdlineEnter Autocommands for "*": Vim(echoerr):FAIL} | :put ='lorem ipsum' | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):change erreor} | + {2:CmdlineChanged Autocommands for "*": Vim(echoerr):change erreor} | :put ='lorem ipsum'^ | ]]) @@ -123,9 +123,9 @@ describe('cmdline autocommands', function() lorem ipsum | {4: }| : | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} | + {2:CmdlineEnter Autocommands for "*": Vim(echoerr):FAIL} | :put ='lorem ipsum' | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):change erreor} | + {2:CmdlineChanged Autocommands for "*": Vim(echoerr):change erreor} | :put ='lorem ipsum^' | ]]) @@ -134,22 +134,22 @@ describe('cmdline autocommands', function() screen:expect([[ {4: }| : | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):FAIL} | + {2:CmdlineEnter Autocommands for "*": Vim(echoerr):FAIL} | :put ='lorem ipsum' | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):change erreor} | + {2:CmdlineChanged Autocommands for "*": Vim(echoerr):change erreor} | :put ='lorem ipsum.' | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):change erreor} | + {2:CmdlineChanged Autocommands for "*": Vim(echoerr):change erreor} | :put ='lorem ipsum.^' | ]]) feed('<cr>') screen:expect([[ :put ='lorem ipsum' | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):change erreor} | + {2:CmdlineChanged Autocommands for "*": Vim(echoerr):change erreor} | :put ='lorem ipsum.' | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):change erreor} | + {2:CmdlineChanged Autocommands for "*": Vim(echoerr):change erreor} | :put ='lorem ipsum.' | - {2:E5500: autocmd has thrown an exception: Vim(echoerr):very error} | + {2:CmdlineLeave Autocommands for "*": Vim(echoerr):very error} | | {3:Press ENTER or type command to continue}^ | ]]) @@ -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('<CR>') + 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(':') @@ -215,7 +223,6 @@ describe('cmdline autocommands', function() eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+1"}}, next_msg()) feed('<cr>') 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('<cr>') eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua index 506b688853..b04bd5233a 100644 --- a/test/functional/autocmd/cursorhold_spec.lua +++ b/test/functional/autocmd/cursorhold_spec.lua @@ -2,30 +2,82 @@ 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 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() + 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 + 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('<Ignore>', 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('<Ignore>') 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() -- 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() sleep(1) - eq(1, eval('g:cursorhold')) + eq(1, meths.get_var('cursorhold')) end) end) end) 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 e3c9e1f9ee..d7a87e17ed 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.is_os('win')) then return end describe('autoread TUI FocusGained/FocusLost', function() local f1 = 'xtest-foo' @@ -33,18 +33,37 @@ 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:~ }| + {4:~ }| + {4:~ }| {5:xtest-foo }| :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/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua index d4f65cc61d..738064090a 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 is_os = helpers.is_os +local skip = helpers.skip -if helpers.pending_win32(pending) then - -- Only applies to POSIX systems. - 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 859c2ebf44..0a33f1b2ac 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -5,11 +5,13 @@ 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 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() @@ -22,7 +24,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('^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://', + pcall_err(command, 'bdelete!')) assert_alive() end @@ -45,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)') @@ -53,7 +56,7 @@ describe('autocmd TermClose', function() end) it('kills job trapping SIGTERM', function() - if iswin() then return end + 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', { ]] @@ -73,7 +76,7 @@ describe('autocmd TermClose', function() end) it('kills PTY job trapping SIGHUP and SIGTERM', function() - if iswin() then return end + 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/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua new file mode 100644 index 0000000000..4957f56dd4 --- /dev/null +++ b/test/functional/autocmd/win_scrolled_resized_spec.lua @@ -0,0 +1,329 @@ +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('<C-W>+') + eq(1, eval('g:resized')) + eq({windows = {1002, 1001}}, eval('g:v_event')) + + -- increase window width, three windows will be reported + feed('<C-W>>') + 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('<amatch>')) + au WinScrolled * let g:afile = str2nr(expand('<afile>')) + 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('<C-E>') + eq(1, eval('g:scrolled')) + eq({ + 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('<C-Y>') + eq(2, eval('g:scrolled')) + eq({ + 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) + + 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, 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, 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) + + 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, 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, 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, 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, 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) + + -- 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, 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, 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('$') + 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<C-X><C-E><Esc>') + eq(1, eval('g:scrolled')) + eq({ + 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<C-X><C-Y><Esc>') + eq(2, eval('g:scrolled')) + eq({ + 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') + eq(2, eval('g:scrolled')) + + feed('A<CR><Esc>') + eq(3, eval('g:scrolled')) + eq({ + 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) + +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('<Esc>') + 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('<C-E>') + 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('<C-E>') + 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<C-E>') + 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('<C-E>') + 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<C-Y>') + 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() + + exec([[ + let g:scrolled = 0 + autocmd WinScrolled * let g:scrolled += 1 + autocmd WinScrolled * let g:amatch = expand('<amatch>') + 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, { + height = 5, + width = 10, + col = 0, + row = 1, + relative = 'editor', + style = 'minimal' + }) + local winid_str = tostring(win.id) + -- WinScrolled should not be triggered when creating a new floating window + 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, 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, 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) diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua deleted file mode 100644 index 5c1b758961..0000000000 --- a/test/functional/autocmd/winscrolled_spec.lua +++ /dev/null @@ -1,85 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -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('<amatch>'))]]) - command([[autocmd WinScrolled * let g:afile = str2nr(expand('<afile>'))]]) - 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('<C-E>') - 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 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<CR><Esc>') - eq(1, eval('g:scrolled')) - 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('<C-E>') - assert_alive() -end) |