Skip to content

Commit 3e72dca

Browse files
committed
patch 8.2.2901: some operators not fully tested
Problem: Some operators not fully tested. Solution: Add a few test cases. (Yegappan Lakshmanan, closes #8282)
1 parent 1174b01 commit 3e72dca

6 files changed

Lines changed: 167 additions & 12 deletions

File tree

src/testdir/test_cpoptions.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func Test_cpo_E()
167167
call assert_beeps('normal "ayl')
168168
" change an empty line
169169
call assert_beeps('normal lcTa')
170+
call assert_beeps('normal 0c0')
170171
" delete an empty line
171172
call assert_beeps('normal D')
172173
call assert_beeps('normal dl')

src/testdir/test_increment.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,4 +876,21 @@ func Test_normal_increment_with_virtualedit()
876876
set virtualedit&
877877
endfunc
878878

879+
" Test for incrementing a signed hexadecimal and octal number
880+
func Test_normal_increment_signed_hexoct_nr()
881+
new
882+
" negative sign before a hex number should be ignored
883+
call setline(1, ["-0x9"])
884+
exe "norm \<C-A>"
885+
call assert_equal(["-0xa"], getline(1, '$'))
886+
exe "norm \<C-X>"
887+
call assert_equal(["-0x9"], getline(1, '$'))
888+
call setline(1, ["-007"])
889+
exe "norm \<C-A>"
890+
call assert_equal(["-010"], getline(1, '$'))
891+
exe "norm \<C-X>"
892+
call assert_equal(["-007"], getline(1, '$'))
893+
bw!
894+
endfunc
895+
879896
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_normal.vim

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,16 @@ func Test_normal30_changecase()
19861986
call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
19871987
set whichwrap&
19881988

1989+
" try changing the case with a double byte encoding (DBCS)
1990+
%bw!
1991+
let enc = &enc
1992+
set encoding=cp932
1993+
call setline(1, "\u8470")
1994+
normal ~
1995+
normal gU$gu$gUgUg~g~gugu
1996+
call assert_equal("\u8470", getline(1))
1997+
let &encoding = enc
1998+
19891999
" clean up
19902000
bw!
19912001
endfunc
@@ -3324,4 +3334,25 @@ func Test_normal_percent_jump()
33243334
close!
33253335
endfunc
33263336

3337+
" Test for << and >> commands to shift text by 'shiftwidth'
3338+
func Test_normal_shift_rightleft()
3339+
new
3340+
call setline(1, ['one', '', "\t", ' two', "\tthree", ' four'])
3341+
set shiftwidth=2 tabstop=8
3342+
normal gg6>>
3343+
call assert_equal([' one', '', "\t ", ' two', "\t three", "\tfour"],
3344+
\ getline(1, '$'))
3345+
normal ggVG2>>
3346+
call assert_equal([' one', '', "\t ", "\ttwo",
3347+
\ "\t three", "\t four"], getline(1, '$'))
3348+
normal gg6<<
3349+
call assert_equal([' one', '', "\t ", ' two', "\t three",
3350+
\ "\t four"], getline(1, '$'))
3351+
normal ggVG2<<
3352+
call assert_equal(['one', '', "\t", ' two', "\tthree", ' four'],
3353+
\ getline(1, '$'))
3354+
set shiftwidth& tabstop&
3355+
bw!
3356+
endfunc
3357+
33273358
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_virtualedit.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func Test_edit_change()
8080
call setline(1, "\t")
8181
normal Cx
8282
call assert_equal('x', getline(1))
83+
" Do a visual block change
84+
call setline(1, ['a', 'b', 'c'])
85+
exe "normal gg3l\<C-V>2jcx"
86+
call assert_equal(['a x', 'b x', 'c x'], getline(1, '$'))
8387
bwipe!
8488
set virtualedit=
8589
endfunc
@@ -289,6 +293,16 @@ func Test_replace_after_eol()
289293
call append(0, '"r"')
290294
normal gg$5lrxa
291295
call assert_equal('"r" x', getline(1))
296+
" visual block replace
297+
%d _
298+
call setline(1, ['a', '', 'b'])
299+
exe "normal 2l\<C-V>2jrx"
300+
call assert_equal(['a x', ' x', 'b x'], getline(1, '$'))
301+
" visual characterwise selection replace after eol
302+
%d _
303+
call setline(1, 'a')
304+
normal 4lv2lrx
305+
call assert_equal('a xxx', getline(1))
292306
bwipe!
293307
set virtualedit=
294308
endfunc
@@ -375,4 +389,17 @@ func Test_ve_backspace()
375389
close!
376390
endfunc
377391

392+
" Test for delete (x) on EOL character and after EOL
393+
func Test_delete_past_eol()
394+
new
395+
call setline(1, "ab")
396+
set virtualedit=all
397+
exe "normal 2lx"
398+
call assert_equal('ab', getline(1))
399+
exe "normal 10lx"
400+
call assert_equal('ab', getline(1))
401+
set virtualedit&
402+
bw!
403+
endfunc
404+
378405
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_visual.vim

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ func Test_visual_mode_reset()
8181
" thus preventing the problem:
8282
exe "normal! GV:call TriggerTheProblem()\<CR>"
8383
call assert_equal("Everything's fine.", g:msg)
84-
8584
endfunc
8685

8786
" Test for visual block shift and tab characters.
8887
func Test_block_shift_tab()
89-
enew!
88+
new
9089
call append(0, repeat(['one two three'], 5))
9190
call cursor(1,1)
9291
exe "normal i\<C-G>u"
@@ -95,7 +94,7 @@ func Test_block_shift_tab()
9594
call assert_equal('on1 two three', getline(2))
9695
call assert_equal('on1 two three', getline(5))
9796

98-
enew!
97+
%d _
9998
call append(0, repeat(['abcdefghijklmnopqrstuvwxyz'], 5))
10099
call cursor(1,1)
101100
exe "normal \<C-V>4jI \<Esc>j<<11|D"
@@ -120,12 +119,26 @@ func Test_block_shift_tab()
120119
call assert_equal(" abc\<Tab>\<Tab>defghijklmnopqrstuvwxyz", getline(4))
121120
call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5))
122121

