diff options
Diffstat (limited to 'test/functional/autocmd')
21 files changed, 1182 insertions, 870 deletions
diff --git a/test/functional/autocmd/autocmd_oldtest_spec.lua b/test/functional/autocmd/autocmd_oldtest_spec.lua index dfd746a06e..0243674f2d 100644 --- a/test/functional/autocmd/autocmd_oldtest_spec.lua +++ b/test/functional/autocmd/autocmd_oldtest_spec.lua @@ -3,8 +3,8 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local eq = helpers.eq -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local exec = helpers.exec local feed = helpers.feed @@ -12,7 +12,7 @@ describe('oldtests', function() before_each(clear) local exec_lines = function(str) - return funcs.split(funcs.execute(str), "\n") + return fn.split(fn.execute(str), '\n') end local add_an_autocmd = function() @@ -23,7 +23,7 @@ describe('oldtests', function() ]] eq(3, #exec_lines('au vimBarTest')) - eq(1, #meths.get_autocmds({ group = 'vimBarTest' })) + eq(1, #api.nvim_get_autocmds({ group = 'vimBarTest' })) end it('should recognize a bar before the {event}', function() @@ -31,14 +31,13 @@ describe('oldtests', function() add_an_autocmd() exec [[ augroup vimBarTest | au! | augroup END ]] eq(1, #exec_lines('au vimBarTest')) - eq({}, meths.get_autocmds({ group = 'vimBarTest' })) + eq({}, api.nvim_get_autocmds({ group = 'vimBarTest' })) -- Sad spacing add_an_autocmd() exec [[ augroup vimBarTest| au!| augroup END ]] eq(1, #exec_lines('au vimBarTest')) - -- test that a bar is recognized after the {event} add_an_autocmd() exec [[ augroup vimBarTest| au!BufReadCmd| augroup END ]] @@ -50,8 +49,8 @@ describe('oldtests', function() end) it('should fire on unload buf', function() - funcs.writefile({'Test file Xxx1'}, 'Xxx1') - funcs.writefile({'Test file Xxx2'}, 'Xxx2') + fn.writefile({ 'Test file Xxx1' }, 'Xxx1') + fn.writefile({ 'Test file Xxx2' }, 'Xxx2') local fname = 'Xtest_functional_autocmd_unload' local content = [[ @@ -72,16 +71,16 @@ describe('oldtests', function() q ]] - funcs.writefile(funcs.split(content, "\n"), fname) + fn.writefile(fn.split(content, '\n'), fname) - funcs.delete('Xout') - funcs.system(string.format('%s -u NORC -i NONE -N -S %s', meths.get_vvar('progpath'), fname)) - eq(1, funcs.filereadable('Xout')) + fn.delete('Xout') + fn.system(string.format('%s --clean -N -S %s', api.nvim_get_vvar('progpath'), fname)) + eq(1, fn.filereadable('Xout')) - funcs.delete('Xxx1') - funcs.delete('Xxx2') - funcs.delete(fname) - funcs.delete('Xout') + fn.delete('Xxx1') + fn.delete('Xxx2') + fn.delete(fname) + fn.delete('Xout') end) -- oldtest: Test_delete_ml_get_errors() @@ -89,7 +88,7 @@ describe('oldtests', function() local screen = Screen.new(75, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {background = Screen.colors.Cyan}; + [1] = { background = Screen.colors.Cyan }, }) exec([[ set noshowcmd noruler scrolloff=0 @@ -97,7 +96,8 @@ describe('oldtests', function() edit test/old/testdir/samples/box.txt ]]) feed('249GV<C-End>d') - screen:expect{grid=[[ + screen:expect { + grid = [[ const auto themeEmoji = _forPeer->themeEmoji(); | if (themeEmoji.isEmpty()) { | return nonCustom; | @@ -108,9 +108,11 @@ describe('oldtests', function() return nonCustom; | {1:^}} | 353 fewer lines | - ]]} + ]], + } feed('<PageUp>') - screen:expect{grid=[[ + screen:expect { + grid = [[ | auto BackgroundBox::Inner::resolveResetCustomPaper() const | -> std::optional<Data::WallPaper> { | @@ -121,6 +123,7 @@ describe('oldtests', function() const auto themeEmoji = _forPeer->themeEmoji(); | ^if (themeEmoji.isEmpty()) { | 353 fewer lines | - ]]} + ]], + } end) end) diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 63a487c8bc..5fffb70095 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -10,14 +10,13 @@ local eval = helpers.eval local feed = helpers.feed local clear = helpers.clear local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local pcall_err = helpers.pcall_err -local funcs = helpers.funcs +local fn = helpers.fn local expect = helpers.expect local command = helpers.command local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua -local curbufmeths = helpers.curbufmeths local retry = helpers.retry local source = helpers.source @@ -26,23 +25,23 @@ describe('autocmd', function() it(':tabnew, :split, :close events order, <afile>', function() local expected = { - {'WinLeave', ''}, - {'TabLeave', ''}, - {'WinEnter', ''}, - {'TabNew', 'testfile1'}, -- :tabnew - {'TabEnter', ''}, - {'BufLeave', ''}, - {'BufEnter', 'testfile1'}, -- :split - {'WinLeave', 'testfile1'}, - {'WinEnter', 'testfile1'}, - {'WinLeave', 'testfile1'}, - {'WinClosed', '1002'}, -- :close, WinClosed <afile> = window-id - {'WinEnter', 'testfile1'}, - {'WinLeave', 'testfile1'}, -- :bdelete - {'WinEnter', 'testfile1'}, - {'BufLeave', 'testfile1'}, - {'BufEnter', 'testfile2'}, - {'WinClosed', '1000'}, + { 'WinLeave', '' }, + { 'TabLeave', '' }, + { 'WinEnter', '' }, + { 'TabNew', 'testfile1' }, -- :tabnew + { 'TabEnter', '' }, + { 'BufLeave', '' }, + { 'BufEnter', 'testfile1' }, -- :split + { 'WinLeave', 'testfile1' }, + { 'WinEnter', 'testfile1' }, + { 'WinLeave', 'testfile1' }, + { 'WinClosed', '1002' }, -- :close, WinClosed <afile> = window-id + { 'WinEnter', 'testfile1' }, + { 'WinLeave', 'testfile1' }, -- :bdelete + { 'WinEnter', 'testfile1' }, + { 'BufLeave', 'testfile1' }, + { 'BufEnter', 'testfile2' }, + { 'WinClosed', '1000' }, } command('let g:evs = []') command('autocmd BufEnter * :call add(g:evs, ["BufEnter", expand("<afile>")])') @@ -63,10 +62,10 @@ describe('autocmd', function() it('first edit causes BufUnload on NoName', function() local expected = { - {'BufUnload', ''}, - {'BufDelete', ''}, - {'BufWipeout', ''}, - {'BufEnter', 'testfile1'}, + { 'BufUnload', '' }, + { 'BufDelete', '' }, + { 'BufWipeout', '' }, + { 'BufEnter', 'testfile1' }, } command('let g:evs = []') command('autocmd BufEnter * :call add(g:evs, ["BufEnter", expand("<afile>")])') @@ -106,20 +105,23 @@ describe('autocmd', function() local buf1 = eval("bufnr('%')") command('new') local buf2 = eval("bufnr('%')") - command('autocmd WinClosed <buffer> :call add(g:evs, ["WinClosed", expand("<abuf>")])' - -- Attempt recursion. - ..' | bdelete '..buf2) + command( + 'autocmd WinClosed <buffer> :call add(g:evs, ["WinClosed", expand("<abuf>")])' + -- Attempt recursion. + .. ' | bdelete ' + .. buf2 + ) command('tabedit testfile2') command('tabedit testfile3') - command('bdelete '..buf2) + command('bdelete ' .. buf2) -- Non-recursive: only triggered once. eq({ - {'WinClosed', '2'}, + { 'WinClosed', '2' }, }, eval('g:evs')) - command('bdelete '..buf1) + command('bdelete ' .. buf1) eq({ - {'WinClosed', '2'}, - {'WinClosed', '1'}, + { 'WinClosed', '2' }, + { 'WinClosed', '1' }, }, eval('g:evs')) end) @@ -130,7 +132,7 @@ describe('autocmd', function() command('new') command('close') eq({ - {'WinClosed', '1001'}, + { 'WinClosed', '1001' }, }, eval('g:evs')) end) @@ -139,16 +141,15 @@ describe('autocmd', function() end) describe('BufLeave autocommand', function() - it('can wipe out the buffer created by :edit which triggered autocmd', - function() - meths.set_option_value('hidden', true, {}) - curbufmeths.set_lines(0, 1, false, { + it('can wipe out the buffer created by :edit which triggered autocmd', function() + api.nvim_set_option_value('hidden', true, {}) + api.nvim_buf_set_lines(0, 0, 1, false, { 'start of test file xx', - 'end of test file xx'}) + 'end of test file xx', + }) command('autocmd BufLeave * bwipeout yy') - eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy', - exc_exec('edit yy')) + eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy', exc_exec('edit yy')) expect([[ start of test file xx @@ -156,7 +157,7 @@ describe('autocmd', function() end) end) - it('++once', function() -- :help autocmd-once + it('++once', function() -- :help autocmd-once -- -- ":autocmd ... ++once" executes its handler once, then removes the handler. -- @@ -177,7 +178,8 @@ describe('autocmd', function() command('autocmd TabNew * ++once :call add(g:foo, "Once2")') command('autocmd TabNew * :call add(g:foo, "Many2")') command('autocmd TabNew * ++once :call add(g:foo, "Once3")') - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- TabNew @@ -186,18 +188,21 @@ describe('autocmd', function() :call add(g:foo, "Once2") :call add(g:foo, "Many2") :call add(g:foo, "Once3")]]), - funcs.execute('autocmd Tabnew')) + fn.execute('autocmd Tabnew') + ) command('tabnew') command('tabnew') command('tabnew') eq(expected, eval('g:foo')) - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- TabNew * :call add(g:foo, "Many1") :call add(g:foo, "Many2")]]), - funcs.execute('autocmd Tabnew')) + fn.execute('autocmd Tabnew') + ) -- -- ":autocmd ... ++once" handlers can be deleted. @@ -218,7 +223,9 @@ describe('autocmd', function() } command('let g:foo = []') command('autocmd OptionSet binary ++nested ++once :call add(g:foo, "OptionSet-Once")') - command('autocmd CursorMoved <buffer> ++once ++nested setlocal binary|:call add(g:foo, "CursorMoved-Once")') + command( + 'autocmd CursorMoved <buffer> ++once ++nested setlocal binary|:call add(g:foo, "CursorMoved-Once")' + ) command("put ='foo bar baz'") feed('0llhlh') eq(expected, eval('g:foo')) @@ -231,15 +238,17 @@ describe('autocmd', function() 'Once2', } command('let g:foo = []') - command('autocmd! TabNew') -- Clear all TabNew handlers. + command('autocmd! TabNew') -- Clear all TabNew handlers. command('autocmd TabNew * ++once :call add(g:foo, "Once1")') command('autocmd TabNew * ++once :call add(g:foo, "Once2")') command('tabnew') eq(expected, eval('g:foo')) - eq(dedent([[ + eq( + dedent([[ --- Autocommands ---]]), - funcs.execute('autocmd Tabnew')) + fn.execute('autocmd Tabnew') + ) end) it('internal `aucmd_win` window', function() @@ -250,9 +259,13 @@ describe('autocmd', function() local screen = Screen.new(50, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {background = Screen.colors.LightMagenta}, - [3] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { background = Screen.colors.LightMagenta }, + [3] = { + background = Screen.colors.LightMagenta, + bold = true, + foreground = Screen.colors.Blue1, + }, }) source([[ @@ -272,96 +285,67 @@ describe('autocmd', function() ]]) screen:expect([[ ^bb | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*8 | ]]) - feed(":enew | doautoall User<cr>") + feed(':enew | doautoall User<cr>') screen:expect([[ {2:bb }| - {3:~ }| - {3:~ }| - {3:~ }| - {3:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {3:~ }|*4 + {1:~ }|*4 ^:enew | doautoall User | ]]) feed('<cr>') screen:expect([[ ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*8 13 | ]]) eq(7, eval('g:test')) -- API calls are blocked when aucmd_win is not in scope - eq('Vim(call):E5555: API call: Invalid window id: 1001', - pcall_err(command, "call nvim_set_current_win(g:winid)")) + eq( + 'Vim(call):E5555: API call: Invalid window id: 1001', + pcall_err(command, 'call nvim_set_current_win(g:winid)') + ) -- second time aucmd_win is needed, a different code path is invoked -- to reuse the same window, so check again - command("let g:test = v:null") - command("let g:had_value = v:null") - feed(":doautoall User<cr>") + command('let g:test = v:null') + command('let g:had_value = v:null') + feed(':doautoall User<cr>') screen:expect([[ {2:bb }| - {3:~ }| - {3:~ }| - {3:~ }| - {3:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {3:~ }|*4 + {1:~ }|*4 ^:doautoall User | ]]) feed('<cr>') screen:expect([[ ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*8 13 | ]]) -- win vars in aucmd_win should have been reset eq(0, eval('g:had_value')) eq(7, eval('g:test')) - eq('Vim(call):E5555: API call: Invalid window id: 1001', - pcall_err(command, "call nvim_set_current_win(g:winid)")) + eq( + 'Vim(call):E5555: API call: Invalid window id: 1001', + pcall_err(command, 'call nvim_set_current_win(g:winid)') + ) end) - it("`aucmd_win` cannot be changed into a normal window #13699", function() + it('`aucmd_win` cannot be changed into a normal window #13699', function() local screen = Screen.new(50, 10) screen:attach() screen:set_default_attr_ids { - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {reverse = true}, - [3] = {bold = true, reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { reverse = true }, + [3] = { bold = true, reverse = true }, } -- Create specific layout and ensure it's left unchanged. @@ -373,11 +357,7 @@ describe('autocmd', function() ]] screen:expect [[ ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {3:[No Name] }| | {2:[No Name] }| @@ -408,13 +388,16 @@ describe('autocmd', function() -- After all of our messing around, aucmd_win should still be floating. -- Use :only to ensure _G.buf is hidden again (so the aucmd_win is used). - eq("editor", exec_lua [[ + eq( + 'editor', + exec_lua [[ vim.cmd "only" vim.api.nvim_buf_call(_G.buf, function() _G.config = vim.api.nvim_win_get_config(0) end) return _G.config.relative - ]]) + ]] + ) end) describe('closing last non-floating window in tab from `aucmd_win`', function() @@ -425,14 +408,22 @@ describe('autocmd', function() end) it('gives E814 when there are no other floating windows', function() - eq('BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', - pcall_err(command, 'doautoall BufAdd')) + 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('BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', - pcall_err(command, 'doautoall BufAdd')) + api.nvim_open_win( + 0, + true, + { width = 10, height = 10, relative = 'editor', row = 10, col = 10 } + ) + eq( + 'BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', + pcall_err(command, 'doautoall BufAdd') + ) end) end) @@ -441,84 +432,116 @@ describe('autocmd', function() vim.cmd('tabnew') _G.buf = vim.api.nvim_create_buf(true, true) ]]) - matches('Vim:E813: Cannot close autocmd window$', pcall_err(exec_lua, [[ + 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, [[ + ]] + ) + ) + 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, [[ + ]] + ) + ) + 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, [[ + ]] + ) + ) + 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() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, }) feed(':doautocmd User Foo<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }| :doautocmd User Foo | - ]]} + ]], + } feed(':autocmd! SessionLoadPost<cr>') feed(':doautocmd SessionLoadPost<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }| :doautocmd SessionLoadPost | - ]]} + ]], + } end) describe('v:event is readonly #18063', function() it('during ChanOpen event', function() command('autocmd ChanOpen * let v:event.info.id = 0') - funcs.jobstart({'cat'}) + fn.jobstart({ 'cat' }) retry(nil, nil, function() - eq('E46: Cannot change read-only variable "v:event.info"', meths.get_vvar('errmsg')) + eq('E46: Cannot change read-only variable "v:event.info"', api.nvim_get_vvar('errmsg')) end) end) it('during ChanOpen event', function() command('autocmd ChanInfo * let v:event.info.id = 0') - meths.set_client_info('foo', {}, 'remote', {}, {}) + api.nvim_set_client_info('foo', {}, 'remote', {}, {}) retry(nil, nil, function() - eq('E46: Cannot change read-only variable "v:event.info"', meths.get_vvar('errmsg')) + eq('E46: Cannot change read-only variable "v:event.info"', api.nvim_get_vvar('errmsg')) end) end) it('during RecordingLeave event', function() command([[autocmd RecordingLeave * let v:event.regname = '']]) - eq('RecordingLeave Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.regname"', - pcall_err(command, 'normal! qqq')) + 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('TermClose Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.status"', - pcall_err(command, 'bdelete!')) + eq( + 'TermClose Autocommands for "*": Vim(let):E46: Cannot change read-only variable "v:event.status"', + pcall_err(command, 'bdelete!') + ) end) end) @@ -554,7 +577,7 @@ describe('autocmd', function() call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') ]] - meths.set_var('did_split', 0) + api.nvim_set_var('did_split', 0) source [[ augroup Testing @@ -566,11 +589,11 @@ describe('autocmd', function() split ]] - eq(2, meths.get_var('did_split')) - eq(1, funcs.exists('#WinNew')) + eq(2, api.nvim_get_var('did_split')) + eq(1, fn.exists('#WinNew')) -- Now with once - meths.set_var('did_split', 0) + api.nvim_set_var('did_split', 0) source [[ augroup Testing @@ -582,13 +605,16 @@ describe('autocmd', function() split ]] - eq(1, meths.get_var('did_split')) - eq(0, funcs.exists('#WinNew')) + eq(1, api.nvim_get_var('did_split')) + eq(0, fn.exists('#WinNew')) -- call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') - local ok, msg = pcall(source, [[ + local ok, msg = pcall( + source, + [[ au WinNew * ++once ++once echo bad - ]]) + ]] + ) eq(false, ok) eq(true, not not string.find(msg, 'E983:')) @@ -596,7 +622,7 @@ describe('autocmd', function() it('should have autocmds in filetypedetect group', function() source [[filetype on]] - neq({}, meths.get_autocmds { group = "filetypedetect" }) + neq({}, api.nvim_get_autocmds { group = 'filetypedetect' }) end) it('should allow comma-separated patterns', function() @@ -608,7 +634,7 @@ describe('autocmd', function() augroup END ]] - eq(4, #meths.get_autocmds { event = "BufReadCmd", group = "TestingPatterns" }) + eq(4, #api.nvim_get_autocmds { event = 'BufReadCmd', group = 'TestingPatterns' }) end) end) @@ -627,7 +653,7 @@ describe('autocmd', function() }) vim.cmd "tabnew" ]] - eq(1, eval('g:count')) -- Added autocommands should not be executed + eq(1, eval('g:count')) -- Added autocommands should not be executed end) it('no crash when clearing a group inside a callback #23355', function() diff --git a/test/functional/autocmd/bufenter_spec.lua b/test/functional/autocmd/bufenter_spec.lua index 47f4adb0d6..af0dd887fa 100644 --- a/test/functional/autocmd/bufenter_spec.lua +++ b/test/functional/autocmd/bufenter_spec.lua @@ -12,9 +12,9 @@ describe('autocmd BufEnter', function() it("triggered by nvim_command('edit <dir>')", function() command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif") - request("nvim_command", "split .") - eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. - eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. + request('nvim_command', 'split .') + eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. + eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. end) it('triggered by "try|:split <dir>|endtry" in a function', function() @@ -27,21 +27,20 @@ describe('autocmd BufEnter', function() endtry endfunction ]]) - command("call Test()") - eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. - eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. + command('call Test()') + eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. + eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. end) it('triggered by ":split normal|:help|:bw"', function() helpers.add_builddir_to_rtp() - command("split normal") - command("wincmd j") - command("help") - command("wincmd L") - command("autocmd BufEnter normal let g:bufentered = 1") - command("bw") + command('split normal') + command('wincmd j') + command('help') + command('wincmd L') + command('autocmd BufEnter normal let g:bufentered = 1') + command('bw') eq(1, eval('bufnr("%")')) -- The cursor is back to the bottom window eq(0, eval("exists('g:bufentered')")) -- The autocmd hasn't been triggered end) - end) diff --git a/test/functional/autocmd/bufmodifiedset_spec.lua b/test/functional/autocmd/bufmodifiedset_spec.lua index c566361e37..27fe9fcc94 100644 --- a/test/functional/autocmd/bufmodifiedset_spec.lua +++ b/test/functional/autocmd/bufmodifiedset_spec.lua @@ -14,9 +14,9 @@ describe('BufModified', function() let g:modified = 0 autocmd BufModifiedSet * let g:modified += 1 ]]) - request("nvim_command", [[normal! aa\<Esc>]]) + request('nvim_command', [[normal! aa\<Esc>]]) eq(1, eval('g:modified')) - request("nvim_command", [[normal! u]]) + request('nvim_command', [[normal! u]]) eq(2, eval('g:modified')) end) end) diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua index 82fb9b9444..7428456656 100644 --- a/test/functional/autocmd/cmdline_spec.lua +++ b/test/functional/autocmd/cmdline_spec.lua @@ -8,14 +8,14 @@ local expect = helpers.expect local eval = helpers.eval local next_msg = helpers.next_msg local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api describe('cmdline autocommands', function() local channel before_each(function() clear() - channel = meths.get_api_info()[1] - meths.set_var("channel",channel) + channel = api.nvim_get_chan_info(0).id + api.nvim_set_var('channel', channel) command("autocmd CmdlineEnter * call rpcnotify(g:channel, 'CmdlineEnter', v:event)") command("autocmd CmdlineLeave * call rpcnotify(g:channel, 'CmdlineLeave', v:event)") command("autocmd CmdWinEnter * call rpcnotify(g:channel, 'CmdWinEnter', v:event)") @@ -24,23 +24,27 @@ describe('cmdline autocommands', function() it('works', function() feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) feed('redraw<cr>') - eq({'notification', 'CmdlineLeave', - {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 1, abort = false } } }, + next_msg() + ) feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) -- note: feed('bork<c-c>') might not consume 'bork' -- due to out-of-band interrupt handling feed('bork<esc>') - eq({'notification', 'CmdlineLeave', - {{cmdtype=':', cmdlevel=1, abort=true}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 1, abort = true } } }, + next_msg() + ) end) it('can abort cmdline', function() - command("autocmd CmdlineLeave * let v:event.abort= len(getcmdline())>15") + command('autocmd CmdlineLeave * let v:event.abort= len(getcmdline())>15') feed(":put! ='ok'<cr>") expect([[ ok @@ -57,10 +61,10 @@ describe('cmdline autocommands', function() local screen = Screen.new(72, 8) screen:attach() 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}, - [4] = {bold = true, reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [4] = { bold = true, reverse = true }, }) command("autocmd CmdlineEnter * echoerr 'FAIL'") command("autocmd CmdlineLeave * echoerr 'very error'") @@ -68,9 +72,7 @@ describe('cmdline autocommands', function() feed(':') screen:expect([[ | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 {4: }| : | {2:CmdlineEnter Autocommands for "*": Vim(echoerr):FAIL} | @@ -94,18 +96,14 @@ describe('cmdline autocommands', function() screen:expect([[ | ^lorem ipsum | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 | ]]) command("autocmd CmdlineChanged * echoerr 'change erreor'") -- history recall still works - feed(":<c-p>") + feed(':<c-p>') screen:expect([[ | lorem ipsum | @@ -117,7 +115,7 @@ describe('cmdline autocommands', function() :put ='lorem ipsum'^ | ]]) - feed("<left>") + feed('<left>') screen:expect([[ | lorem ipsum | @@ -130,7 +128,7 @@ describe('cmdline autocommands', function() ]]) -- edit still works - feed(".") + feed('.') screen:expect([[ {4: }| : | @@ -160,72 +158,104 @@ describe('cmdline autocommands', function() | lorem ipsum | ^lorem ipsum. | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*4 | ]]) end) it('works with nested cmdline', function() feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) feed('<c-r>=') - eq({'notification', 'CmdlineEnter', {{cmdtype='=', cmdlevel=2}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = '=', cmdlevel = 2 } } }, next_msg()) feed('<c-f>') - eq({'notification', 'CmdWinEnter', {{}}}, next_msg()) + eq({ 'notification', 'CmdWinEnter', { {} } }, next_msg()) feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=3}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 3 } } }, next_msg()) feed('<c-c>') - eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=3, abort=true}}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 3, abort = true } } }, + next_msg() + ) feed('<c-c>') - eq({'notification', 'CmdWinLeave', {{}}}, next_msg()) + eq({ 'notification', 'CmdWinLeave', { {} } }, next_msg()) feed('1+2<cr>') - eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg()) + 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()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) feed('<CR>') - eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) + 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())") + it('supports CmdlineChanged', function() + command( + "autocmd CmdlineChanged * call rpcnotify(g:channel, 'CmdlineChanged', v:event, getcmdline())" + ) feed(':') - eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = ':', cmdlevel = 1 } } }, next_msg()) feed('l') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "l"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'l' } }, next_msg()) feed('e') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "le"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'le' } }, next_msg()) feed('t') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let' } }, next_msg()) feed('<space>') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let "}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let ' } }, + next_msg() + ) feed('x') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x"}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x' } }, + next_msg() + ) feed('<space>') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x "}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x ' } }, + next_msg() + ) feed('=') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x ="}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x =' } }, + next_msg() + ) feed('<space>') - eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x = "}}, next_msg()) + eq( + { 'notification', 'CmdlineChanged', { { cmdtype = ':', cmdlevel = 1 }, 'let x = ' } }, + next_msg() + ) feed('<c-r>=') - eq({'notification', 'CmdlineEnter', {{cmdtype='=', cmdlevel=2}}}, next_msg()) + eq({ 'notification', 'CmdlineEnter', { { cmdtype = '=', cmdlevel = 2 } } }, next_msg()) feed('1') - eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = '=', cmdlevel = 2 }, '1' } }, next_msg()) feed('+') - eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+"}}, next_msg()) + eq({ 'notification', 'CmdlineChanged', { { cmdtype = '=', cmdlevel = 2 }, '1+' } }, next_msg()) feed('1') - eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+1"}}, next_msg()) + 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 = 2"}}, next_msg()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = '=', cmdlevel = 2, abort = false } } }, + 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()) + eq( + { 'notification', 'CmdlineLeave', { { cmdtype = ':', cmdlevel = 1, abort = false } } }, + next_msg() + ) eq(2, eval('x')) end) end) diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua index e6bcb19682..fc2b65f53a 100644 --- a/test/functional/autocmd/cursorhold_spec.lua +++ b/test/functional/autocmd/cursorhold_spec.lua @@ -5,8 +5,8 @@ local eq = helpers.eq local feed = helpers.feed local retry = helpers.retry local exec = helpers.source -local sleep = helpers.sleep -local meths = helpers.meths +local sleep = vim.uv.sleep +local api = helpers.api before_each(clear) @@ -26,39 +26,47 @@ describe('CursorHold', function() -- if testing with small 'updatetime' fails, double its value and test again retry(10, nil, function() ut = ut * 2 - meths.set_option_value('updatetime', ut, {}) - feed('0') -- reset did_cursorhold - meths.set_var('cursorhold', 0) + api.nvim_set_option_value('updatetime', ut, {}) + feed('0') -- reset did_cursorhold + api.nvim_set_var('cursorhold', 0) sleep(ut / 4) fn() - eq(0, meths.get_var('cursorhold')) + eq(0, api.nvim_get_var('cursorhold')) sleep(ut / 2) fn() - eq(0, meths.get_var('cursorhold')) + eq(0, api.nvim_get_var('cursorhold')) sleep(ut / 2) - eq(early, meths.get_var('cursorhold')) + eq(early, api.nvim_get_var('cursorhold')) sleep(ut / 4 * 3) - eq(1, meths.get_var('cursorhold')) + eq(1, api.nvim_get_var('cursorhold')) end) end - local ignore_key = meths.replace_termcodes('<Ignore>', true, true, true) + local ignore_key = api.nvim_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) + test_cursorhold(function() + feed('') + end, 1) + test_cursorhold(function() + api.nvim_feedkeys('', 'n', true) + end, 1) + test_cursorhold(function() + feed('<Ignore>') + end, 0) + test_cursorhold(function() + api.nvim_feedkeys(ignore_key, 'n', true) + end, 0) end) it("reducing 'updatetime' while waiting for CursorHold #20241", function() - meths.set_option_value('updatetime', 10000, {}) - feed('0') -- reset did_cursorhold - meths.set_var('cursorhold', 0) + api.nvim_set_option_value('updatetime', 10000, {}) + feed('0') -- reset did_cursorhold + api.nvim_set_var('cursorhold', 0) sleep(50) - eq(0, meths.get_var('cursorhold')) - meths.set_option_value('updatetime', 20, {}) + eq(0, api.nvim_get_var('cursorhold')) + api.nvim_set_option_value('updatetime', 20, {}) sleep(10) - eq(1, meths.get_var('cursorhold')) + eq(1, api.nvim_get_var('cursorhold')) end) end) @@ -77,7 +85,7 @@ describe('CursorHoldI', function() feed('ifoo') retry(5, nil, function() sleep(1) - eq(1, meths.get_var('cursorhold')) + eq(1, api.nvim_get_var('cursorhold')) end) end) end) diff --git a/test/functional/autocmd/cursormoved_spec.lua b/test/functional/autocmd/cursormoved_spec.lua index 854e14b088..302afe87b8 100644 --- a/test/functional/autocmd/cursormoved_spec.lua +++ b/test/functional/autocmd/cursormoved_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval -local meths = helpers.meths +local api = helpers.api local source = helpers.source local command = helpers.command @@ -19,9 +19,9 @@ describe('CursorMoved', function() ]]) eq({}, eval('g:log')) command('new') - eq({'BufEnter2', 'CursorMoved2'}, eval('g:log')) + eq({ 'BufEnter2', 'CursorMoved2' }, eval('g:log')) command('wincmd w') - eq({'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1'}, eval('g:log')) + eq({ 'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1' }, eval('g:log')) end) it('is not triggered by temporarily switching window', function() @@ -41,13 +41,13 @@ describe('CursorMoved', function() vsplit foo autocmd CursorMoved * let g:cursormoved += 1 ]]) - meths.buf_set_lines(eval('g:buf'), 0, -1, true, {'aaa'}) + api.nvim_buf_set_lines(eval('g:buf'), 0, -1, true, { 'aaa' }) eq(0, eval('g:cursormoved')) - eq({'aaa'}, meths.buf_get_lines(eval('g:buf'), 0, -1, true)) + eq({ 'aaa' }, api.nvim_buf_get_lines(eval('g:buf'), 0, -1, true)) eq(0, eval('g:cursormoved')) end) - it("is not triggered by cursor movement prior to first CursorMoved instantiation", function() + it('is not triggered by cursor movement prior to first CursorMoved instantiation', function() source([[ let g:cursormoved = 0 autocmd! CursorMoved diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 20aa07d058..7ad529891f 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -1,4 +1,3 @@ -local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear @@ -9,7 +8,7 @@ local request = helpers.request local is_os = helpers.is_os describe('autocmd DirChanged and DirChangedPre', function() - local curdir = string.gsub(luv.cwd(), '\\', '/') + local curdir = vim.uv.cwd():gsub('\\', '/') local dirs = { curdir .. '/Xtest-functional-autocmd-dirchanged.dir1', curdir .. '/Xtest-functional-autocmd-dirchanged.dir2', @@ -21,41 +20,55 @@ describe('autocmd DirChanged and DirChangedPre', function() curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR3', } - 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) + 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() - command('autocmd DirChangedPre * let [g:evpre, g:amatchpre, g:cdprecount] ' - ..'= [copy(v:event), expand("<amatch>"), 1 + get(g:, "cdprecount", 0)]') - command('autocmd DirChanged * let [g:getcwd, g:ev, g:amatch, g:cdcount] ' - ..'= [getcwd(), copy(v:event), expand("<amatch>"), 1 + get(g:, "cdcount", 0)]') + command( + 'autocmd DirChangedPre * let [g:evpre, g:amatchpre, g:cdprecount] ' + .. '= [copy(v:event), expand("<amatch>"), 1 + get(g:, "cdprecount", 0)]' + ) + command( + 'autocmd DirChanged * let [g:getcwd, g:ev, g:amatch, g:cdcount] ' + .. '= [getcwd(), copy(v:event), expand("<amatch>"), 1 + get(g:, "cdcount", 0)]' + ) -- Normalize path separators. - command([[autocmd DirChangedPre * let g:evpre['directory'] = substitute(g:evpre['directory'], '\\', '/', 'g')]]) + command( + [[autocmd DirChangedPre * let g:evpre['directory'] = substitute(g:evpre['directory'], '\\', '/', 'g')]] + ) command([[autocmd DirChanged * let g:ev['cwd'] = substitute(g:ev['cwd'], '\\', '/', 'g')]]) command([[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]]) end) it('set v:event and <amatch>', function() - command('lcd '..dirs[1]) - eq({directory=dirs[1], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('lcd ' .. dirs[1]) + eq({ directory = dirs[1], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq('window', eval('g:amatchpre')) eq('window', eval('g:amatch')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) - command('tcd '..dirs[2]) - eq({directory=dirs[2], scope='tabpage', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev')) + command('tcd ' .. dirs[2]) + eq({ directory = dirs[2], scope = 'tabpage', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'tabpage', changed_window = false }, eval('g:ev')) eq('tabpage', eval('g:amatchpre')) eq('tabpage', eval('g:amatch')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) - command('cd '..dirs[3]) - eq({directory=dirs[3], scope='global', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev')) + command('cd ' .. dirs[3]) + eq({ directory = dirs[3], scope = 'global', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[3], scope = 'global', changed_window = false }, eval('g:ev')) eq('global', eval('g:amatchpre')) eq('global', eval('g:amatch')) eq(3, eval('g:cdprecount')) @@ -63,22 +76,22 @@ describe('autocmd DirChanged and DirChangedPre', function() end) it('DirChanged set getcwd() during event #6260', function() - command('lcd '..dirs[1]) + command('lcd ' .. dirs[1]) eq(dirs[1], eval('g:getcwd')) - command('tcd '..dirs[2]) + command('tcd ' .. dirs[2]) eq(dirs[2], eval('g:getcwd')) - command('cd '..dirs[3]) + command('cd ' .. dirs[3]) eq(dirs[3], eval('g:getcwd')) end) it('disallow recursion', function() command('set shellslash') -- Set up a _nested_ handler. - command('autocmd DirChanged * nested lcd '..dirs[3]) - command('lcd '..dirs[1]) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('autocmd DirChanged * nested lcd ' .. dirs[3]) + command('lcd ' .. dirs[1]) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq(1, eval('g:cdcount')) -- autocmd changed to dirs[3], but did NOT trigger another DirChanged. eq(dirs[3], eval('getcwd()')) @@ -89,27 +102,36 @@ describe('autocmd DirChanged and DirChangedPre', function() command('let g:cdcount = 0') local status1, err1 = pcall(function() - command('lcd '..dirs[1]..'/doesnotexist') + command('lcd ' .. dirs[1] .. '/doesnotexist') end) - eq({directory=dirs[1]..'/doesnotexist', scope='window', changed_window=false}, eval('g:evpre')) + eq( + { directory = dirs[1] .. '/doesnotexist', scope = 'window', changed_window = false }, + eval('g:evpre') + ) eq({}, eval('g:ev')) eq('window', eval('g:amatchpre')) eq(1, eval('g:cdprecount')) eq(0, eval('g:cdcount')) local status2, err2 = pcall(function() - command('lcd '..dirs[2]..'/doesnotexist') + command('lcd ' .. dirs[2] .. '/doesnotexist') end) - eq({directory=dirs[2]..'/doesnotexist', scope='window', changed_window=false}, eval('g:evpre')) + eq( + { directory = dirs[2] .. '/doesnotexist', scope = 'window', changed_window = false }, + eval('g:evpre') + ) eq({}, eval('g:ev')) eq('window', eval('g:amatchpre')) eq(2, eval('g:cdprecount')) eq(0, eval('g:cdcount')) local status3, err3 = pcall(function() - command('lcd '..dirs[3]..'/doesnotexist') + command('lcd ' .. dirs[3] .. '/doesnotexist') end) - eq({directory=dirs[3]..'/doesnotexist', scope='window', changed_window=false}, eval('g:evpre')) + eq( + { directory = dirs[3] .. '/doesnotexist', scope = 'window', changed_window = false }, + eval('g:evpre') + ) eq({}, eval('g:ev')) eq('window', eval('g:amatchpre')) eq(3, eval('g:cdprecount')) @@ -119,93 +141,93 @@ describe('autocmd DirChanged and DirChangedPre', function() eq(false, status2) eq(false, status3) - eq('E344:', string.match(err1, "E%d*:")) - eq('E344:', string.match(err2, "E%d*:")) - eq('E344:', string.match(err3, "E%d*:")) + eq('E344:', string.match(err1, 'E%d*:')) + eq('E344:', string.match(err2, 'E%d*:')) + eq('E344:', string.match(err3, 'E%d*:')) end) it("are triggered by 'autochdir'", function() command('set autochdir') - command('split '..dirs[1]..'/foo') - eq({directory=dirs[1], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('split ' .. dirs[1] .. '/foo') + eq({ directory = dirs[1], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq('auto', eval('g:amatchpre')) eq('auto', eval('g:amatch')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) - command('split '..dirs[2]..'/bar') - eq({directory=dirs[2], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[2], scope='window', changed_window=false}, eval('g:ev')) + command('split ' .. dirs[2] .. '/bar') + eq({ directory = dirs[2], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'window', changed_window = false }, eval('g:ev')) eq('auto', eval('g:amatch')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) end) it('do not trigger if directory has not changed', function() - command('lcd '..dirs[1]) - eq({directory=dirs[1], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('lcd ' .. dirs[1]) + eq({ directory = dirs[1], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq('window', eval('g:amatchpre')) eq('window', eval('g:amatch')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) command('let g:evpre = {}') command('let g:ev = {}') - command('lcd '..dirs[1]) + command('lcd ' .. dirs[1]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) if is_os('win') then - command('lcd '..win_dirs[1]) + command('lcd ' .. win_dirs[1]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) end - command('tcd '..dirs[2]) - eq({directory=dirs[2], scope='tabpage', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev')) + command('tcd ' .. dirs[2]) + eq({ directory = dirs[2], scope = 'tabpage', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'tabpage', changed_window = false }, eval('g:ev')) eq('tabpage', eval('g:amatchpre')) eq('tabpage', eval('g:amatch')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) command('let g:evpre = {}') command('let g:ev = {}') - command('tcd '..dirs[2]) + command('tcd ' .. dirs[2]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) if is_os('win') then - command('tcd '..win_dirs[2]) + command('tcd ' .. win_dirs[2]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) end - command('cd '..dirs[3]) - eq({directory=dirs[3], scope='global', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev')) + command('cd ' .. dirs[3]) + eq({ directory = dirs[3], scope = 'global', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[3], scope = 'global', changed_window = false }, eval('g:ev')) eq('global', eval('g:amatch')) eq(3, eval('g:cdprecount')) eq(3, eval('g:cdcount')) command('let g:evpre = {}') command('let g:ev = {}') - command('cd '..dirs[3]) + command('cd ' .. dirs[3]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(3, eval('g:cdprecount')) eq(3, eval('g:cdcount')) if is_os('win') then - command('cd '..win_dirs[3]) + command('cd ' .. win_dirs[3]) eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(3, eval('g:cdprecount')) @@ -214,23 +236,23 @@ describe('autocmd DirChanged and DirChangedPre', function() command('set autochdir') - command('split '..dirs[1]..'/foo') - eq({directory=dirs[1], scope='window', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + command('split ' .. dirs[1] .. '/foo') + eq({ directory = dirs[1], scope = 'window', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'window', changed_window = false }, eval('g:ev')) eq('auto', eval('g:amatchpre')) eq('auto', eval('g:amatch')) eq(4, eval('g:cdprecount')) eq(4, eval('g:cdcount')) command('let g:evpre = {}') command('let g:ev = {}') - command('split '..dirs[1]..'/bar') + command('split ' .. dirs[1] .. '/bar') eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(4, eval('g:cdprecount')) eq(4, eval('g:cdcount')) if is_os('win') then - command('split '..win_dirs[1]..'/baz') + command('split ' .. win_dirs[1] .. '/baz') eq({}, eval('g:evpre')) eq({}, eval('g:ev')) eq(4, eval('g:cdprecount')) @@ -238,93 +260,93 @@ describe('autocmd DirChanged and DirChangedPre', function() end end) - it("are triggered by switching to win/tab with different CWD #6054", function() - command('lcd '..dirs[3]) -- window 3 - command('split '..dirs[2]..'/foo') -- window 2 - command('lcd '..dirs[2]) - command('split '..dirs[1]..'/bar') -- window 1 - command('lcd '..dirs[1]) + it('are triggered by switching to win/tab with different CWD #6054', function() + command('lcd ' .. dirs[3]) -- window 3 + command('split ' .. dirs[2] .. '/foo') -- window 2 + command('lcd ' .. dirs[2]) + command('split ' .. dirs[1] .. '/bar') -- window 1 + command('lcd ' .. dirs[1]) - command('2wincmd w') -- window 2 - eq({directory=dirs[2], scope='window', changed_window=true}, eval('g:evpre')) - eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev')) + command('2wincmd w') -- window 2 + eq({ directory = dirs[2], scope = 'window', changed_window = true }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'window', changed_window = true }, eval('g:ev')) eq('window', eval('g:amatchpre')) eq('window', eval('g:amatch')) eq(4, eval('g:cdprecount')) eq(4, eval('g:cdcount')) - command('tabnew') -- tab 2 (tab-local CWD) - eq(4, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(4, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tcd '..dirs[3]) - command('tabnext') -- tab 1 (no tab-local CWD) - eq({directory=dirs[2], scope='window', changed_window=true}, eval('g:evpre')) - eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev')) + command('tabnew') -- tab 2 (tab-local CWD) + eq(4, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(4, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tcd ' .. dirs[3]) + command('tabnext') -- tab 1 (no tab-local CWD) + eq({ directory = dirs[2], scope = 'window', changed_window = true }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'window', changed_window = true }, eval('g:ev')) eq('window', eval('g:amatchpre')) eq('window', eval('g:amatch')) - command('tabnext') -- tab 2 - eq({directory=dirs[3], scope='tabpage', changed_window=true}, eval('g:evpre')) - eq({cwd=dirs[3], scope='tabpage', changed_window=true}, eval('g:ev')) + command('tabnext') -- tab 2 + eq({ directory = dirs[3], scope = 'tabpage', changed_window = true }, eval('g:evpre')) + eq({ cwd = dirs[3], scope = 'tabpage', changed_window = true }, eval('g:ev')) eq('tabpage', eval('g:amatchpre')) eq('tabpage', eval('g:amatch')) eq(7, eval('g:cdprecount')) eq(7, eval('g:cdcount')) - command('tabnext') -- tab 1 - command('3wincmd w') -- window 3 + command('tabnext') -- tab 1 + command('3wincmd w') -- window 3 eq(9, eval('g:cdprecount')) eq(9, eval('g:cdcount')) - command('tabnext') -- tab 2 (has the *same* CWD) - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 2 (has the *same* CWD) + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event 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 - command('tcd '..win_dirs[3]) - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabnext') -- tab 1 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabprevious') -- tab 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabprevious') -- tab 2 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabprevious') -- tab 1 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('lcd '..win_dirs[3]) -- window 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabnext') -- tab 2 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabnext') -- tab 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabnext') -- tab 1 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event - command('tabprevious') -- tab 3 - eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event - eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnew') -- tab 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tcd ' .. win_dirs[3]) + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 1 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 2 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 1 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('lcd ' .. win_dirs[3]) -- window 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 2 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 1 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 3 + eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event end end) it('are triggered by nvim_set_current_dir()', function() request('nvim_set_current_dir', dirs[1]) - eq({directory=dirs[1], scope='global', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[1], scope='global', changed_window=false}, eval('g:ev')) + eq({ directory = dirs[1], scope = 'global', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[1], scope = 'global', changed_window = false }, eval('g:ev')) eq(1, eval('g:cdprecount')) eq(1, eval('g:cdcount')) request('nvim_set_current_dir', dirs[2]) - eq({directory=dirs[2], scope='global', changed_window=false}, eval('g:evpre')) - eq({cwd=dirs[2], scope='global', changed_window=false}, eval('g:ev')) + eq({ directory = dirs[2], scope = 'global', changed_window = false }, eval('g:evpre')) + eq({ cwd = dirs[2], scope = 'global', changed_window = false }, eval('g:ev')) eq(2, eval('g:cdprecount')) eq(2, eval('g:cdcount')) @@ -333,7 +355,7 @@ describe('autocmd DirChanged and DirChangedPre', function() end) eq(false, status) eq('Failed to change directory', string.match(err, ': (.*)')) - eq({directory='/doesnotexist', scope='global', changed_window=false}, eval('g:evpre')) + eq({ directory = '/doesnotexist', scope = 'global', changed_window = false }, eval('g:evpre')) eq(3, eval('g:cdprecount')) eq(2, eval('g:cdcount')) end) @@ -343,7 +365,7 @@ describe('autocmd DirChanged and DirChangedPre', function() command('let g:triggered = 0') command('autocmd DirChangedPre <buffer> let g:triggeredpre = 1') command('autocmd DirChanged <buffer> let g:triggered = 1') - command('cd '..dirs[1]) + command('cd ' .. dirs[1]) eq(1, eval('g:triggeredpre')) eq(1, eval('g:triggered')) end) diff --git a/test/functional/autocmd/filetype_spec.lua b/test/functional/autocmd/filetype_spec.lua index a571f6ee3b..648f830f27 100644 --- a/test/functional/autocmd/filetype_spec.lua +++ b/test/functional/autocmd/filetype_spec.lua @@ -5,13 +5,13 @@ local clear = helpers.clear local command = helpers.command describe('autocmd FileType', function() - before_each(clear) + before_each(clear) - it("is triggered by :help only once", function() - helpers.add_builddir_to_rtp() - command("let g:foo = 0") - command("autocmd FileType help let g:foo = g:foo + 1") - command("help help") - assert.same(1, eval('g:foo')) - end) + it('is triggered by :help only once', function() + helpers.add_builddir_to_rtp() + command('let g:foo = 0') + command('autocmd FileType help let g:foo = g:foo + 1') + command('help help') + assert.same(1, eval('g:foo')) + end) end) diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua index 33e4d88c7b..4f4a036ba8 100644 --- a/test/functional/autocmd/focus_spec.lua +++ b/test/functional/autocmd/focus_spec.lua @@ -1,12 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local luv = require('luv') local clear = helpers.clear -local nvim_prog = helpers.nvim_prog local feed_command = helpers.feed_command local feed_data = thelpers.feed_data -if helpers.skip(helpers.is_os('win')) then return end +if helpers.skip(helpers.is_os('win')) then + return +end describe('autoread TUI FocusGained/FocusLost', function() local f1 = 'xtest-foo' @@ -14,8 +14,16 @@ describe('autoread TUI FocusGained/FocusLost', function() before_each(function() clear() - screen = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]') + screen = thelpers.setup_child_nvim({ + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + 'colorscheme vim', + '--cmd', + 'set noswapfile noshowcmd noruler notermguicolors', + }) end) teardown(function() @@ -33,51 +41,54 @@ describe('autoread TUI FocusGained/FocusLost', function() helpers.write_file(path, '') local atime = os.time() - 10 - luv.fs_utime(path, atime, atime) + vim.uv.fs_utime(path, atime, atime) - screen:expect{grid=[[ + screen:expect { + grid = [[ {1: } | - {4:~ }| - {4:~ }| - {4:~ }| + {4:~ }|*3 {5:[No Name] }| | {3:-- TERMINAL --} | - ]]} - feed_command('edit '..path) - screen:expect{grid=[[ + ]], + } + feed_command('edit ' .. path) + screen:expect { + grid = [[ {1: } | - {4:~ }| - {4:~ }| - {4:~ }| + {4:~ }|*3 {5:xtest-foo }| :edit xtest-foo | {3:-- TERMINAL --} | - ]]} + ]], + } feed_data('\027[O') feed_data('\027[O') - screen:expect{grid=[[ + screen:expect { + grid = [[ {1: } | - {4:~ }| - {4:~ }| - {4:~ }| + {4:~ }|*3 {5:xtest-foo }| :edit xtest-foo | {3:-- TERMINAL --} | - ]], unchanged=true} + ]], + unchanged = true, + } helpers.write_file(path, expected_addition) feed_data('\027[I') - screen:expect{grid=[[ + screen:expect { + grid = [[ {1:l}ine 1 | line 2 | line 3 | line 4 | {5:xtest-foo }| - "xtest-foo" 4L, 28B | + :edit xtest-foo | {3:-- TERMINAL --} | - ]]} + ]], + } end) end) diff --git a/test/functional/autocmd/modechanged_spec.lua b/test/functional/autocmd/modechanged_spec.lua index 69a722a0e9..8ad914a597 100644 --- a/test/functional/autocmd/modechanged_spec.lua +++ b/test/functional/autocmd/modechanged_spec.lua @@ -17,15 +17,15 @@ describe('ModeChanged', function() feed('i') eq({ old_mode = 'nt', - new_mode = 't' + new_mode = 't', }, eval('g:event')) feed('<c-\\><c-n>') eq({ old_mode = 't', - new_mode = 'nt' + new_mode = 'nt', }, eval('g:event')) eq(3, eval('g:count')) - command("bd!") + command('bd!') -- v:event is cleared after the autocommand is done eq({}, eval('v:event')) diff --git a/test/functional/autocmd/safestate_spec.lua b/test/functional/autocmd/safestate_spec.lua index 73693749e4..b5b7ab2f95 100644 --- a/test/functional/autocmd/safestate_spec.lua +++ b/test/functional/autocmd/safestate_spec.lua @@ -3,7 +3,7 @@ local clear = helpers.clear local eq = helpers.eq local exec = helpers.exec local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api before_each(clear) @@ -18,40 +18,40 @@ describe('SafeState autocommand', function() it('with pending operator', function() feed('d') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('d') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) it('with specified register', function() feed('"r') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('x') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) it('with i_CTRL-O', function() feed('i<C-O>') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('x') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) it('with Insert mode completion', function() feed('i<C-X><C-V>') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('<C-X><C-Z>') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) it('with Cmdline completion', function() feed(':<Tab>') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('<C-E>') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) end) diff --git a/test/functional/autocmd/searchwrapped_spec.lua b/test/functional/autocmd/searchwrapped_spec.lua index 46c2c99b3d..0705b2d5de 100644 --- a/test/functional/autocmd/searchwrapped_spec.lua +++ b/test/functional/autocmd/searchwrapped_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command -local curbufmeths = helpers.curbufmeths +local api = helpers.api local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed @@ -13,9 +13,10 @@ describe('autocmd SearchWrapped', function() command('set ignorecase') command('let g:test = 0') command('autocmd! SearchWrapped * let g:test += 1') - curbufmeths.set_lines(0, 1, false, { + api.nvim_buf_set_lines(0, 0, 1, false, { 'The quick brown fox', - 'jumps over the lazy dog'}) + 'jumps over the lazy dog', + }) end) it('gets triggered when search wraps the end', function() diff --git a/test/functional/autocmd/show_spec.lua b/test/functional/autocmd/show_spec.lua index 9e0a5b819a..1a9dc8a337 100644 --- a/test/functional/autocmd/show_spec.lua +++ b/test/functional/autocmd/show_spec.lua @@ -5,29 +5,30 @@ local clear = helpers.clear local command = helpers.command local dedent = helpers.dedent local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local eval = helpers.eval local exec = helpers.exec local feed = helpers.feed -describe(":autocmd", function() +describe(':autocmd', function() before_each(function() - clear({'-u', 'NONE'}) + clear({ '-u', 'NONE' }) end) - it("should not segfault when you just do autocmd", function() - command ":autocmd" + it('should not segfault when you just do autocmd', function() + command ':autocmd' end) - it("should filter based on ++once", function() - command "autocmd! BufEnter" + it('should filter based on ++once', function() + command 'autocmd! BufEnter' command "autocmd BufEnter * :echo 'Hello'" command [[augroup TestingOne]] command [[ autocmd BufEnter * :echo "Line 1"]] command [[ autocmd BufEnter * :echo "Line 2"]] command [[augroup END]] - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- BufEnter @@ -35,15 +36,16 @@ describe(":autocmd", function() TestingOne BufEnter * :echo "Line 1" :echo "Line 2"]]), - funcs.execute('autocmd BufEnter')) + fn.execute('autocmd BufEnter') + ) end) it('should not show group information if interrupted', function() local screen = Screen.new(50, 6) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, -- NonText - [2] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg - [3] = {bold = true, foreground = Screen.colors.Magenta}, -- Title + [1] = { bold = true, foreground = Screen.colors.Blue1 }, -- NonText + [2] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg + [3] = { bold = true, foreground = Screen.colors.Magenta }, -- Title }) screen:attach() exec([[ @@ -79,10 +81,7 @@ describe(":autocmd", function() feed('q') screen:expect([[ ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*4 | ]]) end) @@ -112,7 +111,8 @@ describe(":autocmd", function() autocmd User foo call Func() doautocmd User foo ]]) - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- test_1 BufEnter @@ -122,7 +122,9 @@ describe(":autocmd", function() test_3 BufEnter D echo 'D' E echo 'E' - F echo 'F']]), eval('g:output')) + F echo 'F']]), + eval('g:output') + ) end) it('can filter by pattern #17973', function() @@ -148,7 +150,8 @@ describe(":autocmd", function() autocmd User B echo "B3" augroup END ]]) - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- test_1 User @@ -156,8 +159,11 @@ describe(":autocmd", function() test_2 User A echo "A2" test_3 User - A echo "A3"]]), funcs.execute('autocmd User A')) - eq(dedent([[ + A echo "A3"]]), + fn.execute('autocmd User A') + ) + eq( + dedent([[ --- Autocommands --- test_1 BufEnter @@ -171,14 +177,19 @@ describe(":autocmd", function() test_2 User B echo "B2" test_3 User - B echo "B3"]]), funcs.execute('autocmd * B')) - eq(dedent([[ + B echo "B3"]]), + fn.execute('autocmd * B') + ) + eq( + dedent([[ --- Autocommands --- test_3 BufEnter B echo "B3" test_3 User - B echo "B3"]]), funcs.execute('autocmd test_3 * B')) + B echo "B3"]]), + fn.execute('autocmd test_3 * B') + ) end) it('should skip consecutive patterns', function() @@ -203,7 +214,8 @@ describe(":autocmd", function() let g:output = execute('autocmd BufEnter') ]]) - eq(dedent([[ + eq( + dedent([[ --- Autocommands --- test_1 BufEnter @@ -219,6 +231,8 @@ describe(":autocmd", function() echo 'C' D echo 'D' echo 'E' - echo 'F']]), eval('g:output')) + echo 'F']]), + eval('g:output') + ) end) end) diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua index 738064090a..c7087254e7 100644 --- a/test/functional/autocmd/signal_spec.lua +++ b/test/functional/autocmd/signal_spec.lua @@ -3,15 +3,17 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local next_msg = helpers.next_msg local is_os = helpers.is_os local skip = helpers.skip -if skip(is_os('win'), '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') + os.execute('kill -s ' .. signame .. ' -- ' .. pid .. ' >/dev/null') end describe('autocmd Signal', function() @@ -19,25 +21,25 @@ describe('autocmd Signal', function() it('matches *', function() command('autocmd Signal * call rpcnotify(1, "foo")') - posix_kill('USR1', funcs.getpid()) - eq({'notification', 'foo', {}}, next_msg()) + posix_kill('USR1', fn.getpid()) + eq({ 'notification', 'foo', {} }, next_msg()) end) it('matches SIGUSR1', function() command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")') - posix_kill('USR1', funcs.getpid()) - eq({'notification', 'foo', {}}, next_msg()) + posix_kill('USR1', fn.getpid()) + eq({ 'notification', 'foo', {} }, next_msg()) end) it('matches SIGWINCH', function() command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")') - posix_kill('WINCH', funcs.getpid()) - eq({'notification', 'foo', {}}, next_msg()) + posix_kill('WINCH', fn.getpid()) + eq({ 'notification', 'foo', {} }, next_msg()) end) it('does not match unknown patterns', function() command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")') - posix_kill('USR1', funcs.getpid()) + posix_kill('USR1', fn.getpid()) eq(nil, next_msg(500)) end) end) diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua index 92d860c628..d0b2ac6a8d 100644 --- a/test/functional/autocmd/tabclose_spec.lua +++ b/test/functional/autocmd/tabclose_spec.lua @@ -1,5 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq +local clear, eq = helpers.clear, helpers.eq +local api = helpers.api +local command = helpers.command describe('TabClosed', function() before_each(clear) @@ -7,62 +9,71 @@ describe('TabClosed', function() describe('au TabClosed', function() describe('with * as <afile>', function() it('matches when closing any tab', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()') + command( + 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' + ) repeat - nvim('command', 'tabnew') - until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6 - eq("tabclosed:6:6:5", nvim('exec', 'tabclose', true)) -- close last 6, current tab is now 5 - eq("tabclosed:5:5:4", nvim('exec', 'close', true)) -- close last window on tab, closes tab - eq("tabclosed:2:2:3", nvim('exec', '2tabclose', true)) -- close tab 2, current tab is now 3 - eq("tabclosed:1:1:2\ntabclosed:1:1:1", nvim('exec', 'tabonly', true)) -- close tabs 1 and 2 + command('tabnew') + until api.nvim_eval('tabpagenr()') == 6 -- current tab is now 6 + eq('tabclosed:6:6:5', api.nvim_exec('tabclose', true)) -- close last 6, current tab is now 5 + eq('tabclosed:5:5:4', api.nvim_exec('close', true)) -- close last window on tab, closes tab + eq('tabclosed:2:2:3', api.nvim_exec('2tabclose', true)) -- close tab 2, current tab is now 3 + eq('tabclosed:1:1:2\ntabclosed:1:1:1', api.nvim_exec('tabonly', true)) -- close tabs 1 and 2 end) it('is triggered when closing a window via bdelete from another tab', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()') - nvim('command', '1tabedit Xtestfile') - nvim('command', '1tabedit Xtestfile') - nvim('command', 'normal! 1gt') - eq({1, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq("tabclosed:2:2:1\ntabclosed:2:2:1", nvim('exec', 'bdelete Xtestfile', true)) - eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + command( + 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' + ) + command('1tabedit Xtestfile') + command('1tabedit Xtestfile') + command('normal! 1gt') + eq({ 1, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:1\ntabclosed:2:2:1', api.nvim_exec('bdelete Xtestfile', true)) + eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) end) it('is triggered when closing a window via bdelete from current tab', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()') - nvim('command', 'file Xtestfile1') - nvim('command', '1tabedit Xtestfile2') - nvim('command', '1tabedit Xtestfile2') + command( + 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' + ) + command('file Xtestfile1') + command('1tabedit Xtestfile2') + command('1tabedit Xtestfile2') -- Only one tab is closed, and the alternate file is used for the other. - eq({2, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq("tabclosed:2:2:2", nvim('exec', 'bdelete Xtestfile2', true)) - eq('Xtestfile1', nvim('eval', 'bufname("")')) + eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:2', api.nvim_exec('bdelete Xtestfile2', true)) + eq('Xtestfile1', api.nvim_eval('bufname("")')) end) end) describe('with NR as <afile>', function() it('matches when closing a tab whose index is NR', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()') - nvim('command', 'au! TabClosed 2 echom "tabclosed:match"') + command( + 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' + ) + command('au! TabClosed 2 echom "tabclosed:match"') repeat - nvim('command', 'tabnew') - until nvim('eval', 'tabpagenr()') == 7 -- current tab is now 7 + command('tabnew') + until api.nvim_eval('tabpagenr()') == 7 -- current tab is now 7 -- sanity check, we shouldn't match on tabs with numbers other than 2 - eq("tabclosed:7:7:6", nvim('exec', 'tabclose', true)) + eq('tabclosed:7:7:6', api.nvim_exec('tabclose', true)) -- close tab page 2, current tab is now 5 - eq("tabclosed:2:2:5\ntabclosed:match", nvim('exec', '2tabclose', true)) + eq('tabclosed:2:2:5\ntabclosed:match', api.nvim_exec('2tabclose', true)) end) end) describe('with close', function() it('is triggered', function() - nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()') - nvim('command', 'tabedit Xtestfile') - eq({2, 2}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq("tabclosed:2:2:1", nvim('exec', 'close', true)) - eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + command( + 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' + ) + command('tabedit Xtestfile') + eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:1', api.nvim_exec('close', true)) + eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) end) end) end) end) - diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua index 6e167dd55c..b888845e3b 100644 --- a/test/functional/autocmd/tabnewentered_spec.lua +++ b/test/functional/autocmd/tabnewentered_spec.lua @@ -6,7 +6,7 @@ local dedent = helpers.dedent local eval = helpers.eval local eq = helpers.eq local feed = helpers.feed -local nvim = helpers.nvim +local api = helpers.api local exec_capture = helpers.exec_capture describe('TabNewEntered', function() @@ -14,33 +14,33 @@ describe('TabNewEntered', function() describe('with * as <afile>', function() it('matches when entering any new tab', function() clear() - nvim('command', 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")') - eq("tabnewentered:2:2", nvim('exec', 'tabnew', true)) - eq("tabnewentered:3:3", nvim('exec', 'tabnew test.x2', true)) - end) + command('au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")') + eq('tabnewentered:2:2', api.nvim_exec('tabnew', true)) + eq('tabnewentered:3:3', api.nvim_exec('tabnew test.x2', true)) + end) end) describe('with FILE as <afile>', function() it('matches when opening a new tab for FILE', function() clear() - nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"') - eq('tabnewentered:match', nvim('exec', 'tabnew Xtest-tabnewentered', true)) - end) + command('au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"') + eq('tabnewentered:match', api.nvim_exec('tabnew Xtest-tabnewentered', true)) + end) end) describe('with CTRL-W T', function() it('works when opening a new tab with CTRL-W T', function() clear() - nvim('command', 'au! TabNewEntered * echom "entered"') - nvim('command', 'tabnew test.x2') - nvim('command', 'split') - eq('entered', nvim('exec', 'execute "normal \\<C-W>T"', true)) + command('au! TabNewEntered * echom "entered"') + command('tabnew test.x2') + command('split') + eq('entered', api.nvim_exec('execute "normal \\<C-W>T"', true)) end) end) describe('with tab split #4334', function() it('works when create a tab by using tab split command', function() clear() - nvim('command', 'au! TabNewEntered * let b:entered = "entered"') - nvim('command', 'tab split') - eq('entered', nvim('exec', 'echo b:entered', true)) + command('au! TabNewEntered * let b:entered = "entered"') + command('tab split') + eq('entered', api.nvim_exec('echo b:entered', true)) end) end) end) @@ -49,22 +49,22 @@ end) describe('TabEnter', function() before_each(clear) it('has correct previous tab when entering any new tab', function() - command('augroup TEMP') - nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') - command('augroup END') - eq("tabenter:2:1", nvim('exec', 'tabnew', true)) - eq("tabenter:3:2", nvim('exec', 'tabnew test.x2', true)) - command('augroup! TEMP') + command('augroup TEMP') + command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') + command('augroup END') + eq('tabenter:2:1', api.nvim_exec('tabnew', true)) + eq('tabenter:3:2', api.nvim_exec('tabnew test.x2', true)) + command('augroup! TEMP') end) it('has correct previous tab when entering any preexisting tab', function() - command('tabnew') - command('tabnew') - command('augroup TEMP') - nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') - command('augroup END') - eq("tabenter:1:3", nvim('exec', 'tabnext', true)) - eq("tabenter:2:1", nvim('exec', 'tabnext', true)) - command('augroup! TEMP') + command('tabnew') + command('tabnew') + command('augroup TEMP') + command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') + command('augroup END') + eq('tabenter:1:3', api.nvim_exec('tabnext', true)) + eq('tabenter:2:1', api.nvim_exec('tabnext', true)) + command('augroup! TEMP') end) end) @@ -72,18 +72,19 @@ describe('tabpage/previous', function() before_each(clear) local function switches_to_previous_after_new_tab_creation_at_end(characters) return function() - -- Add three tabs for a total of four - command('tabnew') - command('tabnew') - command('tabnew') + -- Add three tabs for a total of four + command('tabnew') + command('tabnew') + command('tabnew') - -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + -- The previous tab is now the third. + eq(3, eval("tabpagenr('#')")) - -- Switch to the previous (third) tab - feed(characters) + -- Switch to the previous (third) tab + feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -93,18 +94,29 @@ describe('tabpage/previous', function() > [No Name] Tab page 4 # [No Name]]=]), - exec_capture('tabs') - ) + exec_capture('tabs') + ) - -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + -- The previous tab is now the fourth. + eq(4, eval("tabpagenr('#')")) end end - it('switches to previous via g<Tab> after new tab creation at end', - switches_to_previous_after_new_tab_creation_at_end('g<Tab>')) - it('switches to previous via <C-W>g<Tab>. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end('<C-W>g<Tab>')) - it('switches to previous via <C-Tab>. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end('<C-Tab>')) - it('switches to previous via :tabn #<CR>. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end(':tabn #<CR>')) + it( + 'switches to previous via g<Tab> after new tab creation at end', + switches_to_previous_after_new_tab_creation_at_end('g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab>. after new tab creation at end', + switches_to_previous_after_new_tab_creation_at_end('<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab>. after new tab creation at end', + switches_to_previous_after_new_tab_creation_at_end('<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR>. after new tab creation at end', + switches_to_previous_after_new_tab_creation_at_end(':tabn #<CR>') + ) local function switches_to_previous_after_new_tab_creation_in_middle(characters) return function() @@ -118,11 +130,12 @@ describe('tabpage/previous', function() command('tabnew') -- The previous tab is now the second. - eq(2, eval('tabpagenr(\'#\')')) + eq(2, eval("tabpagenr('#')")) -- Switch to the previous (second) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -134,21 +147,29 @@ describe('tabpage/previous', function() [No Name] Tab page 5 [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) end end - it('switches to previous via g<Tab> after new tab creation in middle', - switches_to_previous_after_new_tab_creation_in_middle('g<Tab>')) - it('switches to previous via <C-W>g<Tab> after new tab creation in middle', - switches_to_previous_after_new_tab_creation_in_middle('<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after new tab creation in middle', - switches_to_previous_after_new_tab_creation_in_middle('<C-Tab>')) - it('switches to previous via :tabn #<CR> after new tab creation in middle', - switches_to_previous_after_new_tab_creation_in_middle(':tabn #<CR>')) + it( + 'switches to previous via g<Tab> after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle('g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle('<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle('<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle(':tabn #<CR>') + ) local function switches_to_previous_after_switching_to_next_tab(characters) return function() @@ -160,12 +181,13 @@ describe('tabpage/previous', function() command('tabnext') -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) -- Switch to the previous (fourth) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 # [No Name] @@ -175,21 +197,29 @@ describe('tabpage/previous', function() [No Name] Tab page 4 > [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the first. - eq(1, eval('tabpagenr(\'#\')')) + eq(1, eval("tabpagenr('#')")) end end - it('switches to previous via g<Tab> after switching to next tab', - switches_to_previous_after_switching_to_next_tab('g<Tab>')) - it('switches to previous via <C-W>g<Tab> after switching to next tab', - switches_to_previous_after_switching_to_next_tab('<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after switching to next tab', - switches_to_previous_after_switching_to_next_tab('<C-Tab>')) - it('switches to previous via :tabn #<CR> after switching to next tab', - switches_to_previous_after_switching_to_next_tab(':tabn #<CR>')) + it( + 'switches to previous via g<Tab> after switching to next tab', + switches_to_previous_after_switching_to_next_tab('g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after switching to next tab', + switches_to_previous_after_switching_to_next_tab('<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after switching to next tab', + switches_to_previous_after_switching_to_next_tab('<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after switching to next tab', + switches_to_previous_after_switching_to_next_tab(':tabn #<CR>') + ) local function switches_to_previous_after_switching_to_last_tab(characters) return function() @@ -203,12 +233,13 @@ describe('tabpage/previous', function() command('tablast') -- The previous tab is now the second. - eq(1, eval('tabpagenr(\'#\')')) + eq(1, eval("tabpagenr('#')")) -- Switch to the previous (second) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 > [No Name] @@ -218,21 +249,29 @@ describe('tabpage/previous', function() [No Name] Tab page 4 # [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) end end - it('switches to previous after switching to last tab', - switches_to_previous_after_switching_to_last_tab('g<Tab>')) - it('switches to previous after switching to last tab', - switches_to_previous_after_switching_to_last_tab('<C-W>g<Tab>')) - it('switches to previous after switching to last tab', - switches_to_previous_after_switching_to_last_tab('<C-Tab>')) - it('switches to previous after switching to last tab', - switches_to_previous_after_switching_to_last_tab(':tabn #<CR>')) + it( + 'switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab('g<Tab>') + ) + it( + 'switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab('<C-W>g<Tab>') + ) + it( + 'switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab('<C-Tab>') + ) + it( + 'switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab(':tabn #<CR>') + ) local function switches_to_previous_after_switching_to_previous_tab(characters) return function() @@ -244,12 +283,13 @@ describe('tabpage/previous', function() command('tabprevious') -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) -- Switch to the previous (fourth) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -259,21 +299,29 @@ describe('tabpage/previous', function() # [No Name] Tab page 4 > [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) end end - it('switches to previous via g<Tab> after switching to previous tab', - switches_to_previous_after_switching_to_previous_tab('g<Tab>')) - it('switches to previous via <C-W>g<Tab> after switching to previous tab', - switches_to_previous_after_switching_to_previous_tab('<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after switching to previous tab', - switches_to_previous_after_switching_to_previous_tab('<C-Tab>')) - it('switches to previous via :tabn #<CR> after switching to previous tab', - switches_to_previous_after_switching_to_previous_tab(':tabn #<CR>')) + it( + 'switches to previous via g<Tab> after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab('g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab('<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab('<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab(':tabn #<CR>') + ) local function switches_to_previous_after_switching_to_first_tab(characters) return function() @@ -287,12 +335,13 @@ describe('tabpage/previous', function() command('tabfirst') -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) -- Switch to the previous (third) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 # [No Name] @@ -302,21 +351,29 @@ describe('tabpage/previous', function() > [No Name] Tab page 4 [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the first. - eq(1, eval('tabpagenr(\'#\')')) + eq(1, eval("tabpagenr('#')")) end end - it('switches to previous via g<Tab> after switching to first tab', - switches_to_previous_after_switching_to_first_tab('g<Tab>')) - it('switches to previous via <C-W>g<Tab> after switching to first tab', - switches_to_previous_after_switching_to_first_tab('<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after switching to first tab', - switches_to_previous_after_switching_to_first_tab('<C-Tab>')) - it('switches to previous via :tabn #<CR> after switching to first tab', - switches_to_previous_after_switching_to_first_tab(':tabn #<CR>')) + it( + 'switches to previous via g<Tab> after switching to first tab', + switches_to_previous_after_switching_to_first_tab('g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after switching to first tab', + switches_to_previous_after_switching_to_first_tab('<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after switching to first tab', + switches_to_previous_after_switching_to_first_tab('<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after switching to first tab', + switches_to_previous_after_switching_to_first_tab(':tabn #<CR>') + ) local function switches_to_previous_after_numbered_tab_switch(characters) return function() @@ -328,12 +385,13 @@ describe('tabpage/previous', function() command('tabnext 2') -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) -- Switch to the previous (fourth) tab feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -343,21 +401,29 @@ describe('tabpage/previous', function() [No Name] Tab page 4 > [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the second. - eq(2, eval('tabpagenr(\'#\')')) + eq(2, eval("tabpagenr('#')")) end end - it('switches to previous via g<Tab> after numbered tab switch', - switches_to_previous_after_numbered_tab_switch('g<Tab>')) - it('switches to previous via <C-W>g<Tab> after numbered tab switch', - switches_to_previous_after_numbered_tab_switch('<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after numbered tab switch', - switches_to_previous_after_numbered_tab_switch('<C-Tab>')) - it('switches to previous via :tabn #<CR> after numbered tab switch', - switches_to_previous_after_numbered_tab_switch(':tabn #<CR>')) + it( + 'switches to previous via g<Tab> after numbered tab switch', + switches_to_previous_after_numbered_tab_switch('g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after numbered tab switch', + switches_to_previous_after_numbered_tab_switch('<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after numbered tab switch', + switches_to_previous_after_numbered_tab_switch('<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after numbered tab switch', + switches_to_previous_after_numbered_tab_switch(':tabn #<CR>') + ) local function switches_to_previous_after_switching_to_previous(characters1, characters2) return function() @@ -371,12 +437,13 @@ describe('tabpage/previous', function() feed(characters1) -- The previous tab is now the second. - eq(2, eval('tabpagenr(\'#\')')) + eq(2, eval("tabpagenr('#')")) -- Switch to the previous (second) tab feed(characters2) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -386,45 +453,77 @@ describe('tabpage/previous', function() [No Name] Tab page 4 # [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the fourth. - eq(4, eval('tabpagenr(\'#\')')) + eq(4, eval("tabpagenr('#')")) end end - it('switches to previous via g<Tab> after switching to previous via g<Tab>', - switches_to_previous_after_switching_to_previous('g<Tab>', 'g<Tab>')) - it('switches to previous via <C-W>g<Tab> after switching to previous via g<Tab>', - switches_to_previous_after_switching_to_previous('g<Tab>', '<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after switching to previous via g<Tab>', - switches_to_previous_after_switching_to_previous('g<Tab>', '<C-Tab>')) - it('switches to previous via :tabn #<CR> after switching to previous via g<Tab>', - switches_to_previous_after_switching_to_previous('g<Tab>', ':tabn #<CR>')) - it('switches to previous via g<Tab> after switching to previous via <C-W>g<Tab>', - switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', 'g<Tab>')) - it('switches to previous via <C-W>g<Tab> after switching to previous via <C-W>g<Tab>', - switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', '<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after switching to previous via <C-W>g<Tab>', - switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', '<C-Tab>')) - it('switches to previous via :tabn #<CR> after switching to previous via <C-W>g<Tab>', - switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', ':tabn #<CR>')) - it('switches to previous via g<Tab> after switching to previous via <C-Tab>', - switches_to_previous_after_switching_to_previous('<C-Tab>', 'g<Tab>')) - it('switches to previous via <C-W>g<Tab> after switching to previous via <C-Tab>', - switches_to_previous_after_switching_to_previous('<C-Tab>', '<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after switching to previous via <C-Tab>', - switches_to_previous_after_switching_to_previous('<C-Tab>', '<C-Tab>')) - it('switches to previous via :tabn #<CR> after switching to previous via <C-Tab>', - switches_to_previous_after_switching_to_previous('<C-Tab>', ':tabn #<CR>')) - it('switches to previous via g<Tab> after switching to previous via :tabn #<CR>', - switches_to_previous_after_switching_to_previous(':tabn #<CR>', 'g<Tab>')) - it('switches to previous via <C-W>g<Tab> after switching to previous via :tabn #<CR>', - switches_to_previous_after_switching_to_previous(':tabn #<CR>', '<C-W>g<Tab>')) - it('switches to previous via <C-Tab> after switching to previous via <C-Tab>', - switches_to_previous_after_switching_to_previous(':tabn #<CR>', '<C-Tab>')) - it('switches to previous via :tabn #<CR> after switching to previous via :tabn #<CR>', - switches_to_previous_after_switching_to_previous(':tabn #<CR>', ':tabn #<CR>')) + it( + 'switches to previous via g<Tab> after switching to previous via g<Tab>', + switches_to_previous_after_switching_to_previous('g<Tab>', 'g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after switching to previous via g<Tab>', + switches_to_previous_after_switching_to_previous('g<Tab>', '<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after switching to previous via g<Tab>', + switches_to_previous_after_switching_to_previous('g<Tab>', '<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after switching to previous via g<Tab>', + switches_to_previous_after_switching_to_previous('g<Tab>', ':tabn #<CR>') + ) + it( + 'switches to previous via g<Tab> after switching to previous via <C-W>g<Tab>', + switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', 'g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after switching to previous via <C-W>g<Tab>', + switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', '<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after switching to previous via <C-W>g<Tab>', + switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', '<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after switching to previous via <C-W>g<Tab>', + switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', ':tabn #<CR>') + ) + it( + 'switches to previous via g<Tab> after switching to previous via <C-Tab>', + switches_to_previous_after_switching_to_previous('<C-Tab>', 'g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after switching to previous via <C-Tab>', + switches_to_previous_after_switching_to_previous('<C-Tab>', '<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after switching to previous via <C-Tab>', + switches_to_previous_after_switching_to_previous('<C-Tab>', '<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after switching to previous via <C-Tab>', + switches_to_previous_after_switching_to_previous('<C-Tab>', ':tabn #<CR>') + ) + it( + 'switches to previous via g<Tab> after switching to previous via :tabn #<CR>', + switches_to_previous_after_switching_to_previous(':tabn #<CR>', 'g<Tab>') + ) + it( + 'switches to previous via <C-W>g<Tab> after switching to previous via :tabn #<CR>', + switches_to_previous_after_switching_to_previous(':tabn #<CR>', '<C-W>g<Tab>') + ) + it( + 'switches to previous via <C-Tab> after switching to previous via <C-Tab>', + switches_to_previous_after_switching_to_previous(':tabn #<CR>', '<C-Tab>') + ) + it( + 'switches to previous via :tabn #<CR> after switching to previous via :tabn #<CR>', + switches_to_previous_after_switching_to_previous(':tabn #<CR>', ':tabn #<CR>') + ) local function does_not_switch_to_previous_after_closing_current_tab(characters) return function() @@ -436,13 +535,14 @@ describe('tabpage/previous', function() command('wincmd c') -- The previous tab is now the "zeroth" -- there isn't one. - eq(0, eval('tabpagenr(\'#\')')) + eq(0, eval("tabpagenr('#')")) -- At this point, switching to the "previous" (i.e. fourth) tab would mean -- switching to either a dangling or a null pointer. feed(characters) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -450,21 +550,29 @@ describe('tabpage/previous', function() [No Name] Tab page 3 > [No Name]]=]), - exec_capture('tabs') + exec_capture('tabs') ) -- The previous tab is now the "zero". - eq(0, eval('tabpagenr(\'#\')')) + eq(0, eval("tabpagenr('#')")) end end - it('does not switch to previous via g<Tab> after closing current tab', - does_not_switch_to_previous_after_closing_current_tab('g<Tab>')) - it('does not switch to previous via <C-W>g<Tab> after closing current tab', - does_not_switch_to_previous_after_closing_current_tab('<C-W>g<Tab>')) - it('does not switch to previous via <C-Tab> after closing current tab', - does_not_switch_to_previous_after_closing_current_tab('<C-Tab>')) - it('does not switch to previous via :tabn #<CR> after closing current tab', - does_not_switch_to_previous_after_closing_current_tab(':tabn #<CR>')) + it( + 'does not switch to previous via g<Tab> after closing current tab', + does_not_switch_to_previous_after_closing_current_tab('g<Tab>') + ) + it( + 'does not switch to previous via <C-W>g<Tab> after closing current tab', + does_not_switch_to_previous_after_closing_current_tab('<C-W>g<Tab>') + ) + it( + 'does not switch to previous via <C-Tab> after closing current tab', + does_not_switch_to_previous_after_closing_current_tab('<C-Tab>') + ) + it( + 'does not switch to previous via :tabn #<CR> after closing current tab', + does_not_switch_to_previous_after_closing_current_tab(':tabn #<CR>') + ) local function does_not_switch_to_previous_after_entering_operator_pending(characters) return function() @@ -474,7 +582,7 @@ describe('tabpage/previous', function() command('tabnew') -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) -- Enter operator pending mode. feed('d') @@ -491,11 +599,13 @@ describe('tabpage/previous', function() eq(4, eval('tabpagenr()')) -- The previous tab is still the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) end end - it('does not switch to previous via g<Tab> after entering operator pending', - does_not_switch_to_previous_after_entering_operator_pending('g<Tab>')) + it( + 'does not switch to previous via g<Tab> after entering operator pending', + does_not_switch_to_previous_after_entering_operator_pending('g<Tab>') + ) -- NOTE: When in operator pending mode, attempting to switch to previous has -- the following effect: -- - Ctrl-W exits operator pending mode @@ -506,8 +616,10 @@ describe('tabpage/previous', function() -- be the same as the normal mode command to switch to the previous tab. -- it('does not switch to previous via <C-W>g<Tab> after entering operator pending', -- does_not_switch_to_previous_after_entering_operator_pending('<C-W>g<Tab>')) - it('does not switch to previous via <C-Tab> after entering operator pending', - does_not_switch_to_previous_after_entering_operator_pending('<C-Tab>')) + it( + 'does not switch to previous via <C-Tab> after entering operator pending', + does_not_switch_to_previous_after_entering_operator_pending('<C-Tab>') + ) -- NOTE: When in operator pending mode, pressing : leaves operator pending -- mode and enters command mode, so :tabn #<CR> does in fact switch -- tabs. @@ -522,7 +634,7 @@ describe('tabpage/previous', function() command('tabnew') -- The previous tab is now the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) -- Edit : command line in command-line window feed('q:') @@ -540,31 +652,34 @@ describe('tabpage/previous', function() eq(4, eval('tabpagenr()')) -- The previous tab is still the third. - eq(3, eval('tabpagenr(\'#\')')) + eq(3, eval("tabpagenr('#')")) end end - it('cmdline-win prevents tab switch via g<Tab>', - cmdline_win_prevents_tab_switch('g<Tab>', 0)) - it('cmdline-win prevents tab switch via <C-W>g<Tab>', - cmdline_win_prevents_tab_switch('<C-W>g<Tab>', 1)) - it('cmdline-win prevents tab switch via <C-Tab>', - cmdline_win_prevents_tab_switch('<C-Tab>', 0)) - it('cmdline-win prevents tab switch via :tabn #<CR>', - cmdline_win_prevents_tab_switch(':tabn #<CR>', 0)) + it('cmdline-win prevents tab switch via g<Tab>', cmdline_win_prevents_tab_switch('g<Tab>', 0)) + it( + 'cmdline-win prevents tab switch via <C-W>g<Tab>', + cmdline_win_prevents_tab_switch('<C-W>g<Tab>', 1) + ) + it('cmdline-win prevents tab switch via <C-Tab>', cmdline_win_prevents_tab_switch('<C-Tab>', 0)) + it( + 'cmdline-win prevents tab switch via :tabn #<CR>', + cmdline_win_prevents_tab_switch(':tabn #<CR>', 0) + ) it(':tabs indicates correct prevtab curwin', function() - -- Add three tabs for a total of four - command('tabnew') - command('tabnew') - command('split') - command('vsplit') - feed('<C-w>p') - command('tabnew') + -- Add three tabs for a total of four + command('tabnew') + command('tabnew') + command('split') + command('vsplit') + feed('<C-w>p') + command('tabnew') - -- The previous tab is now the three. - eq(3, eval('tabpagenr(\'#\')')) + -- The previous tab is now the three. + eq(3, eval("tabpagenr('#')")) - eq(dedent([=[ + eq( + dedent([=[ Tab page 1 [No Name] @@ -576,7 +691,7 @@ describe('tabpage/previous', function() [No Name] Tab page 4 > [No Name]]=]), - exec_capture('tabs') - ) + exec_capture('tabs') + ) end) end) diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index 332a936e3f..982edfa06a 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -1,15 +1,13 @@ -local luv = require('luv') +local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -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 clear, command, testprg = helpers.clear, helpers.command, 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 meths = helpers.meths +local api = helpers.api local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive local skip = helpers.skip @@ -18,17 +16,19 @@ local is_os = helpers.is_os describe('autocmd TermClose', function() before_each(function() clear() - nvim('set_option_value', 'shell', testprg('shell-test'), {}) + api.nvim_set_option_value('shell', testprg('shell-test'), {}) command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') end) local function test_termclose_delete_own_buf() -- The terminal process needs to keep running so that TermClose isn't triggered immediately. - nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) + api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) command('autocmd TermClose * bdelete!') command('terminal') - matches('^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://', - 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 @@ -46,58 +46,76 @@ describe('autocmd TermClose', function() command('autocmd TermClose * let g:test_termclose = 23') command('terminal') -- shell-test exits immediately. - retry(nil, nil, function() neq(-1, eval('jobwait([&channel], 0)[0]')) end) - retry(nil, nil, function() eq(23, eval('g:test_termclose')) end) + retry(nil, nil, function() + neq(-1, eval('jobwait([&channel], 0)[0]')) + end) + retry(nil, nil, function() + eq(23, eval('g:test_termclose')) + end) end) it('triggers when long-running terminal job gets stopped', function() skip(is_os('win')) - nvim('set_option_value', 'shell', is_os('win') and 'cmd.exe' or 'sh', {}) + api.nvim_set_option_value('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)') - retry(nil, nil, function() eq(23, eval('g:test_termclose')) end) + retry(nil, nil, function() + eq(23, eval('g:test_termclose')) + end) end) it('kills job trapping SIGTERM', function() skip(is_os('win')) - nvim('set_option_value', 'shell', 'sh', {}) - nvim('set_option_value', 'shellcmdflag', '-c', {}) - command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] - .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] - .. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]]) - retry(nil, nil, function() eq(1, eval('get(g:, "test_job_started", 0)')) end) - - luv.update_time() - local start = luv.now() + api.nvim_set_option_value('shell', 'sh', {}) + api.nvim_set_option_value('shellcmdflag', '-c', {}) + command( + [[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] + .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] + .. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]] + ) + retry(nil, nil, function() + eq(1, eval('get(g:, "test_job_started", 0)')) + end) + + uv.update_time() + local start = uv.now() command('call jobstop(g:test_job)') - retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end) - luv.update_time() - local duration = luv.now() - start + retry(nil, nil, function() + eq(1, eval('get(g:, "test_job_exited", 0)')) + end) + uv.update_time() + local duration = uv.now() - start -- Nvim begins SIGTERM after KILL_TIMEOUT_MS. ok(duration >= 2000) - ok(duration <= 4000) -- Epsilon for slow CI + ok(duration <= 4000) -- Epsilon for slow CI end) it('kills PTY job trapping SIGHUP and SIGTERM', function() skip(is_os('win')) - nvim('set_option_value', 'shell', 'sh', {}) - nvim('set_option_value', 'shellcmdflag', '-c', {}) - command([[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] - .. [[ 'pty': 1,]] - .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] - .. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]]) - retry(nil, nil, function() eq(1, eval('get(g:, "test_job_started", 0)')) end) - - luv.update_time() - local start = luv.now() + api.nvim_set_option_value('shell', 'sh', {}) + api.nvim_set_option_value('shellcmdflag', '-c', {}) + command( + [[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] + .. [[ 'pty': 1,]] + .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] + .. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]] + ) + retry(nil, nil, function() + eq(1, eval('get(g:, "test_job_started", 0)')) + end) + + uv.update_time() + local start = uv.now() command('call jobstop(g:test_job)') - retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end) - luv.update_time() - local duration = luv.now() - start + retry(nil, nil, function() + eq(1, eval('get(g:, "test_job_exited", 0)')) + end) + uv.update_time() + local duration = uv.now() - start -- Nvim begins SIGKILL after (2 * KILL_TIMEOUT_MS). ok(duration >= 4000) - ok(duration <= 7000) -- Epsilon for slow CI + ok(duration <= 7000) -- Epsilon for slow CI end) it('reports the correct <abuf>', function() @@ -109,13 +127,19 @@ describe('autocmd TermClose', function() eq(2, eval('bufnr("%")')) command('terminal ls') - retry(nil, nil, function() eq(3, eval('bufnr("%")')) end) + retry(nil, nil, function() + eq(3, eval('bufnr("%")')) + end) command('buffer 1') - retry(nil, nil, function() eq(1, eval('bufnr("%")')) end) + retry(nil, nil, function() + eq(1, eval('bufnr("%")')) + end) command('3bdelete!') - retry(nil, nil, function() eq('3', eval('g:abuf')) end) + retry(nil, nil, function() + eq('3', eval('g:abuf')) + end) feed('<c-c>:qa!<cr>') end) @@ -124,10 +148,14 @@ describe('autocmd TermClose', function() command('autocmd TermClose * let g:status = v:event.status') command('terminal 0') - retry(nil, nil, function() eq(0, eval('g:status')) end) + retry(nil, nil, function() + eq(0, eval('g:status')) + end) command('terminal 42') - retry(nil, nil, function() eq(42, eval('g:status')) end) + retry(nil, nil, function() + eq(42, eval('g:status')) + end) end) end) @@ -141,27 +169,30 @@ it('autocmd TermEnter, TermLeave', function() command('terminal') feed('i') - eq({ {'TermOpen', 'n'}, {'TermEnter', 't'}, }, eval('g:evs')) + eq({ { 'TermOpen', 'n' }, { 'TermEnter', 't' } }, eval('g:evs')) feed([[<C-\><C-n>]]) feed('A') - eq({ {'TermOpen', 'n'}, {'TermEnter', 't'}, {'TermLeave', 'n'}, {'TermEnter', 't'}, }, eval('g:evs')) + eq( + { { 'TermOpen', 'n' }, { 'TermEnter', 't' }, { 'TermLeave', 'n' }, { 'TermEnter', 't' } }, + eval('g:evs') + ) -- TermLeave is also triggered by :quit. command('split foo') - feed('<Ignore>') -- Add input to separate two RPC requests + feed('<Ignore>') -- Add input to separate two RPC requests command('wincmd w') feed('i') command('q!') - feed('<Ignore>') -- Add input to separate two RPC requests + feed('<Ignore>') -- Add input to separate two RPC requests eq({ - {'TermOpen', 'n'}, - {'TermEnter', 't'}, - {'TermLeave', 'n'}, - {'TermEnter', 't'}, - {'TermLeave', 'n'}, - {'TermEnter', 't'}, - {'TermClose', 't'}, - {'TermLeave', 'n'}, + { 'TermOpen', 'n' }, + { 'TermEnter', 't' }, + { 'TermLeave', 'n' }, + { 'TermEnter', 't' }, + { 'TermLeave', 'n' }, + { 'TermEnter', 't' }, + { 'TermClose', 't' }, + { 'TermLeave', 'n' }, }, eval('g:evs')) end) @@ -172,13 +203,18 @@ describe('autocmd TextChangedT', function() it('works', function() command('autocmd TextChangedT * ++once let g:called = 1') thelpers.feed_data('a') - retry(nil, nil, function() eq(1, meths.get_var('called')) end) + retry(nil, nil, function() + eq(1, api.nvim_get_var('called')) + end) end) it('cannot delete terminal buffer', function() command([[autocmd TextChangedT * call nvim_input('<CR>') | bwipe!]]) thelpers.feed_data('a') - screen:expect({any = 'E937: '}) - matches('^E937: Attempt to delete a buffer that is in use: term://', meths.get_vvar('errmsg')) + screen:expect({ any = 'E937: ' }) + matches( + '^E937: Attempt to delete a buffer that is in use: term://', + api.nvim_get_vvar('errmsg') + ) end) end) diff --git a/test/functional/autocmd/textchanged_spec.lua b/test/functional/autocmd/textchanged_spec.lua index b621eb36bf..d501560dc1 100644 --- a/test/functional/autocmd/textchanged_spec.lua +++ b/test/functional/autocmd/textchanged_spec.lua @@ -88,7 +88,7 @@ it('TextChangedI and TextChangedP autocommands', function() eq('IIPPPP', eval('g:autocmd')) feed('<esc>') - eq({'foo', 'bar', 'foobar', 'foo'}, eval('getline(1, "$")')) + eq({ 'foo', 'bar', 'foobar', 'foo' }, eval('getline(1, "$")')) end) -- oldtest: Test_TextChangedI_with_setline() @@ -172,11 +172,22 @@ it('TextChangedI and TextChanged', function() eq('', eval('g:autocmd_n')) end - validate_mixed_textchangedi({'o', '<esc>'}) - validate_mixed_textchangedi({'O', '<esc>'}) - validate_mixed_textchangedi({'ciw', '<esc>'}) - validate_mixed_textchangedi({'cc', '<esc>'}) - validate_mixed_textchangedi({'C', '<esc>'}) - validate_mixed_textchangedi({'s', '<esc>'}) - validate_mixed_textchangedi({'S', '<esc>'}) + validate_mixed_textchangedi({ 'o', '<esc>' }) + validate_mixed_textchangedi({ 'O', '<esc>' }) + validate_mixed_textchangedi({ 'ciw', '<esc>' }) + validate_mixed_textchangedi({ 'cc', '<esc>' }) + validate_mixed_textchangedi({ 'C', '<esc>' }) + validate_mixed_textchangedi({ 's', '<esc>' }) + validate_mixed_textchangedi({ 'S', '<esc>' }) +end) + +-- oldtest: Test_TextChanged_with_norm() +it('TextChanged is triggered after :norm that enters Insert mode', function() + exec([[ + let g:a = 0 + au TextChanged * let g:a += 1 + ]]) + eq(0, eval('g:a')) + feed(':norm! ia<CR>') + eq(1, eval('g:a')) end) diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua index 1640916ad8..29cd62f586 100644 --- a/test/functional/autocmd/textyankpost_spec.lua +++ b/test/functional/autocmd/textyankpost_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq local feed, command, expect = helpers.feed, helpers.command, helpers.expect -local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq +local api, fn, neq = helpers.api, helpers.fn, helpers.neq describe('TextYankPost', function() before_each(function() @@ -14,7 +14,7 @@ describe('TextYankPost', function() command('autocmd TextYankPost * let g:event = copy(v:event)') command('autocmd TextYankPost * let g:count += 1') - curbufmeths.set_lines(0, -1, true, { + api.nvim_buf_set_lines(0, 0, -1, true, { 'foo\0bar', 'baz text', }) @@ -28,7 +28,7 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(1, eval('g:count')) @@ -42,7 +42,7 @@ describe('TextYankPost', function() regcontents = { 'baz ' }, regname = '', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) eq(2, eval('g:count')) @@ -52,8 +52,8 @@ describe('TextYankPost', function() operator = 'y', regcontents = { 'foo', 'baz' }, regname = '', - regtype = "\0223", -- ^V + block width - visual = true + regtype = '\0223', -- ^V + block width + visual = true, }, eval('g:event')) eq(3, eval('g:count')) end) @@ -66,25 +66,25 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) command('set debug=msg') -- the regcontents should not be changed without copy. - local status, err = pcall(command,'call extend(g:event.regcontents, ["more text"])') - eq(status,false) + local status, err = pcall(command, 'call extend(g:event.regcontents, ["more text"])') + eq(status, false) neq(nil, string.find(err, ':E742:')) -- can't mutate keys inside the autocommand command('autocmd! TextYankPost * let v:event.regcontents = 0') - status, err = pcall(command,'normal yy') - eq(status,false) + status, err = pcall(command, 'normal yy') + eq(status, false) neq(nil, string.find(err, ':E46:')) -- can't add keys inside the autocommand command('autocmd! TextYankPost * let v:event.mykey = 0') - status, err = pcall(command,'normal yy') - eq(status,false) + status, err = pcall(command, 'normal yy') + eq(status, false) neq(nil, string.find(err, ':E742:')) end) @@ -97,10 +97,10 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(1, eval('g:count')) - eq({ 'foo\nbar' }, funcs.getreg('+',1,1)) + eq({ 'foo\nbar' }, fn.getreg('+', 1, 1)) end) it('is executed after delete and change', function() @@ -111,7 +111,7 @@ describe('TextYankPost', function() regcontents = { 'foo' }, regname = '', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) eq(1, eval('g:count')) @@ -122,7 +122,7 @@ describe('TextYankPost', function() regcontents = { '\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(2, eval('g:count')) @@ -133,7 +133,7 @@ describe('TextYankPost', function() regcontents = { 'baz' }, regname = '', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) eq(3, eval('g:count')) end) @@ -162,7 +162,7 @@ describe('TextYankPost', function() regcontents = { 'bar' }, regname = 'b', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) feed('"*yy') @@ -172,10 +172,10 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '*', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) - command("set clipboard=unnamed") + command('set clipboard=unnamed') -- regname still shows the name the user requested feed('yy') @@ -185,7 +185,7 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) feed('"*yy') @@ -195,7 +195,7 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '*', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) end) @@ -207,7 +207,7 @@ describe('TextYankPost', function() regcontents = { 'foo\nbar' }, regname = '+', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(1, eval('g:count')) @@ -218,7 +218,7 @@ describe('TextYankPost', function() regcontents = { 'baz text' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(2, eval('g:count')) @@ -229,7 +229,7 @@ describe('TextYankPost', function() regcontents = { 'baz ' }, regname = '', regtype = 'v', - visual = false + visual = false, }, eval('g:event')) eq(3, eval('g:count')) @@ -240,7 +240,7 @@ describe('TextYankPost', function() regcontents = { 'baz text' }, regname = '', regtype = 'V', - visual = false + visual = false, }, eval('g:event')) eq(4, eval('g:count')) end) diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua index e6fdd9560d..d40dc37103 100644 --- a/test/functional/autocmd/win_scrolled_resized_spec.lua +++ b/test/functional/autocmd/win_scrolled_resized_spec.lua @@ -7,7 +7,7 @@ local eval = helpers.eval local exec = helpers.exec local command = helpers.command local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local assert_alive = helpers.assert_alive before_each(clear) @@ -32,12 +32,29 @@ describe('WinResized', function() -- increase window height, two windows will be reported feed('<C-W>+') eq(1, eval('g:resized')) - eq({windows = {1002, 1001}}, eval('g:v_event')) + 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')) + eq({ windows = { 1002, 1001, 1000 } }, eval('g:v_event')) + end) + + it('is triggered in terminal mode #21197 #27207', function() + exec([[ + autocmd TermOpen * startinsert + let g:resized = 0 + autocmd WinResized * let g:resized += 1 + ]]) + eq(0, eval('g:resized')) + + command('vsplit term://') + eq({ mode = 't', blocking = false }, api.nvim_get_mode()) + eq(1, eval('g:resized')) + + command('split') + eq({ mode = 't', blocking = false }, api.nvim_get_mode()) + eq(2, eval('g:resized')) end) end) @@ -45,7 +62,7 @@ describe('WinScrolled', function() local win_id before_each(function() - win_id = meths.get_current_win().id + win_id = api.nvim_get_current_win() command(string.format('autocmd WinScrolled %d let g:matched = v:true', win_id)) exec([[ let g:scrolled = 0 @@ -63,104 +80,104 @@ describe('WinScrolled', function() end) it('is triggered by scrolling vertically', function() - local lines = {'123', '123'} - meths.buf_set_lines(0, 0, -1, true, lines) + local lines = { '123', '123' } + api.nvim_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}, + 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}, + 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 width = api.nvim_win_get_width(0) local line = '123' .. ('*'):rep(width * 2) - local lines = {line, line} - meths.buf_set_lines(0, 0, -1, true, lines) + local lines = { line, line } + api.nvim_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}, + 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}, + 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}) + local lines = { '', '', 'Foo' } + api.nvim_buf_set_lines(0, 0, -1, true, lines) + api.nvim_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}, + 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}, + 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}, + 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}, + 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}) + local height = api.nvim_win_get_height(0) + local width = api.nvim_win_get_width(0) + api.nvim_buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) }) + api.nvim_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}, + 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}, + 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('$') @@ -168,12 +185,12 @@ describe('WinScrolled', function() end) it('is triggered when the window scrolls in Insert mode', function() - local height = meths.win_get_height(0) + local height = api.nvim_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) + api.nvim_buf_set_lines(0, 0, -1, true, lines) feed('M') eq(0, eval('g:scrolled')) @@ -181,15 +198,15 @@ describe('WinScrolled', function() 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}, + 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}, + 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 +215,8 @@ describe('WinScrolled', function() 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}, + 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) @@ -220,12 +237,12 @@ describe('WinScrolled', function() 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) + api.nvim_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) + api.nvim_input_mouse('wheel', 'down', '', 0, 6, 0) feed('<Esc>') eq(2, eval('g:scrolled')) end) @@ -257,30 +274,30 @@ describe('WinScrolled', function() 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}, + 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}, + 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}, + 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}, + 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) @@ -296,35 +313,41 @@ describe('WinScrolled', function() ]]) eq(0, eval('g:scrolled')) - local buf = meths.create_buf(true, true) - meths.buf_set_lines(buf, 0, -1, false, {'@', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'}) - local win = meths.open_win(buf, false, { + local buf = api.nvim_create_buf(true, true) + api.nvim_buf_set_lines( + buf, + 0, + -1, + false, + { '@', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' } + ) + local win = api.nvim_open_win(buf, false, { height = 5, width = 10, col = 0, row = 1, relative = 'editor', - style = 'minimal' + style = 'minimal', }) screen:expect({ any = '@' }) - local winid_str = tostring(win.id) + local winid_str = tostring(win) -- WinScrolled should not be triggered when creating a new floating window eq(0, eval('g:scrolled')) - meths.input_mouse('wheel', 'down', '', 0, 3, 3) + api.nvim_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}, + 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) + api.nvim_input_mouse('wheel', 'up', '', 0, 3, 3) eq(2, eval('g:scrolled')) - eq(tostring(win.id), eval('g:amatch')) + eq(tostring(win), 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}, + 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) |