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! zp') 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_ 2242 call assert_beeps('normal! 100g_') 2243 call setline(2, [' foo ', ' foobar ']) 2244 normal! 2ggg_ 2245 call assert_equal(5, col('.')) 2246 normal! 2g_ 2247 call assert_equal(8, col('.')) 2248 2249 norm! 2ggdG 2250 $put =lineC 2251 2252 " Test for gM 2253 norm! gMyl 2254 call assert_equal(73, col('.')) 2255 call assert_equal('0', getreg(0)) 2256 " Test for 20gM 2257 norm! 20gMyl 2258 call assert_equal(29, col('.')) 2259 call assert_equal('S', getreg(0)) 2260 " Test for 60gM 2261 norm! 60gMyl 2262 call assert_equal(87, col('.')) 2263 call assert_equal('E', getreg(0)) 2264 2265 " Test for g Ctrl-G 2266 set ff=unix 2267 let a=execute(":norm! g\<c-g>") 2268 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a) 2269 2270 " Test for gI 2271 norm! gIfoo 2272 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$')) 2273 2274 " Test for gi 2275 wincmd c 2276 %d 2277 set tw=0 2278 call setline(1, ['foobar', 'new line']) 2279 norm! A next word 2280 $put ='third line' 2281 norm! gi another word 2282 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) 2283 call setline(1, 'foobar') 2284 normal! Ggifirst line 2285 call assert_equal('foobarfirst line', getline(1)) 2286 " Test gi in 'virtualedit' mode with cursor after the end of the line 2287 set virtualedit=all 2288 call setline(1, 'foo') 2289 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>" 2290 call setline(1, 'foo') 2291 normal! Ggifirst line 2292 call assert_equal('foo first line', getline(1)) 2293 set virtualedit& 2294 2295 " Test for aboring a g command using CTRL-\ CTRL-G 2296 exe "normal! g\<C-\>\<C-G>" 2297 call assert_equal('foo first line', getline('.')) 2298 2299 " clean up 2300 bw! 2301endfunc 2302 2303" Test for g CTRL-G 2304func Test_g_ctrl_g() 2305 new 2306 2307 let a = execute(":norm! g\<c-g>") 2308 call assert_equal("\n--No lines in buffer--", a) 2309 2310 " Test for CTRL-G (same as :file) 2311 let a = execute(":norm! \<c-g>") 2312 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a) 2313 2314 call setline(1, ['first line', 'second line']) 2315 2316 " Test g CTRL-g with dos, mac and unix file type. 2317 norm! gojll 2318 set ff=dos 2319 let a = execute(":norm! g\<c-g>") 2320 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a) 2321 2322 set ff=mac 2323 let a = execute(":norm! g\<c-g>") 2324 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) 2325 2326 set ff=unix 2327 let a = execute(":norm! g\<c-g>") 2328 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) 2329 2330 " Test g CTRL-g in visual mode (v) 2331 let a = execute(":norm! gojllvlg\<c-g>") 2332 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a) 2333 2334 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col 2335 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>") 2336 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) 2337 2338 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col 2339 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>") 2340 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) 2341 2342 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL 2343 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>") 2344 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a) 2345 2346 " There should be one byte less with noeol 2347 set bin noeol 2348 let a = execute(":norm! \<Esc>gog\<c-g>") 2349 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a) 2350 set bin & eol& 2351 2352 call setline(1, ['Français', '日本語']) 2353 2354 let a = execute(":norm! \<Esc>gojlg\<c-g>") 2355 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) 2356 2357 let a = execute(":norm! \<Esc>gojvlg\<c-g>") 2358 call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a) 2359 2360 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>") 2361 call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a) 2362 2363 set fenc=utf8 bomb 2364 let a = execute(":norm! \<Esc>gojlg\<c-g>") 2365 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) 2366 2367 set fenc=utf16 bomb 2368 let a = execute(":norm! g\<c-g>") 2369 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) 2370 2371 set fenc=utf32 bomb 2372 let a = execute(":norm! g\<c-g>") 2373 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) 2374 2375 set fenc& bomb& 2376 2377 set ff& 2378 bwipe! 2379endfunc 2380 2381" Test for g8 2382func Test_normal34_g_cmd3() 2383 new 2384 let a=execute(':norm! 1G0g8') 2385 call assert_equal("\nNUL", a) 2386 2387 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö') 2388 let a=execute(':norm! 1G$g8') 2389 call assert_equal("\nc3 b6 ", a) 2390 2391 call setline(1, "a\u0302") 2392 let a=execute(':norm! 1G0g8') 2393 call assert_equal("\n61 + cc 82 ", a) 2394 2395 " clean up 2396 bw! 2397endfunc 2398 2399" Test 8g8 which finds invalid utf8 at or after the cursor. 2400func Test_normal_8g8() 2401 new 2402 2403 " With invalid byte. 2404 call setline(1, "___\xff___") 2405 norm! 1G08g8g 2406 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2407 2408 " With invalid byte before the cursor. 2409 call setline(1, "___\xff___") 2410 norm! 1G$h8g8g 2411 call assert_equal([0, 1, 6, 0, 9], getcurpos()) 2412 2413 " With truncated sequence. 2414 call setline(1, "___\xE2\x82___") 2415 norm! 1G08g8g 2416 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2417 2418 " With overlong sequence. 2419 call setline(1, "___\xF0\x82\x82\xAC___") 2420 norm! 1G08g8g 2421 call assert_equal([0, 1, 4, 0, 1], getcurpos()) 2422 2423 " With valid utf8. 2424 call setline(1, "café") 2425 norm! 1G08g8 2426 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2427 2428 bw! 2429endfunc 2430 2431" Test for g< 2432func Test_normal35_g_cmd4() 2433 " Cannot capture its output, 2434 " probably a bug, therefore, test disabled: 2435 throw "Skipped: output of g< can't be tested currently" 2436 echo "a\nb\nc\nd" 2437 let b=execute(':norm! g<') 2438 call assert_true(!empty(b), 'failed `execute(g<)`') 2439endfunc 2440 2441" Test for gp gP go 2442func Test_normal36_g_cmd5() 2443 new 2444 call append(0, 'abcdefghijklmnopqrstuvwxyz') 2445 set ff=unix 2446 " Test for gp gP 2447 call append(1, range(1,10)) 2448 1 2449 norm! 1yy 2450 3 2451 norm! gp 2452 call assert_equal([0, 5, 1, 0, 1], getcurpos()) 2453 $ 2454 norm! gP 2455 call assert_equal([0, 14, 1, 0, 1], getcurpos()) 2456 2457 " Test for go 2458 norm! 26go 2459 call assert_equal([0, 1, 26, 0, 26], getcurpos()) 2460 norm! 27go 2461 call assert_equal([0, 1, 26, 0, 26], getcurpos()) 2462 norm! 28go 2463 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 2464 set ff=dos 2465 norm! 29go 2466 call assert_equal([0, 2, 1, 0, 1], getcurpos()) 2467 set ff=unix 2468 norm! gg0 2469 norm! 101go 2470 call assert_equal([0, 13, 26, 0, 26], getcurpos()) 2471 norm! 103go 2472 call assert_equal([0, 14, 1, 0, 1], getcurpos()) 2473 " count > buffer content 2474 norm! 120go 2475 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) 2476 " clean up 2477 bw! 2478endfunc 2479 2480" Test for gt and gT 2481func Test_normal37_g_cmd6() 2482 tabnew 1.txt 2483 tabnew 2.txt 2484 tabnew 3.txt 2485 norm! 1gt 2486 call assert_equal(1, tabpagenr()) 2487 norm! 3gt 2488 call assert_equal(3, tabpagenr()) 2489 norm! 1gT 2490 " count gT goes not to the absolute tabpagenumber 2491 " but, but goes to the count previous tabpagenumber 2492 call assert_equal(2, tabpagenr()) 2493 " wrap around 2494 norm! 3gT 2495 call assert_equal(3, tabpagenr()) 2496 " gt does not wrap around 2497 norm! 5gt 2498 call assert_equal(3, tabpagenr()) 2499 2500 for i in range(3) 2501 tabclose 2502 endfor 2503 " clean up 2504 call assert_fails(':tabclose', 'E784:') 2505endfunc 2506 2507" Test for <Home> and <C-Home> key 2508func Test_normal38_nvhome() 2509 new 2510 call setline(1, range(10)) 2511 $ 2512 setl et sw=2 2513 norm! V10>$ 2514 " count is ignored 2515 exe "norm! 10\<home>" 2516 call assert_equal(1, col('.')) 2517 exe "norm! \<home>" 2518 call assert_equal([0, 10, 1, 0, 1], getcurpos()) 2519 exe "norm! 5\<c-home>" 2520 call assert_equal([0, 5, 1, 0, 1], getcurpos()) 2521 exe "norm! \<c-home>" 2522 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2523 exe "norm! G\<c-kHome>" 2524 call assert_equal([0, 1, 1, 0, 1], getcurpos()) 2525 2526 " clean up 2527 bw! 2528endfunc 2529 2530" Test for <End> and <C-End> keys 2531func Test_normal_nvend() 2532 new 2533 call setline(1, map(range(1, 10), '"line" .. v:val')) 2534 exe "normal! \<End>" 2535 call assert_equal(5, col('.')) 2536 exe "normal! 4\<End>" 2537 call assert_equal([4, 5], [line('.'), col('.')]) 2538 exe "normal! \<C-End>" 2539 call assert_equal([10, 6], [line('.'), col('.')]) 2540 close! 2541endfunc 2542 2543" Test for cw cW ce 2544func Test_normal39_cw() 2545 " Test for cw and cW on whitespace 2546 new 2547 set tw=0 2548 call append(0, 'here are some words') 2549 norm! 1gg0elcwZZZ 2550 call assert_equal('hereZZZare some words', getline('.')) 2551 norm! 1gg0elcWYYY 2552 call assert_equal('hereZZZareYYYsome words', getline('.')) 2553 norm! 2gg0cwfoo 2554 call assert_equal('foo', getline('.')) 2555 2556 call setline(1, 'one; two') 2557 call cursor(1, 1) 2558 call feedkeys('cwvim', 'xt') 2559 call assert_equal('vim; two', getline(1)) 2560 call feedkeys('0cWone', 'xt') 2561 call assert_equal('one two', getline(1)) 2562 "When cursor is at the end of a word 'ce' will change until the end of the 2563 "next word, but 'cw' will change only one character 2564 call setline(1, 'one two') 2565 call feedkeys('0ecwce', 'xt') 2566 call assert_equal('once two', getline(1)) 2567 call setline(1, 'one two') 2568 call feedkeys('0ecely', 'xt') 2569 call assert_equal('only', getline(1)) 2570 2571 " clean up 2572 bw! 2573endfunc 2574 2575" Test for CTRL-\ commands 2576func Test_normal40_ctrl_bsl() 2577 new 2578 call append(0, 'here are some words') 2579 exe "norm! 1gg0a\<C-\>\<C-N>" 2580 call assert_equal('n', mode()) 2581 call assert_equal(1, col('.')) 2582 call assert_equal('', visualmode()) 2583 exe "norm! 1gg0viw\<C-\>\<C-N>" 2584 call assert_equal('n', mode()) 2585 call assert_equal(4, col('.')) 2586 exe "norm! 1gg0a\<C-\>\<C-G>" 2587 call assert_equal('n', mode()) 2588 call assert_equal(1, col('.')) 2589 "imap <buffer> , <c-\><c-n> 2590 set im 2591 exe ":norm! \<c-\>\<c-n>dw" 2592 set noim 2593 call assert_equal('are some words', getline(1)) 2594 call assert_false(&insertmode) 2595 call assert_beeps("normal! \<C-\>\<C-A>", 'xt') 2596 2597 if has('cmdwin') 2598 " Using CTRL-\ CTRL-N in cmd window should close the window 2599 call feedkeys("q:\<C-\>\<C-N>", 'xt') 2600 call assert_equal('', getcmdwintype()) 2601 endif 2602 2603 " clean up 2604 bw! 2605endfunc 2606 2607" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode 2608func Test_normal41_insert_reg() 2609 new 2610 set sts=2 sw=2 ts=8 tw=0 2611 call append(0, ["aaa\tbbb\tccc", '', '', '']) 2612 let a=getline(1) 2613 norm! 2gg0 2614 exe "norm! a\<c-r>=a\<cr>" 2615 norm! 3gg0 2616 exe "norm! a\<c-r>\<c-r>=a\<cr>" 2617 norm! 4gg0 2618 exe "norm! a\<c-r>\<c-o>=a\<cr>" 2619 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) 2620 2621 " clean up 2622 set sts=0 sw=8 ts=8 2623 bw! 2624endfunc 2625 2626" Test for Ctrl-D and Ctrl-U 2627func Test_normal42_halfpage() 2628 call Setup_NewWindow() 2629 call assert_equal(5, &scroll) 2630 exe "norm! \<c-d>" 2631 call assert_equal('6', getline('.')) 2632 exe "norm! 2\<c-d>" 2633 call assert_equal('8', getline('.')) 2634 call assert_equal(2, &scroll) 2635 set scroll=5 2636 exe "norm! \<c-u>" 2637 call assert_equal('3', getline('.')) 2638 1 2639 set scrolloff=5 2640 exe "norm! \<c-d>" 2641 call assert_equal('10', getline('.')) 2642 exe "norm! \<c-u>" 2643 call assert_equal('5', getline('.')) 2644 1 2645 set scrolloff=99 2646 exe "norm! \<c-d>" 2647 call assert_equal('10', getline('.')) 2648 set scrolloff=0 2649 100 2650 exe "norm! $\<c-u>" 2651 call assert_equal('95', getline('.')) 2652 call assert_equal([0, 95, 1, 0, 1], getcurpos()) 2653 100 2654 set nostartofline 2655 exe "norm! $\<c-u>" 2656 call assert_equal('95', getline('.')) 2657 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) 2658 " cleanup 2659 set startofline 2660 bw! 2661endfunc 2662 2663func Test_normal45_drop() 2664 if !has('dnd') 2665 " The ~ register does not exist 2666 call assert_beeps('norm! "~') 2667 return 2668 endif 2669 2670 " basic test for drag-n-drop 2671 " unfortunately, without a gui, we can't really test much here, 2672 " so simply test that ~p fails (which uses the drop register) 2673 new 2674 call assert_fails(':norm! "~p', 'E353:') 2675 call assert_equal([], getreg('~', 1, 1)) 2676 " the ~ register is read only 2677 call assert_fails(':let @~="1"', 'E354:') 2678 bw! 2679endfunc 2680 2681func Test_normal46_ignore() 2682 new 2683 " How to test this? 2684 " let's just for now test, that the buffer 2685 " does not change 2686 call feedkeys("\<c-s>", 't') 2687 call assert_equal([''], getline(1,'$')) 2688 2689 " no valid commands 2690 exe "norm! \<char-0x100>" 2691 call assert_equal([''], getline(1,'$')) 2692 2693 exe "norm! ä" 2694 call assert_equal([''], getline(1,'$')) 2695 2696 " clean up 2697 bw! 2698endfunc 2699 2700func Test_normal47_visual_buf_wipe() 2701 " This was causing a crash or ml_get error. 2702 enew! 2703 call setline(1,'xxx') 2704 normal $ 2705 new 2706 call setline(1, range(1,2)) 2707 2 2708 exe "norm \<C-V>$" 2709 bw! 2710 norm yp 2711 set nomodified 2712endfunc 2713 2714func Test_normal48_wincmd() 2715 new 2716 exe "norm! \<c-w>c" 2717 call assert_equal(1, winnr('$')) 2718 call assert_fails(":norm! \<c-w>c", 'E444:') 2719endfunc 2720 2721func Test_normal49_counts() 2722 new 2723 call setline(1, 'one two three four five six seven eight nine ten') 2724 1 2725 norm! 3d2w 2726 call assert_equal('seven eight nine ten', getline(1)) 2727 bw! 2728endfunc 2729 2730func Test_normal50_commandline() 2731 CheckFeature timers 2732 CheckFeature cmdline_hist 2733 func! DoTimerWork(id) 2734 call assert_equal('[Command Line]', bufname('')) 2735 " should fail, with E11, but does fail with E23? 2736 "call feedkeys("\<c-^>", 'tm') 2737 2738 " should also fail with E11 2739 call assert_fails(":wincmd p", 'E11:') 2740 " return from commandline window 2741 call feedkeys("\<cr>") 2742 endfunc 2743 2744 let oldlang=v:lang 2745 lang C 2746 set updatetime=20 2747 call timer_start(100, 'DoTimerWork') 2748 try 2749 " throws E23, for whatever reason... 2750 call feedkeys('q:', 'x!') 2751 catch /E23/ 2752 " no-op 2753 endtry 2754 " clean up 2755 set updatetime=4000 2756 exe "lang" oldlang 2757 bw! 2758endfunc 2759 2760func Test_normal51_FileChangedRO() 2761 CheckFeature autocmd 2762 " Don't sleep after the warning message. 2763 call test_settime(1) 2764 call writefile(['foo'], 'Xreadonly.log') 2765 new Xreadonly.log 2766 setl ro 2767 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix') 2768 call assert_fails(":norm! Af", 'E788:') 2769 call assert_equal(['foo'], getline(1,'$')) 2770 call assert_equal('Xreadonly.log', bufname('')) 2771 2772 " cleanup 2773 call test_settime(0) 2774 bw! 2775 call delete("Xreadonly.log") 2776endfunc 2777 2778func Test_normal52_rl() 2779 CheckFeature rightleft 2780 new 2781 call setline(1, 'abcde fghij klmnopq') 2782 norm! 1gg$ 2783 set rl 2784 call assert_equal(19, col('.')) 2785 call feedkeys('l', 'tx') 2786 call assert_equal(18, col('.')) 2787 call feedkeys('h', 'tx') 2788 call assert_equal(19, col('.')) 2789 call feedkeys("\<right>", 'tx') 2790 call assert_equal(18, col('.')) 2791 call feedkeys("\<left>", 'tx') 2792 call assert_equal(19, col('.')) 2793 call feedkeys("\<s-right>", 'tx') 2794 call assert_equal(13, col('.')) 2795 call feedkeys("\<c-right>", 'tx') 2796 call assert_equal(7, col('.')) 2797 call feedkeys("\<c-left>", 'tx') 2798 call assert_equal(13, col('.')) 2799 call feedkeys("\<s-left>", 'tx') 2800 call assert_equal(19, col('.')) 2801 call feedkeys("<<", 'tx') 2802 call assert_equal(' abcde fghij klmnopq',getline(1)) 2803 call feedkeys(">>", 'tx') 2804 call assert_equal('abcde fghij klmnopq',getline(1)) 2805 2806 " cleanup 2807 set norl 2808 bw! 2809endfunc 2810 2811func Test_normal54_Ctrl_bsl() 2812 new 2813 call setline(1, 'abcdefghijklmn') 2814 exe "norm! df\<c-\>\<c-n>" 2815 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2816 exe "norm! df\<c-\>\<c-g>" 2817 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2818 exe "norm! df\<c-\>m" 2819 call assert_equal(['abcdefghijklmn'], getline(1,'$')) 2820 2821 call setline(2, 'abcdefghijklmnāf') 2822 norm! 2gg0 2823 exe "norm! df\<Char-0x101>" 2824 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2825 norm! 1gg0 2826 exe "norm! df\<esc>" 2827 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) 2828 2829 " clean up 2830 bw! 2831endfunc 2832 2833func Test_normal_large_count() 2834 " This may fail with 32bit long, how do we detect that? 2835 new 2836 normal o 2837 normal 6666666666dL 2838 bwipe! 2839endfunc 2840 2841func Test_delete_until_paragraph() 2842 new 2843 normal grádv} 2844 call assert_equal('á', getline(1)) 2845 normal grád} 2846 call assert_equal('', getline(1)) 2847 bwipe! 2848endfunc 2849 2850" Test for the gr (virtual replace) command 2851" Test for the bug fixed by 7.4.387 2852func Test_gr_command() 2853 enew! 2854 let save_cpo = &cpo 2855 call append(0, ['First line', 'Second line', 'Third line']) 2856 exe "normal i\<C-G>u" 2857 call cursor(2, 1) 2858 set cpo-=X 2859 normal 4gro 2860 call assert_equal('oooond line', getline(2)) 2861 undo 2862 set cpo+=X 2863 normal 4gro 2864 call assert_equal('ooooecond line', getline(2)) 2865 let &cpo = save_cpo 2866 normal! ggvegrx 2867 call assert_equal('xxxxx line', getline(1)) 2868 exe "normal! gggr\<C-V>122" 2869 call assert_equal('zxxxx line', getline(1)) 2870 set virtualedit=all 2871 normal! 15|grl 2872 call assert_equal('zxxxx line l', getline(1)) 2873 set virtualedit& 2874 set nomodifiable 2875 call assert_fails('normal! grx', 'E21:') 2876 call assert_fails('normal! gRx', 'E21:') 2877 set modifiable& 2878 enew! 2879endfunc 2880 2881" When splitting a window the changelist position is wrong. 2882" Test the changelist position after splitting a window. 2883" Test for the bug fixed by 7.4.386 2884func Test_changelist() 2885 let save_ul = &ul 2886 enew! 2887 call append('$', ['1', '2']) 2888 exe "normal i\<C-G>u" 2889 exe "normal Gkylpa\<C-G>u" 2890 set ul=100 2891 exe "normal Gylpa\<C-G>u" 2892 set ul=100 2893 normal gg 2894 vsplit 2895 normal g; 2896 call assert_equal([3, 2], [line('.'), col('.')]) 2897 normal g; 2898 call assert_equal([2, 2], [line('.'), col('.')]) 2899 call assert_fails('normal g;', 'E662:') 2900 new 2901 call assert_fails('normal g;', 'E664:') 2902 %bwipe! 2903 let &ul = save_ul 2904endfunc 2905 2906func Test_nv_hat_count() 2907 %bwipeout! 2908 let l:nr = bufnr('%') + 1 2909 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:') 2910 2911 edit Xfoo 2912 let l:foo_nr = bufnr('Xfoo') 2913 2914 edit Xbar 2915 let l:bar_nr = bufnr('Xbar') 2916 2917 " Make sure we are not just using the alternate file. 2918 edit Xbaz 2919 2920 call feedkeys(l:foo_nr . "\<C-^>", 'tx') 2921 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) 2922 2923 call feedkeys(l:bar_nr . "\<C-^>", 'tx') 2924 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) 2925 2926 %bwipeout! 2927endfunc 2928 2929func Test_message_when_using_ctrl_c() 2930 " Make sure no buffers are changed. 2931 %bwipe! 2932 2933 exe "normal \<C-C>" 2934 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines)) 2935 2936 new 2937 cal setline(1, 'hi!') 2938 exe "normal \<C-C>" 2939 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines)) 2940 2941 bwipe! 2942endfunc 2943 2944" Test for '[m', ']m', '[M' and ']M' 2945" Jumping to beginning and end of methods in Java-like languages 2946func Test_java_motion() 2947 new 2948 call assert_beeps('normal! [m') 2949 call assert_beeps('normal! ]m') 2950 call assert_beeps('normal! [M') 2951 call assert_beeps('normal! ]M') 2952 let lines =<< trim [CODE] 2953 Piece of Java 2954 { 2955 tt m1 { 2956 t1; 2957 } e1 2958 2959 tt m2 { 2960 t2; 2961 } e2 2962 2963 tt m3 { 2964 if (x) 2965 { 2966 t3; 2967 } 2968 } e3 2969 } 2970 [CODE] 2971 call setline(1, lines) 2972 2973 normal gg 2974 2975 normal 2]maA 2976 call assert_equal("\ttt m1 {A", getline('.')) 2977 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) 2978 2979 normal j]maB 2980 call assert_equal("\ttt m2 {B", getline('.')) 2981 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')]) 2982 2983 normal ]maC 2984 call assert_equal("\ttt m3 {C", getline('.')) 2985 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) 2986 2987 normal [maD 2988 call assert_equal("\ttt m3 {DC", getline('.')) 2989 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) 2990 2991 normal k2[maE 2992 call assert_equal("\ttt m1 {EA", getline('.')) 2993 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) 2994 2995 normal 3[maF 2996 call assert_equal("{F", getline('.')) 2997 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) 2998 2999 normal ]MaG 3000 call assert_equal("\t}G e1", getline('.')) 3001 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')]) 3002 3003 normal j2]MaH 3004 call assert_equal("\t}H e3", getline('.')) 3005 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) 3006 3007 normal ]M]M 3008 normal aI 3009 call assert_equal("}I", getline('.')) 3010 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')]) 3011 3012 normal 2[MaJ 3013 call assert_equal("\t}JH e3", getline('.')) 3014 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) 3015 3016 normal k[MaK 3017 call assert_equal("\t}K e2", getline('.')) 3018 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')]) 3019 3020 normal 3[MaL 3021 call assert_equal("{LF", getline('.')) 3022 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) 3023 3024 call cursor(2, 1) 3025 call assert_beeps('norm! 5]m') 3026 3027 " jumping to a method in a fold should open the fold 3028 6,10fold 3029 call feedkeys("gg3]m", 'xt') 3030 call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')]) 3031 call assert_equal(-1, foldclosedend(7)) 3032 3033 close! 3034endfunc 3035 3036" Tests for g cmds 3037func Test_normal_gdollar_cmd() 3038 CheckFeature jumplist 3039 call Setup_NewWindow() 3040 " Make long lines that will wrap 3041 %s/$/\=repeat(' foobar', 10)/ 3042 20vsp 3043 set wrap 3044 " Test for g$ with count 3045 norm! gg 3046 norm! 0vg$y 3047 call assert_equal(20, col("'>")) 3048 call assert_equal('1 foobar foobar foob', getreg(0)) 3049 norm! gg 3050 norm! 0v4g$y 3051 call assert_equal(72, col("'>")) 3052 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0)) 3053 norm! gg 3054 norm! 0v6g$y 3055 call assert_equal(40, col("'>")) 3056 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3057 \ '2 foobar foobar foobar foobar foobar foo', getreg(0)) 3058 set nowrap 3059 " clean up 3060 norm! gg 3061 norm! 0vg$y 3062 call assert_equal(20, col("'>")) 3063 call assert_equal('1 foobar foobar foob', getreg(0)) 3064 norm! gg 3065 norm! 0v4g$y 3066 call assert_equal(20, col("'>")) 3067 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3068 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3069 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3070 \ '4 foobar foobar foob', getreg(0)) 3071 norm! gg 3072 norm! 0v6g$y 3073 call assert_equal(20, col("'>")) 3074 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3075 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3076 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3077 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3078 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. 3079 \ '6 foobar foobar foob', getreg(0)) 3080 " Move to last line, also down movement is not possible, should still move 3081 " the cursor to the last visible char 3082 norm! G 3083 norm! 0v6g$y 3084 call assert_equal(20, col("'>")) 3085 call assert_equal('100 foobar foobar fo', getreg(0)) 3086 bw! 3087endfunc 3088 3089func Test_normal_gk_gj() 3090 " needs 80 column new window 3091 new 3092 vert 80new 3093 call assert_beeps('normal gk') 3094 put =[repeat('x',90)..' {{{1', 'x {{{1'] 3095 norm! gk 3096 " In a 80 column wide terminal the window will be only 78 char 3097 " (because Vim will leave space for the other window), 3098 " but if the terminal is larger, it will be 80 chars, so verify the 3099 " cursor column correctly. 3100 call assert_equal(winwidth(0)+1, col('.')) 3101 call assert_equal(winwidth(0)+1, virtcol('.')) 3102 norm! j 3103 call assert_equal(6, col('.')) 3104 call assert_equal(6, virtcol('.')) 3105 norm! gk 3106 call assert_equal(95, col('.')) 3107 call assert_equal(95, virtcol('.')) 3108 %bw! 3109 3110 " needs 80 column new window 3111 new 3112 vert 80new 3113 call assert_beeps('normal gj') 3114 set number 3115 set numberwidth=10 3116 set cpoptions+=n 3117 put =[repeat('0',90), repeat('1',90)] 3118 norm! 075l 3119 call assert_equal(76, col('.')) 3120 norm! gk 3121 call assert_equal(1, col('.')) 3122 norm! gk 3123 call assert_equal(76, col('.')) 3124 norm! gk 3125 call assert_equal(1, col('.')) 3126 norm! gj 3127 call assert_equal(76, col('.')) 3128 norm! gj 3129 call assert_equal(1, col('.')) 3130 norm! gj 3131 call assert_equal(76, col('.')) 3132 " When 'nowrap' is set, gk and gj behave like k and j 3133 set nowrap 3134 normal! gk 3135 call assert_equal([2, 76], [line('.'), col('.')]) 3136 normal! gj 3137 call assert_equal([3, 76], [line('.'), col('.')]) 3138 %bw! 3139 set cpoptions& number& numberwidth& wrap& 3140endfunc 3141 3142" Test for using : to run a multi-line Ex command in operator pending mode 3143func Test_normal_yank_with_excmd() 3144 new 3145 call setline(1, ['foo', 'bar', 'baz']) 3146 let @a = '' 3147 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt') 3148 call assert_equal('f', @a) 3149 close! 3150endfunc 3151 3152" Test for supplying a count to a normal-mode command across a cursorhold call 3153func Test_normal_cursorhold_with_count() 3154 func s:cHold() 3155 let g:cHold_Called += 1 3156 endfunc 3157 new 3158 augroup normalcHoldTest 3159 au! 3160 au CursorHold <buffer> call s:cHold() 3161 augroup END 3162 let g:cHold_Called = 0 3163 call feedkeys("3\<CursorHold>2ix", 'xt') 3164 call assert_equal(1, g:cHold_Called) 3165 call assert_equal(repeat('x', 32), getline(1)) 3166 augroup normalcHoldTest 3167 au! 3168 augroup END 3169 au! normalcHoldTest 3170 close! 3171 delfunc s:cHold 3172endfunc 3173 3174" Test for using a count and a command with CTRL-W 3175func Test_wincmd_with_count() 3176 call feedkeys("\<C-W>12n", 'xt') 3177 call assert_equal(12, winheight(0)) 3178endfunc 3179 3180" Test for 'b', 'B' 'ge' and 'gE' commands 3181func Test_horiz_motion() 3182 new 3183 normal! gg 3184 call assert_beeps('normal! b') 3185 call assert_beeps('normal! B') 3186 call assert_beeps('normal! gE') 3187 call assert_beeps('normal! ge') 3188 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left 3189 call setline(1, 'one ,two ,three') 3190 exe "normal! $\<S-BS>" 3191 call assert_equal(11, col('.')) 3192 exe "normal! $\<C-BS>" 3193 call assert_equal(10, col('.')) 3194 close! 3195endfunc 3196 3197" Test for using a : command in operator pending mode 3198func Test_normal_colon_op() 3199 new 3200 call setline(1, ['one', 'two']) 3201 call assert_beeps("normal! Gc:d\<CR>") 3202 close! 3203endfunc 3204 3205" Test for d and D commands 3206func Test_normal_delete_cmd() 3207 new 3208 " D in an empty line 3209 call setline(1, '') 3210 normal D 3211 call assert_equal('', getline(1)) 3212 " D in an empty line in virtualedit mode 3213 set virtualedit=all 3214 normal D 3215 call assert_equal('', getline(1)) 3216 set virtualedit& 3217 " delete to a readonly register 3218 call setline(1, ['abcd']) 3219 call assert_beeps('normal ":d2l') 3220 3221 " D and d with 'nomodifiable' 3222 call setline(1, ['abcd']) 3223 setlocal nomodifiable 3224 call assert_fails('normal D', 'E21:') 3225 call assert_fails('normal d$', 'E21:') 3226 3227 close! 3228endfunc 3229 3230" Test for deleting or changing characters across lines with 'whichwrap' 3231" containing 's'. Should count <EOL> as one character. 3232func Test_normal_op_across_lines() 3233 new 3234 set whichwrap& 3235 call setline(1, ['one two', 'three four']) 3236 exe "norm! $3d\<Space>" 3237 call assert_equal(['one twhree four'], getline(1, '$')) 3238 3239 call setline(1, ['one two', 'three four']) 3240 exe "norm! $3c\<Space>x" 3241 call assert_equal(['one twxhree four'], getline(1, '$')) 3242 3243 set whichwrap+=l 3244 call setline(1, ['one two', 'three four']) 3245 exe "norm! $3x" 3246 call assert_equal(['one twhree four'], getline(1, '$')) 3247 close! 3248 set whichwrap& 3249endfunc 3250 3251" Test for 'w' and 'b' commands 3252func Test_normal_word_move() 3253 new 3254 call setline(1, ['foo bar a', '', 'foo bar b']) 3255 " copy a single character word at the end of a line 3256 normal 1G$yw 3257 call assert_equal('a', @") 3258 " copy a single character word at the end of a file 3259 normal G$yw 3260 call assert_equal('b', @") 3261 " check for a word movement handling an empty line properly 3262 normal 1G$vwy 3263 call assert_equal("a\n\n", @") 3264 3265 " copy using 'b' command 3266 %d 3267 " non-empty blank line at the start of file 3268 call setline(1, [' ', 'foo bar']) 3269 normal 2Gyb 3270 call assert_equal(" \n", @") 3271 " try to copy backwards from the start of the file 3272 call setline(1, ['one two', 'foo bar']) 3273 call assert_beeps('normal ggyb') 3274 " 'b' command should stop at an empty line 3275 call setline(1, ['one two', '', 'foo bar']) 3276 normal 3Gyb 3277 call assert_equal("\n", @") 3278 normal 3Gy2b 3279 call assert_equal("two\n", @") 3280 " 'b' command should not stop at a non-empty blank line 3281 call setline(1, ['one two', ' ', 'foo bar']) 3282 normal 3Gyb 3283 call assert_equal("two\n ", @") 3284 3285 close! 3286endfunc 3287 3288" Test for 'scrolloff' with a long line that doesn't fit in the screen 3289func Test_normal_scroloff() 3290 10new 3291 80vnew 3292 call setline(1, repeat('a', 1000)) 3293 set scrolloff=10 3294 normal gg10gj 3295 call assert_equal(8, winline()) 3296 normal 10gj 3297 call assert_equal(10, winline()) 3298 normal 10gk 3299 call assert_equal(3, winline()) 3300 set scrolloff& 3301 close! 3302endfunc 3303 3304" Test for vertical scrolling with CTRL-F and CTRL-B with a long line 3305func Test_normal_vert_scroll_longline() 3306 10new 3307 80vnew 3308 call setline(1, range(1, 10)) 3309 call append(5, repeat('a', 1000)) 3310 exe "normal gg\<C-F>" 3311 call assert_equal(6, line('.')) 3312 exe "normal \<C-F>\<C-F>" 3313 call assert_equal(11, line('.')) 3314 call assert_equal(1, winline()) 3315 exe "normal \<C-B>" 3316 call assert_equal(10, line('.')) 3317 call assert_equal(3, winline()) 3318 exe "normal \<C-B>\<C-B>" 3319 call assert_equal(5, line('.')) 3320 call assert_equal(5, winline()) 3321 close! 3322endfunc 3323 3324" Test for jumping in a file using % 3325func Test_normal_percent_jump() 3326 new 3327 call setline(1, range(1, 100)) 3328 3329 " jumping to a folded line should open the fold 3330 25,75fold 3331 call feedkeys('50%', 'xt') 3332 call assert_equal(50, line('.')) 3333 call assert_equal(-1, foldclosedend(50)) 3334 close! 3335endfunc 3336 3337" Test for << and >> commands to shift text by 'shiftwidth' 3338func Test_normal_shift_rightleft() 3339 new 3340 call setline(1, ['one', '', "\t", ' two', "\tthree", ' four']) 3341 set shiftwidth=2 tabstop=8 3342 normal gg6>> 3343 call assert_equal([' one', '', "\t ", ' two', "\t three", "\tfour"], 3344 \ getline(1, '$')) 3345 normal ggVG2>> 3346 call assert_equal([' one', '', "\t ", "\ttwo", 3347 \ "\t three", "\t four"], getline(1, '$')) 3348 normal gg6<< 3349 call assert_equal([' one', '', "\t ", ' two', "\t three", 3350 \ "\t four"], getline(1, '$')) 3351 normal ggVG2<< 3352 call assert_equal(['one', '', "\t", ' two', "\tthree", ' four'], 3353 \ getline(1, '$')) 3354 set shiftwidth& tabstop& 3355 bw! 3356endfunc 3357 3358" vim: shiftwidth=2 sts=2 expandtab 3359