diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-10-17 10:26:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-17 10:26:11 -0400 |
commit | a1e8199fff098e158e22e25abc20c512575c1c53 (patch) | |
tree | 360b7b51a293eb4aafa8be7b7bcdd726bf34854b /test | |
parent | 77e6ecf85aa756ebca4548e4cfbc906bf8fff568 (diff) | |
parent | 38821cc50e7d353b7e8a372da8413e550595b734 (diff) | |
download | rneovim-a1e8199fff098e158e22e25abc20c512575c1c53.tar.gz rneovim-a1e8199fff098e158e22e25abc20c512575c1c53.tar.bz2 rneovim-a1e8199fff098e158e22e25abc20c512575c1c53.zip |
Merge pull request #15952 from zeertzjq/vim-8.1.1291
vim-patch:8.0.{1459,1460,1461,1463},8.1.{0602,0604,1291},8.2.{0189,0876,0909,1411}: chdir and DirChanged related patches
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/autocmd/dirchanged_spec.lua | 120 |
1 files changed, 106 insertions, 14 deletions
diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 6f2da24cf2..f4a1642ebf 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -6,6 +6,7 @@ local command = h.command local eq = h.eq local eval = h.eval local request = h.request +local iswin = h.iswin describe('autocmd DirChanged', function() local curdir = string.gsub(lfs.currentdir(), '\\', '/') @@ -14,6 +15,11 @@ describe('autocmd DirChanged', function() curdir .. '/Xtest-functional-autocmd-dirchanged.dir2', curdir .. '/Xtest-functional-autocmd-dirchanged.dir3', } + local win_dirs = { + curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR1', + curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR2', + curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR3', + } setup(function() for _, dir in pairs(dirs) do h.mkdir(dir) end end) teardown(function() for _, dir in pairs(dirs) do h.rmdir(dir) end end) @@ -27,17 +33,20 @@ describe('autocmd DirChanged', function() command([[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]]) end) - it('sets v:event', function() + it('sets v:event and <amatch>', function() command('lcd '..dirs[1]) eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + eq('window', eval('g:amatch')) eq(1, eval('g:cdcount')) command('tcd '..dirs[2]) - eq({cwd=dirs[2], scope='tab', changed_window=false}, eval('g:ev')) + eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev')) + eq('tabpage', eval('g:amatch')) eq(2, eval('g:cdcount')) command('cd '..dirs[3]) eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev')) + eq('global', eval('g:amatch')) eq(3, eval('g:cdcount')) end) @@ -63,17 +72,6 @@ describe('autocmd DirChanged', function() eq(dirs[3], eval('getcwd()')) end) - it('sets <amatch> to CWD "scope"', function() - command('lcd '..dirs[1]) - eq('window', eval('g:amatch')) - - command('tcd '..dirs[2]) - eq('tab', eval('g:amatch')) - - command('cd '..dirs[3]) - eq('global', eval('g:amatch')) - end) - it('does not trigger if :cd fails', function() command('let g:ev = {}') @@ -106,13 +104,79 @@ describe('autocmd DirChanged', function() command('split '..dirs[1]..'/foo') eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + eq('auto', eval('g:amatch')) command('split '..dirs[2]..'/bar') eq({cwd=dirs[2], scope='window', changed_window=false}, eval('g:ev')) + eq('auto', eval('g:amatch')) eq(2, eval('g:cdcount')) end) + it('does not trigger if directory has not changed', function() + command('lcd '..dirs[1]) + eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + eq('window', eval('g:amatch')) + eq(1, eval('g:cdcount')) + command('let g:ev = {}') + command('lcd '..dirs[1]) + eq({}, eval('g:ev')) + eq(1, eval('g:cdcount')) + + if iswin() then + command('lcd '..win_dirs[1]) + eq({}, eval('g:ev')) + eq(1, eval('g:cdcount')) + end + + command('tcd '..dirs[2]) + eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev')) + eq('tabpage', eval('g:amatch')) + eq(2, eval('g:cdcount')) + command('let g:ev = {}') + command('tcd '..dirs[2]) + eq({}, eval('g:ev')) + eq(2, eval('g:cdcount')) + + if iswin() then + command('tcd '..win_dirs[2]) + eq({}, eval('g:ev')) + eq(2, eval('g:cdcount')) + end + + command('cd '..dirs[3]) + eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev')) + eq('global', eval('g:amatch')) + eq(3, eval('g:cdcount')) + command('let g:ev = {}') + command('cd '..dirs[3]) + eq({}, eval('g:ev')) + eq(3, eval('g:cdcount')) + + if iswin() then + command('cd '..win_dirs[3]) + eq({}, eval('g:ev')) + eq(3, eval('g:cdcount')) + end + + command('set autochdir') + + command('split '..dirs[1]..'/foo') + eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev')) + eq('auto', eval('g:amatch')) + eq(4, eval('g:cdcount')) + command('let g:ev = {}') + command('split '..dirs[1]..'/bar') + eq({}, eval('g:ev')) + eq(4, eval('g:cdcount')) + + if iswin() then + command('split '..win_dirs[1]..'/baz') + eq({}, eval('g:ev')) + eq(4, eval('g:cdcount')) + end + end) + it("is triggered by switching to win/tab with different CWD #6054", function() command('lcd '..dirs[3]) -- window 3 command('split '..dirs[2]..'/foo') -- window 2 @@ -122,6 +186,7 @@ describe('autocmd DirChanged', function() command('2wincmd w') -- window 2 eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev')) + eq('window', eval('g:amatch')) eq(4, eval('g:cdcount')) command('tabnew') -- tab 2 (tab-local CWD) @@ -129,8 +194,10 @@ describe('autocmd DirChanged', function() command('tcd '..dirs[3]) command('tabnext') -- tab 1 (no tab-local CWD) eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev')) + eq('window', eval('g:amatch')) command('tabnext') -- tab 2 - eq({cwd=dirs[3], scope='tab', changed_window=true}, eval('g:ev')) + eq({cwd=dirs[3], scope='tabpage', changed_window=true}, eval('g:ev')) + eq('tabpage', eval('g:amatch')) eq(7, eval('g:cdcount')) command('tabnext') -- tab 1 @@ -138,6 +205,31 @@ describe('autocmd DirChanged', function() eq(9, eval('g:cdcount')) command('tabnext') -- tab 2 (has the *same* CWD) eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + + if iswin() then + command('tabnew') -- tab 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tcd '..win_dirs[3]) + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 1 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 2 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 1 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('lcd '..win_dirs[3]) -- window 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 2 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabnext') -- tab 1 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + command('tabprevious') -- tab 3 + eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event + end end) it('is triggered by nvim_set_current_dir()', function() |