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