summaryrefslogtreecommitdiff
path: root/src/testdir/test_swap.vim
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2021-06-05 20:59:22 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-05 20:59:22 +0200
commit59b262362f26b3aaea1eeb0078adc33eed59863e (patch)
tree4b20477712f90b3c4e666c5338b673dbd1866057 /src/testdir/test_swap.vim
parent1328bde9d406aa1292e92673fa8a026889424e79 (diff)
downloadvim-git-59b262362f26b3aaea1eeb0078adc33eed59863e.tar.gz
patch 8.2.2945: some buffer related code is not testedv8.2.2945
Problem: Some buffer related code is not tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes #8320)
Diffstat (limited to 'src/testdir/test_swap.vim')
-rw-r--r--src/testdir/test_swap.vim75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/testdir/test_swap.vim b/src/testdir/test_swap.vim
index 5f3f24da6..52eb62e72 100644
--- a/src/testdir/test_swap.vim
+++ b/src/testdir/test_swap.vim
@@ -483,4 +483,79 @@ func Test_swap_auto_delete()
augroup! test_swap_recover_ext
endfunc
+" Test for renaming a buffer when the swap file is deleted out-of-band
+func Test_missing_swap_file()
+ CheckUnix
+ new Xfile1
+ call delete('.Xfile1.swp')
+ call assert_fails('file Xfile2', 'E301:')
+ call assert_equal('Xfile2', bufname())
+ call assert_true(bufexists('Xfile1'))
+ call assert_true(bufexists('Xfile2'))
+ %bw!
+endfunc
+
+" Test for :preserve command
+func Test_preserve()
+ new Xfile1
+ setlocal noswapfile
+ call assert_fails('preserve', 'E313:')
+ bw!
+endfunc
+
+" Test for the v:swapchoice variable
+func Test_swapchoice()
+ call writefile(['aaa', 'bbb'], 'Xfile1')
+ edit Xfile1
+ preserve
+ let swapfname = swapname('')
+ let b = readblob(swapfname)
+ bw!
+ call writefile(b, swapfname)
+
+ autocmd! SwapExists
+
+ " Test for v:swapchoice = 'o' (readonly)
+ augroup test_swapchoice
+ autocmd!
+ autocmd SwapExists * let v:swapchoice = 'o'
+ augroup END
+ edit Xfile1
+ call assert_true(&readonly)
+ call assert_equal(['aaa', 'bbb'], getline(1, '$'))
+ %bw!
+ call assert_true(filereadable(swapfname))
+
+ " Test for v:swapchoice = 'a' (abort)
+ augroup test_swapchoice
+ autocmd!
+ autocmd SwapExists * let v:swapchoice = 'a'
+ augroup END
+ try
+ edit Xfile1
+ catch /^Vim:Interrupt$/
+ endtry
+ call assert_equal('', @%)
+ call assert_true(bufexists('Xfile1'))
+ %bw!
+ call assert_true(filereadable(swapfname))
+
+ " Test for v:swapchoice = 'd' (delete)
+ augroup test_swapchoice
+ autocmd!
+ autocmd SwapExists * let v:swapchoice = 'd'
+ augroup END
+ edit Xfile1
+ call assert_equal('Xfile1', @%)
+ %bw!
+ call assert_false(filereadable(swapfname))
+
+ call delete('Xfile1')
+ call delete(swapfname)
+ augroup test_swapchoice
+ autocmd!
+ augroup END
+ augroup! test_swapchoice
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab