changeset 24756:ac7ad168caed v8.2.2916

patch 8.2.2916: operators are not fully tested Commit: https://github.com/vim/vim/commit/2ac7184d34cd01e2b76bd1f704fd6a4b4af10239 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon May 31 19:23:01 2021 +0200 patch 8.2.2916: operators are not fully tested Problem: Operators are not fully tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8290)
author Bram Moolenaar <Bram@vim.org>
date Mon, 31 May 2021 19:30:04 +0200
parents 6173011dc313
children 5754851476d7
files src/ops.c src/testdir/test_netbeans.vim src/testdir/test_normal.vim src/testdir/test_visual.vim src/version.c
diffstat 5 files changed, 166 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ops.c
+++ b/src/ops.c
@@ -2383,9 +2383,10 @@ op_addsub(
 #ifdef FEAT_NETBEANS_INTG
 	    if (netbeans_active() && one_change)
 	    {
-		char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
+		char_u *ptr;
 
 		netbeans_removed(curbuf, pos.lnum, pos.col, (long)length);
+		ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
 		netbeans_inserted(curbuf, pos.lnum, pos.col,
 						&ptr[pos.col], length);
 	    }
--- a/src/testdir/test_netbeans.vim
+++ b/src/testdir/test_netbeans.vim
@@ -367,6 +367,46 @@ func Nb_basic(port)
   call assert_match('2:insert=\d\+ 26 "\t"', l[-1])
   let g:last += 18
 
+  " Test for changing case of multiple lines using ~
+  normal ggVG~
+  call WaitFor('len(ReadXnetbeans()) >= (g:last + 6)')
+  let l = ReadXnetbeans()
+  call assert_match('2:remove=\d\+ 0 8', l[-6])
+  call assert_match('2:insert=\d\+ 0 "FOO BAR2"', l[-5])
+  call assert_match('2:remove=\d\+ 9 8', l[-4])
+  call assert_match('2:insert=\d\+ 9 "BLUE SKy"', l[-3])
+  call assert_match('2:remove=\d\+ 18 9', l[-2])
+  call assert_match('2:insert=\d\+ 18 "\tFOO BAR3"', l[-1])
+  let g:last += 6
+
+  " Test for changing case of a visual block using ~
+  exe "normal ggw\<C-V>$~"
+  call WaitFor('len(ReadXnetbeans()) >= (g:last + 2)')
+  let l = ReadXnetbeans()
+  call assert_match('2:remove=\d\+ 4 4', l[-2])
+  call assert_match('2:insert=\d\+ 4 "bar2"', l[-1])
+  let g:last += 2
+
+  " Increment a number using <C-A> in visual mode
+  exe "normal! gg$v6\<C-A>"
+  call WaitFor('len(ReadXnetbeans()) >= (g:last + 6)')
+  let l = ReadXnetbeans()
+  call assert_match('2:remove=\d\+ 0 9', l[-4])
+  call assert_match('2:insert=\d\+ 0 "FOO bar8"', l[-3])
+  call assert_match('2:remove=\d\+ 7 1', l[-2])
+  call assert_match('2:insert=\d\+ 7 "8"', l[-1])
+  let g:last += 6
+
+  " Decrement a number using <C-X> in visual mode
+  exe "normal! gg$v3\<C-X>"
+  call WaitFor('len(ReadXnetbeans()) >= (g:last + 6)')
+  let l = ReadXnetbeans()
+  call assert_match('2:remove=\d\+ 0 9', l[-4])
+  call assert_match('2:insert=\d\+ 0 "FOO bar5"', l[-3])
+  call assert_match('2:remove=\d\+ 7 1', l[-2])
+  call assert_match('2:insert=\d\+ 7 "5"', l[-1])
+  let g:last += 6
+
   " stopDocumentListen test
   call appendbufline(cmdbufnr, '$', 'stopDocumentListen_Test')
   call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)')
--- a/src/testdir/test_normal.vim
+++ b/src/testdir/test_normal.vim
@@ -3377,4 +3377,34 @@ func Test_normal_shift_rightleft()
   bw!
 endfunc
 
+" Some commands like yy, cc, dd, >>, << and !! accept a count after
+" typing the first letter of the command.
+func Test_normal_count_after_operator()
+  new
+  setlocal shiftwidth=4 tabstop=8 autoindent
+  call setline(1, ['one', 'two', 'three', 'four', 'five'])
+  let @a = ''
+  normal! j"ay4y
+  call assert_equal("two\nthree\nfour\nfive\n", @a)
+  normal! 3G>2>
+  call assert_equal(['one', 'two', '    three', '    four', 'five'],
+        \ getline(1, '$'))
+  exe "normal! 3G0c2cred\nblue"
+  call assert_equal(['one', 'two', '    red', '    blue', 'five'],
+        \ getline(1, '$'))
+  exe "normal! gg<8<"
+  call assert_equal(['one', 'two', 'red', 'blue', 'five'],
+        \ getline(1, '$'))
+  exe "normal! ggd3d"
+  call assert_equal(['blue', 'five'], getline(1, '$'))
+  call setline(1, range(1, 4))
+  call feedkeys("gg!3!\<C-B>\"\<CR>", 'xt')
+  call assert_equal('".,.+2!', @:)
+  call feedkeys("gg!1!\<C-B>\"\<CR>", 'xt')
+  call assert_equal('".!', @:)
+  call feedkeys("gg!9!\<C-B>\"\<CR>", 'xt')
+  call assert_equal('".,$!', @:)
+  bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_visual.vim
+++ b/src/testdir/test_visual.vim
@@ -818,7 +818,99 @@ func Test_visual_block_mode()
   exe "normal ld\<C-V>j"
   call assert_equal(['13', '46', '789'], getline(1, '$'))
 
