summaryrefslogtreecommitdiff
path: root/src/testdir/test_writefile.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-01-29 21:57:34 +0100
committerBram Moolenaar <Bram@vim.org>2020-01-29 21:57:34 +0100
commit5d98dc2a48156d44139b75c689bd3137ff7fe8bf (patch)
tree0622310d475027658462943b1b9a9c85fc3ec48e /src/testdir/test_writefile.vim
parent0ff6aad393c4130818fb4f49137380f78d7cc882 (diff)
downloadvim-git-5d98dc2a48156d44139b75c689bd3137ff7fe8bf.tar.gz
patch 8.2.0174: various commands not completely testedv8.2.0174
Problem: Various commands not completely tested. Solution: Add more test cases. (Yegappan Lakshmanan, closes #5551)
Diffstat (limited to 'src/testdir/test_writefile.vim')
-rw-r--r--src/testdir/test_writefile.vim65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/testdir/test_writefile.vim b/src/testdir/test_writefile.vim
index 8eb2e7809..db17e6f9b 100644
--- a/src/testdir/test_writefile.vim
+++ b/src/testdir/test_writefile.vim
@@ -179,3 +179,68 @@ func Test_writefile_autowrite_nowrite()
bwipe!
set noautowrite
endfunc
+
+" Test for ':w !<cmd>' to pipe lines from the current buffer to an external
+" command.
+func Test_write_pipe_to_cmd()
+ if !has('unix')
+ return
+ endif
+ new
+ call setline(1, ['L1', 'L2', 'L3', 'L4'])
+ 2,3w !cat > Xfile
+ call assert_equal(['L2', 'L3'], readfile('Xfile'))
+ close!
+ call delete('Xfile')
+endfunc
+
+" Test for :saveas
+func Test_saveas()
+ call assert_fails('saveas', 'E471:')
+ call writefile(['L1'], 'Xfile')
+ new Xfile
+ new
+ call setline(1, ['L1'])
+ call assert_fails('saveas Xfile', 'E139:')
+ close!
+ enew | only
+ call delete('Xfile')
+endfunc
+
+func Test_write_errors()
+ " Test for writing partial buffer
+ call writefile(['L1', 'L2', 'L3'], 'Xfile')
+ new Xfile
+ call assert_fails('1,2write', 'E140:')
+ close!
+
+ " Try to overwrite a directory
+ if has('unix')
+ call mkdir('Xdir1')
+ call assert_fails('write Xdir1', 'E17:')
+ call delete('Xdir1', 'd')
+ endif
+
+ " Test for :wall for a buffer with no name
+ enew | only
+ call setline(1, ['L1'])
+ call assert_fails('wall', 'E141:')
+ enew!
+
+ " Test for writing a 'readonly' file
+ new Xfile
+ set readonly
+ call assert_fails('write', 'E45:')
+ close
+
+ " Test for writing to a read-only file
+ new Xfile
+ call setfperm('Xfile', 'r--r--r--')
+ call assert_fails('write', 'E505:')
+ call setfperm('Xfile', 'rw-rw-rw-')
+ close
+
+ call delete('Xfile')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab