|
8 | 8 | func Test_cd_up_and_down() |
9 | 9 | let path = getcwd() |
10 | 10 | cd .. |
| 11 | + call assert_notequal(path, getcwd()) |
11 | 12 | exe 'cd ' . path |
12 | 13 | call assert_equal(path, getcwd()) |
13 | 14 | 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 |
0 commit comments