diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2018-09-05 09:45:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-05 09:45:14 +0200 |
| commit | 55a721512b695db47c6c0a792b767a1c850b01fc (patch) | |
| tree | fa3f76da5189581a12ecacc7a8e42b4640ebeac5 /src/nvim/testdir | |
| parent | bfe82d465035a1b792c4a17d7f7a759b61205e15 (diff) | |
| parent | 958467456930badcaf218b6fac56b105ac7655c8 (diff) | |
| download | rneovim-55a721512b695db47c6c0a792b767a1c850b01fc.tar.gz rneovim-55a721512b695db47c6c0a792b767a1c850b01fc.tar.bz2 rneovim-55a721512b695db47c6c0a792b767a1c850b01fc.zip | |
Merge #8953 from janlazo/vim-8.0.1190
Diffstat (limited to 'src/nvim/testdir')
| -rw-r--r-- | src/nvim/testdir/test_exit.vim | 57 | ||||
| -rw-r--r-- | src/nvim/testdir/test_writefile.vim | 82 |
2 files changed, 139 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_exit.vim b/src/nvim/testdir/test_exit.vim new file mode 100644 index 0000000000..8f02fd29e3 --- /dev/null +++ b/src/nvim/testdir/test_exit.vim @@ -0,0 +1,57 @@ +" Tests for exiting Vim. + +source shared.vim + +func Test_exiting() + let after = [ + \ 'au QuitPre * call writefile(["QuitPre"], "Xtestout")', + \ 'au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")', + \ 'quit', + \ ] + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) + endif + call delete('Xtestout') + + let after = [ + \ 'au QuitPre * call writefile(["QuitPre"], "Xtestout")', + \ 'au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")', + \ 'help', + \ 'wincmd w', + \ 'quit', + \ ] + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) + endif + call delete('Xtestout') + + let after = [ + \ 'au QuitPre * call writefile(["QuitPre"], "Xtestout")', + \ 'au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")', + \ 'split', + \ 'new', + \ 'qall', + \ ] + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) + endif + call delete('Xtestout') + + let after = [ + \ 'au QuitPre * call writefile(["QuitPre"], "Xtestout", "a")', + \ 'au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")', + \ 'augroup nasty', + \ ' au ExitPre * split', + \ 'augroup END', + \ 'quit', + \ 'augroup nasty', + \ ' au! ExitPre', + \ 'augroup END', + \ 'quit', + \ ] + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], + \ readfile('Xtestout')) + endif + call delete('Xtestout') +endfunc diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 8b031646b5..06f9d03554 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -31,3 +31,85 @@ func Test_writefile_fails_gently() call assert_fails('call writefile([], [])', 'E730:') endfunc + +func SetFlag(timer) + let g:flag = 1 +endfunc + +func Test_write_quit_split() + " Prevent exiting by splitting window on file write. + augroup testgroup + autocmd BufWritePre * split + augroup END + e! Xfile + call setline(1, 'nothing') + wq + + if has('timers') + " timer will not run if "exiting" is still set + let g:flag = 0 + call timer_start(1, 'SetFlag') + sleep 50m + call assert_equal(1, g:flag) + unlet g:flag + endif + au! testgroup + bwipe Xfile + call delete('Xfile') +endfunc + +func Test_nowrite_quit_split() + " Prevent exiting by opening a help window. + e! Xfile + help + wincmd w + exe winnr() . 'q' + + if has('timers') + " timer will not run if "exiting" is still set + let g:flag = 0 + call timer_start(1, 'SetFlag') + sleep 50m + call assert_equal(1, g:flag) + unlet g:flag + endif + bwipe Xfile +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 |