123-
enew!
122+
" Test for block shift with space characters at the beginning and with
123+
" 'noexpandtab' and 'expandtab'
124+
%d _
125+
call setline(1, [" 1", " 2", " 3"])
126+
setlocal shiftwidth=2 noexpandtab
127+
exe "normal gg\<C-V>3j>"
128+
call assert_equal(["\t1", "\t2", "\t3"], getline(1, '$'))
129+
%d _
130+
call setline(1, [" 1", " 2", " 3"])
131+
setlocal shiftwidth=2 expandtab
132+
exe "normal gg\<C-V>3j>"
133+
call assert_equal([" 1", " 2", " 3"], getline(1, '$'))
134+
setlocal shiftwidth&
135+
136+
bw!
124137
endfunc
125138

126139
" Tests Blockwise Visual when there are TABs before the text.
127140
func Test_blockwise_visual()
128-
enew!
141+
new
129142
call append(0, ['123456',
130143
\ '234567',
131144
\ '345678',
@@ -147,12 +160,12 @@ func Test_blockwise_visual()
147160
\ "\t\tsomext",
148161
\ "\t\ttesext"], getline(1, 7))
149162

150-
enew!
163+
bw!
151164
endfunc
152165

153166
" Test swapping corners in blockwise visual mode with o and O
154167
func Test_blockwise_visual_o_O()
155-
enew!
168+
new
156169

157170
exe "norm! 10i.\<Esc>Y4P3lj\<C-V>4l2jr "
158171
exe "norm! gvO\<Esc>ra"
@@ -171,7 +184,7 @@ func Test_blockwise_visual_o_O()
171184
\ '...a bf.',
172185
\ '..........'], getline(1, '$'))
173186

174-
enew!
187+
bw!
175188
endfun
176189

177190
" Test Virtual replace mode.
@@ -459,15 +472,13 @@ endfunc
459472

