blob: a9cb66b2cea8113b88cb1470ff3fb2da3a225b63 [file] [log] [blame]
Bram Moolenaar5c719942016-07-09 23:40:45 +02001" Test 'autochdir' behavior
2
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02003CheckOption autochdir
Bram Moolenaar5c719942016-07-09 23:40:45 +02004
5func Test_set_filename()
Bram Moolenaarcf1ba352017-10-27 00:55:04 +02006 let cwd = getcwd()
Bram Moolenaar5c719942016-07-09 23:40:45 +02007 call test_autochdir()
8 set acd
Bram Moolenaar2caad3f2018-12-16 15:38:02 +01009
10 let s:li = []
11 autocmd DirChanged auto call add(s:li, "autocd")
12 autocmd DirChanged auto call add(s:li, expand("<afile>"))
13
Bram Moolenaar5c719942016-07-09 23:40:45 +020014 new
15 w samples/Xtest
16 call assert_equal("Xtest", expand('%'))
17 call assert_equal("samples", substitute(getcwd(), '.*/\(\k*\)', '\1', ''))
Bram Moolenaar2caad3f2018-12-16 15:38:02 +010018 call assert_equal(["autocd", getcwd()], s:li)
19
Bram Moolenaar5c719942016-07-09 23:40:45 +020020 bwipe!
Bram Moolenaar2caad3f2018-12-16 15:38:02 +010021 au! DirChanged
Bram Moolenaar5c719942016-07-09 23:40:45 +020022 set noacd
Bram Moolenaar3503d7c2019-11-09 20:10:17 +010023 call chdir(cwd)
Bram Moolenaar5c719942016-07-09 23:40:45 +020024 call delete('samples/Xtest')
25endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020026
Bram Moolenaardea4a612021-12-04 22:03:34 +000027func Test_set_filename_other_window()
Bram Moolenaardea4a612021-12-04 22:03:34 +000028 let cwd = getcwd()
29 call test_autochdir()
Bram Moolenaar6f14da12022-09-07 21:30:44 +010030 call mkdir('Xa', 'R')
31 call mkdir('Xb', 'R')
32 call mkdir('Xc', 'R')
Bram Moolenaardea4a612021-12-04 22:03:34 +000033 try
34 args Xa/aaa.txt Xb/bbb.txt
35 set acd
36 let winid = win_getid()
37 snext
38 call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
39 call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt')
40 call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
41 finally
42 set noacd
43 call chdir(cwd)
Bram Moolenaardea4a612021-12-04 22:03:34 +000044 bwipe! aaa.txt
45 bwipe! bbb.txt
46 bwipe! ccc.txt
47 endtry
48endfunc
49
Bram Moolenaar90c317f2021-12-28 13:15:05 +000050func Test_acd_win_execute()
51 let cwd = getcwd()
52 set acd
53 call test_autochdir()
54
Bram Moolenaar6f14da12022-09-07 21:30:44 +010055 call mkdir('XacdDir', 'R')
Bram Moolenaar90c317f2021-12-28 13:15:05 +000056 let winid = win_getid()
Bram Moolenaare7cda972022-08-29 11:02:59 +010057 new XacdDir/file
58 call assert_match('testdir.XacdDir$', getcwd())
Bram Moolenaar90c317f2021-12-28 13:15:05 +000059 cd ..
60 call assert_match('testdir$', getcwd())
61 call win_execute(winid, 'echo')
62 call assert_match('testdir$', getcwd())
63
64 bwipe!
65 set noacd
66 call chdir(cwd)
Bram Moolenaar90c317f2021-12-28 13:15:05 +000067endfunc
68
Bram Moolenaar05268152021-11-18 18:53:45 +000069func Test_verbose_pwd()
70 let cwd = getcwd()
71 call test_autochdir()
72
73 edit global.txt
74 call assert_match('\[global\].*testdir$', execute('verbose pwd'))
75
Bram Moolenaar6f14da12022-09-07 21:30:44 +010076 call mkdir('Xautodir', 'R')
Bram Moolenaar05268152021-11-18 18:53:45 +000077 split Xautodir/local.txt
78 lcd Xautodir
79 call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
80
81 set acd
82 wincmd w
83 call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
zeertzjq64be6aa2021-11-19 11:59:08 +000084 execute 'tcd' cwd
85 call assert_match('\[tabpage\].*testdir$', execute('verbose pwd'))
86 execute 'cd' cwd
87 call assert_match('\[global\].*testdir$', execute('verbose pwd'))
zeertzjqb29ae152022-03-05 17:00:31 +000088 execute 'lcd' cwd
89 call assert_match('\[window\].*testdir$', execute('verbose pwd'))
zeertzjq64be6aa2021-11-19 11:59:08 +000090 edit
91 call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
zeertzjqb29ae152022-03-05 17:00:31 +000092 enew
93 wincmd w
94 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
95 wincmd w
96 call assert_match('\[window\].*testdir$', execute('verbose pwd'))
Bram Moolenaar05268152021-11-18 18:53:45 +000097 wincmd w
98 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
99 set noacd
100 call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
101 wincmd w
zeertzjqb29ae152022-03-05 17:00:31 +0000102 call assert_match('\[window\].*testdir$', execute('verbose pwd'))
Bram Moolenaardea4a612021-12-04 22:03:34 +0000103 execute 'cd' cwd
zeertzjqb29ae152022-03-05 17:00:31 +0000104 call assert_match('\[global\].*testdir$', execute('verbose pwd'))
Bram Moolenaar05268152021-11-18 18:53:45 +0000105 wincmd w
106 call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
107
108 bwipe!
109 call chdir(cwd)
Bram Moolenaar05268152021-11-18 18:53:45 +0000110endfunc
111
Bram Moolenaar5921aeb2022-02-19 11:20:12 +0000112func Test_multibyte()
113 " using an invalid character should not cause a crash
114 set wic
Bram Moolenaaradbb3832022-02-19 14:49:51 +0000115 call assert_fails('tc û¦*', has('win32') ? 'E480:' : 'E344:')
Bram Moolenaar5921aeb2022-02-19 11:20:12 +0000116 set nowic
117endfunc
118
119
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200120" vim: shiftwidth=2 sts=2 expandtab