1" Test for various Normal mode commands 2 3func! Setup_NewWindow() 4 10new 5 call setline(1, range(1,100)) 6endfunc 7 8func! MyFormatExpr() 9 " Adds '->$' at lines having numbers followed by trailing whitespace 10 for ln in range(v:lnum, v:lnum+v:count-1) 11 let line = getline(ln) 12 if getline(ln) =~# '\d\s\+$' 13 call setline(ln, substitute(line, '\s\+$', '', '') . '->$') 14 endif 15 endfor 16endfunc 17 18func! CountSpaces(type, ...) 19 " for testing operatorfunc 20 " will count the number of spaces 21 " and return the result in g:a 22 let sel_save = &selection 23 let &selection = "inclusive" 24 let reg_save = @@ 25 26 if a:0 " Invoked from Visual mode, use gv command. 27 silent exe "normal! gvy" 28 elseif a:type == 'line' 29 silent exe "normal! '[V']y" 30 else 31 silent exe "normal! `[v`]y" 32 endif 33 let g:a=strlen(substitute(@@, '[^ ]', '', 'g')) 34 let &selection = sel_save 35 let @@ = reg_save 36endfunc 37 38func! OpfuncDummy(type, ...) 39 " for testing operatorfunc 40 let g:opt=&linebreak 41 42 if a:0 " Invoked from Visual mode, use gv command. 43 silent exe "normal! gvy" 44 elseif a:type == 'line' 45 silent exe "normal! '[V']y" 46 else 47 silent exe "normal! `[v`]y" 48 endif 49 " Create a new dummy window 50 new 51 let g:bufnr=bufnr('%') 52endfunc 53 54fun! Test_normal00_optrans() 55 new 56 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) 57 1 58 exe "norm! Sfoobar\<esc>" 59 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$')) 60 2 61 exe "norm! $vbsone" 62 call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$')) 63 norm! VS Second line here 64 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$')) 65 %d 66 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line']) 67 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) 68 69 1 70 norm! 2D 71 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,'$')) 72 set cpo+=# 73 norm! 4D 74 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) 75 76 " clean up 77 set cpo-=# 78 bw! 79endfunc 80 81func! Test_normal01_keymodel() 82 call Setup_NewWindow() 83 " Test 1: depending on 'keymodel' <s-down> does something different 84 50 85 call feedkeys("V\<S-Up>y", 'tx') 86 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>")) 87 set keymodel=startsel 88 50 89 call feedkeys("V\<S-Up>y", 'tx') 90 call assert_equal(['49', '50'], getline("'<", "'>")) 91 " Start visual mode when keymodel = startsel 92 50 93 call feedkeys("\<S-Up>y", 'tx') 94 call assert_equal(['49', '5'], getreg(0, 0, 1)) 95 " Do not start visual mode when keymodel= 96 set keymodel= 97 50 98 call feedkeys("\<S-Up>y$", 'tx') 99 call assert_equal(['42'], getreg(0, 0, 1)) 100 " Stop visual mode when keymodel=stopsel 101 set keymodel=stopsel 102 50 103 call feedkeys("Vkk\<Up>yy", 'tx') 104 call assert_equal(['47'], getreg(0, 0, 1)) 105 106 set keymodel= 107 50 108 call feedkeys("Vkk\<Up>yy", 'tx') 109 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1)) 110 111 " clean up 112 bw! 113endfunc 114 115func! Test_normal02_selectmode() 116 " some basic select mode tests 117 call Setup_NewWindow() 118 50 119 norm! gHy 120 call assert_equal('y51', getline('.')) 121 call setline(1, range(1,100)) 122 50 123 exe ":norm! V9jo\<c-g>y" 124 call assert_equal('y60', getline('.')) 125 " clean up 126 bw! 127endfunc 128 129func! Test_normal02_selectmode2() 130 " some basic select mode tests 131 call Setup_NewWindow() 132 50 133 call feedkeys(":set im\n\<c-o>gHc\<c-o>:set noim\n", 'tx') 134 call assert_equal('c51', getline('.')) 135 " clean up 136 bw! 137endfunc 138 139func! Test_normal03_join() 140 " basic join test 141 call Setup_NewWindow() 142 50 143 norm! VJ 144 call assert_equal('50 51', getline('.')) 145 $ 146 norm! J 147 call assert_equal('100', getline('.')) 148 $ 149 norm! V9-gJ 150 call assert_equal('919293949596979899100', getline('.')) 151 call setline(1, range(1,100)) 152 $ 153 :j 10 154 call assert_equal('100', getline('.')) 155 " clean up 156 bw! 157endfunc 158 159func! Test_normal04_filter() 160 " basic filter test 161 " only test on non windows platform 162 if has('win32') 163 return 164 endif 165 call Setup_NewWindow() 166 1 167 call feedkeys("!!sed -e 's/^/| /'\n", 'tx') 168 call assert_equal('| 1', getline('.')) 169 90 170 :sil :!echo one 171 call feedkeys('.', 'tx') 172 call assert_equal('| 90', getline('.')) 173 95 174 set cpo+=! 175 " 2 <CR>, 1: for executing the command, 176 " 2: clear hit-enter-prompt 177 call feedkeys("!!\n", 'tx') 178 call feedkeys(":!echo one\n\n", 'tx') 179 call feedkeys(".", 'tx') 180 call assert_equal('one', getline('.')) 181 set cpo-=! 182 bw! 183endfunc 184 185func! Test_normal05_formatexpr() 186 " basic formatexpr test 187 call Setup_NewWindow() 188 %d_ 189 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: ']) 190 1 191 set formatexpr=MyFormatExpr() 192 norm! gqG 193 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$')) 194 set formatexpr= 195 bw! 196endfunc 197 198func Test_normal05_formatexpr_newbuf() 199 " Edit another buffer in the 'formatexpr' function 200 new 201 func! Format() 202 edit another 203 endfunc 204 set formatexpr=Format() 205 norm gqG 206 bw! 207 set formatexpr= 208endfunc 209 210func Test_normal05_formatexpr_setopt() 211 " Change the 'formatexpr' value in the function 212 new 213 func! Format() 214 set formatexpr= 215 endfunc 216 set formatexpr=Format() 217 norm gqG 218 bw! 219 set formatexpr= 220endfunc 221 222func! Test_normal06_formatprg() 223 " basic test for formatprg 224 " only test on non windows platform 225 if has('win32') 226 return 227 endif 228 229 " uses sed to number non-empty lines 230 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh') 231 call system('chmod +x ./Xsed_format.sh') 232 let text = ['a', '', 'c', '', ' ', 'd', 'e'] 233 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e'] 234 235 10new 236 call setline(1, text) 237 set formatprg=./Xsed_format.sh 238 norm! gggqG 239 call assert_equal(expected, getline(1, '$')) 240 bw! 241 242 10new 243 call setline(1, text) 244 set formatprg=donothing 245 setlocal formatprg=./Xsed_format.sh 246 norm! gggqG 247 call assert_equal(expected, getline(1, '$')) 248 bw! 249 250 " clean up 251 set formatprg= 252 setlocal formatprg= 253 call delete('Xsed_format.sh') 254endfunc 255 256func! Test_normal07_internalfmt() 257 " basic test for internal formmatter to textwidth of 12 258 let list=range(1,11) 259 call map(list, 'v:val." "') 260 10new 261 call setline(1, list) 262 set tw=12 263 norm! gggqG 264 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$')) 265 " clean up 266 set tw=0 267 bw! 268endfunc 269 270func! Test_normal08_fold() 271 " basic tests for foldopen/folddelete 272 if !has("folding") 273 return 274 endif 275 call Setup_NewWindow() 276 50 277 setl foldenable fdm=marker 278 " First fold 279 norm! V4jzf 280 " check that folds have been created 281 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54)) 282 " Second fold 283 46 284 norm! V10jzf 285 " check that folds have been created 286 call assert_equal('46/*{{{*/', getline(46)) 287 call assert_equal('60/*}}}*/', getline(60)) 288 norm! k 289 call assert_equal('45', getline('.')) 290 norm! j 291 call assert_equal('46/*{{{*/', getline('.')) 292 norm! j 293 call assert_equal('61', getline('.')) 294 norm! k 295 " open a fold 296 norm! Vzo 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('47', getline('.')) 303 norm! k 304 norm! zcVzO 305 call assert_equal('46/*{{{*/', getline('.')) 306 norm! j 307 call assert_equal('47', getline('.')) 308 norm! j 309 call assert_equal('48', getline('.')) 310 norm! j 311 call assert_equal('49', getline('.')) 312 norm! j 313 call assert_equal('50/*{{{*/', getline('.')) 314 norm! j 315 call assert_equal('51', getline('.')) 316 " delete folds 317 :46 318 " collapse fold 319 norm! V14jzC 320 " delete all folds recursively 321 norm! VzD 322 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60)) 323 324 " clean up 325 setl nofoldenable fdm=marker 326 bw! 327endfunc 328 329func! Test_normal09_operatorfunc() 330 " Test operatorfunc 331 call Setup_NewWindow() 332 " Add some spaces for counting 333 50,60s/$/ / 334 unlet! g:a 335 let g:a=0 336 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@ 337 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR> 338 50 339 norm V2j,, 340 call assert_equal(6, g:a) 341 norm V,, 342 call assert_equal(2, g:a) 343 norm ,,l 344 call assert_equal(0, g:a) 345 50 346 exe "norm 0\<c-v>10j2l,," 347 call assert_equal(11, g:a) 348 50 349 norm V10j,, 350 call assert_equal(22, g:a) 351 352 " clean up 353 unmap <buffer> ,, 354 set opfunc= 355 unlet! g:a 356 bw! 357endfunc 358 359func! Test_normal09a_operatorfunc() 360 " Test operatorfunc 361 call Setup_NewWindow() 362 " Add some spaces for counting 363 50,60s/$/ / 364 unlet! g:opt 365 set linebreak 366 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@ 367 50 368 norm ,,j 369 exe "bd!" g:bufnr 370 call assert_true(&linebreak) 371 call assert_equal(g:opt, &linebreak) 372 set nolinebreak 373 norm ,,j 374 exe "bd!" g:bufnr 375 call assert_false(&linebreak) 376 call assert_equal(g:opt, &linebreak) 377 378 " clean up 379 unmap <buffer> ,, 380 set opfunc= 381 bw! 382 unlet! g:opt 383endfunc 384 385func! Test_normal10_expand() 386 " Test for expand() 387 10new 388 call setline(1, ['1', 'ifooar,,cbar']) 389 2 390 norm! $ 391 call assert_equal('cbar', expand('<cword>')) 392 call assert_equal('ifooar,,cbar', expand('<cWORD>')) 393 394 call setline(1, ['prx = list[idx];']) 395 1 396 let expected = ['', 'prx', 'prx', 'prx', 397 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list', 398 \ 'idx', 'idx', 'idx', 'idx', 399 \ 'list[idx]', 400 \ '];', 401 \ ] 402 for i in range(1, 16) 403 exe 'norm ' . i . '|' 404 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i) 405 endfor 406 407 " clean up 408 bw! 409endfunc 410 411func! Test_normal11_showcmd() 412 " test for 'showcmd' 413 10new 414 exe "norm! ofoobar\<esc>" 415 call assert_equal(2, line('$')) 416 set showcmd 417 exe "norm! ofoobar2\<esc>" 418 call assert_equal(3, line('$')) 419 exe "norm! VAfoobar3\<esc>" 420 call assert_equal(3, line('$')) 421 exe "norm! 0d3\<del>2l" 422 call assert_equal('obar2foobar3', getline('.')) 423 bw! 424endfunc 425 426func! Test_normal12_nv_error() 427 " Test for nv_error 428 10new 429 call setline(1, range(1,5)) 430 " should not do anything, just beep 431 exe "norm! <c-k>" 432 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$')) 433 bw! 434endfunc 435 436func! Test_normal13_help() 437 " Test for F1 438 call assert_equal(1, winnr()) 439 call feedkeys("\<f1>", 'txi') 440 call assert_match('help\.txt', bufname('%')) 441 call assert_equal(2, winnr('$')) 442 bw! 443endfunc 444 445func! Test_normal14_page() 446 " basic test for Ctrl-F and Ctrl-B 447 call Setup_NewWindow() 448 exe "norm! \<c-f>" 449 call assert_equal('9', getline('.')) 450 exe "norm! 2\<c-f>" 451 call assert_equal('25', getline('.')) 452 exe "norm! 2\<c-b>" 453 call assert_equal('18', getline('.')) 454 1 455 set scrolloff=5 456 exe "norm! 2\<c-f>" 457 call assert_equal('21', getline('.')) 458 exe "norm! \<c-b>" 459 call assert_equal('13', getline('.')) 460 1 461 set scrolloff=99 462 exe "norm! \<c-f>" 463 call assert_equal('13', getline('.')) 464 set scrolloff=0 465 100 466 exe "norm! $\<c-b>" 467 call assert_equal('92', getline('.')) 468 call assert_equal([0, 92, 1, 0, 1], getcurpos()) 469 100 470 set nostartofline 471 exe "norm! $\<c-b>" 472 call assert_equal('92', getline('.')) 473 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos()) 474 " cleanup 475 set startofline 476 bw! 477endfunc 478 479func! Test_normal14_page_eol() 480 10new 481 norm oxxxxxxx 482 exe "norm 2\<c-f>" 483 " check with valgrind that cursor is put back in column 1 484 exe "norm 2\<c-b>" 485 bw! 486endfunc 487 488func! Test_normal15_z_scroll_vert() 489 " basic test for z commands that scroll the window 490 call Setup_NewWindow() 491 100 492 norm! >> 493 " Test for z<cr> 494 exe "norm! z\<cr>" 495 call assert_equal(' 100', getline('.')) 496 call assert_equal(100, winsaveview()['topline']) 497 call assert_equal([0, 100, 2, 0, 9], getcurpos()) 498 499 " Test for zt 500 21 501 norm! >>0zt 502 call assert_equal(' 21', getline('.')) 503 call assert_equal(21, winsaveview()['topline']) 504 call assert_equal([0, 21, 1, 0, 8], getcurpos()) 505 506 " Test for zb 507 30 508 norm! >>$ztzb 509 call assert_equal(' 30', getline('.')) 510 call assert_equal(30, winsaveview()['topline']+winheight(0)-1) 511 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos()) 512 513 " Test for z- 514 1 515 30 516 norm! 0z- 517 call assert_equal(' 30', getline('.')) 518 call assert_equal(30, winsaveview()['topline']+winheight(0)-1) 519 call assert_equal([0, 30, 2, 0, 9], getcurpos()) 520 521 " Test for z{height}<cr> 522 call assert_equal(10, winheight(0)) 523 exe "norm! z12\<cr>" 524 call assert_equal(12, winheight(0)) 525 exe "norm! z10\<cr>" 526 call assert_equal(10, winheight(0)) 527 528 " Test for z. 529 1 530 21 531 norm! 0z. 532 call assert_equal(' 21', getline('.')) 533 call assert_equal(17, winsaveview()['topline']) 534 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 535 536 " Test for zz 537 1 538 21 539 norm! 0zz 540 call assert_equal(' 21', getline('.')) 541 call assert_equal(17, winsaveview()['topline']) 542 call assert_equal([0, 21, 1, 0, 8], getcurpos()) 543 544 " Test for z+ 545 11 546 norm! zt 547 norm! z+ 548 call assert_equal(' 21', getline('.')) 549 call assert_equal(21, winsaveview()['topline']) 550 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 551 552 " Test for [count]z+ 553 1 554 norm! 21z+ 555 call assert_equal(' 21', getline('.')) 556 call assert_equal(21, winsaveview()['topline']) 557 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 558 559 " Test for z^ 560 norm! 22z+0 561 norm! z^ 562 call assert_equal(' 21', getline('.')) 563 call assert_equal(12, winsaveview()['topline']) 564 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 565 566 " Test for [count]z^ 567 1 568 norm! 30z^ 569 call assert_equal(' 21', getline('.')) 570 call assert_equal(12, winsaveview()['topline']) 571 call assert_equal([0, 21, 2, 0, 9], getcurpos()) 572 573 " cleanup 574 bw! 575endfunc 576 577func! Test_normal16_z_scroll_hor() 578 " basic test for z commands that scroll the window 579 10new 580 15vsp 581 set nowrap listchars= 582 let lineA='abcdefghijklmnopqrstuvwxyz' 583 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 584 $put =lineA 585 $put =lineB 586 1d 587 588 " Test for zl 589 1 590 norm! 5zl 591 call assert_equal(lineA, getline('.')) 592 call assert_equal(6, col('.')) 593 call assert_equal(5, winsaveview()['leftcol']) 594 norm! yl 595 call assert_equal('f', @0) 596 597 " Test for zh 598 norm! 2zh 599 call assert_equal(lineA, getline('.')) 600 call assert_equal(6, col('.')) 601 norm! yl 602 call assert_equal('f', @0) 603 call assert_equal(3, winsaveview()['leftcol']) 604 605 " Test for zL 606 norm! zL 607 call assert_equal(11, col('.')) 608 norm! yl 609 call assert_equal('k', @0) 610 call assert_equal(10, winsaveview()['leftcol']) 611 norm! 2zL 612 call assert_equal(25, col('.')) 613 norm! yl 614 call assert_equal('y', @0) 615 call assert_equal(24, winsaveview()['leftcol']) 616 617 " Test for zH 618 norm! 2zH 619 call assert_equal(25, col('.')) 620 call assert_equal(10, winsaveview()['leftcol']) 621 norm! yl 622 call assert_equal('y', @0) 623 624 " Test for zs 625 norm! $zs 626 call assert_equal(26, col('.')) 627 call assert_equal(25, winsaveview()['leftcol']) 628 norm! yl 629 call assert_equal('z', @0) 630 631 " Test for ze 632 norm! ze 633 call assert_equal(26, col('.')) 634 call assert_equal(11, winsaveview()['leftcol']) 635 norm! yl 636 call assert_equal('z', @0) 637 638 " cleanup 639 set wrap listchars=eol:$ 640 bw! 641endfunc 642 643func! Test_normal17_z_scroll_hor2() 644 " basic test for z commands that scroll the window 645 " using 'sidescrolloff' setting 646 10new 647 20vsp 648 set nowrap listchars= sidescrolloff=5 649 let lineA='abcdefghijklmnopqrstuvwxyz' 650 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 651 $put =lineA 652 $put =lineB 653 1d 654 655 " Test for zl 656 1 657 norm! 5zl 658 call assert_equal(lineA, getline('.')) 659 call assert_equal(11, col('.')) 660 call assert_equal(5, winsaveview()['leftcol']) 661 norm! yl 662 call assert_equal('k', @0) 663 664 " Test for zh 665 norm! 2zh 666 call assert_equal(lineA, getline('.')) 667 call assert_equal(11, col('.')) 668 norm! yl 669 call assert_equal('k', @0) 670 call assert_equal(3, winsaveview()['leftcol']) 671 672 " Test for zL 673 norm! 0zL 674 call assert_equal(16, col('.')) 675 norm! yl 676 call assert_equal('p', @0) 677 call assert_equal(10, winsaveview()['leftcol']) 678 norm! 2zL 679 call assert_equal(26, col('.')) 680 norm! yl 681 call assert_equal('z', @0) 682 call assert_equal(15, winsaveview()['leftcol']) 683 684 " Test for zH 685 norm! 2zH 686 call assert_equal(15, col('.')) 687 call assert_equal(0, winsaveview()['leftcol']) 688 norm! yl 689 call assert_equal('o', @0) 690 691 " Test for zs 692 norm! $zs 693 call assert_equal(26, col('.')) 694 call assert_equal(20, winsaveview()['leftcol']) 695 norm! yl 696 call assert_equal('z', @0) 697 698 " Test for ze 699 norm! ze 700 call assert_equal(26, col('.')) 701 call assert_equal(11, winsaveview()['leftcol']) 702 norm! yl 703 call assert_equal('z', @0) 704 705 " cleanup 706 set wrap listchars=eol:$ sidescrolloff=0 707 bw! 708endfunc 709 710func! Test_normal18_z_fold() 711 " basic tests for foldopen/folddelete 712 if !has("folding") 713 return 714 endif 715 call Setup_NewWindow() 716 50 717 setl foldenable fdm=marker foldlevel=5 718 719 " Test for zF 720 " First fold 721 norm! 4zF 722 " check that folds have been created 723 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53)) 724 725 " Test for zd 726 51 727 norm! 2zF 728 call assert_equal(2, foldlevel('.')) 729 norm! kzd 730 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53)) 731 norm! j 732 call assert_equal(1, foldlevel('.')) 733 734 " Test for zD 735 " also deletes partially selected folds recursively 736 51 737 norm! zF 738 call assert_equal(2, foldlevel('.')) 739 norm! kV2jzD 740 call assert_equal(['50', '51', '52', '53'], getline(50,53)) 741 742 " Test for zE 743 85 744 norm! 4zF 745 86 746 norm! 2zF 747 90 748 norm! 4zF 749 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93)) 750 norm! zE 751 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93)) 752 753 " Test for zn 754 50 755 set foldlevel=0 756 norm! 2zF 757 norm! zn 758 norm! k 759 call assert_equal('49', getline('.')) 760 norm! j 761 call assert_equal('50/*{{{*/', getline('.')) 762 norm! j 763 call assert_equal('51/*}}}*/', getline('.')) 764 norm! j 765 call assert_equal('52', getline('.')) 766 call assert_equal(0, &foldenable) 767 768 " Test for zN 769 49 770 norm! zN 771 call assert_equal('49', getline('.')) 772 norm! j 773 call assert_equal('50/*{{{*/', getline('.')) 774 norm! j 775 call assert_equal('52', getline('.')) 776 call assert_equal(1, &foldenable) 777 778 " Test for zi 779 norm! zi 780 call assert_equal(0, &foldenable) 781 norm! zi 782 call assert_equal(1, &foldenable) 783 norm! zi 784 call assert_equal(0, &foldenable) 785 norm! zi 786 call assert_equal(1, &foldenable) 787 788 " Test for za 789 50 790 norm! za 791 norm! k 792 call assert_equal('49', getline('.')) 793 norm! j 794 call assert_equal('50/*{{{*/', getline('.')) 795 norm! j 796 call assert_equal('51/*}}}*/', getline('.')) 797 norm! j 798 call assert_equal('52', getline('.')) 799 50 800 norm! za 801 norm! k 802 call assert_equal('49', getline('.')) 803 norm! j 804 call assert_equal('50/*{{{*/', getline('.')) 805 norm! j 806 call assert_equal('52', getline('.')) 807 808 49 809 norm! 5zF 810 norm! k 811 call assert_equal('48', getline('.')) 812 norm! j 813 call assert_equal('49/*{{{*/', getline('.')) 814 norm! j 815 call assert_equal('55', getline('.')) 816 49 817 norm! za 818 call assert_equal('49/*{{{*/', getline('.')) 819 norm! j 820 call assert_equal('50/*{{{*/', getline('.')) 821 norm! j 822 call assert_equal('52', getline('.')) 823 set nofoldenable 824 " close fold and set foldenable 825 norm! za 826 call assert_equal(1, &foldenable) 827 828 50 829 " have to use {count}za to open all folds and make the cursor visible 830 norm! 2za 831 norm! 2k 832 call assert_equal('48', getline('.')) 833 norm! j 834 call assert_equal('49/*{{{*/', getline('.')) 835 norm! j 836 call assert_equal('50/*{{{*/', getline('.')) 837 norm! j 838 call assert_equal('51/*}}}*/', getline('.')) 839 norm! j 840 call assert_equal('52', getline('.')) 841 842 " Test for zA 843 49 844 set foldlevel=0 845 50 846 norm! zA 847 norm! 2k 848 call assert_equal('48', getline('.')) 849 norm! j 850 call assert_equal('49/*{{{*/', getline('.')) 851 norm! j 852 call assert_equal('50/*{{{*/', getline('.')) 853 norm! j 854 call assert_equal('51/*}}}*/', getline('.')) 855 norm! j 856 call assert_equal('52', getline('.')) 857 858 " zA on a opened fold when foldenable is not set 859 50 860 set nofoldenable 861 norm! zA 862 call assert_equal(1, &foldenable) 863 norm! k 864 call assert_equal('48', getline('.')) 865 norm! j 866 call assert_equal('49/*{{{*/', getline('.')) 867 norm! j 868 call assert_equal('55', getline('.')) 869 870 " Test for zc 871 norm! zE 872 50 873 norm! 2zF 874 49 875 norm! 5zF 876 set nofoldenable 877 50 878 " There most likely is a bug somewhere: 879 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ 880 " TODO: Should this only close the inner most fold or both folds? 881 norm! zc 882 call assert_equal(1, &foldenable) 883 norm! k 884 call assert_equal('48', getline('.')) 885 norm! j 886 call assert_equal('49/*{{{*/', getline('.')) 887 norm! j 888 call assert_equal('55', getline('.')) 889 set nofoldenable 890 50 891 norm! Vjzc 892 norm! k 893 call assert_equal('48', getline('.')) 894 norm! j 895 call assert_equal('49/*{{{*/', getline('.')) 896 norm! j 897 call assert_equal('55', getline('.')) 898 899 " Test for zC 900 set nofoldenable 901 50 902 norm! zCk 903 call assert_equal('48', getline('.')) 904 norm! j 905 call assert_equal('49/*{{{*/', getline('.')) 906 norm! j 907 call assert_equal('55', getline('.')) 908 909 " Test for zx 910 " 1) close folds at line 49-54 911 set nofoldenable 912 48 913 norm! zx 914 call assert_equal(1, &foldenable) 915 norm! j 916 call assert_equal('49/*{{{*/', getline('.')) 917 norm! j 918 call assert_equal('55', getline('.')) 919 920 " 2) do not close fold under cursor 921 51 922 set nofoldenable 923 norm! zx 924 call assert_equal(1, &foldenable) 925 norm! 3k 926 call assert_equal('48', getline('.')) 927 norm! j 928 call assert_equal('49/*{{{*/', getline('.')) 929 norm! j 930 call assert_equal('50/*{{{*/', getline('.')) 931 norm! j 932 call assert_equal('51/*}}}*/', getline('.')) 933 norm! j 934 call assert_equal('52', getline('.')) 935 norm! j 936 call assert_equal('53', getline('.')) 937 norm! j 938 call assert_equal('54/*}}}*/', getline('.')) 939 norm! j 940 call assert_equal('55', getline('.')) 941 942 " 3) close one level of folds 943 48 944 set nofoldenable 945 set foldlevel=1 946 norm! zx 947 call assert_equal(1, &foldenable) 948 call assert_equal('48', getline('.')) 949 norm! j 950 call assert_equal('49/*{{{*/', getline('.')) 951 norm! j 952 call assert_equal('50/*{{{*/', getline('.')) 953 norm! j 954 call assert_equal('52', getline('.')) 955 norm! j 956 call assert_equal('53', getline('.')) 957 norm! j 958 call assert_equal('54/*}}}*/', getline('.')) 959 norm! j 960 call assert_equal('55', getline('.')) 961 962 " Test for zX 963 " Close all folds 964 set foldlevel=0 nofoldenable 965 50 966 norm! zX 967 call assert_equal(1, &foldenable) 968 norm! k 969 call assert_equal('48', getline('.')) 970 norm! j 971 call assert_equal('49/*{{{*/', getline('.')) 972 norm! j 973 call assert_equal('55', getline('.')) 974 975 " Test for zm 976 50 977 set nofoldenable foldlevel=2 978 norm! zm 979 call assert_equal(1, &foldenable) 980 call assert_equal(1, &foldlevel) 981 norm! zm 982 call assert_equal(0, &foldlevel) 983 norm! zm 984 call assert_equal(0, &foldlevel) 985 norm! k 986 call assert_equal('48', getline('.')) 987 norm! j 988 call assert_equal('49/*{{{*/', getline('.')) 989 norm! j 990 call assert_equal('55', getline('.')) 991 992 " Test for zM 993 48 994 set nofoldenable foldlevel=99 995 norm! zM 996 call assert_equal(1, &foldenable) 997 call assert_equal(0, &foldlevel) 998 call assert_equal('48', getline('.')) 999 norm! j 1000 call assert_equal('49/*{{{*/', getline('.')) 1001 norm! j 1002 call assert_equal('55', getline('.')) 1003 1004 " Test for zr 1005 48 1006 set nofoldenable foldlevel=0 1007 norm! zr 1008 call assert_equal(0, &foldenable) 1009 call assert_equal(1, &foldlevel) 1010 set foldlevel=0 foldenable 1011 norm! zr 1012 call assert_equal(1, &foldenable) 1013 call assert_equal(1, &foldlevel) 1014 norm! zr 1015 call assert_equal(2, &foldlevel) 1016 call assert_equal('48', getline('.')) 1017 norm! j 1018 call assert_equal('49/*{{{*/', getline('.')) 1019 norm! j 1020 call assert_equal('50/*{{{*/', getline('.')) 1021 norm! j 1022 call assert_equal('51/*}}}*/', getline('.')) 1023 norm! j 1024 call assert_equal('52', getline('.')) 1025 1026 " Test for zR 1027 48 1028 set nofoldenable foldlevel=0 1029 norm! zR 1030 call assert_equal(0, &foldenable) 1031 call assert_equal(2, &foldlevel) 1032 set foldenable foldlevel=0 1033 norm! zR 1034 call assert_equal(1, &foldenable) 1035 call assert_equal(2, &foldlevel) 1036 call assert_equal('48', getline('.')) 1037 norm! j 1038 call assert_equal('49/*{{{*/', getline('.')) 1039 norm! j 1040 call assert_equal('50/*{{{*/', getline('.')) 1041 norm! j 1042 call assert_equal('51/*}}}*/', getline('.')) 1043 norm! j 1044 call assert_equal('52', getline('.')) 1045 call append(50, ['a /*{{{*/', 'b /*}}}*/']) 1046 48 1047 call assert_equal('48', getline('.')) 1048 norm! j 1049 call assert_equal('49/*{{{*/', getline('.')) 1050 norm! j 1051 call assert_equal('50/*{{{*/', getline('.')) 1052 norm! j 1053 call assert_equal('a /*{{{*/', getline('.')) 1054 norm! j 1055 call assert_equal('51/*}}}*/', getline('.')) 1056 norm! j 1057 call assert_equal('52', getline('.')) 1058 48 1059 norm! zR 1060 call assert_equal(1, &foldenable) 1061 call assert_equal(3, &foldlevel) 1062 call assert_equal('48', getline('.')) 1063 norm! j 1064 call assert_equal('49/*{{{*/', getline('.')) 1065 norm! j 1066 call assert_equal('50/*{{{*/', getline('.')) 1067 norm! j 1068 call assert_equal('a /*{{{*/', getline('.')) 1069 norm! j 1070 call assert_equal('b /*}}}*/', getline('.')) 1071 norm! j 1072 call assert_equal('51/*}}}*/', getline('.')) 1073 norm! j 1074 call assert_equal('52', getline('.')) 1075 1076 " clean up 1077 setl nofoldenable fdm=marker foldlevel=0 1078 bw! 1079endfunc 1080 1081func! Test_normal19_z_spell() 1082 if !has("spell") || !has('syntax') 1083 return 1084 endif 1085 new 1086 call append(0, ['1 good', '2 goood', '3 goood']) 1087 set spell spellfile=./Xspellfile.add spelllang=en 1088 let oldlang=v:lang 1089 lang C 1090 1091 " Test for zg 1092 1 1093 norm! ]s 1094 call assert_equal('2 goood', getline('.')) 1095 norm! zg 1096 1 1097 let a=execute('unsilent :norm! ]s') 1098 call assert_equal('1 good', getline('.')) 1099 call assert_equal('search hit BOTTOM, continuing at TOP', a[1:]) 1100 let cnt=readfile('./Xspellfile.add') 1101 call assert_equal('goood', cnt[0]) 1102 1103 " Test for zw 1104 2 1105 norm! $zw 1106 1 1107 norm! ]s 1108 call assert_equal('2 goood', getline('.')) 1109 let cnt=readfile('./Xspellfile.add') 1110 call assert_equal('#oood', cnt[0]) 1111 call assert_equal('goood/!', cnt[1]) 1112 1113 " Test for zg in visual mode 1114 let a=execute('unsilent :norm! V$zg') 1115 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) 1116 1 1117 norm! ]s 1118 call assert_equal('3 goood', getline('.')) 1119 let cnt=readfile('./Xspellfile.add') 1120 call assert_equal('2 goood', cnt[2]) 1121 " Remove "2 good" from spellfile 1122 2 1123 let a=execute('unsilent norm! V$zw') 1124 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) 1125 let cnt=readfile('./Xspellfile.add') 1126 call assert_equal('2 goood/!', cnt[3]) 1127 1128 " Test for zG 1129 let a=execute('unsilent norm! V$zG') 1130 call assert_match("Word '2 goood' added to .*", a) 1131 let fname=matchstr(a, 'to\s\+\zs\f\+$') 1132 let cnt=readfile(fname) 1133 call assert_equal('2 goood', cnt[0]) 1134 1135 " Test for zW 1136 let a=execute('unsilent norm! V$zW') 1137 call assert_match("Word '2 goood' added to .*", a) 1138 let cnt=readfile(fname) 1139 call assert_equal('# goood', cnt[0]) 1140 call assert_equal('2 goood/!', cnt[1]) 1141 1142 " Test for zuW 1143 let a=execute('unsilent norm! V$zuW') 1144 call assert_match("Word '2 goood' removed from .*", a) 1145 let cnt=readfile(fname) 1146 call assert_equal('# goood', cnt[0]) 1147 call assert_equal('# goood/!', cnt[1]) 1148 1149 " Test for zuG 1150 let a=execute('unsilent norm! $zG') 1151 call assert_match("Word 'goood' added to .*", a) 1152 let cnt=readfile(fname) 1153 call assert_equal('# goood', cnt[0]) 1154 call assert_equal('# goood/!', cnt[1]) 1155 call assert_equal('goood', cnt[2]) 1156 let a=execute('unsilent norm! $zuG') 1157 let cnt=readfile(fname) 1158 call assert_match("Word 'goood' removed from .*", a) 1159 call assert_equal('# goood', cnt[0]) 1160 call assert_equal('# goood/!', cnt[1]) 1161 call assert_equal('#oood', cnt[2]) 1162 " word not found in wordlist 1163 let a=execute('unsilent norm! V$zuG') 1164 let cnt=readfile(fname) 1165 call assert_match("", a) 1166 call assert_equal('# goood', cnt[0]) 1167 call assert_equal('# goood/!', cnt[1]) 1168 call assert_equal('#oood', cnt[2]) 1169 1170 " Test for zug 1171 call delete('./Xspellfile.add') 1172 2 1173 let a=execute('unsilent norm! $zg') 1174 let cnt=readfile('./Xspellfile.add') 1175 call assert_equal('goood', cnt[0]) 1176 let a=execute('unsilent norm! $zug') 1177 call assert_match("Word 'goood' removed from \./Xspellfile.add", a) 1178 let cnt=readfile('./Xspellfile.add') 1179 call assert_equal('#oood', cnt[0]) 1180 " word not in wordlist 1181 let a=execute('unsilent norm! V$zug') 1182 call assert_match('', a) 1183 let cnt=readfile('./Xspellfile.add') 1184 call assert_equal('#oood', cnt[0]) 1185 1186 " Test for zuw 1187 call delete('./Xspellfile.add') 1188 2 1189 let a=execute('unsilent norm! Vzw') 1190 let cnt=readfile('./Xspellfile.add') 1191 call assert_equal('2 goood/!', cnt[0]) 1192 let a=execute('unsilent norm! Vzuw') 1193 call assert_match("Word '2 goood' removed from \./Xspellfile.add", a) 1194 let cnt=readfile('./Xspellfile.add') 1195 call assert_equal('# goood/!', cnt[0]) 1196 " word not in wordlist 1197 let a=execute('unsilent norm! $zug') 1198 call assert_match('', a) 1199 let cnt=readfile('./Xspellfile.add') 1200 call assert_equal('# goood/!', cnt[0]) 1201 1202 " add second entry to spellfile setting 1203 set spellfile=./Xspellfile.add,./Xspellfile2.add 1204 call delete('./Xspellfile.add') 1205 2 1206 let a=execute('unsilent norm! $2zg') 1207 let cnt=readfile('./Xspellfile2.add') 1208 call assert_match("Word 'goood' added to ./Xspellfile2.add", a) 1209 call assert_equal('goood', cnt[0]) 1210 1211 " Test for :spellgood! 1212 let temp = execute(':spe!0/0') 1213 call assert_match('Invalid region', temp) 1214 let spellfile = matchstr(temp, 'Invalid region nr in \zs.*\ze line \d: 0') 1215 call assert_equal(['# goood', '# goood/!', '#oood', '0/0'], readfile(spellfile)) 1216 call delete(spellfile) 1217 1218 " clean up 1219 exe "lang" oldlang 1220 call delete("./Xspellfile.add") 1221 call delete("./Xspellfile2.add") 1222 call delete("./Xspellfile.add.spl") 1223 call delete("./Xspellfile2.add.spl") 1224 1225 " zux -> no-op 1226 2 1227 norm! $zux 1228 call assert_equal([], glob('Xspellfile.add',0,1)) 1229 call assert_equal([], glob('Xspellfile2.add',0,1)) 1230 1231 set spellfile= 1232 bw! 1233endfunc 1234 1235func! Test_normal20_exmode() 1236 if !has("unix") 1237 " Reading from redirected file doesn't work on MS-Windows 1238 return 1239 endif 1240 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') 1241 call writefile(['1', '2'], 'Xfile') 1242 call system(v:progpath .' -e -s < Xscript Xfile') 1243 let a=readfile('Xfile2') 1244 call assert_equal(['1', 'foo', 'bar', '2'], a) 1245 1246 " clean up 1247 for file in ['Xfile', 'Xfile2', 'Xscript'] 1248 call delete(file) 1249 endfor 1250 bw! 1251endfunc 1252 1253func! Test_normal21_nv_hat() 1254 set hidden 1255 new 1256 " to many buffers opened already, will not work 1257 "call assert_fails(":b#", 'E23') 1258 "call assert_equal('', @#) 1259 e Xfoobar 1260 e Xfile2 1261 call feedkeys("\<c-^>", 't') 1262 call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) 1263 call feedkeys("f\<c-^>", 't') 1264 call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) 1265 " clean up 1266 set nohidden 1267 bw! 1268endfunc 1269 1270func! Test_normal22_zet() 1271 " Test for ZZ 1272 " let shell = &shell 1273 " let &shell = 'sh' 1274 call writefile(['1', '2'], 'Xfile') 1275 let args = ' -u NONE -N -U NONE -i NONE --noplugins -X --not-a-term' 1276 call system(v:progpath . args . ' -c "%d" -c ":norm! ZZ" Xfile') 1277 let a = readfile('Xfile') 1278 call assert_equal([], a) 1279 " Test for ZQ 1280 call writefile(['1', '2'], 'Xfile') 1281 call system(v:progpath . args . ' -c "%d" -c ":norm! ZQ" Xfile') 1282 let a = readfile('Xfile') 1283 call assert_equal(['1', '2'], a) 1284 1285 " clean up 1286 for file in ['Xfile'] 1287 call delete(file) 1288 endfor 1289 " let &shell = shell 1290endfunc 1291 1292func! Test_normal23_K() 1293 " Test for K command 1294 new 1295 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd']) 1296 let k = &keywordprg 1297 set keywordprg=:help 1298 1 1299 norm! VK 1300 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) 1301 call assert_equal('help', &ft) 1302 call assert_match('\*version8.txt\*', getline('.')) 1303 helpclose 1304 norm! 0K 1305 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) 1306 call assert_equal('help', &ft) 1307 call assert_match('\*version8\.0\*', getline('.')) 1308 helpclose 1309 1310 set keywordprg=:new 1311 set iskeyword+=% 1312 set iskeyword+=\| 1313 2 1314 norm! K 1315 call assert_equal('man', fnamemodify(bufname('%'), ':t')) 1316 bwipe! 1317 3 1318 norm! K 1319 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t')) 1320 bwipe! 1321 if !has('win32') 1322 4 1323 norm! K 1324 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t')) 1325 bwipe! 1326 endif 1327 set iskeyword-=% 1328 set iskeyword-=\| 1329 1330 " Only expect "man" to work on Unix 1331 if !has("unix") 1332 let &keywordprg = k 1333 bw! 1334 return 1335 endif 1336 set keywordprg=man\ --pager=cat 1337 " Test for using man 1338 2 1339 let a = execute('unsilent norm! K') 1340 call assert_match("man --pager=cat 'man'", a) 1341 1342 " clean up 1343 let &keywordprg = k 1344 bw! 1345endfunc 1346 1347func! Test_normal24_rot13() 1348 " This test uses multi byte characters 1349 if !has("multi_byte") 1350 return 1351 endif 1352 " Testing for g?? g?g? 1353 new 1354 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') 1355 1 1356 norm! g?? 1357 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.')) 1358 norm! g?g? 1359 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.')) 1360 1361 " clean up 1362 bw! 1363endfunc 1364 1365func! Test_normal25_tag() 1366 " Testing for CTRL-] g CTRL-] g] 1367 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] 1368 h 1369 " Test for CTRL-] 1370 call search('\<x\>$') 1371 exe "norm! \<c-]>" 1372 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) 1373 norm! yiW 1374 call assert_equal("*x*", @0) 1375 exe ":norm \<c-o>" 1376 1377 " Test for g_CTRL-] 1378 call search('\<v_u\>$') 1379 exe "norm! g\<c-]>" 1380 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) 1381 norm! yiW 1382 call assert_equal("*v_u*", @0) 1383 exe ":norm \<c-o>" 1384 1385 " Test for g] 1386 call search('\<i_<Esc>$') 1387 let a = execute(":norm! g]") 1388 call assert_match('i_<Esc>.*insert.txt', a) 1389 1390 if !empty(exepath('cscope')) && has('cscope') 1391 " setting cscopetag changes how g] works 1392 set cst 1393 exe "norm! g]" 1394 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1395 norm! yiW 1396 call assert_equal("*i_<Esc>*", @0) 1397 exe ":norm \<c-o>" 1398 " Test for CTRL-W g] 1399 exe "norm! \<C-W>g]" 1400 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1401 norm! yiW 1402 call assert_equal("*i_<Esc>*", @0) 1403 call assert_equal(3, winnr('$')) 1404 helpclose 1405 set nocst 1406 endif 1407 1408 " Test for CTRL-W g] 1409 let a = execute("norm! \<C-W>g]") 1410 call assert_match('i_<Esc>.*insert.txt', a) 1411 1412 " Test for CTRL-W CTRL-] 1413 exe "norm! \<C-W>\<C-]>" 1414 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1415 norm! yiW 1416 call assert_equal("*i_<Esc>*", @0) 1417 call assert_equal(3, winnr('$')) 1418 helpclose 1419 1420 " Test for CTRL-W g CTRL-] 1421 exe "norm! \<C-W>g\<C-]>" 1422 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) 1423 norm! yiW 1424 call assert_equal("*i_<Esc>*", @0) 1425 call assert_equal(3, winnr('$')) 1426 helpclose 1427 1428 " clean up 1429 helpclose 1430endfunc 1431 1432func! Test_normal26_put() 1433 " Test for ]p ]P [p and [P 1434 new 1435 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) 1436 1 1437 /Error/y a 1438 2 1439 norm! "a]pj"a[p 1440 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5)) 1441 1 1442 /^\s\{4}/ 1443 exe "norm! \"a]P3Eldt'" 1444 exe "norm! j\"a[P2Eldt'" 1445 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10)) 1446 1447 " clean up 1448 bw! 1449endfunc 1450 1451func! Test_normal27_bracket() 1452 " Test for [' [` ]' ]` 1453 call Setup_NewWindow() 1454 1,21s/.\+/ & b/ 1455 1 1456 norm! $ma 1457 5 1458 norm! $mb 1459 10 1460 norm! $mc 1461 15 1462 norm! $md 1463 20 1464 norm! $me 1465 1466 " Test for [' 1467 9 1468 norm! 2[' 1469 call assert_equal(' 1 b', getline('.')) 1470 call assert_equal(1, line('.')) 1471 call assert_equal(3, col('.')) 1472 1473 " Test for ]' 1474 norm! ]' 1475 call assert_equal(' 5 b', getline('.')) 1476 call assert_equal(5, line('.')) 1477 call assert_equal(3, col('.')) 1478 1479 " No mark after line 21, cursor moves to first non blank on current line 1480 21 1481 norm! $]' 1482 call assert_equal(' 21 b', getline('.')) 1483 call assert_equal(21, line('.')) 1484 call assert_equal(3, col('.')) 1485 1486 " Test for [` 1487 norm! 2[` 1488 call assert_equal(' 15 b', getline('.')) 1489 call assert_equal(15, line('.')) 1490 call assert_equal(8, col('.')) 1491 1492 " Test for ]` 1493 norm! ]` 1494 call assert_equal(' 20 b', getline('.')) 1495 call assert_equal(20, line('.')) 1496 call assert_equal(8, col('.')) 1497 1498 " clean up 1499 bw! 1500endfunc 1501 1502func! Test_normal28_parenthesis() 1503 " basic testing for ( and ) 1504 new 1505 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) 1506 1507 $ 1508 norm! d( 1509 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$')) 1510 norm! 2d( 1511 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$')) 1512 1 1513 norm! 0d) 1514 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$')) 1515 1516 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. ']) 1517 $ 1518 norm! $d( 1519 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$')) 1520 1521 " clean up 1522 bw! 1523endfunc 1524 1525fun! Test_normal29_brace() 1526 " basic test for { and } movements 1527 let text= ['A paragraph begins after each empty line, and also at each of a set of', 1528 \ 'paragraph macros, specified by the pairs of characters in the ''paragraphs''', 1529 \ 'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to', 1530 \ 'the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in', 1531 \ 'the first column). A section boundary is also a paragraph boundary.', 1532 \ 'Note that a blank line (only containing white space) is NOT a paragraph', 1533 \ 'boundary.', 1534 \ '', 1535 \ '', 1536 \ 'Also note that this does not include a ''{'' or ''}'' in the first column. When', 1537 \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a', 1538 \ 'paragraph boundary |posix|.', 1539 \ '{', 1540 \ 'This is no paragaraph', 1541 \ 'unless the ''{'' is set', 1542 \ 'in ''cpoptions''', 1543 \ '}', 1544 \ '.IP', 1545 \ 'The nroff macros IP seperates a paragraph', 1546 \ 'That means, it must be a ''.''', 1547 \ 'followed by IP', 1548 \ '.LPIt does not matter, if afterwards some', 1549 \ 'more characters follow.', 1550 \ '.SHAlso section boundaries from the nroff', 1551 \ 'macros terminate a paragraph. That means', 1552 \ 'a character like this:', 1553 \ '.NH', 1554 \ 'End of text here'] 1555 new 1556 call append(0, text) 1557 1 1558 norm! 0d2} 1559 call assert_equal(['.IP', 1560 \ 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 'followed by IP', 1561 \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff', 1562 \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) 1563 norm! 0d} 1564 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', 1565 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 1566 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1, '$')) 1567 $ 1568 norm! d{ 1569 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', 1570 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 'a character like this:', ''], getline(1, '$')) 1571 norm! d{ 1572 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', ''], getline(1,'$')) 1573 " Test with { in cpooptions 1574 %d 1575 call append(0, text) 1576 set cpo+={ 1577 1 1578 norm! 0d2} 1579 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', 1580 \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 1581 \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', 1582 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 1583 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) 1584 $ 1585 norm! d} 1586 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', 1587 \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 1588 \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', 1589 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 1590 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) 1591 norm! gg} 1592 norm! d5} 1593 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) 1594 1595 " clean up 1596 set cpo-={ 1597 bw! 1598endfunc 1599 1600fun! Test_normal30_changecase() 1601 " This test uses multi byte characters 1602 if !has("multi_byte") 1603 return 1604 endif 1605 new 1606 call append(0, 'This is a simple test: äüöß') 1607 norm! 1ggVu 1608 call assert_equal('this is a simple test: äüöß', getline('.')) 1609 norm! VU 1610 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1611 norm! guu 1612 call assert_equal('this is a simple test: äüöss', getline('.')) 1613 norm! gUgU 1614 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1615 norm! gugu 1616 call assert_equal('this is a simple test: äüöss', getline('.')) 1617 norm! gUU 1618 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) 1619 norm! 010~ 1620 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.')) 1621 norm! V~ 1622 call assert_equal('THIS IS A simple test: äüöss', getline('.')) 1623 1624 " Turkish ASCII turns to multi-byte. On Mac the Turkish locale is available 1625 " but toupper()/tolower() don't do the right thing. 1626 if !has('mac') && !has('osx') 1627 try 1628 lang tr_TR.UTF-8 1629 set casemap= 1630 call setline(1, 'iI') 1631 1normal gUU 1632 call assert_equal("\u0130I", getline(1)) 1633 call assert_equal("\u0130I", toupper("iI")) 1634 1635 call setline(1, 'iI') 1636 1normal guu 1637 call assert_equal("i\u0131", getline(1)) 1638 call assert_equal("i\u0131", tolower("iI")) 1639 1640 set casemap& 1641 call setline(1, 'iI') 1642 1normal gUU 1643 call assert_equal("II", getline(1)) 1644 call assert_equal("II", toupper("iI")) 1645 1646 call setline(1, 'iI') 1647 1normal guu 1648 call assert_equal("ii", getline(1)) 1649 call assert_equal("ii", tolower("iI")) 1650 1651 lang en_US.UTF-8 1652 catch /E197:/ 1653 " can't use Turkish locale 1654 throw 'Skipped: Turkish locale not available' 1655 endtry 1656 endif 1657 1658 " clean up 1659 bw! 1660endfunc 1661 1662fun! Test_normal31_r_cmd() 1663 " Test for r command 1664 new 1665 call append(0, 'This is a simple test: abcd') 1666 exe "norm! 1gg$r\<cr>" 1667 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$')) 1668 exe "norm! 1gg2wlr\<cr>" 1669 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$')) 1670 exe "norm! 2gg0W5r\<cr>" 1671 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$')) 1672 set autoindent 1673 call setline(2, ['simple test: abc', '']) 1674 exe "norm! 2gg0W5r\<cr>" 1675 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$')) 1676 exe "norm! 1ggVr\<cr>" 1677 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1))) 1678 call setline(1, 'This is a') 1679 exe "norm! 1gg05rf" 1680 call assert_equal('fffffis a', getline(1)) 1681 1682 " clean up 1683 set noautoindent 1684 bw! 1685endfunc 1686 1687func! Test_normal32_g_cmd1() 1688 " Test for g*, g# 1689 new 1690 call append(0, ['abc.x_foo', 'x_foobar.abc']) 1691 1 1692 norm! $g* 1693 call assert_equal('x_foo', @/) 1694 call assert_equal('x_foobar.abc', getline('.')) 1695 norm! $g# 1696 call assert_equal('abc', @/) 1697 call assert_equal('abc.x_foo', getline('.')) 1698 1699 " clean up 1700 bw! 1701endfunc 1702 1703fun! Test_normal33_g_cmd2() 1704 if !has("jumplist") 1705 return 1706 endif 1707 " Tests for g cmds 1708 call Setup_NewWindow() 1709 " Test for g` 1710 clearjumps 1711 norm! ma10j 1712 let a=execute(':jumps') 1713 " empty jumplist 1714 call assert_equal('>', a[-1:]) 1715 norm! g`a 1716 call assert_equal('>', a[-1:]) 1717 call assert_equal(1, line('.')) 1718 call assert_equal('1', getline('.')) 1719 1720 " Test for g; and g, 1721 norm! g; 1722 " there is only one change in the changelist 1723 " currently, when we setup the window 1724 call assert_equal(2, line('.')) 1725 call assert_fails(':norm! g;', 'E662') 1726 call assert_fails(':norm! g,', 'E663') 1727 let &ul=&ul 1728 call append('$', ['a', 'b', 'c', 'd']) 1729 let &ul=&ul 1730 call append('$', ['Z', 'Y', 'X', 'W']) 1731 let a = execute(':changes') 1732 call assert_match('2\s\+0\s\+2', a) 1733 call assert_match('101\s\+0\s\+a', a) 1734 call assert_match('105\s\+0\s\+Z', a) 1735 norm! 3g; 1736 call assert_equal(2, line('.')) 1737 norm! 2g, 1738 call assert_equal(105, line('.')) 1739 1740 " Test for g& - global substitute 1741 %d 1742 call setline(1, range(1,10)) 1743 call append('$', ['a', 'b', 'c', 'd']) 1744 $s/\w/&&/g 1745 exe "norm! /[1-8]\<cr>" 1746 norm! g& 1747 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$')) 1748 1749 " Test for gv 1750 %d 1751 call append('$', repeat(['abcdefgh'], 8)) 1752 exe "norm! 2gg02l\<c-v>2j2ly" 1753 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1)) 1754 " in visual mode, gv swaps current and last selected region 1755 exe "norm! G0\<c-v>4k4lgvd" 1756 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$')) 1757 exe "norm! G0\<c-v>4k4ly" 1758 exe "norm! gvood" 1759 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) 1760 1761 " Test for gk/gj 1762 %d 1763 15vsp 1764 set wrap listchars= sbr= 1765 let lineA='abcdefghijklmnopqrstuvwxyz' 1766 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 1767 $put =lineA 1768 $put =lineB 1769 1770 norm! 3gg0dgk 1771 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$')) 1772 set nu 1773 norm! 3gg0gjdgj 1774 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1775 1776 " Test for gJ 1777 norm! 2gggJ 1778 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1779 call assert_equal(16, col('.')) 1780 " shouldn't do anything 1781 norm! 10gJ 1782 call assert_equal(1, col('.')) 1783 1784 " Test for g0 g^ gm g$ 1785 exe "norm! 2gg0gji " 1786 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1787 norm! g0yl 1788 call assert_equal(12, col('.')) 1789 call assert_equal(' ', getreg(0)) 1790 norm! g$yl 1791 call assert_equal(22, col('.')) 1792 call assert_equal('3', getreg(0)) 1793 norm! gmyl 1794 call assert_equal(17, col('.')) 1795 call assert_equal('n', getreg(0)) 1796 norm! g^yl 1797 call assert_equal(15, col('.')) 1798 call assert_equal('l', getreg(0)) 1799 1800 " Test for g Ctrl-G 1801 set ff=unix 1802 let a=execute(":norm! g\<c-g>") 1803 call assert_match('Col 15 of 43; Line 2 of 2; Word 2 of 2; Byte 16 of 45', a) 1804 1805 " Test for gI 1806 norm! gIfoo 1807 call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) 1808 1809 " Test for gi 1810 wincmd c 1811 %d 1812 set tw=0 1813 call setline(1, ['foobar', 'new line']) 1814 norm! A next word 1815 $put ='third line' 1816 norm! gi another word 1817 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) 1818 1819 " clean up 1820 bw! 1821endfunc 1822 1823fun! Test_normal34_g_cmd3() 1824 if !has("multi_byte") 1825 return 1826 endif 1827 1828 " Test for g8 1829 new 1830 let a=execute(':norm! 1G0g8') 1831 call assert_equal("\nNUL", a) 1832 1833 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö') 1834 let a=execute(':norm! 1G$g8') 1835 call assert_equal("\nc3 b6 ", a) 1836 1837 call setline(1, "a\u0302") 1838 let a=execute(':norm! 1G0g8') 1839 call assert_equal("\n61 + cc 82 ", a) 1840 1841 " clean up 1842 bw! 1843endfunc 1844 1845func Test_normal_8g8() 1846 if !has("multi_byte") 1847 return 1848 endif 1849 new 1850 1851 " Test 8g8 which finds invalid utf8 at or after the cursor. 1852 1853 " With invalid byte. 1854 call setline(1, "___\xff___") 1855 norm! 1G08g8g 1856 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 1857 1858 " With invalid byte before the cursor. 1859 call setline(1, "___\xff___") 1860 norm! 1G$h8g8g 1861 call assert_equal([0, 1, 6, 0, 9], getcurpos()) 1862 1863 " With truncated sequence. 1864 call setline(1, "___\xE2\x82___") 1865 norm! 1G08g8g 1866 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 1867 1868 " With overlong sequence. 1869 call setline(1, "___\xF0\x82\x82\xAC___") 1870 norm! 1G08g8g 1871 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 1872 1873 " With valid utf8. 1874 call setline(1, "café") 1875 norm! 1G08g8 1876 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 1877 1878 bw! 1879endfunc 1880 1881fun! Test_normal35_g_cmd4() 1882 " Test for g< 1883 " Cannot capture its output, 1884 " probably a bug, therefore, test disabled: 1885 throw "Skipped: output of g< can't be tested currently" 1886 echo "a\nb\nc\nd" 1887 let b=execute(':norm! g<') 1888 call assert_true(!empty(b), 'failed `execute(g<)`') 1889endfunc 1890 1891fun! Test_normal36_g_cmd5() 1892 new 1893 call append(0, 'abcdefghijklmnopqrstuvwxyz') 1894 set ff=unix 1895 " Test for gp gP 1896 call append(1, range(1,10)) 1897 1 1898 norm! 1yy 1899 3 1900 norm! gp 1901 call assert_equal([0, 5, 1, 0, 1], getcurpos()) 1902 $ 1903 norm! gP 1904 call assert_equal([0, 14, 1, 0, 1], getcurpos()) 1905 1906 " Test for go 1907 norm! 26go 1908 call assert_equal([0, 1, 26, 0, 26], getcurpos()) 1909 norm! 27go 1910 call assert_equal([0, 1, 26, 0, 26], getcurpos()) 1911 norm! 28go 1912 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 1913 set ff=dos 1914 norm! 29go 1915 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 1916 set ff=unix 1917 norm! gg0 1918 norm! 101go 1919 call assert_equal([0, 13, 26, 0, 26], getcurpos()) 1920 norm! 103go 1921 call assert_equal([0, 14, 1, 0, 1], getcurpos()) 1922 " count > buffer content 1923 norm! 120go 1924 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) 1925 " clean up 1926 bw! 1927endfunc 1928 1929fun! Test_normal37_g_cmd6() 1930 " basic test for gt and gT 1931 tabnew 1.txt 1932 tabnew 2.txt 1933 tabnew 3.txt 1934 norm! 1gt 1935 call assert_equal(1, tabpagenr()) 1936 norm! 3gt 1937 call assert_equal(3, tabpagenr()) 1938 norm! 1gT 1939 " count gT goes not to the absolute tabpagenumber 1940 " but, but goes to the count previous tabpagenumber 1941 call assert_equal(2, tabpagenr()) 1942 " wrap around 1943 norm! 3gT 1944 call assert_equal(3, tabpagenr()) 1945 " gt does not wrap around 1946 norm! 5gt 1947 call assert_equal(3, tabpagenr()) 1948 1949 for i in range(3) 1950 tabclose 1951 endfor 1952 " clean up 1953 call assert_fails(':tabclose', 'E784') 1954endfunc 1955 1956fun! Test_normal38_nvhome() 1957 " Test for <Home> and <C-Home> key 1958 new 1959 call setline(1, range(10)) 1960 $ 1961 setl et sw=2 1962 norm! V10>$ 1963 " count is ignored 1964 exe "norm! 10\<home>" 1965 call assert_equal(1, col('.')) 1966 exe "norm! \<home>" 1967 call assert_equal([0, 10, 1, 0, 1], getcurpos()) 1968 exe "norm! 5\<c-home>" 1969 call assert_equal([0, 5, 1, 0, 1], getcurpos()) 1970 exe "norm! \<c-home>" 1971 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 1972 1973 " clean up 1974 bw! 1975endfunc 1976 1977fun! Test_normal39_cw() 1978 " Test for cw and cW on whitespace 1979 " and cpo+=w setting 1980 new 1981 set tw=0 1982 call append(0, 'here are some words') 1983 norm! 1gg0elcwZZZ 1984 call assert_equal('hereZZZare some words', getline('.')) 1985 norm! 1gg0elcWYYY 1986 call assert_equal('hereZZZareYYYsome words', getline('.')) 1987 set cpo+=w 1988 call setline(1, 'here are some words') 1989 norm! 1gg0elcwZZZ 1990 call assert_equal('hereZZZ are some words', getline('.')) 1991 norm! 1gg2elcWYYY 1992 call assert_equal('hereZZZ areYYY some words', getline('.')) 1993 set cpo-=w 1994 norm! 2gg0cwfoo 1995 call assert_equal('foo', getline('.')) 1996 1997 " clean up 1998 bw! 1999endfunc 2000 2001fun! Test_normal40_ctrl_bsl() 2002 " Basic test for CTRL-\ commands 2003 new 2004 call append(0, 'here are some words') 2005 exe "norm! 1gg0a\<C-\>\<C-N>" 2006 call assert_equal('n', mode()) 2007 call assert_equal(1, col('.')) 2008 call assert_equal('', visualmode()) 2009 exe "norm! 1gg0viw\<C-\>\<C-N>" 2010 call assert_equal('n', mode()) 2011 call assert_equal(4, col('.')) 2012 exe "norm! 1gg0a\<C-\>\<C-G>" 2013 call assert_equal('n', mode()) 2014 call assert_equal(1, col('.')) 2015 "imap <buffer> , <c-\><c-n> 2016 set im 2017 exe ":norm! \<c-\>\<c-n>dw" 2018 set noim 2019 call assert_equal('are some words', getline(1)) 2020 call assert_false(&insertmode) 2021 2022 " clean up 2023 bw! 2024endfunc 2025 2026fun! Test_normal41_insert_reg() 2027 " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= 2028 " in insert mode 2029 new 2030 set sts=2 sw=2 ts=8 tw=0 2031 call append(0, ["aaa\tbbb\tccc", '', '', '']) 2032 let a=getline(1) 2033 norm! 2gg0 2034 exe "norm! a\<c-r>=a\<cr>" 2035 norm! 3gg0 2036 exe "norm! a\<c-r>\<c-r>=a\<cr>" 2037 norm! 4gg0 2038 exe "norm! a\<c-r>\<c-o>=a\<cr>" 2039 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) 2040 2041 " clean up 2042 set sts=0 sw=8 ts=8 2043 bw! 2044endfunc 2045 2046func! Test_normal42_halfpage() 2047 " basic test for Ctrl-D and Ctrl-U 2048 call Setup_NewWindow() 2049 call assert_equal(5, &scroll) 2050 exe "norm! \<c-d>" 2051 call assert_equal('6', getline('.')) 2052 exe "norm! 2\<c-d>" 2053 call assert_equal('8', getline('.')) 2054 call assert_equal(2, &scroll) 2055 set scroll=5 2056 exe "norm! \<c-u>" 2057 call assert_equal('3', getline('.')) 2058 1 2059 set scrolloff=5 2060 exe "norm! \<c-d>" 2061 call assert_equal('10', getline('.')) 2062 exe "norm! \<c-u>" 2063 call assert_equal('5', getline('.')) 2064 1 2065 set scrolloff=99 2066 exe "norm! \<c-d>" 2067 call assert_equal('10', getline('.')) 2068 set scrolloff=0 2069 100 2070 exe "norm! $\<c-u>" 2071 call assert_equal('95', getline('.')) 2072 call assert_equal([0, 95, 1, 0, 1], getcurpos()) 2073 100 2074 set nostartofline 2075 exe "norm! $\<c-u>" 2076 call assert_equal('95', getline('.')) 2077 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) 2078 " cleanup 2079 set startofline 2080 bw! 2081endfunc 2082 2083fun! Test_normal43_textobject1() 2084 " basic tests for text object aw 2085 new 2086 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) 2087 " diw 2088 norm! 1gg0diw 2089 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$')) 2090 " daw 2091 norm! 2ggEdaw 2092 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$')) 2093 %d 2094 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) 2095 " diW 2096 norm! 2ggwd2iW 2097 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$')) 2098 " daW 2099 norm! 1ggd2aW 2100 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$')) 2101 2102 %d 2103 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) 2104 " aw in visual line mode switches to characterwise mode 2105 norm! 2gg$Vawd 2106 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$')) 2107 norm! 1gg$Viwd 2108 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$')) 2109 2110 " clean up 2111 bw! 2112endfunc 2113 2114func! Test_normal44_textobjects2() 2115 " basic testing for is and as text objects 2116 new 2117 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) 2118 " Test for dis - does not remove trailing whitespace 2119 norm! 1gg0dis 2120 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$')) 2121 " Test for das - removes leading whitespace 2122 norm! 3ggf?ldas 2123 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$')) 2124 " when used in visual mode, is made characterwise 2125 norm! 3gg$Visy 2126 call assert_equal('v', visualmode()) 2127 " reset visualmode() 2128 norm! 3ggVy 2129 norm! 3gg$Vasy 2130 call assert_equal('v', visualmode()) 2131 " basic testing for textobjects a< and at 2132 %d 2133 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) 2134 " a< 2135 norm! 1gg0da< 2136 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) 2137 norm! 1pj 2138 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) 2139 " at 2140 norm! d2at 2141 call assert_equal([' '], getline(1,'$')) 2142 %d 2143 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) 2144 " i< 2145 norm! 1gg0di< 2146 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) 2147 norm! 1Pj 2148 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) 2149 norm! d2it 2150 call assert_equal(['<div></div>',' '], getline(1,'$')) 2151 " basic testing for a[ and i[ text object 2152 %d 2153 call setline(1, [' ', '[', 'one [two]', 'thre', ']']) 2154 norm! 3gg0di[ 2155 call assert_equal([' ', '[', ']'], getline(1,'$')) 2156 call setline(1, [' ', '[', 'one [two]', 'thre', ']']) 2157 norm! 3gg0ftd2a[ 2158 call assert_equal([' '], getline(1,'$')) 2159 %d 2160 " Test for i" when cursor is in front of a quoted object 2161 call append(0, 'foo "bar"') 2162 norm! 1gg0di" 2163 call assert_equal(['foo ""', ''], getline(1,'$')) 2164 2165 " clean up 2166 bw! 2167endfunc 2168 2169func! Test_normal45_drop() 2170 if !has("dnd") 2171 return 2172 endif 2173 " basic test for :drop command 2174 " unfortunately, without a gui, we can't really test much here, 2175 " so simply test that ~p fails (which uses the drop register) 2176 new 2177 call assert_fails(':norm! "~p', 'E353') 2178 call assert_equal([], getreg('~', 1, 1)) 2179 " the ~ register is read only 2180 call assert_fails(':let @~="1"', 'E354') 2181 bw! 2182endfunc 2183 2184func! Test_normal46_ignore() 2185 " This test uses multi byte characters 2186 if !has("multi_byte") 2187 return 2188 endif 2189 2190 new 2191 " How to test this? 2192 " let's just for now test, that the buffer 2193 " does not change 2194 call feedkeys("\<c-s>", 't') 2195 call assert_equal([''], getline(1,'$')) 2196 2197 " no valid commands 2198 exe "norm! \<char-0x100>" 2199 call assert_equal([''], getline(1,'$')) 2200 2201 exe "norm! ä" 2202 call assert_equal([''], getline(1,'$')) 2203 2204 " clean up 2205 bw! 2206endfunc 2207 2208func! Test_normal47_visual_buf_wipe() 2209 " This was causing a crash or ml_get error. 2210 enew! 2211 call setline(1,'xxx') 2212 normal $ 2213 new 2214 call setline(1, range(1,2)) 2215 2 2216 exe "norm \<C-V>$" 2217 bw! 2218 norm yp 2219 set nomodified 2220endfunc 2221 2222func! Test_normal47_autocmd() 2223 " disabled, does not seem to be possible currently 2224 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" 2225 new 2226 call append(0, repeat('-',20)) 2227 au CursorHold * call feedkeys('2l', '') 2228 1 2229 set updatetime=20 2230 " should delete 12 chars (d12l) 2231 call feedkeys('d1', '!') 2232 call assert_equal('--------', getline(1)) 2233 2234 " clean up 2235 au! CursorHold 2236 set updatetime=4000 2237 bw! 2238endfunc 2239 2240func! Test_normal48_wincmd() 2241 new 2242 exe "norm! \<c-w>c" 2243 call assert_equal(1, winnr('$')) 2244 call assert_fails(":norm! \<c-w>c", "E444") 2245endfunc 2246 2247func! Test_normal49_counts() 2248 new 2249 call setline(1, 'one two three four five six seven eight nine ten') 2250 1 2251 norm! 3d2w 2252 call assert_equal('seven eight nine ten', getline(1)) 2253 bw! 2254endfunc 2255 2256func! Test_normal50_commandline() 2257 if !has("timers") || !has("cmdline_hist") 2258 return 2259 endif 2260 func! DoTimerWork(id) 2261 call assert_equal('[Command Line]', bufname('')) 2262 " should fail, with E11, but does fail with E23? 2263 "call feedkeys("\<c-^>", 'tm') 2264 2265 " should also fail with E11 2266 call assert_fails(":wincmd p", 'E11') 2267 " return from commandline window 2268 call feedkeys("\<cr>") 2269 endfunc 2270 2271 let oldlang=v:lang 2272 lang C 2273 set updatetime=20 2274 call timer_start(100, 'DoTimerWork') 2275 try 2276 " throws E23, for whatever reason... 2277 call feedkeys('q:', 'x!') 2278 catch /E23/ 2279 " no-op 2280 endtry 2281 " clean up 2282 set updatetime=4000 2283 exe "lang" oldlang 2284 bw! 2285endfunc 2286 2287func! Test_normal51_FileChangedRO() 2288 if !has("autocmd") 2289 return 2290 endif 2291 " Don't sleep after the warning message. 2292 call test_settime(1) 2293 call writefile(['foo'], 'Xreadonly.log') 2294 new Xreadonly.log 2295 setl ro 2296 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix') 2297 call assert_fails(":norm! Af", 'E788') 2298 call assert_equal(['foo'], getline(1,'$')) 2299 call assert_equal('Xreadonly.log', bufname('')) 2300 2301 " cleanup 2302 call test_settime(0) 2303 bw! 2304 call delete("Xreadonly.log") 2305endfunc 2306 2307func! Test_normal52_rl() 2308 if !has("rightleft") 2309 return 2310 endif 2311 new 2312 call setline(1, 'abcde fghij klmnopq') 2313 norm! 1gg$ 2314 set rl 2315 call assert_equal(19, col('.')) 2316 call feedkeys('l', 'tx') 2317 call assert_equal(18, col('.')) 2318 call feedkeys('h', 'tx') 2319 call assert_equal(19, col('.')) 2320 call feedkeys("\<right>", 'tx') 2321 call assert_equal(18, col('.')) 2322 call feedkeys("\<s-right>", 'tx') 2323 call assert_equal(13, col('.')) 2324 call feedkeys("\<c-right>", 'tx') 2325 call assert_equal(7, col('.')) 2326 call feedkeys("\<c-left>", 'tx') 2327 call assert_equal(13, col('.')) 2328 call feedkeys("\<s-left>", 'tx') 2329 call assert_equal(19, col('.')) 2330 call feedkeys("<<", 'tx') 2331 call assert_equal(' abcde fghij klmnopq',getline(1)) 2332 call feedkeys(">>", 'tx') 2333 call assert_equal('abcde fghij klmnopq',getline(1)) 2334 2335 " cleanup 2336 set norl 2337 bw! 2338endfunc 2339 2340func! Test_normal53_digraph() 2341 if !has('digraphs') 2342 return 2343 endif 2344 new 2345 call setline(1, 'abcdefgh|') 2346 exe "norm! 1gg0f\<c-k>!!" 2347 call assert_equal(9, col('.')) 2348 set cpo+=D 2349 exe "norm! 1gg0f\<c-k>!!" 2350 call assert_equal(1, col('.')) 2351 2352 set cpo-=D 2353 bw! 2354endfunc 2355 2356func Test_normal54_Ctrl_bsl() 2357 new 2358 call setline(1, 'abcdefghijklmn') 2359 exe "norm! df\<c-\>\<c-n>" 2360 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2361 exe "norm! df\<c-\>\<c-g>" 2362 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2363 exe "norm! df\<c-\>m" 2364 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2365 if !has("multi_byte") 2366 return 2367 endif 2368 call setline(2, 'abcdefghijklmnāf') 2369 norm! 2gg0 2370 exe "norm! df\<Char-0x101>" 2371 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2372 norm! 1gg0 2373 exe "norm! df\<esc>" 2374 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2375 2376 " clean up 2377 bw! 2378endfunc 2379 2380func Test_normal_large_count() 2381 " This may fail with 32bit long, how do we detect that? 2382 new 2383 normal o 2384 normal 6666666666dL 2385 bwipe! 2386endfunc 2387 2388func Test_delete_until_paragraph() 2389 if !has('multi_byte') 2390 return 2391 endif 2392 new 2393 normal grádv} 2394 call assert_equal('á', getline(1)) 2395 normal grád} 2396 call assert_equal('', getline(1)) 2397 bwipe! 2398endfunc 2399 2400" Test for the gr (virtual replace) command 2401" Test for the bug fixed by 7.4.387 2402func Test_gr_command() 2403 enew! 2404 let save_cpo = &cpo 2405 call append(0, ['First line', 'Second line', 'Third line']) 2406 exe "normal i\<C-G>u" 2407 call cursor(2, 1) 2408 set cpo-=X 2409 normal 4gro 2410 call assert_equal('oooond line', getline(2)) 2411 undo 2412 set cpo+=X 2413 normal 4gro 2414 call assert_equal('ooooecond line', getline(2)) 2415 let &cpo = save_cpo 2416 enew! 2417endfunc 2418 2419" When splitting a window the changelist position is wrong. 2420" Test the changelist position after splitting a window. 2421" Test for the bug fixed by 7.4.386 2422func Test_changelist() 2423 let save_ul = &ul 2424 enew! 2425 call append('$', ['1', '2']) 2426 exe "normal i\<C-G>u" 2427 exe "normal Gkylpa\<C-G>u" 2428 set ul=100 2429 exe "normal Gylpa\<C-G>u" 2430 set ul=100 2431 normal gg 2432 vsplit 2433 normal g; 2434 call assert_equal([3, 2], [line('.'), col('.')]) 2435 normal g; 2436 call assert_equal([2, 2], [line('.'), col('.')]) 2437 call assert_fails('normal g;', 'E662:') 2438 %bwipe! 2439 let &ul = save_ul 2440endfunc 2441