robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #23119 from zeertzjq/vim-9.0.03700d9b0fbe57

master
3.2 KiB125 linesraw
1" Test 'autochdir' behavior
2
3source check.vim
4CheckOption autochdir
5
6func Test_set_filename()
7  CheckFunction test_autochdir
8  let cwd = getcwd()
9  call test_autochdir()
10  set acd
11
12  let s:li = []
13  autocmd DirChanged auto call add(s:li, "autocd")
14  autocmd DirChanged auto call add(s:li, expand("<afile>"))
15
16  new
17  w samples/Xtest
18  call assert_equal("Xtest", expand('%'))
19  call assert_equal("samples", substitute(getcwd(), '.*/\(\k*\)', '\1', ''))
20  call assert_equal(["autocd", getcwd()], s:li)
21
22  bwipe!
23  au! DirChanged
24  set noacd
25  call chdir(cwd)
26  call delete('samples/Xtest')
27endfunc
28
29func Test_set_filename_other_window()
30  CheckFunction test_autochdir
31  let cwd = getcwd()
32  call test_autochdir()
33  call mkdir('Xa', 'R')
34  call mkdir('Xb', 'R')
35  call mkdir('Xc', 'R')
36  try
37    args Xa/aaa.txt Xb/bbb.txt
38    set acd
39    let winid = win_getid()
40    snext
41    call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
42    call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt')
43    call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
44  finally
45    set noacd
46    call chdir(cwd)
47    bwipe! aaa.txt
48    bwipe! bbb.txt
49    bwipe! ccc.txt
50  endtry
51endfunc
52
53func Test_acd_win_execute()
54  CheckFunction test_autochdir
55  let cwd = getcwd()
56  set acd
57  call test_autochdir()
58
59  call mkdir('XacdDir', 'R')
60  let winid = win_getid()
61  new XacdDir/file
62  call assert_match('testdir.XacdDir$', getcwd())
63  cd ..
64  call assert_match('testdir$', getcwd())
65  call win_execute(winid, 'echo')
66  call assert_match('testdir$', getcwd())
67
68  bwipe!
69  set noacd
70  call chdir(cwd)
71endfunc
72
73func Test_verbose_pwd()
74  CheckFunction test_autochdir
75  let cwd = getcwd()
76  call test_autochdir()
77
78  edit global.txt
79  call assert_match('\[global\].*testdir$', execute('verbose pwd'))
80
81  call mkdir('Xautodir', 'R')
82  split Xautodir/local.txt
83  lcd Xautodir
84  call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
85
86  set acd
87  wincmd w
88  call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
89  execute 'tcd' cwd
90  call assert_match('\[tabpage\].*testdir$', execute('verbose pwd'))
91  execute 'cd' cwd
92  call assert_match('\[global\].*testdir$', execute('verbose pwd'))
93  execute 'lcd' cwd
94  call assert_match('\[window\].*testdir$', execute('verbose pwd'))
95  edit
96  call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
97  enew
98  wincmd w
99  call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
100  wincmd w
101  call assert_match('\[window\].*testdir$', execute('verbose pwd'))
102  wincmd w
103  call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
104  set noacd
105  call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
106  wincmd w
107  call assert_match('\[window\].*testdir$', execute('verbose pwd'))
108  execute 'cd' cwd
109  call assert_match('\[global\].*testdir$', execute('verbose pwd'))
110  wincmd w
111  call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
112
113  bwipe!
114  call chdir(cwd)
115endfunc
116
117func Test_multibyte()
118  " using an invalid character should not cause a crash
119  set wic
120  call assert_fails('tc �����*', has('win32') ? 'E480:' : 'E344:')
121  set nowic
122endfunc
123
124
125" vim: shiftwidth=2 sts=2 expandtab