1" Test for various Normal mode commands 2 3source shared.vim 4source check.vim 5source view_util.vim 6 7func Setup_NewWindow() 8 10new 9 call setline(1, range(1,100)) 10endfunc 11 12func MyFormatExpr() 13 " Adds '->$' at lines having numbers followed by trailing whitespace 14 for ln in range(v:lnum, v:lnum+v:count-1) 15 let line = getline(ln) 16 if getline(ln) =~# '\d\s\+$' 17 call setline(ln, substitute(line, '\s\+$', '', '') . '->$') 18 endif 19 endfor 20endfunc 21 22func CountSpaces(type, ...) 23 " for testing operatorfunc 24 " will count the number of spaces 25 " and return the result in g:a 26 let sel_save = &selection 27 let &selection = "inclusive" 28 let reg_save = @@ 29 30 if a:0 " Invoked from Visual mode, use gv command. 31 silent exe "normal! gvy" 32 elseif a:type == 'line' 33 silent exe "normal! '[V']y" 34 else 35 silent exe "normal! `[v`]y" 36 endif 37 let g:a=strlen(substitute(@@, '[^ ]', '', 'g')) 38 let &selection = sel_save 39 let @@ = reg_save 40endfunc 41 42func OpfuncDummy(type, ...) 43 " for testing operatorfunc 44 let g:opt=&linebreak 45 46 if a:0 " Invoked from Visual mode, use gv command. 47 silent exe "normal! gvy" 48 elseif a:type == 'line' 49 silent exe "normal! '[V']y" 50 else 51 silent exe "normal! `[v`]y" 52 endif 53 " Create a new dummy window 54 new 55 let g:bufnr=bufnr('%') 56endfunc 57 58func Test_normal00_optrans() 59 new 60 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) 61 1 62 exe "norm! Sfoobar\<esc>" 63 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$')) 64 2 65 exe "norm! $vbsone" 66 call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$')) 67 norm! VS Second line here 68 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$')) 69 %d 70 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line']) 71 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) 72 73 1 74 norm! 2D 75 call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) 76 set cpo+=# 77 norm! 4D 78 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) 79 80 " clean up 81 set cpo-=# 82 bw! 83endfunc 84 85func Test_normal01_keymodel() 86 call Setup_NewWindow() 87 " Test 1: depending on 'keymodel' <s-down> does something different 88 50 89 call feedkeys("V\<S-Up>y", 'tx') 90 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>")) 91 set keymodel=startsel 92 50 93 call feedkeys("V\<S-Up>y", 'tx') 94 call assert_equal(['49', '50'], getline("'<", "'>")) 95 " Start visual mode when keymodel = startsel 96 50 97 call feedkeys("\<S-Up>y", 'tx') 98 call assert_equal(['49', '5'], getreg(0, 0, 1)) 99 " Use the different Shift special keys 100 50 101 call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx') 102 call assert_equal(['50'], getline("'<", "'>")) 103 call assert_equal(['50', ''], getreg(0, 0, 1)) 104 105 " Do not start visual mode when keymodel= 106 set keymodel= 107 50 108 call feedkeys("\<S-Up>y$", 'tx') 109 call assert_equal(['42'], getreg(0, 0, 1)) 110 " Stop visual mode when keymodel=stopsel 111 set keymodel=stopsel 112 50 113 call feedkeys("Vkk\<Up>yy", 'tx') 114 call assert_equal(['47'], getreg(0, 0, 1)) 115 116 set keymodel= 117 50 118 call feedkeys("Vkk\<Up>yy", 'tx') 119 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1)) 120 121 " clean up 122 bw! 123endfunc 124 125func Test_normal03_join() 126 " basic join test 127 call Setup_NewWindow() 128 50 129 norm! VJ 130 call assert_equal('50 51', getline('.')) 131 $ 132 norm! J 133 call assert_equal('100', getline('.')) 134 $ 135 norm! V9-gJ 136 call assert_equal('919293949596979899100', getline('.')) 137 call setline(1, range(1,100)) 138 $ 139 :j 10 140 call assert_equal('100', getline('.')) 141 call assert_beeps('normal GVJ') 142 " clean up 143 bw! 144endfunc 145 146" basic filter test 147func Test_normal04_filter() 148 " only test on non windows platform 149 CheckNotMSWindows 150 call Setup_NewWindow() 151 1 152 call feedkeys("!!sed -e 's/^/| /'\n", 'tx') 153 call assert_equal('| 1', getline('.')) 154 90 155 :sil :!echo one 156 call feedkeys('.', 'tx') 157 call assert_equal('| 90', getline('.')) 158 95 159 set cpo+=! 160 " 2 <CR>, 1: for executing the command, 161 " 2: clear hit-enter-prompt 162 call feedkeys("!!\n", 'tx') 163 call feedkeys(":!echo one\n\n", 'tx') 164 call feedkeys(".", 'tx') 165 call assert_equal('one', getline('.')) 166 set cpo-=! 167 bw! 168endfunc 169 170func Test_normal05_formatexpr() 171 " basic formatexpr test 172 call Setup_NewWindow() 173 %d_ 174 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: ']) 175 1 176 set formatexpr=MyFormatExpr() 177 norm! gqG 178 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$')) 179 set formatexpr= 180 bw! 181endfunc 182 183func Test_normal05_formatexpr_newbuf() 184 " Edit another buffer in the 'formatexpr' function 185 new 186 func! Format() 187 edit another 188 endfunc 189 set formatexpr=Format() 190 norm gqG 191 bw! 192 set formatexpr= 193endfunc 194 195func Test_normal05_formatexpr_setopt() 196 " Change the 'formatexpr' value in the function 197 new 198 func! Format() 199 set formatexpr= 200 endfunc 201 set formatexpr=Format() 202 norm gqG 203 bw! 204 set formatexpr= 205endfunc 206 207" basic test for formatprg 208func Test_normal06_formatprg() 209 " only test on non windows platform 210 CheckNotMSWindows 211 212 " uses sed to number non-empty lines 213 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh') 214 call system('chmod +x ./Xsed_format.sh') 215 let text = ['a', '', 'c', '', ' ', 'd', 'e'] 216 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e'] 217 218 10new 219 call setline(1, text) 220 set formatprg=./Xsed_format.sh 221 norm! gggqG 222 call assert_equal(expected, getline(1, '$')) 223 %d 224 225 call setline(1, text) 226 set formatprg=donothing 227 setlocal formatprg=./Xsed_format.sh 228 norm! gggqG 229 call assert_equal(expected, getline(1, '$')) 230 %d 231 232 " Check for the command-line ranges added to 'formatprg' 233 set formatprg=cat 234 call setline(1, ['one', 'two', 'three', 'four', 'five']) 235 call feedkeys('gggqG', 'xt') 236 call assert_equal('.,$!cat', @:) 237 call feedkeys('2Ggq2j', 'xt') 238 call assert_equal('.,.+2!cat', @:) 239 240 bw! 241 " clean up 242 set formatprg= 243 setlocal formatprg= 244 call delete('Xsed_format.sh') 245endfunc 246 247func Test_normal07_internalfmt() 248 " basic test for internal formmatter to textwidth of 12 249 let list=range(1,11) 250 call map(list, 'v:val." "') 251 10new 252 call setline(1, list) 253 set tw=12 254 norm! ggVGgq 255 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$')) 256 " clean up 257 set tw=0 258 bw! 259endfunc 260 261" basic tests for foldopen/folddelete 262func Test_normal08_fold() 263 CheckFeature folding 264 call Setup_NewWindow() 265 50 266 setl foldenable fdm=marker 267 " First fold 268 norm! V4jzf 269 " check that folds have been created 270 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54)) 271 " Second fold 272 46 273 norm! V10jzf 274 " check that folds have been created 275 call assert_equal('46/*{{{*/', getline(46)) 276 call assert_equal('60/*}}}*/', getline(60)) 277 norm! k 278 call assert_equal('45', getline('.')) 279 norm! j 280 call assert_equal('46/*{{{*/', getline('.')) 281 norm! j 282 call assert_equal('61', getline('.')) 283 norm! k 284 " open a fold 285 norm! Vzo 286 norm! k 287 call assert_equal('45', getline('.')) 288 norm! j 289 call assert_equal('46/*{{{*/', getline('.')) 290 norm! j 291 call assert_equal('47', getline('.')) 292 norm! k 293 norm! zcVzO 294 call assert_equal('46/*{{{*/', getline('.')) 295 norm! j 296 call assert_equal('47', getline('.')) 297 norm! j 298 call assert_equal('48', getline('.')) 299 norm! j 300 call assert_equal('49', getline('.')) 301 norm! j 302 call assert_equal('50/*{{{*/', getline('.')) 303 norm! j 304 call assert_equal('51', getline('.')) 305 " delete folds 306 :46 307 " collapse fold 308 norm! V14jzC 309 " delete all folds recursively 310 norm! VzD 311 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60)) 312 313 " clean up 314 setl nofoldenable fdm=marker 315 bw! 316endfunc 317 318func Test_normal09_operatorfunc() 319 " Test operatorfunc 320 call Setup_NewWindow() 321 " Add some spaces for counting 322 50,60s/$/ / 323 unlet! g:a 324 let g:a=0 325 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@ 326 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR> 327 50 328 norm V2j,, 329 call assert_equal(6, g:a) 330 norm V,, 331 call assert_equal(2, g:a) 332 norm ,,l 333 call assert_equal(0, g:a) 334 50 335 exe "norm 0\<c-v>10j2l,," 336 call assert_equal(11, g:a) 337 50 338 norm V10j,, 339 call assert_equal(22, g:a) 340 341 " clean up 342 unmap <buffer> ,, 343 set opfunc= 344 unlet! g:a 345 bw! 346endfunc 347 348func Test_normal09a_operatorfunc() 349 " Test operatorfunc 350 call Setup_NewWindow() 351 " Add some spaces for counting 352 50,60s/$/ / 353 unlet! g:opt 354 set linebreak 355 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@ 356 50 357 norm ,,j 358 exe "bd!" g:bufnr 359 call assert_true(&linebreak) 360 call assert_equal(g:opt, &linebreak) 361 set nolinebreak 362 norm ,,j 363 exe "bd!" g:bufnr 364 call assert_false(&linebreak) 365 call assert_equal(g:opt, &linebreak) 366 367 " clean up 368 unmap <buffer> ,, 369 set opfunc= 370 call assert_fails('normal Vg@', 'E774:') 371 bw! 372 unlet! g:opt 373endfunc 374 375func Test_normal10_expand() 376 " Test for expand() 377 10new 378 call setline(1, ['1', 'ifooar,,cbar']) 379 2 380 norm! $ 381 call assert_equal('cbar', expand('<cword>')) 382 call assert_equal('ifooar,,cbar', expand('<cWORD>')) 383 384 call setline(1, ['prx = list[idx];']) 385 1 386 let expected = ['', 'prx', 'prx', 'prx', 387 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list', 388 \ 'idx', 'idx', 'idx', 'idx', 389 \ 'list[idx]', 390 \ '];', 391 \ ] 392 for i in range(1, 16) 393 exe 'norm ' . i . '|' 394 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i) 395 endfor 396 397 if executable('echo') 398 " Test expand(`...`) i.e. backticks command expansion. 399 call assert_equal('abcde', expand('`echo abcde`')) 400 endif 401 402 " Test expand(`=...`) i.e. backticks expression expansion 403 call assert_equal('5', expand('`=2+3`')) 404 call assert_equal('3.14', expand('`=3.14`')) 405 406 " clean up 407 bw! 408endfunc 409 410func Test_normal11_showcmd() 411 " test for 'showcmd' 412 10new 413 exe "norm! ofoobar\<esc>" 414 call assert_equal(2, line('$')) 415 set showcmd 416 exe "norm! ofoobar2\<esc>" 417 call assert_equal(3, line('$')) 418 exe "norm! VAfoobar3\<esc>" 419 call assert_equal(3, line('$')) 420 exe "norm! 0d3\<del>2l" 421 call assert_equal('obar2foobar3', getline('.')) 422 bw! 423endfunc 424 425" Test for nv_error and normal command errors 426func Test_normal12_nv_error() 427 10new 428 call setline(1, range(1,5)) 429 " should not do anything, just beep 430 call assert_beeps('exe "norm! <c-k>"') 431 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$')) 432 call assert_beeps('normal! G2dd') 433 call assert_beeps("normal! g\<C-A>") 434 call assert_beeps("normal! g\<C-X>") 435 call assert_beeps("normal! g\<C-B>") 436 call assert_beeps("normal! vQ\<Esc>") 437 call assert_beeps("normal! 2[[") 438 call assert_beeps("normal! 2]]") 439 call assert_beeps("normal! 2[]") 440 call assert_beeps("normal! 2][") 441 call assert_beeps("normal! 4[z") 442 call assert_beeps("normal! 4]z") 443 call assert_beeps("normal! 4[c") 444 call assert_beeps("normal! 4]c") 445 call assert_beeps("normal! 200%") 446 call assert_beeps("normal! %") 447 call assert_beeps("normal! 2{") 448 call assert_beeps("normal! 2}") 449 call assert_beeps("normal! r\<Right>") 450 call assert_beeps("normal! 8ry") 451 call assert_beeps('normal! "@') 452 bw! 453endfunc 454 455func Test_normal13_help() 456 " Test for F1 457 call assert_equal(1, winnr()) 458 call feedkeys("\<f1>", 'txi') 459 call assert_match('help\.txt', bufname('%')) 460 call assert_equal(2, winnr('$')) 461 bw! 462endfunc 463 464func Test_normal14_page() 465 " basic test for Ctrl-F and Ctrl-B 466 call Setup_NewWindow() 467 exe "norm! \<c-f>" 468 call assert_equal('9', getline('.')) 469 exe "norm! 2\<c-f>" 470 call assert_equal('25', getline('.')) 471 exe "norm! 2\<c-b>" 472 call assert_equal('18', getline('.')) 473 1 474 set scrolloff=5 475 exe "norm! 2\<c-f>" 476 call assert_equal('21', getline('.')) 477 exe "norm! \<c-b>" 478 call assert_equal('13', getline('.')) 479 1 480 set scrolloff=99 481 exe "norm! \<c-f>" 482 call assert_equal('13', getline('.')) 483 set scrolloff=0 484 100 485 exe "norm! $\<c-b>" 486 call assert_equal('92', getline('.')) 487 call assert_equal([0, 92, 1, 0, 1], getcurpos()) 488 100 489 set nostartofline 490 exe "norm! $\<c-b>" 491 call assert_equal('92', getline('.')) 492 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos()) 493 " cleanup 494 set startofline 495 bw! 496endfunc 497 498func Test_normal14_page_eol() 499 10new 500 norm oxxxxxxx 501 exe "norm 2\<c-f>" 502 " check with valgrind that cursor is put back in column 1 503 exe "norm 2\<c-b>" 504 bw! 505endfunc 506 507" Test for errors with z command 508func Test_normal_z_error() 509 call assert_beeps('normal! z2p') 510 call assert_beeps('normal! zp') 511endfunc 512 513func Test_normal15_z_scroll_vert() 514 " basic test for z commands that scroll the window 515 call Setup_NewWindow() 516 100 517 norm! >> 518 " Test for z<cr> 519 exe "norm! z\<cr>" 520 call assert_equal(' 100', getline('.')) 521 call assert_equal(100, winsaveview()['topline']) 522 call assert_equal([0, 100, 2, 0, 9], getcurpos()) 523 524 " Test for zt 525 21 526 norm! >>0zt 527 call assert_equal(' 21', getline('.')) 528 call assert_equal(21, winsaveview()['topline']) 529 call assert_equal([0, 21, 1, 0, 8], getcurpos()) 530 531 " Test for zb 532 30 533 norm! >>$ztzb 534 call assert_equal(' 30', getline('.')) 535 call assert_equal(30, winsaveview()['topline']+winheight(0)-1) 536 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos()) 537 538 " Test for z- 539 1 540 30 541 norm! 0z- 542 call assert_equal(' 30', getline('.')) 543 call assert_equal(30, winsaveview()['topline']+winheight(0)-1) 544 call assert_equal([0, 30, 2, 0, 9], getcurpos()) 545 546 " Test for z{height}<cr> 547 call assert_equal(10, winheight(0)) 548 exe "norm! z12\<cr>" 549 call assert_equal(12, winheight(0)) 550 exe "norm! z10\<cr>" 551 call assert_equal(10, winheight(0)) 552 553 " Test for z. 554 1 555 21 556 norm! 0z. 557 call assert_equal(' 21', getline('.')) 558 call assert_equal(17, winsaveview()['topline']) 559 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 560 561 " Test for zz 562 1 563 21 564 norm! 0zz 565 call assert_equal(' 21', getline('.')) 566 call assert_equal(17, winsaveview()['topline']) 567 call assert_equal([0, 21, 1, 0, 8], getcurpos()) 568 569 " Test for z+ 570 11 571 norm! zt 572 norm! z+ 573 call assert_equal(' 21', getline('.')) 574 call assert_equal(21, winsaveview()['topline']) 575 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 576 577 " Test for [count]z+ 578 1 579 norm! 21z+ 580 call assert_equal(' 21', getline('.')) 581 call assert_equal(21, winsaveview()['topline']) 582 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 583 584 " Test for z^ 585 norm! 22z+0 586 norm! z^ 587 call assert_equal(' 21', getline('.')) 588 call assert_equal(12, winsaveview()['topline']) 589 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 590 591 " Test for [count]z^ 592 1 593 norm! 30z^ 594 call assert_equal(' 21', getline('.')) 595 call assert_equal(12, winsaveview()['topline']) 596 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 597 598 " cleanup 599 bw! 600endfunc 601 602func Test_normal16_z_scroll_hor() 603 " basic test for z commands that scroll the window 604 10new 605 15vsp 606 set nowrap listchars= 607 let lineA='abcdefghijklmnopqrstuvwxyz' 608 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 609 $put =lineA 610 $put =lineB 611 1d 612 613 " Test for zl and zh with a count 614 norm! 0z10l 615 call assert_equal([11, 1], [col('.'), wincol()]) 616 norm! z4h 617 call assert_equal([11, 5], [col('.'), wincol()]) 618 normal! 2gg 619 620 " Test for zl 621 1 622 norm! 5zl 623 call assert_equal(lineA, getline('.')) 624 call assert_equal(6, col('.')) 625 call assert_equal(5, winsaveview()['leftcol']) 626 norm! yl 627 call assert_equal('f', @0) 628 629 " Test for zh 630 norm! 2zh 631 call assert_equal(lineA, getline('.')) 632 call assert_equal(6, col('.')) 633 norm! yl 634 call assert_equal('f', @0) 635 call assert_equal(3, winsaveview()['leftcol']) 636 637 " Test for zL 638 norm! zL 639 call assert_equal(11, col('.')) 640 norm! yl 641 call assert_equal('k', @0) 642 call assert_equal(10, winsaveview()['leftcol']) 643 norm! 2zL 644 call assert_equal(25, col('.')) 645 norm! yl 646 call assert_equal('y', @0) 647 call assert_equal(24, winsaveview()['leftcol']) 648 649 " Test for zH 650 norm! 2zH 651 call assert_equal(25, col('.')) 652 call assert_equal(10, winsaveview()['leftcol']) 653 norm! yl 654 call assert_equal('y', @0) 655 656 " Test for zs 657 norm! $zs 658 call assert_equal(26, col('.')) 659 call assert_equal(25, winsaveview()['leftcol']) 660 norm! yl 661 call assert_equal('z', @0) 662 663 " Test for ze 664 norm! ze 665 call assert_equal(26, col('.')) 666 call assert_equal(11, winsaveview()['leftcol']) 667 norm! yl 668 call assert_equal('z', @0) 669 670 " cleanup 671 set wrap listchars=eol:$ 672 bw! 673endfunc 674 675func Test_normal17_z_scroll_hor2() 676 " basic test for z commands that scroll the window 677 " using 'sidescrolloff' setting 678 10new 679 20vsp 680 set nowrap listchars= sidescrolloff=5 681 let lineA='abcdefghijklmnopqrstuvwxyz' 682 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 683 $put =lineA 684 $put =lineB 685 1d 686 687 " Test for zl 688 1 689 norm! 5zl 690 call assert_equal(lineA, getline('.')) 691 call assert_equal(11, col('.')) 692 call assert_equal(5, winsaveview()['leftcol']) 693 norm! yl 694 call assert_equal('k', @0) 695 696 " Test for zh 697 norm! 2zh 698 call assert_equal(lineA, getline('.')) 699 call assert_equal(11, col('.')) 700 norm! yl 701 call assert_equal('k', @0) 702 call assert_equal(3, winsaveview()['leftcol']) 703 704 " Test for zL 705 norm! 0zL 706 call assert_equal(16, col('.')) 707 norm! yl 708 call assert_equal('p', @0) 709 call assert_equal(10, winsaveview()['leftcol']) 710 norm! 2zL 711 call assert_equal(26, col('.')) 712 norm! yl 713 call assert_equal('z', @0) 714 call assert_equal(15, winsaveview()['leftcol']) 715 716 " Test for zH 717 norm! 2zH 718 call assert_equal(15, col('.')) 719 call assert_equal(0, winsaveview()['leftcol']) 720 norm! yl 721 call assert_equal('o', @0) 722 723 " Test for zs 724 norm! $zs 725 call assert_equal(26, col('.')) 726 call assert_equal(20, winsaveview()['leftcol']) 727 norm! yl 728 call assert_equal('z', @0) 729 730 " Test for ze 731 norm! ze 732 call assert_equal(26, col('.')) 733 call assert_equal(11, winsaveview()['leftcol']) 734 norm! yl 735 call assert_equal('z', @0) 736 737 " cleanup 738 set wrap listchars=eol:$ sidescrolloff=0 739 bw! 740endfunc 741 742" Test for H, M and L commands with folds 743func Test_scroll_cmds() 744 15new 745 call setline(1, range(1, 100)) 746 exe "normal! 30ggz\<CR>" 747 set foldenable 748 33,36fold 749 40,43fold 750 46,49fold 751 let h = winheight(0) 752 " Top of the screen = 30 753 " Folded lines = 9 754 " Bottom of the screen = 30 + h + 9 - 1 755 normal! 4L 756 call assert_equal(35 + h, line('.')) 757 normal! 4H 758 call assert_equal(33, line('.')) 759 set foldenable& 760 close! 761endfunc 762 763" basic tests for foldopen/folddelete 764func Test_normal18_z_fold() 765 CheckFeature folding 766 call Setup_NewWindow() 767 50 768 setl foldenable fdm=marker foldlevel=5 769 770 call assert_beeps('normal! zj') 771 call assert_beeps('normal! zk') 772 773 " Test for zF 774 " First fold 775 norm! 4zF 776 " check that folds have been created 777 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53)) 778 779 " Test for zd 780 51 781 norm! 2zF 782 call assert_equal(2, foldlevel('.')) 783 norm! kzd 784 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53)) 785 norm! j 786 call assert_equal(1, foldlevel('.')) 787 788 " Test for zD 789 " also deletes partially selected folds recursively 790 51 791 norm! zF 792 call assert_equal(2, foldlevel('.')) 793 norm! kV2jzD 794 call assert_equal(['50', '51', '52', '53'], getline(50,53)) 795 796 " Test for zE 797 85 798 norm! 4zF 799 86 800 norm! 2zF 801 90 802 norm! 4zF 803 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93)) 804 norm! zE 805 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93)) 806 807 " Test for zn 808 50 809 set foldlevel=0 810 norm! 2zF 811 norm! zn 812 norm! k 813 call assert_equal('49', getline('.')) 814 norm! j 815 call assert_equal('50/*{{{*/', getline('.')) 816 norm! j 817 call assert_equal('51/*}}}*/', getline('.')) 818 norm! j 819 call assert_equal('52', getline('.')) 820 call assert_equal(0, &foldenable) 821 822 " Test for zN 823 49 824 norm! zN 825 call assert_equal('49', getline('.')) 826 norm! j 827 call assert_equal('50/*{{{*/', getline('.')) 828 norm! j 829 call assert_equal('52', getline('.')) 830 call assert_equal(1, &foldenable) 831 832 " Test for zi 833 norm! zi 834 call assert_equal(0, &foldenable) 835 norm! zi 836 call assert_equal(1, &foldenable) 837 norm! zi 838 call assert_equal(0, &foldenable) 839 norm! zi 840 call assert_equal(1, &foldenable) 841 842 " Test for za 843 50 844 norm! za 845 norm! k 846 call assert_equal('49', getline('.')) 847 norm! j 848 call assert_equal('50/*{{{*/', getline('.')) 849 norm! j 850 call assert_equal('51/*}}}*/', getline('.')) 851 norm! j 852 call assert_equal('52', getline('.')) 853 50 854 norm! za 855 norm! k 856 call assert_equal('49', getline('.')) 857 norm! j 858 call assert_equal('50/*{{{*/', getline('.')) 859 norm! j 860 call assert_equal('52', getline('.')) 861 862 49 863 norm! 5zF 864 norm! k 865 call assert_equal('48', getline('.')) 866 norm! j 867 call assert_equal('49/*{{{*/', getline('.')) 868 norm! j 869 call assert_equal('55', getline('.')) 870 49 871 norm! za 872 call assert_equal('49/*{{{*/', getline('.')) 873 norm! j 874 call assert_equal('50/*{{{*/', getline('.')) 875 norm! j 876 call assert_equal('52', getline('.')) 877 set nofoldenable 878 " close fold and set foldenable 879 norm! za 880 call assert_equal(1, &foldenable) 881 882 50 883 " have to use {count}za to open all folds and make the cursor visible 884 norm! 2za 885 norm! 2k 886 call assert_equal('48', getline('.')) 887 norm! j 888 call assert_equal('49/*{{{*/', getline('.')) 889 norm! j 890 call assert_equal('50/*{{{*/', getline('.')) 891 norm! j 892 call assert_equal('51/*}}}*/', getline('.')) 893 norm! j 894 call assert_equal('52', getline('.')) 895 896 " Test for zA 897 49 898 set foldlevel=0 899 50 900 norm! zA 901 norm! 2k 902 call assert_equal('48', getline('.')) 903 norm! j 904 call assert_equal('49/*{{{*/', getline('.')) 905 norm! j 906 call assert_equal('50/*{{{*/', getline('.')) 907 norm! j 908 call assert_equal('51/*}}}*/', getline('.')) 909 norm! j 910 call assert_equal('52', getline('.')) 911 912 " zA on a opened fold when foldenable is not set 913 50 914 set nofoldenable 915 norm! zA 916 call assert_equal(1, &foldenable) 917 norm! k 918 call assert_equal('48', getline('.')) 919 norm! j 920 call assert_equal('49/*{{{*/', getline('.')) 921 norm! j 922 call assert_equal('55', getline('.')) 923 924 " Test for zc 925 norm! zE 926 50 927 norm! 2zF 928 49 929 norm! 5zF 930 set nofoldenable 931 50 932 " There most likely is a bug somewhere: 933 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ 934 " TODO: Should this only close the inner most fold or both folds? 935 norm! zc 936 call assert_equal(1, &foldenable) 937 norm! k 938 call assert_equal('48', getline('.')) 939 norm! j 940 call assert_equal('49/*{{{*/', getline('.')) 941 norm! j 942 call assert_equal('55', getline('.')) 943 set nofoldenable 944 50 945 norm! Vjzc 946 norm! k 947 call assert_equal('48', getline('.')) 948 norm! j 949 call assert_equal('49/*{{{*/', getline('.')) 950 norm! j 951 call assert_equal('55', getline('.')) 952 953 " Test for zC 954 set nofoldenable 955 50 956 norm! zCk 957 call assert_equal('48', getline('.')) 958 norm! j 959 call assert_equal('49/*{{{*/', getline('.')) 960 norm! j 961 call assert_equal('55', getline('.')) 962 963 " Test for zx 964 " 1) close folds at line 49-54 965 set nofoldenable 966 48 967 norm! zx 968 call assert_equal(1, &foldenable) 969 norm! j 970 call assert_equal('49/*{{{*/', getline('.')) 971 norm! j 972 call assert_equal('55', getline('.')) 973 974 " 2) do not close fold under cursor 975 51 976 set nofoldenable 977 norm! zx 978 call assert_equal(1, &foldenable) 979 norm! 3k 980 call assert_equal('48', getline('.')) 981 norm! j 982 call assert_equal('49/*{{{*/', getline('.')) 983 norm! j 984 call assert_equal('50/*{{{*/', getline('.')) 985 norm! j 986 call assert_equal('51/*}}}*/', getline('.')) 987 norm! j 988 call assert_equal('52', getline('.')) 989 norm! j 990 call assert_equal('53', getline('.')) 991 norm! j 992 call assert_equal('54/*}}}*/', getline('.')) 993 norm! j 994 call assert_equal('55', getline('.')) 995 996 " 3) close one level of folds 997 48 998 set nofoldenable 999 set foldlevel=1 1000 norm! zx 1001 call assert_equal(1, &foldenable) 1002 call assert_equal('48', getline('.')) 1003 norm! j 1004 call assert_equal('49/*{{{*/', getline('.')) 1005 norm! j 1006 call assert_equal('50/*{{{*/', getline('.')) 1007 norm! j 1008 call assert_equal('52', getline('.')) 1009 norm! j 1010 call assert_equal('53', getline('.')) 1011 norm! j 1012 call assert_equal('54/*}}}*/', getline('.')) 1013 norm! j 1014 call assert_equal('55', getline('.')) 1015 1016 " Test for zX 1017 " Close all folds 1018 set foldlevel=0 nofoldenable 1019 50 1020 norm! zX 1021 call assert_equal(1, &foldenable) 1022 norm! k 1023 call assert_equal('48', getline('.')) 1024 norm! j 1025 call assert_equal('49/*{{{*/', getline('.')) 1026 norm! j 1027 call assert_equal('55', getline('.')) 1028 1029 " Test for zm 1030 50 1031 set nofoldenable foldlevel=2 1032 norm! zm 1033 call assert_equal(1, &foldenable) 1034 call assert_equal(1, &foldlevel) 1035 norm! zm 1036 call assert_equal(0, &foldlevel) 1037 norm! zm 1038 call assert_equal(0, &foldlevel) 1039 norm! k 1040 call assert_equal('48', getline('.')) 1041 norm! j 1042 call assert_equal('49/*{{{*/', getline('.')) 1043 norm! j 1044 call assert_equal('55', getline('.')) 1045 1046 " Test for zM 1047 48 1048 set nofoldenable foldlevel=99 1049 norm! zM 1050 call assert_equal(1, &foldenable) 1051 call assert_equal(0, &foldlevel) 1052 call assert_equal('48', getline('.')) 1053 norm! j 1054 call assert_equal('49/*{{{*/', getline('.')) 1055 norm! j 1056 call assert_equal('55', getline('.')) 1057 1058 " Test for zr 1059 48 1060 set nofoldenable foldlevel=0 1061 norm! zr 1062 call assert_equal(0, &foldenable) 1063 call assert_equal(1, &foldlevel) 1064 set foldlevel=0 foldenable 1065 norm! zr 1066 call assert_equal(1, &foldenable) 1067 call assert_equal(1, &foldlevel) 1068 norm! zr 1069 call assert_equal(2, &foldlevel) 1070 call assert_equal('48', getline('.')) 1071 norm! j 1072 call assert_equal('49/*{{{*/', getline('.')) 1073 norm! j 1074 call assert_equal('50/*{{{*/', getline('.')) 1075 norm! j 1076 call assert_equal('51/*}}}*/', getline('.')) 1077 norm! j 1078 call assert_equal('52', getline('.')) 1079 1080 " Test for zR 1081 48 1082 set nofoldenable foldlevel=0 1083 norm! zR 1084 call assert_equal(0, &foldenable) 1085 call assert_equal(2, &foldlevel) 1086 set foldenable foldlevel=0 1087 norm! zR 1088 call assert_equal(1, &foldenable) 1089 call assert_equal(2, &foldlevel) 1090 call assert_equal('48', getline('.')) 1091 norm! j 1092 call assert_equal('49/*{{{*/', getline('.')) 1093 norm! j 1094 call assert_equal('50/*{{{*/', getline('.')) 1095 norm! j 1096 call assert_equal('51/*}}}*/', getline('.')) 1097 norm! j 1098 call assert_equal('52', getline('.')) 1099 call append(50, ['a /*{{{*/', 'b /*}}}*/']) 1100 48 1101 call assert_equal('48', getline('.')) 1102 norm! j 1103 call assert_equal('49/*{{{*/', getline('.')) 1104 norm! j 1105 call assert_equal('50/*{{{*/', getline('.')) 1106 norm! j 1107 call assert_equal('a /*{{{*/', getline('.')) 1108 norm! j 1109 call assert_equal('51/*}}}*/', getline('.')) 1110 norm! j 1111 call assert_equal('52', getline('.')) 1112 48 1113 norm! zR 1114 call assert_equal(1, &foldenable) 1115 call assert_equal(3, &foldlevel) 1116 call assert_equal('48', getline('.')) 1117 norm! j 1118 call assert_equal('49/*{{{*/', getline('.')) 1119 norm! j 1120 call assert_equal('50/*{{{*/', getline('.')) 1121 norm! j 1122 call assert_equal('a /*{{{*/', getline('.')) 1123 norm! j 1124 call assert_equal('b /*}}}*/', getline('.')) 1125 norm! j 1126 call assert_equal('51/*}}}*/', getline('.')) 1127 norm! j 1128 call assert_equal('52', getline('.')) 1129 1130 " clean up 1131 setl nofoldenable fdm=marker foldlevel=0 1132 bw! 1133endfunc 1134 1135func Test_normal20_exmode() 1136 " Reading from redirected file doesn't work on MS-Windows 1137 CheckNotMSWindows 1138 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') 1139 call writefile(['1', '2'], 'Xfile') 1140 call system(GetVimCommand() .. ' -e -s < Xscript Xfile') 1141 let a=readfile('Xfile2') 1142 call assert_equal(['1', 'foo', 'bar', '2'], a) 1143 1144 " clean up 1145 for file in ['Xfile', 'Xfile2', 'Xscript'] 1146 call delete(file) 1147 endfor 1148 bw! 1149endfunc 1150 1151func Test_normal21_nv_hat() 1152 1153 " Edit a fresh file and wipe the buffer list so that there is no alternate 1154 " file present. Next, check for the expected command failures. 1155 edit Xfoo | %bw 1156 call assert_fails(':buffer #', 'E86') 1157 call assert_fails(':execute "normal! \<C-^>"', 'E23') 1158 1159 " Test for the expected behavior when switching between two named buffers. 1160 edit Xfoo | edit Xbar 1161 call feedkeys("\<C-^>", 'tx') 1162 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) 1163 call feedkeys("\<C-^>", 'tx') 1164 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) 1165 1166 " Test for the expected behavior when only one buffer is named. 1167 enew | let l:nr = bufnr('%') 1168 call feedkeys("\<C-^>", 'tx') 1169 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) 1170 call feedkeys("\<C-^>", 'tx') 1171 call assert_equal('', bufname('%')) 1172 call assert_equal(l:nr, bufnr('%')) 1173 1174 " Test that no action is taken by "<C-^>" when an operator is pending. 1175 edit Xfoo 1176 call feedkeys("ci\<C-^>", 'tx') 1177 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) 1178 1179 %bw! 1180endfunc 1181 1182func Test_normal22_zet() 1183 " Test for ZZ 1184 " let shell = &shell 1185 " let &shell = 'sh' 1186 call writefile(['1', '2'], 'Xfile') 1187 let args = ' -N -i NONE --noplugins -X --not-a-term' 1188 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile') 1189 let a = readfile('Xfile') 1190 call assert_equal([], a) 1191 " Test for ZQ 1192 call writefile(['1', '2'], 'Xfile') 1193 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile') 1194 let a = readfile('Xfile') 1195 call assert_equal(['1', '2'], a) 1196 1197 " Unsupported Z command 1198 call assert_beeps('normal! ZW') 1199 1200 " clean up 1201 for file in ['Xfile'] 1202 call delete(file) 1203 endfor 1204 " let &shell = shell 1205endfunc 1206 1207func Test_normal23_K() 1208 " Test for K command 1209 new 1210 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd']) 1211 let k = &keywordprg 1212 set keywordprg=:help 1213 1 1214 norm! VK 1215 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) 1216 call assert_equal('help', &ft) 1217 call assert_match('\*version8.txt\*', getline('.')) 1218 helpclose 1219 norm! 0K 1220 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) 1221 call assert_equal('help', &ft) 1222 call assert_match('\*version8\.\d\*', getline('.')) 1223 helpclose 1224 1225 set keywordprg=:new 1226 set iskeyword+=% 1227 set iskeyword+=\| 1228 2 1229 norm! K 1230 call assert_equal('man', fnamemodify(bufname('%'), ':t')) 1231 bwipe! 1232 3 1233 norm! K 1234 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t')) 1235 bwipe! 1236 if !has('win32') 1237 4 1238 norm! K 1239 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t')) 1240 bwipe! 1241 endif 1242 set iskeyword-=% 1243 set iskeyword-=\| 1244 1245 " Only expect "man" to work on Unix 1246 if !has("unix") 1247 let &keywordprg = k 1248 bw! 1249 return 1250 endif 1251 1252 let not_gnu_man = has('mac') || has('bsd') 1253 if not_gnu_man 1254 " In MacOS and BSD, the option for specifying a pager is different 1255 set keywordprg=man\ -P\ cat 1256 else 1257 set keywordprg=man\ --pager=cat 1258 endif 1259 " Test for using man 1260 2 1261 let a = execute('unsilent norm! K') 1262 if not_gnu_man 1263 call assert_match("man -P cat 'man'", a) 1264 else 1265 call assert_match("man --pager=cat 'man'", a) 1266 endif 1267 1268 " Error cases 1269 call setline(1, '#$#') 1270 call assert_fails('normal! ggK', 'E349:') 1271 call setline(1, '---') 1272 call assert_fails('normal! ggv2lK', 'E349:') 1273 call setline(1, ['abc', 'xyz']) 1274 call assert_fails("normal! gg2lv2h\<C-]>", 'E426:') 1275 call assert_beeps("normal! ggVjK") 1276 1277 " clean up 1278 let &keywordprg = k 1279 bw! 1280endfunc 1281 1282func Test_normal24_rot13() 1283 " Testing for g?? g?g? 1284 new 1285 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') 1286 1 1287 norm! g?? 1288 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.')) 1289 norm! g?g? 1290 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.')) 1291 1292 " clean up 1293 bw! 1294endfunc 1295 1296func Test_normal25_tag() 1297 CheckFeature quickfix 1298 1299 " Testing for CTRL-] g CTRL-] g] 1300 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] 1301 h 1302 " Test for CTRL-] 1303 call search('\<x\>$') 1304 exe "norm! \<c-]>" 1305 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) 1306 norm! yiW 1307 call assert_equal("*x*", @0) 1308 exe ":norm \<c-o>" 1309 1310 " Test for g_CTRL-] 1311 call search('\<v_u\>$') 1312 exe "norm! g\<c-]>" 1313 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) 1314 norm! yiW 1315 call assert_equal("*v_u*", @0) 1316 exe ":norm \<c-o>" 1317 1318 " Test for g] 1319 call search('\<i_<Esc>$') 1320 let a = execute(":norm! g]") 1321 call assert_match('i_<Esc>.*insert.txt', a) 1322 1323 if !empty(exepath('cscope')) && has('cscope') 1324 " setting cscopetag changes how g] works 1325 set cst 1326 exe "norm! g]" 1327 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1328 norm! yiW 1329 call assert_equal("*i_<Esc>*", @0) 1330 exe ":norm \<c-o>" 1331 " Test for CTRL-W g] 1332 exe "norm! \<C-W>g]" 1333 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1334 norm! yiW 1335 call assert_equal("*i_<Esc>*", @0) 1336 call assert_equal(3, winnr('$')) 1337 helpclose 1338 set nocst 1339 endif 1340 1341 " Test for CTRL-W g] 1342 let a = execute("norm! \<C-W>g]") 1343 call assert_match('i_<Esc>.*insert.txt', a) 1344 1345 " Test for CTRL-W CTRL-] 1346 exe "norm! \<C-W>\<C-]>" 1347 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1348 norm! yiW 1349 call assert_equal("*i_<Esc>*", @0) 1350 call assert_equal(3, winnr('$')) 1351 helpclose 1352 1353 " Test for CTRL-W g CTRL-] 1354 exe "norm! \<C-W>g\<C-]>" 1355 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1356 norm! yiW 1357 call assert_equal("*i_<Esc>*", @0) 1358 call assert_equal(3, winnr('$')) 1359 helpclose 1360 1361 " clean up 1362 helpclose 1363endfunc 1364 1365func Test_normal26_put() 1366 " Test for ]p ]P [p and [P 1367 new 1368 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) 1369 1 1370 /Error/y a 1371 2 1372 norm! "a]pj"a[p 1373 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5)) 1374 1 1375 /^\s\{4}/ 1376 exe "norm! \"a]P3Eldt'" 1377 exe "norm! j\"a[P2Eldt'" 1378 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10)) 1379 1380 " clean up 1381 bw! 1382endfunc 1383 1384func Test_normal27_bracket() 1385 " Test for [' [` ]' ]` 1386 call Setup_NewWindow() 1387 1,21s/.\+/ & b/ 1388 1 1389 norm! $ma 1390 5 1391 norm! $mb 1392 10 1393 norm! $mc 1394 15 1395 norm! $md 1396 20 1397 norm! $me 1398 1399 " Test for [' 1400 9 1401 norm! 2[' 1402 call assert_equal(' 1 b', getline('.')) 1403 call assert_equal(1, line('.')) 1404 call assert_equal(3, col('.')) 1405 1406 " Test for ]' 1407 norm! ]' 1408 call assert_equal(' 5 b', getline('.')) 1409 call assert_equal(5, line('.')) 1410 call assert_equal(3, col('.')) 1411 1412 " No mark after line 21, cursor moves to first non blank on current line 1413 21 1414 norm! $]' 1415 call assert_equal(' 21 b', getline('.')) 1416 call assert_equal(21, line('.')) 1417 call assert_equal(3, col('.')) 1418 1419 " Test for [` 1420 norm! 2[` 1421 call assert_equal(' 15 b', getline('.')) 1422 call assert_equal(15, line('.')) 1423 call assert_equal(8, col('.')) 1424 1425 " Test for ]` 1426 norm! ]` 1427 call assert_equal(' 20 b', getline('.')) 1428 call assert_equal(20, line('.')) 1429 call assert_equal(8, col('.')) 1430 1431 " clean up 1432 bw! 1433endfunc 1434 1435" Test for ( and ) sentence movements 1436func Test_normal28_parenthesis() 1437 new 1438 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) 1439 1440 $ 1441 norm! d( 1442 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$')) 1443 norm! 2d( 1444 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$')) 1445 1 1446 norm! 0d) 1447 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$')) 1448 1449 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. ']) 1450 $ 1451 norm! $d( 1452 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$')) 1453 1454 " It is an error if a next sentence is not found 1455 %d 1456 call setline(1, '.SH') 1457 call assert_beeps('normal )') 1458 1459 " Jumping to a fold should open the fold 1460 call setline(1, ['', '', 'one', 'two', 'three']) 1461 set foldenable 1462 2,$fold 1463 call feedkeys(')', 'xt') 1464 call assert_equal(3, line('.')) 1465 call assert_equal(1, foldlevel('.')) 1466 call assert_equal(-1, foldclosed('.')) 1467 set foldenable& 1468 1469 " clean up 1470 bw! 1471endfunc 1472 1473" Test for { and } paragraph movements 1474func Test_normal29_brace() 1475 let text =<< trim [DATA] 1476 A paragraph begins after each empty line, and also at each of a set of 1477 paragraph macros, specified by the pairs of characters in the 'paragraphs' 1478 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to 1479 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in 1480 the first column). A section boundary is also a paragraph boundary. 1481 Note that a blank line (only containing white space) is NOT a paragraph 1482 boundary. 1483 1484 1485 Also note that this does not include a '{' or '}' in the first column. When 1486 the '{' flag is in 'cpoptions' then '{' in the first column is used as a 1487 paragraph boundary |posix|. 1488 { 1489 This is no paragraph 1490 unless the '{' is set 1491 in 'cpoptions' 1492 } 1493 .IP 1494 The nroff macros IP separates a paragraph 1495 That means, it must be a '.' 1496 followed by IP 1497 .LPIt does not matter, if afterwards some 1498 more characters follow. 1499 .SHAlso section boundaries from the nroff 1500 macros terminate a paragraph. That means 1501 a character like this: 1502 .NH 1503 End of text here 1504 [DATA] 1505 1506 new 1507 call append(0, text) 1508 1 1509 norm! 0d2} 1510 1511 let expected =<< trim [DATA] 1512 .IP 1513 The nroff macros IP separates a paragraph 1514 That means, it must be a '.' 1515 followed by IP 1516 .LPIt does not matter, if afterwards some 1517 more characters follow. 1518 .SHAlso section boundaries from the nroff 1519 macros terminate a paragraph. That means 1520 a character like this: 1521 .NH 1522 End of text here 1523 1524 [DATA] 1525 call assert_equal(expected, getline(1, '$')) 1526 1527 norm! 0d} 1528 1529 let expected =<< trim [DATA] 1530 .LPIt does not matter, if afterwards some 1531 more characters follow. 1532 .SHAlso section boundaries from the nroff 1533 macros terminate a paragraph. That means 1534 a character like this: 1535 .NH 1536 End of text here 1537 1538 [DATA] 1539 call assert_equal(expected, getline(1, '$')) 1540 1541 $ 1542 norm! d{ 1543 1544 let expected =<< trim [DATA] 1545 .LPIt does not matter, if afterwards some 1546 more characters follow. 1547 .SHAlso section boundaries from the nroff 1548 macros terminate a paragraph. That means 1549 a character like this: 1550 1551 [DATA] 1552 call assert_equal(expected, getline(1, '$')) 1553 1554 norm! d{ 1555 1556 let expected =<< trim [DATA] 1557 .LPIt does not matter, if afterwards some 1558 more characters follow. 1559 1560 [DATA] 1561 call assert_equal(expected, getline(1, '$')) 1562 1563 " Test with { in cpooptions 1564 %d 1565 call append(0, text) 1566 set cpo+={ 1567 1 1568 norm! 0d2} 1569 1570 let expected =<< trim [DATA] 1571 { 1572 This is no paragraph 1573 unless the '{' is set 1574 in 'cpoptions' 1575 } 1576 .IP 1577 The nroff macros IP separates a paragraph 1578 That means, it must be a '.' 1579 followed by IP 1580 .LPIt does not matter, if afterwards some 1581 more characters follow. 1582 .SHAlso section boundaries from the nroff 1583 macros terminate a paragraph. That means 1584 a character like this: 1585 .NH 1586 End of text here 1587 1588 [DATA] 1589 call assert_equal(expected, getline(1, '$')) 1590 1591 $ 1592 norm! d} 1593 1594 let expected =<< trim [DATA] 1595 { 1596 This is no paragraph 1597 unless the '{' is set 1598 in 'cpoptions' 1599 } 1600 .IP 1601 The nroff macros IP separates a paragraph 1602 That means, it must be a '.' 1603 followed by IP 1604 .LPIt does not matter, if afterwards some 1605 more characters follow. 1606 .SHAlso section boundaries from the nroff 1607 macros terminate a paragraph. That means 1608 a character like this: 1609 .NH 1610 End of text here 1611 1612 [DATA] 1613 call assert_equal(expected, getline(1, '$')) 1614 1615 norm! gg} 1616 norm! d5} 1617 1618 let expected =<< trim [DATA] 1619 { 1620 This is no paragraph 1621 unless the '{' is set 1622 in 'cpoptions' 1623 } 1624 1625 [DATA] 1626 call assert_equal(expected, getline(1, '$')) 1627 1628 " Jumping to a fold should open the fold 1629 %d 1630 call setline(1, ['', 'one', 'two', '']) 1631 set foldenable 1632 2,$fold 1633 call feedkeys('}', 'xt') 1634 call assert_equal(4, line('.')) 1635 call assert_equal(1, foldlevel('.')) 1636 call assert_equal(-1, foldclosed('.')) 1637 set foldenable& 1638 1639 " clean up 1640 set cpo-={ 1641 bw! 1642endfunc 1643 1644" Test for ~ command 1645func Test_normal30_changecase() 1646 new 1647 call append(0, 'This is a simple test: äüöß') 1648 norm! 1ggVu 1649 call assert_equal('this is a simple test: äüöß', getline('.')) 1650 norm! VU 1651 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1652 norm! guu 1653 call assert_equal('this is a simple test: äüöss', getline('.')) 1654 norm! gUgU 1655 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1656 norm! gugu 1657 call assert_equal('this is a simple test: äüöss', getline('.')) 1658 norm! gUU 1659 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1660 norm! 010~ 1661 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.')) 1662 norm! V~ 1663 call assert_equal('THIS IS A simple test: äüöss', getline('.')) 1664 1665 " Test for changing case across lines using 'whichwrap' 1666 call setline(1, ['aaaaaa', 'aaaaaa']) 1667 normal! gg10~ 1668 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2)) 1669 set whichwrap+=~ 1670 normal! gg10~ 1671 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2)) 1672 set whichwrap& 1673 1674 " clean up 1675 bw! 1676endfunc 1677 1678" Turkish ASCII turns to multi-byte. On some systems Turkish locale 1679" is available but toupper()/tolower() don't do the right thing. 1680func Test_normal_changecase_turkish() 1681 new 1682 try 1683 lang tr_TR.UTF-8 1684 set casemap= 1685 let iupper = toupper('i') 1686 if iupper == "\u0130" 1687 call setline(1, 'iI') 1688 1normal gUU 1689 call assert_equal("\u0130I", getline(1)) 1690 call assert_equal("\u0130I", toupper("iI")) 1691 1692 call setline(1, 'iI') 1693 1normal guu 1694 call assert_equal("i\u0131", getline(1)) 1695 call assert_equal("i\u0131", tolower("iI")) 1696 elseif iupper == "I" 1697 call setline(1, 'iI') 1698 1normal gUU 1699 call assert_equal("II", getline(1)) 1700 call assert_equal("II", toupper("iI")) 1701 1702 call setline(1, 'iI') 1703 1normal guu 1704 call assert_equal("ii", getline(1)) 1705 call assert_equal("ii", tolower("iI")) 1706 else 1707 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'") 1708 endif 1709 set casemap& 1710 call setline(1, 'iI') 1711 1normal gUU 1712 call assert_equal("II", getline(1)) 1713 call assert_equal("II", toupper("iI")) 1714 1715 call setline(1, 'iI') 1716 1normal guu 1717 call assert_equal("ii", getline(1)) 1718 call assert_equal("ii", tolower("iI")) 1719 1720 lang en_US.UTF-8 1721 catch /E197:/ 1722 " can't use Turkish locale 1723 throw 'Skipped: Turkish locale not available' 1724 endtry 1725 close! 1726endfunc 1727 1728" Test for r (replace) command 1729func Test_normal31_r_cmd() 1730 new 1731 call append(0, 'This is a simple test: abcd') 1732 exe "norm! 1gg$r\<cr>" 1733 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$')) 1734 exe "norm! 1gg2wlr\<cr>" 1735 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$')) 1736 exe "norm! 2gg0W5r\<cr>" 1737 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$')) 1738 set autoindent 1739 call setline(2, ['simple test: abc', '']) 1740 exe "norm! 2gg0W5r\<cr>" 1741 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$')) 1742 exe "norm! 1ggVr\<cr>" 1743 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1))) 1744 call setline(1, 'This is a') 1745 exe "norm! 1gg05rf" 1746 call assert_equal('fffffis a', getline(1)) 1747 1748 " When replacing characters, copy characters from above and below lines 1749 " using CTRL-Y and CTRL-E. 1750 " Different code paths are used for utf-8 and latin1 encodings 1751 set showmatch 1752 for enc in ['latin1', 'utf-8'] 1753 enew! 1754 let &encoding = enc 1755 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]']) 1756 exe "norm! 2gg5r\<C-Y>l5r\<C-E>" 1757 call assert_equal(' {a}x [b]x', getline(2)) 1758 endfor 1759 set showmatch& 1760 1761 " r command should fail in operator pending mode 1762 call assert_beeps('normal! cr') 1763 1764 " replace a tab character in visual mode 1765 %d 1766 call setline(1, ["a\tb", "c\td", "e\tf"]) 1767 normal gglvjjrx 1768 call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$')) 1769 1770 " clean up 1771 set noautoindent 1772 bw! 1773endfunc 1774 1775" Test for g*, g# 1776func Test_normal32_g_cmd1() 1777 new 1778 call append(0, ['abc.x_foo', 'x_foobar.abc']) 1779 1 1780 norm! $g* 1781 call assert_equal('x_foo', @/) 1782 call assert_equal('x_foobar.abc', getline('.')) 1783 norm! $g# 1784 call assert_equal('abc', @/) 1785 call assert_equal('abc.x_foo', getline('.')) 1786 1787 " clean up 1788 bw! 1789endfunc 1790 1791" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G, 1792" gi and gI commands 1793func Test_normal33_g_cmd2() 1794 CheckFeature jumplist 1795 call Setup_NewWindow() 1796 " Test for g` 1797 clearjumps 1798 norm! ma10j 1799 let a=execute(':jumps') 1800 " empty jumplist 1801 call assert_equal('>', a[-1:]) 1802 norm! g`a 1803 call assert_equal('>', a[-1:]) 1804 call assert_equal(1, line('.')) 1805 call assert_equal('1', getline('.')) 1806 call cursor(10, 1) 1807 norm! g'a 1808 call assert_equal('>', a[-1:]) 1809 call assert_equal(1, line('.')) 1810 1811 " Test for g; and g, 1812 norm! g; 1813 " there is only one change in the changelist 1814 " currently, when we setup the window 1815 call assert_equal(2, line('.')) 1816 call assert_fails(':norm! g;', 'E662') 1817 call assert_fails(':norm! g,', 'E663') 1818 let &ul=&ul 1819 call append('$', ['a', 'b', 'c', 'd']) 1820 let &ul=&ul 1821 call append('$', ['Z', 'Y', 'X', 'W']) 1822 let a = execute(':changes') 1823 call assert_match('2\s\+0\s\+2', a) 1824 call assert_match('101\s\+0\s\+a', a) 1825 call assert_match('105\s\+0\s\+Z', a) 1826 norm! 3g; 1827 call assert_equal(2, line('.')) 1828 norm! 2g, 1829 call assert_equal(105, line('.')) 1830 1831 " Test for g& - global substitute 1832 %d 1833 call setline(1, range(1,10)) 1834 call append('$', ['a', 'b', 'c', 'd']) 1835 $s/\w/&&/g 1836 exe "norm! /[1-8]\<cr>" 1837 norm! g& 1838 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$')) 1839 1840 " Jumping to a fold using gg should open the fold 1841 set foldenable 1842 set foldopen+=jump 1843 5,8fold 1844 call feedkeys('6gg', 'xt') 1845 call assert_equal(1, foldlevel('.')) 1846 call assert_equal(-1, foldclosed('.')) 1847 set foldopen-=jump 1848 set foldenable& 1849 1850 " Test for gv 1851 %d 1852 call append('$', repeat(['abcdefgh'], 8)) 1853 exe "norm! 2gg02l\<c-v>2j2ly" 1854 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1)) 1855 " in visual mode, gv swaps current and last selected region 1856 exe "norm! G0\<c-v>4k4lgvd" 1857 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$')) 1858 exe "norm! G0\<c-v>4k4ly" 1859 exe "norm! gvood" 1860 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) 1861 " gv cannot be used in operator pending mode 1862 call assert_beeps('normal! cgv') 1863 " gv should beep without a previously selected visual area 1864 new 1865 call assert_beeps('normal! gv') 1866 close 1867 1868 " Test for gk/gj 1869 %d 1870 15vsp 1871 set wrap listchars= sbr= 1872 let lineA='abcdefghijklmnopqrstuvwxyz' 1873 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 1874 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' 1875 $put =lineA 1876 $put =lineB 1877 1878 norm! 3gg0dgk 1879 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$')) 1880 set nu 1881 norm! 3gg0gjdgj 1882 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1883 1884 " Test for gJ 1885 norm! 2gggJ 1886 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1887 call assert_equal(16, col('.')) 1888 " shouldn't do anything 1889 norm! 10gJ 1890 call assert_equal(1, col('.')) 1891 1892 " Test for g0 g^ gm g$ 1893 exe "norm! 2gg0gji " 1894 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1895 norm! g0yl 1896 call assert_equal(12, col('.')) 1897 call assert_equal(' ', getreg(0)) 1898 norm! g$yl 1899 call assert_equal(22, col('.')) 1900 call assert_equal('3', getreg(0)) 1901 norm! gmyl 1902 call assert_equal(17, col('.')) 1903 call assert_equal('n', getreg(0)) 1904 norm! g^yl 1905 call assert_equal(15, col('.')) 1906 call assert_equal('l', getreg(0)) 1907 call assert_beeps('normal 5g$') 1908 1909 " Test for g_ 1910 call assert_beeps('normal! 100g_') 1911 call setline(2, [' foo ', ' foobar ']) 1912 normal! 2ggg_ 1913 call assert_equal(5, col('.')) 1914 normal! 2g_ 1915 call assert_equal(8, col('.')) 1916 1917 norm! 2ggdG 1918 $put =lineC 1919 1920 " Test for gM 1921 norm! gMyl 1922 call assert_equal(73, col('.')) 1923 call assert_equal('0', getreg(0)) 1924 " Test for 20gM 1925 norm! 20gMyl 1926 call assert_equal(29, col('.')) 1927 call assert_equal('S', getreg(0)) 1928 " Test for 60gM 1929 norm! 60gMyl 1930 call assert_equal(87, col('.')) 1931 call assert_equal('E', getreg(0)) 1932 1933 " Test for g Ctrl-G 1934 set ff=unix 1935 let a=execute(":norm! g\<c-g>") 1936 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a) 1937 1938 " Test for gI 1939 norm! gIfoo 1940 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$')) 1941 1942 " Test for gi 1943 wincmd c 1944 %d 1945 set tw=0 1946 call setline(1, ['foobar', 'new line']) 1947 norm! A next word 1948 $put ='third line' 1949 norm! gi another word 1950 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) 1951 call setline(1, 'foobar') 1952 normal! Ggifirst line 1953 call assert_equal('foobarfirst line', getline(1)) 1954 " Test gi in 'virtualedit' mode with cursor after the end of the line 1955 set virtualedit=all 1956 call setline(1, 'foo') 1957 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>" 1958 call setline(1, 'foo') 1959 normal! Ggifirst line 1960 call assert_equal('foo first line', getline(1)) 1961 set virtualedit& 1962 1963 " Test for aboring a g command using CTRL-\ CTRL-G 1964 exe "normal! g\<C-\>\<C-G>" 1965 call assert_equal('foo first line', getline('.')) 1966 1967 " clean up 1968 bw! 1969endfunc 1970 1971" Test for g CTRL-G 1972func Test_g_ctrl_g() 1973 new 1974 1975 let a = execute(":norm! g\<c-g>") 1976 call assert_equal("\n--No lines in buffer--", a) 1977 1978 " Test for CTRL-G (same as :file) 1979 let a = execute(":norm! \<c-g>") 1980 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a) 1981 1982 call setline(1, ['first line', 'second line']) 1983 1984 " Test g CTRL-g with dos, mac and unix file type. 1985 norm! gojll 1986 set ff=dos 1987 let a = execute(":norm! g\<c-g>") 1988 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a) 1989 1990 set ff=mac 1991 let a = execute(":norm! g\<c-g>") 1992 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) 1993 1994 set ff=unix 1995 let a = execute(":norm! g\<c-g>") 1996 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) 1997 1998 " Test g CTRL-g in visual mode (v) 1999 let a = execute(":norm! gojllvlg\<c-g>") 2000 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a) 2001 2002 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col 2003 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>") 2004 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) 2005 2006 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col 2007 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>") 2008 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) 2009 2010 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL 2011 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>") 2012 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a) 2013 2014 " There should be one byte less with noeol 2015 set bin noeol 2016 let a = execute(":norm! \<Esc>gog\<c-g>") 2017 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a) 2018 set bin & eol& 2019 2020 call setline(1, ['Français', '日本語']) 2021 2022 let a = execute(":norm! \<Esc>gojlg\<c-g>") 2023 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a) 2024 2025 let a = execute(":norm! \<Esc>gojvlg\<c-g>") 2026 call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a) 2027 2028 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>") 2029 call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a) 2030 2031 set fenc=utf8 bomb 2032 let a = execute(":norm! \<Esc>gojlg\<c-g>") 2033 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a) 2034 2035 set fenc=utf16 bomb 2036 let a = execute(":norm! g\<c-g>") 2037 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a) 2038 2039 set fenc=utf32 bomb 2040 let a = execute(":norm! g\<c-g>") 2041 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a) 2042 2043 set fenc& bomb& 2044 2045 set ff& 2046 bwipe! 2047endfunc 2048 2049" Test for g8 2050func Test_normal34_g_cmd3() 2051 new 2052 let a=execute(':norm! 1G0g8') 2053 call assert_equal("\nNUL", a) 2054 2055 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö') 2056 let a=execute(':norm! 1G$g8') 2057 call assert_equal("\nc3 b6 ", a) 2058 2059 call setline(1, "a\u0302") 2060 let a=execute(':norm! 1G0g8') 2061 call assert_equal("\n61 + cc 82 ", a) 2062 2063 " clean up 2064 bw! 2065endfunc 2066 2067" Test 8g8 which finds invalid utf8 at or after the cursor. 2068func Test_normal_8g8() 2069 new 2070 2071 " With invalid byte. 2072 call setline(1, "___\xff___") 2073 norm! 1G08g8g 2074 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2075 2076 " With invalid byte before the cursor. 2077 call setline(1, "___\xff___") 2078 norm! 1G$h8g8g 2079 call assert_equal([0, 1, 6, 0, 9], getcurpos()) 2080 2081 " With truncated sequence. 2082 call setline(1, "___\xE2\x82___") 2083 norm! 1G08g8g 2084 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2085 2086 " With overlong sequence. 2087 call setline(1, "___\xF0\x82\x82\xAC___") 2088 norm! 1G08g8g 2089 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2090 2091 " With valid utf8. 2092 call setline(1, "café") 2093 norm! 1G08g8 2094 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2095 2096 bw! 2097endfunc 2098 2099" Test for g< 2100func Test_normal35_g_cmd4() 2101 " Cannot capture its output, 2102 " probably a bug, therefore, test disabled: 2103 throw "Skipped: output of g< can't be tested currently" 2104 echo "a\nb\nc\nd" 2105 let b=execute(':norm! g<') 2106 call assert_true(!empty(b), 'failed `execute(g<)`') 2107endfunc 2108 2109" Test for gp gP go 2110func Test_normal36_g_cmd5() 2111 new 2112 call append(0, 'abcdefghijklmnopqrstuvwxyz') 2113 set ff=unix 2114 " Test for gp gP 2115 call append(1, range(1,10)) 2116 1 2117 norm! 1yy 2118 3 2119 norm! gp 2120 call assert_equal([0, 5, 1, 0, 1], getcurpos()) 2121 $ 2122 norm! gP 2123 call assert_equal([0, 14, 1, 0, 1], getcurpos()) 2124 2125 " Test for go 2126 norm! 26go 2127 call assert_equal([0, 1, 26, 0, 26], getcurpos()) 2128 norm! 27go 2129 call assert_equal([0, 1, 26, 0, 26], getcurpos()) 2130 norm! 28go 2131 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 2132 set ff=dos 2133 norm! 29go 2134 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 2135 set ff=unix 2136 norm! gg0 2137 norm! 101go 2138 call assert_equal([0, 13, 26, 0, 26], getcurpos()) 2139 norm! 103go 2140 call assert_equal([0, 14, 1, 0, 1], getcurpos()) 2141 " count > buffer content 2142 norm! 120go 2143 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) 2144 " clean up 2145 bw! 2146endfunc 2147 2148" Test for gt and gT 2149func Test_normal37_g_cmd6() 2150 tabnew 1.txt 2151 tabnew 2.txt 2152 tabnew 3.txt 2153 norm! 1gt 2154 call assert_equal(1, tabpagenr()) 2155 norm! 3gt 2156 call assert_equal(3, tabpagenr()) 2157 norm! 1gT 2158 " count gT goes not to the absolute tabpagenumber 2159 " but, but goes to the count previous tabpagenumber 2160 call assert_equal(2, tabpagenr()) 2161 " wrap around 2162 norm! 3gT 2163 call assert_equal(3, tabpagenr()) 2164 " gt does not wrap around 2165 norm! 5gt 2166 call assert_equal(3, tabpagenr()) 2167 2168 for i in range(3) 2169 tabclose 2170 endfor 2171 " clean up 2172 call assert_fails(':tabclose', 'E784:') 2173endfunc 2174 2175" Test for <Home> and <C-Home> key 2176func Test_normal38_nvhome() 2177 new 2178 call setline(1, range(10)) 2179 $ 2180 setl et sw=2 2181 norm! V10>$ 2182 " count is ignored 2183 exe "norm! 10\<home>" 2184 call assert_equal(1, col('.')) 2185 exe "norm! \<home>" 2186 call assert_equal([0, 10, 1, 0, 1], getcurpos()) 2187 exe "norm! 5\<c-home>" 2188 call assert_equal([0, 5, 1, 0, 1], getcurpos()) 2189 exe "norm! \<c-home>" 2190 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2191 exe "norm! G\<c-kHome>" 2192 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2193 2194 " clean up 2195 bw! 2196endfunc 2197 2198" Test for <End> and <C-End> keys 2199func Test_normal_nvend() 2200 new 2201 call setline(1, map(range(1, 10), '"line" .. v:val')) 2202 exe "normal! \<End>" 2203 call assert_equal(5, col('.')) 2204 exe "normal! 4\<End>" 2205 call assert_equal([4, 5], [line('.'), col('.')]) 2206 exe "normal! \<C-End>" 2207 call assert_equal([10, 6], [line('.'), col('.')]) 2208 close! 2209endfunc 2210 2211" Test for cw cW ce 2212func Test_normal39_cw() 2213 " Test for cw and cW on whitespace 2214 " and cpo+=w setting 2215 new 2216 set tw=0 2217 call append(0, 'here are some words') 2218 norm! 1gg0elcwZZZ 2219 call assert_equal('hereZZZare some words', getline('.')) 2220 norm! 1gg0elcWYYY 2221 call assert_equal('hereZZZareYYYsome words', getline('.')) 2222 set cpo+=w 2223 call setline(1, 'here are some words') 2224 norm! 1gg0elcwZZZ 2225 call assert_equal('hereZZZ are some words', getline('.')) 2226 norm! 1gg2elcWYYY 2227 call assert_equal('hereZZZ areYYY some words', getline('.')) 2228 set cpo-=w 2229 norm! 2gg0cwfoo 2230 call assert_equal('foo', getline('.')) 2231 2232 call setline(1, 'one; two') 2233 call cursor(1, 1) 2234 call feedkeys('cwvim', 'xt') 2235 call assert_equal('vim; two', getline(1)) 2236 call feedkeys('0cWone', 'xt') 2237 call assert_equal('one two', getline(1)) 2238 "When cursor is at the end of a word 'ce' will change until the end of the 2239 "next word, but 'cw' will change only one character 2240 call setline(1, 'one two') 2241 call feedkeys('0ecwce', 'xt') 2242 call assert_equal('once two', getline(1)) 2243 call setline(1, 'one two') 2244 call feedkeys('0ecely', 'xt') 2245 call assert_equal('only', getline(1)) 2246 2247 " clean up 2248 bw! 2249endfunc 2250 2251" Test for CTRL-\ commands 2252func Test_normal40_ctrl_bsl() 2253 new 2254 call append(0, 'here are some words') 2255 exe "norm! 1gg0a\<C-\>\<C-N>" 2256 call assert_equal('n', mode()) 2257 call assert_equal(1, col('.')) 2258 call assert_equal('', visualmode()) 2259 exe "norm! 1gg0viw\<C-\>\<C-N>" 2260 call assert_equal('n', mode()) 2261 call assert_equal(4, col('.')) 2262 exe "norm! 1gg0a\<C-\>\<C-G>" 2263 call assert_equal('n', mode()) 2264 call assert_equal(1, col('.')) 2265 "imap <buffer> , <c-\><c-n> 2266 set im 2267 exe ":norm! \<c-\>\<c-n>dw" 2268 set noim 2269 call assert_equal('are some words', getline(1)) 2270 call assert_false(&insertmode) 2271 call assert_beeps("normal! \<C-\>\<C-A>", 'xt') 2272 2273 " Using CTRL-\ CTRL-N in cmd window should close the window 2274 call feedkeys("q:\<C-\>\<C-N>", 'xt') 2275 call assert_equal('', getcmdwintype()) 2276 2277 " clean up 2278 bw! 2279endfunc 2280 2281" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode 2282func Test_normal41_insert_reg() 2283 new 2284 set sts=2 sw=2 ts=8 tw=0 2285 call append(0, ["aaa\tbbb\tccc", '', '', '']) 2286 let a=getline(1) 2287 norm! 2gg0 2288 exe "norm! a\<c-r>=a\<cr>" 2289 norm! 3gg0 2290 exe "norm! a\<c-r>\<c-r>=a\<cr>" 2291 norm! 4gg0 2292 exe "norm! a\<c-r>\<c-o>=a\<cr>" 2293 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) 2294 2295 " clean up 2296 set sts=0 sw=8 ts=8 2297 bw! 2298endfunc 2299 2300" Test for Ctrl-D and Ctrl-U 2301func Test_normal42_halfpage() 2302 call Setup_NewWindow() 2303 call assert_equal(5, &scroll) 2304 exe "norm! \<c-d>" 2305 call assert_equal('6', getline('.')) 2306 exe "norm! 2\<c-d>" 2307 call assert_equal('8', getline('.')) 2308 call assert_equal(2, &scroll) 2309 set scroll=5 2310 exe "norm! \<c-u>" 2311 call assert_equal('3', getline('.')) 2312 1 2313 set scrolloff=5 2314 exe "norm! \<c-d>" 2315 call assert_equal('10', getline('.')) 2316 exe "norm! \<c-u>" 2317 call assert_equal('5', getline('.')) 2318 1 2319 set scrolloff=99 2320 exe "norm! \<c-d>" 2321 call assert_equal('10', getline('.')) 2322 set scrolloff=0 2323 100 2324 exe "norm! $\<c-u>" 2325 call assert_equal('95', getline('.')) 2326 call assert_equal([0, 95, 1, 0, 1], getcurpos()) 2327 100 2328 set nostartofline 2329 exe "norm! $\<c-u>" 2330 call assert_equal('95', getline('.')) 2331 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) 2332 " cleanup 2333 set startofline 2334 bw! 2335endfunc 2336 2337" Tests for text object aw 2338func Test_normal43_textobject1() 2339 new 2340 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) 2341 " diw 2342 norm! 1gg0diw 2343 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$')) 2344 " daw 2345 norm! 2ggEdaw 2346 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$')) 2347 %d 2348 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) 2349 " diW 2350 norm! 2ggwd2iW 2351 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$')) 2352 " daW 2353 norm! 1ggd2aW 2354 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$')) 2355 2356 %d 2357 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) 2358 " aw in visual line mode switches to characterwise mode 2359 norm! 2gg$Vawd 2360 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$')) 2361 norm! 1gg$Viwd 2362 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$')) 2363 2364 " clean up 2365 bw! 2366endfunc 2367 2368" Test for is and as text objects 2369func Test_normal44_textobjects2() 2370 new 2371 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) 2372 " Test for dis - does not remove trailing whitespace 2373 norm! 1gg0dis 2374 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$')) 2375 " Test for das - removes leading whitespace 2376 norm! 3ggf?ldas 2377 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$')) 2378 " when used in visual mode, is made characterwise 2379 norm! 3gg$Visy 2380 call assert_equal('v', visualmode()) 2381 " reset visualmode() 2382 norm! 3ggVy 2383 norm! 3gg$Vasy 2384 call assert_equal('v', visualmode()) 2385 " basic testing for textobjects a< and at 2386 %d 2387 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) 2388 " a< 2389 norm! 1gg0da< 2390 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) 2391 norm! 1pj 2392 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) 2393 " at 2394 norm! d2at 2395 call assert_equal([' '], getline(1,'$')) 2396 %d 2397 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) 2398 " i< 2399 norm! 1gg0di< 2400 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) 2401 norm! 1Pj 2402 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) 2403 norm! d2it 2404 call assert_equal(['<div></div>',' '], getline(1,'$')) 2405 " basic testing for a[ and i[ text object 2406 %d 2407 call setline(1, [' ', '[', 'one [two]', 'thre', ']']) 2408 norm! 3gg0di[ 2409 call assert_equal([' ', '[', ']'], getline(1,'$')) 2410 call setline(1, [' ', '[', 'one [two]', 'thre', ']']) 2411 norm! 3gg0ftd2a[ 2412 call assert_equal([' '], getline(1,'$')) 2413 %d 2414 " Test for i" when cursor is in front of a quoted object 2415 call append(0, 'foo "bar"') 2416 norm! 1gg0di" 2417 call assert_equal(['foo ""', ''], getline(1,'$')) 2418 2419 " clean up 2420 bw! 2421endfunc 2422 2423func Test_normal45_drop() 2424 if !has('dnd') 2425 " The ~ register does not exist 2426 call assert_beeps('norm! "~') 2427 return 2428 endif 2429 2430 " basic test for drag-n-drop 2431 " unfortunately, without a gui, we can't really test much here, 2432 " so simply test that ~p fails (which uses the drop register) 2433 new 2434 call assert_fails(':norm! "~p', 'E353') 2435 call assert_equal([], getreg('~', 1, 1)) 2436 " the ~ register is read only 2437 call assert_fails(':let @~="1"', 'E354') 2438 bw! 2439endfunc 2440 2441func Test_normal46_ignore() 2442 new 2443 " How to test this? 2444 " let's just for now test, that the buffer 2445 " does not change 2446 call feedkeys("\<c-s>", 't') 2447 call assert_equal([''], getline(1,'$')) 2448 2449 " no valid commands 2450 exe "norm! \<char-0x100>" 2451 call assert_equal([''], getline(1,'$')) 2452 2453 exe "norm! ä" 2454 call assert_equal([''], getline(1,'$')) 2455 2456 " clean up 2457 bw! 2458endfunc 2459 2460func Test_normal47_visual_buf_wipe() 2461 " This was causing a crash or ml_get error. 2462 enew! 2463 call setline(1,'xxx') 2464 normal $ 2465 new 2466 call setline(1, range(1,2)) 2467 2 2468 exe "norm \<C-V>$" 2469 bw! 2470 norm yp 2471 set nomodified 2472endfunc 2473 2474func Test_normal47_autocmd() 2475 " disabled, does not seem to be possible currently 2476 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" 2477 new 2478 call append(0, repeat('-',20)) 2479 au CursorHold * call feedkeys('2l', '') 2480 1 2481 set updatetime=20 2482 " should delete 12 chars (d12l) 2483 call feedkeys('d1', '!') 2484 call assert_equal('--------', getline(1)) 2485 2486 " clean up 2487 au! CursorHold 2488 set updatetime=4000 2489 bw! 2490endfunc 2491 2492func Test_normal48_wincmd() 2493 new 2494 exe "norm! \<c-w>c" 2495 call assert_equal(1, winnr('$')) 2496 call assert_fails(":norm! \<c-w>c", "E444") 2497endfunc 2498 2499func Test_normal49_counts() 2500 new 2501 call setline(1, 'one two three four five six seven eight nine ten') 2502 1 2503 norm! 3d2w 2504 call assert_equal('seven eight nine ten', getline(1)) 2505 bw! 2506endfunc 2507 2508func Test_normal50_commandline() 2509 CheckFeature timers 2510 CheckFeature cmdline_hist 2511 func! DoTimerWork(id) 2512 call assert_equal('[Command Line]', bufname('')) 2513 " should fail, with E11, but does fail with E23? 2514 "call feedkeys("\<c-^>", 'tm') 2515 2516 " should also fail with E11 2517 call assert_fails(":wincmd p", 'E11') 2518 " return from commandline window 2519 call feedkeys("\<cr>") 2520 endfunc 2521 2522 let oldlang=v:lang 2523 lang C 2524 set updatetime=20 2525 call timer_start(100, 'DoTimerWork') 2526 try 2527 " throws E23, for whatever reason... 2528 call feedkeys('q:', 'x!') 2529 catch /E23/ 2530 " no-op 2531 endtry 2532 " clean up 2533 set updatetime=4000 2534 exe "lang" oldlang 2535 bw! 2536endfunc 2537 2538func Test_normal51_FileChangedRO() 2539 CheckFeature autocmd 2540 " Don't sleep after the warning message. 2541 call test_settime(1) 2542 call writefile(['foo'], 'Xreadonly.log') 2543 new Xreadonly.log 2544 setl ro 2545 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix') 2546 call assert_fails(":norm! Af", 'E788') 2547 call assert_equal(['foo'], getline(1,'$')) 2548 call assert_equal('Xreadonly.log', bufname('')) 2549 2550 " cleanup 2551 call test_settime(0) 2552 bw! 2553 call delete("Xreadonly.log") 2554endfunc 2555 2556func Test_normal52_rl() 2557 CheckFeature rightleft 2558 new 2559 call setline(1, 'abcde fghij klmnopq') 2560 norm! 1gg$ 2561 set rl 2562 call assert_equal(19, col('.')) 2563 call feedkeys('l', 'tx') 2564 call assert_equal(18, col('.')) 2565 call feedkeys('h', 'tx') 2566 call assert_equal(19, col('.')) 2567 call feedkeys("\<right>", 'tx') 2568 call assert_equal(18, col('.')) 2569 call feedkeys("\<left>", 'tx') 2570 call assert_equal(19, col('.')) 2571 call feedkeys("\<s-right>", 'tx') 2572 call assert_equal(13, col('.')) 2573 call feedkeys("\<c-right>", 'tx') 2574 call assert_equal(7, col('.')) 2575 call feedkeys("\<c-left>", 'tx') 2576 call assert_equal(13, col('.')) 2577 call feedkeys("\<s-left>", 'tx') 2578 call assert_equal(19, col('.')) 2579 call feedkeys("<<", 'tx') 2580 call assert_equal(' abcde fghij klmnopq',getline(1)) 2581 call feedkeys(">>", 'tx') 2582 call assert_equal('abcde fghij klmnopq',getline(1)) 2583 2584 " cleanup 2585 set norl 2586 bw! 2587endfunc 2588 2589func Test_normal53_digraph() 2590 CheckFeature digraphs 2591 new 2592 call setline(1, 'abcdefgh|') 2593 exe "norm! 1gg0f\<c-k>!!" 2594 call assert_equal(9, col('.')) 2595 set cpo+=D 2596 exe "norm! 1gg0f\<c-k>!!" 2597 call assert_equal(1, col('.')) 2598 2599 set cpo-=D 2600 bw! 2601endfunc 2602 2603func Test_normal54_Ctrl_bsl() 2604 new 2605 call setline(1, 'abcdefghijklmn') 2606 exe "norm! df\<c-\>\<c-n>" 2607 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2608 exe "norm! df\<c-\>\<c-g>" 2609 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2610 exe "norm! df\<c-\>m" 2611 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2612 2613 call setline(2, 'abcdefghijklmnāf') 2614 norm! 2gg0 2615 exe "norm! df\<Char-0x101>" 2616 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2617 norm! 1gg0 2618 exe "norm! df\<esc>" 2619 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2620 2621 " clean up 2622 bw! 2623endfunc 2624 2625func Test_normal_large_count() 2626 " This may fail with 32bit long, how do we detect that? 2627 new 2628 normal o 2629 normal 6666666666dL 2630 bwipe! 2631endfunc 2632 2633func Test_delete_until_paragraph() 2634 new 2635 normal grádv} 2636 call assert_equal('á', getline(1)) 2637 normal grád} 2638 call assert_equal('', getline(1)) 2639 bwipe! 2640endfunc 2641 2642" Test for the gr (virtual replace) command 2643" Test for the bug fixed by 7.4.387 2644func Test_gr_command() 2645 enew! 2646 let save_cpo = &cpo 2647 call append(0, ['First line', 'Second line', 'Third line']) 2648 exe "normal i\<C-G>u" 2649 call cursor(2, 1) 2650 set cpo-=X 2651 normal 4gro 2652 call assert_equal('oooond line', getline(2)) 2653 undo 2654 set cpo+=X 2655 normal 4gro 2656 call assert_equal('ooooecond line', getline(2)) 2657 let &cpo = save_cpo 2658 normal! ggvegrx 2659 call assert_equal('xxxxx line', getline(1)) 2660 exe "normal! gggr\<C-V>122" 2661 call assert_equal('zxxxx line', getline(1)) 2662 set virtualedit=all 2663 normal! 15|grl 2664 call assert_equal('zxxxx line l', getline(1)) 2665 set virtualedit& 2666 set nomodifiable 2667 call assert_fails('normal! grx', 'E21:') 2668 call assert_fails('normal! gRx', 'E21:') 2669 set modifiable& 2670 enew! 2671endfunc 2672 2673" When splitting a window the changelist position is wrong. 2674" Test the changelist position after splitting a window. 2675" Test for the bug fixed by 7.4.386 2676func Test_changelist() 2677 let save_ul = &ul 2678 enew! 2679 call append('$', ['1', '2']) 2680 exe "normal i\<C-G>u" 2681 exe "normal Gkylpa\<C-G>u" 2682 set ul=100 2683 exe "normal Gylpa\<C-G>u" 2684 set ul=100 2685 normal gg 2686 vsplit 2687 normal g; 2688 call assert_equal([3, 2], [line('.'), col('.')]) 2689 normal g; 2690 call assert_equal([2, 2], [line('.'), col('.')]) 2691 call assert_fails('normal g;', 'E662:') 2692 new 2693 call assert_fails('normal g;', 'E664:') 2694 %bwipe! 2695 let &ul = save_ul 2696endfunc 2697 2698func Test_nv_hat_count() 2699 %bwipeout! 2700 let l:nr = bufnr('%') + 1 2701 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92') 2702 2703 edit Xfoo 2704 let l:foo_nr = bufnr('Xfoo') 2705 2706 edit Xbar 2707 let l:bar_nr = bufnr('Xbar') 2708 2709 " Make sure we are not just using the alternate file. 2710 edit Xbaz 2711 2712 call feedkeys(l:foo_nr . "\<C-^>", 'tx') 2713 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) 2714 2715 call feedkeys(l:bar_nr . "\<C-^>", 'tx') 2716 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) 2717 2718 %bwipeout! 2719endfunc 2720 2721func Test_message_when_using_ctrl_c() 2722 " Make sure no buffers are changed. 2723 %bwipe! 2724 2725 exe "normal \<C-C>" 2726 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines)) 2727 2728 new 2729 cal setline(1, 'hi!') 2730 exe "normal \<C-C>" 2731 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines)) 2732 2733 bwipe! 2734endfunc 2735 2736" Test for '[m', ']m', '[M' and ']M' 2737" Jumping to beginning and end of methods in Java-like languages 2738func Test_java_motion() 2739 new 2740 call assert_beeps('normal! [m') 2741 call assert_beeps('normal! ]m') 2742 call assert_beeps('normal! [M') 2743 call assert_beeps('normal! ]M') 2744 a 2745Piece of Java 2746{ 2747 tt m1 { 2748 t1; 2749 } e1 2750 2751 tt m2 { 2752 t2; 2753 } e2 2754 2755 tt m3 { 2756 if (x) 2757 { 2758 t3; 2759 } 2760 } e3 2761} 2762. 2763 2764 normal gg 2765 2766 normal 2]maA 2767 call assert_equal("\ttt m1 {A", getline('.')) 2768 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) 2769 2770 normal j]maB 2771 call assert_equal("\ttt m2 {B", getline('.')) 2772 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')]) 2773 2774 normal ]maC 2775 call assert_equal("\ttt m3 {C", getline('.')) 2776 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) 2777 2778 normal [maD 2779 call assert_equal("\ttt m3 {DC", getline('.')) 2780 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) 2781 2782 normal k2[maE 2783 call assert_equal("\ttt m1 {EA", getline('.')) 2784 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) 2785 2786 normal 3[maF 2787 call assert_equal("{F", getline('.')) 2788 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) 2789 2790 normal ]MaG 2791 call assert_equal("\t}G e1", getline('.')) 2792 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')]) 2793 2794 normal j2]MaH 2795 call assert_equal("\t}H e3", getline('.')) 2796 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) 2797 2798 normal ]M]M 2799 normal aI 2800 call assert_equal("}I", getline('.')) 2801 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')]) 2802 2803 normal 2[MaJ 2804 call assert_equal("\t}JH e3", getline('.')) 2805 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) 2806 2807 normal k[MaK 2808 call assert_equal("\t}K e2", getline('.')) 2809 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')]) 2810 2811 normal 3[MaL 2812 call assert_equal("{LF", getline('.')) 2813 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) 2814 2815 close! 2816endfunc 2817 2818" Tests for g cmds 2819func Test_normal_gdollar_cmd() 2820 CheckFeature jumplist 2821 call Setup_NewWindow() 2822 " Make long lines that will wrap 2823 %s/$/\=repeat(' foobar', 10)/ 2824 20vsp 2825 set wrap 2826 " Test for g$ with count 2827 norm! gg 2828 norm! 0vg$y 2829 call assert_equal(20, col("'>")) 2830 call assert_equal('1 foobar foobar foob', getreg(0)) 2831 norm! gg 2832 norm! 0v4g$y 2833 call assert_equal(72, col("'>")) 2834 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0)) 2835 norm! gg 2836 norm! 0v6g$y 2837 call assert_equal(40, col("'>")) 2838 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2839 \ '2 foobar foobar foobar foobar foobar foo', getreg(0)) 2840 set nowrap 2841 " clean up 2842 norm! gg 2843 norm! 0vg$y 2844 call assert_equal(20, col("'>")) 2845 call assert_equal('1 foobar foobar foob', getreg(0)) 2846 norm! gg 2847 norm! 0v4g$y 2848 call assert_equal(20, col("'>")) 2849 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2850 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2851 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2852 \ '4 foobar foobar foob', getreg(0)) 2853 norm! gg 2854 norm! 0v6g$y 2855 call assert_equal(20, col("'>")) 2856 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2857 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2858 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2859 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2860 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2861 \ '6 foobar foobar foob', getreg(0)) 2862 " Move to last line, also down movement is not possible, should still move 2863 " the cursor to the last visible char 2864 norm! G 2865 norm! 0v6g$y 2866 call assert_equal(20, col("'>")) 2867 call assert_equal('100 foobar foobar fo', getreg(0)) 2868 bw! 2869endfunc 2870 2871func Test_normal_gk_gj() 2872 " needs 80 column new window 2873 new 2874 vert 80new 2875 call assert_beeps('normal gk') 2876 put =[repeat('x',90)..' {{{1', 'x {{{1'] 2877 norm! gk 2878 " In a 80 column wide terminal the window will be only 78 char 2879 " (because Vim will leave space for the other window), 2880 " but if the terminal is larger, it will be 80 chars, so verify the 2881 " cursor column correctly. 2882 call assert_equal(winwidth(0)+1, col('.')) 2883 call assert_equal(winwidth(0)+1, virtcol('.')) 2884 norm! j 2885 call assert_equal(6, col('.')) 2886 call assert_equal(6, virtcol('.')) 2887 norm! gk 2888 call assert_equal(95, col('.')) 2889 call assert_equal(95, virtcol('.')) 2890 %bw! 2891 2892 " needs 80 column new window 2893 new 2894 vert 80new 2895 call assert_beeps('normal gj') 2896 set number 2897 set numberwidth=10 2898 set cpoptions+=n 2899 put =[repeat('0',90), repeat('1',90)] 2900 norm! 075l 2901 call assert_equal(76, col('.')) 2902 norm! gk 2903 call assert_equal(1, col('.')) 2904 norm! gk 2905 call assert_equal(76, col('.')) 2906 norm! gk 2907 call assert_equal(1, col('.')) 2908 norm! gj 2909 call assert_equal(76, col('.')) 2910 norm! gj 2911 call assert_equal(1, col('.')) 2912 norm! gj 2913 call assert_equal(76, col('.')) 2914 " When 'nowrap' is set, gk and gj behave like k and j 2915 set nowrap 2916 normal! gk 2917 call assert_equal([2, 76], [line('.'), col('.')]) 2918 normal! gj 2919 call assert_equal([3, 76], [line('.'), col('.')]) 2920 %bw! 2921 set cpoptions& number& numberwidth& wrap& 2922endfunc 2923 2924" Test for cursor movement with '-' in 'cpoptions' 2925func Test_normal_cpo_minus() 2926 new 2927 call setline(1, ['foo', 'bar', 'baz']) 2928 let save_cpo = &cpo 2929 set cpo+=- 2930 call assert_beeps('normal 10j') 2931 call assert_equal(1, line('.')) 2932 normal G 2933 call assert_beeps('normal 10k') 2934 call assert_equal(3, line('.')) 2935 call assert_fails(10, 'E16:') 2936 let &cpo = save_cpo 2937 close! 2938endfunc 2939 2940" Test for displaying dollar when changing text ('$' flag in 'cpoptions') 2941func Test_normal_cpo_dollar() 2942 new 2943 let g:Line = '' 2944 func SaveFirstLine() 2945 let g:Line = Screenline(1) 2946 return '' 2947 endfunc 2948 inoremap <expr> <buffer> <F2> SaveFirstLine() 2949 call test_override('redraw_flag', 1) 2950 set cpo+=$ 2951 call setline(1, 'one two three') 2952 redraw! 2953 exe "normal c2w\<F2>vim" 2954 call assert_equal('one tw$ three', g:Line) 2955 call assert_equal('vim three', getline(1)) 2956 set cpo-=$ 2957 call test_override('ALL', 0) 2958 delfunc SaveFirstLine 2959 %bw! 2960endfunc 2961 2962" Test for using : to run a multi-line Ex command in operator pending mode 2963func Test_normal_yank_with_excmd() 2964 new 2965 call setline(1, ['foo', 'bar', 'baz']) 2966 let @a = '' 2967 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt') 2968 call assert_equal('f', @a) 2969 close! 2970endfunc 2971 2972" Test for supplying a count to a normal-mode command across a cursorhold call 2973func Test_normal_cursorhold_with_count() 2974 func s:cHold() 2975 let g:cHold_Called += 1 2976 endfunc 2977 new 2978 augroup normalcHoldTest 2979 au! 2980 au CursorHold <buffer> call s:cHold() 2981 augroup END 2982 let g:cHold_Called = 0 2983 call feedkeys("3\<CursorHold>2ix", 'xt') 2984 call assert_equal(1, g:cHold_Called) 2985 call assert_equal(repeat('x', 32), getline(1)) 2986 augroup normalcHoldTest 2987 au! 2988 augroup END 2989 au! normalcHoldTest 2990 close! 2991 delfunc s:cHold 2992endfunc 2993 2994" Test for using a count and a command with CTRL-W 2995func Test_wincmd_with_count() 2996 call feedkeys("\<C-W>12n", 'xt') 2997 call assert_equal(12, winheight(0)) 2998endfunc 2999 3000" Test for 'b', 'B' 'ge' and 'gE' commands 3001func Test_horiz_motion() 3002 new 3003 normal! gg 3004 call assert_beeps('normal! b') 3005 call assert_beeps('normal! B') 3006 call assert_beeps('normal! gE') 3007 call assert_beeps('normal! ge') 3008 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left 3009 call setline(1, 'one ,two ,three') 3010 exe "normal! $\<S-BS>" 3011 call assert_equal(11, col('.')) 3012 exe "normal! $\<C-BS>" 3013 call assert_equal(10, col('.')) 3014 close! 3015endfunc 3016 3017" Test for using a : command in operator pending mode 3018func Test_normal_colon_op() 3019 new 3020 call setline(1, ['one', 'two']) 3021 call assert_beeps("normal! Gc:d\<CR>") 3022 close! 3023endfunc 3024 3025" Test for d and D commands 3026func Test_normal_delete_cmd() 3027 new 3028 " D in an empty line 3029 call setline(1, '') 3030 normal D 3031 call assert_equal('', getline(1)) 3032 " D in an empty line in virtualedit mode 3033 set virtualedit=all 3034 normal D 3035 call assert_equal('', getline(1)) 3036 set virtualedit& 3037 " delete to a readonly register 3038 call setline(1, ['abcd']) 3039 call assert_beeps('normal ":d2l') 3040 close! 3041endfunc 3042 3043" Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators 3044func Test_empty_region_error() 3045 new 3046 call setline(1, '') 3047 set cpo+=E 3048 " yank an empty line 3049 call assert_beeps('normal "ayl') 3050 " change an empty line 3051 call assert_beeps('normal lcTa') 3052 " delete an empty line 3053 call assert_beeps('normal D') 3054 call assert_beeps('normal dl') 3055 call assert_equal('', getline(1)) 3056 " change case of an empty line 3057 call assert_beeps('normal gul') 3058 call assert_beeps('normal gUl') 3059 " replace a character 3060 call assert_beeps('normal vrx') 3061 " increment and decrement 3062 call assert_beeps('exe "normal v\<C-A>"') 3063 call assert_beeps('exe "normal v\<C-X>"') 3064 set cpo-=E 3065 close! 3066endfunc 3067 3068" vim: shiftwidth=2 sts=2 expandtab 3069