robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each , after_each =t . describe , t . it , t . before_each , t . after_each 5local clear , eq , matches =n . clear , t . eq , t . matches 6local eval , command , call , api =n . eval , n . command , n . call , n . api 7local source , exec_capture =n . source , n . exec_capture 8local mkdir =t . mkdir 9 10local function expected_empty () 11eq ( {} , api . nvim_get_vvar ( 'errors' )) 12end 13 14describe ( 'autochdir behavior' , function () 15local dir ='Xtest_functional_legacy_autochdir' 16 17before_each ( function () 18mkdir ( dir ) 19clear () 20command ( 'set shellslash' ) 21end ) 22 23after_each ( function () 24n . rmdir ( dir ) 25end ) 26 27-- Tests vim/vim#777 without test_autochdir(). 28it ( 'sets filename' , function () 29command ( 'set acd' ) 30command ( 'new' ) 31command ( 'w ' .. dir .. '/Xtest' ) 32eq ( 'Xtest' , eval ( "expand('%')" )) 33eq ( dir , eval ( [[substitute(getcwd(), '.*/\(\k*\)', '\1', '')]] )) 34end ) 35 36-- oldtest: Test_set_filename_other_window() 37it ( ':file in win_execute() does not cause wrong directory' , function () 38command ( 'cd ' .. dir ) 39source ( [[ 40func Test_set_filename_other_window() 41let cwd = getcwd() 42call mkdir('Xa') 43call mkdir('Xb') 44call mkdir('Xc') 45try 46args Xa/aaa.txt Xb/bbb.txt 47set acd 48let winid = win_getid() 49snext 50call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', '')) 51call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt') 52call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', '')) 53finally 54set noacd 55call chdir(cwd) 56call delete('Xa', 'rf') 57call delete('Xb', 'rf') 58call delete('Xc', 'rf') 59bwipe! aaa.txt 60bwipe! bbb.txt 61bwipe! ccc.txt 62endtry 63endfunc 64]] ) 65call ( 'Test_set_filename_other_window' ) 66expected_empty () 67end ) 68 69-- oldtest: Test_acd_win_execute() 70it ( 'win_execute() does not change directory' , function () 71local subdir ='Xfile' 72command ( 'cd ' .. dir ) 73command ( 'set acd' ) 74call ( 'mkdir' , subdir ) 75local winid =eval ( 'win_getid()' ) 76command ( 'new ' .. subdir .. '/file' ) 77matches ( dir .. '/' .. subdir .. '$' , eval ( 'getcwd()' )) 78command ( 'cd ..' ) 79matches ( dir .. '$' , eval ( 'getcwd()' )) 80call ( 'win_execute' , winid , 'echo' ) 81matches ( dir .. '$' , eval ( 'getcwd()' )) 82end ) 83 84-- oldtest: Test_verbose_pwd() 85it ( ':verbose pwd shows whether autochdir is used' , function () 86local subdir ='Xautodir' 87command ( 'cd ' .. dir ) 88local cwd =eval ( 'getcwd()' ) 89command ( 'edit global.txt' ) 90matches ( '%[global%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 91call ( 'mkdir' , subdir ) 92command ( 'split ' .. subdir .. '/local.txt' ) 93command ( 'lcd ' .. subdir ) 94matches ( '%[window%].*' .. dir .. '/' .. subdir .. '$' , exec_capture ( 'verbose pwd' )) 95command ( 'set acd' ) 96command ( 'wincmd w' ) 97matches ( '%[autochdir%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 98command ( 'tcd ' .. cwd ) 99matches ( '%[tabpage%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 100command ( 'cd ' .. cwd ) 101matches ( '%[global%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 102command ( 'lcd ' .. cwd ) 103matches ( '%[window%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 104command ( 'edit' ) 105matches ( '%[autochdir%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 106command ( 'enew' ) 107command ( 'wincmd w' ) 108matches ( '%[autochdir%].*' .. dir .. '/' .. subdir .. '$' , exec_capture ( 'verbose pwd' )) 109command ( 'wincmd w' ) 110matches ( '%[window%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 111command ( 'wincmd w' ) 112matches ( '%[autochdir%].*' .. dir .. '/' .. subdir .. '$' , exec_capture ( 'verbose pwd' )) 113command ( 'set noacd' ) 114matches ( '%[autochdir%].*' .. dir .. '/' .. subdir .. '$' , exec_capture ( 'verbose pwd' )) 115command ( 'wincmd w' ) 116matches ( '%[window%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 117command ( 'cd ' .. cwd ) 118matches ( '%[global%].*' .. dir .. '$' , exec_capture ( 'verbose pwd' )) 119command ( 'wincmd w' ) 120matches ( '%[window%].*' .. dir .. '/' .. subdir .. '$' , exec_capture ( 'verbose pwd' )) 121end ) 122 123it ( 'overriding via :lcd is not clobbered by win_execute()' , function () 124command ( 'cd ' .. dir ) 125source ( [[ 126func Test_lcd_win_execute() 127let startdir = getcwd() 128call mkdir('Xsubdir', 'R') 129set autochdir 130edit Xsubdir/file 131call assert_match('_autochdir.Xsubdir.file$', expand('%:p')) 132split 133lcd .. 134call assert_match('_autochdir.Xsubdir.file$', expand('%:p')) 135call win_execute(win_getid(2), "") 136call assert_match('_autochdir.Xsubdir.file$', expand('%:p')) 137 138set noautochdir 139bwipe! 140call chdir(startdir) 141endfunc 142]] ) 143call ( 'Test_lcd_win_execute' ) 144expected_empty () 145end ) 146end )