1" Tests for various Visual modes. 2 3func Test_block_shift_multibyte() 4 " Uses double-wide character. 5 split 6 call setline(1, ['xヹxxx', 'ヹxxx']) 7 exe "normal 1G0l\<C-V>jl>" 8 call assert_equal('x ヹxxx', getline(1)) 9 call assert_equal(' ヹxxx', getline(2)) 10 q! 11endfunc 12 13func Test_block_shift_overflow() 14 " This used to cause a multiplication overflow followed by a crash. 15 new 16 normal ii 17 exe "normal \<C-V>876543210>" 18 q! 19endfunc 20 21func Test_dotregister_paste() 22 new 23 exe "norm! ihello world\<esc>" 24 norm! 0ve".p 25 call assert_equal('hello world world', getline(1)) 26 q! 27endfunc 28 29func Test_Visual_ctrl_o() 30 new 31 call setline(1, ['one', 'two', 'three']) 32 call cursor(1,2) 33 set noshowmode 34 set tw=0 35 call feedkeys("\<c-v>jjlIa\<c-\>\<c-o>:set tw=88\<cr>\<esc>", 'tx') 36 call assert_equal(['oane', 'tawo', 'tahree'], getline(1, 3)) 37 call assert_equal(88, &tw) 38 set tw& 39 bw! 40endfu 41 42func Test_Visual_vapo() 43 new 44 normal oxx 45 normal vapo 46 bwipe! 47endfunc 48 49func Test_Visual_inner_quote() 50 new 51 normal oxX 52 normal vki' 53 bwipe! 54endfunc 55 56" Test for Visual mode not being reset causing E315 error. 57func TriggerTheProblem() 58 " At this point there is no visual selection because :call reset it. 59 " Let's restore the selection: 60 normal gv 61 '<,'>del _ 62 try 63 exe "normal \<Esc>" 64 catch /^Vim\%((\a\+)\)\=:E315/ 65 echom 'Snap! E315 error!' 66 let g:msg = 'Snap! E315 error!' 67 endtry 68endfunc 69 70func Test_visual_mode_reset() 71 enew 72 let g:msg = "Everything's fine." 73 enew 74 setl buftype=nofile 75 call append(line('$'), 'Delete this line.') 76 77 " NOTE: this has to be done by a call to a function because executing :del 78 " the ex-way will require the colon operator which resets the visual mode 79 " thus preventing the problem: 80 exe "normal! GV:call TriggerTheProblem()\<CR>" 81 call assert_equal("Everything's fine.", g:msg) 82 83endfunc 84 85" Test for visual block shift and tab characters. 86func Test_block_shift_tab() 87 enew! 88 call append(0, repeat(['one two three'], 5)) 89 call cursor(1,1) 90 exe "normal i\<C-G>u" 91 exe "normal fe\<C-V>4jR\<Esc>ugvr1" 92 call assert_equal('on1 two three', getline(1)) 93 call assert_equal('on1 two three', getline(2)) 94 call assert_equal('on1 two three', getline(5)) 95 96 enew! 97 call append(0, repeat(['abcdefghijklmnopqrstuvwxyz'], 5)) 98 call cursor(1,1) 99 exe "normal \<C-V>4jI \<Esc>j<<11|D" 100 exe "normal j7|a\<Tab>\<Tab>" 101 exe "normal j7|a\<Tab>\<Tab> " 102 exe "normal j7|a\<Tab> \<Tab>\<Esc>4k13|\<C-V>4j<" 103 call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1)) 104 call assert_equal('abcdefghij', getline(2)) 105 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3)) 106 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(4)) 107 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5)) 108 109 %s/\s\+//g 110 call cursor(1,1) 111 exe "normal \<C-V>4jI \<Esc>j<<" 112 exe "normal j7|a\<Tab>\<Tab>" 113 exe "normal j7|a\<Tab>\<Tab>\<Tab>\<Tab>\<Tab>" 114 exe "normal j7|a\<Tab> \<Tab>\<Tab>\<Esc>4k13|\<C-V>4j3<" 115 call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1)) 116 call assert_equal('abcdefghij', getline(2)) 117 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3)) 118 call assert_equal(" abc\<Tab>\<Tab>defghijklmnopqrstuvwxyz", getline(4)) 119 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5)) 120 121 enew! 122endfunc 123 124" Tests Blockwise Visual when there are TABs before the text. 125func Test_blockwise_visual() 126 enew! 127 call append(0, ['123456', 128 \ '234567', 129 \ '345678', 130 \ '', 131 \ 'test text test tex start here', 132 \ "\t\tsome text", 133 \ "\t\ttest text", 134 \ 'test text']) 135 call cursor(1,1) 136 exe "normal /start here$\<CR>" 137 exe 'normal "by$' . "\<C-V>jjlld" 138 exe "normal /456$\<CR>" 139 exe "normal \<C-V>jj" . '"bP' 140 call assert_equal(['123start here56', 141 \ '234start here67', 142 \ '345start here78', 143 \ '', 144 \ 'test text test tex rt here', 145 \ "\t\tsomext", 146 \ "\t\ttesext"], getline(1, 7)) 147 148 enew! 149endfunc 150 151" Test swapping corners in blockwise visual mode with o and O 152func Test_blockwise_visual_o_O() 153 enew! 154 155 exe "norm! 10i.\<Esc>Y4P3lj\<C-V>4l2jr " 156 exe "norm! gvO\<Esc>ra" 157 exe "norm! gvO\<Esc>rb" 158 exe "norm! gvo\<C-c>rc" 159 exe "norm! gvO\<C-c>rd" 160 set selection=exclusive 161 exe "norm! gvOo\<C-c>re" 162 call assert_equal('...a be.', getline(4)) 163 exe "norm! gvOO\<C-c>rf" 164 set selection& 165 166 call assert_equal(['..........', 167 \ '...c d..', 168 \ '... ..', 169 \ '...a bf.', 170 \ '..........'], getline(1, '$')) 171 172 enew! 173endfun 174 175" Test Virtual replace mode. 176func Test_virtual_replace() 177 if exists('&t_kD') 178 let save_t_kD = &t_kD 179 endif 180 if exists('&t_kb') 181 let save_t_kb = &t_kb 182 endif 183 exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08" 184 enew! 185 exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" 186 call cursor(1,1) 187 set ai bs=2 188 exe "normal gR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" 189 call assert_equal([' 1', 190 \ ' A', 191 \ ' BCDEFGHIJ', 192 \ ' KL', 193 \ ' MNO', 194 \ ' PQR', 195 \ ], getline(1, 6)) 196 normal G 197 mark a 198 exe "normal o0\<C-D>\nabcdefghi\njk\tlmn\n opq\trst\n\<C-D>uvwxyz\n" 199 exe "normal 'ajgR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" . repeat("\<BS>", 29) 200 call assert_equal([' 1', 201 \ 'abcdefghi', 202 \ 'jk lmn', 203 \ ' opq rst', 204 \ 'uvwxyz'], getline(7, 11)) 205 normal G 206 exe "normal iab\tcdefghi\tjkl" 207 exe "normal 0gRAB......CDEFGHI.J\<Esc>o" 208 exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR" 209 call assert_equal(['AB......CDEFGHI.Jkl', 210 \ 'AB IJKLMNO QRst'], getline(12, 13)) 211 enew! 212 set noai bs&vim 213 if exists('save_t_kD') 214 let &t_kD = save_t_kD 215 endif 216 if exists('save_t_kb') 217 let &t_kb = save_t_kb 218 endif 219endfunc 220 221" Test Virtual replace mode. 222func Test_virtual_replace2() 223 enew! 224 set bs=2 225 exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" 226 call cursor(1,1) 227 " Test 1: Test that del deletes the newline 228 exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" 229 call assert_equal(['0 1', 230 \ 'A', 231 \ 'BCDEFGHIJ', 232 \ ' KL', 233 \ 'MNO', 234 \ 'PQR', 235 \ ], getline(1, 6)) 236 " Test 2: 237 " a newline is not deleted, if no newline has been added in virtual replace mode 238 %d_ 239 call setline(1, ['abcd', 'efgh', 'ijkl']) 240 call cursor(2,1) 241 exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>" 242 call assert_equal(['abcd', 243 \ '123h', 244 \ 'ijkl'], getline(1, '$')) 245 " Test 3: 246 " a newline is deleted, if a newline has been inserted before in virtual replace mode 247 %d_ 248 call setline(1, ['abcd', 'efgh', 'ijkl']) 249 call cursor(2,1) 250 exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>" 251 call assert_equal(['abcd', 252 \ '1234', 253 \ 'ijkl'], getline(1, '$')) 254 " Test 4: 255 " delete add a newline, delete it, add it again and check undo 256 %d_ 257 call setline(1, ['abcd', 'efgh', 'ijkl']) 258 call cursor(2,1) 259 " break undo sequence explicitly 260 let &ul = &ul 261 exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>" 262 let &ul = &ul 263 call assert_equal(['abcd', 264 \ '123456', 265 \ ''], getline(1, '$')) 266 norm! u 267 call assert_equal(['abcd', 268 \ 'efgh', 269 \ 'ijkl'], getline(1, '$')) 270 271 " Test for truncating spaces in a newly added line using 'autoindent' if 272 " characters are not added to that line. 273 %d_ 274 call setline(1, [' app', ' bee', ' cat']) 275 setlocal autoindent 276 exe "normal gg$gRt\n\nr" 277 call assert_equal([' apt', '', ' rat'], getline(1, '$')) 278 279 " clean up 280 %d_ 281 set bs&vim 282endfunc 283 284func Test_Visual_word_textobject() 285 new 286 call setline(1, ['First sentence. Second sentence.']) 287 288 " When start and end of visual area are identical, 'aw' or 'iw' select 289 " the whole word. 290 norm! 1go2fcvawy 291 call assert_equal('Second ', @") 292 norm! 1go2fcviwy 293 call assert_equal('Second', @") 294 295 " When start and end of visual area are not identical, 'aw' or 'iw' 296 " extend the word in direction of the end of the visual area. 297 norm! 1go2fcvlawy 298 call assert_equal('cond ', @") 299 norm! gv2awy 300 call assert_equal('cond sentence.', @") 301 302 norm! 1go2fcvliwy 303 call assert_equal('cond', @") 304 norm! gv2iwy 305 call assert_equal('cond sentence', @") 306 307 " Extend visual area in opposite direction. 308 norm! 1go2fcvhawy 309 call assert_equal(' Sec', @") 310 norm! gv2awy 311 call assert_equal(' sentence. Sec', @") 312 313 norm! 1go2fcvhiwy 314 call assert_equal('Sec', @") 315 norm! gv2iwy 316 call assert_equal('. Sec', @") 317 318 bwipe! 319endfunc 320 321func Test_Visual_sentence_textobject() 322 new 323 call setline(1, ['First sentence. Second sentence. Third', 'sentence. Fourth sentence']) 324 325 " When start and end of visual area are identical, 'as' or 'is' select 326 " the whole sentence. 327 norm! 1gofdvasy 328 call assert_equal('Second sentence. ', @") 329 norm! 1gofdvisy 330 call assert_equal('Second sentence.', @") 331 332 " When start and end of visual area are not identical, 'as' or 'is' 333 " extend the sentence in direction of the end of the visual area. 334 norm! 1gofdvlasy 335 call assert_equal('d sentence. ', @") 336 norm! gvasy 337 call assert_equal("d sentence. Third\nsentence. ", @") 338 339 norm! 1gofdvlisy 340 call assert_equal('d sentence.', @") 341 norm! gvisy 342 call assert_equal('d sentence. ', @") 343 norm! gvisy 344 call assert_equal("d sentence. Third\nsentence.", @") 345 346 " Extend visual area in opposite direction. 347 norm! 1gofdvhasy 348 call assert_equal(' Second', @") 349 norm! gvasy 350 call assert_equal("First sentence. Second", @") 351 352 norm! 1gofdvhisy 353 call assert_equal('Second', @") 354 norm! gvisy 355 call assert_equal(' Second', @") 356 norm! gvisy 357 call assert_equal('First sentence. Second', @") 358 359 bwipe! 360endfunc 361 362func Test_Visual_paragraph_textobject() 363 new 364 call setline(1, ['First line.', 365 \ '', 366 \ 'Second line.', 367 \ 'Third line.', 368 \ 'Fourth line.', 369 \ 'Fifth line.', 370 \ '', 371 \ 'Sixth line.']) 372 373 " When start and end of visual area are identical, 'ap' or 'ip' select 374 " the whole paragraph. 375 norm! 4ggvapy 376 call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n\n", @") 377 norm! 4ggvipy 378 call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n", @") 379 380 " When start and end of visual area are not identical, 'ap' or 'ip' 381 " extend the sentence in direction of the end of the visual area. 382 " FIXME: actually, it is not sufficient to have different start and 383 " end of visual selection, the start line and end line have to differ, 384 " which is not consistent with the documentation. 385 norm! 4ggVjapy 386 call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") 387 norm! gvapy 388 call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") 389 norm! 4ggVjipy 390 call assert_equal("Third line.\nFourth line.\nFifth line.\n", @") 391 norm! gvipy 392 call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") 393 norm! gvipy 394 call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") 395 396 " Extend visual area in opposite direction. 397 norm! 5ggVkapy 398 call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") 399 norm! gvapy 400 call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") 401 norm! 5ggVkipy 402 call assert_equal("Second line.\nThird line.\nFourth line.\n", @") 403 norma gvipy 404 call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") 405 norm! gvipy 406 call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") 407 408 bwipe! 409endfunc 410 411func Test_curswant_not_changed() 412 new 413 call setline(1, ['one', 'two']) 414 au InsertLeave * call getcurpos() 415 call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt') 416 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 417 418 bwipe! 419 au! InsertLeave 420endfunc 421 422" Tests for "vaBiB", end could be wrong. 423func Test_Visual_Block() 424 new 425 a 426- Bug in "vPPPP" on this text: 427 { 428 cmd; 429 { 430 cmd;\t/* <-- Start cursor here */ 431 { 432 } 433 } 434 } 435. 436 normal gg 437 call search('Start cursor here') 438 normal vaBiBD 439 call assert_equal(['- Bug in "vPPPP" on this text:', 440 \ "\t{", 441 \ "\t}"], getline(1, '$')) 442 443 close! 444endfunc 445 446" Test for 'p'ut in visual block mode 447func Test_visual_block_put() 448 enew 449 450 call append(0, ['One', 'Two', 'Three']) 451 normal gg 452 yank 453 call feedkeys("jl\<C-V>ljp", 'xt') 454 call assert_equal(['One', 'T', 'Tee', 'One', ''], getline(1, '$')) 455 456 enew! 457endfunc 458 459" Visual modes (v V CTRL-V) followed by an operator; count; repeating 460func Test_visual_mode_op() 461 new 462 call append(0, '') 463 464 call setline(1, 'apple banana cherry') 465 call cursor(1, 1) 466 normal lvld.l3vd. 467 call assert_equal('a y', getline(1)) 468 469 call setline(1, ['line 1 line 1', 'line 2 line 2', 'line 3 line 3', 470 \ 'line 4 line 4', 'line 5 line 5', 'line 6 line 6']) 471 call cursor(1, 1) 472 exe "normal Vcnewline\<Esc>j.j2Vd." 473 call assert_equal(['newline', 'newline'], getline(1, '$')) 474 475 call deletebufline('', 1, '$') 476 call setline(1, ['xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 477 \ 'xxxxxxxxxxxxx']) 478 exe "normal \<C-V>jlc \<Esc>l.l2\<C-V>c----\<Esc>l." 479 call assert_equal([' --------x', 480 \ ' --------x', 481 \ 'xxxx--------x', 482 \ 'xxxx--------x'], getline(1, '$')) 483 484 bwipe! 485endfunc 486 487" Visual mode maps (movement and text object) 488" Visual mode maps; count; repeating 489" - Simple 490" - With an Ex command (custom text object) 491func Test_visual_mode_maps() 492 new 493 call append(0, '') 494 495 func SelectInCaps() 496 let [line1, col1] = searchpos('\u', 'bcnW') 497 let [line2, col2] = searchpos('.\u', 'nW') 498 call setpos("'<", [0, line1, col1, 0]) 499 call setpos("'>", [0, line2, col2, 0]) 500 normal! gv 501 endfunction 502 503 vnoremap W /\u/s-1<CR> 504 vnoremap iW :<C-U>call SelectInCaps()<CR> 505 506 call setline(1, 'KiwiRaspberryDateWatermelonPeach') 507 call cursor(1, 1) 508 exe "normal vWcNo\<Esc>l.fD2vd." 509 call assert_equal('NoNoberryach', getline(1)) 510 511 call setline(1, 'JambuRambutanBananaTangerineMango') 512 call cursor(1, 1) 513 exe "normal llviWc-\<Esc>l.l2vdl." 514 call assert_equal('--ago', getline(1)) 515 516 vunmap W 517 vunmap iW 518 bwipe! 519 delfunc SelectInCaps 520endfunc 521 522" Operator-pending mode maps (movement and text object) 523" - Simple 524" - With Ex command moving the cursor 525" - With Ex command and Visual selection (custom text object) 526func Test_visual_oper_pending_mode_maps() 527 new 528 call append(0, '') 529 530 func MoveToCap() 531 call search('\u', 'W') 532 endfunction 533 534 func SelectInCaps() 535 let [line1, col1] = searchpos('\u', 'bcnW') 536 let [line2, col2] = searchpos('.\u', 'nW') 537 call setpos("'<", [0, line1, col1, 0]) 538 call setpos("'>", [0, line2, col2, 0]) 539 normal! gv 540 endfunction 541 542 onoremap W /\u/<CR> 543 onoremap <Leader>W :<C-U>call MoveToCap()<CR> 544 onoremap iW :<C-U>call SelectInCaps()<CR> 545 546 call setline(1, 'PineappleQuinceLoganberryOrangeGrapefruitKiwiZ') 547 call cursor(1, 1) 548 exe "normal cW-\<Esc>l.l2.l." 549 call assert_equal('----Z', getline(1)) 550 551 call setline(1, 'JuniperDurianZ') 552 call cursor(1, 1) 553 exe "normal g?\WfD." 554 call assert_equal('WhavcreQhevnaZ', getline(1)) 555 556 call setline(1, 'LemonNectarineZ') 557 call cursor(1, 1) 558 exe "normal yiWPlciWNew\<Esc>fr." 559 call assert_equal('LemonNewNewZ', getline(1)) 560 561 ounmap W 562 ounmap <Leader>W 563 ounmap iW 564 bwipe! 565 delfunc MoveToCap 566 delfunc SelectInCaps 567endfunc 568 569" Patch 7.3.879: Properly abort Operator-pending mode for "dv:<Esc>" etc. 570func Test_op_pend_mode_abort() 571 new 572 call append(0, '') 573 574 call setline(1, ['zzzz', 'zzzz']) 575 call cursor(1, 1) 576 577 exe "normal dV:\<CR>dv:\<CR>" 578 call assert_equal(['zzz'], getline(1, 2)) 579 set nomodifiable 580 call assert_fails('exe "normal d:\<CR>"', 'E21:') 581 set modifiable 582 call feedkeys("dv:\<Esc>dV:\<Esc>", 'xt') 583 call assert_equal(['zzz'], getline(1, 2)) 584 set nomodifiable 585 let v:errmsg = '' 586 call feedkeys("d:\<Esc>", 'xt') 587 call assert_true(v:errmsg !~# '^E21:') 588 set modifiable 589 590 bwipe! 591endfunc 592 593func Test_characterwise_visual_mode() 594 new 595 596 " characterwise visual mode: replace last line 597 $put ='a' 598 let @" = 'x' 599 normal v$p 600 call assert_equal('x', getline('$')) 601 602 " characterwise visual mode: delete middle line 603 call deletebufline('', 1, '$') 604 call append('$', ['a', 'b', 'c']) 605 normal G 606 normal kkv$d 607 call assert_equal(['', 'b', 'c'], getline(1, '$')) 608 609 " characterwise visual mode: delete middle two lines 610 call deletebufline('', 1, '$') 611 call append('$', ['a', 'b', 'c']) 612 normal Gkkvj$d 613 call assert_equal(['', 'c'], getline(1, '$')) 614 615 " characterwise visual mode: delete last line 616 call deletebufline('', 1, '$') 617 call append('$', ['a', 'b', 'c']) 618 normal Gv$d 619 call assert_equal(['', 'a', 'b', ''], getline(1, '$')) 620 621 " characterwise visual mode: delete last two lines 622 call deletebufline('', 1, '$') 623 call append('$', ['a', 'b', 'c']) 624 normal Gkvj$d 625 call assert_equal(['', 'a', ''], getline(1, '$')) 626 627 bwipe! 628endfunc 629 630func Test_visual_mode_put() 631 new 632 633 " v_p: replace last character with line register at middle line 634 call append('$', ['aaa', 'bbb', 'ccc']) 635 normal G 636 -2yank 637 normal k$vp 638 call assert_equal(['', 'aaa', 'bb', 'aaa', '', 'ccc'], getline(1, '$')) 639 640 " v_p: replace last character with line register at middle line selecting 641 " newline 642 call deletebufline('', 1, '$') 643 call append('$', ['aaa', 'bbb', 'ccc']) 644 normal G 645 -2yank 646 normal k$v$p 647 call assert_equal(['', 'aaa', 'bb', 'aaa', 'ccc'], getline(1, '$')) 648 649 " v_p: replace last character with line register at last line 650 call deletebufline('', 1, '$') 651 call append('$', ['aaa', 'bbb', 'ccc']) 652 normal G 653 -2yank 654 normal $vp 655 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) 656 657 " v_p: replace last character with line register at last line selecting 658 " newline 659 call deletebufline('', 1, '$') 660 call append('$', ['aaa', 'bbb', 'ccc']) 661 normal G 662 -2yank 663 normal $v$p 664 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) 665 666 bwipe! 667endfunc 668 669func Test_gv_with_exclusive_selection() 670 new 671 672 " gv with exclusive selection after an operation 673 call append('$', ['zzz ', 'äà ']) 674 set selection=exclusive 675 normal Gkv3lyjv3lpgvcxxx 676 call assert_equal(['', 'zzz ', 'xxx '], getline(1, '$')) 677 678 " gv with exclusive selection without an operation 679 call deletebufline('', 1, '$') 680 call append('$', 'zzz ') 681 set selection=exclusive 682 exe "normal G0v3l\<Esc>gvcxxx" 683 call assert_equal(['', 'xxx '], getline(1, '$')) 684 685 set selection&vim 686 bwipe! 687endfunc 688 689" Tests for the visual block mode commands 690func Test_visual_block_mode() 691 new 692 call append(0, '') 693 call setline(1, repeat(['abcdefghijklm'], 5)) 694 call cursor(1, 1) 695 696 " Test shift-right of a block 697 exe "normal jllll\<C-V>jj>wll\<C-V>jlll>" 698 " Test shift-left of a block 699 exe "normal G$hhhh\<C-V>kk<" 700 " Test block-insert 701 exe "normal Gkl\<C-V>kkkIxyz" 702 " Test block-replace 703 exe "normal Gllll\<C-V>kkklllrq" 704 " Test block-change 705 exe "normal G$khhh\<C-V>hhkkcmno" 706 call assert_equal(['axyzbcdefghijklm', 707 \ 'axyzqqqq mno ghijklm', 708 \ 'axyzqqqqef mno ghijklm', 709 \ 'axyzqqqqefgmnoklm', 710 \ 'abcdqqqqijklm'], getline(1, 5)) 711 712 " Test 'C' to change till the end of the line 713 call cursor(3, 4) 714 exe "normal! \<C-V>j3lCooo" 715 call assert_equal(['axyooo', 'axyooo'], getline(3, 4)) 716 717 " Test 'D' to delete till the end of the line 718 call cursor(3, 3) 719 exe "normal! \<C-V>j2lD" 720 call assert_equal(['ax', 'ax'], getline(3, 4)) 721 722 bwipe! 723endfunc 724 725" Test block-insert using cursor keys for movement 726func Test_visual_block_insert_cursor_keys() 727 new 728 call append(0, ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd']) 729 call cursor(1, 1) 730 731 exe "norm! l\<C-V>jjjlllI\<Right>\<Right> \<Esc>" 732 call assert_equal(['aaa aaa', 'bbb bbb', 'ccc ccc', 'ddd ddd'], 733 \ getline(1, 4)) 734 735 call deletebufline('', 1, '$') 736 call setline(1, ['xaaa', 'bbbb', 'cccc', 'dddd']) 737 call cursor(1, 1) 738 exe "norm! \<C-V>jjjI<>\<Left>p\<Esc>" 739 call assert_equal(['<p>xaaa', '<p>bbbb', '<p>cccc', '<p>dddd'], 740 \ getline(1, 4)) 741 bwipe! 742endfunc 743 744func Test_visual_block_create() 745 new 746 call append(0, '') 747 " Test for Visual block was created with the last <C-v>$ 748 call setline(1, ['A23', '4567']) 749 call cursor(1, 1) 750 exe "norm! l\<C-V>j$Aab\<Esc>" 751 call assert_equal(['A23ab', '4567ab'], getline(1, 2)) 752 753 " Test for Visual block was created with the middle <C-v>$ (1) 754 call deletebufline('', 1, '$') 755 call setline(1, ['B23', '4567']) 756 call cursor(1, 1) 757 exe "norm! l\<C-V>j$hAab\<Esc>" 758 call assert_equal(['B23 ab', '4567ab'], getline(1, 2)) 759 760 " Test for Visual block was created with the middle <C-v>$ (2) 761 call deletebufline('', 1, '$') 762 call setline(1, ['C23', '4567']) 763 call cursor(1, 1) 764 exe "norm! l\<C-V>j$hhAab\<Esc>" 765 call assert_equal(['C23ab', '456ab7'], getline(1, 2)) 766 bwipe! 767endfunc 768 769" Test for Visual block insert when virtualedit=all 770func Test_virtualedit_visual_block() 771 set ve=all 772 new 773 call append(0, ["\t\tline1", "\t\tline2", "\t\tline3"]) 774 call cursor(1, 1) 775 exe "norm! 07l\<C-V>jjIx\<Esc>" 776 call assert_equal([" x \tline1", 777 \ " x \tline2", 778 \ " x \tline3"], getline(1, 3)) 779 780 " Test for Visual block append when virtualedit=all 781 exe "norm! 012l\<C-v>jjAx\<Esc>" 782 call assert_equal([' x x line1', 783 \ ' x x line2', 784 \ ' x x line3'], getline(1, 3)) 785 set ve= 786 bwipe! 787endfunc 788 789" Test for changing case 790func Test_visual_change_case() 791 new 792 " gUe must uppercase a whole word, also when ß changes to SS 793 exe "normal Gothe youtußeuu end\<Esc>Ypk0wgUe\r" 794 " gUfx must uppercase until x, inclusive. 795 exe "normal O- youßtußexu -\<Esc>0fogUfx\r" 796 " VU must uppercase a whole line 797 exe "normal YpkVU\r" 798 " same, when it's the last line in the buffer 799 exe "normal YPGi111\<Esc>VUddP\r" 800 " Uppercase two lines 801 exe "normal Oblah di\rdoh dut\<Esc>VkUj\r" 802 " Uppercase part of two lines 803 exe "normal ddppi333\<Esc>k0i222\<Esc>fyllvjfuUk" 804 call assert_equal(['the YOUTUSSEUU end', '- yOUSSTUSSEXu -', 805 \ 'THE YOUTUSSEUU END', '111THE YOUTUSSEUU END', 'BLAH DI', 'DOH DUT', 806 \ '222the yoUTUSSEUU END', '333THE YOUTUßeuu end'], getline(2, '$')) 807 bwipe! 808endfunc 809 810" Test for Visual replace using Enter or NL 811func Test_visual_replace_crnl() 812 new 813 exe "normal G3o123456789\e2k05l\<C-V>2jr\r" 814 exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\r\n" 815 exe "normal G3o123456789\e2k05l\<C-V>2jr\n" 816 exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\n" 817 call assert_equal(['12345', '789', '12345', '789', '12345', '789', "98\r65", 818 \ "98\r65", "98\r65", '12345', '789', '12345', '789', '12345', '789', 819 \ "98\n65", "98\n65", "98\n65"], getline(2, '$')) 820 bwipe! 821endfunc 822 823func Test_ve_block_curpos() 824 new 825 " Test cursor position. When ve=block and Visual block mode and $gj 826 call append(0, ['12345', '789']) 827 call cursor(1, 3) 828 set virtualedit=block 829 exe "norm! \<C-V>$gj\<Esc>" 830 call assert_equal([0, 2, 4, 0], getpos("'>")) 831 set virtualedit= 832 bwipe! 833endfunc 834 835" Test for block_insert when replacing spaces in front of the a with tabs 836func Test_block_insert_replace_tabs() 837 new 838 set ts=8 sts=4 sw=4 839 call append(0, ["#define BO_ALL\t 0x0001", 840 \ "#define BO_BS\t 0x0002", 841 \ "#define BO_CRSR\t 0x0004"]) 842 call cursor(1, 1) 843 exe "norm! f0\<C-V>2jI\<tab>\<esc>" 844 call assert_equal([ 845 \ "#define BO_ALL\t\t0x0001", 846 \ "#define BO_BS\t \t0x0002", 847 \ "#define BO_CRSR\t \t0x0004", ''], getline(1, '$')) 848 set ts& sts& sw& 849 bwipe! 850endfunc 851 852" Test for * register in : 853func Test_star_register() 854 call assert_fails('*bfirst', 'E16:') 855 new 856 call setline(1, ['foo', 'bar', 'baz', 'qux']) 857 exe "normal jVj\<ESC>" 858 *yank r 859 call assert_equal("bar\nbaz\n", @r) 860 861 delmarks < > 862 call assert_fails('*yank', 'E20:') 863 close! 864endfunc 865 866" Test for changing text in visual mode with 'exclusive' selection 867func Test_exclusive_selection() 868 new 869 call setline(1, ['one', 'two']) 870 set selection=exclusive 871 call feedkeys("vwcabc", 'xt') 872 call assert_equal('abctwo', getline(1)) 873 call setline(1, ["\tone"]) 874 set virtualedit=all 875 call feedkeys('0v2lcl', 'xt') 876 call assert_equal('l one', getline(1)) 877 set virtualedit& 878 set selection& 879 close! 880endfunc 881 882" Test for starting visual mode with a count. 883" This test should be run without any previous visual modes. So this should be 884" run as a first test. 885func Test_AAA_start_visual_mode_with_count() 886 new 887 call setline(1, ['aaaaaaa', 'aaaaaaa', 'aaaaaaa', 'aaaaaaa']) 888 normal! gg2Vy 889 call assert_equal("aaaaaaa\naaaaaaa\n", @") 890 close! 891endfunc 892 893" Test for visually selecting an inner block (iB) 894func Test_visual_inner_block() 895 new 896 call setline(1, ['one', '{', 'two', '{', 'three', '}', 'four', '}', 'five']) 897 call cursor(5, 1) 898 " visually select all the lines in the block and then execute iB 899 call feedkeys("ViB\<C-C>", 'xt') 900 call assert_equal([0, 5, 1, 0], getpos("'<")) 901 call assert_equal([0, 5, 6, 0], getpos("'>")) 902 " visually select two inner blocks 903 call feedkeys("ViBiB\<C-C>", 'xt') 904 call assert_equal([0, 3, 1, 0], getpos("'<")) 905 call assert_equal([0, 7, 5, 0], getpos("'>")) 906 " try to select non-existing inner block 907 call cursor(5, 1) 908 call assert_beeps('normal ViBiBiB') 909 " try to select a unclosed inner block 910 8,9d 911 call cursor(5, 1) 912 call assert_beeps('normal ViBiB') 913 close! 914endfunc 915 916" vim: shiftwidth=2 sts=2 expandtab 917