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