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