robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
b296666e41
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it =t . describe , t . it 5local clear =n . clear 6local eq =t . eq 7local fn =n . fn 8local command =n . command 9local api =n . api 10local mkdir =t . mkdir 11 12describe ( "'autochdir'" , function () 13it ( 'given on the shell gets processed properly' , function () 14local start_dir =vim . uv . cwd () 15local target_dir =t . paths . test_source_path .. '/test/functional/fixtures' 16 17-- By default 'autochdir' is off, thus getcwd() returns the initial directory. 18clear ( target_dir .. '/tty-test.c' ) 19eq ( start_dir , fn . getcwd ()) 20 21-- With 'autochdir' on, we should get the directory of tty-test.c. 22clear ( '--cmd' , 'set autochdir' , target_dir .. '/tty-test.c' ) 23eq ( t . is_os ( 'win' ) and target_dir : gsub ( '/' , '\\' ) or target_dir , fn . getcwd ()) 24end ) 25 26it ( 'is not overwritten by getwinvar() call #17609' , function () 27local curdir =t . fix_slashes ( vim . uv . cwd ()) 28local dir_a =curdir .. '/Xtest-functional-options-autochdir.dir_a' 29local dir_b =curdir .. '/Xtest-functional-options-autochdir.dir_b' 30mkdir ( dir_a ) 31mkdir ( dir_b ) 32clear () 33command ( 'set shellslash' ) 34command ( 'set autochdir' ) 35command ( 'edit ' .. dir_a .. '/file1' ) 36eq ( dir_a , fn . getcwd ()) 37command ( 'lcd ' .. dir_b ) 38eq ( dir_b , fn . getcwd ()) 39command ( 'botright vnew ../file2' ) 40eq ( curdir , fn . getcwd ()) 41command ( 'wincmd w' ) 42eq ( dir_a , fn . getcwd ()) 43fn . getwinvar ( 2 , 'foo' ) 44eq ( dir_a , fn . getcwd ()) 45n . rmdir ( dir_a ) 46n . rmdir ( dir_b ) 47end ) 48 49it ( 'win_execute() keeps buffer names #41417' , function () 50local root =vim . fs . normalize ( t . tmpname ( false )) 51mkdir ( root ) 52mkdir ( root .. '/a' ) 53mkdir ( root .. '/b' ) 54clear () 55command ( 'set shellslash' ) 56command ( 'edit ' .. root .. '/a/file_a' ) 57command ( 'vsplit ' .. root .. '/b/file_b' ) 58local win_b , buf_b =api . nvim_get_current_win (), api . nvim_get_current_buf () 59command ( 'wincmd p' ) 60command ( 'set autochdir' ) 61-- Sit in an ancestor of both files: 'autochdir' moves away from it during win_execute(), and 62-- both buffer names stay shortened, i.e. relative to the CWD. 63command ( 'cd ' .. root ) 64eq ( { 'a/file_a' , 'b/file_b' } , { fn . bufname ( '%' ), fn . bufname ( buf_b ) } ) 65 66fn . win_execute ( win_b , 'echo' ) 67 68eq ( { 'a/file_a' , 'b/file_b' } , { fn . bufname ( '%' ), fn . bufname ( buf_b ) } ) 69end ) 70end )