robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Tests for 'directory' option. 2-- - ".", in same dir as file 3-- - "./dir", in directory relative to file 4-- - "dir", in directory relative to current dir 5 6local t =require ( 'test.testutil' ) 7local n =require ( 'test.functional.testnvim' )() 8 9local describe , it , setup , teardown =t . describe , t . it , t . setup , t . teardown 10local eq =t . eq 11local neq =t . neq 12local poke_eventloop =n . poke_eventloop 13local fn =n . fn 14local api =n . api 15local clear =n . clear 16local insert =n . insert 17local command =n . command 18local write_file =t . write_file 19local mkdir =t . mkdir 20 21local function ls_dir_sorted ( dirname ) 22local files ={} 23for f in vim . fs . dir ( dirname ) do 24if f ~= '.' and f ~= '..' then 25table . insert ( files , f ) 26end 27end 28table . sort ( files ) 29return files 30end 31 32describe ( "'directory' option" , function () 33setup ( function () 34local text =[[ 35start of testfile 36line 2 Abcdefghij 37line 3 Abcdefghij 38end of testfile 39]] 40write_file ( 'Xtest1' , text ) 41mkdir ( 'Xtest.je' ) 42mkdir ( 'Xtest2' ) 43write_file ( 'Xtest2/Xtest3' , text ) 44clear () 45end ) 46teardown ( function () 47command ( '%bwipe!' ) 48api . nvim_set_option_value ( 'swapfile' , false , {} ) 49api . nvim_set_option_value ( 'directory' , '.' , {} ) 50n . rmdir ( 'Xtest.je' ) 51n . rmdir ( 'Xtest2' ) 52os . remove ( 'Xtest1' ) 53end ) 54 55it ( 'is working' , function () 56insert ( [[ 57start of testfile 58line 2 Abcdefghij 59line 3 Abcdefghij 60end of testfile]] ) 61 62api . nvim_set_option_value ( 'swapfile' , true , {} ) 63api . nvim_set_option_value ( 'directory' , '.' , {} ) 64 65-- sanity check: files should not exist yet. 66eq ( nil , vim . uv . fs_stat ( '.Xtest1.swp' )) 67 68command ( 'edit! Xtest1' ) 69poke_eventloop () 70eq ( 'Xtest1' , fn . buffer_name ( '%' )) 71-- Verify that the swapfile exists. In the legacy test this was done by 72-- reading the output from :!ls. 73neq ( nil , vim . uv . fs_stat ( '.Xtest1.swp' )) 74 75api . nvim_set_option_value ( 'directory' , './Xtest2,.' , {} ) 76command ( 'edit Xtest1' ) 77poke_eventloop () 78 79-- swapfile should no longer exist in CWD. 80eq ( nil , vim . uv . fs_stat ( '.Xtest1.swp' )) 81 82eq ( { 'Xtest1.swp' , 'Xtest3' } , ls_dir_sorted ( 'Xtest2' )) 83 84api . nvim_set_option_value ( 'directory' , 'Xtest.je' , {} ) 85command ( 'bdelete' ) 86command ( 'edit Xtest2/Xtest3' ) 87eq ( true , api . nvim_get_option_value ( 'swapfile' , {} )) 88poke_eventloop () 89 90eq ( { 'Xtest3' } , ls_dir_sorted ( 'Xtest2' )) 91eq ( { 'Xtest3.swp' } , ls_dir_sorted ( 'Xtest.je' )) 92end ) 93end )