Skip to content

Commit 2ac7184

Browse files
yegappanbrammool
authored andcommitted
patch 8.2.2916: operators are not fully tested
Problem: Operators are not fully tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes #8290)
1 parent ef8706f commit 2ac7184

5 files changed

Lines changed: 166 additions & 1 deletion

File tree

src/ops.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,9 +2383,10 @@ op_addsub(
23832383
#ifdef FEAT_NETBEANS_INTG
23842384
if (netbeans_active() && one_change)
23852385
{
2386-
char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
2386+
char_u *ptr;
23872387

23882388
netbeans_removed(curbuf, pos.lnum, pos.col, (long)length);
2389+
ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
23892390
netbeans_inserted(curbuf, pos.lnum, pos.col,
23902391
&ptr[pos.col], length);
23912392
}

src/testdir/test_netbeans.vim

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,46 @@ func Nb_basic(port)
367367
call assert_match('2:insert=\d\+ 26 "\t"', l[-1])
368368
let g:last += 18
369369

370+
" Test for changing case of multiple lines using ~
371+
normal ggVG~
372+
call WaitFor('len(ReadXnetbeans()) >= (g:last + 6)')
373+
let l = ReadXnetbeans()
374+
call assert_match('2:remove=\d\+ 0 8', l[-6])
375+
call assert_match('2:insert=\d\+ 0 "FOO BAR2"', l[-5])
376+
call assert_match('2:remove=\d\+ 9 8', l[-4])
377+
call assert_match('2:insert=\d\+ 9 "BLUE SKy"', l[-3])
378+
call assert_match('2:remove=\d\+ 18 9', l[-2])
379+
call assert_match('2:insert=\d\+ 18 "\tFOO BAR3"', l[-1])
380+
let g:last += 6
381+
382+
" Test for changing case of a visual block using ~
383+
exe "normal ggw\<C-V>$~"
384+
call WaitFor('len(ReadXnetbeans()) >= (g:last + 2)')
385+
let l = ReadXnetbeans()
386+
call assert_match('2:remove=\d\+ 4 4', l[-2])
387+
call assert_match('2:insert=\d\+ 4 "bar2"', l[-1])
388+
let g:last += 2
389+
390+
" Increment a number using <C-A> in visual mode
391+
exe "normal! gg$v6\<C-A>"
392+
call WaitFor('len(ReadXnetbeans()) >= (g:last + 6)')
393+
let l = ReadXnetbeans()
394+
call assert_match('2:remove=\d\+ 0 9', l[-4])
395+
call assert_match('2:insert=\d\+ 0 "FOO bar8"', l[-3])
396+
call assert_match('2:remove=\d\+ 7 1', l[-2])
397+
call assert_match('2:insert=\d\+ 7 "8"', l[-1])
398+
let g:last += 6
399+
400+
" Decrement a number using <C-X> in visual mode
401+
exe "normal! gg$v3\<C-X>"
402+
call WaitFor('len(ReadXnetbeans()) >= (g:last + 6)')
403+
let l = ReadXnetbeans()
404+
call assert_match('2:remove=\d\+ 0 9', l[-4])
405+
call assert_match('2:insert=\d\+ 0 "FOO bar5"', l[-3])
406+
call assert_match('2:remove=\d\+ 7 1', l[-2])
407+
call assert_match('2:insert=\d\+ 7 "5"', l[-1])
408+
let g:last += 6
409+
370410
" stopDocumentListen test
371411
call appendbufline(cmdbufnr, '$', 'stopDocumentListen_Test')
372412
call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)')

src/testdir/test_normal.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,4 +3377,34 @@ func Test_normal_shift_rightleft()
33773377
bw!
33783378
endfunc
33793379

3380+
" Some commands like yy, cc, dd, >>, << and !! accept a count after
3381+
" typing the first letter of the command.
3382+
func Test_normal_count_after_operator()
3383+
new
3384+
setlocal shiftwidth=4 tabstop=8 autoindent
3385+
call setline(1, ['one', 'two', 'three', 'four', 'five'])
3386+
let @a = ''
3387+
normal! j"ay4y
3388+
call assert_equal("two\nthree\nfour\nfive\n", @a)
3389+
normal! 3G>2>
3390+
call assert_equal(['one', 'two', ' three', ' four', 'five'],
3391+
\ getline(1, '$'))
3392+
exe "normal! 3G0c2cred\nblue"
3393+
call assert_equal(['one', 'two', ' red', ' blue', 'five'],
3394+
\ getline(1, '$'))
3395+
exe "normal! gg<8<"
3396+
call assert_equal(['one', 'two', 'red', 'blue', 'five'],
3397+
\ getline(1, '$'))
3398+
exe "normal! ggd3d"
3399+
call assert_equal(['blue', 'five'], getline(1, '$'))
3400+
call setline(1, range(1, 4))
3401+
call feedkeys("gg!3!\<C-B>\"\<CR>", 'xt')
3402+
call assert_equal('".,.+2!', @:)
3403+
call feedkeys("gg!1!\<C-B>\"\<CR>", 'xt')
3404+
call assert_equal('".!', @:)
3405+
call feedkeys("gg!9!\<C-B>\"\<CR>", 'xt')
3406+
call assert_equal('".,$!', @:)
3407+
bw!
3408+
endfunc
3409+
33803410
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_visual.vim

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,99 @@ func Test_visual_block_mode()
818818
exe "normal ld\<C-V>j"
819819
call assert_equal(['13', '46', '789'], getline(1, '$'))
820820

