xref: /vim-8.2.3635/src/testdir/test_cd.vim (revision 01a6c216)
1" Test for :cd
2
3func Test_cd_large_path()
4  " This used to crash with a heap write overflow.
5  call assert_fails('cd ' . repeat('x', 5000), 'E472:')
6endfunc
7
8func Test_cd_up_and_down()
9  let path = getcwd()
10  cd ..
11  call assert_notequal(path, getcwd())
12  exe 'cd ' . path
13  call assert_equal(path, getcwd())
14endfunc
15
16func 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
29endfunc
30
31func 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())
43endfunc
44
45func 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!
67endfunc
68