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