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 bw! 403 endif 404endfunc 405 406func Test_edit_CR() 407 " Test for <CR> in insert mode 408 " basically only in quickfix mode ist tested, the rest 409 " has been taken care of by other tests 410 if !has("quickfix") 411 return 412 endif 413 botright new 414 call writefile(range(1, 10), 'Xqflist.txt') 415 call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}]) 416 copen 417 set modifiable 418 call feedkeys("A\<cr>", 'tnix') 419 call assert_equal('Xqflist.txt', bufname('')) 420 call assert_equal(2, line('.')) 421 cclose 422 botright new 423 call setloclist(0, [{'filename': 'Xqflist.txt', 'lnum': 10}]) 424 lopen 425 set modifiable 426 call feedkeys("A\<cr>", 'tnix') 427 call assert_equal('Xqflist.txt', bufname('')) 428 call assert_equal(10, line('.')) 429 call feedkeys("A\<Enter>", 'tnix') 430 call feedkeys("A\<kEnter>", 'tnix') 431 call feedkeys("A\n", 'tnix') 432 call feedkeys("A\r", 'tnix') 433 call assert_equal(map(range(1, 10), 'string(v:val)') + ['', '', '', ''], getline(1, '$')) 434 bw! 435 lclose 436 call delete('Xqflist.txt') 437endfunc 438 439func Test_edit_CTRL_() 440 " disabled for Windows builds, why? 441 if !has("rightleft") || has("win32") 442 return 443 endif 444 let _encoding=&encoding 445 set encoding=utf-8 446 " Test for CTRL-_ 447 new 448 call setline(1, ['abc']) 449 call cursor(1, 1) 450 call feedkeys("i\<c-_>xyz\<esc>", 'tnix') 451 call assert_equal(["\<C-_>xyzabc"], getline(1, '$')) 452 call assert_false(&revins) 453 set ari 454 call setline(1, ['abc']) 455 call cursor(1, 1) 456 call feedkeys("i\<c-_>xyz\<esc>", 'tnix') 457 call assert_equal(["æèñabc"], getline(1, '$')) 458 call assert_true(&revins) 459 call setline(1, ['abc']) 460 call cursor(1, 1) 461 call feedkeys("i\<c-_>xyz\<esc>", 'tnix') 462 call assert_equal(["xyzabc"], getline(1, '$')) 463 call assert_false(&revins) 464 set noari 465 let &encoding=_encoding 466 bw! 467endfunc 468 469" needs to come first, to have the @. register empty 470func Test_edit_00a_CTRL_A() 471 " Test pressing CTRL-A 472 new 473 call setline(1, repeat([''], 5)) 474 call cursor(1, 1) 475 try 476 call feedkeys("A\<NUL>", 'tnix') 477 catch /^Vim\%((\a\+)\)\=:E29/ 478 call assert_true(1, 'E29 error caught') 479 endtry 480 call cursor(1, 1) 481 call feedkeys("Afoobar \<esc>", 'tnix') 482 call cursor(2, 1) 483 call feedkeys("A\<c-a>more\<esc>", 'tnix') 484 call cursor(3, 1) 485 call feedkeys("A\<NUL>and more\<esc>", 'tnix') 486 call assert_equal(['foobar ', 'foobar more', 'foobar morend more', '', ''], getline(1, '$')) 487 bw! 488endfunc 489 490func Test_edit_CTRL_EY() 491 " Ctrl-E/ Ctrl-Y in insert mode completion to scroll 492 10new 493 call setline(1, range(1, 100)) 494 call cursor(30, 1) 495 norm! z. 496 call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') 497 call assert_equal(30, winsaveview()['topline']) 498 call assert_equal([0, 30, 2, 0], getpos('.')) 499 call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') 500 call feedkeys("A\<c-x>".repeat("\<c-y>", 10), 'tnix') 501 call assert_equal(21, winsaveview()['topline']) 502 call assert_equal([0, 30, 2, 0], getpos('.')) 503 bw! 504endfunc 505 506func Test_edit_CTRL_G() 507 new 508 call setline(1, ['foobar', 'foobar', 'foobar']) 509 call cursor(2, 4) 510 call feedkeys("ioooooooo\<c-g>k\<c-r>.\<esc>", 'tnix') 511 call assert_equal(['foooooooooobar', 'foooooooooobar', 'foobar'], getline(1, '$')) 512 call assert_equal([0, 1, 11, 0], getpos('.')) 513 call feedkeys("i\<c-g>k\<esc>", 'tnix') 514 call assert_equal([0, 1, 10, 0], getpos('.')) 515 call cursor(2, 4) 516 call feedkeys("i\<c-g>jzzzz\<esc>", 'tnix') 517 call assert_equal(['foooooooooobar', 'foooooooooobar', 'foozzzzbar'], getline(1, '$')) 518 call assert_equal([0, 3, 7, 0], getpos('.')) 519 call feedkeys("i\<c-g>j\<esc>", 'tnix') 520 call assert_equal([0, 3, 6, 0], getpos('.')) 521 bw! 522endfunc 523 524func Test_edit_CTRL_I() 525 " Tab in completion mode 526 let path=expand("%:p:h") 527 new 528 call setline(1, [path. "/", '']) 529 call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix') 530 call assert_match('runtest\.vim', getline(1)) 531 %d 532 call writefile(['one', 'two', 'three'], 'Xinclude.txt') 533 let include='#include Xinclude.txt' 534 call setline(1, [include, '']) 535 call cursor(2, 1) 536 call feedkeys("A\<c-x>\<tab>\<cr>\<esc>", 'tnix') 537 call assert_equal([include, 'one', ''], getline(1, '$')) 538 call feedkeys("2ggC\<c-x>\<tab>\<down>\<cr>\<esc>", 'tnix') 539 call assert_equal([include, 'two', ''], getline(1, '$')) 540 call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix') 541 call assert_equal([include, 'three', ''], getline(1, '$')) 542 call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') 543 call assert_equal([include, '', ''], getline(1, '$')) 544 call delete("Xinclude.txt") 545 bw! 546endfunc 547 548func Test_edit_CTRL_K() 549 " Test pressing CTRL-K (basically only dictionary completion and digraphs 550 " the rest is already covered 551 call writefile(['A', 'AA', 'AAA', 'AAAA'], 'Xdictionary.txt') 552 set dictionary=Xdictionary.txt 553 new 554 call setline(1, 'A') 555 call cursor(1, 1) 556 call feedkeys("A\<c-x>\<c-k>\<cr>\<esc>", 'tnix') 557 call assert_equal(['AA', ''], getline(1, '$')) 558 %d 559 call setline(1, 'A') 560 call cursor(1, 1) 561 call feedkeys("A\<c-x>\<c-k>\<down>\<cr>\<esc>", 'tnix') 562 call assert_equal(['AAA'], getline(1, '$')) 563 %d 564 call setline(1, 'A') 565 call cursor(1, 1) 566 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<cr>\<esc>", 'tnix') 567 call assert_equal(['AAAA'], getline(1, '$')) 568 %d 569 call setline(1, 'A') 570 call cursor(1, 1) 571 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') 572 call assert_equal(['A'], getline(1, '$')) 573 %d 574 call setline(1, 'A') 575 call cursor(1, 1) 576 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') 577 call assert_equal(['AA'], getline(1, '$')) 578 579 " press an unexecpted key after dictionary completion 580 %d 581 call setline(1, 'A') 582 call cursor(1, 1) 583 call feedkeys("A\<c-x>\<c-k>\<c-]>\<cr>\<esc>", 'tnix') 584 call assert_equal(['AA', ''], getline(1, '$')) 585 %d 586 call setline(1, 'A') 587 call cursor(1, 1) 588 call feedkeys("A\<c-x>\<c-k>\<c-s>\<cr>\<esc>", 'tnix') 589 call assert_equal(["AA\<c-s>", ''], getline(1, '$')) 590 %d 591 call setline(1, 'A') 592 call cursor(1, 1) 593 call feedkeys("A\<c-x>\<c-k>\<c-f>\<cr>\<esc>", 'tnix') 594 call assert_equal(["AA\<c-f>", ''], getline(1, '$')) 595 596 set dictionary= 597 %d 598 call setline(1, 'A') 599 call cursor(1, 1) 600 let v:testing = 1 601 try 602 call feedkeys("A\<c-x>\<c-k>\<esc>", 'tnix') 603 catch 604 " error sleeps 2 seconds, when v:testing is not set 605 let v:testing = 0 606 endtry 607 call delete('Xdictionary.txt') 608 609 call test_override("char_avail", 1) 610 set showcmd 611 %d 612 call feedkeys("A\<c-k>a:\<esc>", 'tnix') 613 call assert_equal(['ä'], getline(1, '$')) 614 call test_override("char_avail", 0) 615 set noshowcmd 616 617 bw! 618endfunc 619 620func Test_edit_CTRL_L() 621 " Test Ctrl-X Ctrl-L (line completion) 622 new 623 set complete=. 624 call setline(1, ['one', 'two', 'three', '', '', '', '']) 625 call cursor(4, 1) 626 call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix') 627 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) 628 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix') 629 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) 630 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix') 631 call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) 632 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') 633 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) 634 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') 635 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) 636 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix') 637 call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) 638 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix') 639 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) 640 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix') 641 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) 642 set complete= 643 call cursor(5, 1) 644 call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix') 645 call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$')) 646 set complete& 647 %d 648 if has("conceal") && has("syntax") 649 call setline(1, ['foo', 'bar', 'foobar']) 650 call test_override("char_avail", 1) 651 set conceallevel=2 concealcursor=n 652 syn on 653 syn match ErrorMsg "^bar" 654 call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'}) 655 func! DoIt() 656 let g:change=1 657 endfunc 658 au! TextChangedI <buffer> :call DoIt() 659 660 call cursor(2, 1) 661 call assert_false(exists("g:change")) 662 call feedkeys("A \<esc>", 'tnix') 663 call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$')) 664 call assert_equal(1, g:change) 665 666 call test_override("char_avail", 0) 667 call clearmatches() 668 syn off 669 au! TextChangedI 670 delfu DoIt 671 unlet! g:change 672 endif 673 bw! 674endfunc 675 676func Test_edit_CTRL_N() 677 " Check keyword completion 678 new 679 set complete=. 680 call setline(1, ['INFER', 'loWER', '', '', ]) 681 call cursor(3, 1) 682 call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix") 683 call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') 684 call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$')) 685 %d 686 call setline(1, ['INFER', 'loWER', '', '', ]) 687 call cursor(3, 1) 688 set ignorecase infercase 689 call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix") 690 call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') 691 call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$')) 692 693 set noignorecase noinfercase complete& 694 bw! 695endfunc 696 697func Test_edit_CTRL_O() 698 " Check for CTRL-O in insert mode 699 new 700 inoreabbr <buffer> h here some more 701 call setline(1, ['abc', 'def']) 702 call cursor(1, 1) 703 " Ctrl-O after an abbreviation 704 exe "norm A h\<c-o>:set nu\<cr> text" 705 call assert_equal(['abc here some more text', 'def'], getline(1, '$')) 706 call assert_true(&nu) 707 set nonu 708 iunabbr <buffer> h 709 " Ctrl-O at end of line with 've'=onemore 710 call cursor(1, 1) 711 call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') 712 call assert_equal([0, 1, 23, 0], g:a) 713 call cursor(1, 1) 714 set ve=onemore 715 call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') 716 call assert_equal([0, 1, 24, 0], g:a) 717 set ve= 718 unlet! g:a 719 bw! 720endfunc 721 722func Test_edit_CTRL_R() 723 " Insert Register 724 new 725 call test_override("ALL", 1) 726 set showcmd 727 call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix') 728 call feedkeys("O\<c-r>.", 'tnix') 729 call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix') 730 call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix') 731 call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$')) 732 call test_override("ALL", 0) 733 set noshowcmd 734 bw! 735endfunc 736 737func Test_edit_CTRL_S() 738 " Test pressing CTRL-S (basically only spellfile completion) 739 " the rest is already covered 740 new 741 if !has("spell") 742 call setline(1, 'vim') 743 call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix') 744 call assert_equal(['vims', ''], getline(1, '$')) 745 bw! 746 return 747 endif 748 call setline(1, 'vim') 749 " spell option not yet set 750 try 751 call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') 752 catch /^Vim\%((\a\+)\)\=:E756/ 753 call assert_true(1, 'error caught') 754 endtry 755 call assert_equal(['vim', ''], getline(1, '$')) 756 %d 757 setl spell spelllang=en 758 call setline(1, 'vim') 759 call cursor(1, 1) 760 call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') 761 call assert_equal(['Vim', ''], getline(1, '$')) 762 %d 763 call setline(1, 'vim') 764 call cursor(1, 1) 765 call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix') 766 call assert_equal(['Aim'], getline(1, '$')) 767 %d 768 call setline(1, 'vim') 769 call cursor(1, 1) 770 call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') 771 call assert_equal(['vim', ''], getline(1, '$')) 772 %d 773 " empty buffer 774 call cursor(1, 1) 775 call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') 776 call assert_equal(['', ''], getline(1, '$')) 777 setl nospell 778 bw! 779endfunc 780 781func Test_edit_CTRL_T() 782 " Check for CTRL-T and CTRL-X CTRL-T in insert mode 783 " 1) increase indent 784 new 785 call setline(1, "abc") 786 call cursor(1, 1) 787 call feedkeys("A\<c-t>xyz", 'tnix') 788 call assert_equal(["\<tab>abcxyz"], getline(1, '$')) 789 " 2) also when paste option is set 790 set paste 791 call setline(1, "abc") 792 call cursor(1, 1) 793 call feedkeys("A\<c-t>xyz", 'tnix') 794 call assert_equal(["\<tab>abcxyz"], getline(1, '$')) 795 set nopaste 796 " CTRL-X CTRL-T (thesaurus complete) 797 call writefile(['angry furious mad enraged'], 'Xthesaurus') 798 set thesaurus=Xthesaurus 799 call setline(1, 'mad') 800 call cursor(1, 1) 801 call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix') 802 call assert_equal(['mad', ''], getline(1, '$')) 803 %d 804 call setline(1, 'mad') 805 call cursor(1, 1) 806 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') 807 call assert_equal(['angry', ''], getline(1, '$')) 808 %d 809 call setline(1, 'mad') 810 call cursor(1, 1) 811 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 812 call assert_equal(['furious', ''], getline(1, '$')) 813 %d 814 call setline(1, 'mad') 815 call cursor(1, 1) 816 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 817 call assert_equal(['enraged', ''], getline(1, '$')) 818 %d 819 call setline(1, 'mad') 820 call cursor(1, 1) 821 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 822 call assert_equal(['mad', ''], getline(1, '$')) 823 %d 824 call setline(1, 'mad') 825 call cursor(1, 1) 826 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 827 call assert_equal(['mad', ''], getline(1, '$')) 828 " Using <c-p> <c-n> when 'complete' is empty 829 set complete= 830 %d 831 call setline(1, 'mad') 832 call cursor(1, 1) 833 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') 834 call assert_equal(['angry', ''], getline(1, '$')) 835 %d 836 call setline(1, 'mad') 837 call cursor(1, 1) 838 call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix') 839 call assert_equal(['mad', ''], getline(1, '$')) 840 set complete& 841 842 set thesaurus= 843 %d 844 call setline(1, 'mad') 845 call cursor(1, 1) 846 let v:testing = 1 847 try 848 call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix') 849 catch 850 " error sleeps 2 seconds, when v:testing is not set 851 let v:testing = 0 852 endtry 853 call assert_equal(['mad'], getline(1, '$')) 854 call delete('Xthesaurus') 855 bw! 856endfunc 857 858func Test_edit_CTRL_U() 859 " Test 'completefunc' 860 new 861 " -1, -2 and -3 are special return values 862 let g:special=0 863 fun! CompleteMonths(findstart, base) 864 if a:findstart 865 " locate the start of the word 866 return g:special 867 else 868 " find months matching with "a:base" 869 let res = [] 870 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") 871 if m =~ '^\c'.a:base 872 call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0}) 873 endif 874 endfor 875 return {'words': res, 'refresh': 'always'} 876 endif 877 endfun 878 set completefunc=CompleteMonths 879 call setline(1, ['', '']) 880 call cursor(1, 1) 881 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 882 call assert_equal(['X', '', ''], getline(1, '$')) 883 %d 884 let g:special=-1 885 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 886 call assert_equal(['XJan', ''], getline(1, '$')) 887 %d 888 let g:special=-2 889 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 890 call assert_equal(['X', ''], getline(1, '$')) 891 %d 892 let g:special=-3 893 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 894 call assert_equal(['X', ''], getline(1, '$')) 895 %d 896 let g:special=0 897 call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix') 898 call assert_equal(['Mar', ''], getline(1, '$')) 899 %d 900 call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix') 901 call assert_equal(['May', ''], getline(1, '$')) 902 %d 903 call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') 904 call assert_equal(['M', ''], getline(1, '$')) 905 delfu CompleteMonths 906 %d 907 try 908 call feedkeys("A\<c-x>\<c-u>", 'tnix') 909 call assert_fails(1, 'unknown completion function') 910 catch /^Vim\%((\a\+)\)\=:E117/ 911 call assert_true(1, 'E117 error caught') 912 endtry 913 set completefunc= 914 bw! 915endfunc 916 917func Test_edit_CTRL_Z() 918 " Ctrl-Z when insertmode is not set inserts it literally 919 new 920 call setline(1, 'abc') 921 call feedkeys("A\<c-z>\<esc>", 'tnix') 922 call assert_equal(["abc\<c-z>"], getline(1,'$')) 923 bw! 924 " TODO: How to Test Ctrl-Z in insert mode, e.g. suspend? 925endfunc 926 927func Test_edit_DROP() 928 if !has("dnd") 929 return 930 endif 931 new 932 call setline(1, ['abc def ghi']) 933 call cursor(1, 1) 934 try 935 call feedkeys("i\<Drop>\<Esc>", 'tnix') 936 call assert_fails(1, 'Invalid register name') 937 catch /^Vim\%((\a\+)\)\=:E353/ 938 call assert_true(1, 'error caught') 939 endtry 940 bw! 941endfunc 942 943func Test_edit_CTRL_V() 944 if has("ebcdic") 945 return 946 endif 947 new 948 call setline(1, ['abc']) 949 call cursor(2, 1) 950 " force some redraws 951 set showmode showcmd 952 "call test_override_char_avail(1) 953 call test_override('ALL', 1) 954 call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') 955 call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) 956 957 if has("rightleft") && exists("+rl") 958 set rl 959 call setline(1, ['abc']) 960 call cursor(2, 1) 961 call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') 962 call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) 963 set norl 964 endif 965 966 call test_override('ALL', 0) 967 set noshowmode showcmd 968 bw! 969endfunc 970 971func Test_edit_F1() 972 " Pressing <f1> 973 new 974 call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix') 975 set noinsertmode 976 call assert_equal('help', &buftype) 977 bw 978 bw 979endfunc 980 981func Test_edit_F21() 982 " Pressing <f21> 983 " sends a netbeans command 984 if has("netbeans_intg") 985 new 986 " I have no idea what this is supposed to do :) 987 call feedkeys("A\<F21>\<F1>\<esc>", 'tnix') 988 bw 989 endif 990endfunc 991 992func Test_edit_HOME_END() 993 " Test Home/End Keys 994 new 995 set foldopen+=hor 996 call setline(1, ['abc', 'def']) 997 call cursor(1, 1) 998 call feedkeys("AX\<Home>Y\<esc>", 'tnix') 999 call cursor(2, 1) 1000 call feedkeys("iZ\<End>Y\<esc>", 'tnix') 1001 call assert_equal(['YabcX', 'ZdefY'], getline(1, '$')) 1002 1003 set foldopen-=hor 1004 bw! 1005endfunc 1006 1007func Test_edit_INS() 1008 " Test for Pressing <Insert> 1009 new 1010 call setline(1, ['abc', 'def']) 1011 call cursor(1, 1) 1012 call feedkeys("i\<Insert>ZYX>", 'tnix') 1013 call assert_equal(['ZYX>', 'def'], getline(1, '$')) 1014 call setline(1, ['abc', 'def']) 1015 call cursor(1, 1) 1016 call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix') 1017 call assert_equal(['ZYX>bc', 'def'], getline(1, '$')) 1018 bw! 1019endfunc 1020 1021func Test_edit_LEFT_RIGHT() 1022 " Left, Shift-Left, Right, Shift-Right 1023 new 1024 call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX']) 1025 let _ww=&ww 1026 set ww= 1027 call cursor(2, 1) 1028 call feedkeys("i\<left>\<esc>", 'tnix') 1029 call assert_equal([0, 2, 1, 0], getpos('.')) 1030 " Is this a bug, <s-left> does not respect whichwrap option 1031 call feedkeys("i\<s-left>\<esc>", 'tnix') 1032 call assert_equal([0, 1, 8, 0], getpos('.')) 1033 call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix') 1034 call assert_equal([0, 1, 1, 0], getpos('.')) 1035 call feedkeys("i\<right>\<esc>", 'tnix') 1036 call assert_equal([0, 1, 1, 0], getpos('.')) 1037 call feedkeys("i\<right>\<right>\<esc>", 'tnix') 1038 call assert_equal([0, 1, 2, 0], getpos('.')) 1039 call feedkeys("A\<right>\<esc>", 'tnix') 1040 call assert_equal([0, 1, 11, 0], getpos('.')) 1041 call feedkeys("A\<s-right>\<esc>", 'tnix') 1042 call assert_equal([0, 2, 1, 0], getpos('.')) 1043 call feedkeys("i\<s-right>\<esc>", 'tnix') 1044 call assert_equal([0, 2, 4, 0], getpos('.')) 1045 call cursor(3, 11) 1046 call feedkeys("A\<right>\<esc>", 'tnix') 1047 call feedkeys("A\<s-right>\<esc>", 'tnix') 1048 call assert_equal([0, 3, 11, 0], getpos('.')) 1049 call cursor(2, 11) 1050 " <S-Right> does not respect 'whichwrap' option 1051 call feedkeys("A\<s-right>\<esc>", 'tnix') 1052 call assert_equal([0, 3, 1, 0], getpos('.')) 1053 " Check motion when 'whichwrap' contains cursor keys for insert mode 1054 set ww+=[,] 1055 call cursor(2, 1) 1056 call feedkeys("i\<left>\<esc>", 'tnix') 1057 call assert_equal([0, 1, 11, 0], getpos('.')) 1058 call cursor(2, 11) 1059 call feedkeys("A\<right>\<esc>", 'tnix') 1060 call assert_equal([0, 3, 1, 0], getpos('.')) 1061 call cursor(2, 11) 1062 call feedkeys("A\<s-right>\<esc>", 'tnix') 1063 call assert_equal([0, 3, 1, 0], getpos('.')) 1064 let &ww = _ww 1065 bw! 1066endfunc 1067 1068func Test_edit_MOUSE() 1069 " This is a simple test, since we not really using the mouse here 1070 if !has("mouse") 1071 return 1072 endif 1073 10new 1074 call setline(1, range(1, 100)) 1075 call cursor(1, 1) 1076 set mouse=a 1077 call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix') 1078 call assert_equal([0, 4, 1, 0], getpos('.')) 1079 " This should move by one pageDown, but only moves 1080 " by one line when the test is run... 1081 call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix') 1082 call assert_equal([0, 5, 1, 0], getpos('.')) 1083 set nostartofline 1084 call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix') 1085 call assert_equal([0, 6, 1, 0], getpos('.')) 1086 call feedkeys("A\<LeftMouse>\<esc>", 'tnix') 1087 call assert_equal([0, 6, 1, 0], getpos('.')) 1088 call feedkeys("A\<RightMouse>\<esc>", 'tnix') 1089 call assert_equal([0, 6, 1, 0], getpos('.')) 1090 call cursor(1, 100) 1091 norm! zt 1092 " this should move by a screen up, but when the test 1093 " is run, it moves up to the top of the buffer... 1094 call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix') 1095 call assert_equal([0, 1, 1, 0], getpos('.')) 1096 call cursor(1, 30) 1097 norm! zt 1098 call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix') 1099 call assert_equal([0, 1, 1, 0], getpos('.')) 1100 call cursor(1, 30) 1101 norm! zt 1102 call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix') 1103 call assert_equal([0, 1, 1, 0], getpos('.')) 1104 %d 1105 call setline(1, repeat(["12345678901234567890"], 100)) 1106 call cursor(2, 1) 1107 call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix') 1108 call assert_equal([0, 2, 20, 0], getpos('.')) 1109 call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix') 1110 call assert_equal([0, 2, 20, 0], getpos('.')) 1111 call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix') 1112 call assert_equal([0, 2, 20, 0], getpos('.')) 1113 call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix') 1114 call assert_equal([0, 2, 20, 0], getpos('.')) 1115 call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix') 1116 call assert_equal([0, 2, 20, 0], getpos('.')) 1117 call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix') 1118 call assert_equal([0, 2, 20, 0], getpos('.')) 1119 set mouse& startofline 1120 bw! 1121endfunc 1122 1123func Test_edit_PAGEUP_PAGEDOWN() 1124 10new 1125 call setline(1, repeat(['abc def ghi'], 30)) 1126 call cursor(1, 1) 1127 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1128 call assert_equal([0, 9, 1, 0], getpos('.')) 1129 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1130 call assert_equal([0, 17, 1, 0], getpos('.')) 1131 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1132 call assert_equal([0, 25, 1, 0], getpos('.')) 1133 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1134 call assert_equal([0, 30, 1, 0], getpos('.')) 1135 call feedkeys("i\<PageDown>\<esc>", 'tnix') 1136 call assert_equal([0, 30, 1, 0], getpos('.')) 1137 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1138 call assert_equal([0, 29, 1, 0], getpos('.')) 1139 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1140 call assert_equal([0, 21, 1, 0], getpos('.')) 1141 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1142 call assert_equal([0, 13, 1, 0], getpos('.')) 1143 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1144 call assert_equal([0, 5, 1, 0], getpos('.')) 1145 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1146 call assert_equal([0, 5, 11, 0], getpos('.')) 1147 " <S-Up> is the same as <PageUp> 1148 " <S-Down> is the same as <PageDown> 1149 call cursor(1, 1) 1150 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1151 call assert_equal([0, 9, 1, 0], getpos('.')) 1152 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1153 call assert_equal([0, 17, 1, 0], getpos('.')) 1154 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1155 call assert_equal([0, 25, 1, 0], getpos('.')) 1156 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1157 call assert_equal([0, 30, 1, 0], getpos('.')) 1158 call feedkeys("i\<S-Down>\<esc>", 'tnix') 1159 call assert_equal([0, 30, 1, 0], getpos('.')) 1160 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1161 call assert_equal([0, 29, 1, 0], getpos('.')) 1162 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1163 call assert_equal([0, 21, 1, 0], getpos('.')) 1164 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1165 call assert_equal([0, 13, 1, 0], getpos('.')) 1166 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1167 call assert_equal([0, 5, 1, 0], getpos('.')) 1168 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1169 call assert_equal([0, 5, 11, 0], getpos('.')) 1170 set nostartofline 1171 call cursor(30, 11) 1172 norm! zt 1173 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1174 call assert_equal([0, 29, 11, 0], getpos('.')) 1175 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1176 call assert_equal([0, 21, 11, 0], getpos('.')) 1177 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1178 call assert_equal([0, 13, 11, 0], getpos('.')) 1179 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1180 call assert_equal([0, 5, 11, 0], getpos('.')) 1181 call feedkeys("A\<PageUp>\<esc>", 'tnix') 1182 call assert_equal([0, 5, 11, 0], getpos('.')) 1183 call cursor(1, 1) 1184 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1185 call assert_equal([0, 9, 11, 0], getpos('.')) 1186 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1187 call assert_equal([0, 17, 11, 0], getpos('.')) 1188 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1189 call assert_equal([0, 25, 11, 0], getpos('.')) 1190 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1191 call assert_equal([0, 30, 11, 0], getpos('.')) 1192 call feedkeys("A\<PageDown>\<esc>", 'tnix') 1193 call assert_equal([0, 30, 11, 0], getpos('.')) 1194 " <S-Up> is the same as <PageUp> 1195 " <S-Down> is the same as <PageDown> 1196 call cursor(30, 11) 1197 norm! zt 1198 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1199 call assert_equal([0, 29, 11, 0], getpos('.')) 1200 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1201 call assert_equal([0, 21, 11, 0], getpos('.')) 1202 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1203 call assert_equal([0, 13, 11, 0], getpos('.')) 1204 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1205 call assert_equal([0, 5, 11, 0], getpos('.')) 1206 call feedkeys("A\<S-Up>\<esc>", 'tnix') 1207 call assert_equal([0, 5, 11, 0], getpos('.')) 1208 call cursor(1, 1) 1209 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1210 call assert_equal([0, 9, 11, 0], getpos('.')) 1211 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1212 call assert_equal([0, 17, 11, 0], getpos('.')) 1213 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1214 call assert_equal([0, 25, 11, 0], getpos('.')) 1215 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1216 call assert_equal([0, 30, 11, 0], getpos('.')) 1217 call feedkeys("A\<S-Down>\<esc>", 'tnix') 1218 call assert_equal([0, 30, 11, 0], getpos('.')) 1219 bw! 1220endfunc 1221 1222func Test_edit_forbidden() 1223 new 1224 " 1) edit in the sandbox is not allowed 1225 call setline(1, 'a') 1226 com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix') 1227 call assert_fails(':Sandbox', 'E48:') 1228 com! Sandbox :sandbox exe "norm! i\<del>" 1229 call assert_fails(':Sandbox', 'E48:') 1230 delcom Sandbox 1231 call assert_equal(['a'], getline(1,'$')) 1232 " 2) edit with textlock set 1233 fu! DoIt() 1234 call feedkeys("i\<del>\<esc>", 'tnix') 1235 endfu 1236 au InsertCharPre <buffer> :call DoIt() 1237 try 1238 call feedkeys("ix\<esc>", 'tnix') 1239 call assert_fails(1, 'textlock') 1240 catch /^Vim\%((\a\+)\)\=:E523/ " catch E523: not allowed here 1241 endtry 1242 " TODO: Might be a bug: should x really be inserted here 1243 call assert_equal(['xa'], getline(1, '$')) 1244 delfu DoIt 1245 try 1246 call feedkeys("ix\<esc>", 'tnix') 1247 call assert_fails(1, 'unknown function') 1248 catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function 1249 endtry 1250 au! InsertCharPre 1251 " 3) edit when completion is shown 1252 fun! Complete(findstart, base) 1253 if a:findstart 1254 return col('.') 1255 else 1256 call feedkeys("i\<del>\<esc>", 'tnix') 1257 return [] 1258 endif 1259 endfun 1260 set completefunc=Complete 1261 try 1262 call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix') 1263 call assert_fails(1, 'change in complete function') 1264 catch /^Vim\%((\a\+)\)\=:E523/ " catch E523 1265 endtry 1266 delfu Complete 1267 set completefunc= 1268 if has("rightleft") && exists("+fkmap") 1269 " 4) 'R' when 'fkmap' and 'revins' is set. 1270 set revins fkmap 1271 try 1272 normal Ri 1273 call assert_fails(1, "R with 'fkmap' and 'ri' set") 1274 catch 1275 finally 1276 set norevins nofkmap 1277 endtry 1278 endif 1279 bw! 1280endfunc 1281 1282func Test_edit_rightleft() 1283 " Cursor in rightleft mode moves differently 1284 if !exists("+rightleft") 1285 return 1286 endif 1287 call NewWindow(10, 20) 1288 call setline(1, ['abc', 'def', 'ghi']) 1289 call cursor(1, 2) 1290 set rightleft 1291 " Screen looks as expected 1292 let lines = ScreenLines([1, 4], winwidth(0)) 1293 let expect = [ 1294 \" cba", 1295 \" fed", 1296 \" ihg", 1297 \" ~"] 1298 call assert_equal(join(expect, "\n"), join(lines, "\n")) 1299 " 2) right moves to the left 1300 call feedkeys("i\<right>\<esc>x", 'txin') 1301 call assert_equal(['bc', 'def', 'ghi'], getline(1,'$')) 1302 call cursor(1, 2) 1303 call feedkeys("i\<s-right>\<esc>", 'txin') 1304 call cursor(1, 2) 1305 call feedkeys("i\<c-right>\<esc>", 'txin') 1306 " Screen looks as expected 1307 let lines = ScreenLines([1, 4], winwidth(0)) 1308 let expect = [ 1309 \" cb", 1310 \" fed", 1311 \" ihg", 1312 \" ~"] 1313 call assert_equal(join(expect, "\n"), join(lines, "\n")) 1314 " 2) left moves to the right 1315 call setline(1, ['abc', 'def', 'ghi']) 1316 call cursor(1, 2) 1317 call feedkeys("i\<left>\<esc>x", 'txin') 1318 call assert_equal(['ac', 'def', 'ghi'], getline(1,'$')) 1319 call cursor(1, 2) 1320 call feedkeys("i\<s-left>\<esc>", 'txin') 1321 call cursor(1, 2) 1322 call feedkeys("i\<c-left>\<esc>", 'txin') 1323 " Screen looks as expected 1324 let lines = ScreenLines([1, 4], winwidth(0)) 1325 let expect = [ 1326 \" ca", 1327 \" fed", 1328 \" ihg", 1329 \" ~"] 1330 call assert_equal(join(expect, "\n"), join(lines, "\n")) 1331 set norightleft 1332 bw! 1333endfunc 1334 1335func Test_edit_complete_very_long_name() 1336 if !has('unix') 1337 " Long directory names only work on Unix. 1338 return 1339 endif 1340 1341 let dirname = getcwd() . "/Xdir" 1342 let longdirname = dirname . repeat('/' . repeat('d', 255), 4) 1343 try 1344 call mkdir(longdirname, 'p') 1345 catch /E739:/ 1346 " Long directory name probably not supported. 1347 call delete(dirname, 'rf') 1348 return 1349 endtry 1350 1351 " Try to get the Vim window position before setting 'columns'. 1352 let winposx = getwinposx() 1353 let winposy = getwinposy() 1354 let save_columns = &columns 1355 " Need at least about 1100 columns to reproduce the problem. 1356 set columns=2000 1357 set noswapfile 1358 1359 let longfilename = longdirname . '/' . repeat('a', 255) 1360 call writefile(['Totum', 'Table'], longfilename) 1361 new 1362 exe "next Xfile " . longfilename 1363 exe "normal iT\<C-N>" 1364 1365 bwipe! 1366 exe 'bwipe! ' . longfilename 1367 call delete(dirname, 'rf') 1368 let &columns = save_columns 1369 if winposx >= 0 && winposy >= 0 1370 exe 'winpos ' . winposx . ' ' . winposy 1371 endif 1372 set swapfile& 1373endfunc 1374 1375func Test_edit_backtick() 1376 next a\`b c 1377 call assert_equal('a`b', expand('%')) 1378 next 1379 call assert_equal('c', expand('%')) 1380 call assert_equal('a\`b c', expand('##')) 1381endfunc 1382 1383func Test_edit_quit() 1384 edit foo.txt 1385 split 1386 new 1387 call setline(1, 'hello') 1388 3wincmd w 1389 redraw! 1390 call assert_fails('1q', 'E37:') 1391 bwipe! foo.txt 1392 only 1393endfunc 1394 1395func Test_edit_alt() 1396 " Keeping the cursor line didn't happen when the first line has indent. 1397 new 1398 call setline(1, [' one', 'two', 'three']) 1399 w XAltFile 1400 $ 1401 call assert_equal(3, line('.')) 1402 e Xother 1403 e # 1404 call assert_equal(3, line('.')) 1405 1406 bwipe XAltFile 1407 call delete('XAltFile') 1408endfunc 1409 1410func Test_leave_insert_autocmd() 1411 new 1412 au InsertLeave * let g:did_au = 1 1413 let g:did_au = 0 1414 call feedkeys("afoo\<Esc>", 'tx') 1415 call assert_equal(1, g:did_au) 1416 call assert_equal('foo', getline(1)) 1417 1418 let g:did_au = 0 1419 call feedkeys("Sbar\<C-C>", 'tx') 1420 call assert_equal(0, g:did_au) 1421 call assert_equal('bar', getline(1)) 1422 1423 inoremap x xx<Esc> 1424 let g:did_au = 0 1425 call feedkeys("Saax", 'tx') 1426 call assert_equal(1, g:did_au) 1427 call assert_equal('aaxx', getline(1)) 1428 1429 inoremap x xx<C-C> 1430 let g:did_au = 0 1431 call feedkeys("Sbbx", 'tx') 1432 call assert_equal(0, g:did_au) 1433 call assert_equal('bbxx', getline(1)) 1434 1435 bwipe! 1436 au! InsertLeave 1437 iunmap x 1438endfunc 1439