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