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 " clean up 271 %d_ 272 set bs&vim 273endfunc 274 275func Test_Visual_word_textobject() 276 new 277 call setline(1, ['First sentence. Second sentence.']) 278 279 " When start and end of visual area are identical, 'aw' or 'iw' select 280 " the whole word. 281 norm! 1go2fcvawy 282 call assert_equal('Second ', @") 283 norm! 1go2fcviwy 284 call assert_equal('Second', @") 285 286 " When start and end of visual area are not identical, 'aw' or 'iw' 287 " extend the word in direction of the end of the visual area. 288 norm! 1go2fcvlawy 289 call assert_equal('cond ', @") 290 norm! gv2awy 291 call assert_equal('cond sentence.', @") 292 293 norm! 1go2fcvliwy 294 call assert_equal('cond', @") 295 norm! gv2iwy 296 call assert_equal('cond sentence', @") 297 298 " Extend visual area in opposite direction. 299 norm! 1go2fcvhawy 300 call assert_equal(' Sec', @") 301 norm! gv2awy 302 call assert_equal(' sentence. Sec', @") 303 304 norm! 1go2fcvhiwy 305 call assert_equal('Sec', @") 306 norm! gv2iwy 307 call assert_equal('. Sec', @") 308 309 bwipe! 310endfunc 311 312func Test_Visual_sentence_textobject() 313 new 314 call setline(1, ['First sentence. Second sentence. Third', 'sentence. Fourth sentence']) 315 316 " When start and end of visual area are identical, 'as' or 'is' select 317 " the whole sentence. 318 norm! 1gofdvasy 319 call assert_equal('Second sentence. ', @") 320 norm! 1gofdvisy 321 call assert_equal('Second sentence.', @") 322 323 " When start and end of visual area are not identical, 'as' or 'is' 324 " extend the sentence in direction of the end of the visual area. 325 norm! 1gofdvlasy 326 call assert_equal('d sentence. ', @") 327 norm! gvasy 328 call assert_equal("d sentence. Third\nsentence. ", @") 329 330 norm! 1gofdvlisy 331 call assert_equal('d sentence.', @") 332 norm! gvisy 333 call assert_equal('d sentence. ', @") 334 norm! gvisy 335 call assert_equal("d sentence. Third\nsentence.", @") 336 337 " Extend visual area in opposite direction. 338 norm! 1gofdvhasy 339 call assert_equal(' Second', @") 340 norm! gvasy 341 call assert_equal("First sentence. Second", @") 342 343 norm! 1gofdvhisy 344 call assert_equal('Second', @") 345 norm! gvisy 346 call assert_equal(' Second', @") 347 norm! gvisy 348 call assert_equal('First sentence. Second', @") 349 350 bwipe! 351endfunc 352 353func Test_Visual_paragraph_textobject() 354 new 355 call setline(1, ['First line.', 356 \ '', 357 \ 'Second line.', 358 \ 'Third line.', 359 \ 'Fourth line.', 360 \ 'Fifth line.', 361 \ '', 362 \ 'Sixth line.']) 363 364 " When start and end of visual area are identical, 'ap' or 'ip' select 365 " the whole paragraph. 366 norm! 4ggvapy 367 call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n\n", @") 368 norm! 4ggvipy 369 call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n", @") 370 371 " When start and end of visual area are not identical, 'ap' or 'ip' 372 " extend the sentence in direction of the end of the visual area. 373 " FIXME: actually, it is not sufficient to have different start and 374 " end of visual selection, the start line and end line have to differ, 375 " which is not consistent with the documentation. 376 norm! 4ggVjapy 377 call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") 378 norm! gvapy 379 call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") 380 norm! 4ggVjipy 381 call assert_equal("Third line.\nFourth line.\nFifth line.\n", @") 382 norm! gvipy 383 call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") 384 norm! gvipy 385 call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") 386 387 " Extend visual area in opposite direction. 388 norm! 5ggVkapy 389 call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") 390 norm! gvapy 391 call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") 392 norm! 5ggVkipy 393 call assert_equal("Second line.\nThird line.\nFourth line.\n", @") 394 norma gvipy 395 call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") 396 norm! gvipy 397 call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") 398 399 bwipe! 400endfunc 401 402func Test_curswant_not_changed() 403 new 404 call setline(1, ['one', 'two']) 405 au InsertLeave * call getcurpos() 406 call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt') 407 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 408 409 bwipe! 410 au! InsertLeave 411endfunc 412 413" Tests for "vaBiB", end could be wrong. 414func Test_Visual_Block() 415 new 416 a 417- Bug in "vPPPP" on this text: 418 { 419 cmd; 420 { 421 cmd;\t/* <-- Start cursor here */ 422 { 423 } 424 } 425 } 426. 427 normal gg 428 call search('Start cursor here') 429 normal vaBiBD 430 call assert_equal(['- Bug in "vPPPP" on this text:', 431 \ "\t{", 432 \ "\t}"], getline(1, '$')) 433 434 close! 435endfunc 436 437" Test for 'p'ut in visual block mode 438func Test_visual_block_put() 439 enew 440 441 call append(0, ['One', 'Two', 'Three']) 442 normal gg 443 yank 444 call feedkeys("jl\<C-V>ljp", 'xt') 445 call assert_equal(['One', 'T', 'Tee', 'One', ''], getline(1, '$')) 446 447 enew! 448endfunc 449 450" Visual modes (v V CTRL-V) followed by an operator; count; repeating 451func Test_visual_mode_op() 452 new 453 call append(0, '') 454 455 call setline(1, 'apple banana cherry') 456 call cursor(1, 1) 457 normal lvld.l3vd. 458 call assert_equal('a y', getline(1)) 459 460 call setline(1, ['line 1 line 1', 'line 2 line 2', 'line 3 line 3', 461 \ 'line 4 line 4', 'line 5 line 5', 'line 6 line 6']) 462 call cursor(1, 1) 463 exe "normal Vcnewline\<Esc>j.j2Vd." 464 call assert_equal(['newline', 'newline'], getline(1, '$')) 465 466 call deletebufline('', 1, '$') 467 call setline(1, ['xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 468 \ 'xxxxxxxxxxxxx']) 469 exe "normal \<C-V>jlc \<Esc>l.l2\<C-V>c----\<Esc>l." 470 call assert_equal([' --------x', 471 \ ' --------x', 472 \ 'xxxx--------x', 473 \ 'xxxx--------x'], getline(1, '$')) 474 475 bwipe! 476endfunc 477 478" Visual mode maps (movement and text object) 479" Visual mode maps; count; repeating 480" - Simple 481" - With an Ex command (custom text object) 482func Test_visual_mode_maps() 483 new 484 call append(0, '') 485 486 func SelectInCaps() 487 let [line1, col1] = searchpos('\u', 'bcnW') 488 let [line2, col2] = searchpos('.\u', 'nW') 489 call setpos("'<", [0, line1, col1, 0]) 490 call setpos("'>", [0, line2, col2, 0]) 491 normal! gv 492 endfunction 493 494 vnoremap W /\u/s-1<CR> 495 vnoremap iW :<C-U>call SelectInCaps()<CR> 496 497 call setline(1, 'KiwiRaspberryDateWatermelonPeach') 498 call cursor(1, 1) 499 exe "normal vWcNo\<Esc>l.fD2vd." 500 call assert_equal('NoNoberryach', getline(1)) 501 502 call setline(1, 'JambuRambutanBananaTangerineMango') 503 call cursor(1, 1) 504 exe "normal llviWc-\<Esc>l.l2vdl." 505 call assert_equal('--ago', getline(1)) 506 507 vunmap W 508 vunmap iW 509 bwipe! 510 delfunc SelectInCaps 511endfunc 512 513" Operator-pending mode maps (movement and text object) 514" - Simple 515" - With Ex command moving the cursor 516" - With Ex command and Visual selection (custom text object) 517func Test_visual_oper_pending_mode_maps() 518 new 519 call append(0, '') 520 521 func MoveToCap() 522 call search('\u', 'W') 523 endfunction 524 525 func SelectInCaps() 526 let [line1, col1] = searchpos('\u', 'bcnW') 527 let [line2, col2] = searchpos('.\u', 'nW') 528 call setpos("'<", [0, line1, col1, 0]) 529 call setpos("'>", [0, line2, col2, 0]) 530 normal! gv 531 endfunction 532 533 onoremap W /\u/<CR> 534 onoremap <Leader>W :<C-U>call MoveToCap()<CR> 535 onoremap iW :<C-U>call SelectInCaps()<CR> 536 537 call setline(1, 'PineappleQuinceLoganberryOrangeGrapefruitKiwiZ') 538 call cursor(1, 1) 539 exe "normal cW-\<Esc>l.l2.l." 540 call assert_equal('----Z', getline(1)) 541 542 call setline(1, 'JuniperDurianZ') 543 call cursor(1, 1) 544 exe "normal g?\WfD." 545 call assert_equal('WhavcreQhevnaZ', getline(1)) 546 547 call setline(1, 'LemonNectarineZ') 548 call cursor(1, 1) 549 exe "normal yiWPlciWNew\<Esc>fr." 550 call assert_equal('LemonNewNewZ', getline(1)) 551 552 ounmap W 553 ounmap <Leader>W 554 ounmap iW 555 bwipe! 556 delfunc MoveToCap 557 delfunc SelectInCaps 558endfunc 559 560" Patch 7.3.879: Properly abort Operator-pending mode for "dv:<Esc>" etc. 561func Test_op_pend_mode_abort() 562 new 563 call append(0, '') 564 565 call setline(1, ['zzzz', 'zzzz']) 566 call cursor(1, 1) 567 568 exe "normal dV:\<CR>dv:\<CR>" 569 call assert_equal(['zzz'], getline(1, 2)) 570 set nomodifiable 571 call assert_fails('exe "normal d:\<CR>"', 'E21:') 572 set modifiable 573 call feedkeys("dv:\<Esc>dV:\<Esc>", 'xt') 574 call assert_equal(['zzz'], getline(1, 2)) 575 set nomodifiable 576 let v:errmsg = '' 577 call feedkeys("d:\<Esc>", 'xt') 578 call assert_true(v:errmsg !~# '^E21:') 579 set modifiable 580 581 bwipe! 582endfunc 583 584func Test_characterwise_visual_mode() 585 new 586 587 " characterwise visual mode: replace last line 588 $put ='a' 589 let @" = 'x' 590 normal v$p 591 call assert_equal('x', getline('$')) 592 593 " characterwise visual mode: delete middle line 594 call deletebufline('', 1, '$') 595 call append('$', ['a', 'b', 'c']) 596 normal G 597 normal kkv$d 598 call assert_equal(['', 'b', 'c'], getline(1, '$')) 599 600 " characterwise visual mode: delete middle two lines 601 call deletebufline('', 1, '$') 602 call append('$', ['a', 'b', 'c']) 603 normal Gkkvj$d 604 call assert_equal(['', 'c'], getline(1, '$')) 605 606 " characterwise visual mode: delete last line 607 call deletebufline('', 1, '$') 608 call append('$', ['a', 'b', 'c']) 609 normal Gv$d 610 call assert_equal(['', 'a', 'b', ''], getline(1, '$')) 611 612 " characterwise visual mode: delete last two lines 613 call deletebufline('', 1, '$') 614 call append('$', ['a', 'b', 'c']) 615 normal Gkvj$d 616 call assert_equal(['', 'a', ''], getline(1, '$')) 617 618 bwipe! 619endfunc 620 621func Test_visual_mode_put() 622 new 623 624 " v_p: replace last character with line register at middle line 625 call append('$', ['aaa', 'bbb', 'ccc']) 626 normal G 627 -2yank 628 normal k$vp 629 call assert_equal(['', 'aaa', 'bb', 'aaa', '', 'ccc'], getline(1, '$')) 630 631 " v_p: replace last character with line register at middle line selecting 632 " newline 633 call deletebufline('', 1, '$') 634 call append('$', ['aaa', 'bbb', 'ccc']) 635 normal G 636 -2yank 637 normal k$v$p 638 call assert_equal(['', 'aaa', 'bb', 'aaa', 'ccc'], getline(1, '$')) 639 640 " v_p: replace last character with line register at last line 641 call deletebufline('', 1, '$') 642 call append('$', ['aaa', 'bbb', 'ccc']) 643 normal G 644 -2yank 645 normal $vp 646 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) 647 648 " v_p: replace last character with line register at last line selecting 649 " newline 650 call deletebufline('', 1, '$') 651 call append('$', ['aaa', 'bbb', 'ccc']) 652 normal G 653 -2yank 654 normal $v$p 655 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) 656 657 bwipe! 658endfunc 659 660func Test_gv_with_exclusive_selection() 661 new 662 663 " gv with exclusive selection after an operation 664 call append('$', ['zzz ', 'äà ']) 665 set selection=exclusive 666 normal Gkv3lyjv3lpgvcxxx 667 call assert_equal(['', 'zzz ', 'xxx '], getline(1, '$')) 668 669 " gv with exclusive selection without an operation 670 call deletebufline('', 1, '$') 671 call append('$', 'zzz ') 672 set selection=exclusive 673 exe "normal G0v3l\<Esc>gvcxxx" 674 call assert_equal(['', 'xxx '], getline(1, '$')) 675 676 set selection&vim 677 bwipe! 678endfunc 679 680" Tests for the visual block mode commands 681func Test_visual_block_mode() 682 new 683 call append(0, '') 684 call setline(1, repeat(['abcdefghijklm'], 5)) 685 call cursor(1, 1) 686 687 " Test shift-right of a block 688 exe "normal jllll\<C-V>jj>wll\<C-V>jlll>" 689 " Test shift-left of a block 690 exe "normal G$hhhh\<C-V>kk<" 691 " Test block-insert 692 exe "normal Gkl\<C-V>kkkIxyz" 693 " Test block-replace 694 exe "normal Gllll\<C-V>kkklllrq" 695 " Test block-change 696 exe "normal G$khhh\<C-V>hhkkcmno" 697 call assert_equal(['axyzbcdefghijklm', 698 \ 'axyzqqqq mno ghijklm', 699 \ 'axyzqqqqef mno ghijklm', 700 \ 'axyzqqqqefgmnoklm', 701 \ 'abcdqqqqijklm'], getline(1, 5)) 702 703 " Test 'C' to change till the end of the line 704 call cursor(3, 4) 705 exe "normal! \<C-V>j3lCooo" 706 call assert_equal(['axyooo', 'axyooo'], getline(3, 4)) 707 708 " Test 'D' to delete till the end of the line 709 call cursor(3, 3) 710 exe "normal! \<C-V>j2lD" 711 call assert_equal(['ax', 'ax'], getline(3, 4)) 712 713 bwipe! 714endfunc 715 716" Test block-insert using cursor keys for movement 717func Test_visual_block_insert_cursor_keys() 718 new 719 call append(0, ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd']) 720 call cursor(1, 1) 721 722 exe "norm! l\<C-V>jjjlllI\<Right>\<Right> \<Esc>" 723 call assert_equal(['aaa aaa', 'bbb bbb', 'ccc ccc', 'ddd ddd'], 724 \ getline(1, 4)) 725 726 call deletebufline('', 1, '$') 727 call setline(1, ['xaaa', 'bbbb', 'cccc', 'dddd']) 728 call cursor(1, 1) 729 exe "norm! \<C-V>jjjI<>\<Left>p\<Esc>" 730 call assert_equal(['<p>xaaa', '<p>bbbb', '<p>cccc', '<p>dddd'], 731 \ getline(1, 4)) 732 bwipe! 733endfunc 734 735func Test_visual_block_create() 736 new 737 call append(0, '') 738 " Test for Visual block was created with the last <C-v>$ 739 call setline(1, ['A23', '4567']) 740 call cursor(1, 1) 741 exe "norm! l\<C-V>j$Aab\<Esc>" 742 call assert_equal(['A23ab', '4567ab'], getline(1, 2)) 743 744 " Test for Visual block was created with the middle <C-v>$ (1) 745 call deletebufline('', 1, '$') 746 call setline(1, ['B23', '4567']) 747 call cursor(1, 1) 748 exe "norm! l\<C-V>j$hAab\<Esc>" 749 call assert_equal(['B23 ab', '4567ab'], getline(1, 2)) 750 751 " Test for Visual block was created with the middle <C-v>$ (2) 752 call deletebufline('', 1, '$') 753 call setline(1, ['C23', '4567']) 754 call cursor(1, 1) 755 exe "norm! l\<C-V>j$hhAab\<Esc>" 756 call assert_equal(['C23ab', '456ab7'], getline(1, 2)) 757 bwipe! 758endfunc 759 760" Test for Visual block insert when virtualedit=all 761func Test_virtualedit_visual_block() 762 set ve=all 763 new 764 call append(0, ["\t\tline1", "\t\tline2", "\t\tline3"]) 765 call cursor(1, 1) 766 exe "norm! 07l\<C-V>jjIx\<Esc>" 767 call assert_equal([" x \tline1", 768 \ " x \tline2", 769 \ " x \tline3"], getline(1, 3)) 770 771 " Test for Visual block append when virtualedit=all 772 exe "norm! 012l\<C-v>jjAx\<Esc>" 773 call assert_equal([' x x line1', 774 \ ' x x line2', 775 \ ' x x line3'], getline(1, 3)) 776 set ve= 777 bwipe! 778endfunc 779 780" Test for changing case 781func Test_visual_change_case() 782 new 783 " gUe must uppercase a whole word, also when ß changes to SS 784 exe "normal Gothe youtußeuu end\<Esc>Ypk0wgUe\r" 785 " gUfx must uppercase until x, inclusive. 786 exe "normal O- youßtußexu -\<Esc>0fogUfx\r" 787 " VU must uppercase a whole line 788 exe "normal YpkVU\r" 789 " same, when it's the last line in the buffer 790 exe "normal YPGi111\<Esc>VUddP\r" 791 " Uppercase two lines 792 exe "normal Oblah di\rdoh dut\<Esc>VkUj\r" 793 " Uppercase part of two lines 794 exe "normal ddppi333\<Esc>k0i222\<Esc>fyllvjfuUk" 795 call assert_equal(['the YOUTUSSEUU end', '- yOUSSTUSSEXu -', 796 \ 'THE YOUTUSSEUU END', '111THE YOUTUSSEUU END', 'BLAH DI', 'DOH DUT', 797 \ '222the yoUTUSSEUU END', '333THE YOUTUßeuu end'], getline(2, '$')) 798 bwipe! 799endfunc 800 801" Test for Visual replace using Enter or NL 802func Test_visual_replace_crnl() 803 new 804 exe "normal G3o123456789\e2k05l\<C-V>2jr\r" 805 exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\r\n" 806 exe "normal G3o123456789\e2k05l\<C-V>2jr\n" 807 exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\n" 808 call assert_equal(['12345', '789', '12345', '789', '12345', '789', "98\r65", 809 \ "98\r65", "98\r65", '12345', '789', '12345', '789', '12345', '789', 810 \ "98\n65", "98\n65", "98\n65"], getline(2, '$')) 811 bwipe! 812endfunc 813 814func Test_ve_block_curpos() 815 new 816 " Test cursor position. When ve=block and Visual block mode and $gj 817 call append(0, ['12345', '789']) 818 call cursor(1, 3) 819 set virtualedit=block 820 exe "norm! \<C-V>$gj\<Esc>" 821 call assert_equal([0, 2, 4, 0], getpos("'>")) 822 set virtualedit= 823 bwipe! 824endfunc 825 826" Test for block_insert when replacing spaces in front of the a with tabs 827func Test_block_insert_replace_tabs() 828 new 829 set ts=8 sts=4 sw=4 830 call append(0, ["#define BO_ALL\t 0x0001", 831 \ "#define BO_BS\t 0x0002", 832 \ "#define BO_CRSR\t 0x0004"]) 833 call cursor(1, 1) 834 exe "norm! f0\<C-V>2jI\<tab>\<esc>" 835 call assert_equal([ 836 \ "#define BO_ALL\t\t0x0001", 837 \ "#define BO_BS\t \t0x0002", 838 \ "#define BO_CRSR\t \t0x0004", ''], getline(1, '$')) 839 set ts& sts& sw& 840 bwipe! 841endfunc 842 843" Test for * register in : 844func Test_star_register() 845 call assert_fails('*bfirst', 'E16:') 846 new 847 call setline(1, ['foo', 'bar', 'baz', 'qux']) 848 exe "normal jVj\<ESC>" 849 *yank r 850 call assert_equal("bar\nbaz\n", @r) 851 852 delmarks < > 853 call assert_fails('*yank', 'E20:') 854 close! 855endfunc 856 857" Test for changing text in visual mode with 'exclusive' selection 858func Test_exclusive_selection() 859 new 860 call setline(1, ['one', 'two']) 861 set selection=exclusive 862 call feedkeys("vwcabc", 'xt') 863 call assert_equal('abctwo', getline(1)) 864 call setline(1, ["\tone"]) 865 set virtualedit=all 866 call feedkeys('0v2lcl', 'xt') 867 call assert_equal('l one', getline(1)) 868 set virtualedit& 869 set selection& 870 close! 871endfunc 872 873" Test for starting visual mode with a count. 874" This test should be run without any previous visual modes. So this should be 875" run as a first test. 876func Test_AAA_start_visual_mode_with_count() 877 new 878 call setline(1, ['aaaaaaa', 'aaaaaaa', 'aaaaaaa', 'aaaaaaa']) 879 normal! gg2Vy 880 call assert_equal("aaaaaaa\naaaaaaa\n", @") 881 close! 882endfunc 883 884" vim: shiftwidth=2 sts=2 expandtab 885