821+
" Test from ':help v_b_I_example'
822+
%d _
823+
setlocal tabstop=8 shiftwidth=4
824+
let lines =<< trim END
825+
abcdefghijklmnopqrstuvwxyz
826+
abc defghijklmnopqrstuvwxyz
827+
abcdef ghi jklmnopqrstuvwxyz
828+
abcdefghijklmnopqrstuvwxyz
829+
END
830+
call setline(1, lines)
831+
exe "normal ggfo\<C-V>3jISTRING"
832+
let expected =<< trim END
833+
abcdefghijklmnSTRINGopqrstuvwxyz
834+
abc STRING defghijklmnopqrstuvwxyz
835+
abcdef ghi STRING jklmnopqrstuvwxyz
836+
abcdefghijklmnSTRINGopqrstuvwxyz
837+
END
838+
call assert_equal(expected, getline(1, '$'))
839+
840+
" Test from ':help v_b_A_example'
841+
%d _
842+
let lines =<< trim END
843+
abcdefghijklmnopqrstuvwxyz
844+
abc defghijklmnopqrstuvwxyz
845+
abcdef ghi jklmnopqrstuvwxyz
846+
abcdefghijklmnopqrstuvwxyz
847+
END
848+
call setline(1, lines)
849+
exe "normal ggfo\<C-V>3j$ASTRING"
850+
let expected =<< trim END
851+
abcdefghijklmnopqrstuvwxyzSTRING
852+
abc defghijklmnopqrstuvwxyzSTRING
853+
abcdef ghi jklmnopqrstuvwxyzSTRING
854+
abcdefghijklmnopqrstuvwxyzSTRING
855+
END
856+
call assert_equal(expected, getline(1, '$'))
857+
858+
" Test from ':help v_b_<_example'
859+
%d _
860+
let lines =<< trim END
861+
abcdefghijklmnopqrstuvwxyz
862+
abc defghijklmnopqrstuvwxyz
863+
abcdef ghi jklmnopqrstuvwxyz
864+
abcdefghijklmnopqrstuvwxyz
865+
END
866+
call setline(1, lines)
867+
exe "normal ggfo\<C-V>3j3l<.."
868+
let expected =<< trim END
869+
abcdefghijklmnopqrstuvwxyz
870+
abc defghijklmnopqrstuvwxyz
871+
abcdef ghi jklmnopqrstuvwxyz
872+
abcdefghijklmnopqrstuvwxyz
873+
END
874+
call assert_equal(expected, getline(1, '$'))
875+
876+
" Test from ':help v_b_>_example'
877+
%d _
878+
let lines =<< trim END
879+
abcdefghijklmnopqrstuvwxyz
880+
abc defghijklmnopqrstuvwxyz
881+
abcdef ghi jklmnopqrstuvwxyz
882+
abcdefghijklmnopqrstuvwxyz
883+
END
884+
call setline(1, lines)
885+
exe "normal ggfo\<C-V>3j>.."
886+
let expected =<< trim END
887+
abcdefghijklmn opqrstuvwxyz
888+
abc defghijklmnopqrstuvwxyz
889+
abcdef ghi jklmnopqrstuvwxyz
890+
abcdefghijklmn opqrstuvwxyz
891+
END
892+
call assert_equal(expected, getline(1, '$'))
893+
894+
" Test from ':help v_b_r_example'
895+
%d _
896+
let lines =<< trim END
897+
abcdefghijklmnopqrstuvwxyz
898+
abc defghijklmnopqrstuvwxyz
899+
abcdef ghi jklmnopqrstuvwxyz
900+
abcdefghijklmnopqrstuvwxyz
901+
END
902+
call setline(1, lines)
903+
exe "normal ggfo\<C-V>5l3jrX"
904+
let expected =<< trim END
905+
abcdefghijklmnXXXXXXuvwxyz
906+
abc XXXXXXhijklmnopqrstuvwxyz
907+
abcdef ghi XXXXXX jklmnopqrstuvwxyz
908+
abcdefghijklmnXXXXXXuvwxyz
909+
END
910+
call assert_equal(expected, getline(1, '$'))
911+
821912
bwipe!
913+
set tabstop& shiftwidth&
822914
endfunc
823915

824916
" Test block-insert using cursor keys for movement

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2916,
753755
/**/
754756
2915,
755757
/**/

0 commit comments

Comments
 (0)