1" Tests for stat functions and checktime 2 3func Test_existent_file() 4 let fname = 'Xtest.tmp' 5 6 let ts = localtime() 7 let fl = ['Hello World!'] 8 call writefile(fl, fname) 9 let tf = getftime(fname) 10 let te = localtime() 11 12 call assert_true(ts <= tf && tf <= te) 13 call assert_equal(strlen(fl[0] . "\n"), getfsize(fname)) 14 call assert_equal('file', getftype(fname)) 15 call assert_equal('rw-', getfperm(fname)[0:2]) 16 17 call delete(fname) 18endfunc 19 20func Test_existent_directory() 21 let dname = '.' 22 23 call assert_equal(0, getfsize(dname)) 24 call assert_equal('dir', getftype(dname)) 25 call assert_equal('rwx', getfperm(dname)[0:2]) 26endfunc 27 28func Test_checktime() 29 let fname = 'Xtest.tmp' 30 31 let fl = ['Hello World!'] 32 call writefile(fl, fname) 33 set autoread 34 exec 'e' fname 35 " FAT has a granularity of 2 seconds, otherwise it's usually 1 second 36 if has('win32') 37 sleep 2 38 else 39 sleep 1 40 endif 41 let fl = readfile(fname) 42 let fl[0] .= ' - checktime' 43 call writefile(fl, fname) 44 checktime 45 call assert_equal(fl[0], getline(1)) 46 47 call delete(fname) 48endfunc 49 50func Test_nonexistent_file() 51 let fname = 'Xtest.tmp' 52 53 call delete(fname) 54 call assert_equal(-1, getftime(fname)) 55 call assert_equal(-1, getfsize(fname)) 56 call assert_equal('', getftype(fname)) 57 call assert_equal('', getfperm(fname)) 58endfunc 59 60func Test_win32_symlink_dir() 61 " On Windows, non-admin users cannot create symlinks. 62 " So we use an existing symlink for this test. 63 if has('win32') 64 " Check if 'C:\Users\All Users' is a symlink to a directory. 65 let res = system('dir C:\Users /a') 66 if match(res, '\C<SYMLINKD> *All Users') >= 0 67 " Get the filetype of the symlink. 68 call assert_equal('dir', getftype('C:\Users\All Users')) 69 endif 70 endif 71endfunc 72