460473
" Test for 'p'ut in visual block mode
461474
func Test_visual_block_put()
462-
enew
463-
475+
new
464476
call append(0, ['One', 'Two', 'Three'])
465477
normal gg
466478
yank
467479
call feedkeys("jl\<C-V>ljp", 'xt')
468480
call assert_equal(['One', 'T', 'Tee', 'One', ''], getline(1, '$'))
469-
470-
enew!
481+
bw!
471482
endfunc
472483

473484
" Visual modes (v V CTRL-V) followed by an operator; count; repeating
@@ -646,6 +657,12 @@ func Test_characterwise_visual_mode()
646657
norm! G1vy
647658
call assert_equal('four', @")
648659

660+
" characterwise visual mode: replace a single character line and the eol
661+
%d _
662+
call setline(1, "a")
663+
normal v$rx
664+
call assert_equal(['x'], getline(1, '$'))
665+
649666
bwipe!
650667
endfunc
651668

@@ -741,6 +758,66 @@ func Test_visual_block_mode()
741758
exe "normal! \<C-V>j2lD"
742759
call assert_equal(['ax', 'ax'], getline(3, 4))
743760

761+
" Test block insert with a short line that ends before the block
762+
%d _
763+
call setline(1, [" one", "a", " two"])
764+
exe "normal gg\<C-V>2jIx"
765+
call assert_equal([" xone", "a", " xtwo"], getline(1, '$'))
766+
767+
" Test block append at EOL with '$' and without '$'
768+
%d _
769+
call setline(1, ["one", "a", "two"])
770+
exe "normal gg$\<C-V>2jAx"
771+
call assert_equal(["onex", "ax", "twox"], getline(1, '$'))
772+
%d _
773+
call setline(1, ["one", "a", "two"])
774+
exe "normal gg3l\<C-V>2jAx"
775+
call assert_equal(["onex", "a x", "twox"], getline(1, '$'))
776+
777+
" Test block replace with an empty line in the middle and use $ to jump to
778+
" the end of the line.
779+
%d _
780+
call setline(1, ['one', '', 'two'])
781+
exe "normal gg$\<C-V>2jrx"
782+
call assert_equal(["onx", "", "twx"], getline(1, '$'))
783+
784+
" Test block replace with an empty line in the middle and move cursor to the
785+
" end of the line
786+
%d _
787+
call setline(1, ['one', '', 'two'])
788+
exe "normal gg2l\<C-V>2jrx"
789+
call assert_equal(["onx", "", "twx"], getline(1, '$'))
790+
791+
" Replace odd number of characters with a multibyte character
792+
%d _
793+
call setline(1, ['abcd', 'efgh'])
794+
exe "normal ggl\<C-V>2ljr\u1100"
795+
call assert_equal(["a\u1100 ", "e\u1100 "], getline(1, '$'))
796+
797+
" During visual block append, if the cursor moved outside of the selected
798+
" range, then the edit should not be applied to the block.
799+
%d _
800+
call setline(1, ['aaa', 'bbb', 'ccc'])
801+
exe "normal 2G\<C-V>jAx\<Up>"
802+
call assert_equal(['aaa', 'bxbb', 'ccc'], getline(1, '$'))
803+
804+
" During visual block append, if the cursor is moved before the start of the
805+
" block, then the new text should be appended there.
806+
%d _
807+
call setline(1, ['aaa', 'bbb', 'ccc'])
808+
exe "normal $\<C-V>2jA\<Left>x"
809+
" BUG: Instead of adding x as the third character in all the three lines,
810+
" 'a' is added in the second and third lines at the end. This bug is not
811+
" reproducible if this operation is performed manually.
812+
"call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
813+
call assert_equal(['aaxa', 'bbba', 'ccca'], getline(1, '$'))
814+
815+
" Change a characterwise motion to a blockwise motion using CTRL-V
816+
%d _
817+
call setline(1, ['123', '456', '789'])
818+
exe "normal ld\<C-V>j"
819+
call assert_equal(['13', '46', '789'], getline(1, '$'))
820+
744821
bwipe!
745822
endfunc
746823

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+
2901,
753755
/**/
754756
2900,
755757
/**/

0 commit comments

Comments
 (0)