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 161 call assert_equal(['..........', 162 \ '...c d..', 163 \ '... ..', 164 \ '...a b..', 165 \ '..........'], getline(1, '$')) 166 167 enew! 168endfun 169 170" Test Virtual replace mode. 171func Test_virtual_replace() 172 if exists('&t_kD') 173 let save_t_kD = &t_kD 174 endif 175 if exists('&t_kb') 176 let save_t_kb = &t_kb 177 endif 178 exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08" 179 enew! 180 exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" 181 call cursor(1,1) 182 set ai bs=2 183 exe "normal gR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" 184 call assert_equal([' 1', 185 \ ' A', 186 \ ' BCDEFGHIJ', 187 \ ' KL', 188 \ ' MNO', 189 \ ' PQR', 190 \ ], getline(1, 6)) 191 normal G 192 mark a 193 exe "normal o0\<C-D>\nabcdefghi\njk\tlmn\n opq\trst\n\<C-D>uvwxyz\n" 194 exe "normal 'ajgR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" . repeat("\<BS>", 29) 195 call assert_equal([' 1', 196 \ 'abcdefghi', 197 \ 'jk lmn', 198 \ ' opq rst', 199 \ 'uvwxyz'], getline(7, 11)) 200 normal G 201 exe "normal iab\tcdefghi\tjkl" 202 exe "normal 0gRAB......CDEFGHI.J\<Esc>o" 203 exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR" 204 call assert_equal(['AB......CDEFGHI.Jkl', 205 \ 'AB IJKLMNO QRst'], getline(12, 13)) 206 enew! 207 set noai bs&vim 208 if exists('save_t_kD') 209 let &t_kD = save_t_kD 210 endif 211 if exists('save_t_kb') 212 let &t_kb = save_t_kb 213 endif 214endfunc 215 216" Test Virtual replace mode. 217func Test_virtual_replace2() 218 enew! 219 set bs=2 220 exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" 221 call cursor(1,1) 222 " Test 1: Test that del deletes the newline 223 exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" 224 call assert_equal(['0 1', 225 \ 'A', 226 \ 'BCDEFGHIJ', 227 \ ' KL', 228 \ 'MNO', 229 \ 'PQR', 230 \ ], getline(1, 6)) 231 " Test 2: 232 " a newline is not deleted, if no newline has been added in virtual replace mode 233 %d_ 234 call setline(1, ['abcd', 'efgh', 'ijkl']) 235 call cursor(2,1) 236 exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>" 237 call assert_equal(['abcd', 238 \ '123h', 239 \ 'ijkl'], getline(1, '$')) 240 " Test 3: 241 " a newline is deleted, if a newline has been inserted before in virtual replace mode 242 %d_ 243 call setline(1, ['abcd', 'efgh', 'ijkl']) 244 call cursor(2,1) 245 exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>" 246 call assert_equal(['abcd', 247 \ '1234', 248 \ 'ijkl'], getline(1, '$')) 249 " Test 4: 250 " delete add a newline, delete it, add it again and check undo 251 %d_ 252 call setline(1, ['abcd', 'efgh', 'ijkl']) 253 call cursor(2,1) 254 " break undo sequence explicitly 255 let &ul = &ul 256 exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>" 257 let &ul = &ul 258 call assert_equal(['abcd', 259 \ '123456', 260 \ ''], getline(1, '$')) 261 norm! u 262 call assert_equal(['abcd', 263 \ 'efgh', 264 \ 'ijkl'], getline(1, '$')) 265 " clean up 266 %d_ 267 set bs&vim 268endfunc 269 270func Test_Visual_word_textobject() 271 new 272 call setline(1, ['First sentence. Second sentence.']) 273 274 " When start and end of visual area are identical, 'aw' or 'iw' select 275 " the whole word. 276 norm! 1go2fcvawy 277 call assert_equal('Second ', @") 278 norm! 1go2fcviwy 279 call assert_equal('Second', @") 280 281 " When start and end of visual area are not identical, 'aw' or 'iw' 282 " extend the word in direction of the end of the visual area. 283 norm! 1go2fcvlawy 284 call assert_equal('cond ', @") 285 norm! gv2awy 286 call assert_equal('cond sentence.', @") 287 288 norm! 1go2fcvliwy 289 call assert_equal('cond', @") 290 norm! gv2iwy 291 call assert_equal('cond sentence', @") 292 293 " Extend visual area in opposite direction. 294 norm! 1go2fcvhawy 295 call assert_equal(' Sec', @") 296 norm! gv2awy 297 call assert_equal(' sentence. Sec', @") 298 299 norm! 1go2fcvhiwy 300 call assert_equal('Sec', @") 301 norm! gv2iwy 302 call assert_equal('. Sec', @") 303 304 bwipe! 305endfunc 306 307func Test_Visual_sentence_textobject() 308 new 309 call setline(1, ['First sentence. Second sentence. Third', 'sentence. Fourth sentence']) 310 311 " When start and end of visual area are identical, 'as' or 'is' select 312 " the whole sentence. 313 norm! 1gofdvasy 314 call assert_equal('Second sentence. ', @") 315 norm! 1gofdvisy 316 call assert_equal('Second sentence.', @") 317 318 " When start and end of visual area are not identical, 'as' or 'is' 319 " extend the sentence in direction of the end of the visual area. 320 norm! 1gofdvlasy 321 call assert_equal('d sentence. ', @") 322 norm! gvasy 323 call assert_equal("d sentence. Third\nsentence. ", @") 324 325 norm! 1gofdvlisy 326 call assert_equal('d sentence.', @") 327 norm! gvisy 328 call assert_equal('d sentence. ', @") 329 norm! gvisy 330 call assert_equal("d sentence. Third\nsentence.", @") 331 332 " Extend visual area in opposite direction. 333 norm! 1gofdvhasy 334 call assert_equal(' Second', @") 335 norm! gvasy 336 call assert_equal("First sentence. Second", @") 337 338 norm! 1gofdvhisy 339 call assert_equal('Second', @") 340 norm! gvisy 341 call assert_equal(' Second', @") 342 norm! gvisy 343 call assert_equal('First sentence. Second', @") 344 345 bwipe! 346endfunc 347 348func Test_Visual_paragraph_textobject() 349 new 350 call setline(1, ['First line.', 351 \ '', 352 \ 'Second line.', 353 \ 'Third line.', 354 \ 'Fourth line.', 355 \ 'Fifth line.', 356 \ '', 357 \ 'Sixth line.']) 358 359 " When start and end of visual area are identical, 'ap' or 'ip' select 360 " the whole paragraph. 361 norm! 4ggvapy 362 call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n\n", @") 363 norm! 4ggvipy 364 call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n", @") 365 366 " When start and end of visual area are not identical, 'ap' or 'ip' 367 " extend the sentence in direction of the end of the visual area. 368 " FIXME: actually, it is not sufficient to have different start and 369 " end of visual selection, the start line and end line have to differ, 370 " which is not consistent with the documentation. 371 norm! 4ggVjapy 372 call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") 373 norm! gvapy 374 call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") 375 norm! 4ggVjipy 376 call assert_equal("Third line.\nFourth line.\nFifth line.\n", @") 377 norm! gvipy 378 call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") 379 norm! gvipy 380 call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") 381 382 " Extend visual area in opposite direction. 383 norm! 5ggVkapy 384 call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") 385 norm! gvapy 386 call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") 387 norm! 5ggVkipy 388 call assert_equal("Second line.\nThird line.\nFourth line.\n", @") 389 norma gvipy 390 call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") 391 norm! gvipy 392 call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") 393 394 bwipe! 395endfunc 396 397func Test_curswant_not_changed() 398 new 399 call setline(1, ['one', 'two']) 400 au InsertLeave * call getcurpos() 401 call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt') 402 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 403 404 bwipe! 405 au! InsertLeave 406endfunc 407 408" Tests for "vaBiB", end could be wrong. 409func Test_Visual_Block() 410 new 411 a 412- Bug in "vPPPP" on this text: 413 { 414 cmd; 415 { 416 cmd;\t/* <-- Start cursor here */ 417 { 418 } 419 } 420 } 421. 422 normal gg 423 call search('Start cursor here') 424 normal vaBiBD 425 call assert_equal(['- Bug in "vPPPP" on this text:', 426 \ "\t{", 427 \ "\t}"], getline(1, '$')) 428 429 close! 430endfunc 431 432" Test for 'p'ut in visual block mode 433func Test_visual_block_put() 434 enew 435 436 call append(0, ['One', 'Two', 'Three']) 437 normal gg 438 yank 439 call feedkeys("jl\<C-V>ljp", 'xt') 440 call assert_equal(['One', 'T', 'Tee', 'One', ''], getline(1, '$')) 441 442 enew! 443endfunc 444 445" Visual modes (v V CTRL-V) followed by an operator; count; repeating 446func Test_visual_mode_op() 447 new 448 call append(0, '') 449 450 call setline(1, 'apple banana cherry') 451 call cursor(1, 1) 452 normal lvld.l3vd. 453 call assert_equal('a y', getline(1)) 454 455 call setline(1, ['line 1 line 1', 'line 2 line 2', 'line 3 line 3', 456 \ 'line 4 line 4', 'line 5 line 5', 'line 6 line 6']) 457 call cursor(1, 1) 458 exe "normal Vcnewline\<Esc>j.j2Vd." 459 call assert_equal(['newline', 'newline'], getline(1, '$')) 460 461 call deletebufline('', 1, '$') 462 call setline(1, ['xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 463 \ 'xxxxxxxxxxxxx']) 464 exe "normal \<C-V>jlc \<Esc>l.l2\<C-V>c----\<Esc>l." 465 call assert_equal([' --------x', 466 \ ' --------x', 467 \ 'xxxx--------x', 468 \ 'xxxx--------x'], getline(1, '$')) 469 470 bwipe! 471endfunc 472 473" Visual mode maps (movement and text object) 474" Visual mode maps; count; repeating 475" - Simple 476" - With an Ex command (custom text object) 477func Test_visual_mode_maps() 478 new 479 call append(0, '') 480 481 func SelectInCaps() 482 let [line1, col1] = searchpos('\u', 'bcnW') 483 let [line2, col2] = searchpos('.\u', 'nW') 484 call setpos("'<", [0, line1, col1, 0]) 485 call setpos("'>", [0, line2, col2, 0]) 486 normal! gv 487 endfunction 488 489 vnoremap W /\u/s-1<CR> 490 vnoremap iW :<C-U>call SelectInCaps()<CR> 491 492 call setline(1, 'KiwiRaspberryDateWatermelonPeach') 493 call cursor(1, 1) 494 exe "normal vWcNo\<Esc>l.fD2vd." 495 call assert_equal('NoNoberryach', getline(1)) 496 497 call setline(1, 'JambuRambutanBananaTangerineMango') 498 call cursor(1, 1) 499 exe "normal llviWc-\<Esc>l.l2vdl." 500 call assert_equal('--ago', getline(1)) 501 502 vunmap W 503 vunmap iW 504 bwipe! 505 delfunc SelectInCaps 506endfunc 507 508" Operator-pending mode maps (movement and text object) 509" - Simple 510" - With Ex command moving the cursor 511" - With Ex command and Visual selection (custom text object) 512func Test_visual_oper_pending_mode_maps() 513 new 514 call append(0, '') 515 516 func MoveToCap() 517 call search('\u', 'W') 518 endfunction 519 520 func SelectInCaps() 521 let [line1, col1] = searchpos('\u', 'bcnW') 522 let [line2, col2] = searchpos('.\u', 'nW') 523 call setpos("'<", [0, line1, col1, 0]) 524 call setpos("'>", [0, line2, col2, 0]) 525 normal! gv 526 endfunction 527 528 onoremap W /\u/<CR> 529 onoremap <Leader>W :<C-U>call MoveToCap()<CR> 530 onoremap iW :<C-U>call SelectInCaps()<CR> 531 532 call setline(1, 'PineappleQuinceLoganberryOrangeGrapefruitKiwiZ') 533 call cursor(1, 1) 534 exe "normal cW-\<Esc>l.l2.l." 535 call assert_equal('----Z', getline(1)) 536 537 call setline(1, 'JuniperDurianZ') 538 call cursor(1, 1) 539 exe "normal g?\WfD." 540 call assert_equal('WhavcreQhevnaZ', getline(1)) 541 542 call setline(1, 'LemonNectarineZ') 543 call cursor(1, 1) 544 exe "normal yiWPlciWNew\<Esc>fr." 545 call assert_equal('LemonNewNewZ', getline(1)) 546 547 ounmap W 548 ounmap <Leader>W 549 ounmap iW 550 bwipe! 551 delfunc MoveToCap 552 delfunc SelectInCaps 553endfunc 554 555" Patch 7.3.879: Properly abort Operator-pending mode for "dv:<Esc>" etc. 556func Test_op_pend_mode_abort() 557 new 558 call append(0, '') 559 560 call setline(1, ['zzzz', 'zzzz']) 561 call cursor(1, 1) 562 563 exe "normal dV:\<CR>dv:\<CR>" 564 call assert_equal(['zzz'], getline(1, 2)) 565 set nomodifiable 566 call assert_fails('exe "normal d:\<CR>"', 'E21:') 567 set modifiable 568 call feedkeys("dv:\<Esc>dV:\<Esc>", 'xt') 569 call assert_equal(['zzz'], getline(1, 2)) 570 set nomodifiable 571 let v:errmsg = '' 572 call feedkeys("d:\<Esc>", 'xt') 573 call assert_true(v:errmsg !~# '^E21:') 574 set modifiable 575 576 bwipe! 577endfunc 578 579func Test_characterwise_visual_mode() 580 new 581 582 " characterwise visual mode: replace last line 583 $put ='a' 584 let @" = 'x' 585 normal v$p 586 call assert_equal('x', getline('$')) 587 588 " characterwise visual mode: delete middle line 589 call deletebufline('', 1, '$') 590 call append('$', ['a', 'b', 'c']) 591 normal G 592 normal kkv$d 593 call assert_equal(['', 'b', 'c'], getline(1, '$')) 594 595 " characterwise visual mode: delete middle two lines 596 call deletebufline('', 1, '$') 597 call append('$', ['a', 'b', 'c']) 598 normal Gkkvj$d 599 call assert_equal(['', 'c'], getline(1, '$')) 600 601 " characterwise visual mode: delete last line 602 call deletebufline('', 1, '$') 603 call append('$', ['a', 'b', 'c']) 604 normal Gv$d 605 call assert_equal(['', 'a', 'b', ''], getline(1, '$')) 606 607 " characterwise visual mode: delete last two lines 608 call deletebufline('', 1, '$') 609 call append('$', ['a', 'b', 'c']) 610 normal Gkvj$d 611 call assert_equal(['', 'a', ''], getline(1, '$')) 612 613 bwipe! 614endfunc 615 616func Test_characterwise_select_mode() 617 new 618 619 " Select mode maps 620 snoremap <lt>End> <End> 621 snoremap <lt>Down> <Down> 622 snoremap <lt>Del> <Del> 623 624 " characterwise select mode: delete middle line 625 call deletebufline('', 1, '$') 626 call append('$', ['a', 'b', 'c']) 627 exe "normal Gkkgh\<End>\<Del>" 628 call assert_equal(['', 'b', 'c'], getline(1, '$')) 629 630 " characterwise select mode: delete middle two lines 631 call deletebufline('', 1, '$') 632 call append('$', ['a', 'b', 'c']) 633 exe "normal Gkkgh\<Down>\<End>\<Del>" 634 call assert_equal(['', 'c'], getline(1, '$')) 635 636 " characterwise select mode: delete last line 637 call deletebufline('', 1, '$') 638 call append('$', ['a', 'b', 'c']) 639 exe "normal Ggh\<End>\<Del>" 640 call assert_equal(['', 'a', 'b', ''], getline(1, '$')) 641 642 " characterwise select mode: delete last two lines 643 call deletebufline('', 1, '$') 644 call append('$', ['a', 'b', 'c']) 645 exe "normal Gkgh\<Down>\<End>\<Del>" 646 call assert_equal(['', 'a', ''], getline(1, '$')) 647 648 sunmap <lt>End> 649 sunmap <lt>Down> 650 sunmap <lt>Del> 651 bwipe! 652endfunc 653 654func Test_linewise_select_mode() 655 new 656 657 " linewise select mode: delete middle line 658 call append('$', ['a', 'b', 'c']) 659 exe "normal GkkgH\<Del>" 660 call assert_equal(['', 'b', 'c'], getline(1, '$')) 661 662 " linewise select mode: delete middle two lines 663 call deletebufline('', 1, '$') 664 call append('$', ['a', 'b', 'c']) 665 exe "normal GkkgH\<Down>\<Del>" 666 call assert_equal(['', 'c'], getline(1, '$')) 667 668 " linewise select mode: delete last line 669 call deletebufline('', 1, '$') 670 call append('$', ['a', 'b', 'c']) 671 exe "normal GgH\<Del>" 672 call assert_equal(['', 'a', 'b'], getline(1, '$')) 673 674 " linewise select mode: delete last two lines 675 call deletebufline('', 1, '$') 676 call append('$', ['a', 'b', 'c']) 677 exe "normal GkgH\<Down>\<Del>" 678 call assert_equal(['', 'a'], getline(1, '$')) 679 680 bwipe! 681endfunc 682 683" Test for blockwise select mode (g CTRL-H) 684func Test_blockwise_select_mode() 685 new 686 call setline(1, ['foo', 'bar']) 687 call feedkeys("g\<BS>\<Right>\<Down>mm", 'xt') 688 call assert_equal(['mmo', 'mmr'], getline(1, '$')) 689 close! 690endfunc 691 692func Test_visual_mode_put() 693 new 694 695 " v_p: replace last character with line register at middle line 696 call append('$', ['aaa', 'bbb', 'ccc']) 697 normal G 698 -2yank 699 normal k$vp 700 call assert_equal(['', 'aaa', 'bb', 'aaa', '', 'ccc'], getline(1, '$')) 701 702 " v_p: replace last character with line register at middle line selecting 703 " newline 704 call deletebufline('', 1, '$') 705 call append('$', ['aaa', 'bbb', 'ccc']) 706 normal G 707 -2yank 708 normal k$v$p 709 call assert_equal(['', 'aaa', 'bb', 'aaa', 'ccc'], getline(1, '$')) 710 711 " v_p: replace last character with line register at last line 712 call deletebufline('', 1, '$') 713 call append('$', ['aaa', 'bbb', 'ccc']) 714 normal G 715 -2yank 716 normal $vp 717 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) 718 719 " v_p: replace last character with line register at last line selecting 720 " newline 721 call deletebufline('', 1, '$') 722 call append('$', ['aaa', 'bbb', 'ccc']) 723 normal G 724 -2yank 725 normal $v$p 726 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) 727 728 bwipe! 729endfunc 730 731func Test_select_mode_gv() 732 new 733 734 " gv in exclusive select mode after operation 735 call append('$', ['zzz ', 'äà ']) 736 set selection=exclusive 737 normal Gkv3lyjv3lpgvcxxx 738 call assert_equal(['', 'zzz ', 'xxx '], getline(1, '$')) 739 740 " gv in exclusive select mode without operation 741 call deletebufline('', 1, '$') 742 call append('$', 'zzz ') 743 set selection=exclusive 744 exe "normal G0v3l\<Esc>gvcxxx" 745 call assert_equal(['', 'xxx '], getline(1, '$')) 746 747 set selection&vim 748 bwipe! 749endfunc 750 751" Tests for the visual block mode commands 752func Test_visual_block_mode() 753 new 754 call append(0, '') 755 call setline(1, ['abcdefghijklm', 'abcdefghijklm', 'abcdefghijklm', 756 \ 'abcdefghijklm', 'abcdefghijklm']) 757 call cursor(1, 1) 758 759 " Test shift-right of a block 760 exe "normal jllll\<C-V>jj>wll\<C-V>jlll>" 761 " Test shift-left of a block 762 exe "normal G$hhhh\<C-V>kk<" 763 " Test block-insert 764 exe "normal Gkl\<C-V>kkkIxyz" 765 " Test block-replace 766 exe "normal Gllll\<C-V>kkklllrq" 767 " Test block-change 768 exe "normal G$khhh\<C-V>hhkkcmno" 769 call assert_equal(['axyzbcdefghijklm', 770 \ 'axyzqqqq mno ghijklm', 771 \ 'axyzqqqqef mno ghijklm', 772 \ 'axyzqqqqefgmnoklm', 773 \ 'abcdqqqqijklm'], getline(1, 5)) 774 775 bwipe! 776endfunc 777 778" Test block-insert using cursor keys for movement 779func Test_visual_block_insert_cursor_keys() 780 new 781 call append(0, ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd']) 782 call cursor(1, 1) 783 784 exe "norm! l\<C-V>jjjlllI\<Right>\<Right> \<Esc>" 785 call assert_equal(['aaa aaa', 'bbb bbb', 'ccc ccc', 'ddd ddd'], 786 \ getline(1, 4)) 787 788 call deletebufline('', 1, '$') 789 call setline(1, ['xaaa', 'bbbb', 'cccc', 'dddd']) 790 call cursor(1, 1) 791 exe "norm! \<C-V>jjjI<>\<Left>p\<Esc>" 792 call assert_equal(['<p>xaaa', '<p>bbbb', '<p>cccc', '<p>dddd'], 793 \ getline(1, 4)) 794 bwipe! 795endfunc 796 797func Test_visual_block_create() 798 new 799 call append(0, '') 800 " Test for Visual block was created with the last <C-v>$ 801 call setline(1, ['A23', '4567']) 802 call cursor(1, 1) 803 exe "norm! l\<C-V>j$Aab\<Esc>" 804 call assert_equal(['A23ab', '4567ab'], getline(1, 2)) 805 806 " Test for Visual block was created with the middle <C-v>$ (1) 807 call deletebufline('', 1, '$') 808 call setline(1, ['B23', '4567']) 809 call cursor(1, 1) 810 exe "norm! l\<C-V>j$hAab\<Esc>" 811 call assert_equal(['B23 ab', '4567ab'], getline(1, 2)) 812 813 " Test for Visual block was created with the middle <C-v>$ (2) 814 call deletebufline('', 1, '$') 815 call setline(1, ['C23', '4567']) 816 call cursor(1, 1) 817 exe "norm! l\<C-V>j$hhAab\<Esc>" 818 call assert_equal(['C23ab', '456ab7'], getline(1, 2)) 819 bwipe! 820endfunc 821 822" Test for Visual block insert when virtualedit=all 823func Test_virtualedit_visual_block() 824 set ve=all 825 new 826 call append(0, ["\t\tline1", "\t\tline2", "\t\tline3"]) 827 call cursor(1, 1) 828 exe "norm! 07l\<C-V>jjIx\<Esc>" 829 call assert_equal([" x \tline1", 830 \ " x \tline2", 831 \ " x \tline3"], getline(1, 3)) 832 833 " Test for Visual block append when virtualedit=all 834 exe "norm! 012l\<C-v>jjAx\<Esc>" 835 call assert_equal([' x x line1', 836 \ ' x x line2', 837 \ ' x x line3'], getline(1, 3)) 838 set ve= 839 bwipe! 840endfunc 841 842" Test for changing case 843func Test_visual_change_case() 844 new 845 " gUe must uppercase a whole word, also when ß changes to SS 846 exe "normal Gothe youtußeuu end\<Esc>Ypk0wgUe\r" 847 " gUfx must uppercase until x, inclusive. 848 exe "normal O- youßtußexu -\<Esc>0fogUfx\r" 849 " VU must uppercase a whole line 850 exe "normal YpkVU\r" 851 " same, when it's the last line in the buffer 852 exe "normal YPGi111\<Esc>VUddP\r" 853 " Uppercase two lines 854 exe "normal Oblah di\rdoh dut\<Esc>VkUj\r" 855 " Uppercase part of two lines 856 exe "normal ddppi333\<Esc>k0i222\<Esc>fyllvjfuUk" 857 call assert_equal(['the YOUTUSSEUU end', '- yOUSSTUSSEXu -', 858 \ 'THE YOUTUSSEUU END', '111THE YOUTUSSEUU END', 'BLAH DI', 'DOH DUT', 859 \ '222the yoUTUSSEUU END', '333THE YOUTUßeuu end'], getline(2, '$')) 860 bwipe! 861endfunc 862 863" Test for Visual replace using Enter or NL 864func Test_visual_replace_crnl() 865 new 866 exe "normal G3o123456789\e2k05l\<C-V>2jr\r" 867 exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\r\n" 868 exe "normal G3o123456789\e2k05l\<C-V>2jr\n" 869 exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\n" 870 call assert_equal(['12345', '789', '12345', '789', '12345', '789', "98\r65", 871 \ "98\r65", "98\r65", '12345', '789', '12345', '789', '12345', '789', 872 \ "98\n65", "98\n65", "98\n65"], getline(2, '$')) 873 bwipe! 874endfunc 875 876func Test_ve_block_curpos() 877 new 878 " Test cursor position. When ve=block and Visual block mode and $gj 879 call append(0, ['12345', '789']) 880 call cursor(1, 3) 881 set virtualedit=block 882 exe "norm! \<C-V>$gj\<Esc>" 883 call assert_equal([0, 2, 4, 0], getpos("'>")) 884 set virtualedit= 885 bwipe! 886endfunc 887 888" Test for block_insert when replacing spaces in front of the a with tabs 889func Test_block_insert_replace_tabs() 890 new 891 set ts=8 sts=4 sw=4 892 call append(0, ["#define BO_ALL\t 0x0001", 893 \ "#define BO_BS\t 0x0002", 894 \ "#define BO_CRSR\t 0x0004"]) 895 call cursor(1, 1) 896 exe "norm! f0\<C-V>2jI\<tab>\<esc>" 897 call assert_equal([ 898 \ "#define BO_ALL\t\t0x0001", 899 \ "#define BO_BS\t \t0x0002", 900 \ "#define BO_CRSR\t \t0x0004", ''], getline(1, '$')) 901 set ts& sts& sw& 902 bwipe! 903endfunc 904 905" Test for * register in : 906func Test_star_register() 907 call assert_fails('*bfirst', 'E16:') 908 new 909 call setline(1, ['foo', 'bar', 'baz', 'qux']) 910 exe "normal jVj\<ESC>" 911 *yank r 912 call assert_equal("bar\nbaz\n", @r) 913 914 delmarks < > 915 call assert_fails('*yank', 'E20:') 916 close! 917endfunc 918 919" Test for using visual mode maps in select mode 920func Test_select_mode_map() 921 new 922 vmap <buffer> <F2> 3l 923 call setline(1, 'Test line') 924 call feedkeys("gh\<F2>map", 'xt') 925 call assert_equal('map line', getline(1)) 926 927 vmap <buffer> <F2> ygV 928 call feedkeys("0gh\<Right>\<Right>\<F2>cwabc", 'xt') 929 call assert_equal('abc line', getline(1)) 930 931 vmap <buffer> <F2> :<C-U>let v=100<CR> 932 call feedkeys("gggh\<Right>\<Right>\<F2>foo", 'xt') 933 call assert_equal('foo line', getline(1)) 934 935 " reselect the select mode using gv from a visual mode map 936 vmap <buffer> <F2> gv 937 set selectmode=cmd 938 call feedkeys("0gh\<F2>map", 'xt') 939 call assert_equal('map line', getline(1)) 940 set selectmode& 941 942 close! 943endfunc 944 945" Test for changing text in visual mode with 'exclusive' selection 946func Test_exclusive_selection() 947 new 948 call setline(1, ['one', 'two']) 949 set selection=exclusive 950 call feedkeys("vwcabc", 'xt') 951 call assert_equal('abctwo', getline(1)) 952 call setline(1, ["\tone"]) 953 set virtualedit=all 954 call feedkeys('0v2lcl', 'xt') 955 call assert_equal('l one', getline(1)) 956 set virtualedit& 957 set selection& 958 close! 959endfunc 960 961" Test for starting visual mode with a count 962" This test should be run withou any previous visual modes. So this should be 963" run as a first test. 964func Test_AAA_start_visual_mode_with_count() 965 new 966 call setline(1, ['aaaaaaa', 'aaaaaaa', 'aaaaaaa', 'aaaaaaa']) 967 normal! gg2Vy 968 call assert_equal("aaaaaaa\naaaaaaa\n", @") 969 close! 970endfunc 971 972" vim: shiftwidth=2 sts=2 expandtab 973