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