summaryrefslogtreecommitdiff
path: root/src/testdir/test_swap.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-04-28 22:25:38 +0200
committerBram Moolenaar <Bram@vim.org>2019-04-28 22:25:38 +0200
commit67cf86bfff5fd5224d557d81cb146f46e33b831c (patch)
tree3ffaca7f4014f393ceb0216a2ec8fca091019c1c /src/testdir/test_swap.vim
parentafde13b62b8fa25dac4635d5caee8d088b937ee0 (diff)
downloadvim-git-67cf86bfff5fd5224d557d81cb146f46e33b831c.tar.gz
patch 8.1.1231: asking about existing swap file unnecessarilyv8.1.1231
Problem: Asking about existing swap file unnecessarily. Solution: When it is safe, delete the swap file. Remove HAS_SWAP_EXISTS_ACTION, it is always defined. (closes #1237)
Diffstat (limited to 'src/testdir/test_swap.vim')
-rw-r--r--src/testdir/test_swap.vim56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/testdir/test_swap.vim b/src/testdir/test_swap.vim
index ce5257891..b6bf90c29 100644
--- a/src/testdir/test_swap.vim
+++ b/src/testdir/test_swap.vim
@@ -164,3 +164,59 @@ func Test_swapname()
call delete('Xtest2')
call delete('Xtest3')
endfunc
+
+func Test_swapfile_delete()
+ autocmd! SwapExists
+ function s:swap_exists()
+ let v:swapchoice = s:swap_choice
+ let s:swapname = v:swapname
+ let s:filename = expand('<afile>')
+ endfunc
+ augroup test_swapfile_delete
+ autocmd!
+ autocmd SwapExists * call s:swap_exists()
+ augroup END
+
+
+ " Create a valid swapfile by editing a file.
+ split XswapfileText
+ call setline(1, ['one', 'two', 'three'])
+ write " file is written, not modified
+ " read the swapfile as a Blob
+ let swapfile_name = swapname('%')
+ let swapfile_bytes = readfile(swapfile_name, 'B')
+
+ " Close the file and recreate the swap file.
+ " Now editing the file will run into the process still existing
+ quit
+ call writefile(swapfile_bytes, swapfile_name)
+ let s:swap_choice = 'e'
+ let s:swapname = ''
+ split XswapfileText
+ quit
+ call assert_equal(swapfile_name, s:swapname)
+
+ " Write the swapfile with a modified PID, now it will be automatically
+ " deleted. Process one should never be Vim.
+ let swapfile_bytes[24:27] = 0z01000000
+ call writefile(swapfile_bytes, swapfile_name)
+ let s:swapname = ''
+ split XswapfileText
+ quit
+ call assert_equal('', s:swapname)
+
+ " Now set the modified flag, the swap file will not be deleted
+ let swapfile_bytes[28 + 80 + 899] = 0x55
+ call writefile(swapfile_bytes, swapfile_name)
+ let s:swapname = ''
+ split XswapfileText
+ quit
+ call assert_equal(swapfile_name, s:swapname)
+
+ call delete('XswapfileText')
+ call delete(swapfile_name)
+ augroup test_swapfile_delete
+ autocmd!
+ augroup END
+ augroup! test_swapfile_delete
+endfunc