Skip to content

Commit bdd2c29

Browse files
committed
patch 8.2.1040: not enough testing for movement commands
Problem: Not enough testing for movement commands. Solution: Add more tests. (Yegappan Lakshmanan, closes #6313)
1 parent 25fd267 commit bdd2c29

7 files changed

Lines changed: 251 additions & 48 deletions

File tree

src/testdir/test_cursor_func.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func Test_screenpos()
9999
\ 'curscol': wincol + 9,
100100
\ 'endcol': wincol + 9}, screenpos(winid, 2, 22))
101101
close
102+
call assert_equal({}, screenpos(999, 1, 1))
102103
bwipe!
103104
endfunc
104105

src/testdir/test_functions.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ func Test_simplify()
475475
call assert_equal('./file', simplify('./dir/../file'))
476476
call assert_equal('../dir/file', simplify('dir/../../dir/file'))
477477
call assert_equal('./file', simplify('dir/.././file'))
478+
call assert_equal('../dir', simplify('./../dir'))
479+
call assert_equal('..', simplify('../testdir/..'))
480+
call mkdir('Xdir')
481+
call assert_equal('.', simplify('Xdir/../.'))
482+
call delete('Xdir', 'd')
478483

479484
call assert_fails('call simplify({->0})', 'E729:')
480485
call assert_fails('call simplify([])', 'E730:')

src/testdir/test_gf.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
" Test for the gf and gF (goto file) commands
12

23
" This is a test if a URL is recognized by "gf", with the cursor before and
34
" after the "://". Also test ":\\".
@@ -38,6 +39,13 @@ func Test_gf_url()
3839
call search("URL")
3940
call assert_equal("URL://machine.name:1234?q=vim", expand("<cfile>"))
4041

42+
%d
43+
call setline(1, "demo://remote_file")
44+
wincmd f
45+
call assert_equal('demo://remote_file', @%)
46+
call assert_equal(2, winnr('$'))
47+
close!
48+
4149
set isf&vim
4250
enew!
4351
endfunc
@@ -118,6 +126,11 @@ func Test_gf_visual()
118126
norm! ttvtXgf
119127
call assert_equal('Xtest_gf_visual', bufname('%'))
120128

129+
" if multiple lines are selected, then gf should fail
130+
call setline(1, ["one", "two"])
131+
normal VGgf
132+
call assert_equal('Xtest_gf_visual', @%)
133+
121134
bwipe!
122135
call delete('Xtest_gf_visual')
123136
set hidden&
@@ -146,4 +159,21 @@ func Test_gf_error()
146159
bwipe!
147160
endfunc
148161

162+
" If a file is not found by 'gf', then 'includeexpr' should be used to locate
163+
" the file.
164+
func Test_gf_includeexpr()
165+
new
166+
let g:Inc_fname = ''
167+
func IncFunc()
168+
let g:Inc_fname = v:fname
169+
return v:fname
170+
endfunc
171+
setlocal includeexpr=IncFunc()
172+
call setline(1, 'somefile.java')
173+
call assert_fails('normal gf', 'E447:')
174+
call assert_equal('somefile.java', g:Inc_fname)
175+
close!
176+
delfunc IncFunc
177+
endfunc
178+
149179
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_normal.vim

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,9 @@ func Test_normal17_z_scroll_hor2()
754754
bw!
755755
endfunc
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
15new
760761
call setline(1, range(1, 100))
761762
exe "normal! 30ggz\<CR>"
@@ -764,17 +765,113 @@ func Test_scroll_cmds()
764765
40,43fold
765766
46,49fold
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! 4L
771774
call assert_equal(35 + h, line('.'))
772775
normal! 4H
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,5fold
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,35fold
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,100fold
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!
776846
endfunc
777847

848+
" Test for the 'sidescroll' option
849+
func Test_sidescroll_opt()
850+
new
851+
20vnew
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
779876
func Test_normal18_z_fold()
780877
CheckFeature folding
@@ -2962,4 +3059,40 @@ func Test_normal_word_move()
29623059
close!
29633060
endfunc
29643061

3062+
" Test for 'scrolloff' with a long line that doesn't fit in the screen
3063+
func Test_normal_scroloff()
3064+
10new
3065+
80vnew
3066+
call setline(1, repeat('a', 1000))
3067+
set scrolloff=10
3068+
normal gg10gj
3069+
call assert_equal(8, winline())
3070+
normal 10gj
3071+
call assert_equal(10, winline())
3072+
normal 10gk
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+
10new
3081+
80vnew
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

src/testdir/test_options.vim

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ func Test_set_one_column()
513513
endfunc
514514

515515
func Test_set_values()
516+
" opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
516517
if filereadable('opt_test.vim')
517518
source opt_test.vim
518519
else
@@ -921,4 +922,35 @@ func Test_opt_boolean()
921922
set number&
922923
endfunc
923924

925+
" Test for the 'window' option
926+
func Test_window_opt()
927+
" Needs only one open widow
928+
%bw!
929+
call setline(1, range(1, 8))
930+
set window=5
931+
exe "normal \<C-F>"
932+
call assert_equal(4, line('w0'))
933+
exe "normal \<C-F>"
934+
call assert_equal(7, line('w0'))
935+
exe "normal \<C-F>"
936+
call assert_equal(8, line('w0'))
937+
exe "normal \<C-B>"
938+
call assert_equal(5, line('w0'))
939+
exe "normal \<C-B>"
940+
call assert_equal(2, line('w0'))
941+
exe "normal \<C-B>"
942+
call assert_equal(1, line('w0'))
943+
set window=1
944+
exe "normal gg\<C-F>"
945+
call assert_equal(2, line('w0'))
946+
exe "normal \<C-F>"
947+
call assert_equal(3, line('w0'))
948+
exe "normal \<C-B>"
949+
call assert_equal(2, line('w0'))
950+
exe "normal \<C-B>"
951+
call assert_equal(1, line('w0'))
952+
enew!
953+
set window&
954+
endfunc
955+
924956
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)