diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-05-07 22:06:52 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-05-07 22:06:52 +0200 |
commit | 1063f3d2008f22d02ccfa9dab83a23db52febbdc (patch) | |
tree | ed4a5e7fddc01bdf2abb1d0d7931010c724d4ac5 /src/testdir/test_cd.vim | |
parent | fd31e45e4bccd7070d02e4d20bcab1f45b271600 (diff) | |
download | vim-git-1063f3d2008f22d02ccfa9dab83a23db52febbdc.tar.gz |
patch 8.1.1291: not easy to change directory and restorev8.1.1291
Problem: Not easy to change directory and restore.
Solution: Add the chdir() function. (Yegappan Lakshmanan, closes #4358)
Diffstat (limited to 'src/testdir/test_cd.vim')
-rw-r--r-- | src/testdir/test_cd.vim | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/testdir/test_cd.vim b/src/testdir/test_cd.vim index c63f0060f..31859542e 100644 --- a/src/testdir/test_cd.vim +++ b/src/testdir/test_cd.vim @@ -1,4 +1,4 @@ -" Test for :cd +" Test for :cd and chdir() func Test_cd_large_path() " This used to crash with a heap write overflow. @@ -65,3 +65,44 @@ func Test_cd_with_cpo_chdir() set cpo& 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 |