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