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 " and cpo+=w setting 2246 new 2247 set tw=0 2248 call append(0, 'here are some words') 2249 norm! 1gg0elcwZZZ 2250 call assert_equal('hereZZZare some words', getline('.')) 2251 norm! 1gg0elcWYYY 2252 call assert_equal('hereZZZareYYYsome words', getline('.')) 2253 set cpo+=w 2254 call setline(1, 'here are some words') 2255 norm! 1gg0elcwZZZ 2256 call assert_equal('hereZZZ are some words', getline('.')) 2257 norm! 1gg2elcWYYY 2258 call assert_equal('hereZZZ areYYY some words', getline('.')) 2259 set cpo-=w 2260 norm! 2gg0cwfoo 2261 call assert_equal('foo', getline('.')) 2262 2263 call setline(1, 'one; two') 2264 call cursor(1, 1) 2265 call feedkeys('cwvim', 'xt') 2266 call assert_equal('vim; two', getline(1)) 2267 call feedkeys('0cWone', 'xt') 2268 call assert_equal('one two', getline(1)) 2269 "When cursor is at the end of a word 'ce' will change until the end of the 2270 "next word, but 'cw' will change only one character 2271 call setline(1, 'one two') 2272 call feedkeys('0ecwce', 'xt') 2273 call assert_equal('once two', getline(1)) 2274 call setline(1, 'one two') 2275 call feedkeys('0ecely', 'xt') 2276 call assert_equal('only', getline(1)) 2277 2278 " clean up 2279 bw! 2280endfunc 2281 2282" Test for CTRL-\ commands 2283func Test_normal40_ctrl_bsl() 2284 new 2285 call append(0, 'here are some words') 2286 exe "norm! 1gg0a\<C-\>\<C-N>" 2287 call assert_equal('n', mode()) 2288 call assert_equal(1, col('.')) 2289 call assert_equal('', visualmode()) 2290 exe "norm! 1gg0viw\<C-\>\<C-N>" 2291 call assert_equal('n', mode()) 2292 call assert_equal(4, col('.')) 2293 exe "norm! 1gg0a\<C-\>\<C-G>" 2294 call assert_equal('n', mode()) 2295 call assert_equal(1, col('.')) 2296 "imap <buffer> , <c-\><c-n> 2297 set im 2298 exe ":norm! \<c-\>\<c-n>dw" 2299 set noim 2300 call assert_equal('are some words', getline(1)) 2301 call assert_false(&insertmode) 2302 call assert_beeps("normal! \<C-\>\<C-A>", 'xt') 2303 2304 " Using CTRL-\ CTRL-N in cmd window should close the window 2305 call feedkeys("q:\<C-\>\<C-N>", 'xt') 2306 call assert_equal('', getcmdwintype()) 2307 2308 " clean up 2309 bw! 2310endfunc 2311 2312" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode 2313func Test_normal41_insert_reg() 2314 new 2315 set sts=2 sw=2 ts=8 tw=0 2316 call append(0, ["aaa\tbbb\tccc", '', '', '']) 2317 let a=getline(1) 2318 norm! 2gg0 2319 exe "norm! a\<c-r>=a\<cr>" 2320 norm! 3gg0 2321 exe "norm! a\<c-r>\<c-r>=a\<cr>" 2322 norm! 4gg0 2323 exe "norm! a\<c-r>\<c-o>=a\<cr>" 2324 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) 2325 2326 " clean up 2327 set sts=0 sw=8 ts=8 2328 bw! 2329endfunc 2330 2331" Test for Ctrl-D and Ctrl-U 2332func Test_normal42_halfpage() 2333 call Setup_NewWindow() 2334 call assert_equal(5, &scroll) 2335 exe "norm! \<c-d>" 2336 call assert_equal('6', getline('.')) 2337 exe "norm! 2\<c-d>" 2338 call assert_equal('8', getline('.')) 2339 call assert_equal(2, &scroll) 2340 set scroll=5 2341 exe "norm! \<c-u>" 2342 call assert_equal('3', getline('.')) 2343 1 2344 set scrolloff=5 2345 exe "norm! \<c-d>" 2346 call assert_equal('10', getline('.')) 2347 exe "norm! \<c-u>" 2348 call assert_equal('5', getline('.')) 2349 1 2350 set scrolloff=99 2351 exe "norm! \<c-d>" 2352 call assert_equal('10', getline('.')) 2353 set scrolloff=0 2354 100 2355 exe "norm! $\<c-u>" 2356 call assert_equal('95', getline('.')) 2357 call assert_equal([0, 95, 1, 0, 1], getcurpos()) 2358 100 2359 set nostartofline 2360 exe "norm! $\<c-u>" 2361 call assert_equal('95', getline('.')) 2362 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) 2363 " cleanup 2364 set startofline 2365 bw! 2366endfunc 2367 2368func Test_normal45_drop() 2369 if !has('dnd') 2370 " The ~ register does not exist 2371 call assert_beeps('norm! "~') 2372 return 2373 endif 2374 2375 " basic test for drag-n-drop 2376 " unfortunately, without a gui, we can't really test much here, 2377 " so simply test that ~p fails (which uses the drop register) 2378 new 2379 call assert_fails(':norm! "~p', 'E353') 2380 call assert_equal([], getreg('~', 1, 1)) 2381 " the ~ register is read only 2382 call assert_fails(':let @~="1"', 'E354') 2383 bw! 2384endfunc 2385 2386func Test_normal46_ignore() 2387 new 2388 " How to test this? 2389 " let's just for now test, that the buffer 2390 " does not change 2391 call feedkeys("\<c-s>", 't') 2392 call assert_equal([''], getline(1,'$')) 2393 2394 " no valid commands 2395 exe "norm! \<char-0x100>" 2396 call assert_equal([''], getline(1,'$')) 2397 2398 exe "norm! ä" 2399 call assert_equal([''], getline(1,'$')) 2400 2401 " clean up 2402 bw! 2403endfunc 2404 2405func Test_normal47_visual_buf_wipe() 2406 " This was causing a crash or ml_get error. 2407 enew! 2408 call setline(1,'xxx') 2409 normal $ 2410 new 2411 call setline(1, range(1,2)) 2412 2 2413 exe "norm \<C-V>$" 2414 bw! 2415 norm yp 2416 set nomodified 2417endfunc 2418 2419func Test_normal47_autocmd() 2420 " disabled, does not seem to be possible currently 2421 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" 2422 new 2423 call append(0, repeat('-',20)) 2424 au CursorHold * call feedkeys('2l', '') 2425 1 2426 set updatetime=20 2427 " should delete 12 chars (d12l) 2428 call feedkeys('d1', '!') 2429 call assert_equal('--------', getline(1)) 2430 2431 " clean up 2432 au! CursorHold 2433 set updatetime=4000 2434 bw! 2435endfunc 2436 2437func Test_normal48_wincmd() 2438 new 2439 exe "norm! \<c-w>c" 2440 call assert_equal(1, winnr('$')) 2441 call assert_fails(":norm! \<c-w>c", "E444") 2442endfunc 2443 2444func Test_normal49_counts() 2445 new 2446 call setline(1, 'one two three four five six seven eight nine ten') 2447 1 2448 norm! 3d2w 2449 call assert_equal('seven eight nine ten', getline(1)) 2450 bw! 2451endfunc 2452 2453func Test_normal50_commandline() 2454 CheckFeature timers 2455 CheckFeature cmdline_hist 2456 func! DoTimerWork(id) 2457 call assert_equal('[Command Line]', bufname('')) 2458 " should fail, with E11, but does fail with E23? 2459 "call feedkeys("\<c-^>", 'tm') 2460 2461 " should also fail with E11 2462 call assert_fails(":wincmd p", 'E11') 2463 " return from commandline window 2464 call feedkeys("\<cr>") 2465 endfunc 2466 2467 let oldlang=v:lang 2468 lang C 2469 set updatetime=20 2470 call timer_start(100, 'DoTimerWork') 2471 try 2472 " throws E23, for whatever reason... 2473 call feedkeys('q:', 'x!') 2474 catch /E23/ 2475 " no-op 2476 endtry 2477 " clean up 2478 set updatetime=4000 2479 exe "lang" oldlang 2480 bw! 2481endfunc 2482 2483func Test_normal51_FileChangedRO() 2484 CheckFeature autocmd 2485 " Don't sleep after the warning message. 2486 call test_settime(1) 2487 call writefile(['foo'], 'Xreadonly.log') 2488 new Xreadonly.log 2489 setl ro 2490 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix') 2491 call assert_fails(":norm! Af", 'E788') 2492 call assert_equal(['foo'], getline(1,'$')) 2493 call assert_equal('Xreadonly.log', bufname('')) 2494 2495 " cleanup 2496 call test_settime(0) 2497 bw! 2498 call delete("Xreadonly.log") 2499endfunc 2500 2501func Test_normal52_rl() 2502 CheckFeature rightleft 2503 new 2504 call setline(1, 'abcde fghij klmnopq') 2505 norm! 1gg$ 2506 set rl 2507 call assert_equal(19, col('.')) 2508 call feedkeys('l', 'tx') 2509 call assert_equal(18, col('.')) 2510 call feedkeys('h', 'tx') 2511 call assert_equal(19, col('.')) 2512 call feedkeys("\<right>", 'tx') 2513 call assert_equal(18, col('.')) 2514 call feedkeys("\<left>", 'tx') 2515 call assert_equal(19, col('.')) 2516 call feedkeys("\<s-right>", 'tx') 2517 call assert_equal(13, col('.')) 2518 call feedkeys("\<c-right>", 'tx') 2519 call assert_equal(7, col('.')) 2520 call feedkeys("\<c-left>", 'tx') 2521 call assert_equal(13, col('.')) 2522 call feedkeys("\<s-left>", 'tx') 2523 call assert_equal(19, col('.')) 2524 call feedkeys("<<", 'tx') 2525 call assert_equal(' abcde fghij klmnopq',getline(1)) 2526 call feedkeys(">>", 'tx') 2527 call assert_equal('abcde fghij klmnopq',getline(1)) 2528 2529 " cleanup 2530 set norl 2531 bw! 2532endfunc 2533 2534func Test_normal53_digraph() 2535 CheckFeature digraphs 2536 new 2537 call setline(1, 'abcdefgh|') 2538 exe "norm! 1gg0f\<c-k>!!" 2539 call assert_equal(9, col('.')) 2540 set cpo+=D 2541 exe "norm! 1gg0f\<c-k>!!" 2542 call assert_equal(1, col('.')) 2543 2544 set cpo-=D 2545 bw! 2546endfunc 2547 2548func Test_normal54_Ctrl_bsl() 2549 new 2550 call setline(1, 'abcdefghijklmn') 2551 exe "norm! df\<c-\>\<c-n>" 2552 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2553 exe "norm! df\<c-\>\<c-g>" 2554 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2555 exe "norm! df\<c-\>m" 2556 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2557 2558 call setline(2, 'abcdefghijklmnāf') 2559 norm! 2gg0 2560 exe "norm! df\<Char-0x101>" 2561 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2562 norm! 1gg0 2563 exe "norm! df\<esc>" 2564 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2565 2566 " clean up 2567 bw! 2568endfunc 2569 2570func Test_normal_large_count() 2571 " This may fail with 32bit long, how do we detect that? 2572 new 2573 normal o 2574 normal 6666666666dL 2575 bwipe! 2576endfunc 2577 2578func Test_delete_until_paragraph() 2579 new 2580 normal grádv} 2581 call assert_equal('á', getline(1)) 2582 normal grád} 2583 call assert_equal('', getline(1)) 2584 bwipe! 2585endfunc 2586 2587" Test for the gr (virtual replace) command 2588" Test for the bug fixed by 7.4.387 2589func Test_gr_command() 2590 enew! 2591 let save_cpo = &cpo 2592 call append(0, ['First line', 'Second line', 'Third line']) 2593 exe "normal i\<C-G>u" 2594 call cursor(2, 1) 2595 set cpo-=X 2596 normal 4gro 2597 call assert_equal('oooond line', getline(2)) 2598 undo 2599 set cpo+=X 2600 normal 4gro 2601 call assert_equal('ooooecond line', getline(2)) 2602 let &cpo = save_cpo 2603 normal! ggvegrx 2604 call assert_equal('xxxxx line', getline(1)) 2605 exe "normal! gggr\<C-V>122" 2606 call assert_equal('zxxxx line', getline(1)) 2607 set virtualedit=all 2608 normal! 15|grl 2609 call assert_equal('zxxxx line l', getline(1)) 2610 set virtualedit& 2611 set nomodifiable 2612 call assert_fails('normal! grx', 'E21:') 2613 call assert_fails('normal! gRx', 'E21:') 2614 set modifiable& 2615 enew! 2616endfunc 2617 2618" When splitting a window the changelist position is wrong. 2619" Test the changelist position after splitting a window. 2620" Test for the bug fixed by 7.4.386 2621func Test_changelist() 2622 let save_ul = &ul 2623 enew! 2624 call append('$', ['1', '2']) 2625 exe "normal i\<C-G>u" 2626 exe "normal Gkylpa\<C-G>u" 2627 set ul=100 2628 exe "normal Gylpa\<C-G>u" 2629 set ul=100 2630 normal gg 2631 vsplit 2632 normal g; 2633 call assert_equal([3, 2], [line('.'), col('.')]) 2634 normal g; 2635 call assert_equal([2, 2], [line('.'), col('.')]) 2636 call assert_fails('normal g;', 'E662:') 2637 new 2638 call assert_fails('normal g;', 'E664:') 2639 %bwipe! 2640 let &ul = save_ul 2641endfunc 2642 2643func Test_nv_hat_count() 2644 %bwipeout! 2645 let l:nr = bufnr('%') + 1 2646 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92') 2647 2648 edit Xfoo 2649 let l:foo_nr = bufnr('Xfoo') 2650 2651 edit Xbar 2652 let l:bar_nr = bufnr('Xbar') 2653 2654 " Make sure we are not just using the alternate file. 2655 edit Xbaz 2656 2657 call feedkeys(l:foo_nr . "\<C-^>", 'tx') 2658 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) 2659 2660 call feedkeys(l:bar_nr . "\<C-^>", 'tx') 2661 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) 2662 2663 %bwipeout! 2664endfunc 2665 2666func Test_message_when_using_ctrl_c() 2667 " Make sure no buffers are changed. 2668 %bwipe! 2669 2670 exe "normal \<C-C>" 2671 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines)) 2672 2673 new 2674 cal setline(1, 'hi!') 2675 exe "normal \<C-C>" 2676 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines)) 2677 2678 bwipe! 2679endfunc 2680 2681" Test for '[m', ']m', '[M' and ']M' 2682" Jumping to beginning and end of methods in Java-like languages 2683func Test_java_motion() 2684 new 2685 call assert_beeps('normal! [m') 2686 call assert_beeps('normal! ]m') 2687 call assert_beeps('normal! [M') 2688 call assert_beeps('normal! ]M') 2689 a 2690Piece of Java 2691{ 2692 tt m1 { 2693 t1; 2694 } e1 2695 2696 tt m2 { 2697 t2; 2698 } e2 2699 2700 tt m3 { 2701 if (x) 2702 { 2703 t3; 2704 } 2705 } e3 2706} 2707. 2708 2709 normal gg 2710 2711 normal 2]maA 2712 call assert_equal("\ttt m1 {A", getline('.')) 2713 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) 2714 2715 normal j]maB 2716 call assert_equal("\ttt m2 {B", getline('.')) 2717 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')]) 2718 2719 normal ]maC 2720 call assert_equal("\ttt m3 {C", getline('.')) 2721 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) 2722 2723 normal [maD 2724 call assert_equal("\ttt m3 {DC", getline('.')) 2725 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) 2726 2727 normal k2[maE 2728 call assert_equal("\ttt m1 {EA", getline('.')) 2729 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) 2730 2731 normal 3[maF 2732 call assert_equal("{F", getline('.')) 2733 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) 2734 2735 normal ]MaG 2736 call assert_equal("\t}G e1", getline('.')) 2737 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')]) 2738 2739 normal j2]MaH 2740 call assert_equal("\t}H e3", getline('.')) 2741 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) 2742 2743 normal ]M]M 2744 normal aI 2745 call assert_equal("}I", getline('.')) 2746 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')]) 2747 2748 normal 2[MaJ 2749 call assert_equal("\t}JH e3", getline('.')) 2750 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) 2751 2752 normal k[MaK 2753 call assert_equal("\t}K e2", getline('.')) 2754 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')]) 2755 2756 normal 3[MaL 2757 call assert_equal("{LF", getline('.')) 2758 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) 2759 2760 close! 2761endfunc 2762 2763" Tests for g cmds 2764func Test_normal_gdollar_cmd() 2765 CheckFeature jumplist 2766 call Setup_NewWindow() 2767 " Make long lines that will wrap 2768 %s/$/\=repeat(' foobar', 10)/ 2769 20vsp 2770 set wrap 2771 " Test for g$ with count 2772 norm! gg 2773 norm! 0vg$y 2774 call assert_equal(20, col("'>")) 2775 call assert_equal('1 foobar foobar foob', getreg(0)) 2776 norm! gg 2777 norm! 0v4g$y 2778 call assert_equal(72, col("'>")) 2779 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0)) 2780 norm! gg 2781 norm! 0v6g$y 2782 call assert_equal(40, col("'>")) 2783 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2784 \ '2 foobar foobar foobar foobar foobar foo', getreg(0)) 2785 set nowrap 2786 " clean up 2787 norm! gg 2788 norm! 0vg$y 2789 call assert_equal(20, col("'>")) 2790 call assert_equal('1 foobar foobar foob', getreg(0)) 2791 norm! gg 2792 norm! 0v4g$y 2793 call assert_equal(20, col("'>")) 2794 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2795 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2796 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2797 \ '4 foobar foobar foob', getreg(0)) 2798 norm! gg 2799 norm! 0v6g$y 2800 call assert_equal(20, col("'>")) 2801 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2802 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2803 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2804 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2805 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 2806 \ '6 foobar foobar foob', getreg(0)) 2807 " Move to last line, also down movement is not possible, should still move 2808 " the cursor to the last visible char 2809 norm! G 2810 norm! 0v6g$y 2811 call assert_equal(20, col("'>")) 2812 call assert_equal('100 foobar foobar fo', getreg(0)) 2813 bw! 2814endfunc 2815 2816func Test_normal_gk_gj() 2817 " needs 80 column new window 2818 new 2819 vert 80new 2820 call assert_beeps('normal gk') 2821 put =[repeat('x',90)..' {{{1', 'x {{{1'] 2822 norm! gk 2823 " In a 80 column wide terminal the window will be only 78 char 2824 " (because Vim will leave space for the other window), 2825 " but if the terminal is larger, it will be 80 chars, so verify the 2826 " cursor column correctly. 2827 call assert_equal(winwidth(0)+1, col('.')) 2828 call assert_equal(winwidth(0)+1, virtcol('.')) 2829 norm! j 2830 call assert_equal(6, col('.')) 2831 call assert_equal(6, virtcol('.')) 2832 norm! gk 2833 call assert_equal(95, col('.')) 2834 call assert_equal(95, virtcol('.')) 2835 %bw! 2836 2837 " needs 80 column new window 2838 new 2839 vert 80new 2840 call assert_beeps('normal gj') 2841 set number 2842 set numberwidth=10 2843 set cpoptions+=n 2844 put =[repeat('0',90), repeat('1',90)] 2845 norm! 075l 2846 call assert_equal(76, col('.')) 2847 norm! gk 2848 call assert_equal(1, col('.')) 2849 norm! gk 2850 call assert_equal(76, col('.')) 2851 norm! gk 2852 call assert_equal(1, col('.')) 2853 norm! gj 2854 call assert_equal(76, col('.')) 2855 norm! gj 2856 call assert_equal(1, col('.')) 2857 norm! gj 2858 call assert_equal(76, col('.')) 2859 " When 'nowrap' is set, gk and gj behave like k and j 2860 set nowrap 2861 normal! gk 2862 call assert_equal([2, 76], [line('.'), col('.')]) 2863 normal! gj 2864 call assert_equal([3, 76], [line('.'), col('.')]) 2865 %bw! 2866 set cpoptions& number& numberwidth& wrap& 2867endfunc 2868 2869" Test for cursor movement with '-' in 'cpoptions' 2870func Test_normal_cpo_minus() 2871 new 2872 call setline(1, ['foo', 'bar', 'baz']) 2873 let save_cpo = &cpo 2874 set cpo+=- 2875 call assert_beeps('normal 10j') 2876 call assert_equal(1, line('.')) 2877 normal G 2878 call assert_beeps('normal 10k') 2879 call assert_equal(3, line('.')) 2880 call assert_fails(10, 'E16:') 2881 let &cpo = save_cpo 2882 close! 2883endfunc 2884 2885" Test for displaying dollar when changing text ('$' flag in 'cpoptions') 2886func Test_normal_cpo_dollar() 2887 new 2888 let g:Line = '' 2889 func SaveFirstLine() 2890 let g:Line = Screenline(1) 2891 return '' 2892 endfunc 2893 inoremap <expr> <buffer> <F2> SaveFirstLine() 2894 call test_override('redraw_flag', 1) 2895 set cpo+=$ 2896 call setline(1, 'one two three') 2897 redraw! 2898 exe "normal c2w\<F2>vim" 2899 call assert_equal('one tw$ three', g:Line) 2900 call assert_equal('vim three', getline(1)) 2901 set cpo-=$ 2902 call test_override('ALL', 0) 2903 delfunc SaveFirstLine 2904 %bw! 2905endfunc 2906 2907" Test for using : to run a multi-line Ex command in operator pending mode 2908func Test_normal_yank_with_excmd() 2909 new 2910 call setline(1, ['foo', 'bar', 'baz']) 2911 let @a = '' 2912 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt') 2913 call assert_equal('f', @a) 2914 close! 2915endfunc 2916 2917" Test for supplying a count to a normal-mode command across a cursorhold call 2918func Test_normal_cursorhold_with_count() 2919 func s:cHold() 2920 let g:cHold_Called += 1 2921 endfunc 2922 new 2923 augroup normalcHoldTest 2924 au! 2925 au CursorHold <buffer> call s:cHold() 2926 augroup END 2927 let g:cHold_Called = 0 2928 call feedkeys("3\<CursorHold>2ix", 'xt') 2929 call assert_equal(1, g:cHold_Called) 2930 call assert_equal(repeat('x', 32), getline(1)) 2931 augroup normalcHoldTest 2932 au! 2933 augroup END 2934 au! normalcHoldTest 2935 close! 2936 delfunc s:cHold 2937endfunc 2938 2939" Test for using a count and a command with CTRL-W 2940func Test_wincmd_with_count() 2941 call feedkeys("\<C-W>12n", 'xt') 2942 call assert_equal(12, winheight(0)) 2943endfunc 2944 2945" Test for 'b', 'B' 'ge' and 'gE' commands 2946func Test_horiz_motion() 2947 new 2948 normal! gg 2949 call assert_beeps('normal! b') 2950 call assert_beeps('normal! B') 2951 call assert_beeps('normal! gE') 2952 call assert_beeps('normal! ge') 2953 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left 2954 call setline(1, 'one ,two ,three') 2955 exe "normal! $\<S-BS>" 2956 call assert_equal(11, col('.')) 2957 exe "normal! $\<C-BS>" 2958 call assert_equal(10, col('.')) 2959 close! 2960endfunc 2961 2962" Test for using a : command in operator pending mode 2963func Test_normal_colon_op() 2964 new 2965 call setline(1, ['one', 'two']) 2966 call assert_beeps("normal! Gc:d\<CR>") 2967 close! 2968endfunc 2969 2970" Test for d and D commands 2971func Test_normal_delete_cmd() 2972 new 2973 " D in an empty line 2974 call setline(1, '') 2975 normal D 2976 call assert_equal('', getline(1)) 2977 " D in an empty line in virtualedit mode 2978 set virtualedit=all 2979 normal D 2980 call assert_equal('', getline(1)) 2981 set virtualedit& 2982 " delete to a readonly register 2983 call setline(1, ['abcd']) 2984 call assert_beeps('normal ":d2l') 2985 close! 2986endfunc 2987 2988" Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators 2989func Test_empty_region_error() 2990 new 2991 call setline(1, '') 2992 set cpo+=E 2993 " yank an empty line 2994 call assert_beeps('normal "ayl') 2995 " change an empty line 2996 call assert_beeps('normal lcTa') 2997 " delete an empty line 2998 call assert_beeps('normal D') 2999 call assert_beeps('normal dl') 3000 call assert_equal('', getline(1)) 3001 " change case of an empty line 3002 call assert_beeps('normal gul') 3003 call assert_beeps('normal gUl') 3004 " replace a character 3005 call assert_beeps('normal vrx') 3006 " increment and decrement 3007 call assert_beeps('exe "normal v\<C-A>"') 3008 call assert_beeps('exe "normal v\<C-X>"') 3009 set cpo-=E 3010 close! 3011endfunc 3012 3013" Test for 'w' and 'b' commands 3014func Test_normal_word_move() 3015 new 3016 call setline(1, ['foo bar a', '', 'foo bar b']) 3017 " copy a single character word at the end of a line 3018 normal 1G$yw 3019 call assert_equal('a', @") 3020 " copy a single character word at the end of a file 3021 normal G$yw 3022 call assert_equal('b', @") 3023 " check for a word movement handling an empty line properly 3024 normal 1G$vwy 3025 call assert_equal("a\n\n", @") 3026 3027 " copy using 'b' command 3028 %d 3029 " non-empty blank line at the start of file 3030 call setline(1, [' ', 'foo bar']) 3031 normal 2Gyb 3032 call assert_equal(" \n", @") 3033 " try to copy backwards from the start of the file 3034 call setline(1, ['one two', 'foo bar']) 3035 call assert_beeps('normal ggyb') 3036 " 'b' command should stop at an empty line 3037 call setline(1, ['one two', '', 'foo bar']) 3038 normal 3Gyb 3039 call assert_equal("\n", @") 3040 normal 3Gy2b 3041 call assert_equal("two\n", @") 3042 " 'b' command should not stop at a non-empty blank line 3043 call setline(1, ['one two', ' ', 'foo bar']) 3044 normal 3Gyb 3045 call assert_equal("two\n ", @") 3046 3047 close! 3048endfunc 3049 3050" vim: shiftwidth=2 sts=2 expandtab 3051