diff src/testdir/test_normal.vim @ 22476:b3751f4d3b26 v8.2.1786

patch 8.2.1786: various Normal mode commands not fully tested Commit: https://github.com/vim/vim/commit/8a9bc95eaec53f4e0c951ff8f2686ae5113a5709 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Oct 2 18:48:07 2020 +0200 patch 8.2.1786: various Normal mode commands not fully tested Problem: Various Normal mode commands not fully tested. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/7059)
author Bram Moolenaar <Bram@vim.org>
date Fri, 02 Oct 2020 19:00:05 +0200
parents ff21e2962490
children 1503ecd54f8a
line wrap: on
line diff
--- a/src/testdir/test_normal.vim
+++ b/src/testdir/test_normal.vim
@@ -596,6 +596,19 @@ func Test_normal15_z_scroll_vert()
   call assert_equal(21, winsaveview()['topline'])
   call assert_equal([0, 21, 2, 0, 9], getcurpos())
 
+  " Test for z+ with [count] greater than buffer size
+  1
+  norm! 1000z+
+  call assert_equal('	100', getline('.'))
+  call assert_equal(100, winsaveview()['topline'])
+  call assert_equal([0, 100, 2, 0, 9], getcurpos())
+
+  " Test for z+ from the last buffer line
+  norm! Gz.z+
+  call assert_equal('	100', getline('.'))
+  call assert_equal(100, winsaveview()['topline'])
+  call assert_equal([0, 100, 2, 0, 9], getcurpos())
+
   " Test for z^
   norm! 22z+0
   norm! z^
@@ -603,6 +616,12 @@ func Test_normal15_z_scroll_vert()
   call assert_equal(12, winsaveview()['topline'])
   call assert_equal([0, 21, 2, 0, 9], getcurpos())
 
+  " Test for z^ from first buffer line
+  norm! ggz^
+  call assert_equal('1', getline('.'))
+  call assert_equal(1, winsaveview()['topline'])
+  call assert_equal([0, 1, 1, 0, 1], getcurpos())
+
   " Test for [count]z^
   1
   norm! 30z^
@@ -682,6 +701,19 @@ func Test_normal16_z_scroll_hor()
   norm! yl
   call assert_equal('z', @0)
 
+  " Test for zs and ze with folds
+  %fold
+  norm! $zs
+  call assert_equal(26, col('.'))
+  call assert_equal(0, winsaveview()['leftcol'])
+  norm! yl
+  call assert_equal('z', @0)
+  norm! ze
+  call assert_equal(26, col('.'))
+  call assert_equal(0, winsaveview()['leftcol'])
+  norm! yl
+  call assert_equal('z', @0)
+
   " cleanup
   set wrap listchars=eol:$
   bw!
@@ -775,6 +807,19 @@ func Test_vert_scroll_cmds()
   normal! 4H
   call assert_equal(33, line('.'))
 
+  " Test for using a large count value
+  %d
+  call setline(1, range(1, 4))
+  norm! 6H
+  call assert_equal(4, line('.'))
+
+  " Test for 'M' with folded lines
+  %d
+  call setline(1, range(1, 20))
+  1,5fold
+  norm! LM
+  call assert_equal(12, line('.'))
+
   " Test for the CTRL-E and CTRL-Y commands with folds
   %d
   call setline(1, range(1, 10))
@@ -1155,6 +1200,13 @@ func Test_normal18_z_fold()
   norm! j
   call assert_equal('55', getline('.'))
 
+  " Test for zm with a count
+  50
+  set foldlevel=2
+  norm! 3zm
+  call assert_equal(0, &foldlevel)
+  call assert_equal(49, foldclosed(line('.')))
+
   " Test for zM
   48
   set nofoldenable foldlevel=99
@@ -1355,6 +1407,14 @@ func Test_normal23_K()
   set iskeyword-=%
   set iskeyword-=\|
 
