diff src/testdir/test_autocmd.vim @ 12662:15f0f9f16cd9 v8.0.1209

patch 8.0.1209: still too many old style tests commit https://github.com/vim/vim/commit/53f0c962394dc6bc66d5b0762af9434e672d1b25 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Oct 22 14:23:59 2017 +0200 patch 8.0.1209: still too many old style tests Problem: Still too many old style tests. Solution: Convert a few more tests to new style. (Yegappan Lakshmanan, closes #2230)
author Christian Brabandt <cb@256bit.org>
date Sun, 22 Oct 2017 14:30:07 +0200
parents 0a9dacb8826a
children 429bf1b9292f
line wrap: on
line diff
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -773,6 +773,7 @@ func Test_BufLeave_Wipe()
 
   call delete('Xxx1')
   call delete('Xxx2')
+  call delete('test.out')
   %bwipe
   au! BufLeave
 
@@ -809,9 +810,93 @@ func Test_Cmdline()
   au! CmdlineLeave / let g:left = expand('<afile>')
   let g:entered = 0
   let g:left = 0
-  call feedkeys("/hello<CR>", 'xt')
+  new
+  call setline(1, 'hello')
+  call feedkeys("/hello\<CR>", 'xt')
   call assert_equal('/', g:entered)
   call assert_equal('/', g:left)
+  bwipe!
   au! CmdlineEnter
   au! CmdlineLeave
 endfunc
+
+" Test for BufWritePre autocommand that deletes or unloads the buffer.
+func Test_BufWritePre()
+  %bwipe
+  au BufWritePre Xxx1 bunload
+  au BufWritePre Xxx2 bwipe
+
+  call writefile(['start of Xxx1', 'test', 'end of Xxx1'], 'Xxx1')
+  call writefile(['start of Xxx2', 'test', 'end of Xxx2'], 'Xxx2')
+
+  edit Xtest
+  e! Xxx2
+  bdel Xtest
+  e Xxx1
+  " write it, will unload it and give an error msg
+  call assert_fails('w', 'E203')
+  call assert_equal('Xxx2', bufname('%'))
+  edit Xtest
+  e! Xxx2
+  bwipe Xtest
+  " write it, will delete the buffer and give an error msg
+  call assert_fails('w', 'E203')
+  call assert_equal('Xxx1', bufname('%'))
+  au! BufWritePre
+  call delete('Xxx1')
+  call delete('Xxx2')
+endfunc
+
+" Test for BufUnload autocommand that unloads all the other buffers
+func Test_bufunload_all()
+  call writefile(['Test file Xxx1'], 'Xxx1')"
+  call writefile(['Test file Xxx2'], 'Xxx2')"
+
+  let content = [
+	      \ "func UnloadAllBufs()",
+	      \ "  let i = 1",
+	      \ "  while i <= bufnr('$')",
+	      \ "    if i != bufnr('%') && bufloaded(i)",
+	      \ "      exe  i . 'bunload'",
+	      \ "    endif",
+	      \ "    let i += 1",
+	      \ "  endwhile",
+	      \ "endfunc",
+	      \ "au BufUnload * call UnloadAllBufs()",
+	      \ "au VimLeave * call writefile(['Test Finished'], 'Xout')",
+	      \ "edit Xxx1",
+	      \ "split Xxx2",
+	      \ "q"]
+  call writefile(content, 'Xtest')
+
+  call delete('Xout')
+  call system(v:progpath. ' --clean -N --not-a-term -S Xtest')
+  call assert_true(filereadable('Xout'))
+
+  call delete('Xxx1')
+  call delete('Xxx2')
+  call delete('Xtest')
+  call delete('Xout')
+endfunc
+
+" Some tests for buffer-local autocommands
+func Test_buflocal_autocmd()
+  let g:bname = ''
+  edit xx
+  au BufLeave <buffer> let g:bname = expand("%")
+  " here, autocommand for xx should trigger.
+  " but autocommand shall not apply to buffer named <buffer>.
+  edit somefile
+  call assert_equal('xx', g:bname)
+  let g:bname = ''
+  " here, autocommand shall be auto-deleted
+  bwipe xx
+  " autocmd should not trigger
+  edit xx
+  call assert_equal('', g:bname)
+  " autocmd should not trigger
+  edit somefile
+  call assert_equal('', g:bname)
+  enew
+  unlet g:bname
+endfunc