+  " Test from ':help v_b_I_example'
+  %d _
+  setlocal tabstop=8 shiftwidth=4
+  let lines =<< trim END
+    abcdefghijklmnopqrstuvwxyz
+    abc		defghijklmnopqrstuvwxyz
+    abcdef  ghi		jklmnopqrstuvwxyz
+    abcdefghijklmnopqrstuvwxyz
+  END
+  call setline(1, lines)
+  exe "normal ggfo\<C-V>3jISTRING"
+  let expected =<< trim END
+    abcdefghijklmnSTRINGopqrstuvwxyz
+    abc	      STRING  defghijklmnopqrstuvwxyz
+    abcdef  ghi   STRING  	jklmnopqrstuvwxyz
+    abcdefghijklmnSTRINGopqrstuvwxyz
+  END
+  call assert_equal(expected, getline(1, '$'))
+
+  " Test from ':help v_b_A_example'
+  %d _
+  let lines =<< trim END
+    abcdefghijklmnopqrstuvwxyz
+    abc		defghijklmnopqrstuvwxyz
+    abcdef  ghi		jklmnopqrstuvwxyz
+    abcdefghijklmnopqrstuvwxyz
+  END
+  call setline(1, lines)
+  exe "normal ggfo\<C-V>3j$ASTRING"
+  let expected =<< trim END
+    abcdefghijklmnopqrstuvwxyzSTRING
+    abc		defghijklmnopqrstuvwxyzSTRING
+    abcdef  ghi		jklmnopqrstuvwxyzSTRING
+    abcdefghijklmnopqrstuvwxyzSTRING
+  END
+  call assert_equal(expected, getline(1, '$'))
+
+  " Test from ':help v_b_<_example'
+  %d _
+  let lines =<< trim END
+    abcdefghijklmnopqrstuvwxyz
+    abc		defghijklmnopqrstuvwxyz
+    abcdef  ghi		jklmnopqrstuvwxyz
+    abcdefghijklmnopqrstuvwxyz
+  END
+  call setline(1, lines)
+  exe "normal ggfo\<C-V>3j3l<.."
+  let expected =<< trim END
+    abcdefghijklmnopqrstuvwxyz
+    abc	      defghijklmnopqrstuvwxyz
+    abcdef  ghi   jklmnopqrstuvwxyz
+    abcdefghijklmnopqrstuvwxyz
+  END
+  call assert_equal(expected, getline(1, '$'))
+
+  " Test from ':help v_b_>_example'
+  %d _
+  let lines =<< trim END
+    abcdefghijklmnopqrstuvwxyz
+    abc		defghijklmnopqrstuvwxyz
+    abcdef  ghi		jklmnopqrstuvwxyz
+    abcdefghijklmnopqrstuvwxyz
+  END
+  call setline(1, lines)
+  exe "normal ggfo\<C-V>3j>.."
+  let expected =<< trim END
+    abcdefghijklmn		  opqrstuvwxyz
+    abc			    defghijklmnopqrstuvwxyz
+    abcdef  ghi			    jklmnopqrstuvwxyz
+    abcdefghijklmn		  opqrstuvwxyz
+  END
+  call assert_equal(expected, getline(1, '$'))
+
+  " Test from ':help v_b_r_example'
+  %d _
+  let lines =<< trim END
+    abcdefghijklmnopqrstuvwxyz
+    abc		defghijklmnopqrstuvwxyz
+    abcdef  ghi		jklmnopqrstuvwxyz
+    abcdefghijklmnopqrstuvwxyz
+  END
+  call setline(1, lines)
+  exe "normal ggfo\<C-V>5l3jrX"
+  let expected =<< trim END
+    abcdefghijklmnXXXXXXuvwxyz
+    abc	      XXXXXXhijklmnopqrstuvwxyz
+    abcdef  ghi   XXXXXX    jklmnopqrstuvwxyz
+    abcdefghijklmnXXXXXXuvwxyz
+  END
+  call assert_equal(expected, getline(1, '$'))
+
   bwipe!
+  set tabstop& shiftwidth&
 endfunc
 
 " Test block-insert using cursor keys for movement
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2916,
+/**/
     2915,
 /**/
     2914,