Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1 | " Test for edit functions |
| 2 | " |
| 3 | if exists("+t_kD") |
| 4 | let &t_kD="[3;*~" |
| 5 | endif |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 6 | |
| 7 | " Needed for testing basic rightleft: Test_edit_rightleft |
| 8 | source 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 |
| 12 | func! 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! |
| 22 | endfunc |
| 23 | |
| 24 | func! Test_edit_01() |
| 25 | " set for Travis CI? |
| 26 | " set nocp noesckeys |
| 27 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 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 | if has("multi_byte") |
| 41 | call setline(1, "\u0401") |
| 42 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 43 | call assert_equal([''], getline(1,'$')) |
| 44 | %d |
| 45 | endif |
| 46 | " 5.1) delete linebreak with 'bs' option containing eol |
| 47 | let _bs=&bs |
| 48 | set bs=eol |
| 49 | call setline(1, ["abc def", "ghi jkl"]) |
| 50 | call cursor(1, 1) |
| 51 | call feedkeys("A\<del>\<esc>", 'tnix') |
| 52 | call assert_equal(['abc defghi jkl'], getline(1, 2)) |
| 53 | %d |
| 54 | " 5.2) delete linebreak with backspace option w/out eol |
| 55 | set bs= |
| 56 | call setline(1, ["abc def", "ghi jkl"]) |
| 57 | call cursor(1, 1) |
| 58 | call feedkeys("A\<del>\<esc>", 'tnix') |
| 59 | call assert_equal(["abc def", "ghi jkl"], getline(1, 2)) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 60 | let &bs=_bs |
| 61 | bw! |
| 62 | endfunc |
| 63 | |
| 64 | func! Test_edit_02() |
| 65 | " Change cursor position in InsertCharPre command |
| 66 | new |
| 67 | call setline(1, 'abc') |
| 68 | call cursor(1, 1) |
| 69 | fu! DoIt(...) |
| 70 | call cursor(1, 4) |
| 71 | if len(a:000) |
| 72 | let v:char=a:1 |
| 73 | endif |
| 74 | endfu |
| 75 | au InsertCharPre <buffer> :call DoIt('y') |
| 76 | call feedkeys("ix\<esc>", 'tnix') |
| 77 | call assert_equal(['abcy'], getline(1, '$')) |
| 78 | " Setting <Enter> in InsertCharPre |
| 79 | au! InsertCharPre <buffer> :call DoIt("\n") |
| 80 | call setline(1, 'abc') |
| 81 | call cursor(1, 1) |
| 82 | call feedkeys("ix\<esc>", 'tnix') |
| 83 | call assert_equal(['abc', ''], getline(1, '$')) |
| 84 | %d |
| 85 | au! InsertCharPre |
| 86 | " Change cursor position in InsertEnter command |
| 87 | " 1) when setting v:char, keeps changed cursor position |
| 88 | au! InsertEnter <buffer> :call DoIt('y') |
| 89 | call setline(1, 'abc') |
| 90 | call cursor(1, 1) |
| 91 | call feedkeys("ix\<esc>", 'tnix') |
| 92 | call assert_equal(['abxc'], getline(1, '$')) |
| 93 | " 2) when not setting v:char, restores changed cursor position |
| 94 | au! InsertEnter <buffer> :call DoIt() |
| 95 | call setline(1, 'abc') |
| 96 | call cursor(1, 1) |
| 97 | call feedkeys("ix\<esc>", 'tnix') |
| 98 | call assert_equal(['xabc'], getline(1, '$')) |
| 99 | au! InsertEnter |
| 100 | delfu DoIt |
| 101 | bw! |
| 102 | endfunc |
| 103 | |
| 104 | func! Test_edit_03() |
| 105 | " Change cursor after <c-o> command to end of line |
| 106 | new |
| 107 | call setline(1, 'abc') |
| 108 | call cursor(1, 1) |
| 109 | call feedkeys("i\<c-o>$y\<esc>", 'tnix') |
| 110 | call assert_equal(['abcy'], getline(1, '$')) |
| 111 | %d |
| 112 | call setline(1, 'abc') |
| 113 | call cursor(1, 1) |
| 114 | call feedkeys("i\<c-o>80|y\<esc>", 'tnix') |
| 115 | call assert_equal(['abcy'], getline(1, '$')) |
| 116 | %d |
| 117 | call setline(1, 'abc') |
| 118 | call feedkeys("Ad\<c-o>:s/$/efg/\<cr>hij", 'tnix') |
| 119 | call assert_equal(['hijabcdefg'], getline(1, '$')) |
| 120 | bw! |
| 121 | endfunc |
| 122 | |
| 123 | func! Test_edit_04() |
| 124 | " test for :stopinsert |
| 125 | new |
| 126 | call setline(1, 'abc') |
| 127 | call cursor(1, 1) |
| 128 | call feedkeys("i\<c-o>:stopinsert\<cr>$", 'tnix') |
| 129 | call feedkeys("aX\<esc>", 'tnix') |
| 130 | call assert_equal(['abcX'], getline(1, '$')) |
| 131 | %d |
| 132 | bw! |
| 133 | endfunc |
| 134 | |
| 135 | func! Test_edit_05() |
| 136 | " test for folds being opened |
| 137 | new |
| 138 | call setline(1, ['abcX', 'abcX', 'zzzZ']) |
| 139 | call cursor(1, 1) |
| 140 | set foldmethod=manual foldopen+=insert |
| 141 | " create fold for those two lines |
| 142 | norm! Vjzf |
| 143 | call feedkeys("$ay\<esc>", 'tnix') |
| 144 | call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) |
| 145 | %d |
| 146 | call setline(1, ['abcX', 'abcX', 'zzzZ']) |
| 147 | call cursor(1, 1) |
| 148 | set foldmethod=manual foldopen-=insert |
| 149 | " create fold for those two lines |
| 150 | norm! Vjzf |
| 151 | call feedkeys("$ay\<esc>", 'tnix') |
| 152 | call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) |
| 153 | %d |
| 154 | bw! |
| 155 | endfunc |
| 156 | |
| 157 | func! Test_edit_06() |
| 158 | " Test in diff mode |
| 159 | if !has("diff") || !executable("diff") |
| 160 | return |
| 161 | endif |
| 162 | new |
| 163 | call setline(1, ['abc', 'xxx', 'yyy']) |
| 164 | vnew |
| 165 | call setline(1, ['abc', 'zzz', 'xxx', 'yyy']) |
| 166 | wincmd p |
| 167 | diffthis |
| 168 | wincmd p |
| 169 | diffthis |
| 170 | wincmd p |
| 171 | call cursor(2, 1) |
| 172 | norm! zt |
| 173 | call feedkeys("Ozzz\<esc>", 'tnix') |
| 174 | call assert_equal(['abc', 'zzz', 'xxx', 'yyy'], getline(1,'$')) |
| 175 | bw! |
| 176 | bw! |
| 177 | endfunc |
| 178 | |
| 179 | func! Test_edit_07() |
| 180 | " 1) Test with completion <c-l> when popupmenu is visible |
| 181 | new |
| 182 | call setline(1, 'J') |
| 183 | |
| 184 | func! ListMonths() |
| 185 | call complete(col('.')-1, ['January', 'February', 'March', |
| 186 | \ 'April', 'May', 'June', 'July', 'August', 'September', |
| 187 | \ 'October', 'November', 'December']) |
| 188 | return '' |
| 189 | endfunc |
| 190 | inoremap <buffer> <F5> <C-R>=ListMonths()<CR> |
| 191 | |
| 192 | call feedkeys("A\<f5>\<c-p>". repeat("\<down>", 6)."\<c-l>\<down>\<c-l>\<cr>", 'tx') |
| 193 | call assert_equal(['July'], getline(1,'$')) |
| 194 | " 1) Test completion when InsertCharPre kicks in |
| 195 | %d |
| 196 | call setline(1, 'J') |
| 197 | fu! DoIt() |
| 198 | if v:char=='u' |
| 199 | let v:char='an' |
| 200 | endif |
| 201 | endfu |
| 202 | au InsertCharPre <buffer> :call DoIt() |
| 203 | call feedkeys("A\<f5>\<c-p>u\<cr>\<c-l>\<cr>", 'tx') |
| 204 | call assert_equal(["Jan\<c-l>",''], getline(1,'$')) |
| 205 | %d |
| 206 | call setline(1, 'J') |
| 207 | call feedkeys("A\<f5>\<c-p>u\<down>\<c-l>\<cr>", 'tx') |
| 208 | call assert_equal(["January"], getline(1,'$')) |
| 209 | |
| 210 | delfu ListMonths |
| 211 | delfu DoIt |
| 212 | iunmap <buffer> <f5> |
| 213 | bw! |
| 214 | endfunc |
| 215 | |
| 216 | func! Test_edit_08() |
| 217 | " reset insertmode from i_ctrl-r_= |
| 218 | new |
| 219 | call setline(1, ['abc']) |
| 220 | call cursor(1, 4) |
| 221 | call feedkeys(":set im\<cr>ZZZ\<c-r>=setbufvar(1,'&im', 0)\<cr>",'tnix') |
| 222 | call assert_equal(['abZZZc'], getline(1,'$')) |
| 223 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 224 | call assert_false(0, '&im') |
| 225 | bw! |
| 226 | endfunc |
| 227 | |
| 228 | func! 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! |
| 256 | endfunc |
| 257 | |
| 258 | func! 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! |
| 268 | endfunc |
| 269 | |
| 270 | func! 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! |
| 312 | endfunc |
| 313 | |
Bram Moolenaar | 1b38344 | 2017-09-26 20:04:54 +0200 | [diff] [blame] | 314 | func! 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! |
| 339 | endfunc |
| 340 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 341 | func! 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! |
| 391 | endfunc |
| 392 | |
| 393 | func! 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 |
| 404 | endfunc |
| 405 | |
| 406 | func! 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') |
| 437 | endfunc |
| 438 | |
| 439 | func! Test_edit_CTRL_() |
| 440 | " disabled for Windows builds, why? |
| 441 | if !has("multi_byte") || !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! |
| 467 | endfunc |
| 468 | |
| 469 | " needs to come first, to have the @. register empty |
| 470 | func! Test_edit_00a_CTRL_A() |
| 471 | " Test pressing CTRL-A |
| 472 | new |
| 473 | call setline(1, repeat([''], 5)) |
| 474 | call cursor(1, 1) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 475 | try |
| 476 | call feedkeys("A\<NUL>", 'tnix') |
| 477 | catch /^Vim\%((\a\+)\)\=:E29/ |
| 478 | call assert_true(1, 'E29 error caught') |
| 479 | endtry |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 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! |
| 488 | endfunc |
| 489 | |
| 490 | func! 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! |
| 504 | endfunc |
| 505 | |
| 506 | func! Test_edit_CTRL_G() |
| 507 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 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('.')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 521 | bw! |
| 522 | endfunc |
| 523 | |
| 524 | func! Test_edit_CTRL_I() |
| 525 | " Tab in completion mode |
| 526 | let path=expand("%:p:h") |
| 527 | new |
| 528 | call setline(1, [path."/", '']) |
Bram Moolenaar | c537947 | 2017-03-16 22:38:00 +0100 | [diff] [blame] | 529 | call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix') |
| 530 | call assert_match('runtest\.vim', getline(1)) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 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! |
| 546 | endfunc |
| 547 | |
| 548 | func! 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) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 607 | call delete('Xdictionary.txt') |
| 608 | |
| 609 | if has("multi_byte") |
| 610 | call test_override("char_avail", 1) |
| 611 | set showcmd |
| 612 | %d |
| 613 | call feedkeys("A\<c-k>a:\<esc>", 'tnix') |
| 614 | call assert_equal(['ä'], getline(1, '$')) |
| 615 | call test_override("char_avail", 0) |
| 616 | set noshowcmd |
| 617 | endif |
| 618 | bw! |
| 619 | endfunc |
| 620 | |
| 621 | func! Test_edit_CTRL_L() |
| 622 | " Test Ctrl-X Ctrl-L (line completion) |
| 623 | new |
| 624 | set complete=. |
| 625 | call setline(1, ['one', 'two', 'three', '', '', '', '']) |
| 626 | call cursor(4, 1) |
| 627 | call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix') |
| 628 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
| 629 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix') |
| 630 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
| 631 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix') |
| 632 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
| 633 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') |
| 634 | call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) |
| 635 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') |
| 636 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
| 637 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix') |
| 638 | call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) |
| 639 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix') |
| 640 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
| 641 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix') |
| 642 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
| 643 | set complete= |
| 644 | call cursor(5, 1) |
| 645 | call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix') |
| 646 | call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$')) |
| 647 | set complete& |
| 648 | %d |
| 649 | if has("conceal") && has("syntax") |
| 650 | call setline(1, ['foo', 'bar', 'foobar']) |
| 651 | call test_override("char_avail", 1) |
| 652 | set conceallevel=2 concealcursor=n |
| 653 | syn on |
| 654 | syn match ErrorMsg "^bar" |
| 655 | call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'}) |
| 656 | func! DoIt() |
| 657 | let g:change=1 |
| 658 | endfunc |
| 659 | au! TextChangedI <buffer> :call DoIt() |
| 660 | |
| 661 | call cursor(2, 1) |
| 662 | call assert_false(exists("g:change")) |
| 663 | call feedkeys("A \<esc>", 'tnix') |
| 664 | call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$')) |
| 665 | call assert_equal(1, g:change) |
| 666 | |
| 667 | call test_override("char_avail", 0) |
| 668 | call clearmatches() |
| 669 | syn off |
| 670 | au! TextChangedI |
| 671 | delfu DoIt |
| 672 | unlet! g:change |
| 673 | endif |
| 674 | bw! |
| 675 | endfunc |
| 676 | |
| 677 | func! Test_edit_CTRL_N() |
| 678 | " Check keyword completion |
| 679 | new |
| 680 | set complete=. |
| 681 | call setline(1, ['INFER', 'loWER', '', '', ]) |
| 682 | call cursor(3, 1) |
| 683 | call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix") |
| 684 | call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') |
| 685 | call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$')) |
| 686 | %d |
| 687 | call setline(1, ['INFER', 'loWER', '', '', ]) |
| 688 | call cursor(3, 1) |
| 689 | set ignorecase infercase |
| 690 | call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix") |
| 691 | call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') |
| 692 | call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$')) |
| 693 | |
| 694 | set noignorecase noinfercase complete& |
| 695 | bw! |
| 696 | endfunc |
| 697 | |
| 698 | func! Test_edit_CTRL_O() |
| 699 | " Check for CTRL-O in insert mode |
| 700 | new |
| 701 | inoreabbr <buffer> h here some more |
| 702 | call setline(1, ['abc', 'def']) |
| 703 | call cursor(1, 1) |
| 704 | " Ctrl-O after an abbreviation |
| 705 | exe "norm A h\<c-o>:set nu\<cr> text" |
| 706 | call assert_equal(['abc here some more text', 'def'], getline(1, '$')) |
| 707 | call assert_true(&nu) |
| 708 | set nonu |
| 709 | iunabbr <buffer> h |
| 710 | " Ctrl-O at end of line with 've'=onemore |
| 711 | call cursor(1, 1) |
| 712 | call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') |
| 713 | call assert_equal([0, 1, 23, 0], g:a) |
| 714 | call cursor(1, 1) |
| 715 | set ve=onemore |
| 716 | call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') |
| 717 | call assert_equal([0, 1, 24, 0], g:a) |
| 718 | set ve= |
| 719 | unlet! g:a |
| 720 | bw! |
| 721 | endfunc |
| 722 | |
| 723 | func! Test_edit_CTRL_R() |
| 724 | " Insert Register |
| 725 | new |
| 726 | call test_override("ALL", 1) |
| 727 | set showcmd |
| 728 | call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix') |
| 729 | call feedkeys("O\<c-r>.", 'tnix') |
| 730 | call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix') |
| 731 | call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix') |
| 732 | call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$')) |
| 733 | call test_override("ALL", 0) |
| 734 | set noshowcmd |
| 735 | bw! |
| 736 | endfunc |
| 737 | |
| 738 | func! Test_edit_CTRL_S() |
| 739 | " Test pressing CTRL-S (basically only spellfile completion) |
| 740 | " the rest is already covered |
| 741 | new |
| 742 | if !has("spell") |
| 743 | call setline(1, 'vim') |
| 744 | call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix') |
| 745 | call assert_equal(['vims', ''], getline(1, '$')) |
| 746 | bw! |
| 747 | return |
| 748 | endif |
| 749 | call setline(1, 'vim') |
| 750 | " spell option not yet set |
| 751 | try |
| 752 | call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') |
| 753 | catch /^Vim\%((\a\+)\)\=:E756/ |
| 754 | call assert_true(1, 'error caught') |
| 755 | endtry |
| 756 | call assert_equal(['vim', ''], getline(1, '$')) |
| 757 | %d |
| 758 | setl spell spelllang=en |
| 759 | call setline(1, 'vim') |
| 760 | call cursor(1, 1) |
| 761 | call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') |
| 762 | call assert_equal(['Vim', ''], getline(1, '$')) |
| 763 | %d |
| 764 | call setline(1, 'vim') |
| 765 | call cursor(1, 1) |
| 766 | call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix') |
| 767 | call assert_equal(['Aim'], getline(1, '$')) |
| 768 | %d |
| 769 | call setline(1, 'vim') |
| 770 | call cursor(1, 1) |
| 771 | call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') |
| 772 | call assert_equal(['vim', ''], getline(1, '$')) |
| 773 | %d |
| 774 | " empty buffer |
| 775 | call cursor(1, 1) |
| 776 | call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') |
| 777 | call assert_equal(['', ''], getline(1, '$')) |
| 778 | setl nospell |
| 779 | bw! |
| 780 | endfunc |
| 781 | |
| 782 | func! Test_edit_CTRL_T() |
| 783 | " Check for CTRL-T and CTRL-X CTRL-T in insert mode |
| 784 | " 1) increase indent |
| 785 | new |
| 786 | call setline(1, "abc") |
| 787 | call cursor(1, 1) |
| 788 | call feedkeys("A\<c-t>xyz", 'tnix') |
| 789 | call assert_equal(["\<tab>abcxyz"], getline(1, '$')) |
| 790 | " 2) also when paste option is set |
| 791 | set paste |
| 792 | call setline(1, "abc") |
| 793 | call cursor(1, 1) |
| 794 | call feedkeys("A\<c-t>xyz", 'tnix') |
| 795 | call assert_equal(["\<tab>abcxyz"], getline(1, '$')) |
| 796 | set nopaste |
| 797 | " CTRL-X CTRL-T (thesaurus complete) |
| 798 | call writefile(['angry furious mad enraged'], 'Xthesaurus') |
| 799 | set thesaurus=Xthesaurus |
| 800 | call setline(1, 'mad') |
| 801 | call cursor(1, 1) |
| 802 | call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix') |
| 803 | call assert_equal(['mad', ''], getline(1, '$')) |
| 804 | %d |
| 805 | call setline(1, 'mad') |
| 806 | call cursor(1, 1) |
| 807 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') |
| 808 | call assert_equal(['angry', ''], getline(1, '$')) |
| 809 | %d |
| 810 | call setline(1, 'mad') |
| 811 | call cursor(1, 1) |
| 812 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 813 | call assert_equal(['furious', ''], getline(1, '$')) |
| 814 | %d |
| 815 | call setline(1, 'mad') |
| 816 | call cursor(1, 1) |
| 817 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 818 | call assert_equal(['enraged', ''], 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>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 823 | call assert_equal(['mad', ''], 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>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 828 | call assert_equal(['mad', ''], getline(1, '$')) |
| 829 | " Using <c-p> <c-n> when 'complete' is empty |
| 830 | set complete= |
| 831 | %d |
| 832 | call setline(1, 'mad') |
| 833 | call cursor(1, 1) |
| 834 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') |
| 835 | call assert_equal(['angry', ''], getline(1, '$')) |
| 836 | %d |
| 837 | call setline(1, 'mad') |
| 838 | call cursor(1, 1) |
| 839 | call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix') |
| 840 | call assert_equal(['mad', ''], getline(1, '$')) |
| 841 | set complete& |
| 842 | |
| 843 | set thesaurus= |
| 844 | %d |
| 845 | call setline(1, 'mad') |
| 846 | call cursor(1, 1) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 847 | let v:testing = 1 |
| 848 | try |
| 849 | call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix') |
| 850 | catch |
| 851 | " error sleeps 2 seconds, when v:testing is not set |
| 852 | let v:testing = 0 |
| 853 | endtry |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 854 | call assert_equal(['mad'], getline(1, '$')) |
| 855 | call delete('Xthesaurus') |
| 856 | bw! |
| 857 | endfunc |
| 858 | |
| 859 | func! Test_edit_CTRL_U() |
| 860 | " Test 'completefunc' |
| 861 | new |
| 862 | " -1, -2 and -3 are special return values |
| 863 | let g:special=0 |
| 864 | fun! CompleteMonths(findstart, base) |
| 865 | if a:findstart |
| 866 | " locate the start of the word |
| 867 | return g:special |
| 868 | else |
| 869 | " find months matching with "a:base" |
| 870 | let res = [] |
| 871 | for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") |
| 872 | if m =~ '^\c'.a:base |
| 873 | call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0}) |
| 874 | endif |
| 875 | endfor |
| 876 | return {'words': res, 'refresh': 'always'} |
| 877 | endif |
| 878 | endfun |
| 879 | set completefunc=CompleteMonths |
| 880 | call setline(1, ['', '']) |
| 881 | call cursor(1, 1) |
| 882 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 883 | call assert_equal(['X', '', ''], getline(1, '$')) |
| 884 | %d |
| 885 | let g:special=-1 |
| 886 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 887 | call assert_equal(['XJan', ''], getline(1, '$')) |
| 888 | %d |
| 889 | let g:special=-2 |
| 890 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 891 | call assert_equal(['X', ''], getline(1, '$')) |
| 892 | %d |
| 893 | let g:special=-3 |
| 894 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 895 | call assert_equal(['X', ''], getline(1, '$')) |
| 896 | %d |
| 897 | let g:special=0 |
| 898 | call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 899 | call assert_equal(['Mar', ''], getline(1, '$')) |
| 900 | %d |
| 901 | call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix') |
| 902 | call assert_equal(['May', ''], getline(1, '$')) |
| 903 | %d |
| 904 | call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 905 | call assert_equal(['M', ''], getline(1, '$')) |
| 906 | delfu CompleteMonths |
| 907 | %d |
| 908 | try |
| 909 | call feedkeys("A\<c-x>\<c-u>", 'tnix') |
| 910 | call assert_fails(1, 'unknown completion function') |
| 911 | catch /^Vim\%((\a\+)\)\=:E117/ |
| 912 | call assert_true(1, 'E117 error caught') |
| 913 | endtry |
| 914 | set completefunc= |
| 915 | bw! |
| 916 | endfunc |
| 917 | |
| 918 | func! Test_edit_CTRL_Z() |
| 919 | " Ctrl-Z when insertmode is not set inserts it literally |
| 920 | new |
| 921 | call setline(1, 'abc') |
| 922 | call feedkeys("A\<c-z>\<esc>", 'tnix') |
| 923 | call assert_equal(["abc\<c-z>"], getline(1,'$')) |
| 924 | bw! |
| 925 | " TODO: How to Test Ctrl-Z in insert mode, e.g. suspend? |
| 926 | endfunc |
| 927 | |
| 928 | func! Test_edit_DROP() |
| 929 | if !has("dnd") |
| 930 | return |
| 931 | endif |
| 932 | new |
| 933 | call setline(1, ['abc def ghi']) |
| 934 | call cursor(1, 1) |
| 935 | try |
| 936 | call feedkeys("i\<Drop>\<Esc>", 'tnix') |
| 937 | call assert_fails(1, 'Invalid register name') |
| 938 | catch /^Vim\%((\a\+)\)\=:E353/ |
| 939 | call assert_true(1, 'error caught') |
| 940 | endtry |
| 941 | bw! |
| 942 | endfunc |
| 943 | |
| 944 | func! Test_edit_CTRL_V() |
| 945 | if has("ebcdic") |
| 946 | return |
| 947 | endif |
| 948 | new |
| 949 | call setline(1, ['abc']) |
| 950 | call cursor(2, 1) |
| 951 | " force some redraws |
| 952 | set showmode showcmd |
| 953 | "call test_override_char_avail(1) |
| 954 | call test_override('ALL', 1) |
| 955 | call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') |
| 956 | call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) |
| 957 | |
| 958 | if has("rightleft") && exists("+rl") |
| 959 | set rl |
| 960 | call setline(1, ['abc']) |
| 961 | call cursor(2, 1) |
| 962 | call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') |
| 963 | call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) |
| 964 | set norl |
| 965 | endif |
| 966 | |
| 967 | call test_override('ALL', 0) |
| 968 | set noshowmode showcmd |
| 969 | bw! |
| 970 | endfunc |
| 971 | |
| 972 | func! Test_edit_F1() |
| 973 | " Pressing <f1> |
| 974 | new |
| 975 | call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix') |
| 976 | set noinsertmode |
| 977 | call assert_equal('help', &buftype) |
| 978 | bw |
| 979 | bw |
| 980 | endfunc |
| 981 | |
| 982 | func! Test_edit_F21() |
| 983 | " Pressing <f21> |
| 984 | " sends a netbeans command |
| 985 | if has("netbeans_intg") |
| 986 | new |
| 987 | " I have no idea what this is supposed to do :) |
| 988 | call feedkeys("A\<F21>\<F1>\<esc>", 'tnix') |
| 989 | bw |
| 990 | endif |
| 991 | endfunc |
| 992 | |
| 993 | func! Test_edit_HOME_END() |
| 994 | " Test Home/End Keys |
| 995 | new |
| 996 | set foldopen+=hor |
| 997 | call setline(1, ['abc', 'def']) |
| 998 | call cursor(1, 1) |
| 999 | call feedkeys("AX\<Home>Y\<esc>", 'tnix') |
| 1000 | call cursor(2, 1) |
| 1001 | call feedkeys("iZ\<End>Y\<esc>", 'tnix') |
| 1002 | call assert_equal(['YabcX', 'ZdefY'], getline(1, '$')) |
| 1003 | |
| 1004 | set foldopen-=hor |
| 1005 | bw! |
| 1006 | endfunc |
| 1007 | |
| 1008 | func! Test_edit_INS() |
| 1009 | " Test for Pressing <Insert> |
| 1010 | new |
| 1011 | call setline(1, ['abc', 'def']) |
| 1012 | call cursor(1, 1) |
| 1013 | call feedkeys("i\<Insert>ZYX>", 'tnix') |
| 1014 | call assert_equal(['ZYX>', 'def'], getline(1, '$')) |
| 1015 | call setline(1, ['abc', 'def']) |
| 1016 | call cursor(1, 1) |
| 1017 | call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix') |
| 1018 | call assert_equal(['ZYX>bc', 'def'], getline(1, '$')) |
| 1019 | bw! |
| 1020 | endfunc |
| 1021 | |
| 1022 | func! Test_edit_LEFT_RIGHT() |
| 1023 | " Left, Shift-Left, Right, Shift-Right |
| 1024 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1025 | call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX']) |
| 1026 | let _ww=&ww |
| 1027 | set ww= |
| 1028 | call cursor(2, 1) |
| 1029 | call feedkeys("i\<left>\<esc>", 'tnix') |
| 1030 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 1031 | " Is this a bug, <s-left> does not respect whichwrap option |
| 1032 | call feedkeys("i\<s-left>\<esc>", 'tnix') |
| 1033 | call assert_equal([0, 1, 8, 0], getpos('.')) |
| 1034 | call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix') |
| 1035 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1036 | call feedkeys("i\<right>\<esc>", 'tnix') |
| 1037 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1038 | call feedkeys("i\<right>\<right>\<esc>", 'tnix') |
| 1039 | call assert_equal([0, 1, 2, 0], getpos('.')) |
| 1040 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1041 | call assert_equal([0, 1, 11, 0], getpos('.')) |
| 1042 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1043 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 1044 | call feedkeys("i\<s-right>\<esc>", 'tnix') |
| 1045 | call assert_equal([0, 2, 4, 0], getpos('.')) |
| 1046 | call cursor(3, 11) |
| 1047 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1048 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1049 | call assert_equal([0, 3, 11, 0], getpos('.')) |
| 1050 | call cursor(2, 11) |
| 1051 | " <S-Right> does not respect 'whichwrap' option |
| 1052 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1053 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1054 | " Check motion when 'whichwrap' contains cursor keys for insert mode |
| 1055 | set ww+=[,] |
| 1056 | call cursor(2, 1) |
| 1057 | call feedkeys("i\<left>\<esc>", 'tnix') |
| 1058 | call assert_equal([0, 1, 11, 0], getpos('.')) |
| 1059 | call cursor(2, 11) |
| 1060 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1061 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1062 | call cursor(2, 11) |
| 1063 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1064 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1065 | let &ww = _ww |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1066 | bw! |
| 1067 | endfunc |
| 1068 | |
| 1069 | func! Test_edit_MOUSE() |
| 1070 | " This is a simple test, since we not really using the mouse here |
| 1071 | if !has("mouse") |
| 1072 | return |
| 1073 | endif |
| 1074 | 10new |
| 1075 | call setline(1, range(1, 100)) |
| 1076 | call cursor(1, 1) |
| 1077 | set mouse=a |
| 1078 | call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix') |
| 1079 | call assert_equal([0, 4, 1, 0], getpos('.')) |
| 1080 | " This should move by one pageDown, but only moves |
| 1081 | " by one line when the test is run... |
| 1082 | call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix') |
| 1083 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 1084 | set nostartofline |
| 1085 | call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix') |
| 1086 | call assert_equal([0, 6, 1, 0], getpos('.')) |
| 1087 | call feedkeys("A\<LeftMouse>\<esc>", 'tnix') |
| 1088 | call assert_equal([0, 6, 1, 0], getpos('.')) |
| 1089 | call feedkeys("A\<RightMouse>\<esc>", 'tnix') |
| 1090 | call assert_equal([0, 6, 1, 0], getpos('.')) |
| 1091 | call cursor(1, 100) |
| 1092 | norm! zt |
| 1093 | " this should move by a screen up, but when the test |
| 1094 | " is run, it moves up to the top of the buffer... |
| 1095 | call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix') |
| 1096 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1097 | call cursor(1, 30) |
| 1098 | norm! zt |
| 1099 | call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix') |
| 1100 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1101 | call cursor(1, 30) |
| 1102 | norm! zt |
| 1103 | call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix') |
| 1104 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1105 | %d |
| 1106 | call setline(1, repeat(["12345678901234567890"], 100)) |
| 1107 | call cursor(2, 1) |
| 1108 | call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix') |
| 1109 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1110 | call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix') |
| 1111 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1112 | call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix') |
| 1113 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1114 | call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix') |
| 1115 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1116 | call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix') |
| 1117 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1118 | call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix') |
| 1119 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1120 | set mouse& startofline |
| 1121 | bw! |
| 1122 | endfunc |
| 1123 | |
| 1124 | func! Test_edit_PAGEUP_PAGEDOWN() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1125 | 10new |
| 1126 | call setline(1, repeat(['abc def ghi'], 30)) |
| 1127 | call cursor(1, 1) |
| 1128 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1129 | call assert_equal([0, 9, 1, 0], getpos('.')) |
| 1130 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1131 | call assert_equal([0, 17, 1, 0], getpos('.')) |
| 1132 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1133 | call assert_equal([0, 25, 1, 0], getpos('.')) |
| 1134 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1135 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1136 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1137 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1138 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1139 | call assert_equal([0, 29, 1, 0], getpos('.')) |
| 1140 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1141 | call assert_equal([0, 21, 1, 0], getpos('.')) |
| 1142 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1143 | call assert_equal([0, 13, 1, 0], getpos('.')) |
| 1144 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1145 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 1146 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1147 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1148 | " <S-Up> is the same as <PageUp> |
| 1149 | " <S-Down> is the same as <PageDown> |
| 1150 | call cursor(1, 1) |
| 1151 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1152 | call assert_equal([0, 9, 1, 0], getpos('.')) |
| 1153 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1154 | call assert_equal([0, 17, 1, 0], getpos('.')) |
| 1155 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1156 | call assert_equal([0, 25, 1, 0], getpos('.')) |
| 1157 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1158 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1159 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1160 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1161 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1162 | call assert_equal([0, 29, 1, 0], getpos('.')) |
| 1163 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1164 | call assert_equal([0, 21, 1, 0], getpos('.')) |
| 1165 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1166 | call assert_equal([0, 13, 1, 0], getpos('.')) |
| 1167 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1168 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 1169 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1170 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1171 | set nostartofline |
| 1172 | call cursor(30, 11) |
| 1173 | norm! zt |
| 1174 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1175 | call assert_equal([0, 29, 11, 0], getpos('.')) |
| 1176 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1177 | call assert_equal([0, 21, 11, 0], getpos('.')) |
| 1178 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1179 | call assert_equal([0, 13, 11, 0], getpos('.')) |
| 1180 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1181 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1182 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1183 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1184 | call cursor(1, 1) |
| 1185 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1186 | call assert_equal([0, 9, 11, 0], getpos('.')) |
| 1187 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1188 | call assert_equal([0, 17, 11, 0], getpos('.')) |
| 1189 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1190 | call assert_equal([0, 25, 11, 0], getpos('.')) |
| 1191 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1192 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1193 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1194 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1195 | " <S-Up> is the same as <PageUp> |
| 1196 | " <S-Down> is the same as <PageDown> |
| 1197 | call cursor(30, 11) |
| 1198 | norm! zt |
| 1199 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1200 | call assert_equal([0, 29, 11, 0], getpos('.')) |
| 1201 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1202 | call assert_equal([0, 21, 11, 0], getpos('.')) |
| 1203 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1204 | call assert_equal([0, 13, 11, 0], getpos('.')) |
| 1205 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1206 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1207 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1208 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1209 | call cursor(1, 1) |
| 1210 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1211 | call assert_equal([0, 9, 11, 0], getpos('.')) |
| 1212 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1213 | call assert_equal([0, 17, 11, 0], getpos('.')) |
| 1214 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1215 | call assert_equal([0, 25, 11, 0], getpos('.')) |
| 1216 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1217 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1218 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1219 | call assert_equal([0, 30, 11, 0], getpos('.')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1220 | bw! |
| 1221 | endfunc |
| 1222 | |
| 1223 | func! Test_edit_forbidden() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1224 | new |
| 1225 | " 1) edit in the sandbox is not allowed |
| 1226 | call setline(1, 'a') |
| 1227 | com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix') |
| 1228 | call assert_fails(':Sandbox', 'E48:') |
| 1229 | com! Sandbox :sandbox exe "norm! i\<del>" |
| 1230 | call assert_fails(':Sandbox', 'E48:') |
| 1231 | delcom Sandbox |
| 1232 | call assert_equal(['a'], getline(1,'$')) |
| 1233 | " 2) edit with textlock set |
| 1234 | fu! DoIt() |
| 1235 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 1236 | endfu |
| 1237 | au InsertCharPre <buffer> :call DoIt() |
| 1238 | try |
| 1239 | call feedkeys("ix\<esc>", 'tnix') |
| 1240 | call assert_fails(1, 'textlock') |
| 1241 | catch /^Vim\%((\a\+)\)\=:E523/ " catch E523: not allowed here |
| 1242 | endtry |
| 1243 | " TODO: Might be a bug: should x really be inserted here |
| 1244 | call assert_equal(['xa'], getline(1, '$')) |
| 1245 | delfu DoIt |
| 1246 | try |
| 1247 | call feedkeys("ix\<esc>", 'tnix') |
| 1248 | call assert_fails(1, 'unknown function') |
| 1249 | catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function |
| 1250 | endtry |
| 1251 | au! InsertCharPre |
| 1252 | " 3) edit when completion is shown |
| 1253 | fun! Complete(findstart, base) |
| 1254 | if a:findstart |
| 1255 | return col('.') |
| 1256 | else |
| 1257 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 1258 | return [] |
| 1259 | endif |
| 1260 | endfun |
| 1261 | set completefunc=Complete |
| 1262 | try |
| 1263 | call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix') |
| 1264 | call assert_fails(1, 'change in complete function') |
| 1265 | catch /^Vim\%((\a\+)\)\=:E523/ " catch E523 |
| 1266 | endtry |
| 1267 | delfu Complete |
| 1268 | set completefunc= |
| 1269 | if has("rightleft") && exists("+fkmap") |
| 1270 | " 4) 'R' when 'fkmap' and 'revins' is set. |
| 1271 | set revins fkmap |
| 1272 | try |
| 1273 | normal Ri |
| 1274 | call assert_fails(1, "R with 'fkmap' and 'ri' set") |
| 1275 | catch |
| 1276 | finally |
| 1277 | set norevins nofkmap |
| 1278 | endtry |
| 1279 | endif |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1280 | bw! |
| 1281 | endfunc |
| 1282 | |
| 1283 | func! Test_edit_rightleft() |
| 1284 | " Cursor in rightleft mode moves differently |
| 1285 | if !exists("+rightleft") |
| 1286 | return |
| 1287 | endif |
| 1288 | call NewWindow(10, 20) |
| 1289 | call setline(1, ['abc', 'def', 'ghi']) |
| 1290 | call cursor(1, 2) |
| 1291 | set rightleft |
| 1292 | " Screen looks as expected |
| 1293 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1294 | let expect = [ |
| 1295 | \" cba", |
| 1296 | \" fed", |
| 1297 | \" ihg", |
| 1298 | \" ~"] |
| 1299 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
| 1300 | " 2) right moves to the left |
| 1301 | call feedkeys("i\<right>\<esc>x", 'txin') |
| 1302 | call assert_equal(['bc', 'def', 'ghi'], getline(1,'$')) |
| 1303 | call cursor(1, 2) |
| 1304 | call feedkeys("i\<s-right>\<esc>", 'txin') |
| 1305 | call cursor(1, 2) |
| 1306 | call feedkeys("i\<c-right>\<esc>", 'txin') |
| 1307 | " Screen looks as expected |
| 1308 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1309 | let expect = [ |
| 1310 | \" cb", |
| 1311 | \" fed", |
| 1312 | \" ihg", |
| 1313 | \" ~"] |
| 1314 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
| 1315 | " 2) left moves to the right |
| 1316 | call setline(1, ['abc', 'def', 'ghi']) |
| 1317 | call cursor(1, 2) |
| 1318 | call feedkeys("i\<left>\<esc>x", 'txin') |
| 1319 | call assert_equal(['ac', 'def', 'ghi'], getline(1,'$')) |
| 1320 | call cursor(1, 2) |
| 1321 | call feedkeys("i\<s-left>\<esc>", 'txin') |
| 1322 | call cursor(1, 2) |
| 1323 | call feedkeys("i\<c-left>\<esc>", 'txin') |
| 1324 | " Screen looks as expected |
| 1325 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1326 | let expect = [ |
| 1327 | \" ca", |
| 1328 | \" fed", |
| 1329 | \" ihg", |
| 1330 | \" ~"] |
| 1331 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
| 1332 | set norightleft |
| 1333 | bw! |
| 1334 | endfunc |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1335 | |
| 1336 | func Test_edit_complete_very_long_name() |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1337 | if !has('unix') |
Bram Moolenaar | 9b81079 | 2017-03-31 23:32:53 +0200 | [diff] [blame] | 1338 | " Long directory names only work on Unix. |
| 1339 | return |
| 1340 | endif |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1341 | |
| 1342 | let dirname = getcwd() . "/Xdir" |
| 1343 | let longdirname = dirname . repeat('/' . repeat('d', 255), 4) |
| 1344 | try |
| 1345 | call mkdir(longdirname, 'p') |
| 1346 | catch /E739:/ |
| 1347 | " Long directory name probably not supported. |
| 1348 | call delete(dirname, 'rf') |
| 1349 | return |
| 1350 | endtry |
| 1351 | |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1352 | " Try to get the Vim window position before setting 'columns'. |
| 1353 | let winposx = getwinposx() |
| 1354 | let winposy = getwinposy() |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1355 | let save_columns = &columns |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1356 | " Need at least about 1100 columns to reproduce the problem. |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1357 | set columns=2000 |
| 1358 | call assert_equal(2000, &columns) |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1359 | set noswapfile |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1360 | |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1361 | let longfilename = longdirname . '/' . repeat('a', 255) |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1362 | call writefile(['Totum', 'Table'], longfilename) |
| 1363 | new |
| 1364 | exe "next Xfile " . longfilename |
| 1365 | exe "normal iT\<C-N>" |
| 1366 | |
| 1367 | bwipe! |
| 1368 | exe 'bwipe! ' . longfilename |
| 1369 | call delete(dirname, 'rf') |
| 1370 | let &columns = save_columns |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1371 | if winposx >= 0 && winposy >= 0 |
| 1372 | exe 'winpos ' . winposx . ' ' . winposy |
| 1373 | endif |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1374 | set swapfile& |
| 1375 | endfunc |
Bram Moolenaar | ff930ca | 2017-10-19 17:12:10 +0200 | [diff] [blame] | 1376 | |
| 1377 | func Test_edit_quit() |
| 1378 | edit foo.txt |
| 1379 | split |
| 1380 | new |
| 1381 | call setline(1, 'hello') |
| 1382 | 3wincmd w |
| 1383 | redraw! |
| 1384 | call assert_fails('1q', 'E37:') |
| 1385 | bwipe! foo.txt |
| 1386 | only |
| 1387 | endfunc |
| 1388 | |