robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
28fbba2092
master
1" Test filecopy() 2 3source check.vim 4source shared.vim 5 6func Test_copy_file_to_file () 7call writefile ([ 'foo' ], 'Xcopy1' ) 8 9call assert_true ( filecopy ( 'Xcopy1' , 'Xcopy2' )) 10 11call assert_equal ([ 'foo' ], readfile ( 'Xcopy2' )) 12 13" When the destination file already exists, it should not be overwritten. 14call writefile ([ 'foo' ], 'Xcopy1' ) 15call writefile ([ 'bar' ], 'Xcopy2' , 'D' ) 16call assert_false ( filecopy ( 'Xcopy1' , 'Xcopy2' )) 17call assert_equal ([ 'bar' ], readfile ( 'Xcopy2' )) 18 19call delete ( 'Xcopy2' ) 20call delete ( 'Xcopy1' ) 21endfunc 22 23func Test_copy_symbolic_link () 24CheckUnix 25 26call writefile ([ 'text' ], 'Xtestfile' , 'D' ) 27silent !ln -s -fXtestfile Xtestlink 28 29call assert_true ( filecopy ( 'Xtestlink' , 'Xtestlink2' )) 30call assert_equal ( 'link' , getftype ( 'Xtestlink2' )) 31call assert_equal ([ 'text' ], readfile ( 'Xtestlink2' )) 32 33" When the destination file already exists, it should not be overwritten. 34call assert_false ( filecopy ( 'Xtestlink' , 'Xtestlink2' )) 35 36call delete ( 'Xtestlink2' ) 37call delete ( 'Xtestlink' ) 38call delete ( 'Xtestfile' ) 39endfunc 40 41func Test_copy_dir_to_dir () 42call mkdir ( 'Xcopydir1' ) 43call writefile ([ 'foo' ], 'Xcopydir1/Xfilecopy' ) 44call mkdir ( 'Xcopydir2' ) 45 46" Directory copy is not supported 47call assert_false ( filecopy ( 'Xcopydir1' , 'Xcopydir2' )) 48 49call delete ( 'Xcopydir2' , 'rf' ) 50call delete ( 'Xcopydir1' , 'rf' ) 51endfunc 52 53func Test_copy_fails () 54CheckUnix 55 56call writefile ([ 'foo' ], 'Xfilecopy' , 'D' ) 57 58" Can't copy into a non-existing directory. 59call assert_false ( filecopy ( 'Xfilecopy' , 'Xdoesnotexist/Xfilecopy' )) 60 61" Can't copy a non-existing file. 62call assert_false ( filecopy ( 'Xdoesnotexist' , 'Xfilecopy2' )) 63call assert_equal ( '' , glob ( 'Xfilecopy2' )) 64 65" Can't copy to en empty file name. 66call assert_false ( filecopy ( 'Xfilecopy' , '' )) 67 68call assert_fails ( 'call filecopy("Xfilecopy", [])' , 'E1174:' ) 69call assert_fails ( 'call filecopy(0z, "Xfilecopy")' , 'E1174:' ) 70endfunc 71 72" vim: shiftwidth=2 sts=2 expandtab