1" Test for edit functions 2" 3if exists("+t_kD") 4 let &t_kD="[3;*~" 5endif 6 7" Needed for testing basic rightleft: Test_edit_rightleft 8source view_util.vim 9 10" Needs to come first until the bug in getchar() is 11" fixed: https://groups.google.com/d/msg/vim_dev/fXL9yme4H4c/bOR-U6_bAQAJ 12func Test_edit_00b() 13 new 14 call setline(1, ['abc ']) 15 inoreabbr <buffer> h here some more 16 call cursor(1, 4) 17 " <c-l> expands the abbreviation and ends insertmode 18 call feedkeys(":set im\<cr> h\<c-l>:set noim\<cr>", 'tix') 19 call assert_equal(['abc here some more '], getline(1,'$')) 20 iunabbr <buffer> h 21 bw! 22endfunc 23 24func Test_edit_01() 25 " set for Travis CI? 26 " set nocp noesckeys 27 new 28 " 1) empty buffer 29 call assert_equal([''], getline(1,'$')) 30 " 2) delete in an empty line 31 call feedkeys("i\<del>\<esc>", 'tnix') 32 call assert_equal([''], getline(1,'$')) 33 %d 34 " 3) delete one character 35 call setline(1, 'a') 36 call feedkeys("i\<del>\<esc>", 'tnix') 37 call assert_equal([''], getline(1,'$')) 38 %d 39 " 4) delete a multibyte character 40 call setline(1, "\u0401") 41 call feedkeys("i\<del>\<esc>", 'tnix') 42 call assert_equal([''], getline(1,'$')) 43 %d 44 " 5.1) delete linebreak with 'bs' option containing eol 45 let _bs=&bs 46 set bs=eol 47 call setline(1, ["abc def", "ghi jkl"]) 48 call cursor(1, 1) 49 call feedkeys("A\<del>\<esc>", 'tnix') 50 call assert_equal(['abc defghi jkl'], getline(1, 2)) 51 %d 52 " 5.2) delete linebreak with backspace option w/out eol 53 set bs= 54 call setline(1, ["abc def", "ghi jkl"]) 55 call cursor(1, 1) 56 call feedkeys("A\<del>\<esc>", 'tnix') 57 call assert_equal(["abc def", "ghi jkl"], getline(1, 2)) 58 let &bs=_bs 59 bw! 60endfunc 61 62func Test_edit_02() 63 " Change cursor position in InsertCharPre command 64 new 65 call setline(1, 'abc') 66 call cursor(1, 1) 67 fu! DoIt(...) 68 call cursor(1, 4) 69 if len(a:000) 70 let v:char=a:1 71 endif 72 endfu 73 au InsertCharPre <buffer> :call DoIt('y') 74 call feedkeys("ix\<esc>", 'tnix') 75 call assert_equal(['abcy'], getline(1, '$')) 76 " Setting <Enter> in InsertCharPre 77 au! InsertCharPre <buffer> :call DoIt("\n") 78 call setline(1, 'abc') 79 call cursor(1, 1) 80 call feedkeys("ix\<esc>", 'tnix') 81 call assert_equal(['abc', ''], getline(1, '$')) 82 %d 83 au! InsertCharPre 84 " Change cursor position in InsertEnter command 85 " 1) when setting v:char, keeps changed cursor position 86 au! InsertEnter <buffer> :call DoIt('y') 87 call setline(1, 'abc') 88 call cursor(1, 1) 89 call feedkeys("ix\<esc>", 'tnix') 90 call assert_equal(['abxc'], getline(1, '$')) 91 " 2) when not setting v:char, restores changed cursor position 92 au! InsertEnter <buffer> :call DoIt() 93 call setline(1, 'abc') 94 call cursor(1, 1) 95 call feedkeys("ix\<esc>", 'tnix') 96 call assert_equal(['xabc'], getline(1, '$')) 97 au! InsertEnter 98 delfu DoIt 99 bw! 100endfunc 101 102func Test_edit_03() 103 " Change cursor after <c-o> command to end of line 104 new 105 call setline(1, 'abc') 106 call cursor(1, 1) 107 call feedkeys("i\<c-o>$y\<esc>", 'tnix') 108 call assert_equal(['abcy'], getline(1, '$')) 109 %d 110 call setline(1, 'abc') 111 call cursor(1, 1) 112 call feedkeys("i\<c-o>80|y\<esc>", 'tnix') 113 call assert_equal(['abcy'], getline(1, '$')) 114 %d 115 call setline(1, 'abc') 116 call feedkeys("Ad\<c-o>:s/$/efg/\<cr>hij", 'tnix') 117 call assert_equal(['hijabcdefg'], getline(1, '$')) 118 bw! 119endfunc 120 121func Test_edit_04() 122 " test for :stopinsert 123 new 124 call setline(1, 'abc') 125 call cursor(1, 1) 126 call feedkeys("i\<c-o>:stopinsert\<cr>$", 'tnix') 127 call feedkeys("aX\<esc>", 'tnix') 128 call assert_equal(['abcX'], getline(1, '$')) 129 %d 130 bw! 131endfunc 132 133func Test_edit_05() 134 " test for folds being opened 135 new 136 call setline(1, ['abcX', 'abcX', 'zzzZ']) 137 call cursor(1, 1) 138 set foldmethod=manual foldopen+=insert 139 " create fold for those two lines 140 norm! Vjzf 141 call feedkeys("$ay\<esc>", 'tnix') 142 call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) 143 %d 144 call setline(1, ['abcX', 'abcX', 'zzzZ']) 145 call cursor(1, 1) 146 set foldmethod=manual foldopen-=insert 147 " create fold for those two lines 148 norm! Vjzf 149 call feedkeys("$ay\<esc>", 'tnix') 150 call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) 151 %d 152 bw! 153endfunc 154 155func Test_edit_06() 156 " Test in diff mode 157 if !has("diff") || !executable("diff") 158 return 159 endif 160 new 161 call setline(1, ['abc', 'xxx', 'yyy']) 162 vnew 163 call setline(1, ['abc', 'zzz', 'xxx', 'yyy']) 164 wincmd p 165 diffthis 166 wincmd p 167 diffthis 168 wincmd p 169 call cursor(2, 1) 170 norm! zt 171 call feedkeys("Ozzz\<esc>", 'tnix') 172 call assert_equal(['abc', 'zzz', 'xxx', 'yyy'], getline(1,'$')) 173 bw! 174 bw! 175endfunc 176 177func Test_edit_07() 178 " 1) Test with completion <c-l> when popupmenu is visible 179 new 180 call setline(1, 'J') 181 182 func! ListMonths() 183 call complete(col('.')-1, ['January', 'February', 'March', 184 \ 'April', 'May', 'June', 'July', 'August', 'September', 185 \ 'October', 'November', 'December']) 186 return '' 187 endfunc 188 inoremap <buffer> <F5> <C-R>=ListMonths()<CR> 189 190 call feedkeys("A\<f5>\<c-p>". repeat("\<down>", 6)."\<c-l>\<down>\<c-l>\<cr>", 'tx') 191 call assert_equal(['July'], getline(1,'$')) 192 " 1) Test completion when InsertCharPre kicks in 193 %d 194 call setline(1, 'J') 195 fu! DoIt() 196 if v:char=='u' 197 let v:char='an' 198 endif 199 endfu 200 au InsertCharPre <buffer> :call DoIt() 201 call feedkeys("A\<f5>\<c-p>u\<cr>\<c-l>\<cr>", 'tx') 202 call assert_equal(["Jan\<c-l>",''], getline(1,'$')) 203 %d 204 call setline(1, 'J') 205 call feedkeys("A\<f5>\<c-p>u\<down>\<c-l>\<cr>", 'tx') 206 call assert_equal(["January"], getline(1,'$')) 207 208 delfu ListMonths 209 delfu DoIt 210 iunmap <buffer> <f5> 211 bw! 212endfunc 213 214func Test_edit_08() 215 " reset insertmode from i_ctrl-r_= 216 let g:bufnr = bufnr('%') 217 new 218 call setline(1, ['abc']) 219 call cursor(1, 4) 220 call feedkeys(":set im\<cr>ZZZ\<c-r>=setbufvar(g:bufnr,'&im', 0)\<cr>",'tnix') 221 call assert_equal(['abZZZc'], getline(1,'$')) 222 call assert_equal([0, 1, 1, 0], getpos('.')) 223 call assert_false(0, '&im') 224 bw! 225 unlet g:bufnr 226endfunc 227 228func Test_edit_09() 229 " test i_CTRL-\ combinations 230 new 231 call setline(1, ['abc', 'def', 'ghi']) 232 call cursor(1, 1) 233 " 1) CTRL-\ CTLR-N 234 call feedkeys(":set im\<cr>\<c-\>\<c-n>ccABC\<c-l>", 'txin') 235 call assert_equal(['ABC', 'def', 'ghi'], getline(1,'$')) 236 call setline(1, ['ABC', 'def', 'ghi']) 237 " 2) CTRL-\ CTLR-G 238 call feedkeys("j0\<c-\>\<c-g>ZZZ\<cr>\<c-l>", 'txin') 239 call assert_equal(['ABC', 'ZZZ', 'def', 'ghi'], getline(1,'$')) 240 call feedkeys("I\<c-\>\<c-g>YYY\<c-l>", 'txin') 241 call assert_equal(['ABC', 'ZZZ', 'YYYdef', 'ghi'], getline(1,'$')) 242 set noinsertmode 243 " 3) CTRL-\ CTRL-O 244 call setline(1, ['ABC', 'ZZZ', 'def', 'ghi']) 245 call cursor(1, 1) 246 call feedkeys("A\<c-o>ix", 'txin') 247 call assert_equal(['ABxC', 'ZZZ', 'def', 'ghi'], getline(1,'$')) 248 call feedkeys("A\<c-\>\<c-o>ix", 'txin') 249 call assert_equal(['ABxCx', 'ZZZ', 'def', 'ghi'], getline(1,'$')) 250 " 4) CTRL-\ a (should be inserted literally, not special after <c-\> 251 call setline(1, ['ABC', 'ZZZ', 'def', 'ghi']) 252 call cursor(1, 1) 253 call feedkeys("A\<c-\>a", 'txin') 254 call assert_equal(["ABC\<c-\>a", 'ZZZ', 'def', 'ghi'], getline(1, '$')) 255 bw! 256endfunc 257 258func Test_edit_10() 259 " Test for starting selectmode 260 new 261 set selectmode=key keymodel=startsel 262 call setline(1, ['abc', 'def', 'ghi']) 263 call cursor(1, 4) 264 call feedkeys("A\<s-home>start\<esc>", 'txin') 265 call assert_equal(['startdef', 'ghi'], getline(1, '$')) 266 set selectmode= keymodel= 267 bw! 268endfunc 269 270func Test_edit_11() 271 " Test that indenting kicks in 272 new 273 set cindent 274 call setline(1, ['{', '', '']) 275 call cursor(2, 1) 276 call feedkeys("i\<c-f>int c;\<esc>", 'tnix') 277 call cursor(3, 1) 278 call feedkeys("i/* comment */", 'tnix') 279 call assert_equal(['{', "\<tab>int c;", "/* comment */"], getline(1, '$')) 280 " added changed cindentkeys slightly 281 set cindent cinkeys+=*/ 282 call setline(1, ['{', '', '']) 283 call cursor(2, 1) 284 call feedkeys("i\<c-f>int c;\<esc>", 'tnix') 285 call cursor(3, 1) 286 call feedkeys("i/* comment */", 'tnix') 287 call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */"], getline(1, '$')) 288 set cindent cinkeys+==end 289 call feedkeys("oend\<cr>\<esc>", 'tnix') 290 call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */", "\tend", ''], getline(1, '$')) 291 set cinkeys-==end 292 %d 293 " Use indentexpr instead of cindenting 294 func! Do_Indent() 295 if v:lnum == 3 296 return 3*shiftwidth() 297 else 298 return 2*shiftwidth() 299 endif 300 endfunc 301 setl indentexpr=Do_Indent() indentkeys+=*/ 302 call setline(1, ['{', '', '']) 303 call cursor(2, 1) 304 call feedkeys("i\<c-f>int c;\<esc>", 'tnix') 305 call cursor(3, 1) 306 call feedkeys("i/* comment */", 'tnix') 307 call assert_equal(['{', "\<tab>\<tab>int c;", "\<tab>\<tab>\<tab>/* comment */"], getline(1, '$')) 308 set cinkeys&vim indentkeys&vim 309 set nocindent indentexpr= 310 delfu Do_Indent 311 bw! 312endfunc 313 314func Test_edit_11_indentexpr() 315 " Test that indenting kicks in 316 new 317 " Use indentexpr instead of cindenting 318 func! Do_Indent() 319 let pline=prevnonblank(v:lnum) 320 if empty(getline(v:lnum)) 321 if getline(pline) =~ 'if\|then' 322 return shiftwidth() 323 else 324 return 0 325 endif 326 else 327 return 0 328 endif 329 endfunc 330 setl indentexpr=Do_Indent() indentkeys+=0=then,0=fi 331 call setline(1, ['if [ $this ]']) 332 call cursor(1, 1) 333 call feedkeys("othen\<cr>that\<cr>fi", 'tnix') 334 call assert_equal(['if [ $this ]', "then", "\<tab>that", "fi"], getline(1, '$')) 335 set cinkeys&vim indentkeys&vim 336 set nocindent indentexpr= 337 delfu Do_Indent 338 bw! 339endfunc 340 341func Test_edit_12() 342 " Test changing indent in replace mode 343 new 344 call setline(1, ["\tabc", "\tdef"]) 345 call cursor(2, 4) 346 call feedkeys("R^\<c-d>", 'tnix') 347 call assert_equal(["\tabc", "def"], getline(1, '$')) 348 call assert_equal([0, 2, 2, 0], getpos('.')) 349 %d 350 call setline(1, ["\tabc", "\t\tdef"]) 351 call cursor(2, 2) 352 call feedkeys("R^\<c-d>", 'tnix') 353 call assert_equal(["\tabc", "def"], getline(1, '$')) 354 call assert_equal([0, 2, 1, 0], getpos('.')) 355 %d 356 call setline(1, ["\tabc", "\t\tdef"]) 357 call cursor(2, 2) 358 call feedkeys("R\<c-t>", 'tnix') 359 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) 360 call assert_equal([0, 2, 2, 0], getpos('.')) 361 bw! 362 10vnew 363 call setline(1, ["\tabc", "\t\tdef"]) 364 call cursor(2, 2) 365 call feedkeys("R\<c-t>", 'tnix') 366 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) 367 call assert_equal([0, 2, 2, 0], getpos('.')) 368 %d 369 set sw=4 370 call setline(1, ["\tabc", "\t\tdef"]) 371 call cursor(2, 2) 372 call feedkeys("R\<c-t>\<c-t>", 'tnix') 373 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) 374 call assert_equal([0, 2, 2, 0], getpos('.')) 375 %d 376 call setline(1, ["\tabc", "\t\tdef"]) 377 call cursor(2, 2) 378 call feedkeys("R\<c-t>\<c-t>", 'tnix') 379 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) 380 call assert_equal([0, 2, 2, 0], getpos('.')) 381 set et 382 set sw& et& 383 %d 384 call setline(1, ["\t/*"]) 385 set formatoptions=croql 386 call cursor(1, 3) 387 call feedkeys("A\<cr>\<cr>/", 'tnix') 388 call assert_equal(["\t/*", " *", " */"], getline(1, '$')) 389 set formatoptions& 390 bw! 391endfunc 392 393func Test_edit_13() 394 " Test smartindenting 395 if exists("+smartindent") 396 new 397 set smartindent autoindent 398 call setline(1, ["\tabc"]) 399 call feedkeys("A {\<cr>more\<cr>}\<esc>", 'tnix') 400 call assert_equal(["\tabc {", "\t\tmore", "\t}"], getline(1, '$')) 401 set smartindent& autoindent& 402 bwipe! 403 endif 404 405 " Test autoindent removing indent of blank line. 406 new 407 call setline(1, ' foo bar baz') 408 set autoindent 409 exe "normal 0eea\<CR>\<CR>\<Esc>" 410 call assert_equal(" foo bar", getline(1)) 411 call assert_equal("", getline(2)) 412 call assert_equal(" baz", getline(3)) 413 set autoindent& 414 bwipe! 415endfunc 416 417func Test_edit_CR() 418 " Test for <CR> in insert mode 419 " basically only in quickfix mode ist tested, the rest 420 " has been taken care of by other tests 421 if !has("quickfix") 422 return 423 endif 424 botright new 425 call writefile(range(1, 10), 'Xqflist.txt') 426 call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}]) 427 copen 428 set modifiable 429 call feedkeys("A\<cr>", 'tnix') 430 call assert_equal('Xqflist.txt', bufname('')) 431 call assert_equal(2, line('.')) 432 cclose 433 botright new 434 call setloclist(0, [{'filename': 'Xqflist.txt', 'lnum': 10}]) 435 lopen 436 set modifiable 437 call feedkeys("A\<cr>", 'tnix') 438 call assert_equal('Xqflist.txt', bufname('')) 439 call assert_equal(10, line('.')) 440 call feedkeys("A\<Enter>", 'tnix') 441 call feedkeys("A\<kEnter>", 'tnix') 442 call feedkeys("A\n", 'tnix') 443 call feedkeys("A\r", 'tnix') 444 call assert_equal(map(range(1, 10), 'string(v:val)') + ['', '', '', ''], getline(1, '$')) 445 bw! 446 lclose 447 call delete('Xqflist.txt') 448endfunc 449 450func Test_edit_CTRL_() 451 " disabled for Windows builds, why? 452 if !has("rightleft") || has("win32") 453 return 454 endif 455 let _encoding=&encoding 456 set encoding=utf-8 457 " Test for CTRL-_ 458 new 459 call setline(1, ['abc']) 460 call cursor(1, 1) 461 call feedkeys("i\<c-_>xyz\<esc>", 'tnix') 462 call assert_equal(["\<C-_>xyzabc"], getline(1, '$')) 463 call assert_false(&revins) 464 set ari 465 call setline(1, ['abc']) 466 call cursor(1, 1) 467 call feedkeys("i\<c-_>xyz\<esc>", 'tnix') 468 call assert_equal(["æèñabc"], getline(1, '$')) 469 call assert_true(&revins) 470 call setline(1, ['abc']) 471 call cursor(1, 1) 472 call feedkeys("i\<c-_>xyz\<esc>", 'tnix') 473 call assert_equal(["xyzabc"], getline(1, '$')) 474 call assert_false(&revins) 475 set noari 476 let &encoding=_encoding 477 bw! 478endfunc 479 480" needs to come first, to have the @. register empty 481func Test_edit_00a_CTRL_A() 482 " Test pressing CTRL-A 483 new 484 call setline(1, repeat([''], 5)) 485 call cursor(1, 1) 486 try 487 call feedkeys("A\<NUL>", 'tnix') 488 catch /^Vim\%((\a\+)\)\=:E29/ 489 call assert_true(1, 'E29 error caught') 490 endtry 491 call cursor(1, 1) 492 call feedkeys("Afoobar \<esc>", 'tnix') 493 call cursor(2, 1) 494 call feedkeys("A\<c-a>more\<esc>", 'tnix') 495 call cursor(3, 1) 496 call feedkeys("A\<NUL>and more\<esc>", 'tnix') 497 call assert_equal(['foobar ', 'foobar more', 'foobar morend more', '', ''], getline(1, '$')) 498 bw! 499endfunc 500 501func Test_edit_CTRL_EY() 502 " Ctrl-E/ Ctrl-Y in insert mode completion to scroll 503 10new 504 call setline(1, range(1, 100)) 505 call cursor(30, 1) 506 norm! z. 507 call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') 508 call assert_equal(30, winsaveview()['topline']) 509 call assert_equal([0, 30, 2, 0], getpos('.')) 510 call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') 511 call feedkeys("A\<c-x>".repeat("\<c-y>", 10), 'tnix') 512 call assert_equal(21, winsaveview()['topline']) 513 call assert_equal([0, 30, 2, 0], getpos('.')) 514 bw! 515endfunc 516 517func Test_edit_CTRL_G() 518 new 519 call setline(1, ['foobar', 'foobar', 'foobar']) 520 call cursor(2, 4) 521 call feedkeys("ioooooooo\<c-g>k\<c-r>.\<esc>", 'tnix') 522 call assert_equal(['foooooooooobar', 'foooooooooobar', 'foobar'], getline(1, '$')) 523 call assert_equal([0, 1, 11, 0], getpos('.')) 524 call feedkeys("i\<c-g>k\<esc>", 'tnix') 525 call assert_equal([0, 1, 10, 0], getpos('.')) 526 call cursor(2, 4) 527 call feedkeys("i\<c-g>jzzzz\<esc>", 'tnix') 528 call assert_equal(['foooooooooobar', 'foooooooooobar', 'foozzzzbar'], getline(1, '$')) 529 call assert_equal([0, 3, 7, 0], getpos('.')) 530 call feedkeys("i\<c-g>j\<esc>", 'tnix') 531 call assert_equal([0, 3, 6, 0], getpos('.')) 532 bw! 533endfunc 534 535func Test_edit_CTRL_I() 536 " Tab in completion mode 537 let path=expand("%:p:h") 538 new 539 call setline(1, [path. "/", '']) 540 call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix') 541 call assert_match('runtest\.vim', getline(1)) 542 %d 543 call writefile(['one', 'two', 'three'], 'Xinclude.txt') 544 let include='#include Xinclude.txt' 545 call setline(1, [include, '']) 546 call cursor(2, 1) 547 call feedkeys("A\<c-x>\<tab>\<cr>\<esc>", 'tnix') 548 call assert_equal([include, 'one', ''], getline(1, '$')) 549 call feedkeys("2ggC\<c-x>\<tab>\<down>\<cr>\<esc>", 'tnix') 550 call assert_equal([include, 'two', ''], getline(1, '$')) 551 call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix') 552 call assert_equal([include, 'three', ''], getline(1, '$')) 553 call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') 554 call assert_equal([include, '', ''], getline(1, '$')) 555 call delete("Xinclude.txt") 556 bw! 557endfunc 558 559func Test_edit_CTRL_K() 560 " Test pressing CTRL-K (basically only dictionary completion and digraphs 561 " the rest is already covered 562 call writefile(['A', 'AA', 'AAA', 'AAAA'], 'Xdictionary.txt') 563 set dictionary=Xdictionary.txt 564 new 565 call setline(1, 'A') 566 call cursor(1, 1) 567 call feedkeys("A\<c-x>\<c-k>\<cr>\<esc>", 'tnix') 568 call assert_equal(['AA', ''], getline(1, '$')) 569 %d 570 call setline(1, 'A') 571 call cursor(1, 1) 572 call feedkeys("A\<c-x>\<c-k>\<down>\<cr>\<esc>", 'tnix') 573 call assert_equal(['AAA'], getline(1, '$')) 574 %d 575 call setline(1, 'A') 576 call cursor(1, 1) 577 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<cr>\<esc>", 'tnix') 578 call assert_equal(['AAAA'], getline(1, '$')) 579 %d 580 call setline(1, 'A') 581 call cursor(1, 1) 582 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') 583 call assert_equal(['A'], getline(1, '$')) 584 %d 585 call setline(1, 'A') 586 call cursor(1, 1) 587 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') 588 call assert_equal(['AA'], getline(1, '$')) 589 590 " press an unexecpted key after dictionary completion 591 %d 592 call setline(1, 'A') 593 call cursor(1, 1) 594 call feedkeys("A\<c-x>\<c-k>\<c-]>\<cr>\<esc>", 'tnix') 595 call assert_equal(['AA', ''], getline(1, '$')) 596 %d 597 call setline(1, 'A') 598 call cursor(1, 1) 599 call feedkeys("A\<c-x>\<c-k>\<c-s>\<cr>\<esc>", 'tnix') 600 call assert_equal(["AA\<c-s>", ''], getline(1, '$')) 601 %d 602 call setline(1, 'A') 603 call cursor(1, 1) 604 call feedkeys("A\<c-x>\<c-k>\<c-f>\<cr>\<esc>", 'tnix') 605 call assert_equal(["AA\<c-f>", ''], getline(1, '$')) 606 607 set dictionary= 608 %d 609 call setline(1, 'A') 610 call cursor(1, 1) 611 let v:testing = 1 612 try 613 call feedkeys("A\<c-x>\<c-k>\<esc>", 'tnix') 614 catch 615 " error sleeps 2 seconds, when v:testing is not set 616 let v:testing = 0 617 endtry 618 call delete('Xdictionary.txt') 619 620 call test_override("char_avail", 1) 621 set showcmd 622 %d 623 call feedkeys("A\<c-k>a:\<esc>", 'tnix') 624 call assert_equal(['ä'], getline(1, '$')) 625 call test_override("char_avail", 0) 626 set noshowcmd 627 628 bw! 629endfunc 630 631func Test_edit_CTRL_L() 632 " Test Ctrl-X Ctrl-L (line completion) 633 new 634 set complete=. 635 call setline(1, ['one', 'two', 'three', '', '', '', '']) 636 call cursor(4, 1) 637 call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix') 638 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) 639 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix') 640 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) 641 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix') 642 call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) 643 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') 644 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) 645 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') 646 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) 647 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix') 648 call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) 649 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix') 650 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) 651 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix') 652 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) 653 set complete= 654 call cursor(5, 1) 655 call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix') 656 call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$')) 657 set complete& 658 %d 659 if has("conceal") && has("syntax") 660 call setline(1, ['foo', 'bar', 'foobar']) 661 call test_override("char_avail", 1) 662 set conceallevel=2 concealcursor=n 663 syn on 664 syn match ErrorMsg "^bar" 665 call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'}) 666 func! DoIt() 667 let g:change=1 668 endfunc 669 au! TextChangedI <buffer> :call DoIt() 670 671 call cursor(2, 1) 672 call assert_false(exists("g:change")) 673 call feedkeys("A \<esc>", 'tnix') 674 call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$')) 675 call assert_equal(1, g:change) 676 677 call test_override("char_avail", 0) 678 call clearmatches() 679 syn off 680 au! TextChangedI 681 delfu DoIt 682 unlet! g:change 683 endif 684 bw! 685endfunc 686 687func Test_edit_CTRL_N() 688 " Check keyword completion 689 new 690 set complete=. 691 call setline(1, ['INFER', 'loWER', '', '', ]) 692 call cursor(3, 1) 693 call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix") 694 call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') 695 call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$')) 696 %d 697 call setline(1, ['INFER', 'loWER', '', '', ]) 698 call cursor(3, 1) 699 set ignorecase infercase 700 call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix") 701 call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') 702 call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$')) 703 704 set noignorecase noinfercase complete& 705 bw! 706endfunc 707 708func Test_edit_CTRL_O() 709 " Check for CTRL-O in insert mode 710 new 711 inoreabbr <buffer> h here some more 712 call setline(1, ['abc', 'def']) 713 call cursor(1, 1) 714 " Ctrl-O after an abbreviation 715 exe "norm A h\<c-o>:set nu\<cr> text" 716 call assert_equal(['abc here some more text', 'def'], getline(1, '$')) 717 call assert_true(&nu) 718 set nonu 719 iunabbr <buffer> h 720 " Ctrl-O at end of line with 've'=onemore 721 call cursor(1, 1) 722 call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') 723 call assert_equal([0, 1, 23, 0], g:a) 724 call cursor(1, 1) 725 set ve=onemore 726 call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') 727 call assert_equal([0, 1, 24, 0], g:a) 728 set ve= 729 unlet! g:a 730 bw! 731endfunc 732 733func Test_edit_CTRL_R() 734 " Insert Register 735 new 736 call test_override("ALL", 1) 737 set showcmd 738 call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix') 739 call feedkeys("O\<c-r>.", 'tnix') 740 call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix') 741 call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix') 742 call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$')) 743 call test_override("ALL", 0) 744 set noshowcmd 745 bw! 746endfunc 747 748func Test_edit_CTRL_S() 749 " Test pressing CTRL-S (basically only spellfile completion) 750 " the rest is already covered 751 new 752 if !has("spell") 753 call setline(1, 'vim') 754 call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix') 755 call assert_equal(['vims', ''], getline(1, '$')) 756 bw! 757 return 758 endif 759 call setline(1, 'vim') 760 " spell option not yet set 761 try 762 call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') 763 catch /^Vim\%((\a\+)\)\=:E756/ 764 call assert_true(1, 'error caught') 765 endtry 766 call assert_equal(['vim', ''], getline(1, '$')) 767 %d 768 setl spell spelllang=en 769 call setline(1, 'vim') 770 call cursor(1, 1) 771 call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') 772 call assert_equal(['Vim', ''], getline(1, '$')) 773 %d 774 call setline(1, 'vim') 775 call cursor(1, 1) 776 call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix') 777 call assert_equal(['Aim'], getline(1, '$')) 778 %d 779 call setline(1, 'vim') 780 call cursor(1, 1) 781 call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') 782 call assert_equal(['vim', ''], getline(1, '$')) 783 %d 784 " empty buffer 785 call cursor(1, 1) 786 call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') 787 call assert_equal(['', ''], getline(1, '$')) 788 setl nospell 789 bw! 790endfunc 791 792func Test_edit_CTRL_T() 793 " Check for CTRL-T and CTRL-X CTRL-T in insert mode 794 " 1) increase indent 795 new 796 call setline(1, "abc") 797 call cursor(1, 1) 798 call feedkeys("A\<c-t>xyz", 'tnix') 799 call assert_equal(["\<tab>abcxyz"], getline(1, '$')) 800 " 2) also when paste option is set 801 set paste 802 call setline(1, "abc") 803 call cursor(1, 1) 804 call feedkeys("A\<c-t>xyz", 'tnix') 805 call assert_equal(["\<tab>abcxyz"], getline(1, '$')) 806 set nopaste 807 " CTRL-X CTRL-T (thesaurus complete) 808 call writefile(['angry furious mad enraged'], 'Xthesaurus') 809 set thesaurus=Xthesaurus 810 call setline(1, 'mad') 811 call cursor(1, 1) 812 call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix') 813 call assert_equal(['mad', ''], getline(1, '$')) 814 %d 815 call setline(1, 'mad') 816 call cursor(1, 1) 817 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') 818 call assert_equal(['angry', ''], getline(1, '$')) 819 %d 820 call setline(1, 'mad') 821 call cursor(1, 1) 822 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 823 call assert_equal(['furious', ''], getline(1, '$')) 824 %d 825 call setline(1, 'mad') 826 call cursor(1, 1) 827 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 828 call assert_equal(['enraged', ''], getline(1, '$')) 829 %d 830 call setline(1, 'mad') 831 call cursor(1, 1) 832 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 833 call assert_equal(['mad', ''], getline(1, '$')) 834 %d 835 call setline(1, 'mad') 836 call cursor(1, 1) 837 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 838 call assert_equal(['mad', ''], getline(1, '$')) 839 " Using <c-p> <c-n> when 'complete' is empty 840 set complete= 841 %d 842 call setline(1, 'mad') 843 call cursor(1, 1) 844 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') 845 call assert_equal(['angry', ''], getline(1, '$')) 846 %d 847 call setline(1, 'mad') 848 call cursor(1, 1) 849 call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix') 850 call assert_equal(['mad', ''], getline(1, '$')) 851 set complete& 852 853 set thesaurus= 854 %d 855 call setline(1, 'mad') 856 call cursor(1, 1) 857 let v:testing = 1 858 try 859 call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix') 860 catch 861 " error sleeps 2 seconds, when v:testing is not set 862 let v:testing = 0 863 endtry 864 call assert_equal(['mad'], getline(1, '$')) 865 call delete('Xthesaurus') 866 bw! 867endfunc 868 869func Test_edit_CTRL_U() 870 " Test 'completefunc' 871 new 872 " -1, -2 and -3 are special return values 873 let g:special=0 874 fun! CompleteMonths(findstart, base) 875 if a:findstart 876 " locate the start of the word 877 return g:special 878 else 879 " find months matching with "a:base" 880 let res = [] 881 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") 882 if m =~ '^\c'.a:base 883 call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0}) 884 endif 885 endfor 886 return {'words': res, 'refresh': 'always'} 887 endif 888 endfun 889 set completefunc=CompleteMonths 890 call setline(1, ['', '']) 891 call cursor(1, 1) 892 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 893 call assert_equal(['X', '', ''], getline(1, '$')) 894 %d 895 let g:special=-1 896 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 897 call assert_equal(['XJan', ''], getline(1, '$')) 898 %d 899 let g:special=-2 900 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 901 call assert_equal(['X', ''], getline(1, '$')) 902 %d 903 let g:special=-3 904 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 905 call assert_equal(['X', ''], getline(1, '$')) 906 %d 907 let g:special=0 908 call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 909 call assert_equal(['Mar', ''], getline(1, '$')) 910 %d 911 call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix') 912 call assert_equal(['May', ''], getline(1, '$')) 913 %d 914 call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 915 call assert_equal(['M', ''], getline(1, '$')) 916 delfu CompleteMonths 917 %d 918 try 919 call feedkeys("A\<c-x>\<c-u>", 'tnix') 920 call assert_fails(1, 'unknown completion function') 921 catch /^Vim\%((\a\+)\)\=:E117/ 922 call assert_true(1, 'E117 error caught') 923 endtry 924 set completefunc= 925 bw! 926endfunc 927 928func Test_edit_CTRL_Z() 929 " Ctrl-Z when insertmode is not set inserts it literally 930 new 931 call setline(1, 'abc') 932 call feedkeys("A\<c-z>\<esc>", 'tnix') 933 call assert_equal(["abc\<c-z>"], getline(1,'$')) 934 bw! 935 " TODO: How to Test Ctrl-Z in insert mode, e.g. suspend? 936endfunc 937 938func Test_edit_DROP() 939 if !has("dnd") 940 return 941 endif 942 new 943 call setline(1, ['abc def ghi']) 944 call cursor(1, 1) 945 try 946 call feedkeys("i\<Drop>\<Esc>", 'tnix') 947 call assert_fails(1, 'Invalid register name') 948 catch /^Vim\%((\a\+)\)\=:E353/ 949 call assert_true(1, 'error caught') 950 endtry 951 bw! 952endfunc 953 954func Test_edit_CTRL_V() 955 if has("ebcdic") 956 return 957 endif 958 new 959 call setline(1, ['abc']) 960 call cursor(2, 1) 961 " force some redraws 962 set showmode showcmd 963 "call test_override_char_avail(1) 964 call test_override('ALL', 1) 965 call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') 966 call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) 967 968 if has("rightleft") && exists("+rl") 969 set rl 970 call setline(1, ['abc']) 971 call cursor(2, 1) 972 call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') 973 call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) 974 set norl 975 endif 976 977 call test_override('ALL', 0) 978 set noshowmode showcmd 979 bw! 980endfunc 981 982func Test_edit_F1() 983 " Pressing <f1> 984 new 985 call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix') 986 set noinsertmode 987 call assert_equal('help', &buftype) 988 bw 989 bw 990endfunc 991 992func Test_edit_F21() 993 " Pressing <f21> 994 " sends a netbeans command 995 if has("netbeans_intg") 996 new 997 " I have no idea what this is supposed to do :) 998 call feedkeys("A\<F21>\<F1>\<esc>", 'tnix') 999 bw 1000 endif 1001endfunc 1002 1003func Test_edit_HOME_END() 1004 " Test Home/End Keys 1005 new 1006 set foldopen+=hor 1007 call setline(1, ['abc', 'def']) 1008 call cursor(1, 1) 1009 call feedkeys("AX\<Home>Y\<esc>", 'tnix') 1010 call cursor(2, 1) 1011 call feedkeys("iZ\<End>Y\<esc>", 'tnix') 1012 call assert_equal(['YabcX', 'ZdefY'], getline(1, '$')) 1013 1014 set foldopen-=hor 1015 bw! 1016endfunc 1017 1018func Test_edit_INS() 1019 " Test for Pressing <Insert> 1020 new 1021 call setline(1, ['abc', 'def']) 1022 call cursor(1, 1) 1023 call feedkeys("i\<Insert>ZYX>", 'tnix') 1024 call assert_equal(['ZYX>', 'def'], getline(1, '$')) 1025 call setline(1, ['abc', 'def']) 1026 call cursor(1, 1) 1027 call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix') 1028 call assert_equal(['ZYX>bc', 'def'], getline(1, '$')) 1029 bw! 1030endfunc 1031 1032func Test_edit_LEFT_RIGHT() 1033 " Left, Shift-Left, Right, Shift-Right 1034 new 1035 call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX']) 1036 let _ww=&ww 1037 set ww= 1038 call cursor(2, 1) 1039 call feedkeys("i\<left>\<esc>", 'tnix') 1040 call assert_equal([0, 2, 1, 0], getpos('.')) 1041 " Is this a bug, <s-left> does not respect whichwrap option 1042 call feedkeys("i\<s-left>\<esc>", 'tnix') 1043 call assert_equal([0, 1, 8, 0], getpos('.')) 1044 call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix') 1045 call assert_equal([0, 1, 1, 0], getpos('.')) 1046 call feedkeys("i\<right>\<esc>", 'tnix') 1047 call assert_equal([0, 1, 1, 0], getpos('.')) 1048 call feedkeys("i\<right>\<right>\<esc>", 'tnix') 1049 call assert_equal([0, 1, 2, 0], getpos('.')) 1050 call feedkeys("A\<right>\<esc>", 'tnix') 1051 call assert_equal([0, 1, 11, 0], getpos('.')) 1052 call feedkeys("A\<s-right>\<esc>", 'tnix') 1053 call assert_equal([0, 2, 1, 0], getpos('.')) 1054 call feedkeys("i\<s-right>\<esc>", 'tnix') 1055 call assert_equal([0, 2, 4, 0], getpos('.')) 1056 call cursor(3, 11) 1057 call feedkeys("A\<right>\<esc>", 'tnix') 1058 call feedkeys("A\<s-right>\<esc>", 'tnix') 1059 call assert_equal([0, 3, 11, 0], getpos('.')) 1060 call cursor(2, 11) 1061 " <S-Right> does not respect 'whichwrap' option 1062 call feedkeys("A\<s-right>\<esc>", 'tnix') 1063 call assert_equal([0, 3, 1, 0], getpos('.')) 1064 " Check motion when 'whichwrap' contains cursor keys for insert mode 1065 set ww+=[,] 1066 call cursor(2, 1) 1067 call feedkeys("i\<left>\<esc>", 'tnix') 1068 call assert_equal([0, 1, 11, 0], getpos('.')) 1069 call cursor(2, 11) 1070 call feedkeys("A\<right>\<esc>", 'tnix') 1071 call assert_equal([0, 3, 1, 0], getpos('.')) 1072 call cursor(2, 11) 1073 call feedkeys("A\<s-right>\<esc>", 'tnix') 1074 call assert_equal([0, 3, 1, 0], getpos('.')) 1075 let &ww = _ww 1076 bw! 1077endfunc 1078 1079func Test_edit_MOUSE() 1080 " This is a simple test, since we not really using the mouse here 1081 if !has("mouse") 1082 return 1083 endif 1084 10new 1085 call setline(1, range(1, 100)) 1086 call cursor(1, 1) 1087 set mouse=a 1088 call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix') 1089 call assert_equal([0, 4, 1, 0], getpos('.')) 1090 " This should move by one pageDown, but only moves 1091 " by one line when the test is run... 1092 call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix') 1093 call assert_equal([0, 5, 1, 0], getpos('.')) 1094 set nostartofline 1095 call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix') 1096 call assert_equal([0, 6, 1, 0], getpos('.')) 1097 call feedkeys("A\<LeftMouse>\<esc>", 'tnix') 1098 call assert_equal([0, 6, 1, 0], getpos('.')) 1099 call feedkeys("A\<RightMouse>\<esc>", 'tnix') 1100 call assert_equal([0, 6, 1, 0], getpos('.')) 1101 call cursor(1, 100) 1102 norm! zt 1103 " this should move by a screen up, but when the test 1104 " is run, it moves up to the top of the buffer... 1105 call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix') 1106 call assert_equal([0, 1, 1, 0], getpos('.')) 1107 call cursor(1, 30) 1108 norm! zt 1109 call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix') 1110 call assert_equal([0, 1, 1, 0], getpos('.')) 1111 call cursor(1, 30) 1112 norm! zt 1113 call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix') 1114 call assert_equal([0, 1, 1, 0], getpos('.')) 1115 %d 1116 call setline(1, repeat(["12345678901234567890"], 100)) 1117 call cursor(2, 1) 1118 call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix') 1119 call assert_equal([0, 2, 20, 0], getpos('.')) 1120 call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix') 1121 call assert_equal([0, 2, 20, 0], getpos('.')) 1122 call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix') 1123 call assert_equal([0, 2, 20, 0], getpos('.')) 1124 call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix') 1125 call assert_equal([0, 2, 20, 0], getpos('.')) 1126 call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix') 1127 call assert_equal([0, 2, 20, 0], getpos('.')) 1128 call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix') 1129 call assert_equal([0, 2, 20, 0], getpos('.')) 1130 set mouse& startofline 1131 bw! 1132endfunc 1133 1134func Test_edit_PAGEUP_PAGEDOWN() 1135 10new 1136 call setline(1, repeat(['abc def ghi'], 30)) 1137 call cursor(1, 1) 1138 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1139 call assert_equal([0, 9, 1, 0], getpos('.')) 1140 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1141 call assert_equal([0, 17, 1, 0], getpos('.')) 1142 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1143 call assert_equal([0, 25, 1, 0], getpos('.')) 1144 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1145 call assert_equal([0, 30, 1, 0], getpos('.')) 1146 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1147 call assert_equal([0, 30, 1, 0], getpos('.')) 1148 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1149 call assert_equal([0, 29, 1, 0], getpos('.')) 1150 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1151 call assert_equal([0, 21, 1, 0], getpos('.')) 1152 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1153 call assert_equal([0, 13, 1, 0], getpos('.')) 1154 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1155 call assert_equal([0, 5, 1, 0], getpos('.')) 1156 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1157 call assert_equal([0, 5, 11, 0], getpos('.')) 1158 " <S-Up> is the same as <PageUp> 1159 " <S-Down> is the same as <PageDown> 1160 call cursor(1, 1) 1161 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1162 call assert_equal([0, 9, 1, 0], getpos('.')) 1163 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1164 call assert_equal([0, 17, 1, 0], getpos('.')) 1165 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1166 call assert_equal([0, 25, 1, 0], getpos('.')) 1167 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1168 call assert_equal([0, 30, 1, 0], getpos('.')) 1169 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1170 call assert_equal([0, 30, 1, 0], getpos('.')) 1171 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1172 call assert_equal([0, 29, 1, 0], getpos('.')) 1173 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1174 call assert_equal([0, 21, 1, 0], getpos('.')) 1175 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1176 call assert_equal([0, 13, 1, 0], getpos('.')) 1177 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1178 call assert_equal([0, 5, 1, 0], getpos('.')) 1179 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1180 call assert_equal([0, 5, 11, 0], getpos('.')) 1181 set nostartofline 1182 call cursor(30, 11) 1183 norm! zt 1184 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1185 call assert_equal([0, 29, 11, 0], getpos('.')) 1186 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1187 call assert_equal([0, 21, 11, 0], getpos('.')) 1188 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1189 call assert_equal([0, 13, 11, 0], getpos('.')) 1190 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1191 call assert_equal([0, 5, 11, 0], getpos('.')) 1192 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1193 call assert_equal([0, 5, 11, 0], getpos('.')) 1194 call cursor(1, 1) 1195 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1196 call assert_equal([0, 9, 11, 0], getpos('.')) 1197 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1198 call assert_equal([0, 17, 11, 0], getpos('.')) 1199 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1200 call assert_equal([0, 25, 11, 0], getpos('.')) 1201 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1202 call assert_equal([0, 30, 11, 0], getpos('.')) 1203 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1204 call assert_equal([0, 30, 11, 0], getpos('.')) 1205 " <S-Up> is the same as <PageUp> 1206 " <S-Down> is the same as <PageDown> 1207 call cursor(30, 11) 1208 norm! zt 1209 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1210 call assert_equal([0, 29, 11, 0], getpos('.')) 1211 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1212 call assert_equal([0, 21, 11, 0], getpos('.')) 1213 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1214 call assert_equal([0, 13, 11, 0], getpos('.')) 1215 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1216 call assert_equal([0, 5, 11, 0], getpos('.')) 1217 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1218 call assert_equal([0, 5, 11, 0], getpos('.')) 1219 call cursor(1, 1) 1220 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1221 call assert_equal([0, 9, 11, 0], getpos('.')) 1222 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1223 call assert_equal([0, 17, 11, 0], getpos('.')) 1224 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1225 call assert_equal([0, 25, 11, 0], getpos('.')) 1226 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1227 call assert_equal([0, 30, 11, 0], getpos('.')) 1228 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1229 call assert_equal([0, 30, 11, 0], getpos('.')) 1230 bw! 1231endfunc 1232 1233func Test_edit_forbidden() 1234 new 1235 " 1) edit in the sandbox is not allowed 1236 call setline(1, 'a') 1237 com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix') 1238 call assert_fails(':Sandbox', 'E48:') 1239 com! Sandbox :sandbox exe "norm! i\<del>" 1240 call assert_fails(':Sandbox', 'E48:') 1241 delcom Sandbox 1242 call assert_equal(['a'], getline(1,'$')) 1243 " 2) edit with textlock set 1244 fu! DoIt() 1245 call feedkeys("i\<del>\<esc>", 'tnix') 1246 endfu 1247 au InsertCharPre <buffer> :call DoIt() 1248 try 1249 call feedkeys("ix\<esc>", 'tnix') 1250 call assert_fails(1, 'textlock') 1251 catch /^Vim\%((\a\+)\)\=:E523/ " catch E523: not allowed here 1252 endtry 1253 " TODO: Might be a bug: should x really be inserted here 1254 call assert_equal(['xa'], getline(1, '$')) 1255 delfu DoIt 1256 try 1257 call feedkeys("ix\<esc>", 'tnix') 1258 call assert_fails(1, 'unknown function') 1259 catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function 1260 endtry 1261 au! InsertCharPre 1262 " 3) edit when completion is shown 1263 fun! Complete(findstart, base) 1264 if a:findstart 1265 return col('.') 1266 else 1267 call feedkeys("i\<del>\<esc>", 'tnix') 1268 return [] 1269 endif 1270 endfun 1271 set completefunc=Complete 1272 try 1273 call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix') 1274 call assert_fails(1, 'change in complete function') 1275 catch /^Vim\%((\a\+)\)\=:E523/ " catch E523 1276 endtry 1277 delfu Complete 1278 set completefunc= 1279 if has("rightleft") && exists("+fkmap") 1280 " 4) 'R' when 'fkmap' and 'revins' is set. 1281 set revins fkmap 1282 try 1283 normal Ri 1284 call assert_fails(1, "R with 'fkmap' and 'ri' set") 1285 catch 1286 finally 1287 set norevins nofkmap 1288 endtry 1289 endif 1290 bw! 1291endfunc 1292 1293func Test_edit_rightleft() 1294 " Cursor in rightleft mode moves differently 1295 if !exists("+rightleft") 1296 return 1297 endif 1298 call NewWindow(10, 20) 1299 call setline(1, ['abc', 'def', 'ghi']) 1300 call cursor(1, 2) 1301 set rightleft 1302 " Screen looks as expected 1303 let lines = ScreenLines([1, 4], winwidth(0)) 1304 let expect = [ 1305 \" cba", 1306 \" fed", 1307 \" ihg", 1308 \" ~"] 1309 call assert_equal(join(expect, "\n"), join(lines, "\n")) 1310 " 2) right moves to the left 1311 call feedkeys("i\<right>\<esc>x", 'txin') 1312 call assert_equal(['bc', 'def', 'ghi'], getline(1,'$')) 1313 call cursor(1, 2) 1314 call feedkeys("i\<s-right>\<esc>", 'txin') 1315 call cursor(1, 2) 1316 call feedkeys("i\<c-right>\<esc>", 'txin') 1317 " Screen looks as expected 1318 let lines = ScreenLines([1, 4], winwidth(0)) 1319 let expect = [ 1320 \" cb", 1321 \" fed", 1322 \" ihg", 1323 \" ~"] 1324 call assert_equal(join(expect, "\n"), join(lines, "\n")) 1325 " 2) left moves to the right 1326 call setline(1, ['abc', 'def', 'ghi']) 1327 call cursor(1, 2) 1328 call feedkeys("i\<left>\<esc>x", 'txin') 1329 call assert_equal(['ac', 'def', 'ghi'], getline(1,'$')) 1330 call cursor(1, 2) 1331 call feedkeys("i\<s-left>\<esc>", 'txin') 1332 call cursor(1, 2) 1333 call feedkeys("i\<c-left>\<esc>", 'txin') 1334 " Screen looks as expected 1335 let lines = ScreenLines([1, 4], winwidth(0)) 1336 let expect = [ 1337 \" ca", 1338 \" fed", 1339 \" ihg", 1340 \" ~"] 1341 call assert_equal(join(expect, "\n"), join(lines, "\n")) 1342 set norightleft 1343 bw! 1344endfunc 1345 1346func Test_edit_complete_very_long_name() 1347 if !has('unix') 1348 " Long directory names only work on Unix. 1349 return 1350 endif 1351 1352 let dirname = getcwd() . "/Xdir" 1353 let longdirname = dirname . repeat('/' . repeat('d', 255), 4) 1354 try 1355 call mkdir(longdirname, 'p') 1356 catch /E739:/ 1357 " Long directory name probably not supported. 1358 call delete(dirname, 'rf') 1359 return 1360 endtry 1361 1362 " Try to get the Vim window position before setting 'columns', so that we can 1363 " move the window back to where it was. 1364 let winposx = getwinposx() 1365 let winposy = getwinposy() 1366 1367 if winposx >= 0 && winposy >= 0 && !has('gui_running') 1368 " We did get the window position, but xterm may report the wrong numbers. 1369 " Move the window to the reported position and compute any offset. 1370 exe 'winpos ' . winposx . ' ' . winposy 1371 sleep 100m 1372 let x = getwinposx() 1373 if x >= 0 1374 let winposx += winposx - x 1375 endif 1376 let y = getwinposy() 1377 if y >= 0 1378 let winposy += winposy - y 1379 endif 1380 endif 1381 1382 let save_columns = &columns 1383 " Need at least about 1100 columns to reproduce the problem. 1384 set columns=2000 1385 set noswapfile 1386 1387 let longfilename = longdirname . '/' . repeat('a', 255) 1388 call writefile(['Totum', 'Table'], longfilename) 1389 new 1390 exe "next Xfile " . longfilename 1391 exe "normal iT\<C-N>" 1392 1393 bwipe! 1394 exe 'bwipe! ' . longfilename 1395 call delete(dirname, 'rf') 1396 let &columns = save_columns 1397 if winposx >= 0 && winposy >= 0 1398 exe 'winpos ' . winposx . ' ' . winposy 1399 endif 1400 set swapfile& 1401endfunc 1402 1403func Test_edit_backtick() 1404 next a\`b c 1405 call assert_equal('a`b', expand('%')) 1406 next 1407 call assert_equal('c', expand('%')) 1408 call assert_equal('a\`b c', expand('##')) 1409endfunc 1410 1411func Test_edit_quit() 1412 edit foo.txt 1413 split 1414 new 1415 call setline(1, 'hello') 1416 3wincmd w 1417 redraw! 1418 call assert_fails('1q', 'E37:') 1419 bwipe! foo.txt 1420 only 1421endfunc 1422 1423func Test_edit_alt() 1424 " Keeping the cursor line didn't happen when the first line has indent. 1425 new 1426 call setline(1, [' one', 'two', 'three']) 1427 w XAltFile 1428 $ 1429 call assert_equal(3, line('.')) 1430 e Xother 1431 e # 1432 call assert_equal(3, line('.')) 1433 1434 bwipe XAltFile 1435 call delete('XAltFile') 1436endfunc 1437 1438func Test_leave_insert_autocmd() 1439 new 1440 au InsertLeave * let g:did_au = 1 1441 let g:did_au = 0 1442 call feedkeys("afoo\<Esc>", 'tx') 1443 call assert_equal(1, g:did_au) 1444 call assert_equal('foo', getline(1)) 1445 1446 let g:did_au = 0 1447 call feedkeys("Sbar\<C-C>", 'tx') 1448 call assert_equal(0, g:did_au) 1449 call assert_equal('bar', getline(1)) 1450 1451 inoremap x xx<Esc> 1452 let g:did_au = 0 1453 call feedkeys("Saax", 'tx') 1454 call assert_equal(1, g:did_au) 1455 call assert_equal('aaxx', getline(1)) 1456 1457 inoremap x xx<C-C> 1458 let g:did_au = 0 1459 call feedkeys("Sbbx", 'tx') 1460 call assert_equal(0, g:did_au) 1461 call assert_equal('bbxx', getline(1)) 1462 1463 bwipe! 1464 au! InsertLeave 1465 iunmap x 1466endfunc 1467 1468" Test for inserting characters using CTRL-V followed by a number. 1469func Test_edit_special_chars() 1470 new 1471 1472 if has("ebcdic") 1473 let t = "o\<C-V>193\<C-V>xc2\<C-V>o303 \<C-V>90a\<C-V>xfg\<C-V>o578\<Esc>" 1474 else 1475 let t = "o\<C-V>65\<C-V>x42\<C-V>o103 \<C-V>33a\<C-V>xfg\<C-V>o78\<Esc>" 1476 endif 1477 1478 exe "normal " . t 1479 call assert_equal("ABC !a\<C-O>g\<C-G>8", getline(2)) 1480 1481 close! 1482endfunc 1483