Skip to content

Commit b2e0c94

Browse files
committed
patch 8.1.0144: the :cd command does not have good test coverage
Problem: The :cd command does not have good test coverage. Solution: Add more tests. (Dominique Pelle, closes #2972)
1 parent 3d1d647 commit b2e0c94

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/testdir/test_cd.vim

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,60 @@ endfunc
88
func Test_cd_up_and_down()
99
let path = getcwd()
1010
cd ..
11+
call assert_notequal(path, getcwd())
1112
exe 'cd ' . path
1213
call assert_equal(path, getcwd())
1314
endfunc
15+
16+
func Test_cd_no_arg()
17+
if has('unix')
18+
" Test that cd without argument goes to $HOME directory on Unix systems.
19+
let path = getcwd()
20+
cd
21+
call assert_equal($HOME, getcwd())
22+
call assert_notequal(path, getcwd())
23+
exe 'cd ' . path
24+
call assert_equal(path, getcwd())
25+
else
26+
" Test that cd without argument echoes cwd on non-Unix systems.
27+
call assert_match(getcwd(), execute('cd'))
28+
endif
29+
endfunc
30+
31+
func Test_cd_minus()
32+
" Test the :cd - goes back to the previous directory.
33+
let path = getcwd()
34+
cd ..
35+
let path_dotdot = getcwd()
36+
call assert_notequal(path, path_dotdot)
37+
cd -
38+
call assert_equal(path, getcwd())
39+
cd -
40+
call assert_equal(path_dotdot, getcwd())
41+
cd -
42+
call assert_equal(path, getcwd())
43+
endfunc
44+
45+
func Test_cd_with_cpo_chdir()
46+
e Xfoo
47+
call setline(1, 'foo')
48+
let path = getcwd()
49+
set cpo+=.
50+
51+
" :cd should fail when buffer is modified and 'cpo' contains dot.
52+
call assert_fails('cd ..', 'E747:')
53+
call assert_equal(path, getcwd())
54+
55+
" :cd with exclamation mark should succeed.
56+
cd! ..
57+
call assert_notequal(path, getcwd())
58+
59+
" :cd should succeed when buffer has been written.
60+
w!
61+
exe 'cd ' . path
62+
call assert_equal(path, getcwd())
63+
64+
call delete('Xfoo')
65+
set cpo&
66+
bw!
67+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ static char *(features[]) =
789789

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
144,
792794
/**/
793795
143,
794796
/**/

0 commit comments

Comments
 (0)