robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.1.0465: missing filecopy() function (#29989)28fbba2092

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