@@ -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-
8584endfunc
8685
8786" Test for visual block shift and tab characters.
8887func 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 ([" \t 1" , " \t 2" , " \t 3" ], 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 !
124137endfunc
125138
126139" Tests Blockwise Visual when there are TABs before the text.
127140func 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\t somext" ,
148161 \ " \t\t tesext" ], getline (1 , 7 ))
149162
150- enew !
163+ bw !
151164endfunc
152165
153166" Test swapping corners in blockwise visual mode with o and O
154167func 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 !
175188endfun
176189
177190" Test Virtual replace mode.
@@ -459,15 +472,13 @@ endfunc
459472
460473" Test for 'p'ut in visual block mode
461474func 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 !
471482endfunc
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!
650667endfunc
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!
745822endfunc
746823
0 commit comments