@@ -754,8 +754,9 @@ func Test_normal17_z_scroll_hor2()
754754 bw !
755755endfunc
756756
757- " Test for H, M and L commands with folds
758- func Test_scroll_cmds ()
757+ " Test for commands that scroll the window horizontally. Test with folds.
758+ " H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
759+ func Test_vert_scroll_cmds ()
759760 15 new
760761 call setline (1 , range (1 , 100 ))
761762 exe " normal! 30ggz\<CR> "
@@ -764,17 +765,113 @@ func Test_scroll_cmds()
764765 40 ,43 fold
765766 46 ,49 fold
766767 let h = winheight (0 )
768+
769+ " Test for H, M and L commands
767770 " Top of the screen = 30
768771 " Folded lines = 9
769772 " Bottom of the screen = 30 + h + 9 - 1
770773 normal ! 4 L
771774 call assert_equal (35 + h , line (' .' ))
772775 normal ! 4 H
773776 call assert_equal (33 , line (' .' ))
777+
778+ " Test for the CTRL-E and CTRL-Y commands with folds
779+ % d
780+ call setline (1 , range (1 , 10 ))
781+ 3 ,5 fold
782+ exe " normal 6G3\<C-E> "
783+ call assert_equal (6 , line (' w0' ))
784+ exe " normal 2\<C-Y> "
785+ call assert_equal (2 , line (' w0' ))
786+
787+ " Test for CTRL-Y on a folded line
788+ % d
789+ call setline (1 , range (1 , 100 ))
790+ exe (h + 2 ) .. " ," .. (h + 4 ) .. " fold"
791+ exe h + 5
792+ normal z-
793+ exe " normal \<C-Y>\<C-Y> "
794+ call assert_equal (h + 1 , line (' w$' ))
795+
796+ " Using <PageUp> and <PageDown> in an empty buffer should beep
797+ % d
798+ call assert_beeps (' exe "normal \<PageUp>"' )
799+ call assert_beeps (' exe "normal \<C-B>"' )
800+ call assert_beeps (' exe "normal \<PageDown>"' )
801+ call assert_beeps (' exe "normal \<C-F>"' )
802+
803+ " Test for <C-U> and <C-D> with fold
804+ % d
805+ call setline (1 , range (1 , 100 ))
806+ 10 ,35 fold
807+ set scroll = 10
808+ exe " normal \<C-D> "
809+ call assert_equal (36 , line (' .' ))
810+ exe " normal \<C-D> "
811+ call assert_equal (46 , line (' .' ))
812+ exe " normal \<C-U> "
813+ call assert_equal (36 , line (' .' ))
814+ exe " normal \<C-U> "
815+ call assert_equal (10 , line (' .' ))
816+ exe " normal \<C-U> "
817+ call assert_equal (1 , line (' .' ))
818+ set scroll &
819+
820+ " Test for scrolling to the top of the file with <C-U> and a fold
821+ 10
822+ normal ztL
823+ exe " normal \<C-U>\<C-U> "
824+ call assert_equal (1 , line (' w0' ))
825+
826+ " Test for CTRL-D on a folded line
827+ % d
828+ call setline (1 , range (1 , 100 ))
829+ 50 ,100 fold
830+ 75
831+ normal z-
832+ exe " normal \<C-D> "
833+ call assert_equal (50 , line (' .' ))
834+ call assert_equal (100 , line (' w$' ))
835+ normal z.
836+ let lnum = winline ()
837+ exe " normal \<C-D> "
838+ call assert_equal (lnum, winline ())
839+ call assert_equal (50 , line (' .' ))
840+ normal zt
841+ exe " normal \<C-D> "
842+ call assert_equal (50 , line (' w0' ))
843+
774844 set foldenable &
775845 close !
776846endfunc
777847
848+ " Test for the 'sidescroll' option
849+ func Test_sidescroll_opt ()
850+ new
851+ 20 vnew
852+
853+ " scroll by 2 characters horizontally
854+ set sidescroll = 2 nowrap
855+ call setline (1 , repeat (' a' , 40 ))
856+ normal g $l
857+ call assert_equal (19 , screenpos (0 , 1 , 21 ).col )
858+ normal l
859+ call assert_equal (20 , screenpos (0 , 1 , 22 ).col )
860+ normal g0h
861+ call assert_equal (2 , screenpos (0 , 1 , 2 ).col )
862+ call assert_equal (20 , screenpos (0 , 1 , 20 ).col )
863+
864+ " when 'sidescroll' is 0, cursor positioned at the center
865+ set sidescroll = 0
866+ normal g $l
867+ call assert_equal (11 , screenpos (0 , 1 , 21 ).col )
868+ normal g0h
869+ call assert_equal (10 , screenpos (0 , 1 , 10 ).col )
870+
871+ % bw !
872+ set wrap & sidescroll &
873+ endfunc
874+
778875" basic tests for foldopen/folddelete
779876func Test_normal18_z_fold ()
780877 CheckFeature folding
@@ -2962,4 +3059,40 @@ func Test_normal_word_move()
29623059 close !
29633060endfunc
29643061
3062+ " Test for 'scrolloff' with a long line that doesn't fit in the screen
3063+ func Test_normal_scroloff ()
3064+ 10 new
3065+ 80 vnew
3066+ call setline (1 , repeat (' a' , 1000 ))
3067+ set scrolloff = 10
3068+ normal gg10gj
3069+ call assert_equal (8 , winline ())
3070+ normal 10 gj
3071+ call assert_equal (10 , winline ())
3072+ normal 10 gk
3073+ call assert_equal (3 , winline ())
3074+ set scrolloff &
3075+ close !
3076+ endfunc
3077+
3078+ " Test for vertical scrolling with CTRL-F and CTRL-B with a long line
3079+ func Test_normal_vert_scroll_longline ()
3080+ 10 new
3081+ 80 vnew
3082+ call setline (1 , range (1 , 10 ))
3083+ call append (5 , repeat (' a' , 1000 ))
3084+ exe " normal gg\<C-F> "
3085+ call assert_equal (6 , line (' .' ))
3086+ exe " normal \<C-F>\<C-F> "
3087+ call assert_equal (11 , line (' .' ))
3088+ call assert_equal (1 , winline ())
3089+ exe " normal \<C-B> "
3090+ call assert_equal (10 , line (' .' ))
3091+ call assert_equal (3 , winline ())
3092+ exe " normal \<C-B>\<C-B> "
3093+ call assert_equal (5 , line (' .' ))
3094+ call assert_equal (5 , winline ())
3095+ close !
3096+ endfunc
3097+
29653098" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments