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