summaryrefslogtreecommitdiffstats
path: root/src/testdir
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2024-06-03 22:59:27 +0200
committerChristian Brabandt <cb@256bit.org>2024-06-03 23:01:40 +0200
commit60c8743ab6c90e402e6ed49d27455ef7e5698abe (patch)
tree441cc398a542d10a60cd9c1dd7862ebcf0f1353e /src/testdir
parent0a0830624a260660c7fa692ecb7e6e5de09114ba (diff)
patch 9.1.0465: missing filecopy() functionv9.1.0465
Problem: missing filecopy() function Solution: implement filecopy() Vim script function (Shougo Matsushita) closes: #12346 Co-authored-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/testdir')
-rw-r--r--src/testdir/Make_all.mak2
-rw-r--r--src/testdir/test_filecopy.vim72
2 files changed, 74 insertions, 0 deletions
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index a80b1300e5..e31d2b5f3e 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -143,6 +143,7 @@ NEW_TESTS = \
test_file_perm \
test_file_size \
test_filechanged \
+ test_filecopy \
test_fileformat \
test_filetype \
test_filter_cmd \
@@ -404,6 +405,7 @@ NEW_TESTS_RES = \
test_expr.res \
test_file_size.res \
test_filechanged.res \
+ test_filecopy.res \
test_fileformat.res \
test_filetype.res \
test_filter_cmd.res \
diff --git a/src/testdir/test_filecopy.vim b/src/testdir/test_filecopy.vim
new file mode 100644
index 0000000000..b526dce7b8
--- /dev/null
+++ b/src/testdir/test_filecopy.vim
@@ -0,0 +1,72 @@
+" Test filecopy()
+
+source check.vim
+source shared.vim
+
+func Test_copy_file_to_file()
+ call writefile(['foo'], 'Xcopy1')
+
+ call assert_true(filecopy('Xcopy1', 'Xcopy2'))
+
+ call assert_equal(['foo'], readfile('Xcopy2'))
+
+ " When the destination file already exists, it should not be overwritten.
+ call writefile(['foo'], 'Xcopy1')
+ call writefile(['bar'], 'Xcopy2', 'D')
+ call assert_false(filecopy('Xcopy1', 'Xcopy2'))
+ call assert_equal(['bar'], readfile('Xcopy2'))
+
+ call delete('Xcopy2')
+ call delete('Xcopy1')
+endfunc
+
+func Test_copy_symbolic_link()
+ CheckUnix
+
+ call writefile(['text'], 'Xtestfile', 'D')
+ silent !ln -s -f Xtestfile Xtestlink
+
+ call assert_true(filecopy('Xtestlink', 'Xtestlink2'))
+ call assert_equal('link', getftype('Xtestlink2'))
+ call assert_equal(['text'], readfile('Xtestlink2'))
+
+ " When the destination file already exists, it should not be overwritten.
+ call assert_false(filecopy('Xtestlink', 'Xtestlink2'))
+
+ call delete('Xtestlink2')
+ call delete('Xtestlink')
+ call delete('Xtestfile')
+endfunc
+
+func Test_copy_dir_to_dir()
+ call mkdir('Xcopydir1')
+ call writefile(['foo'], 'Xcopydir1/Xfilecopy')
+ call mkdir('Xcopydir2')
+
+ " Directory copy is not supported
+ call assert_false(filecopy('Xcopydir1', 'Xcopydir2'))
+
+ call delete('Xcopydir2', 'rf')
+ call delete('Xcopydir1', 'rf')
+endfunc
+
+func Test_copy_fails()
+ CheckUnix
+
+ call writefile(['foo'], 'Xfilecopy', 'D')
+
+ " Can't copy into a non-existing directory.
+ call assert_false(filecopy('Xfilecopy', 'Xdoesnotexist/Xfilecopy'))
+
+ " Can't copy a non-existing file.
+ call assert_false(filecopy('Xdoesnotexist', 'Xfilecopy2'))
+ call assert_equal('', glob('Xfilecopy2'))
+
+ " Can't copy to en empty file name.
+ call assert_false(filecopy('Xfilecopy', ''))
+
+ call assert_fails('call filecopy("Xfilecopy", [])', 'E1174:')
+ call assert_fails('call filecopy(0z, "Xfilecopy")', 'E1174:')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab