Mercurial > vim
comparison src/testdir/test_cd.vim @ 16576:bcc343175103 v8.1.1291
patch 8.1.1291: not easy to change directory and restore
commit https://github.com/vim/vim/commit/1063f3d2008f22d02ccfa9dab83a23db52febbdc
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 7 22:06:52 2019 +0200
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 https://github.com/vim/vim/issues/4358)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 07 May 2019 22:15:05 +0200 |
parents | a1d21fc6e457 |
children | f71ee7b04f0b |
comparison
equal
deleted
inserted
replaced
16575:e0baba49b677 | 16576:bcc343175103 |
---|---|
1 " Test for :cd | 1 " Test for :cd and chdir() |
2 | 2 |
3 func Test_cd_large_path() | 3 func Test_cd_large_path() |
4 " This used to crash with a heap write overflow. | 4 " This used to crash with a heap write overflow. |
5 call assert_fails('cd ' . repeat('x', 5000), 'E472:') | 5 call assert_fails('cd ' . repeat('x', 5000), 'E472:') |
6 endfunc | 6 endfunc |
63 | 63 |
64 call delete('Xfoo') | 64 call delete('Xfoo') |
65 set cpo& | 65 set cpo& |
66 bw! | 66 bw! |
67 endfunc | 67 endfunc |
68 | |
69 " Test for chdir() | |
70 func Test_chdir_func() | |
71 let topdir = getcwd() | |
72 call mkdir('Xdir/y/z', 'p') | |
73 | |
74 " Create a few tabpages and windows with different directories | |
75 new | |
76 cd Xdir | |
77 tabnew | |
78 tcd y | |
79 below new | |
80 below new | |
81 lcd z | |
82 | |
83 tabfirst | |
84 call chdir('..') | |
85 call assert_equal('y', fnamemodify(getcwd(1, 2), ':t')) | |
86 call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) | |
87 tabnext | wincmd t | |
88 call chdir('..') | |
89 call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t')) | |
90 call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t')) | |
91 call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) | |
92 call assert_equal('testdir', fnamemodify(getcwd(1, 1), ':t')) | |
93 3wincmd w | |
94 call chdir('..') | |
95 call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t')) | |
96 call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t')) | |
97 call assert_equal('y', fnamemodify(getcwd(3, 2), ':t')) | |
98 call assert_equal('testdir', fnamemodify(getcwd(1, 1), ':t')) | |
99 | |
100 " Error case | |
101 call assert_fails("call chdir('dir-abcd')", 'E472:') | |
102 silent! let d = chdir("dir_abcd") | |
103 call assert_equal("", d) | |
104 | |
105 only | tabonly | |
106 exe 'cd ' . topdir | |
107 call delete('Xdir', 'rf') | |
108 endfunc |