blob: eb402539ffb265847783aaa8cf4a4361d6cd369f [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()
Bram Moolenaardea4a612021-12-04 22:03:34 +000029 let cwd = getcwd()
30 call test_autochdir()
Bram Moolenaar6f14da12022-09-07 21:30:44 +010031 call mkdir('Xa', 'R')
32 call mkdir('Xb', 'R')
33 call mkdir('Xc', 'R')
Bram Moolenaardea4a612021-12-04 22:03:34 +000034 try
35 args Xa/aaa.txt Xb/bbb.txt
36 set acd
37 let winid = win_getid()
38 snext
39 call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
40 call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt')
41 call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
42 finally
43 set noacd
44 call chdir(cwd)
Bram Moolenaardea4a612021-12-04 22:03:34 +000045 bwipe! aaa.txt
46 bwipe! bbb.txt
47 bwipe! ccc.txt
48 endtry
49endfunc
50
Bram Moolenaar90c317f2021-12-28 13:15:05 +000051func Test_acd_win_execute()
52 let cwd = getcwd()
53 set acd
54 call test_autochdir()
55
Bram Moolenaar6f14da12022-09-07 21:30:44 +010056 call mkdir('XacdDir', 'R')
Bram Moolenaar90c317f2021-12-28 13:15:05 +000057 let winid = win_getid()
Bram Moolenaare7cda972022-08-29 11:02:59 +010058 new XacdDir/file
59 call assert_match('testdir.XacdDir$', getcwd())
Bram Moolenaar90c317f2021-12-28 13:15:05 +000060 cd ..
61 call assert_match('testdir$', getcwd())
62 call win_execute(winid, 'echo')
63 call assert_match('testdir$', getcwd())
64
65 bwipe!
66 set noacd
67 call chdir(cwd)
Bram Moolenaar90c317f2021-12-28 13:15:05 +000068endfunc
69
Bram Moolenaar05268152021-11-18 18:53:45 +000070func Test_verbose_pwd()
71 let cwd = getcwd()
72 call test_autochdir()
73
74 edit global.txt
75 call assert_match('\[global\].*testdir$', execute('verbose pwd'))
76
Bram Moolenaar6f14da12022-09-07 21:30:44 +010077 call mkdir('Xautodir', 'R')
Bram Moolenaar05268152021-11-18 18:53:45 +000078 split Xautodir/local.txt
79 lcd Xautodir
80 call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
81
82 set acd
83 wincmd w
84 call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
zeertzjq64be6aa2021-11-19 11:59:08 +000085 execute 'tcd' cwd
86 call assert_match('\[tabpage\].*testdir$', execute('verbose pwd'))
87 execute 'cd' cwd
88 call assert_match('\[global\].*testdir$', execute('verbose pwd'))
zeertzjqb29ae152022-03-05 17:00:31 +000089 execute 'lcd' cwd
90 call assert_match('\[window\].*testdir$', execute('verbose pwd'))
zeertzjq64be6aa2021-11-19 11:59:08 +000091 edit
92 call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
zeertzjqb29ae152022-03-05 17:00:31 +000093 enew
94 wincmd w
95 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
96 wincmd w
97 call assert_match('\[window\].*testdir$', execute('verbose pwd'))
Bram Moolenaar05268152021-11-18 18:53:45 +000098 wincmd w
99 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
100 set noacd
101 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
102 wincmd w
zeertzjqb29ae152022-03-05 17:00:31 +0000103 call assert_match('\[window\].*testdir$', execute('verbose pwd'))
Bram Moolenaardea4a612021-12-04 22:03:34 +0000104 execute 'cd' cwd
zeertzjqb29ae152022-03-05 17:00:31 +0000105 call assert_match('\[global\].*testdir$', execute('verbose pwd'))
Bram Moolenaar05268152021-11-18 18:53:45 +0000106 wincmd w
107 call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
108
109 bwipe!
110 call chdir(cwd)
Bram Moolenaar05268152021-11-18 18:53:45 +0000111endfunc
112
Bram Moolenaar5921aeb2022-02-19 11:20:12 +0000113func Test_multibyte()
114 " using an invalid character should not cause a crash
115 set wic
Bram Moolenaaradbb3832022-02-19 14:49:51 +0000116 call assert_fails('tc û¦*', has('win32') ? 'E480:' : 'E344:')
Bram Moolenaar5921aeb2022-02-19 11:20:12 +0000117 set nowic
118endfunc
119
120
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200121" vim: shiftwidth=2 sts=2 expandtab