From 920473d2f228fb33c63c092c825b182a7434f25f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: vim-patch:8.0.1459: cannot handle change of directory Problem: Cannot handle change of directory. Solution: Add the DirChanged autocommand event. (Andy Massimino, closes vim/vim#888) Avoid changing directory for 'autochdir' too often. https://github.com/vim/vim/commit/b7407d3fc9496f9048fb65ab17b5ba3444965c0e Only add "auto" pattern. "window" and "global" are already implemented. Skip `Test_dirchanged_auto` using `CheckFunction test_autochdir`. Part of PR #15952. More information can be found there. N/A patches for version.c: vim-patch:8.0.1460: missing file in patch Problem: Missing file in patch. Solution: Add changes to missing file. https://github.com/vim/vim/commit/b5cb65ba2bcc6bbc6d2798a2dea18b95f0b38f5e vim-patch:8.0.1461: missing another file in patch Problem: Missing another file in patch. Solution: Add changes to missing file. https://github.com/vim/vim/commit/15833239a4131279935a4bd574b74fe3a2b0f49f --- src/nvim/testdir/test_autocmd.vim | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 015979e1be..d174b11a9c 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1328,6 +1328,62 @@ func Test_autocommand_all_events() call assert_fails('au * x bwipe', 'E1155:') endfunc +function s:Before_test_dirchanged() + augroup test_dirchanged + autocmd! + augroup END + let s:li = [] + let s:dir_this = getcwd() + let s:dir_other = s:dir_this . '/foo' + call mkdir(s:dir_other) +endfunc + +function s:After_test_dirchanged() + exe 'cd' s:dir_this + call delete(s:dir_other, 'd') + augroup test_dirchanged + autocmd! + augroup END +endfunc + +function Test_dirchanged_global() + call s:Before_test_dirchanged() + autocmd test_dirchanged DirChanged global call add(s:li, "cd:") + autocmd test_dirchanged DirChanged global call add(s:li, expand("")) + exe 'cd' s:dir_other + call assert_equal(["cd:", s:dir_other], s:li) + exe 'lcd' s:dir_other + call assert_equal(["cd:", s:dir_other], s:li) + call s:After_test_dirchanged() +endfunc + +function Test_dirchanged_local() + call s:Before_test_dirchanged() + autocmd test_dirchanged DirChanged window call add(s:li, "lcd:") + autocmd test_dirchanged DirChanged window call add(s:li, expand("")) + exe 'cd' s:dir_other + call assert_equal([], s:li) + exe 'lcd' s:dir_other + call assert_equal(["lcd:", s:dir_other], s:li) + call s:After_test_dirchanged() +endfunc + +function Test_dirchanged_auto() + call s:Before_test_dirchanged() + call test_autochdir() + autocmd test_dirchanged DirChanged auto call add(s:li, "auto:") + autocmd test_dirchanged DirChanged auto call add(s:li, expand("")) + set acd + exe 'cd ..' + call assert_equal([], s:li) + exe 'edit ' . s:dir_other . '/Xfile' + call assert_equal(s:dir_other, getcwd()) + call assert_equal(["auto:", s:dir_other], s:li) + set noacd + bwipe! + call s:After_test_dirchanged() +endfunc + " Test TextChangedI and TextChangedP " See test/functional/viml/completion_spec.lua' func Test_ChangedP() -- cgit From eed89d5e0c3bd6870e6e9959ccfdbf99549dce6b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: vim-patch:8.0.1463: test fails without 'autochdir' option Problem: Test fails without 'autochdir' option. Solution: Skip test if 'autochdir' is not supported. https://github.com/vim/vim/commit/ec48a9c58989babcad23d73483955f35b6e41492 --- src/nvim/testdir/test_autocmd.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index d174b11a9c..a2ed3ae677 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1369,6 +1369,9 @@ function Test_dirchanged_local() endfunc function Test_dirchanged_auto() + if !exists('+autochdir') + return + endif call s:Before_test_dirchanged() call test_autochdir() autocmd test_dirchanged DirChanged auto call add(s:li, "auto:") -- cgit From e91dee5c21ffca22ac821336ad23bce6339b5f7c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: vim-patch:8.1.0602: DirChanged is also triggered when directory didn't change Problem: DirChanged is also triggered when the directory didn't change. (Daniel Hahler) Solution: Compare the current with the new directory. (closes vim/vim#3697) https://github.com/vim/vim/commit/2caad3fbbdbf1486a176c9f6bfbc3d9be90e09f7 --- src/nvim/testdir/test_autochdir.vim | 8 ++++++++ src/nvim/testdir/test_autocmd.vim | 33 ++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 13 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autochdir.vim b/src/nvim/testdir/test_autochdir.vim index d071f4b325..3d1ba084c6 100644 --- a/src/nvim/testdir/test_autochdir.vim +++ b/src/nvim/testdir/test_autochdir.vim @@ -8,11 +8,19 @@ func Test_set_filename() let cwd = getcwd() call test_autochdir() set acd + + let s:li = [] + autocmd DirChanged auto call add(s:li, "autocd") + autocmd DirChanged auto call add(s:li, expand("")) + new w samples/Xtest call assert_equal("Xtest", expand('%')) call assert_equal("samples", substitute(getcwd(), '.*/\(\k*\)', '\1', '')) + call assert_equal(["autocd", getcwd()], s:li) + bwipe! + au! DirChanged set noacd exe 'cd ' . cwd call delete('samples/Xtest') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index a2ed3ae677..93083f55c7 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1334,13 +1334,16 @@ function s:Before_test_dirchanged() augroup END let s:li = [] let s:dir_this = getcwd() - let s:dir_other = s:dir_this . '/foo' - call mkdir(s:dir_other) + let s:dir_foo = s:dir_this . '/foo' + call mkdir(s:dir_foo) + let s:dir_bar = s:dir_this . '/bar' + call mkdir(s:dir_bar) endfunc function s:After_test_dirchanged() exe 'cd' s:dir_this - call delete(s:dir_other, 'd') + call delete(s:dir_foo, 'd') + call delete(s:dir_bar, 'd') augroup test_dirchanged autocmd! augroup END @@ -1350,10 +1353,12 @@ function Test_dirchanged_global() call s:Before_test_dirchanged() autocmd test_dirchanged DirChanged global call add(s:li, "cd:") autocmd test_dirchanged DirChanged global call add(s:li, expand("")) - exe 'cd' s:dir_other - call assert_equal(["cd:", s:dir_other], s:li) - exe 'lcd' s:dir_other - call assert_equal(["cd:", s:dir_other], s:li) + exe 'cd' s:dir_foo + call assert_equal(["cd:", s:dir_foo], s:li) + exe 'cd' s:dir_foo + call assert_equal(["cd:", s:dir_foo], s:li) + exe 'lcd' s:dir_bar + call assert_equal(["cd:", s:dir_foo], s:li) call s:After_test_dirchanged() endfunc @@ -1361,10 +1366,12 @@ function Test_dirchanged_local() call s:Before_test_dirchanged() autocmd test_dirchanged DirChanged window call add(s:li, "lcd:") autocmd test_dirchanged DirChanged window call add(s:li, expand("")) - exe 'cd' s:dir_other + exe 'cd' s:dir_foo call assert_equal([], s:li) - exe 'lcd' s:dir_other - call assert_equal(["lcd:", s:dir_other], s:li) + exe 'lcd' s:dir_bar + call assert_equal(["lcd:", s:dir_bar], s:li) + exe 'lcd' s:dir_bar + call assert_equal(["lcd:", s:dir_bar], s:li) call s:After_test_dirchanged() endfunc @@ -1379,9 +1386,9 @@ function Test_dirchanged_auto() set acd exe 'cd ..' call assert_equal([], s:li) - exe 'edit ' . s:dir_other . '/Xfile' - call assert_equal(s:dir_other, getcwd()) - call assert_equal(["auto:", s:dir_other], s:li) + exe 'edit ' . s:dir_foo . '/Xfile' + call assert_equal(s:dir_foo, getcwd()) + call assert_equal(["auto:", s:dir_foo], s:li) set noacd bwipe! call s:After_test_dirchanged() -- cgit From 8727d38012f3c4c54380d554e2a8c53e8c50ad0d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: vim-patch:8.1.1291: not easy to change directory and restore Problem: Not easy to change directory and restore. Solution: Add the chdir() function. (Yegappan Lakshmanan, closes vim/vim#4358) https://github.com/vim/vim/commit/1063f3d2008f22d02ccfa9dab83a23db52febbdc Also includes some documentation changes from patch 8.1.1218. --- src/nvim/testdir/test_cd.vim | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index 02a23bf82f..7500c35563 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -69,6 +69,47 @@ func Test_cd_with_cpo_chdir() bw! endfunc +" Test for chdir() +func Test_chdir_func() + let topdir = getcwd() + call mkdir('Xdir/y/z', 'p') + + " Create a few tabpages and windows with different directories + new + cd Xdir + tabnew + tcd y + below new + below new + lcd z + + tabfirst + call chdir('..') + call assert_equal('y', fnamemodify(getcwd(1, 2), ':t')) + call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) + tabnext | wincmd t + call chdir('..') + call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t')) + call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t')) + call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) + call assert_equal('testdir', fnamemodify(getcwd(1, 1), ':t')) + 3wincmd w + call chdir('..') + call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t')) + call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t')) + call assert_equal('y', fnamemodify(getcwd(3, 2), ':t')) + call assert_equal('testdir', fnamemodify(getcwd(1, 1), ':t')) + + " Error case + call assert_fails("call chdir('dir-abcd')", 'E472:') + silent! let d = chdir("dir_abcd") + call assert_equal("", d) + + only | tabonly + exe 'cd ' . topdir + call delete('Xdir', 'rf') +endfunc + func Test_cd_from_non_existing_dir() CheckNotMSWindows -- cgit From 8a2489d0a43f6fe0bfd21840293610c44c88dcff Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: test: partially port Vim patches 8.1.2278 and 8.2.1432 --- src/nvim/testdir/test_autochdir.vim | 2 +- src/nvim/testdir/test_autocmd.vim | 33 ++++++++++++++------------------- src/nvim/testdir/test_cd.vim | 8 ++++---- src/nvim/testdir/test_find_complete.vim | 8 ++++---- src/nvim/testdir/test_findfile.vim | 4 ++-- src/nvim/testdir/test_getcwd.vim | 2 +- 6 files changed, 26 insertions(+), 31 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autochdir.vim b/src/nvim/testdir/test_autochdir.vim index 3d1ba084c6..0b76828dd7 100644 --- a/src/nvim/testdir/test_autochdir.vim +++ b/src/nvim/testdir/test_autochdir.vim @@ -22,7 +22,7 @@ func Test_set_filename() bwipe! au! DirChanged set noacd - exe 'cd ' . cwd + call chdir(cwd) call delete('samples/Xtest') endfunc diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 93083f55c7..c350a17236 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -42,9 +42,7 @@ if has('timers') endfunc func Test_cursorhold_insert_with_timer_interrupt() - if !has('job') - return - endif + CheckFeature job " Need to move the cursor. call feedkeys("ggG", "xt") @@ -551,9 +549,7 @@ endfunc func Test_OptionSet() CheckFunction test_override - if !has("eval") || !exists("+autochdir") - return - endif + CheckOption autochdir call test_override('starting', 1) set nocp @@ -1334,14 +1330,14 @@ function s:Before_test_dirchanged() augroup END let s:li = [] let s:dir_this = getcwd() - let s:dir_foo = s:dir_this . '/foo' + let s:dir_foo = s:dir_this . '/Xfoo' call mkdir(s:dir_foo) - let s:dir_bar = s:dir_this . '/bar' + let s:dir_bar = s:dir_this . '/Xbar' call mkdir(s:dir_bar) endfunc function s:After_test_dirchanged() - exe 'cd' s:dir_this + call chdir(s:dir_this) call delete(s:dir_foo, 'd') call delete(s:dir_bar, 'd') augroup test_dirchanged @@ -1353,11 +1349,11 @@ function Test_dirchanged_global() call s:Before_test_dirchanged() autocmd test_dirchanged DirChanged global call add(s:li, "cd:") autocmd test_dirchanged DirChanged global call add(s:li, expand("")) - exe 'cd' s:dir_foo + call chdir(s:dir_foo) call assert_equal(["cd:", s:dir_foo], s:li) - exe 'cd' s:dir_foo + call chdir(s:dir_foo) call assert_equal(["cd:", s:dir_foo], s:li) - exe 'lcd' s:dir_bar + exe 'lcd ' .. fnameescape(s:dir_bar) call assert_equal(["cd:", s:dir_foo], s:li) call s:After_test_dirchanged() endfunc @@ -1366,25 +1362,24 @@ function Test_dirchanged_local() call s:Before_test_dirchanged() autocmd test_dirchanged DirChanged window call add(s:li, "lcd:") autocmd test_dirchanged DirChanged window call add(s:li, expand("")) - exe 'cd' s:dir_foo + call chdir(s:dir_foo) call assert_equal([], s:li) - exe 'lcd' s:dir_bar + exe 'lcd ' .. fnameescape(s:dir_bar) call assert_equal(["lcd:", s:dir_bar], s:li) - exe 'lcd' s:dir_bar + exe 'lcd ' .. fnameescape(s:dir_bar) call assert_equal(["lcd:", s:dir_bar], s:li) call s:After_test_dirchanged() endfunc function Test_dirchanged_auto() - if !exists('+autochdir') - return - endif + CheckFunction test_autochdir + CheckOption autochdir call s:Before_test_dirchanged() call test_autochdir() autocmd test_dirchanged DirChanged auto call add(s:li, "auto:") autocmd test_dirchanged DirChanged auto call add(s:li, expand("")) set acd - exe 'cd ..' + cd .. call assert_equal([], s:li) exe 'edit ' . s:dir_foo . '/Xfile' call assert_equal(s:dir_foo, getcwd()) diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index 7500c35563..96c67bd7fc 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -12,7 +12,7 @@ func Test_cd_up_and_down() let path = getcwd() cd .. call assert_notequal(path, getcwd()) - exe 'cd ' . path + exe 'cd ' .. fnameescape(path) call assert_equal(path, getcwd()) endfunc @@ -23,7 +23,7 @@ func Test_cd_no_arg() cd call assert_equal($HOME, getcwd()) call assert_notequal(path, getcwd()) - exe 'cd ' . path + exe 'cd ' .. fnameescape(path) call assert_equal(path, getcwd()) else " Test that cd without argument echoes cwd on non-Unix systems. @@ -61,7 +61,7 @@ func Test_cd_with_cpo_chdir() " :cd should succeed when buffer has been written. w! - exe 'cd ' . path + exe 'cd ' .. fnameescape(path) call assert_equal(path, getcwd()) call delete('Xfoo') @@ -106,7 +106,7 @@ func Test_chdir_func() call assert_equal("", d) only | tabonly - exe 'cd ' . topdir + call chdir(topdir) call delete('Xdir', 'rf') endfunc diff --git a/src/nvim/testdir/test_find_complete.vim b/src/nvim/testdir/test_find_complete.vim index 0a00d9432f..32ca9672ef 100644 --- a/src/nvim/testdir/test_find_complete.vim +++ b/src/nvim/testdir/test_find_complete.vim @@ -36,7 +36,7 @@ func Test_find_complete() " We shouldn't find any file till this point call mkdir('in/path', 'p') - exe 'cd ' . cwd + call chdir(cwd) call writefile(['Holy Grail'], 'Xfind/file.txt') call writefile(['Jimmy Hoffa'], 'Xfind/in/file.txt') call writefile(['Another Holy Grail'], 'Xfind/in/stuff.txt') @@ -133,12 +133,12 @@ func Test_find_complete() call assert_equal('Voyager 2', getline(1)) " Check for correct handling of shorten_fname()'s behavior on windows - exec "cd " . cwd . "/Xfind/in" + call chdir(cwd .. "/Xfind/in") call feedkeys(":find file\t\n", "xt") call assert_equal('Jimmy Hoffa', getline(1)) " Test for relative to current buffer 'path' item - exec "cd " . cwd . "/Xfind/" + call chdir(cwd . "/Xfind/") set path=./path " Open the file where Jimmy Hoffa is found e in/file.txt @@ -157,7 +157,7 @@ func Test_find_complete() call assert_equal('Another Holy Grail', getline(1)) enew | only - exe 'cd ' . cwd + call chdir(cwd) call delete('Xfind', 'rf') set path& endfunc diff --git a/src/nvim/testdir/test_findfile.vim b/src/nvim/testdir/test_findfile.vim index d92706dbe5..5a20475d3d 100644 --- a/src/nvim/testdir/test_findfile.vim +++ b/src/nvim/testdir/test_findfile.vim @@ -113,7 +113,7 @@ func Test_findfile() call assert_match('.*/Xdir1/bar', findfile('bar', '**;', 2)) bwipe! - exe 'cd ' . save_dir + call chdir(save_dir) call CleanFiles() let &path = save_path let &shellslash = save_shellslash @@ -171,7 +171,7 @@ func Test_finddir() call assert_match('.*/Xdir1/Xdir2', finddir('Xdir2', '**;', 2)) call assert_equal('Xdir3', finddir('Xdir3', '**;', 1)) - exe 'cd ' . save_dir + call chdir(save_dir) call CleanFiles() let &path = save_path let &shellslash = save_shellslash diff --git a/src/nvim/testdir/test_getcwd.vim b/src/nvim/testdir/test_getcwd.vim index 2ff396b641..a75583cd2c 100644 --- a/src/nvim/testdir/test_getcwd.vim +++ b/src/nvim/testdir/test_getcwd.vim @@ -46,7 +46,7 @@ endfunction let g:cwd=getcwd() function TearDown() q - exec "cd " . g:cwd + call chdir(g:cwd) call delete("Xtopdir", "rf") endfunction -- cgit From b1dd90c760cd87f6c5c0c7c66bd0cc61c69319c3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: vim-patch:8.2.0189: cd() with NULL argument crashes Problem: cd() with NULL argument crashes. Solution: Check for NULL. (Ken Takata, closes vim/vim#5558) https://github.com/vim/vim/commit/7cc96923c44bbcc541cbd211b6308d87a965f0c3 --- src/nvim/testdir/test_cd.vim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index 96c67bd7fc..0421c1d6ff 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -104,6 +104,8 @@ func Test_chdir_func() call assert_fails("call chdir('dir-abcd')", 'E472:') silent! let d = chdir("dir_abcd") call assert_equal("", d) + " Should not crash + call chdir(d) only | tabonly call chdir(topdir) -- cgit From 34cfe745681189bbd8ec2543971a49e013bfebf9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: vim-patch:8.2.0876: :pwd does not give a hint about the scope of the directory Problem: :pwd does not give a hint about the scope of the directory Solution: Make ":verbose pwd" show the scope. (Takuya Fujiwara, closes vim/vim#5469) https://github.com/vim/vim/commit/950587242cad52d067a15f0f0c83528a28f75731 --- src/nvim/testdir/test_cd.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index 0421c1d6ff..c6eda58284 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -84,16 +84,19 @@ func Test_chdir_func() lcd z tabfirst + call assert_match('^\[global\] .*/Xdir$', trim(execute('verbose pwd'))) call chdir('..') call assert_equal('y', fnamemodify(getcwd(1, 2), ':t')) call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) tabnext | wincmd t + call assert_match('^\[tabpage\] .*/y$', trim(execute('verbose pwd'))) call chdir('..') call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t')) call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t')) call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) call assert_equal('testdir', fnamemodify(getcwd(1, 1), ':t')) 3wincmd w + call assert_match('^\[window\] .*/z$', trim(execute('verbose pwd'))) call chdir('..') call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t')) call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t')) -- cgit From 60584c0245a55d72422686aa702132814145b0c1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: vim-patch:8.2.0909: cannot go back to the previous local directory Problem: Cannot go back to the previous local directory. Solution: Add "tcd -" and "lcd -". (Yegappan Lakshmanan, closes vim/vim#4362) https://github.com/vim/vim/commit/002bc79991286934a9593b80635c27d4238cdfc4 --- src/nvim/testdir/test_cd.vim | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index c6eda58284..36135b52ce 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -43,6 +43,20 @@ func Test_cd_minus() call assert_equal(path_dotdot, getcwd()) cd - call assert_equal(path, getcwd()) + + " Test for :cd - without a previous directory + let lines =<< trim [SCRIPT] + call assert_fails('cd -', 'E186:') + call assert_fails('call chdir("-")', 'E186:') + call writefile(v:errors, 'Xresult') + qall! + [SCRIPT] + call writefile(lines, 'Xscript') + if RunVim([], [], '--clean -S Xscript') + call assert_equal([], readfile('Xresult')) + endif + call delete('Xscript') + call delete('Xresult') endfunc func Test_cd_with_cpo_chdir() @@ -115,6 +129,69 @@ func Test_chdir_func() call delete('Xdir', 'rf') endfunc +" Test for changing to the previous directory '-' +func Test_prev_dir() + let topdir = getcwd() + call mkdir('Xdir/a/b/c', 'p') + + " Create a few tabpages and windows with different directories + new | only + tabnew | new + tabnew + tabfirst + cd Xdir + tabnext | wincmd t + tcd a + wincmd w + lcd b + tabnext + tcd a/b/c + + " Change to the previous directory twice in all the windows. + tabfirst + cd - | cd - + tabnext | wincmd t + tcd - | tcd - + wincmd w + lcd - | lcd - + tabnext + tcd - | tcd - + + " Check the directory of all the windows + tabfirst + call assert_equal('Xdir', fnamemodify(getcwd(), ':t')) + tabnext | wincmd t + call assert_equal('a', fnamemodify(getcwd(), ':t')) + wincmd w + call assert_equal('b', fnamemodify(getcwd(), ':t')) + tabnext + call assert_equal('c', fnamemodify(getcwd(), ':t')) + + " Change to the previous directory using chdir() + tabfirst + call chdir("-") | call chdir("-") + tabnext | wincmd t + call chdir("-") | call chdir("-") + wincmd w + call chdir("-") | call chdir("-") + tabnext + call chdir("-") | call chdir("-") + + " Check the directory of all the windows + tabfirst + call assert_equal('Xdir', fnamemodify(getcwd(), ':t')) + tabnext | wincmd t + call assert_equal('a', fnamemodify(getcwd(), ':t')) + wincmd w + call assert_equal('b', fnamemodify(getcwd(), ':t')) + tabnext + call assert_equal('c', fnamemodify(getcwd(), ':t')) + + only | tabonly + call chdir(topdir) + call delete('Xdir', 'rf') +endfunc + func Test_cd_from_non_existing_dir() CheckNotMSWindows -- cgit From 36290a2ebd3d49fa43f90fbdbf32e0cbe4f76d87 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Oct 2021 22:04:53 +0800 Subject: vim-patch:8.2.1411: when splitting a window localdir is copied but prevdir is not Problem: when splitting a window localdir is copied but prevdir is not. Solution: Also copy prevdir. (closes vim/vim#6667) https://github.com/vim/vim/commit/a9a47d157ab1946d1e286c9695bc68d71305af68 --- src/nvim/testdir/test_cd.vim | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index 36135b52ce..0bba321ee2 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -192,6 +192,15 @@ func Test_prev_dir() call delete('Xdir', 'rf') endfunc +func Test_lcd_split() + let curdir = getcwd() + lcd .. + split + lcd - + call assert_equal(curdir, getcwd()) + quit! +endfunc + func Test_cd_from_non_existing_dir() CheckNotMSWindows -- cgit