robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.unit.testutil' ) 2local describe , before_each =t . describe , t . before_each 3local itp =t . gen_itp ( t . it ) 4 5local eq =t . eq 6local neq =t . neq 7local cimport =t . cimport 8local child_call_once =t . child_call_once 9local child_cleanup_once =t . child_cleanup_once 10 11local lib =cimport ( './src/nvim/os/os.h' , './src/nvim/fileio.h' ) 12 13describe ( 'tempfile related functions' , function () 14before_each ( function () 15local function vim_deltempdir () 16lib . vim_deltempdir () 17end 18child_call_once ( vim_deltempdir ) 19child_cleanup_once ( vim_deltempdir ) 20end ) 21 22local vim_gettempdir =function () 23return t . ffi . string ( lib . vim_gettempdir ()) 24end 25 26describe ( 'vim_gettempdir' , function () 27itp ( 'returns path to Nvim own temp directory' , function () 28local dir =vim_gettempdir () 29t . ok ( dir ~= nil and dir : len () > 0 ) 30-- os_file_is_writable returns 2 for a directory which we have rights 31-- to write into. 32eq ( 2 , lib . os_file_is_writable ( t . to_cstr ( dir ))) 33for entry in vim . fs . dir ( dir ) do 34t . ok ( entry == '.' or entry == '..' ) 35end 36end ) 37 38itp ( 'returns the same directory on each call' , function () 39eq ( vim_gettempdir (), vim_gettempdir ()) 40end ) 41end ) 42 43describe ( 'vim_tempname' , function () 44local vim_tempname =function () 45return t . ffi . string ( lib . vim_tempname ()) 46end 47 48itp ( 'generate name of non-existing file' , function () 49local file =vim_tempname () 50assert ( file ) 51assert ( not lib . os_path_exists ( file )) 52end ) 53 54itp ( 'generate different names on each call' , function () 55neq ( vim_tempname (), vim_tempname ()) 56end ) 57 58itp ( 'generate file name in Nvim own temp directory' , function () 59local dir =vim_gettempdir () 60local file =vim_tempname () 61eq ( dir , string . sub ( file , 1 , string . len ( dir ))) 62end ) 63end ) 64end )