Patch 8.2.2945
Problem:    Some buffer related code is not tested.
Solution:   Add a few more tests. (Yegappan Lakshmanan, closes #8320)
Files:      src/termlib.c, src/testdir/test_excmd.vim,
            src/testdir/test_recover.vim, src/testdir/test_swap.vim,
            src/testdir/test_visual.vim


*** ../vim-8.2.2944/src/termlib.c       2019-12-05 21:32:07.000000000 +0100
--- src/termlib.c       2021-06-05 20:57:28.196091176 +0200
***************
*** 591,597 ****
      static char *
  _find(char *s, char *set)
  {
!     for(; *s; s++)
      {
        char    *ptr = set;
  
--- 591,597 ----
      static char *
  _find(char *s, char *set)
  {
!     for (; *s; s++)
      {
        char    *ptr = set;
  
*** ../vim-8.2.2944/src/testdir/test_excmd.vim  2021-05-06 17:36:50.984003922 
+0200
--- src/testdir/test_excmd.vim  2021-06-05 20:57:28.196091176 +0200
***************
*** 69,74 ****
--- 69,82 ----
    call assert_fails('3file', 'E474:')
    call assert_fails('0,0file', 'E474:')
    call assert_fails('0file abc', 'E474:')
+   if !has('win32')
+     " Change the name of the buffer to the same name
+     new Xfile1
+     file Xfile1
+     call assert_equal('Xfile1', @%)
+     call assert_equal('Xfile1', @#)
+     bw!
+   endif
  endfunc
  
  " Test for the :drop command
*** ../vim-8.2.2944/src/testdir/test_recover.vim        2021-03-10 
22:27:44.597737046 +0100
--- src/testdir/test_recover.vim        2021-06-05 20:57:28.196091176 +0200
***************
*** 133,136 ****
--- 133,263 ----
    call delete(swname)
  endfunc
  
+ " Test for :recover with multiple swap files
+ func Test_recover_multiple_swap_files()
+   CheckUnix
+   new Xfile1
+   call setline(1, ['a', 'b', 'c'])
+   preserve
+   let b = readblob('.Xfile1.swp')
+   call writefile(b, '.Xfile1.swm')
+   call writefile(b, '.Xfile1.swn')
+   call writefile(b, '.Xfile1.swo')
+   %bw!
+   call feedkeys(":recover Xfile1\<CR>3\<CR>q", 'xt')
+   call assert_equal(['a', 'b', 'c'], getline(1, '$'))
+ 
+   call delete('.Xfile1.swm')
+   call delete('.Xfile1.swn')
+   call delete('.Xfile1.swo')
+ endfunc
+ 
+ " Test for :recover using an empty swap file
+ func Test_recover_empty_swap_file()
+   CheckUnix
+   call writefile([], '.Xfile1.swp')
+   let msg = execute('recover Xfile1')
+   call assert_match('Unable to read block 0 from .Xfile1.swp', msg)
+   call assert_equal('Xfile1', @%)
+   bw!
+   " :recover from an empty buffer
+   call assert_fails('recover', 'E305:')
+   call delete('.Xfile1.swp')
+ endfunc
+ 
+ " Test for :recover using a corrupted swap file
+ func Test_recover_corrupted_swap_file()
+   CheckUnix
+   " recover using a partial swap file
+   call writefile(0z1234, '.Xfile1.swp')
+   call assert_fails('recover Xfile1', 'E295:')
+   bw!
+ 
+   " recover using invalid content in the swap file
+   call writefile([repeat('1', 2*1024)], '.Xfile1.swp')
+   call assert_fails('recover Xfile1', 'E307:')
+   call delete('.Xfile1.swp')
+ 
+   " :recover using a swap file with a corrupted header
+   edit Xfile1
+   preserve
+   let sn = swapname('')
+   let b = readblob(sn)
+   bw!
+   " clear the B0_MAGIC_LONG field
+   let b[1008:1011] = 0z00000000
+   call writefile(b, sn)
+   let msg = execute('recover Xfile1')
+   call assert_match('the file has been damaged', msg)
+   bw!
+   call delete(sn)
+ endfunc
+ 
+ " Test for :recover using an encrypted swap file
+ func Test_recover_encrypted_swap_file()
+   CheckUnix
+ 
+   " Recover an encrypted file from the swap file without the original file
+   new Xfile1
+   call feedkeys(":X\<CR>vim\<CR>vim\<CR>", 'xt')
+   call setline(1, ['aaa', 'bbb', 'ccc'])
+   preserve
+   let b = readblob('.Xfile1.swp')
+   call writefile(b, '.Xfile1.swm')
+   bw!
+   call feedkeys(":recover Xfile1\<CR>vim\<CR>\<CR>", 'xt')
+   call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$'))
+   bw!
+   call delete('.Xfile1.swm')
+ 
+   " Recover an encrypted file from the swap file with the original file
+   new Xfile1
+   call feedkeys(":X\<CR>vim\<CR>vim\<CR>", 'xt')
+   call setline(1, ['aaa', 'bbb', 'ccc'])
+   update
+   call setline(1, ['111', '222', '333'])
+   preserve
+   let b = readblob('.Xfile1.swp')
+   call writefile(b, '.Xfile1.swm')
+   bw!
+   call feedkeys(":recover Xfile1\<CR>vim\<CR>\<CR>", 'xt')
+   call assert_equal(['111', '222', '333'], getline(1, '$'))
+   call assert_true(&modified)
+   bw!
+   call delete('.Xfile1.swm')
+   call delete('Xfile1')
+ endfunc
+ 
+ " Test for :recover using a unreadable swap file
+ func Test_recover_unreadble_swap_file()
+   CheckUnix
+   CheckNotRoot
+   new Xfile1
+   let b = readblob('.Xfile1.swp')
+   call writefile(b, '.Xfile1.swm')
+   bw!
+   call setfperm('.Xfile1.swm', '-w-------')
+   call assert_fails('recover Xfile1', 'E306:')
+   call delete('.Xfile1.swm')
+ endfunc
+ 
+ " Test for using :recover when the original file and the swap file have the
+ " same contents.
+ func Test_recover_unmodified_file()
+   CheckUnix
+   call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1')
+   edit Xfile1
+   preserve
+   let b = readblob('.Xfile1.swp')
+   %bw!
+   call writefile(b, '.Xfile1.swz')
+   let msg = execute('recover Xfile1')
+   call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$'))
+   call assert_false(&modified)
+   call assert_match('Buffer contents equals file contents', msg)
+   bw!
+   call delete('Xfile1')
+   call delete('.Xfile1.swz')
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.2944/src/testdir/test_swap.vim   2020-11-25 12:43:24.136768912 
+0100
--- src/testdir/test_swap.vim   2021-06-05 20:57:28.196091176 +0200
***************
*** 483,486 ****
--- 483,561 ----
    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
*** ../vim-8.2.2944/src/testdir/test_visual.vim 2021-06-04 21:57:53.935646716 
+0200
--- src/testdir/test_visual.vim 2021-06-05 20:57:28.200091167 +0200
***************
*** 811,816 ****
--- 811,820 ----
    " reproducible if this operation is performed manually.
    "call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
    call assert_equal(['aaxa', 'bbba', 'ccca'], getline(1, '$'))
+   " Repeat the previous test but use 'l' to move the cursor instead of '$'
+   call setline(1, ['aaa', 'bbb', 'ccc'])
+   exe "normal! gg2l\<C-V>2jA\<Left>x"
+   call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
  
    " Change a characterwise motion to a blockwise motion using CTRL-V
    %d _
*** ../vim-8.2.2944/src/version.c       2021-06-05 20:51:34.741122335 +0200
--- src/version.c       2021-06-05 20:58:03.591988696 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2945,
  /**/

-- 
TERRY GILLIAM PLAYED: PATSY (ARTHUR'S TRUSTY STEED), THE GREEN KNIGHT
                      SOOTHSAYER, BRIDGEKEEPER, SIR GAWAIN (THE FIRST TO BE
                      KILLED BY THE RABBIT)
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202106051901.155J1O7q115227%40masaka.moolenaar.net.

Raspunde prin e-mail lui