diff src/testdir/test_writefile.vim @ 14642:96858d612aff v8.1.0334

patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written commit https://github.com/vim/vim/commit/8c9e7b00f6566dc41e794ef11c93d93b034c7134 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 30 13:07:17 2018 +0200 patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written Problem: 'autowrite' takes effect when buffer is not to be written. Solution: Don't write buffers that are not supposed to be written. (Even Q Jones, closes #3391) Add tests for 'autowrite'.
author Christian Brabandt <cb@256bit.org>
date Thu, 30 Aug 2018 13:15:06 +0200
parents d6553cde1292
children 63d5ae57a663
line wrap: on
line diff
--- a/src/testdir/test_writefile.vim
+++ b/src/testdir/test_writefile.vim
@@ -112,3 +112,41 @@ func Test_writefile_sync_dev_stdout()
     throw 'Skipped: /dev/stdout is not writable'
   endif
 endfunc
+
+func Test_writefile_autowrite()
+  set autowrite
+  new
+  next Xa Xb Xc
+  call setline(1, 'aaa')
+  next
+  call assert_equal(['aaa'], readfile('Xa'))
+  call setline(1, 'bbb')
+  call assert_fails('edit XX')
+  call assert_false(filereadable('Xb'))
+
+  set autowriteall
+  edit XX
+  call assert_equal(['bbb'], readfile('Xb'))
+
+  bwipe!
+  call delete('Xa')
+  call delete('Xb')
+  set noautowrite
+endfunc
+
+func Test_writefile_autowrite_nowrite()
+  set autowrite
+  new
+  next Xa Xb Xc
+  set buftype=nowrite
+  call setline(1, 'aaa')
+  let buf = bufnr('%')
+  " buffer contents silently lost
+  edit XX
+  call assert_false(filereadable('Xa'))
+  rewind
+  call assert_equal('', getline(1))
+
+  bwipe!
+  set noautowrite
+endfunc