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