/
test_normal.vim
3522 lines (3148 loc) · 89.2 KB
/
test_normal.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" Test for various Normal mode commands
source shared.vim
source check.vim
source view_util.vim
func Setup_NewWindow()
10new
call setline(1, range(1,100))
endfunc
func MyFormatExpr()
" Adds '->$' at lines having numbers followed by trailing whitespace
for ln in range(v:lnum, v:lnum+v:count-1)
let line = getline(ln)
if getline(ln) =~# '\d\s\+$'
call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
endif
endfor
endfunc
func CountSpaces(type, ...)
" for testing operatorfunc
" will count the number of spaces
" and return the result in g:a
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
if a:0 " Invoked from Visual mode, use gv command.
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
let g:a = strlen(substitute(@@, '[^ ]', '', 'g'))
let &selection = sel_save
let @@ = reg_save
endfunc
func OpfuncDummy(type, ...)
" for testing operatorfunc
let g:opt = &linebreak
if a:0 " Invoked from Visual mode, use gv command.
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
" Create a new dummy window
new
let g:bufnr = bufnr('%')
endfunc
func Test_normal00_optrans()
new
call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
1
exe "norm! Sfoobar\<esc>"
call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
2
exe "norm! $vbsone"
call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$'))
norm! VS Second line here
call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
%d
call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
1
norm! 2D
call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
set cpo+=#
norm! 4D
call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
" clean up
set cpo-=#
bw!
endfunc
func Test_normal01_keymodel()
call Setup_NewWindow()
" Test 1: depending on 'keymodel' <s-down> does something different
50
call feedkeys("V\<S-Up>y", 'tx')
call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
set keymodel=startsel
50
call feedkeys("V\<S-Up>y", 'tx')
call assert_equal(['49', '50'], getline("'<", "'>"))
" Start visual mode when keymodel = startsel
50
call feedkeys("\<S-Up>y", 'tx')
call assert_equal(['49', '5'], getreg(0, 0, 1))
" Use the different Shift special keys
50
call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
call assert_equal(['50'], getline("'<", "'>"))
call assert_equal(['50', ''], getreg(0, 0, 1))
" Do not start visual mode when keymodel=
set keymodel=
50
call feedkeys("\<S-Up>y$", 'tx')
call assert_equal(['42'], getreg(0, 0, 1))
" Stop visual mode when keymodel=stopsel
set keymodel=stopsel
50
call feedkeys("Vkk\<Up>yy", 'tx')
call assert_equal(['47'], getreg(0, 0, 1))
set keymodel=
50
call feedkeys("Vkk\<Up>yy", 'tx')
call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
" Test for using special keys to start visual selection
%d
call setline(1, ['red fox tail', 'red fox tail', 'red fox tail'])
set keymodel=startsel
" Test for <S-PageUp> and <S-PageDown>
call cursor(1, 1)
call feedkeys("\<S-PageDown>y", 'xt')
call assert_equal([0, 1, 1, 0], getpos("'<"))
call assert_equal([0, 3, 1, 0], getpos("'>"))
call feedkeys("Gz\<CR>8|\<S-PageUp>y", 'xt')
call assert_equal([0, 2, 1, 0], getpos("'<"))
call assert_equal([0, 3, 8, 0], getpos("'>"))
" Test for <S-C-Home> and <S-C-End>
call cursor(2, 12)
call feedkeys("\<S-C-Home>y", 'xt')
call assert_equal([0, 1, 1, 0], getpos("'<"))
call assert_equal([0, 2, 12, 0], getpos("'>"))
call cursor(1, 4)
call feedkeys("\<S-C-End>y", 'xt')
call assert_equal([0, 1, 4, 0], getpos("'<"))
call assert_equal([0, 3, 13, 0], getpos("'>"))
" Test for <S-C-Left> and <S-C-Right>
call cursor(2, 5)
call feedkeys("\<S-C-Right>y", 'xt')
call assert_equal([0, 2, 5, 0], getpos("'<"))
call assert_equal([0, 2, 9, 0], getpos("'>"))
call cursor(2, 9)
call feedkeys("\<S-C-Left>y", 'xt')
call assert_equal([0, 2, 5, 0], getpos("'<"))
call assert_equal([0, 2, 9, 0], getpos("'>"))
set keymodel&
" clean up
bw!
endfunc
func Test_normal03_join()
" basic join test
call Setup_NewWindow()
50
norm! VJ
call assert_equal('50 51', getline('.'))
$
norm! J
call assert_equal('100', getline('.'))
$
norm! V9-gJ
call assert_equal('919293949596979899100', getline('.'))
call setline(1, range(1,100))
$
:j 10
call assert_equal('100', getline('.'))
call assert_beeps('normal GVJ')
" clean up
bw!
endfunc
" basic filter test
func Test_normal04_filter()
" only test on non windows platform
CheckNotMSWindows
call Setup_NewWindow()
1
call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
call assert_equal('| 1', getline('.'))
90
:sil :!echo one
call feedkeys('.', 'tx')
call assert_equal('| 90', getline('.'))
95
set cpo+=!
" 2 <CR>, 1: for executing the command,
" 2: clear hit-enter-prompt
call feedkeys("!!\n", 'tx')
call feedkeys(":!echo one\n\n", 'tx')
call feedkeys(".", 'tx')
call assert_equal('one', getline('.'))
set cpo-=!
bw!
endfunc
func Test_normal05_formatexpr()
" basic formatexpr test
call Setup_NewWindow()
%d_
call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
1
set formatexpr=MyFormatExpr()
norm! gqG
call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
set formatexpr=
bw!
endfunc
func Test_normal05_formatexpr_newbuf()
" Edit another buffer in the 'formatexpr' function
new
func! Format()
edit another
endfunc
set formatexpr=Format()
norm gqG
bw!
set formatexpr=
endfunc
func Test_normal05_formatexpr_setopt()
" Change the 'formatexpr' value in the function
new
func! Format()
set formatexpr=
endfunc
set formatexpr=Format()
norm gqG
bw!
set formatexpr=
endfunc
" When 'formatexpr' returns non-zero, internal formatting is used.
func Test_normal_formatexpr_returns_nonzero()
new
call setline(1, ['one', 'two'])
func! Format()
return 1
endfunc
setlocal formatexpr=Format()
normal VGgq
call assert_equal(['one two'], getline(1, '$'))
setlocal formatexpr=
delfunc Format
close!
endfunc
" basic test for formatprg
func Test_normal06_formatprg()
" only test on non windows platform
CheckNotMSWindows
" uses sed to number non-empty lines
call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
call system('chmod +x ./Xsed_format.sh')
let text = ['a', '', 'c', '', ' ', 'd', 'e']
let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
10new
call setline(1, text)
set formatprg=./Xsed_format.sh
norm! gggqG
call assert_equal(expected, getline(1, '$'))
%d
call setline(1, text)
set formatprg=donothing
setlocal formatprg=./Xsed_format.sh
norm! gggqG
call assert_equal(expected, getline(1, '$'))
%d
" Check for the command-line ranges added to 'formatprg'
set formatprg=cat
call setline(1, ['one', 'two', 'three', 'four', 'five'])
call feedkeys('gggqG', 'xt')
call assert_equal('.,$!cat', @:)
call feedkeys('2Ggq2j', 'xt')
call assert_equal('.,.+2!cat', @:)
bw!
" clean up
set formatprg=
setlocal formatprg=
call delete('Xsed_format.sh')
endfunc
func Test_normal07_internalfmt()
" basic test for internal formmatter to textwidth of 12
let list=range(1,11)
call map(list, 'v:val." "')
10new
call setline(1, list)
set tw=12
norm! ggVGgq
call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
" clean up
set tw=0
bw!
endfunc
" basic tests for foldopen/folddelete
func Test_normal08_fold()
CheckFeature folding
call Setup_NewWindow()
50
setl foldenable fdm=marker
" First fold
norm! V4jzf
" check that folds have been created
call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
" Second fold
46
norm! V10jzf
" check that folds have been created
call assert_equal('46/*{{{*/', getline(46))
call assert_equal('60/*}}}*/', getline(60))
norm! k
call assert_equal('45', getline('.'))
norm! j
call assert_equal('46/*{{{*/', getline('.'))
norm! j
call assert_equal('61', getline('.'))
norm! k
" open a fold
norm! Vzo
norm! k
call assert_equal('45', getline('.'))
norm! j
call assert_equal('46/*{{{*/', getline('.'))
norm! j
call assert_equal('47', getline('.'))
norm! k
norm! zcVzO
call assert_equal('46/*{{{*/', getline('.'))
norm! j
call assert_equal('47', getline('.'))
norm! j
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51', getline('.'))
" delete folds
:46
" collapse fold
norm! V14jzC
" delete all folds recursively
norm! VzD
call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
" clean up
setl nofoldenable fdm=marker
bw!
endfunc
func Test_normal09a_operatorfunc()
" Test operatorfunc
call Setup_NewWindow()
" Add some spaces for counting
50,60s/$/ /
unlet! g:a
let g:a=0
nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
50
norm V2j,,
call assert_equal(6, g:a)
norm V,,
call assert_equal(2, g:a)
norm ,,l
call assert_equal(0, g:a)
50
exe "norm 0\<c-v>10j2l,,"
call assert_equal(11, g:a)
50
norm V10j,,
call assert_equal(22, g:a)
" Use a lambda function for 'opfunc'
unmap <buffer> ,,
call cursor(1, 1)
let g:a=0
nmap <buffer><silent> ,, :set opfunc={type\ ->\ CountSpaces(type)}<CR>g@
vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
50
norm V2j,,
call assert_equal(6, g:a)
norm V,,
call assert_equal(2, g:a)
norm ,,l
call assert_equal(0, g:a)
50
exe "norm 0\<c-v>10j2l,,"
call assert_equal(11, g:a)
50
norm V10j,,
call assert_equal(22, g:a)
" use a partial function for 'opfunc'
let g:OpVal = 0
func! Test_opfunc1(x, y, type)
let g:OpVal = a:x + a:y
endfunc
set opfunc=function('Test_opfunc1',\ [5,\ 7])
normal! g@l
call assert_equal(12, g:OpVal)
" delete the function and try to use g@
delfunc Test_opfunc1
call test_garbagecollect_now()
call assert_fails('normal! g@l', 'E117:')
set opfunc=
" use a funcref for 'opfunc'
let g:OpVal = 0
func! Test_opfunc2(x, y, type)
let g:OpVal = a:x + a:y
endfunc
set opfunc=funcref('Test_opfunc2',\ [4,\ 3])
normal! g@l
call assert_equal(7, g:OpVal)
" delete the function and try to use g@
delfunc Test_opfunc2
call test_garbagecollect_now()
call assert_fails('normal! g@l', 'E933:')
set opfunc=
" Try to use a function with two arguments for 'operatorfunc'
let g:OpVal = 0
func! Test_opfunc3(x, y)
let g:OpVal = 4
endfunc
set opfunc=Test_opfunc3
call assert_fails('normal! g@l', 'E119:')
call assert_equal(0, g:OpVal)
set opfunc=
delfunc Test_opfunc3
unlet g:OpVal
" Try to use a lambda function with two arguments for 'operatorfunc'
set opfunc={x,\ y\ ->\ 'done'}
call assert_fails('normal! g@l', 'E119:')
" clean up
unmap <buffer> ,,
set opfunc=
unlet! g:a
bw!
endfunc
func Test_normal09b_operatorfunc()
" Test operatorfunc
call Setup_NewWindow()
" Add some spaces for counting
50,60s/$/ /
unlet! g:opt
set linebreak
nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
50
norm ,,j
exe "bd!" g:bufnr
call assert_true(&linebreak)
call assert_equal(g:opt, &linebreak)
set nolinebreak
norm ,,j
exe "bd!" g:bufnr
call assert_false(&linebreak)
call assert_equal(g:opt, &linebreak)
" clean up
unmap <buffer> ,,
set opfunc=
call assert_fails('normal Vg@', 'E774:')
bw!
unlet! g:opt
endfunc
func OperatorfuncRedo(_)
let g:opfunc_count = v:count
endfunc
func Test_normal09c_operatorfunc()
" Test redoing operatorfunc
new
call setline(1, 'some text')
set operatorfunc=OperatorfuncRedo
normal v3g@
call assert_equal(3, g:opfunc_count)
let g:opfunc_count = 0
normal .
call assert_equal(3, g:opfunc_count)
bw!
unlet g:opfunc_count
set operatorfunc=
endfunc
func Test_normal10_expand()
" Test for expand()
10new
call setline(1, ['1', 'ifooar,,cbar'])
2
norm! $
call assert_equal('cbar', expand('<cword>'))
call assert_equal('ifooar,,cbar', expand('<cWORD>'))
call setline(1, ['prx = list[idx];'])
1
let expected = ['', 'prx', 'prx', 'prx',
\ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
\ 'idx', 'idx', 'idx', 'idx',
\ 'list[idx]',
\ '];',
\ ]
for i in range(1, 16)
exe 'norm ' . i . '|'
call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
endfor
" Test for <cexpr> in state.val and ptr->val
call setline(1, 'x = state.val;')
call cursor(1, 10)
call assert_equal('state.val', expand('<cexpr>'))
call setline(1, 'x = ptr->val;')
call cursor(1, 9)
call assert_equal('ptr->val', expand('<cexpr>'))
if executable('echo')
" Test expand(`...`) i.e. backticks command expansion.
call assert_equal('abcde', expand('`echo abcde`'))
endif
" Test expand(`=...`) i.e. backticks expression expansion
call assert_equal('5', expand('`=2+3`'))
call assert_equal('3.14', expand('`=3.14`'))
" clean up
bw!
endfunc
" Test for expand() in latin1 encoding
func Test_normal_expand_latin1()
new
let save_enc = &encoding
set encoding=latin1
call setline(1, 'val = item->color;')
call cursor(1, 11)
call assert_equal('color', expand("<cword>"))
call assert_equal('item->color', expand("<cexpr>"))
let &encoding = save_enc
bw!
endfunc
func Test_normal11_showcmd()
" test for 'showcmd'
10new
exe "norm! ofoobar\<esc>"
call assert_equal(2, line('$'))
set showcmd
exe "norm! ofoobar2\<esc>"
call assert_equal(3, line('$'))
exe "norm! VAfoobar3\<esc>"
call assert_equal(3, line('$'))
exe "norm! 0d3\<del>2l"
call assert_equal('obar2foobar3', getline('.'))
" test for the visual block size displayed in the status line
call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
call feedkeys("ggl\<C-V>lljj", 'xt')
redraw!
call assert_match('3x3$', Screenline(&lines))
call feedkeys("\<C-V>", 'xt')
" test for visually selecting a multi-byte character
call setline(1, ["\U2206"])
call feedkeys("ggv", 'xt')
redraw!
call assert_match('1-3$', Screenline(&lines))
call feedkeys("v", 'xt')
" test for visually selecting the end of line
call setline(1, ["foobar"])
call feedkeys("$vl", 'xt')
redraw!
call assert_match('2$', Screenline(&lines))
call feedkeys("y", 'xt')
call assert_equal("r\n", @")
bw!
endfunc
" Test for nv_error and normal command errors
func Test_normal12_nv_error()
10new
call setline(1, range(1,5))
" should not do anything, just beep
call assert_beeps('exe "norm! <c-k>"')
call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
call assert_beeps('normal! G2dd')
call assert_beeps("normal! g\<C-A>")
call assert_beeps("normal! g\<C-X>")
call assert_beeps("normal! g\<C-B>")
call assert_beeps("normal! vQ\<Esc>")
call assert_beeps("normal! 2[[")
call assert_beeps("normal! 2]]")
call assert_beeps("normal! 2[]")
call assert_beeps("normal! 2][")
call assert_beeps("normal! 4[z")
call assert_beeps("normal! 4]z")
call assert_beeps("normal! 4[c")
call assert_beeps("normal! 4]c")
call assert_beeps("normal! 200%")
call assert_beeps("normal! %")
call assert_beeps("normal! 2{")
call assert_beeps("normal! 2}")
call assert_beeps("normal! r\<Right>")
call assert_beeps("normal! 8ry")
call assert_beeps('normal! "@')
bw!
endfunc
func Test_normal13_help()
" Test for F1
call assert_equal(1, winnr())
call feedkeys("\<f1>", 'txi')
call assert_match('help\.txt', bufname('%'))
call assert_equal(2, winnr('$'))
bw!
endfunc
func Test_normal14_page()
" basic test for Ctrl-F and Ctrl-B
call Setup_NewWindow()
exe "norm! \<c-f>"
call assert_equal('9', getline('.'))
exe "norm! 2\<c-f>"
call assert_equal('25', getline('.'))
exe "norm! 2\<c-b>"
call assert_equal('18', getline('.'))
1
set scrolloff=5
exe "norm! 2\<c-f>"
call assert_equal('21', getline('.'))
exe "norm! \<c-b>"
call assert_equal('13', getline('.'))
1
set scrolloff=99
exe "norm! \<c-f>"
call assert_equal('13', getline('.'))
set scrolloff=0
100
exe "norm! $\<c-b>"
call assert_equal('92', getline('.'))
call assert_equal([0, 92, 1, 0, 1], getcurpos())
100
set nostartofline
exe "norm! $\<c-b>"
call assert_equal('92', getline('.'))
call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
" cleanup
set startofline
bw!
endfunc
func Test_normal14_page_eol()
10new
norm oxxxxxxx
exe "norm 2\<c-f>"
" check with valgrind that cursor is put back in column 1
exe "norm 2\<c-b>"
bw!
endfunc
" Test for errors with z command
func Test_normal_z_error()
call assert_beeps('normal! z2p')
call assert_beeps('normal! zq')
endfunc
func Test_normal15_z_scroll_vert()
" basic test for z commands that scroll the window
call Setup_NewWindow()
100
norm! >>
" Test for z<cr>
exe "norm! z\<cr>"
call assert_equal(' 100', getline('.'))
call assert_equal(100, winsaveview()['topline'])
call assert_equal([0, 100, 2, 0, 9], getcurpos())
" Test for zt
21
norm! >>0zt
call assert_equal(' 21', getline('.'))
call assert_equal(21, winsaveview()['topline'])
call assert_equal([0, 21, 1, 0, 8], getcurpos())
" Test for zb
30
norm! >>$ztzb
call assert_equal(' 30', getline('.'))
call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
" Test for z-
1
30
norm! 0z-
call assert_equal(' 30', getline('.'))
call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
call assert_equal([0, 30, 2, 0, 9], getcurpos())
" Test for z{height}<cr>
call assert_equal(10, winheight(0))
exe "norm! z12\<cr>"
call assert_equal(12, winheight(0))
exe "norm! z10\<cr>"
call assert_equal(10, winheight(0))
" Test for z.
1
21
norm! 0z.
call assert_equal(' 21', getline('.'))
call assert_equal(17, winsaveview()['topline'])
call assert_equal([0, 21, 2, 0, 9], getcurpos())
" Test for zz
1
21
norm! 0zz
call assert_equal(' 21', getline('.'))
call assert_equal(17, winsaveview()['topline'])
call assert_equal([0, 21, 1, 0, 8], getcurpos())
" Test for z+
11
norm! zt
norm! z+
call assert_equal(' 21', getline('.'))
call assert_equal(21, winsaveview()['topline'])
call assert_equal([0, 21, 2, 0, 9], getcurpos())
" Test for [count]z+
1
norm! 21z+
call assert_equal(' 21', getline('.'))
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^
call assert_equal(' 21', getline('.'))
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^
call assert_equal(' 21', getline('.'))
call assert_equal(12, winsaveview()['topline'])
call assert_equal([0, 21, 2, 0, 9], getcurpos())
" cleanup
bw!
endfunc
func Test_normal16_z_scroll_hor()
" basic test for z commands that scroll the window
10new
15vsp
set nowrap listchars=
let lineA='abcdefghijklmnopqrstuvwxyz'
let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
$put =lineA
$put =lineB
1d
" Test for zl and zh with a count
norm! 0z10l
call assert_equal([11, 1], [col('.'), wincol()])
norm! z4h
call assert_equal([11, 5], [col('.'), wincol()])
normal! 2gg
" Test for zl
1
norm! 5zl
call assert_equal(lineA, getline('.'))
call assert_equal(6, col('.'))
call assert_equal(5, winsaveview()['leftcol'])
norm! yl
call assert_equal('f', @0)
" Test for zh
norm! 2zh
call assert_equal(lineA, getline('.'))
call assert_equal(6, col('.'))
norm! yl
call assert_equal('f', @0)
call assert_equal(3, winsaveview()['leftcol'])
" Test for zL
norm! zL
call assert_equal(11, col('.'))
norm! yl
call assert_equal('k', @0)
call assert_equal(10, winsaveview()['leftcol'])
norm! 2zL
call assert_equal(25, col('.'))
norm! yl
call assert_equal('y', @0)
call assert_equal(24, winsaveview()['leftcol'])
" Test for zH
norm! 2zH
call assert_equal(25, col('.'))
call assert_equal(10, winsaveview()['leftcol'])
norm! yl
call assert_equal('y', @0)
" Test for zs
norm! $zs
call assert_equal(26, col('.'))
call assert_equal(25, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
" Test for ze
norm! ze
call assert_equal(26, col('.'))
call assert_equal(11, winsaveview()['leftcol'])
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!
endfunc
func Test_normal17_z_scroll_hor2()
" basic test for z commands that scroll the window
" using 'sidescrolloff' setting
10new
20vsp
set nowrap listchars= sidescrolloff=5
let lineA='abcdefghijklmnopqrstuvwxyz'
let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
$put =lineA
$put =lineB
1d
" Test for zl
1
norm! 5zl
call assert_equal(lineA, getline('.'))
call assert_equal(11, col('.'))
call assert_equal(5, winsaveview()['leftcol'])
norm! yl
call assert_equal('k', @0)
" Test for zh
norm! 2zh
call assert_equal(lineA, getline('.'))
call assert_equal(11, col('.'))
norm! yl
call assert_equal('k', @0)
call assert_equal(3, winsaveview()['leftcol'])
" Test for zL
norm! 0zL
call assert_equal(16, col('.'))
norm! yl
call assert_equal('p', @0)
call assert_equal(10, winsaveview()['leftcol'])
norm! 2zL
call assert_equal(26, col('.'))
norm! yl
call assert_equal('z', @0)
call assert_equal(15, winsaveview()['leftcol'])
" Test for zH
norm! 2zH
call assert_equal(15, col('.'))
call assert_equal(0, winsaveview()['leftcol'])
norm! yl
call assert_equal('o', @0)
" Test for zs
norm! $zs
call assert_equal(26, col('.'))
call assert_equal(20, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
" Test for ze
norm! ze
call assert_equal(26, col('.'))
call assert_equal(11, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
" cleanup
set wrap listchars=eol:$ sidescrolloff=0
bw!
endfunc
" Test for commands that scroll the window horizontally. Test with folds.
" H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
func Test_vert_scroll_cmds()
15new
call setline(1, range(1, 100))
exe "normal! 30ggz\<CR>"
set foldenable
33,36fold
40,43fold
46,49fold
let h = winheight(0)
" Test for H, M and L commands
" Top of the screen = 30
" Folded lines = 9
" Bottom of the screen = 30 + h + 9 - 1
normal! 4L
call assert_equal(35 + h, line('.'))
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))
3,5fold
exe "normal 6G3\<C-E>"
call assert_equal(6, line('w0'))
exe "normal 2\<C-Y>"
call assert_equal(2, line('w0'))
" Test for CTRL-Y on a folded line
%d
call setline(1, range(1, 100))
exe (h + 2) .. "," .. (h + 4) .. "fold"
exe h + 5
normal z-
exe "normal \<C-Y>\<C-Y>"
call assert_equal(h + 1, line('w$'))
" Test for CTRL-Y from the first line and CTRL-E from the last line
%d
set scrolloff=2