+  " Test for specifying a count to K
+  1
+  com! -nargs=* Kprog let g:Kprog_Args = <q-args>
+  set keywordprg=:Kprog
+  norm! 3K
+  call assert_equal('3 version8', g:Kprog_Args)
+  delcom Kprog
+
   " Only expect "man" to work on Unix
   if !has("unix")
     let &keywordprg = k
@@ -1386,6 +1446,8 @@ func Test_normal23_K()
   call setline(1, ['abc', 'xyz'])
   call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
   call assert_beeps("normal! ggVjK")
+  norm! V
+  call assert_beeps("norm! cK")
 
   " clean up
   let &keywordprg = k
@@ -1770,6 +1832,30 @@ func Test_normal29_brace()
   bw!
 endfunc
 
+" Test for section movements
+func Test_normal_section()
+  new
+  let lines =<< trim [END]
+    int foo()
+    {
+      if (1)
+      {
+        a = 1;
+      }
+    }
+  [END]
+  call setline(1, lines)
+
+  " jumping to a folded line using [[ should open the fold
+  2,3fold
+  call cursor(5, 1)
+  call feedkeys("[[", 'xt')
+  call assert_equal(2, line('.'))
+  call assert_equal(-1, foldclosedend(line('.')))
+
+  close!
+endfunc
+
 " Test for ~ command
 func Test_normal30_changecase()
   new
@@ -2744,25 +2830,26 @@ func Test_java_motion()
   call assert_beeps('normal! ]m')
   call assert_beeps('normal! [M')
   call assert_beeps('normal! ]M')
-  a
-Piece of Java
-{
-	tt m1 {
-		t1;
-	} e1
-
-	tt m2 {
-		t2;
-	} e2
-
-	tt m3 {
-		if (x)
-		{
-			t3;
-		}
-	} e3
-}
-.
+  let lines =<< trim [CODE]
+	Piece of Java
+	{
+		tt m1 {
+			t1;
+		} e1
+
+		tt m2 {
+			t2;
+		} e2
+
+		tt m3 {
+			if (x)
+			{
+				t3;
+			}
+		} e3
+	}
+  [CODE]
+  call setline(1, lines)
 
   normal gg
 
@@ -2815,6 +2902,15 @@ Piece of Java
   call assert_equal("{LF", getline('.'))
   call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
 
+  call cursor(2, 1)
+  call assert_beeps('norm! 5]m')
+
+  " jumping to a method in a fold should open the fold
+  6,10fold
+  call feedkeys("gg3]m", 'xt')
+  call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')])
+  call assert_equal(-1, foldclosedend(7))
+
   close!
 endfunc
 
@@ -3005,6 +3101,27 @@ func Test_normal_delete_cmd()
   close!
 endfunc
 
+" Test for deleting or changing characters across lines with 'whichwrap'
+" containing 's'. Should count <EOL> as one character.
+func Test_normal_op_across_lines()
+  new
+  set whichwrap&
+  call setline(1, ['one two', 'three four'])
+  exe "norm! $3d\<Space>"
+  call assert_equal(['one twhree four'], getline(1, '$'))
+
+  call setline(1, ['one two', 'three four'])
+  exe "norm! $3c\<Space>x"
+  call assert_equal(['one twxhree four'], getline(1, '$'))
+
+  set whichwrap+=l
+  call setline(1, ['one two', 'three four'])
+  exe "norm! $3x"
+  call assert_equal(['one twhree four'], getline(1, '$'))
+  close!
+  set whichwrap&
+endfunc
+
 " Test for 'w' and 'b' commands
 func Test_normal_word_move()
   new
@@ -3078,4 +3195,17 @@ func Test_normal_vert_scroll_longline()
   close!
 endfunc
 
+" Test for jumping in a file using %
+func Test_normal_percent_jump()
+  new
+  call setline(1, range(1, 100))
+
+  " jumping to a folded line should open the fold
+  25,75fold
+  call feedkeys('50%', 'xt')
+  call assert_equal(50, line('.'))
+  call assert_equal(-1, foldclosedend(50))
+  close!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab