blob: 7278bcd85d14c9b7e070159c4f5451361e85ce81 [file] [log] [blame]
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001" Test for edit functions
2"
3if exists("+t_kD")
4 let &t_kD="[3;*~"
5endif
Bram Moolenaareb992cb2017-03-09 18:20:16 +01006
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
Bram Moolenaareb992cb2017-03-09 18:20:16 +010028 " 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 Moolenaareb992cb2017-03-09 18:20:16 +010060 let &bs=_bs
61 bw!
62endfunc
63
64func! 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!
102endfunc
103
104func! 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!
121endfunc
122
123func! 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!
133endfunc
134
135func! 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!
155endfunc
156
157func! 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!
177endfunc
178
179func! 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!
214endfunc
215
216func! Test_edit_08()
217 " reset insertmode from i_ctrl-r_=
Bram Moolenaar2a45d642017-10-27 01:35:00 +0200218 let g:bufnr = bufnr('%')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100219 new
220 call setline(1, ['abc'])
221 call cursor(1, 4)
Bram Moolenaar2a45d642017-10-27 01:35:00 +0200222 call feedkeys(":set im\<cr>ZZZ\<c-r>=setbufvar(g:bufnr,'&im', 0)\<cr>",'tnix')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100223 call assert_equal(['abZZZc'], getline(1,'$'))
224 call assert_equal([0, 1, 1, 0], getpos('.'))
225 call assert_false(0, '&im')
226 bw!
Bram Moolenaar2a45d642017-10-27 01:35:00 +0200227 unlet g:bufnr
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100228endfunc
229
230func! Test_edit_09()
231 " test i_CTRL-\ combinations
232 new
233 call setline(1, ['abc', 'def', 'ghi'])
234 call cursor(1, 1)
235 " 1) CTRL-\ CTLR-N
236 call feedkeys(":set im\<cr>\<c-\>\<c-n>ccABC\<c-l>", 'txin')
237 call assert_equal(['ABC', 'def', 'ghi'], getline(1,'$'))
238 call setline(1, ['ABC', 'def', 'ghi'])
239 " 2) CTRL-\ CTLR-G
240 call feedkeys("j0\<c-\>\<c-g>ZZZ\<cr>\<c-l>", 'txin')
241 call assert_equal(['ABC', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
242 call feedkeys("I\<c-\>\<c-g>YYY\<c-l>", 'txin')
243 call assert_equal(['ABC', 'ZZZ', 'YYYdef', 'ghi'], getline(1,'$'))
244 set noinsertmode
245 " 3) CTRL-\ CTRL-O
246 call setline(1, ['ABC', 'ZZZ', 'def', 'ghi'])
247 call cursor(1, 1)
248 call feedkeys("A\<c-o>ix", 'txin')
249 call assert_equal(['ABxC', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
250 call feedkeys("A\<c-\>\<c-o>ix", 'txin')
251 call assert_equal(['ABxCx', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
252 " 4) CTRL-\ a (should be inserted literally, not special after <c-\>
253 call setline(1, ['ABC', 'ZZZ', 'def', 'ghi'])
254 call cursor(1, 1)
255 call feedkeys("A\<c-\>a", 'txin')
256 call assert_equal(["ABC\<c-\>a", 'ZZZ', 'def', 'ghi'], getline(1, '$'))
257 bw!
258endfunc
259
260func! Test_edit_10()
261 " Test for starting selectmode
262 new
263 set selectmode=key keymodel=startsel
264 call setline(1, ['abc', 'def', 'ghi'])
265 call cursor(1, 4)
266 call feedkeys("A\<s-home>start\<esc>", 'txin')
267 call assert_equal(['startdef', 'ghi'], getline(1, '$'))
268 set selectmode= keymodel=
269 bw!
270endfunc
271
272func! Test_edit_11()
273 " Test that indenting kicks in
274 new
275 set cindent
276 call setline(1, ['{', '', ''])
277 call cursor(2, 1)
278 call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
279 call cursor(3, 1)
280 call feedkeys("i/* comment */", 'tnix')
281 call assert_equal(['{', "\<tab>int c;", "/* comment */"], getline(1, '$'))
282 " added changed cindentkeys slightly
283 set cindent cinkeys+=*/
284 call setline(1, ['{', '', ''])
285 call cursor(2, 1)
286 call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
287 call cursor(3, 1)
288 call feedkeys("i/* comment */", 'tnix')
289 call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */"], getline(1, '$'))
290 set cindent cinkeys+==end
291 call feedkeys("oend\<cr>\<esc>", 'tnix')
292 call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */", "\tend", ''], getline(1, '$'))
293 set cinkeys-==end
294 %d
295 " Use indentexpr instead of cindenting
296 func! Do_Indent()
297 if v:lnum == 3
298 return 3*shiftwidth()
299 else
300 return 2*shiftwidth()
301 endif
302 endfunc
303 setl indentexpr=Do_Indent() indentkeys+=*/
304 call setline(1, ['{', '', ''])
305 call cursor(2, 1)
306 call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
307 call cursor(3, 1)
308 call feedkeys("i/* comment */", 'tnix')
309 call assert_equal(['{', "\<tab>\<tab>int c;", "\<tab>\<tab>\<tab>/* comment */"], getline(1, '$'))
310 set cinkeys&vim indentkeys&vim
311 set nocindent indentexpr=
312 delfu Do_Indent
313 bw!
314endfunc
315
Bram Moolenaar1b383442017-09-26 20:04:54 +0200316func! Test_edit_11_indentexpr()
317 " Test that indenting kicks in
318 new
319 " Use indentexpr instead of cindenting
320 func! Do_Indent()
321 let pline=prevnonblank(v:lnum)
322 if empty(getline(v:lnum))
323 if getline(pline) =~ 'if\|then'
324 return shiftwidth()
325 else
326 return 0
327 endif
328 else
329 return 0
330 endif
331 endfunc
332 setl indentexpr=Do_Indent() indentkeys+=0=then,0=fi
333 call setline(1, ['if [ $this ]'])
334 call cursor(1, 1)
335 call feedkeys("othen\<cr>that\<cr>fi", 'tnix')
336 call assert_equal(['if [ $this ]', "then", "\<tab>that", "fi"], getline(1, '$'))
337 set cinkeys&vim indentkeys&vim
338 set nocindent indentexpr=
339 delfu Do_Indent
340 bw!
341endfunc
342
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100343func! Test_edit_12()
344 " Test changing indent in replace mode
345 new
346 call setline(1, ["\tabc", "\tdef"])
347 call cursor(2, 4)
348 call feedkeys("R^\<c-d>", 'tnix')
349 call assert_equal(["\tabc", "def"], getline(1, '$'))
350 call assert_equal([0, 2, 2, 0], getpos('.'))
351 %d
352 call setline(1, ["\tabc", "\t\tdef"])
353 call cursor(2, 2)
354 call feedkeys("R^\<c-d>", 'tnix')
355 call assert_equal(["\tabc", "def"], getline(1, '$'))
356 call assert_equal([0, 2, 1, 0], getpos('.'))
357 %d
358 call setline(1, ["\tabc", "\t\tdef"])
359 call cursor(2, 2)
360 call feedkeys("R\<c-t>", 'tnix')
361 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
362 call assert_equal([0, 2, 2, 0], getpos('.'))
363 bw!
364 10vnew
365 call setline(1, ["\tabc", "\t\tdef"])
366 call cursor(2, 2)
367 call feedkeys("R\<c-t>", 'tnix')
368 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
369 call assert_equal([0, 2, 2, 0], getpos('.'))
370 %d
371 set sw=4
372 call setline(1, ["\tabc", "\t\tdef"])
373 call cursor(2, 2)
374 call feedkeys("R\<c-t>\<c-t>", 'tnix')
375 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
376 call assert_equal([0, 2, 2, 0], getpos('.'))
377 %d
378 call setline(1, ["\tabc", "\t\tdef"])
379 call cursor(2, 2)
380 call feedkeys("R\<c-t>\<c-t>", 'tnix')
381 call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
382 call assert_equal([0, 2, 2, 0], getpos('.'))
383 set et
384 set sw& et&
385 %d
386 call setline(1, ["\t/*"])
387 set formatoptions=croql
388 call cursor(1, 3)
389 call feedkeys("A\<cr>\<cr>/", 'tnix')
390 call assert_equal(["\t/*", " *", " */"], getline(1, '$'))
391 set formatoptions&
392 bw!
393endfunc
394
395func! Test_edit_13()
396 " Test smartindenting
397 if exists("+smartindent")
398 new
399 set smartindent autoindent
400 call setline(1, ["\tabc"])
401 call feedkeys("A {\<cr>more\<cr>}\<esc>", 'tnix')
402 call assert_equal(["\tabc {", "\t\tmore", "\t}"], getline(1, '$'))
403 set smartindent& autoindent&
404 bw!
405 endif
406endfunc
407
408func! Test_edit_CR()
409 " Test for <CR> in insert mode
410 " basically only in quickfix mode ist tested, the rest
411 " has been taken care of by other tests
412 if !has("quickfix")
413 return
414 endif
415 botright new
416 call writefile(range(1, 10), 'Xqflist.txt')
417 call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}])
418 copen
419 set modifiable
420 call feedkeys("A\<cr>", 'tnix')
421 call assert_equal('Xqflist.txt', bufname(''))
422 call assert_equal(2, line('.'))
423 cclose
424 botright new
425 call setloclist(0, [{'filename': 'Xqflist.txt', 'lnum': 10}])
426 lopen
427 set modifiable
428 call feedkeys("A\<cr>", 'tnix')
429 call assert_equal('Xqflist.txt', bufname(''))
430 call assert_equal(10, line('.'))
431 call feedkeys("A\<Enter>", 'tnix')
432 call feedkeys("A\<kEnter>", 'tnix')
433 call feedkeys("A\n", 'tnix')
434 call feedkeys("A\r", 'tnix')
435 call assert_equal(map(range(1, 10), 'string(v:val)') + ['', '', '', ''], getline(1, '$'))
436 bw!
437 lclose
438 call delete('Xqflist.txt')
439endfunc
440
441func! Test_edit_CTRL_()
442 " disabled for Windows builds, why?
443 if !has("multi_byte") || !has("rightleft") || has("win32")
444 return
445 endif
446 let _encoding=&encoding
447 set encoding=utf-8
448 " Test for CTRL-_
449 new
450 call setline(1, ['abc'])
451 call cursor(1, 1)
452 call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
453 call assert_equal(["\<C-_>xyzabc"], getline(1, '$'))
454 call assert_false(&revins)
455 set ari
456 call setline(1, ['abc'])
457 call cursor(1, 1)
458 call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
459 call assert_equal(["æèñabc"], getline(1, '$'))
460 call assert_true(&revins)
461 call setline(1, ['abc'])
462 call cursor(1, 1)
463 call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
464 call assert_equal(["xyzabc"], getline(1, '$'))
465 call assert_false(&revins)
466 set noari
467 let &encoding=_encoding
468 bw!
469endfunc
470
471" needs to come first, to have the @. register empty
472func! Test_edit_00a_CTRL_A()
473 " Test pressing CTRL-A
474 new
475 call setline(1, repeat([''], 5))
476 call cursor(1, 1)
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100477 try
478 call feedkeys("A\<NUL>", 'tnix')
479 catch /^Vim\%((\a\+)\)\=:E29/
480 call assert_true(1, 'E29 error caught')
481 endtry
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100482 call cursor(1, 1)
483 call feedkeys("Afoobar \<esc>", 'tnix')
484 call cursor(2, 1)
485 call feedkeys("A\<c-a>more\<esc>", 'tnix')
486 call cursor(3, 1)
487 call feedkeys("A\<NUL>and more\<esc>", 'tnix')
488 call assert_equal(['foobar ', 'foobar more', 'foobar morend more', '', ''], getline(1, '$'))
489 bw!
490endfunc
491
492func! Test_edit_CTRL_EY()
493 " Ctrl-E/ Ctrl-Y in insert mode completion to scroll
494 10new
495 call setline(1, range(1, 100))
496 call cursor(30, 1)
497 norm! z.
498 call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix')
499 call assert_equal(30, winsaveview()['topline'])
500 call assert_equal([0, 30, 2, 0], getpos('.'))
501 call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix')
502 call feedkeys("A\<c-x>".repeat("\<c-y>", 10), 'tnix')
503 call assert_equal(21, winsaveview()['topline'])
504 call assert_equal([0, 30, 2, 0], getpos('.'))
505 bw!
506endfunc
507
508func! Test_edit_CTRL_G()
509 new
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100510 call setline(1, ['foobar', 'foobar', 'foobar'])
511 call cursor(2, 4)
512 call feedkeys("ioooooooo\<c-g>k\<c-r>.\<esc>", 'tnix')
513 call assert_equal(['foooooooooobar', 'foooooooooobar', 'foobar'], getline(1, '$'))
514 call assert_equal([0, 1, 11, 0], getpos('.'))
515 call feedkeys("i\<c-g>k\<esc>", 'tnix')
516 call assert_equal([0, 1, 10, 0], getpos('.'))
517 call cursor(2, 4)
518 call feedkeys("i\<c-g>jzzzz\<esc>", 'tnix')
519 call assert_equal(['foooooooooobar', 'foooooooooobar', 'foozzzzbar'], getline(1, '$'))
520 call assert_equal([0, 3, 7, 0], getpos('.'))
521 call feedkeys("i\<c-g>j\<esc>", 'tnix')
522 call assert_equal([0, 3, 6, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100523 bw!
524endfunc
525
526func! Test_edit_CTRL_I()
527 " Tab in completion mode
528 let path=expand("%:p:h")
529 new
530 call setline(1, [path."/", ''])
Bram Moolenaarc5379472017-03-16 22:38:00 +0100531 call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix')
532 call assert_match('runtest\.vim', getline(1))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100533 %d
534 call writefile(['one', 'two', 'three'], 'Xinclude.txt')
535 let include='#include Xinclude.txt'
536 call setline(1, [include, ''])
537 call cursor(2, 1)
538 call feedkeys("A\<c-x>\<tab>\<cr>\<esc>", 'tnix')
539 call assert_equal([include, 'one', ''], getline(1, '$'))
540 call feedkeys("2ggC\<c-x>\<tab>\<down>\<cr>\<esc>", 'tnix')
541 call assert_equal([include, 'two', ''], getline(1, '$'))
542 call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix')
543 call assert_equal([include, 'three', ''], getline(1, '$'))
544 call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
545 call assert_equal([include, '', ''], getline(1, '$'))
546 call delete("Xinclude.txt")
547 bw!
548endfunc
549
550func! Test_edit_CTRL_K()
551 " Test pressing CTRL-K (basically only dictionary completion and digraphs
552 " the rest is already covered
553 call writefile(['A', 'AA', 'AAA', 'AAAA'], 'Xdictionary.txt')
554 set dictionary=Xdictionary.txt
555 new
556 call setline(1, 'A')
557 call cursor(1, 1)
558 call feedkeys("A\<c-x>\<c-k>\<cr>\<esc>", 'tnix')
559 call assert_equal(['AA', ''], getline(1, '$'))
560 %d
561 call setline(1, 'A')
562 call cursor(1, 1)
563 call feedkeys("A\<c-x>\<c-k>\<down>\<cr>\<esc>", 'tnix')
564 call assert_equal(['AAA'], getline(1, '$'))
565 %d
566 call setline(1, 'A')
567 call cursor(1, 1)
568 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<cr>\<esc>", 'tnix')
569 call assert_equal(['AAAA'], getline(1, '$'))
570 %d
571 call setline(1, 'A')
572 call cursor(1, 1)
573 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
574 call assert_equal(['A'], getline(1, '$'))
575 %d
576 call setline(1, 'A')
577 call cursor(1, 1)
578 call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
579 call assert_equal(['AA'], getline(1, '$'))
580
581 " press an unexecpted key after dictionary completion
582 %d
583 call setline(1, 'A')
584 call cursor(1, 1)
585 call feedkeys("A\<c-x>\<c-k>\<c-]>\<cr>\<esc>", 'tnix')
586 call assert_equal(['AA', ''], getline(1, '$'))
587 %d
588 call setline(1, 'A')
589 call cursor(1, 1)
590 call feedkeys("A\<c-x>\<c-k>\<c-s>\<cr>\<esc>", 'tnix')
591 call assert_equal(["AA\<c-s>", ''], getline(1, '$'))
592 %d
593 call setline(1, 'A')
594 call cursor(1, 1)
595 call feedkeys("A\<c-x>\<c-k>\<c-f>\<cr>\<esc>", 'tnix')
596 call assert_equal(["AA\<c-f>", ''], getline(1, '$'))
597
598 set dictionary=
599 %d
600 call setline(1, 'A')
601 call cursor(1, 1)
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100602 let v:testing = 1
603 try
604 call feedkeys("A\<c-x>\<c-k>\<esc>", 'tnix')
605 catch
606 " error sleeps 2 seconds, when v:testing is not set
607 let v:testing = 0
608 endtry
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100609 call delete('Xdictionary.txt')
610
611 if has("multi_byte")
612 call test_override("char_avail", 1)
613 set showcmd
614 %d
615 call feedkeys("A\<c-k>a:\<esc>", 'tnix')
616 call assert_equal(['ä'], getline(1, '$'))
617 call test_override("char_avail", 0)
618 set noshowcmd
619 endif
620 bw!
621endfunc
622
623func! Test_edit_CTRL_L()
624 " Test Ctrl-X Ctrl-L (line completion)
625 new
626 set complete=.
627 call setline(1, ['one', 'two', 'three', '', '', '', ''])
628 call cursor(4, 1)
629 call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix')
630 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
631 call feedkeys("cct\<c-x>\<c-l>\<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>\<esc>", 'tnix')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100634 call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$'))
Bram Moolenaar02ae9b42018-02-09 15:06:02 +0100635 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100636 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
Bram Moolenaar02ae9b42018-02-09 15:06:02 +0100637 call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
638 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100639 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix')
640 call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$'))
641 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix')
642 call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
643 call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix')
644 call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
645 set complete=
646 call cursor(5, 1)
647 call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix')
648 call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$'))
649 set complete&
650 %d
651 if has("conceal") && has("syntax")
652 call setline(1, ['foo', 'bar', 'foobar'])
653 call test_override("char_avail", 1)
654 set conceallevel=2 concealcursor=n
655 syn on
656 syn match ErrorMsg "^bar"
657 call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'})
658 func! DoIt()
659 let g:change=1
660 endfunc
661 au! TextChangedI <buffer> :call DoIt()
662
663 call cursor(2, 1)
664 call assert_false(exists("g:change"))
665 call feedkeys("A \<esc>", 'tnix')
666 call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$'))
667 call assert_equal(1, g:change)
668
669 call test_override("char_avail", 0)
670 call clearmatches()
671 syn off
672 au! TextChangedI
673 delfu DoIt
674 unlet! g:change
675 endif
676 bw!
677endfunc
678
679func! Test_edit_CTRL_N()
680 " Check keyword completion
681 new
682 set complete=.
683 call setline(1, ['INFER', 'loWER', '', '', ])
684 call cursor(3, 1)
685 call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix")
686 call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix')
687 call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$'))
688 %d
689 call setline(1, ['INFER', 'loWER', '', '', ])
690 call cursor(3, 1)
691 set ignorecase infercase
692 call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix")
693 call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix')
694 call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$'))
695
696 set noignorecase noinfercase complete&
697 bw!
698endfunc
699
700func! Test_edit_CTRL_O()
701 " Check for CTRL-O in insert mode
702 new
703 inoreabbr <buffer> h here some more
704 call setline(1, ['abc', 'def'])
705 call cursor(1, 1)
706 " Ctrl-O after an abbreviation
707 exe "norm A h\<c-o>:set nu\<cr> text"
708 call assert_equal(['abc here some more text', 'def'], getline(1, '$'))
709 call assert_true(&nu)
710 set nonu
711 iunabbr <buffer> h
712 " Ctrl-O at end of line with 've'=onemore
713 call cursor(1, 1)
714 call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix')
715 call assert_equal([0, 1, 23, 0], g:a)
716 call cursor(1, 1)
717 set ve=onemore
718 call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix')
719 call assert_equal([0, 1, 24, 0], g:a)
720 set ve=
721 unlet! g:a
722 bw!
723endfunc
724
725func! Test_edit_CTRL_R()
726 " Insert Register
727 new
728 call test_override("ALL", 1)
729 set showcmd
730 call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix')
731 call feedkeys("O\<c-r>.", 'tnix')
732 call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix')
733 call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix')
734 call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$'))
735 call test_override("ALL", 0)
736 set noshowcmd
737 bw!
738endfunc
739
740func! Test_edit_CTRL_S()
741 " Test pressing CTRL-S (basically only spellfile completion)
742 " the rest is already covered
743 new
744 if !has("spell")
745 call setline(1, 'vim')
746 call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix')
747 call assert_equal(['vims', ''], getline(1, '$'))
748 bw!
749 return
750 endif
751 call setline(1, 'vim')
752 " spell option not yet set
753 try
754 call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix')
755 catch /^Vim\%((\a\+)\)\=:E756/
756 call assert_true(1, 'error caught')
757 endtry
758 call assert_equal(['vim', ''], getline(1, '$'))
759 %d
760 setl spell spelllang=en
761 call setline(1, 'vim')
762 call cursor(1, 1)
763 call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix')
764 call assert_equal(['Vim', ''], getline(1, '$'))
765 %d
766 call setline(1, 'vim')
767 call cursor(1, 1)
768 call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix')
769 call assert_equal(['Aim'], getline(1, '$'))
770 %d
771 call setline(1, 'vim')
772 call cursor(1, 1)
773 call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix')
774 call assert_equal(['vim', ''], getline(1, '$'))
775 %d
776 " empty buffer
777 call cursor(1, 1)
778 call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix')
779 call assert_equal(['', ''], getline(1, '$'))
780 setl nospell
781 bw!
782endfunc
783
784func! Test_edit_CTRL_T()
785 " Check for CTRL-T and CTRL-X CTRL-T in insert mode
786 " 1) increase indent
787 new
788 call setline(1, "abc")
789 call cursor(1, 1)
790 call feedkeys("A\<c-t>xyz", 'tnix')
791 call assert_equal(["\<tab>abcxyz"], getline(1, '$'))
792 " 2) also when paste option is set
793 set paste
794 call setline(1, "abc")
795 call cursor(1, 1)
796 call feedkeys("A\<c-t>xyz", 'tnix')
797 call assert_equal(["\<tab>abcxyz"], getline(1, '$'))
798 set nopaste
799 " CTRL-X CTRL-T (thesaurus complete)
800 call writefile(['angry furious mad enraged'], 'Xthesaurus')
801 set thesaurus=Xthesaurus
802 call setline(1, 'mad')
803 call cursor(1, 1)
804 call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix')
805 call assert_equal(['mad', ''], getline(1, '$'))
806 %d
807 call setline(1, 'mad')
808 call cursor(1, 1)
809 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix')
810 call assert_equal(['angry', ''], getline(1, '$'))
811 %d
812 call setline(1, 'mad')
813 call cursor(1, 1)
814 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
815 call assert_equal(['furious', ''], getline(1, '$'))
816 %d
817 call setline(1, 'mad')
818 call cursor(1, 1)
819 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
820 call assert_equal(['enraged', ''], getline(1, '$'))
821 %d
822 call setline(1, 'mad')
823 call cursor(1, 1)
824 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
825 call assert_equal(['mad', ''], getline(1, '$'))
826 %d
827 call setline(1, 'mad')
828 call cursor(1, 1)
829 call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
830 call assert_equal(['mad', ''], getline(1, '$'))
831 " Using <c-p> <c-n> when 'complete' is empty
832 set complete=
833 %d
834 call setline(1, 'mad')
835 call cursor(1, 1)
836 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix')
837 call assert_equal(['angry', ''], getline(1, '$'))
838 %d
839 call setline(1, 'mad')
840 call cursor(1, 1)
841 call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix')
842 call assert_equal(['mad', ''], getline(1, '$'))
843 set complete&
844
845 set thesaurus=
846 %d
847 call setline(1, 'mad')
848 call cursor(1, 1)
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100849 let v:testing = 1
850 try
851 call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix')
852 catch
853 " error sleeps 2 seconds, when v:testing is not set
854 let v:testing = 0
855 endtry
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100856 call assert_equal(['mad'], getline(1, '$'))
857 call delete('Xthesaurus')
858 bw!
859endfunc
860
861func! Test_edit_CTRL_U()
862 " Test 'completefunc'
863 new
864 " -1, -2 and -3 are special return values
865 let g:special=0
866 fun! CompleteMonths(findstart, base)
867 if a:findstart
868 " locate the start of the word
869 return g:special
870 else
871 " find months matching with "a:base"
872 let res = []
873 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")
874 if m =~ '^\c'.a:base
875 call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0})
876 endif
877 endfor
878 return {'words': res, 'refresh': 'always'}
879 endif
880 endfun
881 set completefunc=CompleteMonths
882 call setline(1, ['', ''])
883 call cursor(1, 1)
884 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
885 call assert_equal(['X', '', ''], getline(1, '$'))
886 %d
887 let g:special=-1
888 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
889 call assert_equal(['XJan', ''], getline(1, '$'))
890 %d
891 let g:special=-2
892 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
893 call assert_equal(['X', ''], getline(1, '$'))
894 %d
895 let g:special=-3
896 call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
897 call assert_equal(['X', ''], getline(1, '$'))
898 %d
899 let g:special=0
900 call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
901 call assert_equal(['Mar', ''], getline(1, '$'))
902 %d
903 call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix')
904 call assert_equal(['May', ''], getline(1, '$'))
905 %d
906 call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
907 call assert_equal(['M', ''], getline(1, '$'))
908 delfu CompleteMonths
909 %d
910 try
911 call feedkeys("A\<c-x>\<c-u>", 'tnix')
912 call assert_fails(1, 'unknown completion function')
913 catch /^Vim\%((\a\+)\)\=:E117/
914 call assert_true(1, 'E117 error caught')
915 endtry
916 set completefunc=
917 bw!
918endfunc
919
920func! Test_edit_CTRL_Z()
921 " Ctrl-Z when insertmode is not set inserts it literally
922 new
923 call setline(1, 'abc')
924 call feedkeys("A\<c-z>\<esc>", 'tnix')
925 call assert_equal(["abc\<c-z>"], getline(1,'$'))
926 bw!
927 " TODO: How to Test Ctrl-Z in insert mode, e.g. suspend?
928endfunc
929
930func! Test_edit_DROP()
931 if !has("dnd")
932 return
933 endif
934 new
935 call setline(1, ['abc def ghi'])
936 call cursor(1, 1)
937 try
938 call feedkeys("i\<Drop>\<Esc>", 'tnix')
939 call assert_fails(1, 'Invalid register name')
940 catch /^Vim\%((\a\+)\)\=:E353/
941 call assert_true(1, 'error caught')
942 endtry
943 bw!
944endfunc
945
946func! Test_edit_CTRL_V()
947 if has("ebcdic")
948 return
949 endif
950 new
951 call setline(1, ['abc'])
952 call cursor(2, 1)
953 " force some redraws
954 set showmode showcmd
955 "call test_override_char_avail(1)
956 call test_override('ALL', 1)
957 call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix')
958 call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$'))
959
960 if has("rightleft") && exists("+rl")
961 set rl
962 call setline(1, ['abc'])
963 call cursor(2, 1)
964 call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix')
965 call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$'))
966 set norl
967 endif
968
969 call test_override('ALL', 0)
970 set noshowmode showcmd
971 bw!
972endfunc
973
974func! Test_edit_F1()
975 " Pressing <f1>
976 new
977 call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix')
978 set noinsertmode
979 call assert_equal('help', &buftype)
980 bw
981 bw
982endfunc
983
984func! Test_edit_F21()
985 " Pressing <f21>
986 " sends a netbeans command
987 if has("netbeans_intg")
988 new
989 " I have no idea what this is supposed to do :)
990 call feedkeys("A\<F21>\<F1>\<esc>", 'tnix')
991 bw
992 endif
993endfunc
994
995func! Test_edit_HOME_END()
996 " Test Home/End Keys
997 new
998 set foldopen+=hor
999 call setline(1, ['abc', 'def'])
1000 call cursor(1, 1)
1001 call feedkeys("AX\<Home>Y\<esc>", 'tnix')
1002 call cursor(2, 1)
1003 call feedkeys("iZ\<End>Y\<esc>", 'tnix')
1004 call assert_equal(['YabcX', 'ZdefY'], getline(1, '$'))
1005
1006 set foldopen-=hor
1007 bw!
1008endfunc
1009
1010func! Test_edit_INS()
1011 " Test for Pressing <Insert>
1012 new
1013 call setline(1, ['abc', 'def'])
1014 call cursor(1, 1)
1015 call feedkeys("i\<Insert>ZYX>", 'tnix')
1016 call assert_equal(['ZYX>', 'def'], getline(1, '$'))
1017 call setline(1, ['abc', 'def'])
1018 call cursor(1, 1)
1019 call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix')
1020 call assert_equal(['ZYX>bc', 'def'], getline(1, '$'))
1021 bw!
1022endfunc
1023
1024func! Test_edit_LEFT_RIGHT()
1025 " Left, Shift-Left, Right, Shift-Right
1026 new
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001027 call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX'])
1028 let _ww=&ww
1029 set ww=
1030 call cursor(2, 1)
1031 call feedkeys("i\<left>\<esc>", 'tnix')
1032 call assert_equal([0, 2, 1, 0], getpos('.'))
1033 " Is this a bug, <s-left> does not respect whichwrap option
1034 call feedkeys("i\<s-left>\<esc>", 'tnix')
1035 call assert_equal([0, 1, 8, 0], getpos('.'))
1036 call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix')
1037 call assert_equal([0, 1, 1, 0], getpos('.'))
1038 call feedkeys("i\<right>\<esc>", 'tnix')
1039 call assert_equal([0, 1, 1, 0], getpos('.'))
1040 call feedkeys("i\<right>\<right>\<esc>", 'tnix')
1041 call assert_equal([0, 1, 2, 0], getpos('.'))
1042 call feedkeys("A\<right>\<esc>", 'tnix')
1043 call assert_equal([0, 1, 11, 0], getpos('.'))
1044 call feedkeys("A\<s-right>\<esc>", 'tnix')
1045 call assert_equal([0, 2, 1, 0], getpos('.'))
1046 call feedkeys("i\<s-right>\<esc>", 'tnix')
1047 call assert_equal([0, 2, 4, 0], getpos('.'))
1048 call cursor(3, 11)
1049 call feedkeys("A\<right>\<esc>", 'tnix')
1050 call feedkeys("A\<s-right>\<esc>", 'tnix')
1051 call assert_equal([0, 3, 11, 0], getpos('.'))
1052 call cursor(2, 11)
1053 " <S-Right> does not respect 'whichwrap' option
1054 call feedkeys("A\<s-right>\<esc>", 'tnix')
1055 call assert_equal([0, 3, 1, 0], getpos('.'))
1056 " Check motion when 'whichwrap' contains cursor keys for insert mode
1057 set ww+=[,]
1058 call cursor(2, 1)
1059 call feedkeys("i\<left>\<esc>", 'tnix')
1060 call assert_equal([0, 1, 11, 0], getpos('.'))
1061 call cursor(2, 11)
1062 call feedkeys("A\<right>\<esc>", 'tnix')
1063 call assert_equal([0, 3, 1, 0], getpos('.'))
1064 call cursor(2, 11)
1065 call feedkeys("A\<s-right>\<esc>", 'tnix')
1066 call assert_equal([0, 3, 1, 0], getpos('.'))
1067 let &ww = _ww
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001068 bw!
1069endfunc
1070
1071func! Test_edit_MOUSE()
1072 " This is a simple test, since we not really using the mouse here
1073 if !has("mouse")
1074 return
1075 endif
1076 10new
1077 call setline(1, range(1, 100))
1078 call cursor(1, 1)
1079 set mouse=a
1080 call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix')
1081 call assert_equal([0, 4, 1, 0], getpos('.'))
1082 " This should move by one pageDown, but only moves
1083 " by one line when the test is run...
1084 call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix')
1085 call assert_equal([0, 5, 1, 0], getpos('.'))
1086 set nostartofline
1087 call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix')
1088 call assert_equal([0, 6, 1, 0], getpos('.'))
1089 call feedkeys("A\<LeftMouse>\<esc>", 'tnix')
1090 call assert_equal([0, 6, 1, 0], getpos('.'))
1091 call feedkeys("A\<RightMouse>\<esc>", 'tnix')
1092 call assert_equal([0, 6, 1, 0], getpos('.'))
1093 call cursor(1, 100)
1094 norm! zt
1095 " this should move by a screen up, but when the test
1096 " is run, it moves up to the top of the buffer...
1097 call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix')
1098 call assert_equal([0, 1, 1, 0], getpos('.'))
1099 call cursor(1, 30)
1100 norm! zt
1101 call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix')
1102 call assert_equal([0, 1, 1, 0], getpos('.'))
1103 call cursor(1, 30)
1104 norm! zt
1105 call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix')
1106 call assert_equal([0, 1, 1, 0], getpos('.'))
1107 %d
1108 call setline(1, repeat(["12345678901234567890"], 100))
1109 call cursor(2, 1)
1110 call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix')
1111 call assert_equal([0, 2, 20, 0], getpos('.'))
1112 call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix')
1113 call assert_equal([0, 2, 20, 0], getpos('.'))
1114 call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix')
1115 call assert_equal([0, 2, 20, 0], getpos('.'))
1116 call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix')
1117 call assert_equal([0, 2, 20, 0], getpos('.'))
1118 call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix')
1119 call assert_equal([0, 2, 20, 0], getpos('.'))
1120 call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix')
1121 call assert_equal([0, 2, 20, 0], getpos('.'))
1122 set mouse& startofline
1123 bw!
1124endfunc
1125
1126func! Test_edit_PAGEUP_PAGEDOWN()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001127 10new
1128 call setline(1, repeat(['abc def ghi'], 30))
1129 call cursor(1, 1)
1130 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1131 call assert_equal([0, 9, 1, 0], getpos('.'))
1132 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1133 call assert_equal([0, 17, 1, 0], getpos('.'))
1134 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1135 call assert_equal([0, 25, 1, 0], getpos('.'))
1136 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1137 call assert_equal([0, 30, 1, 0], getpos('.'))
1138 call feedkeys("i\<PageDown>\<esc>", 'tnix')
1139 call assert_equal([0, 30, 1, 0], getpos('.'))
1140 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1141 call assert_equal([0, 29, 1, 0], getpos('.'))
1142 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1143 call assert_equal([0, 21, 1, 0], getpos('.'))
1144 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1145 call assert_equal([0, 13, 1, 0], getpos('.'))
1146 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1147 call assert_equal([0, 5, 1, 0], getpos('.'))
1148 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1149 call assert_equal([0, 5, 11, 0], getpos('.'))
1150 " <S-Up> is the same as <PageUp>
1151 " <S-Down> is the same as <PageDown>
1152 call cursor(1, 1)
1153 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1154 call assert_equal([0, 9, 1, 0], getpos('.'))
1155 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1156 call assert_equal([0, 17, 1, 0], getpos('.'))
1157 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1158 call assert_equal([0, 25, 1, 0], getpos('.'))
1159 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1160 call assert_equal([0, 30, 1, 0], getpos('.'))
1161 call feedkeys("i\<S-Down>\<esc>", 'tnix')
1162 call assert_equal([0, 30, 1, 0], getpos('.'))
1163 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1164 call assert_equal([0, 29, 1, 0], getpos('.'))
1165 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1166 call assert_equal([0, 21, 1, 0], getpos('.'))
1167 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1168 call assert_equal([0, 13, 1, 0], getpos('.'))
1169 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1170 call assert_equal([0, 5, 1, 0], getpos('.'))
1171 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1172 call assert_equal([0, 5, 11, 0], getpos('.'))
1173 set nostartofline
1174 call cursor(30, 11)
1175 norm! zt
1176 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1177 call assert_equal([0, 29, 11, 0], getpos('.'))
1178 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1179 call assert_equal([0, 21, 11, 0], getpos('.'))
1180 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1181 call assert_equal([0, 13, 11, 0], getpos('.'))
1182 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1183 call assert_equal([0, 5, 11, 0], getpos('.'))
1184 call feedkeys("A\<PageUp>\<esc>", 'tnix')
1185 call assert_equal([0, 5, 11, 0], getpos('.'))
1186 call cursor(1, 1)
1187 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1188 call assert_equal([0, 9, 11, 0], getpos('.'))
1189 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1190 call assert_equal([0, 17, 11, 0], getpos('.'))
1191 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1192 call assert_equal([0, 25, 11, 0], getpos('.'))
1193 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1194 call assert_equal([0, 30, 11, 0], getpos('.'))
1195 call feedkeys("A\<PageDown>\<esc>", 'tnix')
1196 call assert_equal([0, 30, 11, 0], getpos('.'))
1197 " <S-Up> is the same as <PageUp>
1198 " <S-Down> is the same as <PageDown>
1199 call cursor(30, 11)
1200 norm! zt
1201 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1202 call assert_equal([0, 29, 11, 0], getpos('.'))
1203 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1204 call assert_equal([0, 21, 11, 0], getpos('.'))
1205 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1206 call assert_equal([0, 13, 11, 0], getpos('.'))
1207 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1208 call assert_equal([0, 5, 11, 0], getpos('.'))
1209 call feedkeys("A\<S-Up>\<esc>", 'tnix')
1210 call assert_equal([0, 5, 11, 0], getpos('.'))
1211 call cursor(1, 1)
1212 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1213 call assert_equal([0, 9, 11, 0], getpos('.'))
1214 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1215 call assert_equal([0, 17, 11, 0], getpos('.'))
1216 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1217 call assert_equal([0, 25, 11, 0], getpos('.'))
1218 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1219 call assert_equal([0, 30, 11, 0], getpos('.'))
1220 call feedkeys("A\<S-Down>\<esc>", 'tnix')
1221 call assert_equal([0, 30, 11, 0], getpos('.'))
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001222 bw!
1223endfunc
1224
1225func! Test_edit_forbidden()
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001226 new
1227 " 1) edit in the sandbox is not allowed
1228 call setline(1, 'a')
1229 com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix')
1230 call assert_fails(':Sandbox', 'E48:')
1231 com! Sandbox :sandbox exe "norm! i\<del>"
1232 call assert_fails(':Sandbox', 'E48:')
1233 delcom Sandbox
1234 call assert_equal(['a'], getline(1,'$'))
1235 " 2) edit with textlock set
1236 fu! DoIt()
1237 call feedkeys("i\<del>\<esc>", 'tnix')
1238 endfu
1239 au InsertCharPre <buffer> :call DoIt()
1240 try
1241 call feedkeys("ix\<esc>", 'tnix')
1242 call assert_fails(1, 'textlock')
1243 catch /^Vim\%((\a\+)\)\=:E523/ " catch E523: not allowed here
1244 endtry
1245 " TODO: Might be a bug: should x really be inserted here
1246 call assert_equal(['xa'], getline(1, '$'))
1247 delfu DoIt
1248 try
1249 call feedkeys("ix\<esc>", 'tnix')
1250 call assert_fails(1, 'unknown function')
1251 catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function
1252 endtry
1253 au! InsertCharPre
1254 " 3) edit when completion is shown
1255 fun! Complete(findstart, base)
1256 if a:findstart
1257 return col('.')
1258 else
1259 call feedkeys("i\<del>\<esc>", 'tnix')
1260 return []
1261 endif
1262 endfun
1263 set completefunc=Complete
1264 try
1265 call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix')
1266 call assert_fails(1, 'change in complete function')
1267 catch /^Vim\%((\a\+)\)\=:E523/ " catch E523
1268 endtry
1269 delfu Complete
1270 set completefunc=
1271 if has("rightleft") && exists("+fkmap")
1272 " 4) 'R' when 'fkmap' and 'revins' is set.
1273 set revins fkmap
1274 try
1275 normal Ri
1276 call assert_fails(1, "R with 'fkmap' and 'ri' set")
1277 catch
1278 finally
1279 set norevins nofkmap
1280 endtry
1281 endif
Bram Moolenaareb992cb2017-03-09 18:20:16 +01001282 bw!
1283endfunc
1284
1285func! Test_edit_rightleft()
1286 " Cursor in rightleft mode moves differently
1287 if !exists("+rightleft")
1288 return
1289 endif
1290 call NewWindow(10, 20)
1291 call setline(1, ['abc', 'def', 'ghi'])
1292 call cursor(1, 2)
1293 set rightleft
1294 " Screen looks as expected
1295 let lines = ScreenLines([1, 4], winwidth(0))
1296 let expect = [
1297 \" cba",
1298 \" fed",
1299 \" ihg",
1300 \" ~"]
1301 call assert_equal(join(expect, "\n"), join(lines, "\n"))
1302 " 2) right moves to the left
1303 call feedkeys("i\<right>\<esc>x", 'txin')
1304 call assert_equal(['bc', 'def', 'ghi'], getline(1,'$'))
1305 call cursor(1, 2)
1306 call feedkeys("i\<s-right>\<esc>", 'txin')
1307 call cursor(1, 2)
1308 call feedkeys("i\<c-right>\<esc>", 'txin')
1309 " Screen looks as expected
1310 let lines = ScreenLines([1, 4], winwidth(0))
1311 let expect = [
1312 \" cb",
1313 \" fed",
1314 \" ihg",
1315 \" ~"]
1316 call assert_equal(join(expect, "\n"), join(lines, "\n"))
1317 " 2) left moves to the right
1318 call setline(1, ['abc', 'def', 'ghi'])
1319 call cursor(1, 2)
1320 call feedkeys("i\<left>\<esc>x", 'txin')
1321 call assert_equal(['ac', 'def', 'ghi'], getline(1,'$'))
1322 call cursor(1, 2)
1323 call feedkeys("i\<s-left>\<esc>", 'txin')
1324 call cursor(1, 2)
1325 call feedkeys("i\<c-left>\<esc>", 'txin')
1326 " Screen looks as expected
1327 let lines = ScreenLines([1, 4], winwidth(0))
1328 let expect = [
1329 \" ca",
1330 \" fed",
1331 \" ihg",
1332 \" ~"]
1333 call assert_equal(join(expect, "\n"), join(lines, "\n"))
1334 set norightleft
1335 bw!
1336endfunc
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001337
1338func Test_edit_complete_very_long_name()
Bram Moolenaar15ecbd62017-04-07 14:10:48 +02001339 if !has('unix')
Bram Moolenaar9b810792017-03-31 23:32:53 +02001340 " Long directory names only work on Unix.
1341 return
1342 endif
Bram Moolenaar15ecbd62017-04-07 14:10:48 +02001343
1344 let dirname = getcwd() . "/Xdir"
1345 let longdirname = dirname . repeat('/' . repeat('d', 255), 4)
1346 try
1347 call mkdir(longdirname, 'p')
1348 catch /E739:/
1349 " Long directory name probably not supported.
1350 call delete(dirname, 'rf')
1351 return
1352 endtry
1353
Bram Moolenaarba6ec182017-04-04 22:41:10 +02001354 " Try to get the Vim window position before setting 'columns'.
1355 let winposx = getwinposx()
1356 let winposy = getwinposy()
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001357 let save_columns = &columns
Bram Moolenaar15ecbd62017-04-07 14:10:48 +02001358 " Need at least about 1100 columns to reproduce the problem.
Bram Moolenaarba6ec182017-04-04 22:41:10 +02001359 set columns=2000
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001360 set noswapfile
Bram Moolenaarba6ec182017-04-04 22:41:10 +02001361
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001362 let longfilename = longdirname . '/' . repeat('a', 255)
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001363 call writefile(['Totum', 'Table'], longfilename)
1364 new
1365 exe "next Xfile " . longfilename
1366 exe "normal iT\<C-N>"
1367
1368 bwipe!
1369 exe 'bwipe! ' . longfilename
1370 call delete(dirname, 'rf')
1371 let &columns = save_columns
Bram Moolenaarba6ec182017-04-04 22:41:10 +02001372 if winposx >= 0 && winposy >= 0
1373 exe 'winpos ' . winposx . ' ' . winposy
1374 endif
Bram Moolenaar658a3a22017-03-31 22:27:12 +02001375 set swapfile&
1376endfunc
Bram Moolenaarff930ca2017-10-19 17:12:10 +02001377
1378func Test_edit_quit()
1379 edit foo.txt
1380 split
1381 new
1382 call setline(1, 'hello')
1383 3wincmd w
1384 redraw!
1385 call assert_fails('1q', 'E37:')
1386 bwipe! foo.txt
1387 only
1388endfunc
1389