blob: e7a688567631f06c54d7834f2960bbcb7d49e262 [file] [log] [blame]
Bram Moolenaar5c719942016-07-09 23:40:45 +02001" Test 'autochdir' behavior
2
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02003source check.vim
4CheckOption autochdir
Bram Moolenaar5c719942016-07-09 23:40:45 +02005
6func Test_set_filename()
Bram Moolenaarcf1ba352017-10-27 00:55:04 +02007 let cwd = getcwd()
Bram Moolenaar5c719942016-07-09 23:40:45 +02008 call test_autochdir()
9 set acd
Bram Moolenaar2caad3f2018-12-16 15:38:02 +010010
11 let s:li = []
12 autocmd DirChanged auto call add(s:li, "autocd")
13 autocmd DirChanged auto call add(s:li, expand("<afile>"))
14
Bram Moolenaar5c719942016-07-09 23:40:45 +020015 new
16 w samples/Xtest
17 call assert_equal("Xtest", expand('%'))
18 call assert_equal("samples", substitute(getcwd(), '.*/\(\k*\)', '\1', ''))
Bram Moolenaar2caad3f2018-12-16 15:38:02 +010019 call assert_equal(["autocd", getcwd()], s:li)
20
Bram Moolenaar5c719942016-07-09 23:40:45 +020021 bwipe!
Bram Moolenaar2caad3f2018-12-16 15:38:02 +010022 au! DirChanged
Bram Moolenaar5c719942016-07-09 23:40:45 +020023 set noacd
Bram Moolenaar3503d7c2019-11-09 20:10:17 +010024 call chdir(cwd)
Bram Moolenaar5c719942016-07-09 23:40:45 +020025 call delete('samples/Xtest')
26endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020027
Bram Moolenaardea4a612021-12-04 22:03:34 +000028func Test_set_filename_other_window()
29 call ch_logfile('logfile', 'w')
30 let cwd = getcwd()
31 call test_autochdir()
32 call mkdir('Xa')
33 call mkdir('Xb')
34 call mkdir('Xc')
35 try
36 args Xa/aaa.txt Xb/bbb.txt
37 set acd
38 let winid = win_getid()
39 snext
40 call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
41 call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt')
42 call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
43 finally
44 set noacd
45 call chdir(cwd)
Bram Moolenaardea4a612021-12-04 22:03:34 +000046 bwipe! aaa.txt
47 bwipe! bbb.txt
48 bwipe! ccc.txt
Dominique Pellef589fd32021-12-05 12:39:21 +000049 call delete('Xa', 'rf')
50 call delete('Xb', 'rf')
51 call delete('Xc', 'rf')
Bram Moolenaardea4a612021-12-04 22:03:34 +000052 endtry
53endfunc
54
Bram Moolenaar05268152021-11-18 18:53:45 +000055func Test_verbose_pwd()
56 let cwd = getcwd()
57 call test_autochdir()
58
59 edit global.txt
60 call assert_match('\[global\].*testdir$', execute('verbose pwd'))
61
62 call mkdir('Xautodir')
63 split Xautodir/local.txt
64 lcd Xautodir
65 call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
66
67 set acd
68 wincmd w
69 call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
zeertzjq64be6aa2021-11-19 11:59:08 +000070 execute 'lcd' cwd
71 call assert_match('\[window\].*testdir$', execute('verbose pwd'))
72 execute 'tcd' cwd
73 call assert_match('\[tabpage\].*testdir$', execute('verbose pwd'))
74 execute 'cd' cwd
75 call assert_match('\[global\].*testdir$', execute('verbose pwd'))
76 edit
77 call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
Bram Moolenaar05268152021-11-18 18:53:45 +000078 wincmd w
79 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
80 set noacd
81 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
82 wincmd w
Bram Moolenaardea4a612021-12-04 22:03:34 +000083 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
84 execute 'cd' cwd
Bram Moolenaar05268152021-11-18 18:53:45 +000085 call assert_match('\[global\].*testdir', execute('verbose pwd'))
86 wincmd w
87 call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
88
89 bwipe!
90 call chdir(cwd)
91 call delete('Xautodir', 'rf')
92endfunc
93
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020094" vim: shiftwidth=2 sts=2 expandtab