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