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 H, M and L commands with folds 758func Test_scroll_cmds() 759 15new 760 call setline(1, range(1, 100)) 761 exe "normal! 30ggz\<CR>" 762 set foldenable 763 33,36fold 764 40,43fold 765 46,49fold 766 let h = winheight(0) 767 " Top of the screen = 30 768 " Folded lines = 9 769 " Bottom of the screen = 30 + h + 9 - 1 770 normal! 4L 771 call assert_equal(35 + h, line('.')) 772 normal! 4H 773 call assert_equal(33, line('.')) 774 set foldenable& 775 close! 776endfunc 777 778" basic tests for foldopen/folddelete 779func Test_normal18_z_fold() 780 CheckFeature folding 781 call Setup_NewWindow() 782 50 783 setl foldenable fdm=marker foldlevel=5 784 785 call assert_beeps('normal! zj') 786 call assert_beeps('normal! zk') 787 788 " Test for zF 789 " First fold 790 norm! 4zF 791 " check that folds have been created 792 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53)) 793 794 " Test for zd 795 51 796 norm! 2zF 797 call assert_equal(2, foldlevel('.')) 798 norm! kzd 799 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53)) 800 norm! j 801 call assert_equal(1, foldlevel('.')) 802 803 " Test for zD 804 " also deletes partially selected folds recursively 805 51 806 norm! zF 807 call assert_equal(2, foldlevel('.')) 808 norm! kV2jzD 809 call assert_equal(['50', '51', '52', '53'], getline(50,53)) 810 811 " Test for zE 812 85 813 norm! 4zF 814 86 815 norm! 2zF 816 90 817 norm! 4zF 818 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93)) 819 norm! zE 820 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93)) 821 822 " Test for zn 823 50 824 set foldlevel=0 825 norm! 2zF 826 norm! zn 827 norm! k 828 call assert_equal('49', getline('.')) 829 norm! j 830 call assert_equal('50/*{{{*/', getline('.')) 831 norm! j 832 call assert_equal('51/*}}}*/', getline('.')) 833 norm! j 834 call assert_equal('52', getline('.')) 835 call assert_equal(0, &foldenable) 836 837 " Test for zN 838 49 839 norm! zN 840 call assert_equal('49', getline('.')) 841 norm! j 842 call assert_equal('50/*{{{*/', getline('.')) 843 norm! j 844 call assert_equal('52', getline('.')) 845 call assert_equal(1, &foldenable) 846 847 " Test for zi 848 norm! zi 849 call assert_equal(0, &foldenable) 850 norm! zi 851 call assert_equal(1, &foldenable) 852 norm! zi 853 call assert_equal(0, &foldenable) 854 norm! zi 855 call assert_equal(1, &foldenable) 856 857 " Test for za 858 50 859 norm! za 860 norm! k 861 call assert_equal('49', getline('.')) 862 norm! j 863 call assert_equal('50/*{{{*/', getline('.')) 864 norm! j 865 call assert_equal('51/*}}}*/', getline('.')) 866 norm! j 867 call assert_equal('52', getline('.')) 868 50 869 norm! za 870 norm! k 871 call assert_equal('49', getline('.')) 872 norm! j 873 call assert_equal('50/*{{{*/', getline('.')) 874 norm! j 875 call assert_equal('52', getline('.')) 876 877 49 878 norm! 5zF 879 norm! k 880 call assert_equal('48', getline('.')) 881 norm! j 882 call assert_equal('49/*{{{*/', getline('.')) 883 norm! j 884 call assert_equal('55', getline('.')) 885 49 886 norm! za 887 call assert_equal('49/*{{{*/', getline('.')) 888 norm! j 889 call assert_equal('50/*{{{*/', getline('.')) 890 norm! j 891 call assert_equal('52', getline('.')) 892 set nofoldenable 893 " close fold and set foldenable 894 norm! za 895 call assert_equal(1, &foldenable) 896 897 50 898 " have to use {count}za to open all folds and make the cursor visible 899 norm! 2za 900 norm! 2k 901 call assert_equal('48', getline('.')) 902 norm! j 903 call assert_equal('49/*{{{*/', getline('.')) 904 norm! j 905 call assert_equal('50/*{{{*/', getline('.')) 906 norm! j 907 call assert_equal('51/*}}}*/', getline('.')) 908 norm! j 909 call assert_equal('52', getline('.')) 910 911 " Test for zA 912 49 913 set foldlevel=0 914 50 915 norm! zA 916 norm! 2k 917 call assert_equal('48', getline('.')) 918 norm! j 919 call assert_equal('49/*{{{*/', getline('.')) 920 norm! j 921 call assert_equal('50/*{{{*/', getline('.')) 922 norm! j 923 call assert_equal('51/*}}}*/', getline('.')) 924 norm! j 925 call assert_equal('52', getline('.')) 926 927 " zA on a opened fold when foldenable is not set 928 50 929 set nofoldenable 930 norm! zA 931 call assert_equal(1, &foldenable) 932 norm! k 933 call assert_equal('48', getline('.')) 934 norm! j 935 call assert_equal('49/*{{{*/', getline('.')) 936 norm! j 937 call assert_equal('55', getline('.')) 938 939 " Test for zc 940 norm! zE 941 50 942 norm! 2zF 943 49 944 norm! 5zF 945 set nofoldenable 946 50 947 " There most likely is a bug somewhere: 948 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ 949 " TODO: Should this only close the inner most fold or both folds? 950 norm! zc 951 call assert_equal(1, &foldenable) 952 norm! k 953 call assert_equal('48', getline('.')) 954 norm! j 955 call assert_equal('49/*{{{*/', getline('.')) 956 norm! j 957 call assert_equal('55', getline('.')) 958 set nofoldenable 959 50 960 norm! Vjzc 961 norm! k 962 call assert_equal('48', getline('.')) 963 norm! j 964 call assert_equal('49/*{{{*/', getline('.')) 965 norm! j 966 call assert_equal('55', getline('.')) 967 968 " Test for zC 969 set nofoldenable 970 50 971 norm! zCk 972 call assert_equal('48', getline('.')) 973 norm! j 974 call assert_equal('49/*{{{*/', getline('.')) 975 norm! j 976 call assert_equal('55', getline('.')) 977 978 " Test for zx 979 " 1) close folds at line 49-54 980 set nofoldenable 981 48 982 norm! zx 983 call assert_equal(1, &foldenable) 984 norm! j 985 call assert_equal('49/*{{{*/', getline('.')) 986 norm! j 987 call assert_equal('55', getline('.')) 988 989 " 2) do not close fold under cursor 990 51 991 set nofoldenable 992 norm! zx 993 call assert_equal(1, &foldenable) 994 norm! 3k 995 call assert_equal('48', getline('.')) 996 norm! j 997 call assert_equal('49/*{{{*/', getline('.')) 998 norm! j 999 call assert_equal('50/*{{{*/', getline('.')) 1000 norm! j 1001 call assert_equal('51/*}}}*/', getline('.')) 1002 norm! j 1003 call assert_equal('52', getline('.')) 1004 norm! j 1005 call assert_equal('53', getline('.')) 1006 norm! j 1007 call assert_equal('54/*}}}*/', getline('.')) 1008 norm! j 1009 call assert_equal('55', getline('.')) 1010 1011 " 3) close one level of folds 1012 48 1013 set nofoldenable 1014 set foldlevel=1 1015 norm! zx 1016 call assert_equal(1, &foldenable) 1017 call assert_equal('48', getline('.')) 1018 norm! j 1019 call assert_equal('49/*{{{*/', getline('.')) 1020 norm! j 1021 call assert_equal('50/*{{{*/', getline('.')) 1022 norm! j 1023 call assert_equal('52', getline('.')) 1024 norm! j 1025 call assert_equal('53', getline('.')) 1026 norm! j 1027 call assert_equal('54/*}}}*/', getline('.')) 1028 norm! j 1029 call assert_equal('55', getline('.')) 1030 1031 " Test for zX 1032 " Close all folds 1033 set foldlevel=0 nofoldenable 1034 50 1035 norm! zX 1036 call assert_equal(1, &foldenable) 1037 norm! k 1038 call assert_equal('48', getline('.')) 1039 norm! j 1040 call assert_equal('49/*{{{*/', getline('.')) 1041 norm! j 1042 call assert_equal('55', getline('.')) 1043 1044 " Test for zm 1045 50 1046 set nofoldenable foldlevel=2 1047 norm! zm 1048 call assert_equal(1, &foldenable) 1049 call assert_equal(1, &foldlevel) 1050 norm! zm 1051 call assert_equal(0, &foldlevel) 1052 norm! zm 1053 call assert_equal(0, &foldlevel) 1054 norm! k 1055 call assert_equal('48', getline('.')) 1056 norm! j 1057 call assert_equal('49/*{{{*/', getline('.')) 1058 norm! j 1059 call assert_equal('55', getline('.')) 1060 1061 " Test for zM 1062 48 1063 set nofoldenable foldlevel=99 1064 norm! zM 1065 call assert_equal(1, &foldenable) 1066 call assert_equal(0, &foldlevel) 1067 call assert_equal('48', getline('.')) 1068 norm! j 1069 call assert_equal('49/*{{{*/', getline('.')) 1070 norm! j 1071 call assert_equal('55', getline('.')) 1072 1073 " Test for zr 1074 48 1075 set nofoldenable foldlevel=0 1076 norm! zr 1077 call assert_equal(0, &foldenable) 1078 call assert_equal(1, &foldlevel) 1079 set foldlevel=0 foldenable 1080 norm! zr 1081 call assert_equal(1, &foldenable) 1082 call assert_equal(1, &foldlevel) 1083 norm! zr 1084 call assert_equal(2, &foldlevel) 1085 call assert_equal('48', getline('.')) 1086 norm! j 1087 call assert_equal('49/*{{{*/', getline('.')) 1088 norm! j 1089 call assert_equal('50/*{{{*/', getline('.')) 1090 norm! j 1091 call assert_equal('51/*}}}*/', getline('.')) 1092 norm! j 1093 call assert_equal('52', getline('.')) 1094 1095 " Test for zR 1096 48 1097 set nofoldenable foldlevel=0 1098 norm! zR 1099 call assert_equal(0, &foldenable) 1100 call assert_equal(2, &foldlevel) 1101 set foldenable foldlevel=0 1102 norm! zR 1103 call assert_equal(1, &foldenable) 1104 call assert_equal(2, &foldlevel) 1105 call assert_equal('48', getline('.')) 1106 norm! j 1107 call assert_equal('49/*{{{*/', getline('.')) 1108 norm! j 1109 call assert_equal('50/*{{{*/', getline('.')) 1110 norm! j 1111 call assert_equal('51/*}}}*/', getline('.')) 1112 norm! j 1113 call assert_equal('52', getline('.')) 1114 call append(50, ['a /*{{{*/', 'b /*}}}*/']) 1115 48 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('51/*}}}*/', getline('.')) 1125 norm! j 1126 call assert_equal('52', getline('.')) 1127 48 1128 norm! zR 1129 call assert_equal(1, &foldenable) 1130 call assert_equal(3, &foldlevel) 1131 call assert_equal('48', getline('.')) 1132 norm! j 1133 call assert_equal('49/*{{{*/', getline('.')) 1134 norm! j 1135 call assert_equal('50/*{{{*/', getline('.')) 1136 norm! j 1137 call assert_equal('a /*{{{*/', getline('.')) 1138 norm! j 1139 call assert_equal('b /*}}}*/', getline('.')) 1140 norm! j 1141 call assert_equal('51/*}}}*/', getline('.')) 1142 norm! j 1143 call assert_equal('52', getline('.')) 1144 1145 " clean up 1146 setl nofoldenable fdm=marker foldlevel=0 1147 bw! 1148endfunc 1149 1150func Test_normal20_exmode() 1151 " Reading from redirected file doesn't work on MS-Windows 1152 CheckNotMSWindows 1153 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') 1154 call writefile(['1', '2'], 'Xfile') 1155 call system(GetVimCommand() .. ' -e -s < Xscript Xfile') 1156 let a=readfile('Xfile2') 1157 call assert_equal(['1', 'foo', 'bar', '2'], a) 1158 1159 " clean up 1160 for file in ['Xfile', 'Xfile2', 'Xscript'] 1161 call delete(file) 1162 endfor 1163 bw! 1164endfunc 1165 1166func Test_normal21_nv_hat() 1167 1168 " Edit a fresh file and wipe the buffer list so that there is no alternate 1169 " file present. Next, check for the expected command failures. 1170 edit Xfoo | %bw 1171 call assert_fails(':buffer #', 'E86') 1172 call assert_fails(':execute "normal! \<C-^>"', 'E23') 1173 1174 " Test for the expected behavior when switching between two named buffers. 1175 edit Xfoo | edit Xbar 1176 call feedkeys("\<C-^>", 'tx') 1177 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) 1178 call feedkeys("\<C-^>", 'tx') 1179 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) 1180 1181 " Test for the expected behavior when only one buffer is named. 1182 enew | let l:nr = bufnr('%') 1183 call feedkeys("\<C-^>", 'tx') 1184 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) 1185 call feedkeys("\<C-^>", 'tx') 1186 call assert_equal('', bufname('%')) 1187 call assert_equal(l:nr, bufnr('%')) 1188 1189 " Test that no action is taken by "<C-^>" when an operator is pending. 1190 edit Xfoo 1191 call feedkeys("ci\<C-^>", 'tx') 1192 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) 1193 1194 %bw! 1195endfunc 1196 1197func Test_normal22_zet() 1198 " Test for ZZ 1199 " let shell = &shell 1200 " let &shell = 'sh' 1201 call writefile(['1', '2'], 'Xfile') 1202 let args = ' -N -i NONE --noplugins -X --not-a-term' 1203 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile') 1204 let a = readfile('Xfile') 1205 call assert_equal([], a) 1206 " Test for ZQ 1207 call writefile(['1', '2'], 'Xfile') 1208 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile') 1209 let a = readfile('Xfile') 1210 call assert_equal(['1', '2'], a) 1211 1212 " Unsupported Z command 1213 call assert_beeps('normal! ZW') 1214 1215 " clean up 1216 for file in ['Xfile'] 1217 call delete(file) 1218 endfor 1219 " let &shell = shell 1220endfunc 1221 1222func Test_normal23_K() 1223 " Test for K command 1224 new 1225 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd']) 1226 let k = &keywordprg 1227 set keywordprg=:help 1228 1 1229 norm! VK 1230 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) 1231 call assert_equal('help', &ft) 1232 call assert_match('\*version8.txt\*', getline('.')) 1233 helpclose 1234 norm! 0K 1235 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) 1236 call assert_equal('help', &ft) 1237 call assert_match('\*version8\.\d\*', getline('.')) 1238 helpclose 1239 1240 set keywordprg=:new 1241 set iskeyword+=% 1242 set iskeyword+=\| 1243 2 1244 norm! K 1245 call assert_equal('man', fnamemodify(bufname('%'), ':t')) 1246 bwipe! 1247 3 1248 norm! K 1249 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t')) 1250 bwipe! 1251 if !has('win32') 1252 4 1253 norm! K 1254 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t')) 1255 bwipe! 1256 endif 1257 set iskeyword-=% 1258 set iskeyword-=\| 1259 1260 " Only expect "man" to work on Unix 1261 if !has("unix") 1262 let &keywordprg = k 1263 bw! 1264 return 1265 endif 1266 1267 let not_gnu_man = has('mac') || has('bsd') 1268 if not_gnu_man 1269 " In MacOS and BSD, the option for specifying a pager is different 1270 set keywordprg=man\ -P\ cat 1271 else 1272 set keywordprg=man\ --pager=cat 1273 endif 1274 " Test for using man 1275 2 1276 let a = execute('unsilent norm! K') 1277 if not_gnu_man 1278 call assert_match("man -P cat 'man'", a) 1279 else 1280 call assert_match("man --pager=cat 'man'", a) 1281 endif 1282 1283 " Error cases 1284 call setline(1, '#$#') 1285 call assert_fails('normal! ggK', 'E349:') 1286 call setline(1, '---') 1287 call assert_fails('normal! ggv2lK', 'E349:') 1288 call setline(1, ['abc', 'xyz']) 1289 call assert_fails("normal! gg2lv2h\<C-]>", 'E426:') 1290 call assert_beeps("normal! ggVjK") 1291 1292 " clean up 1293 let &keywordprg = k 1294 bw! 1295endfunc 1296 1297func Test_normal24_rot13() 1298 " Testing for g?? g?g? 1299 new 1300 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') 1301 1 1302 norm! g?? 1303 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.')) 1304 norm! g?g? 1305 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.')) 1306 1307 " clean up 1308 bw! 1309endfunc 1310 1311func Test_normal25_tag() 1312 CheckFeature quickfix 1313 1314 " Testing for CTRL-] g CTRL-] g] 1315 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] 1316 h 1317 " Test for CTRL-] 1318 call search('\<x\>$') 1319 exe "norm! \<c-]>" 1320 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) 1321 norm! yiW 1322 call assert_equal("*x*", @0) 1323 exe ":norm \<c-o>" 1324 1325 " Test for g_CTRL-] 1326 call search('\<v_u\>$') 1327 exe "norm! g\<c-]>" 1328 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) 1329 norm! yiW 1330 call assert_equal("*v_u*", @0) 1331 exe ":norm \<c-o>" 1332 1333 " Test for g] 1334 call search('\<i_<Esc>$') 1335 let a = execute(":norm! g]") 1336 call assert_match('i_<Esc>.*insert.txt', a) 1337 1338 if !empty(exepath('cscope')) && has('cscope') 1339 " setting cscopetag changes how g] works 1340 set cst 1341 exe "norm! g]" 1342 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1343 norm! yiW 1344 call assert_equal("*i_<Esc>*", @0) 1345 exe ":norm \<c-o>" 1346 " Test for CTRL-W g] 1347 exe "norm! \<C-W>g]" 1348 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1349 norm! yiW 1350 call assert_equal("*i_<Esc>*", @0) 1351 call assert_equal(3, winnr('$')) 1352 helpclose 1353 set nocst 1354 endif 1355 1356 " Test for CTRL-W g] 1357 let a = execute("norm! \<C-W>g]") 1358 call assert_match('i_<Esc>.*insert.txt', a) 1359 1360 " Test for CTRL-W CTRL-] 1361 exe "norm! \<C-W>\<C-]>" 1362 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1363 norm! yiW 1364 call assert_equal("*i_<Esc>*", @0) 1365 call assert_equal(3, winnr('$')) 1366 helpclose 1367 1368 " Test for CTRL-W g CTRL-] 1369 exe "norm! \<C-W>g\<C-]>" 1370 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1371 norm! yiW 1372 call assert_equal("*i_<Esc>*", @0) 1373 call assert_equal(3, winnr('$')) 1374 helpclose 1375 1376 " clean up 1377 helpclose 1378endfunc 1379 1380func Test_normal26_put() 1381 " Test for ]p ]P [p and [P 1382 new 1383 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) 1384 1 1385 /Error/y a 1386 2 1387 norm! "a]pj"a[p 1388 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5)) 1389 1 1390 /^\s\{4}/ 1391 exe "norm! \"a]P3Eldt'" 1392 exe "norm! j\"a[P2Eldt'" 1393 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10)) 1394 1395 " clean up 1396 bw! 1397endfunc 1398 1399func Test_normal27_bracket() 1400 " Test for [' [` ]' ]` 1401 call Setup_NewWindow() 1402 1,21s/.\+/ & b/ 1403 1 1404 norm! $ma 1405 5 1406 norm! $mb 1407 10 1408 norm! $mc 1409 15 1410 norm! $md 1411 20 1412 norm! $me 1413 1414 " Test for [' 1415 9 1416 norm! 2[' 1417 call assert_equal(' 1 b', getline('.')) 1418 call assert_equal(1, line('.')) 1419 call assert_equal(3, col('.')) 1420 1421 " Test for ]' 1422 norm! ]' 1423 call assert_equal(' 5 b', getline('.')) 1424 call assert_equal(5, line('.')) 1425 call assert_equal(3, col('.')) 1426 1427 " No mark after line 21, cursor moves to first non blank on current line 1428 21 1429 norm! $]' 1430 call assert_equal(' 21 b', getline('.')) 1431 call assert_equal(21, line('.')) 1432 call assert_equal(3, col('.')) 1433 1434 " Test for [` 1435 norm! 2[` 1436 call assert_equal(' 15 b', getline('.')) 1437 call assert_equal(15, line('.')) 1438 call assert_equal(8, col('.')) 1439 1440 " Test for ]` 1441 norm! ]` 1442 call assert_equal(' 20 b', getline('.')) 1443 call assert_equal(20, line('.')) 1444 call assert_equal(8, col('.')) 1445 1446 " clean up 1447 bw! 1448endfunc 1449 1450" Test for ( and ) sentence movements 1451func Test_normal28_parenthesis() 1452 new 1453 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) 1454 1455 $ 1456 norm! d( 1457 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$')) 1458 norm! 2d( 1459 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$')) 1460 1 1461 norm! 0d) 1462 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$')) 1463 1464 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. ']) 1465 $ 1466 norm! $d( 1467 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$')) 1468 1469 " Move to the next sentence from a paragraph macro 1470 %d 1471 call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.']) 1472 call cursor(1, 1) 1473 normal ) 1474 call assert_equal([2, 1], [line('.'), col('.')]) 1475 normal ) 1476 call assert_equal([2, 12], [line('.'), col('.')]) 1477 normal (( 1478 call assert_equal([1, 1], [line('.'), col('.')]) 1479 1480 " It is an error if a next sentence is not found 1481 %d 1482 call setline(1, '.SH') 1483 call assert_beeps('normal )') 1484 1485 " If only dot is present, don't treat that as a sentence 1486 call setline(1, '. This is a sentence.') 1487 normal $(( 1488 call assert_equal(3, col('.')) 1489 1490 " Jumping to a fold should open the fold 1491 call setline(1, ['', '', 'one', 'two', 'three']) 1492 set foldenable 1493 2,$fold 1494 call feedkeys(')', 'xt') 1495 call assert_equal(3, line('.')) 1496 call assert_equal(1, foldlevel('.')) 1497 call assert_equal(-1, foldclosed('.')) 1498 set foldenable& 1499 1500 " clean up 1501 bw! 1502endfunc 1503 1504" Test for { and } paragraph movements 1505func Test_normal29_brace() 1506 let text =<< trim [DATA] 1507 A paragraph begins after each empty line, and also at each of a set of 1508 paragraph macros, specified by the pairs of characters in the 'paragraphs' 1509 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to 1510 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in 1511 the first column). A section boundary is also a paragraph boundary. 1512 Note that a blank line (only containing white space) is NOT a paragraph 1513 boundary. 1514 1515 1516 Also note that this does not include a '{' or '}' in the first column. When 1517 the '{' flag is in 'cpoptions' then '{' in the first column is used as a 1518 paragraph boundary |posix|. 1519 { 1520 This is no paragraph 1521 unless the '{' is set 1522 in 'cpoptions' 1523 } 1524 .IP 1525 The nroff macros IP separates a paragraph 1526 That means, it must be a '.' 1527 followed by IP 1528 .LPIt does not matter, if afterwards some 1529 more characters follow. 1530 .SHAlso section boundaries from the nroff 1531 macros terminate a paragraph. That means 1532 a character like this: 1533 .NH 1534 End of text here 1535 [DATA] 1536 1537 new 1538 call append(0, text) 1539 1 1540 norm! 0d2} 1541 1542 let expected =<< trim [DATA] 1543 .IP 1544 The nroff macros IP separates a paragraph 1545 That means, it must be a '.' 1546 followed by IP 1547 .LPIt does not matter, if afterwards some 1548 more characters follow. 1549 .SHAlso section boundaries from the nroff 1550 macros terminate a paragraph. That means 1551 a character like this: 1552 .NH 1553 End of text here 1554 1555 [DATA] 1556 call assert_equal(expected, getline(1, '$')) 1557 1558 norm! 0d} 1559 1560 let expected =<< trim [DATA] 1561 .LPIt does not matter, if afterwards some 1562 more characters follow. 1563 .SHAlso section boundaries from the nroff 1564 macros terminate a paragraph. That means 1565 a character like this: 1566 .NH 1567 End of text here 1568 1569 [DATA] 1570 call assert_equal(expected, getline(1, '$')) 1571 1572 $ 1573 norm! d{ 1574 1575 let expected =<< trim [DATA] 1576 .LPIt does not matter, if afterwards some 1577 more characters follow. 1578 .SHAlso section boundaries from the nroff 1579 macros terminate a paragraph. That means 1580 a character like this: 1581 1582 [DATA] 1583 call assert_equal(expected, getline(1, '$')) 1584 1585 norm! d{ 1586 1587 let expected =<< trim [DATA] 1588 .LPIt does not matter, if afterwards some 1589 more characters follow. 1590 1591 [DATA] 1592 call assert_equal(expected, getline(1, '$')) 1593 1594 " Test with { in cpooptions 1595 %d 1596 call append(0, text) 1597 set cpo+={ 1598 1 1599 norm! 0d2} 1600 1601 let expected =<< trim [DATA] 1602 { 1603 This is no paragraph 1604 unless the '{' is set 1605 in 'cpoptions' 1606 } 1607 .IP 1608 The nroff macros IP separates a paragraph 1609 That means, it must be a '.' 1610 followed by IP 1611 .LPIt does not matter, if afterwards some 1612 more characters follow. 1613 .SHAlso section boundaries from the nroff 1614 macros terminate a paragraph. That means 1615 a character like this: 1616 .NH 1617 End of text here 1618 1619 [DATA] 1620 call assert_equal(expected, getline(1, '$')) 1621 1622 $ 1623 norm! d} 1624 1625 let expected =<< trim [DATA] 1626 { 1627 This is no paragraph 1628 unless the '{' is set 1629 in 'cpoptions' 1630 } 1631 .IP 1632 The nroff macros IP separates a paragraph 1633 That means, it must be a '.' 1634 followed by IP 1635 .LPIt does not matter, if afterwards some 1636 more characters follow. 1637 .SHAlso section boundaries from the nroff 1638 macros terminate a paragraph. That means 1639 a character like this: 1640 .NH 1641 End of text here 1642 1643 [DATA] 1644 call assert_equal(expected, getline(1, '$')) 1645 1646 norm! gg} 1647 norm! d5} 1648 1649 let expected =<< trim [DATA] 1650 { 1651 This is no paragraph 1652 unless the '{' is set 1653 in 'cpoptions' 1654 } 1655 1656 [DATA] 1657 call assert_equal(expected, getline(1, '$')) 1658 1659 " Jumping to a fold should open the fold 1660 %d 1661 call setline(1, ['', 'one', 'two', '']) 1662 set foldenable 1663 2,$fold 1664 call feedkeys('}', 'xt') 1665 call assert_equal(4, line('.')) 1666 call assert_equal(1, foldlevel('.')) 1667 call assert_equal(-1, foldclosed('.')) 1668 set foldenable& 1669 1670 " clean up 1671 set cpo-={ 1672 bw! 1673endfunc 1674 1675" Test for ~ command 1676func Test_normal30_changecase() 1677 new 1678 call append(0, 'This is a simple test: äüöß') 1679 norm! 1ggVu 1680 call assert_equal('this is a simple test: äüöß', getline('.')) 1681 norm! VU 1682 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1683 norm! guu 1684 call assert_equal('this is a simple test: äüöss', getline('.')) 1685 norm! gUgU 1686 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1687 norm! gugu 1688 call assert_equal('this is a simple test: äüöss', getline('.')) 1689 norm! gUU 1690 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1691 norm! 010~ 1692 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.')) 1693 norm! V~ 1694 call assert_equal('THIS IS A simple test: äüöss', getline('.')) 1695 1696 " Test for changing case across lines using 'whichwrap' 1697 call setline(1, ['aaaaaa', 'aaaaaa']) 1698 normal! gg10~ 1699 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2)) 1700 set whichwrap+=~ 1701 normal! gg10~ 1702 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2)) 1703 set whichwrap& 1704 1705 " clean up 1706 bw! 1707endfunc 1708 1709" Turkish ASCII turns to multi-byte. On some systems Turkish locale 1710" is available but toupper()/tolower() don't do the right thing. 1711func Test_normal_changecase_turkish() 1712 new 1713 try 1714 lang tr_TR.UTF-8 1715 set casemap= 1716 let iupper = toupper('i') 1717 if iupper == "\u0130" 1718 call setline(1, 'iI') 1719 1normal gUU 1720 call assert_equal("\u0130I", getline(1)) 1721 call assert_equal("\u0130I", toupper("iI")) 1722 1723 call setline(1, 'iI') 1724 1normal guu 1725 call assert_equal("i\u0131", getline(1)) 1726 call assert_equal("i\u0131", tolower("iI")) 1727 elseif iupper == "I" 1728 call setline(1, 'iI') 1729 1normal gUU 1730 call assert_equal("II", getline(1)) 1731 call assert_equal("II", toupper("iI")) 1732 1733 call setline(1, 'iI') 1734 1normal guu 1735 call assert_equal("ii", getline(1)) 1736 call assert_equal("ii", tolower("iI")) 1737 else 1738 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'") 1739 endif 1740 set casemap& 1741 call setline(1, 'iI') 1742 1normal gUU 1743 call assert_equal("II", getline(1)) 1744 call assert_equal("II", toupper("iI")) 1745 1746 call setline(1, 'iI') 1747 1normal guu 1748 call assert_equal("ii", getline(1)) 1749 call assert_equal("ii", tolower("iI")) 1750 1751 lang en_US.UTF-8 1752 catch /E197:/ 1753 " can't use Turkish locale 1754 throw 'Skipped: Turkish locale not available' 1755 endtry 1756 close! 1757endfunc 1758 1759" Test for r (replace) command 1760func Test_normal31_r_cmd() 1761 new 1762 call append(0, 'This is a simple test: abcd') 1763 exe "norm! 1gg$r\<cr>" 1764 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$')) 1765 exe "norm! 1gg2wlr\<cr>" 1766 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$')) 1767 exe "norm! 2gg0W5r\<cr>" 1768 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$')) 1769 set autoindent 1770 call setline(2, ['simple test: abc', '']) 1771 exe "norm! 2gg0W5r\<cr>" 1772 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$')) 1773 exe "norm! 1ggVr\<cr>" 1774 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1))) 1775 call setline(1, 'This is a') 1776 exe "norm! 1gg05rf" 1777 call assert_equal('fffffis a', getline(1)) 1778 1779 " When replacing characters, copy characters from above and below lines 1780 " using CTRL-Y and CTRL-E. 1781 " Different code paths are used for utf-8 and latin1 encodings 1782 set showmatch 1783 for enc in ['latin1', 'utf-8'] 1784 enew! 1785 let &encoding = enc 1786 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]']) 1787 exe "norm! 2gg5r\<C-Y>l5r\<C-E>" 1788 call assert_equal(' {a}x [b]x', getline(2)) 1789 endfor 1790 set showmatch& 1791 1792 " r command should fail in operator pending mode 1793 call assert_beeps('normal! cr') 1794 1795 " replace a tab character in visual mode 1796 %d 1797 call setline(1, ["a\tb", "c\td", "e\tf"]) 1798 normal gglvjjrx 1799 call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$')) 1800 1801 " clean up 1802 set noautoindent 1803 bw! 1804endfunc 1805 1806" Test for g*, g# 1807func Test_normal32_g_cmd1() 1808 new 1809 call append(0, ['abc.x_foo', 'x_foobar.abc']) 1810 1 1811 norm! $g* 1812 call assert_equal('x_foo', @/) 1813 call assert_equal('x_foobar.abc', getline('.')) 1814 norm! $g# 1815 call assert_equal('abc', @/) 1816 call assert_equal('abc.x_foo', getline('.')) 1817 1818 " clean up 1819 bw! 1820endfunc 1821 1822" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G, 1823" gi and gI commands 1824func Test_normal33_g_cmd2() 1825 CheckFeature jumplist 1826 call Setup_NewWindow() 1827 " Test for g` 1828 clearjumps 1829 norm! ma10j 1830 let a=execute(':jumps') 1831 " empty jumplist 1832 call assert_equal('>', a[-1:]) 1833 norm! g`a 1834 call assert_equal('>', a[-1:]) 1835 call assert_equal(1, line('.')) 1836 call assert_equal('1', getline('.')) 1837 call cursor(10, 1) 1838 norm! g'a 1839 call assert_equal('>', a[-1:]) 1840 call assert_equal(1, line('.')) 1841 1842 " Test for g; and g, 1843 norm! g; 1844 " there is only one change in the changelist 1845 " currently, when we setup the window 1846 call assert_equal(2, line('.')) 1847 call assert_fails(':norm! g;', 'E662') 1848 call assert_fails(':norm! g,', 'E663') 1849 let &ul=&ul 1850 call append('$', ['a', 'b', 'c', 'd']) 1851 let &ul=&ul 1852 call append('$', ['Z', 'Y', 'X', 'W']) 1853 let a = execute(':changes') 1854 call assert_match('2\s\+0\s\+2', a) 1855 call assert_match('101\s\+0\s\+a', a) 1856 call assert_match('105\s\+0\s\+Z', a) 1857 norm! 3g; 1858 call assert_equal(2, line('.')) 1859 norm! 2g, 1860 call assert_equal(105, line('.')) 1861 1862 " Test for g& - global substitute 1863 %d 1864 call setline(1, range(1,10)) 1865 call append('$', ['a', 'b', 'c', 'd']) 1866 $s/\w/&&/g 1867 exe "norm! /[1-8]\<cr>" 1868 norm! g& 1869 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$')) 1870 1871 " Jumping to a fold using gg should open the fold 1872 set foldenable 1873 set foldopen+=jump 1874 5,8fold 1875 call feedkeys('6gg', 'xt') 1876 call assert_equal(1, foldlevel('.')) 1877 call assert_equal(-1, foldclosed('.')) 1878 set foldopen-=jump 1879 set foldenable& 1880 1881 " Test for gv 1882 %d 1883 call append('$', repeat(['abcdefgh'], 8)) 1884 exe "norm! 2gg02l\<c-v>2j2ly" 1885 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1)) 1886 " in visual mode, gv swaps current and last selected region 1887 exe "norm! G0\<c-v>4k4lgvd" 1888 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$')) 1889 exe "norm! G0\<c-v>4k4ly" 1890 exe "norm! gvood" 1891 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) 1892 " gv cannot be used in operator pending mode 1893 call assert_beeps('normal! cgv') 1894 " gv should beep without a previously selected visual area 1895 new 1896 call assert_beeps('normal! gv') 1897 close 1898 1899 " Test for gk/gj 1900 %d 1901 15vsp 1902 set wrap listchars= sbr= 1903 let lineA='abcdefghijklmnopqrstuvwxyz' 1904 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 1905 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' 1906 $put =lineA 1907 $put =lineB 1908 1909 norm! 3gg0dgk 1910 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$')) 1911 set nu 1912 norm! 3gg0gjdgj 1913 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1914 1915 " Test for gJ 1916 norm! 2gggJ 1917 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1918 call assert_equal(16, col('.')) 1919 " shouldn't do anything 1920 norm! 10gJ 1921 call assert_equal(1, col('.')) 1922 1923 " Test for g0 g^ gm g$ 1924 exe "norm! 2gg0gji " 1925 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1926 norm! g0yl 1927 call assert_equal(12, col('.')) 1928 call assert_equal(' ', getreg(0)) 1929 norm! g$yl 1930 call assert_equal(22, col('.')) 1931 call assert_equal('3', getreg(0)) 1932 norm! gmyl 1933 call assert_equal(17, col('.')) 1934 call assert_equal('n', getreg(0)) 1935 norm! g^yl 1936 call assert_equal(15, col('.')) 1937 call assert_equal('l', getreg(0)) 1938 call assert_beeps('normal 5g$') 1939 1940 " Test for g_ 1941 call assert_beeps('normal! 100g_') 1942 call setline(2, [' foo ', ' foobar ']) 1943 normal! 2ggg_ 1944 call assert_equal(5, col('.')) 1945 normal! 2g_ 1946 call assert_equal(8, col('.')) 1947 1948 norm! 2ggdG 1949 $put =lineC 1950 1951 " Test for gM 1952 norm! gMyl 1953 call assert_equal(73, col('.')) 1954 call assert_equal('0', getreg(0)) 1955 " Test for 20gM 1956 norm! 20gMyl 1957 call assert_equal(29, col('.')) 1958 call assert_equal('S', getreg(0)) 1959 " Test for 60gM 1960 norm! 60gMyl 1961 call assert_equal(87, col('.')) 1962 call assert_equal('E', getreg(0)) 1963 1964 " Test for g Ctrl-G 1965 set ff=unix 1966 let a=execute(":norm! g\<c-g>") 1967 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a) 1968 1969 " Test for gI 1970 norm! gIfoo 1971 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$')) 1972 1973 " Test for gi 1974 wincmd c 1975 %d 1976 set tw=0 1977 call setline(1, ['foobar', 'new line']) 1978 norm! A next word 1979 $put ='third line' 1980 norm! gi another word 1981 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) 1982 call setline(1, 'foobar') 1983 normal! Ggifirst line 1984 call assert_equal('foobarfirst line', getline(1)) 1985 " Test gi in 'virtualedit' mode with cursor after the end of the line 1986 set virtualedit=all 1987 call setline(1, 'foo') 1988 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>" 1989 call setline(1, 'foo') 1990 normal! Ggifirst line 1991 call assert_equal('foo first line', getline(1)) 1992 set virtualedit& 1993 1994 " Test for aboring a g command using CTRL-\ CTRL-G 1995 exe "normal! g\<C-\>\<C-G>" 1996 call assert_equal('foo first line', getline('.')) 1997 1998 " clean up 1999 bw! 2000endfunc 2001 2002" Test for g CTRL-G 2003func Test_g_ctrl_g() 2004 new 2005 2006 let a = execute(":norm! g\<c-g>") 2007 call assert_equal("\n--No lines in buffer--", a) 2008 2009 " Test for CTRL-G (same as :file) 2010 let a = execute(":norm! \<c-g>") 2011 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a) 2012 2013 call setline(1, ['first line', 'second line']) 2014 2015 " Test g CTRL-g with dos, mac and unix file type. 2016 norm! gojll 2017 set ff=dos 2018 let a = execute(":norm! g\<c-g>") 2019 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a) 2020 2021 set ff=mac 2022 let a = execute(":norm! g\<c-g>") 2023 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) 2024 2025 set ff=unix 2026 let a = execute(":norm! g\<c-g>") 2027 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) 2028 2029 " Test g CTRL-g in visual mode (v) 2030 let a = execute(":norm! gojllvlg\<c-g>") 2031 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a) 2032 2033 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col 2034 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>") 2035 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) 2036 2037 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col 2038 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>") 2039 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) 2040 2041 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL 2042 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>") 2043 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a) 2044 2045 " There should be one byte less with noeol 2046 set bin noeol 2047 let a = execute(":norm! \<Esc>gog\<c-g>") 2048 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a) 2049 set bin & eol& 2050 2051 call setline(1, ['Français', '日本語']) 2052 2053 let a = execute(":norm! \<Esc>gojlg\<c-g>") 2054 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) 2055 2056 let a = execute(":norm! \<Esc>gojvlg\<c-g>") 2057 call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a) 2058 2059 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>") 2060 call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a) 2061 2062 set fenc=utf8 bomb 2063 let a = execute(":norm! \<Esc>gojlg\<c-g>") 2064 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) 2065 2066 set fenc=utf16 bomb 2067 let a = execute(":norm! g\<c-g>") 2068 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) 2069 2070 set fenc=utf32 bomb 2071 let a = execute(":norm! g\<c-g>") 2072 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) 2073 2074 set fenc& bomb& 2075 2076 set ff& 2077 bwipe! 2078endfunc 2079 2080" Test for g8 2081func Test_normal34_g_cmd3() 2082 new 2083 let a=execute(':norm! 1G0g8') 2084 call assert_equal("\nNUL", a) 2085 2086 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö') 2087 let a=execute(':norm! 1G$g8') 2088 call assert_equal("\nc3 b6 ", a) 2089 2090 call setline(1, "a\u0302") 2091 let a=execute(':norm! 1G0g8') 2092 call assert_equal("\n61 + cc 82 ", a) 2093 2094 " clean up 2095 bw! 2096endfunc 2097 2098" Test 8g8 which finds invalid utf8 at or after the cursor. 2099func Test_normal_8g8() 2100 new 2101 2102 " With invalid byte. 2103 call setline(1, "___\xff___") 2104 norm! 1G08g8g 2105 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2106 2107 " With invalid byte before the cursor. 2108 call setline(1, "___\xff___") 2109 norm! 1G$h8g8g 2110 call assert_equal([0, 1, 6, 0, 9], getcurpos()) 2111 2112 " With truncated sequence. 2113 call setline(1, "___\xE2\x82___") 2114 norm! 1G08g8g 2115 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2116 2117 " With overlong sequence. 2118 call setline(1, "___\xF0\x82\x82\xAC___") 2119 norm! 1G08g8g 2120 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2121 2122 " With valid utf8. 2123 call setline(1, "café") 2124 norm! 1G08g8 2125 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2126 2127 bw! 2128endfunc 2129 2130" Test for g< 2131func Test_normal35_g_cmd4() 2132 " Cannot capture its output, 2133 " probably a bug, therefore, test disabled: 2134 throw "Skipped: output of g< can't be tested currently" 2135 echo "a\nb\nc\nd" 2136 let b=execute(':norm! g<') 2137 call assert_true(!empty(b), 'failed `execute(g<)`') 2138endfunc 2139 2140" Test for gp gP go 2141func Test_normal36_g_cmd5() 2142 new 2143 call append(0, 'abcdefghijklmnopqrstuvwxyz') 2144 set ff=unix 2145 " Test for gp gP 2146 call append(1, range(1,10)) 2147 1 2148 norm! 1yy 2149 3 2150 norm! gp 2151 call assert_equal([0, 5, 1, 0, 1], getcurpos()) 2152 $ 2153 norm! gP 2154 call assert_equal([0, 14, 1, 0, 1], getcurpos()) 2155 2156 " Test for go 2157 norm! 26go 2158 call assert_equal([0, 1, 26, 0, 26], getcurpos()) 2159 norm! 27go 2160 call assert_equal([0, 1, 26, 0, 26], getcurpos()) 2161 norm! 28go 2162 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 2163 set ff=dos 2164 norm! 29go 2165 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 2166 set ff=unix 2167 norm! gg0 2168 norm! 101go 2169 call assert_equal([0, 13, 26, 0, 26], getcurpos()) 2170 norm! 103go 2171 call assert_equal([0, 14, 1, 0, 1], getcurpos()) 2172 " count > buffer content 2173 norm! 120go 2174 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) 2175 " clean up 2176 bw! 2177endfunc 2178 2179" Test for gt and gT 2180func Test_normal37_g_cmd6() 2181 tabnew 1.txt 2182 tabnew 2.txt 2183 tabnew 3.txt 2184 norm! 1gt 2185 call assert_equal(1, tabpagenr()) 2186 norm! 3gt 2187 call assert_equal(3, tabpagenr()) 2188 norm! 1gT 2189 " count gT goes not to the absolute tabpagenumber 2190 " but, but goes to the count previous tabpagenumber 2191 call assert_equal(2, tabpagenr()) 2192 " wrap around 2193 norm! 3gT 2194 call assert_equal(3, tabpagenr()) 2195 " gt does not wrap around 2196 norm! 5gt 2197 call assert_equal(3, tabpagenr()) 2198 2199 for i in range(3) 2200 tabclose 2201 endfor 2202 " clean up 2203 call assert_fails(':tabclose', 'E784:') 2204endfunc 2205 2206" Test for <Home> and <C-Home> key 2207func Test_normal38_nvhome() 2208 new 2209 call setline(1, range(10)) 2210 $ 2211 setl et sw=2 2212 norm! V10>$ 2213 " count is ignored 2214 exe "norm! 10\<home>" 2215 call assert_equal(1, col('.')) 2216 exe "norm! \<home>" 2217 call assert_equal([0, 10, 1, 0, 1], getcurpos()) 2218 exe "norm! 5\<c-home>" 2219 call assert_equal([0, 5, 1, 0, 1], getcurpos()) 2220 exe "norm! \<c-home>" 2221 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2222 exe "norm! G\<c-kHome>" 2223 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2224 2225 " clean up 2226 bw! 2227endfunc 2228 2229" Test for <End> and <C-End> keys 2230func Test_normal_nvend() 2231 new 2232 call setline(1, map(range(1, 10), '"line" .. v:val')) 2233 exe "normal! \<End>" 2234 call assert_equal(5, col('.')) 2235 exe "normal! 4\<End>" 2236 call assert_equal([4, 5], [line('.'), col('.')]) 2237 exe "normal! \<C-End>" 2238 call assert_equal([10, 6], [line('.'), col('.')]) 2239 close! 2240endfunc 2241 2242" Test for cw cW ce 2243func Test_normal39_cw() 2244 " Test for cw and cW on whitespace 2245 new 2246 set tw=0 2247 call append(0, 'here are some words') 2248 norm! 1gg0elcwZZZ 2249 call assert_equal('hereZZZare some words', getline('.')) 2250 norm! 1gg0elcWYYY 2251 call assert_equal('hereZZZareYYYsome words', getline('.')) 2252 norm! 2gg0cwfoo 2253 call assert_equal('foo', getline('.')) 2254 2255 call setline(1, 'one; two') 2256 call cursor(1, 1) 2257 call feedkeys('cwvim', 'xt') 2258 call assert_equal('vim; two', getline(1)) 2259 call feedkeys('0cWone', 'xt') 2260 call assert_equal('one two', getline(1)) 2261 "When cursor is at the end of a word 'ce' will change until the end of the 2262 "next word, but 'cw' will change only one character 2263 call setline(1, 'one two') 2264 call feedkeys('0ecwce', 'xt') 2265 call assert_equal('once two', getline(1)) 2266 call setline(1, 'one two') 2267 call feedkeys('0ecely', 'xt') 2268 call assert_equal('only', getline(1)) 2269 2270 " clean up 2271 bw! 2272endfunc 2273 2274" Test for CTRL-\ commands 2275func Test_normal40_ctrl_bsl() 2276 new 2277 call append(0, 'here are some words') 2278 exe "norm! 1gg0a\<C-\>\<C-N>" 2279 call assert_equal('n', mode()) 2280 call assert_equal(1, col('.')) 2281 call assert_equal('', visualmode()) 2282 exe "norm! 1gg0viw\<C-\>\<C-N>" 2283 call assert_equal('n', mode()) 2284 call assert_equal(4, col('.')) 2285 exe "norm! 1gg0a\<C-\>\<C-G>" 2286 call assert_equal('n', mode()) 2287 call assert_equal(1, col('.')) 2288 "imap <buffer> , <c-\><c-n> 2289 set im 2290 exe ":norm! \<c-\>\<c-n>dw" 2291 set noim 2292 call assert_equal('are some words', getline(1)) 2293 call assert_false(&insertmode) 2294 call assert_beeps("normal! \<C-\>\<C-A>", 'xt') 2295 2296 " Using CTRL-\ CTRL-N in cmd window should close the window 2297 call feedkeys("q:\<C-\>\<C-N>", 'xt') 2298 call assert_equal('', getcmdwintype()) 2299 2300 " clean up 2301 bw! 2302endfunc 2303 2304" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode 2305func Test_normal41_insert_reg() 2306 new 2307 set sts=2 sw=2 ts=8 tw=0 2308 call append(0, ["aaa\tbbb\tccc", '', '', '']) 2309 let a=getline(1) 2310 norm! 2gg0 2311 exe "norm! a\<c-r>=a\<cr>" 2312 norm! 3gg0 2313 exe "norm! a\<c-r>\<c-r>=a\<cr>" 2314 norm! 4gg0 2315 exe "norm! a\<c-r>\<c-o>=a\<cr>" 2316 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) 2317 2318 " clean up 2319 set sts=0 sw=8 ts=8 2320 bw! 2321endfunc 2322 2323" Test for Ctrl-D and Ctrl-U 2324func Test_normal42_halfpage() 2325 call Setup_NewWindow() 2326 call assert_equal(5, &scroll) 2327 exe "norm! \<c-d>" 2328 call assert_equal('6', getline('.')) 2329 exe "norm! 2\<c-d>" 2330 call assert_equal('8', getline('.')) 2331 call assert_equal(2, &scroll) 2332 set scroll=5 2333 exe "norm! \<c-u>" 2334 call assert_equal('3', getline('.')) 2335 1 2336 set scrolloff=5 2337 exe "norm! \<c-d>" 2338 call assert_equal('10', getline('.')) 2339 exe "norm! \<c-u>" 2340 call assert_equal('5', getline('.')) 2341 1 2342 set scrolloff=99 2343 exe "norm! \<c-d>" 2344 call assert_equal('10', getline('.')) 2345 set scrolloff=0 2346 100 2347 exe "norm! $\<c-u>" 2348 call assert_equal('95', getline('.')) 2349 call assert_equal([0, 95, 1, 0, 1], getcurpos()) 2350 100 2351 set nostartofline 2352 exe "norm! $\<c-u>" 2353 call assert_equal('95', getline('.')) 2354 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) 2355 " cleanup 2356 set startofline 2357 bw! 2358endfunc 2359 2360func Test_normal45_drop() 2361 if !has('dnd') 2362 " The ~ register does not exist 2363 call assert_beeps('norm! "~') 2364 return 2365 endif 2366 2367 " basic test for drag-n-drop 2368 " unfortunately, without a gui, we can't really test much here, 2369 " so simply test that ~p fails (which uses the drop register) 2370 new 2371 call assert_fails(':norm! "~p', 'E353') 2372 call assert_equal([], getreg('~', 1, 1)) 2373 " the ~ register is read only 2374 call assert_fails(':let @~="1"', 'E354') 2375 bw! 2376endfunc 2377 2378func Test_normal46_ignore() 2379 new 2380 " How to test this? 2381 " let's just for now test, that the buffer 2382 " does not change 2383 call feedkeys("\<c-s>", 't') 2384 call assert_equal([''], getline(1,'$')) 2385 2386 " no valid commands 2387 exe "norm! \<char-0x100>" 2388 call assert_equal([''], getline(1,'$')) 2389 2390 exe "norm! ä" 2391 call assert_equal([''], getline(1,'$')) 2392 2393 " clean up 2394 bw! 2395endfunc 2396 2397func Test_normal47_visual_buf_wipe() 2398 " This was causing a crash or ml_get error. 2399 enew! 2400 call setline(1,'xxx') 2401 normal $ 2402 new 2403 call setline(1, range(1,2)) 2404 2 2405 exe "norm \<C-V>$" 2406 bw! 2407 norm yp 2408 set nomodified 2409endfunc 2410 2411func Test_normal47_autocmd() 2412 " disabled, does not seem to be possible currently 2413 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" 2414 new 2415 call append(0, repeat('-',20)) 2416 au CursorHold * call feedkeys('2l', '') 2417 1 2418 set updatetime=20 2419 " should delete 12 chars (d12l) 2420 call feedkeys('d1', '!') 2421 call assert_equal('--------', getline(1)) 2422 2423 " clean up 2424 au! CursorHold 2425 set updatetime=4000 2426 bw! 2427endfunc 2428 2429func Test_normal48_wincmd() 2430 new 2431 exe "norm! \<c-w>c" 2432 call assert_equal(1, winnr('$')) 2433 call assert_fails(":norm! \<c-w>c", "E444") 2434endfunc 2435 2436func Test_normal49_counts() 2437 new 2438 call setline(1, 'one two three four five six seven eight nine ten') 2439 1 2440 norm! 3d2w 2441 call assert_equal('seven eight nine ten', getline(1)) 2442 bw! 2443endfunc 2444 2445func Test_normal50_commandline() 2446 CheckFeature timers 2447 CheckFeature cmdline_hist 2448 func! DoTimerWork(id) 2449 call assert_equal('[Command Line]', bufname('')) 2450 " should fail, with E11, but does fail with E23? 2451 "call feedkeys("\<c-^>", 'tm') 2452 2453 " should also fail with E11 2454 call assert_fails(":wincmd p", 'E11') 2455 " return from commandline window 2456 call feedkeys("\<cr>") 2457 endfunc 2458 2459 let oldlang=v:lang 2460 lang C 2461 set updatetime=20 2462 call timer_start(100, 'DoTimerWork') 2463 try 2464 " throws E23, for whatever reason... 2465 call feedkeys('q:', 'x!') 2466 catch /E23/ 2467 " no-op 2468 endtry 2469 " clean up 2470 set updatetime=4000 2471 exe "lang" oldlang 2472 bw! 2473endfunc 2474 2475func Test_normal51_FileChangedRO() 2476 CheckFeature autocmd 2477 " Don't sleep after the warning message. 2478 call test_settime(1) 2479 call writefile(['foo'], 'Xreadonly.log') 2480 new Xreadonly.log 2481 setl ro 2482 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix') 2483 call assert_fails(":norm! Af", 'E788') 2484 call assert_equal(['foo'], getline(1,'$')) 2485 call assert_equal('Xreadonly.log', bufname('')) 2486 2487 " cleanup 2488 call test_settime(0) 2489 bw! 2490 call delete("Xreadonly.log") 2491endfunc 2492 2493func Test_normal52_rl() 2494 CheckFeature rightleft 2495 new 2496 call setline(1, 'abcde fghij klmnopq') 2497 norm! 1gg$ 2498 set rl 2499 call assert_equal(19, col('.')) 2500 call feedkeys('l', 'tx') 2501 call assert_equal(18, col('.')) 2502 call feedkeys('h', 'tx') 2503 call assert_equal(19, col('.')) 2504 call feedkeys("\<right>", 'tx') 2505 call assert_equal(18, col('.')) 2506 call feedkeys("\<left>", 'tx') 2507 call assert_equal(19, col('.')) 2508 call feedkeys("\<s-right>", 'tx') 2509 call assert_equal(13, col('.')) 2510 call feedkeys("\<c-right>", 'tx') 2511 call assert_equal(7, col('.')) 2512 call feedkeys("\<c-left>", 'tx') 2513 call assert_equal(13, col('.')) 2514 call feedkeys("\<s-left>", 'tx') 2515 call assert_equal(19, col('.')) 2516 call feedkeys("<<", 'tx') 2517 call assert_equal(' abcde fghij klmnopq',getline(1)) 2518 call feedkeys(">>", 'tx') 2519 call assert_equal('abcde fghij klmnopq',getline(1)) 2520 2521 " cleanup 2522 set norl 2523 bw! 2524endfunc 2525 2526func Test_normal54_Ctrl_bsl() 2527 new 2528 call setline(1, 'abcdefghijklmn') 2529 exe "norm! df\<c-\>\<c-n>" 2530 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2531 exe "norm! df\<c-\>\<c-g>" 2532 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2533 exe "norm! df\<c-\>m" 2534 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2535 2536 call setline(2, 'abcdefghijklmnāf') 2537 norm! 2gg0 2538 exe "norm! df\<Char-0x101>" 2539 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2540 norm! 1gg0 2541 exe "norm! df\<esc>" 2542 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2543 2544 " clean up 2545 bw! 2546endfunc 2547 2548func Test_normal_large_count() 2549 " This may fail with 32bit long, how do we detect that? 2550 new 2551 normal o 2552 normal 6666666666dL 2553 bwipe! 2554endfunc 2555 2556func Test_delete_until_paragraph() 2557 new 2558 normal grádv} 2559 call assert_equal('á', getline(1)) 2560 normal grád} 2561 call assert_equal('', getline(1)) 2562 bwipe! 2563endfunc 2564 2565" Test for the gr (virtual replace) command 2566" Test for the bug fixed by 7.4.387 2567func Test_gr_command() 2568 enew! 2569 let save_cpo = &cpo 2570 call append(0, ['First line', 'Second line', 'Third line']) 2571 exe "normal i\<C-G>u" 2572 call cursor(2, 1) 2573 set cpo-=X 2574 normal 4gro 2575 call assert_equal('oooond line', getline(2)) 2576 undo 2577 set cpo+=X 2578 normal 4gro 2579 call assert_equal('ooooecond line', getline(2)) 2580 let &cpo = save_cpo 2581 normal! ggvegrx 2582 call assert_equal('xxxxx line', getline(1)) 2583 exe "normal! gggr\<C-V>122" 2584 call assert_equal('zxxxx line', getline(1)) 2585 set virtualedit=all 2586 normal! 15|grl 2587 call assert_equal('zxxxx line l', getline(1)) 2588 set virtualedit& 2589 set nomodifiable 2590 call assert_fails('normal! grx', 'E21:') 2591 call assert_fails('normal! gRx', 'E21:') 2592 set modifiable& 2593 enew! 2594endfunc 2595 2596" When splitting a window the changelist position is wrong. 2597" Test the changelist position after splitting a window. 2598" Test for the bug fixed by 7.4.386 2599func Test_changelist() 2600 let save_ul = &ul 2601 enew! 2602 call append('$', ['1', '2']) 2603 exe "normal i\<C-G>u" 2604 exe "normal Gkylpa\<C-G>u" 2605 set ul=100 2606 exe "normal Gylpa\<C-G>u" 2607 set ul=100 2608 normal gg 2609 vsplit 2610 normal g; 2611 call assert_equal([3, 2], [line('.'), col('.')]) 2612 normal g; 2613 call assert_equal([2, 2], [line('.'), col('.')]) 2614 call assert_fails('normal g;', 'E662:') 2615 new 2616 call assert_fails('normal g;', 'E664:') 2617 %bwipe! 2618 let &ul = save_ul 2619endfunc 2620 2621func Test_nv_hat_count() 2622 %bwipeout! 2623 let l:nr = bufnr('%') + 1 2624 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92') 2625 2626 edit Xfoo 2627 let l:foo_nr = bufnr('Xfoo') 2628 2629 edit Xbar 2630 let l:bar_nr = bufnr('Xbar') 2631 2632 " Make sure we are not just using the alternate file. 2633 edit Xbaz 2634 2635 call feedkeys(l:foo_nr . "\<C-^>", 'tx') 2636 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) 2637 2638 call feedkeys(l:bar_nr . "\<C-^>", 'tx') 2639 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) 2640 2641 %bwipeout! 2642endfunc 2643 2644func Test_message_when_using_ctrl_c() 2645 " Make sure no buffers are changed. 2646 %bwipe! 2647 2648 exe "normal \<C-C>" 2649 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines)) 2650 2651 new 2652 cal setline(1, 'hi!') 2653 exe "normal \<C-C>" 2654 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines)) 2655 2656 bwipe! 2657endfunc 2658 2659" Test for '[m', ']m', '[M' and ']M' 2660" Jumping to beginning and end of methods in Java-like languages 2661func Test_java_motion() 2662 new 2663 call assert_beeps('normal! [m') 2664 call assert_beeps('normal! ]m') 2665 call assert_beeps('normal! [M') 2666 call assert_beeps('normal! ]M') 2667 a 2668Piece of Java 2669{ 2670 tt m1 { 2671 t1; 2672 } e1 2673 2674 tt m2 { 2675 t2; 2676 } e2 2677 2678 tt m3 { 2679 if (x) 2680 { 2681 t3; 2682 } 2683 } e3 2684} 2685. 2686 2687 normal gg 2688 2689 normal 2]maA 2690 call assert_equal("\ttt m1 {A", getline('.')) 2691 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) 2692 2693 normal j]maB 2694 call assert_equal("\ttt m2 {B", getline('.')) 2695 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')]) 2696 2697 normal ]maC 2698 call assert_equal("\ttt m3 {C", getline('.')) 2699 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) 2700 2701 normal [maD 2702 call assert_equal("\ttt m3 {DC", getline('.')) 2703 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) 2704 2705 normal k2[maE 2706 call assert_equal("\ttt m1 {EA", getline('.')) 2707 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) 2708 2709 normal 3[maF 2710 call assert_equal("{F", getline('.')) 2711 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) 2712 2713 normal ]MaG 2714 call assert_equal("\t}G e1", getline('.')) 2715 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')]) 2716 2717 normal j2]MaH 2718 call assert_equal("\t}H e3", getline('.')) 2719 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) 2720 2721 normal ]M]M 2722 normal aI 2723 call assert_equal("}I", getline('.')) 2724 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')]) 2725 2726 normal 2[MaJ 2727 call assert_equal("\t}JH e3", getline('.')) 2728 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) 2729 2730 normal k[MaK 2731 call assert_equal("\t}K e2", getline('.')) 2732 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')]) 2733 2734 normal 3[MaL 2735 call assert_equal("{LF", getline('.')) 2736 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) 2737 2738 close! 2739endfunc 2740 2741" Tests for g cmds 2742func Test_normal_gdollar_cmd() 2743 CheckFeature jumplist 2744 call Setup_NewWindow() 2745 " Make long lines that will wrap 2746 %s/$/\=repeat(' foobar', 10)/ 2747 20vsp 2748 set wrap 2749 " Test for g$ with count 2750 norm! gg 2751 norm! 0vg$y 2752 call assert_equal(20, col("'>")) 2753 call assert_equal('1 foobar foobar foob', getreg(0)) 2754 norm! gg 2755 norm! 0v4g$y 2756 call assert_equal(72, col("'>")) 2757 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0)) 2758 norm! gg 2759 norm! 0v6g$y 2760 call assert_equal(40, col("'>")) 2761 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2762 \ '2 foobar foobar foobar foobar foobar foo', getreg(0)) 2763 set nowrap 2764 " clean up 2765 norm! gg 2766 norm! 0vg$y 2767 call assert_equal(20, col("'>")) 2768 call assert_equal('1 foobar foobar foob', getreg(0)) 2769 norm! gg 2770 norm! 0v4g$y 2771 call assert_equal(20, col("'>")) 2772 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2773 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2774 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2775 \ '4 foobar foobar foob', getreg(0)) 2776 norm! gg 2777 norm! 0v6g$y 2778 call assert_equal(20, col("'>")) 2779 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2780 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2781 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2782 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2783 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2784 \ '6 foobar foobar foob', getreg(0)) 2785 " Move to last line, also down movement is not possible, should still move 2786 " the cursor to the last visible char 2787 norm! G 2788 norm! 0v6g$y 2789 call assert_equal(20, col("'>")) 2790 call assert_equal('100 foobar foobar fo', getreg(0)) 2791 bw! 2792endfunc 2793 2794func Test_normal_gk_gj() 2795 " needs 80 column new window 2796 new 2797 vert 80new 2798 call assert_beeps('normal gk') 2799 put =[repeat('x',90)..' {{{1', 'x {{{1'] 2800 norm! gk 2801 " In a 80 column wide terminal the window will be only 78 char 2802 " (because Vim will leave space for the other window), 2803 " but if the terminal is larger, it will be 80 chars, so verify the 2804 " cursor column correctly. 2805 call assert_equal(winwidth(0)+1, col('.')) 2806 call assert_equal(winwidth(0)+1, virtcol('.')) 2807 norm! j 2808 call assert_equal(6, col('.')) 2809 call assert_equal(6, virtcol('.')) 2810 norm! gk 2811 call assert_equal(95, col('.')) 2812 call assert_equal(95, virtcol('.')) 2813 %bw! 2814 2815 " needs 80 column new window 2816 new 2817 vert 80new 2818 call assert_beeps('normal gj') 2819 set number 2820 set numberwidth=10 2821 set cpoptions+=n 2822 put =[repeat('0',90), repeat('1',90)] 2823 norm! 075l 2824 call assert_equal(76, col('.')) 2825 norm! gk 2826 call assert_equal(1, col('.')) 2827 norm! gk 2828 call assert_equal(76, col('.')) 2829 norm! gk 2830 call assert_equal(1, col('.')) 2831 norm! gj 2832 call assert_equal(76, col('.')) 2833 norm! gj 2834 call assert_equal(1, col('.')) 2835 norm! gj 2836 call assert_equal(76, col('.')) 2837 " When 'nowrap' is set, gk and gj behave like k and j 2838 set nowrap 2839 normal! gk 2840 call assert_equal([2, 76], [line('.'), col('.')]) 2841 normal! gj 2842 call assert_equal([3, 76], [line('.'), col('.')]) 2843 %bw! 2844 set cpoptions& number& numberwidth& wrap& 2845endfunc 2846 2847" Test for using : to run a multi-line Ex command in operator pending mode 2848func Test_normal_yank_with_excmd() 2849 new 2850 call setline(1, ['foo', 'bar', 'baz']) 2851 let @a = '' 2852 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt') 2853 call assert_equal('f', @a) 2854 close! 2855endfunc 2856 2857" Test for supplying a count to a normal-mode command across a cursorhold call 2858func Test_normal_cursorhold_with_count() 2859 func s:cHold() 2860 let g:cHold_Called += 1 2861 endfunc 2862 new 2863 augroup normalcHoldTest 2864 au! 2865 au CursorHold <buffer> call s:cHold() 2866 augroup END 2867 let g:cHold_Called = 0 2868 call feedkeys("3\<CursorHold>2ix", 'xt') 2869 call assert_equal(1, g:cHold_Called) 2870 call assert_equal(repeat('x', 32), getline(1)) 2871 augroup normalcHoldTest 2872 au! 2873 augroup END 2874 au! normalcHoldTest 2875 close! 2876 delfunc s:cHold 2877endfunc 2878 2879" Test for using a count and a command with CTRL-W 2880func Test_wincmd_with_count() 2881 call feedkeys("\<C-W>12n", 'xt') 2882 call assert_equal(12, winheight(0)) 2883endfunc 2884 2885" Test for 'b', 'B' 'ge' and 'gE' commands 2886func Test_horiz_motion() 2887 new 2888 normal! gg 2889 call assert_beeps('normal! b') 2890 call assert_beeps('normal! B') 2891 call assert_beeps('normal! gE') 2892 call assert_beeps('normal! ge') 2893 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left 2894 call setline(1, 'one ,two ,three') 2895 exe "normal! $\<S-BS>" 2896 call assert_equal(11, col('.')) 2897 exe "normal! $\<C-BS>" 2898 call assert_equal(10, col('.')) 2899 close! 2900endfunc 2901 2902" Test for using a : command in operator pending mode 2903func Test_normal_colon_op() 2904 new 2905 call setline(1, ['one', 'two']) 2906 call assert_beeps("normal! Gc:d\<CR>") 2907 close! 2908endfunc 2909 2910" Test for d and D commands 2911func Test_normal_delete_cmd() 2912 new 2913 " D in an empty line 2914 call setline(1, '') 2915 normal D 2916 call assert_equal('', getline(1)) 2917 " D in an empty line in virtualedit mode 2918 set virtualedit=all 2919 normal D 2920 call assert_equal('', getline(1)) 2921 set virtualedit& 2922 " delete to a readonly register 2923 call setline(1, ['abcd']) 2924 call assert_beeps('normal ":d2l') 2925 close! 2926endfunc 2927 2928" Test for 'w' and 'b' commands 2929func Test_normal_word_move() 2930 new 2931 call setline(1, ['foo bar a', '', 'foo bar b']) 2932 " copy a single character word at the end of a line 2933 normal 1G$yw 2934 call assert_equal('a', @") 2935 " copy a single character word at the end of a file 2936 normal G$yw 2937 call assert_equal('b', @") 2938 " check for a word movement handling an empty line properly 2939 normal 1G$vwy 2940 call assert_equal("a\n\n", @") 2941 2942 " copy using 'b' command 2943 %d 2944 " non-empty blank line at the start of file 2945 call setline(1, [' ', 'foo bar']) 2946 normal 2Gyb 2947 call assert_equal(" \n", @") 2948 " try to copy backwards from the start of the file 2949 call setline(1, ['one two', 'foo bar']) 2950 call assert_beeps('normal ggyb') 2951 " 'b' command should stop at an empty line 2952 call setline(1, ['one two', '', 'foo bar']) 2953 normal 3Gyb 2954 call assert_equal("\n", @") 2955 normal 3Gy2b 2956 call assert_equal("two\n", @") 2957 " 'b' command should not stop at a non-empty blank line 2958 call setline(1, ['one two', ' ', 'foo bar']) 2959 normal 3Gyb 2960 call assert_equal("two\n ", @") 2961 2962 close! 2963endfunc 2964 2965" vim: shiftwidth=2 sts=2 expandtab 2966