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/test_cd.vim') 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_cd.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/testdir/test_cd.vim') 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 -- 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/test_cd.vim') 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/test_cd.vim') 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/test_cd.vim') 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/test_cd.vim') 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