robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.2.0621: 'autoindent' not stripped with virtualedit=onemore (#40203)00289fa20a

master
20.4 KiB805 linesraw
1" Tests for 'virtualedit'.
2
3func Test_yank_move_change()
4  new
5  call setline(1, [
6	\ "func foo() error {",
7	\ "\tif n, err := bar();",
8	\ "\terr != nil {",
9	\ "\t\treturn err",
10	\ "\t}",
11	\ "\tn = n * n",
12	\ ])
13  set virtualedit=all
14  set ts=4
15  function! MoveSelectionDown(count) abort
16    normal! m`
17    silent! exe "'<,'>move'>+".a:count
18    norm! ``
19  endfunction
20
21  xmap ]e :<C-U>call MoveSelectionDown(v:count1)<CR>
22  2
23  normal 2gg
24  normal J
25  normal jVj
26  normal ]e
27  normal ce
28  bwipe!
29  set virtualedit=
30  set ts=8
31endfunc
32
33func Test_paste_end_of_line()
34  new
35  set virtualedit=all
36  call setline(1, ['456', '123'])
37  normal! gg0"ay$
38  exe "normal! 2G$lllA\<C-O>:normal! \"agP\r"
39  call assert_equal('123456', getline(2))
40
41  bwipe!
42  set virtualedit=
43endfunc
44
45func Test_replace_end_of_line()
46  new
47  set virtualedit=all
48  call setline(1, range(20))
49  exe "normal! gg2jv10lr-"
50  call assert_equal(["1", "-----------", "3"], getline(2,4))
51  call setline(1, range(20))
52  exe "normal! gg2jv10lr\<c-k>hh"
53  call assert_equal(["1", "───────────", "3"], getline(2,4))
54
55  bwipe!
56  set virtualedit=
57endfunc
58
59func Test_edit_CTRL_G()
60  new
61  set virtualedit=insert
62  call setline(1, ['123', '1', '12'])
63  exe "normal! ggA\<c-g>jx\<c-g>jx"
64  call assert_equal(['123', '1  x', '12 x'], getline(1,'$'))
65
66  set virtualedit=all
67  %d_
68  call setline(1, ['1', '12'])
69  exe "normal! ggllix\<c-g>jx"
70  call assert_equal(['1 x', '12x'], getline(1,'$'))
71
72
73  bwipe!
74  set virtualedit=
75endfunc
76
77func Test_edit_change()
78  new
79  set virtualedit=all
80
81  call setline(1, "\t⒌")
82  normal Cx
83  call assert_equal('x', getline(1))
84
85  call setline(1, "\ta̳")
86  normal Cx
87  call assert_equal('x', getline(1))
88
89  call setline(1, "\tβ̳")
90  normal Cx
91  call assert_equal('x', getline(1))
92
93  if has('arabic')
94    call setline(1, "\tلا")
95    normal Cx
96    call assert_equal('x', getline(1))
97  endif
98
99  " Do a visual block change
100  call setline(1, ['a', 'b', 'c'])
101  exe "normal gg3l\<C-V>2jcx"
102  call assert_equal(['a  x', 'b  x', 'c  x'], getline(1, '$'))
103
104  bwipe!
105  set virtualedit=
106endfunc
107
108func Test_edit_special_char()
109  new
110  se ve=all
111  norm a0
112  sil! exe "norm o00000\<Nul>k<a0s"
113
114  bwipe!
115  set virtualedit=
116endfunc
117
118" Tests for pasting at the beginning, end and middle of a tab character
119" in virtual edit mode.
120func Test_paste_in_tab()
121  new
122  call append(0, '')
123  set virtualedit=all
124
125  " Tests for pasting a register with characterwise mode type
126  call setreg('"', 'xyz', 'c')
127
128  " paste (p) unnamed register at the beginning of a tab
129  call setline(1, "a\tb")
130  call cursor(1, 2, 0)
131  normal p
132  call assert_equal('a xyz      b', getline(1))
133
134  " paste (P) unnamed register at the beginning of a tab
135  call setline(1, "a\tb")
136  call cursor(1, 2, 0)
137  normal P
138  call assert_equal("axyz\tb", getline(1))
139
140  " paste (p) unnamed register at the end of a tab
141  call setline(1, "a\tb")
142  call cursor(1, 2, 6)
143  normal p
144  call assert_equal("a\txyzb", getline(1))
145
146  " paste (P) unnamed register at the end of a tab
147  call setline(1, "a\tb")
148  call cursor(1, 2, 6)
149  normal P
150  call assert_equal('a      xyz b', getline(1))
151
152  " Tests for pasting a register with blockwise mode type
153  call setreg('"', 'xyz', 'b')
154
155  " paste (p) unnamed register at the beginning of a tab
156  call setline(1, "a\tb")
157  call cursor(1, 2, 0)
158  normal p
159  call assert_equal('a xyz      b', getline(1))
160
161  " paste (P) unnamed register at the beginning of a tab
162  call setline(1, "a\tb")
163  call cursor(1, 2, 0)
164  normal P
165  call assert_equal("axyz\tb", getline(1))
166
167  " paste (p) unnamed register at the end of a tab
168  call setline(1, "a\tb")
169  call cursor(1, 2, 6)
170  normal p
171  call assert_equal("a\txyzb", getline(1))
172
173  " paste (P) unnamed register at the end of a tab
174  call setline(1, "a\tb")
175  call cursor(1, 2, 6)
176  normal P
177  call assert_equal('a      xyz b', getline(1))
178
179  " Tests for pasting with gp and gP in virtual edit mode
180
181  " paste (gp) unnamed register at the beginning of a tab
182  call setline(1, "a\tb")
183  call cursor(1, 2, 0)
184  normal gp
185  call assert_equal('a xyz      b', getline(1))
186  call assert_equal([0, 1, 12, 0, 12], getcurpos())
187
188  " paste (gP) unnamed register at the beginning of a tab
189  call setline(1, "a\tb")
190  call cursor(1, 2, 0)
191  normal gP
192  call assert_equal("axyz\tb", getline(1))
193  call assert_equal([0, 1, 5, 0, 5], getcurpos())
194
195  " paste (gp) unnamed register at the end of a tab
196  call setline(1, "a\tb")
197  call cursor(1, 2, 6)
198  normal gp
199  call assert_equal("a\txyzb", getline(1))
200  call assert_equal([0, 1, 6, 0, 12], getcurpos())
201
202  " paste (gP) unnamed register at the end of a tab
203  call setline(1, "a\tb")
204  call cursor(1, 2, 6)
205  normal gP
206  call assert_equal('a      xyz b', getline(1))
207  call assert_equal([0, 1, 12, 0, 12], getcurpos())
208
209  " Tests for pasting a named register
210  let @r = 'xyz'
211
212  " paste (gp) named register in the middle of a tab
213  call setline(1, "a\tb")
214  call cursor(1, 2, 2)
215  normal "rgp
216  call assert_equal('a   xyz    b', getline(1))
217  call assert_equal([0, 1, 8, 0, 8], getcurpos())
218
219  " paste (gP) named register in the middle of a tab
220  call setline(1, "a\tb")
221  call cursor(1, 2, 2)
222  normal "rgP
223  call assert_equal('a  xyz     b', getline(1))
224  call assert_equal([0, 1, 7, 0, 7], getcurpos())
225
226  bwipe!
227  set virtualedit=
228endfunc
229
230" Test for yanking a few spaces within a tab to a register
231func Test_yank_in_tab()
232  new
233  let @r = ''
234  call setline(1, "a\tb")
235  set virtualedit=all
236  call cursor(1, 2, 2)
237  normal "ry5l
238  call assert_equal('     ', @r)
239
240  bwipe!
241  set virtualedit=
242endfunc
243
244" Insert "keyword keyw", ESC, C CTRL-N, shows "keyword ykeyword".
245" Repeating CTRL-N fixes it. (Mary Ellen Foster)
246func Test_ve_completion()
247  new
248  set completeopt&vim
249  set virtualedit=all
250  exe "normal ikeyword keyw\<Esc>C\<C-N>"
251  call assert_equal('keyword keyword', getline(1))
252  bwipe!
253  set virtualedit=
254endfunc
255
256" Using "C" then <CR> moves the last remaining character to the next
257" line.  (Mary Ellen Foster)
258func Test_ve_del_to_eol()
259  new
260  set virtualedit=all
261  call append(0, 'all your base are belong to us')
262  call search('are', 'w')
263  exe "normal C\<CR>are belong to vim"
264  call assert_equal(['all your base ', 'are belong to vim'], getline(1, 2))
265  bwipe!
266  set virtualedit=
267endfunc
268
269" When past the end of a line that ends in a single character "b" skips
270" that word.
271func Test_ve_b_past_eol()
272  new
273  set virtualedit=all
274  call append(0, '1 2 3 4 5 6')
275  normal gg^$15lbC7
276  call assert_equal('1 2 3 4 5 7', getline(1))
277  bwipe!
278  set virtualedit=
279endfunc
280
281" Make sure 'i', 'C', 'a', 'A' and 'D' works
282func Test_ve_ins_del()
283  new
284  set virtualedit=all
285  call append(0, ["'i'", "'C'", "'a'", "'A'", "'D'"])
286  call cursor(1, 1)
287  normal $4lix
288  call assert_equal("'i'   x", getline(1))
289  call cursor(2, 1)
290  normal $4lCx
291  call assert_equal("'C'   x", getline(2))
292  call cursor(3, 1)
293  normal $4lax
294  call assert_equal("'a'    x", getline(3))
295  call cursor(4, 1)
296  normal $4lAx
297  call assert_equal("'A'x", getline(4))
298  call cursor(5, 1)
299  normal $4lDix
300  call assert_equal("'D'   x", getline(5))
301  bwipe!
302  set virtualedit=
303endfunc
304
305" Test for yank bug reported by Mark Waggoner.
306func Test_yank_block()
307  new
308  set virtualedit=block
309  call append(0, repeat(['this is a test'], 3))
310  exe "normal gg^2w\<C-V>3jy"
311  call assert_equal("a\na\na\n ", @")
312  bwipe!
313  set virtualedit=
314endfunc
315
316" Test "r" beyond the end of the line
317func Test_replace_after_eol()
318  new
319  set virtualedit=all
320  call append(0, '"r"')
321  normal gg$5lrxa
322  call assert_equal('"r"    x', getline(1))
323  " visual block replace
324  %d _
325  call setline(1, ['a', '', 'b'])
326  exe "normal 2l\<C-V>2jrx"
327  call assert_equal(['a x', '  x', 'b x'], getline(1, '$'))
328  " visual characterwise selection replace after eol
329  %d _
330  call setline(1, 'a')
331  normal 4lv2lrx
332  call assert_equal('a   xxx', getline(1))
333  bwipe!
334  set virtualedit=
335endfunc
336
337" Test "r" on a tab
338" Note that for this test, 'ts' must be 8 (the default).
339func Test_replace_on_tab()
340  new
341  set virtualedit=all
342  call append(0, "'r'\t")
343  normal gg^5lrxAy
344  call assert_equal("'r'  x  y", getline(1))
345  call setline(1, 'aaaaaaaaaaaa')
346  exe "normal! gg2lgR\<Tab>"
347  call assert_equal("aa\taaaa", getline(1))
348  bwipe!
349  set virtualedit=
350endfunc
351
352" Test to make sure 'x' can delete control characters
353func Test_ve_del_ctrl_chars()
354  new
355  set virtualedit=all
356  call append(0, "a\<C-V>b\<CR>sd")
357  set display=uhex
358  normal gg^xxxxxxi[text]
359  set display=
360  call assert_equal('[text]', getline(1))
361  bwipe!
362  set virtualedit=
363endfunc
364
365" Test for ^Y/^E due to bad w_virtcol value, reported by
366" Roy <royl@netropolis.net>.
367func Test_ins_copy_char()
368  new
369  set virtualedit=all
370  call append(0, 'abcv8efi.him2kl')
371  exe "normal gg^O\<Esc>3li\<C-E>\<Esc>4li\<C-E>\<Esc>4li\<C-E>   <--"
372  exe "normal j^o\<Esc>4li\<C-Y>\<Esc>4li\<C-Y>\<Esc>4li\<C-Y>   <--"
373  call assert_equal('   v   i   m   <--', getline(1))
374  call assert_equal('    8   .   2   <--', getline(3))
375  bwipe!
376  set virtualedit=
377endfunc
378
379" Test for yanking and pasting using the small delete register
380func Test_yank_paste_small_del_reg()
381  new
382  set virtualedit=all
383  call append(0, "foo, bar")
384  normal ggdewve"-p
385  call assert_equal(', foo', getline(1))
386  bwipe!
387  set virtualedit=
388endfunc
389
390" Test for delete that breaks a tab into spaces
391func Test_delete_break_tab()
392  new
393  call setline(1, "one\ttwo")
394  set virtualedit=all
395  normal v3ld
396  call assert_equal('    two', getline(1))
397  set virtualedit&
398  bw!
399endfunc
400
401" Test for using <BS>, <C-W> and <C-U> in virtual edit mode
402" to erase character, word and line.
403func Test_ve_backspace()
404  new
405  call setline(1, 'sample')
406  set virtualedit=all
407  set backspace=indent,eol,start
408  exe "normal 15|i\<BS>\<BS>"
409  call assert_equal([0, 1, 7, 5], getpos('.'))
410  exe "normal 15|i\<C-W>"
411  call assert_equal([0, 1, 6, 0], getpos('.'))
412  exe "normal 15|i\<C-U>"
413  call assert_equal([0, 1, 1, 0], getpos('.'))
414  set backspace&
415  set virtualedit&
416  bw!
417endfunc
418
419" Test for delete (x) on EOL character and after EOL
420func Test_delete_past_eol()
421  new
422  call setline(1, "ab")
423  set virtualedit=all
424  exe "normal 2lx"
425  call assert_equal('ab', getline(1))
426  exe "normal 10lx"
427  call assert_equal('ab', getline(1))
428  set virtualedit&
429  bw!
430endfunc
431
432" After calling s:TryVirtualeditReplace(), line 1 will contain one of these
433" two strings, depending on whether virtual editing is on or off.
434let s:result_ve_on  = 'a      x'
435let s:result_ve_off = 'x'
436
437" Utility function for Test_global_local_virtualedit()
438func s:TryVirtualeditReplace()
439  call setline(1, 'a')
440  normal gg7l
441  normal rx
442endfunc
443
444" Test for :set and :setlocal
445func Test_global_local_virtualedit()
446  new
447
448  " Verify that 'virtualedit' is initialized to empty, can be set globally to
449  " all and to empty, and can be set locally to all and to empty.
450  call s:TryVirtualeditReplace()
451  call assert_equal(s:result_ve_off, getline(1))
452  set ve=all
453  call s:TryVirtualeditReplace()
454  call assert_equal(s:result_ve_on, getline(1))
455  set ve=
456  call s:TryVirtualeditReplace()
457  call assert_equal(s:result_ve_off, getline(1))
458  setlocal ve=all
459  call s:TryVirtualeditReplace()
460  call assert_equal(s:result_ve_on, getline(1))
461  setlocal ve=
462  call s:TryVirtualeditReplace()
463  call assert_equal(s:result_ve_off, getline(1))
464
465  " Verify that :set affects multiple windows.
466  split
467  set ve=all
468  call s:TryVirtualeditReplace()
469  call assert_equal(s:result_ve_on, getline(1))
470  wincmd p
471  call s:TryVirtualeditReplace()
472  call assert_equal(s:result_ve_on, getline(1))
473  set ve=
474  wincmd p
475  call s:TryVirtualeditReplace()
476  call assert_equal(s:result_ve_off, getline(1))
477  bwipe!
478
479  " Verify that :setlocal affects only the current window.
480  new
481  split
482  setlocal ve=all
483  call s:TryVirtualeditReplace()
484  call assert_equal(s:result_ve_on, getline(1))
485  wincmd p
486  call s:TryVirtualeditReplace()
487  call assert_equal(s:result_ve_off, getline(1))
488  bwipe!
489  call s:TryVirtualeditReplace()
490  call assert_equal(s:result_ve_off, getline(1))
491
492  " Verify that the buffer 'virtualedit' state follows the global value only
493  " when empty and that "none" works as expected.
494  "
495  "          'virtualedit' State
496  " +--------+--------------------------+
497  " | Local  |          Global          |
498  " |        |                          |
499  " +--------+--------+--------+--------+
500  " |        | ""     | "all"  | "none" |
501  " +--------+--------+--------+--------+
502  " | ""     |  off   |  on    |  off   |
503  " | "all"  |  on    |  on    |  on    |
504  " | "none" |  off   |  off   |  off   |
505  " +--------+--------+--------+--------+
506  new
507
508  setglobal ve=
509  setlocal ve=
510  call s:TryVirtualeditReplace()
511  call assert_equal(s:result_ve_off, getline(1))
512  setlocal ve=all
513  call s:TryVirtualeditReplace()
514  call assert_equal(s:result_ve_on, getline(1))
515  setlocal ve=none
516  call s:TryVirtualeditReplace()
517  call assert_equal(s:result_ve_off, getline(1))
518
519  setglobal ve=all
520  setlocal ve=
521  call s:TryVirtualeditReplace()
522  call assert_equal(s:result_ve_on, getline(1))
523  setlocal ve=all
524  call s:TryVirtualeditReplace()
525  call assert_equal(s:result_ve_on, getline(1))
526  setlocal ve=none
527  call s:TryVirtualeditReplace()
528  call assert_equal(s:result_ve_off, getline(1))
529  setlocal ve=NONE
530  call s:TryVirtualeditReplace()
531  call assert_equal(s:result_ve_off, getline(1))
532
533  setglobal ve=none
534  setlocal ve=
535  call s:TryVirtualeditReplace()
536  call assert_equal(s:result_ve_off, getline(1))
537  setlocal ve=all
538  call s:TryVirtualeditReplace()
539  call assert_equal(s:result_ve_on, getline(1))
540  setlocal ve=none
541  call s:TryVirtualeditReplace()
542  call assert_equal(s:result_ve_off, getline(1))
543
544  bwipe!
545
546  " Verify that the 'virtualedit' state is copied to new windows.
547  new
548  call s:TryVirtualeditReplace()
549  call assert_equal(s:result_ve_off, getline(1))
550  split
551  setlocal ve=all
552  call s:TryVirtualeditReplace()
553  call assert_equal(s:result_ve_on, getline(1))
554  split
555  call s:TryVirtualeditReplace()
556  call assert_equal(s:result_ve_on, getline(1))
557  setlocal ve=
558  split
559  call s:TryVirtualeditReplace()
560  call assert_equal(s:result_ve_off, getline(1))
561  bwipe!
562
563  setlocal virtualedit&
564  set virtualedit&
565endfunc
566
567func Test_virtualedit_setlocal()
568  enew
569  setglobal virtualedit=all
570  setlocal virtualedit=all
571  normal! l
572  redraw
573  setlocal virtualedit=none
574  call assert_equal(1, wincol())
575
576  setlocal virtualedit&
577  set virtualedit&
578endfunc
579
580func Test_virtualedit_mouse()
581  let save_mouse = &mouse
582  set mouse=a
583  set virtualedit=all
584  botright new
585  let row = win_screenpos(0)[0]
586  20vsplit
587  wincmd p
588
589  call setline(1, ["text\tword"])
590  redraw
591  call Ntest_setmouse(row, 21 + 4)
592  call feedkeys("\<LeftMouse>", "xt")
593  call assert_equal([0, 1, 4, 0, 4], getcurpos())
594  call Ntest_setmouse(row, 21 + 5)
595  call feedkeys("\<LeftMouse>", "xt")
596  call assert_equal([0, 1, 5, 0, 5], getcurpos())
597  call Ntest_setmouse(row, 21 + 6)
598  call feedkeys("\<LeftMouse>", "xt")
599  call assert_equal([0, 1, 5, 1, 6], getcurpos())
600  call Ntest_setmouse(row, 21 + 7)
601  call feedkeys("\<LeftMouse>", "xt")
602  call assert_equal([0, 1, 5, 2, 7], getcurpos())
603  call Ntest_setmouse(row, 21 + 8)
604  call feedkeys("\<LeftMouse>", "xt")
605  call assert_equal([0, 1, 5, 3, 8], getcurpos())
606  call Ntest_setmouse(row, 21 + 9)
607  call feedkeys("\<LeftMouse>", "xt")
608  call assert_equal([0, 1, 6, 0, 9], getcurpos())
609  call Ntest_setmouse(row, 21 + 12)
610  call feedkeys("\<LeftMouse>", "xt")
611  call assert_equal([0, 1, 9, 0, 12], getcurpos())
612  call Ntest_setmouse(row, 21 + 13)
613  call feedkeys("\<LeftMouse>", "xt")
614  call assert_equal([0, 1, 10, 0, 13], getcurpos())
615  call Ntest_setmouse(row, 21 + 15)
616  call feedkeys("\<LeftMouse>", "xt")
617  call assert_equal([0, 1, 10, 2, 15], getcurpos())
618  call Ntest_setmouse(row, 21 + 20)
619  call feedkeys("\<LeftMouse>", "xt")
620  call assert_equal([0, 1, 10, 7, 20], getcurpos())
621
622  setlocal nowrap
623  call setline(2, repeat('a', 19))
624  normal! j14zl
625  redraw
626  call Ntest_setmouse(row, 21 + 1)
627  call feedkeys("\<LeftMouse>", "xt")
628  call assert_equal([0, 1, 10, 2, 15], getcurpos())
629  call Ntest_setmouse(row, 21 + 11)
630  call feedkeys("\<LeftMouse>", "xt")
631  call assert_equal([0, 1, 10, 12, 25], getcurpos())
632  call Ntest_setmouse(row + 1, 21 + 1)
633  call feedkeys("\<LeftMouse>", "xt")
634  call assert_equal([0, 2, 15, 0, 15], getcurpos())
635  call Ntest_setmouse(row + 1, 21 + 11)
636  call feedkeys("\<LeftMouse>", "xt")
637  call assert_equal([0, 2, 20, 5, 25], getcurpos())
638
639  setlocal number numberwidth=2
640  redraw
641  call Ntest_setmouse(row, 21 + 3)
642  call feedkeys("\<LeftMouse>", "xt")
643  call assert_equal([0, 1, 10, 2, 15], getcurpos())
644  call Ntest_setmouse(row, 21 + 13)
645  call feedkeys("\<LeftMouse>", "xt")
646  call assert_equal([0, 1, 10, 12, 25], getcurpos())
647  call Ntest_setmouse(row + 1, 21 + 3)
648  call feedkeys("\<LeftMouse>", "xt")
649  call assert_equal([0, 2, 15, 0, 15], getcurpos())
650  call Ntest_setmouse(row + 1, 21 + 13)
651  call feedkeys("\<LeftMouse>", "xt")
652  call assert_equal([0, 2, 20, 5, 25], getcurpos())
653  setlocal nonumber
654
655  if has('signs')
656    sign define Sign1 text=口
657    sign place 1 name=Sign1 line=1
658    sign place 2 name=Sign1 line=2
659    redraw
660    call Ntest_setmouse(row, 21 + 3)
661    call feedkeys("\<LeftMouse>", "xt")
662    call assert_equal([0, 1, 10, 2, 15], getcurpos())
663    call Ntest_setmouse(row, 21 + 13)
664    call feedkeys("\<LeftMouse>", "xt")
665    call assert_equal([0, 1, 10, 12, 25], getcurpos())
666    call Ntest_setmouse(row + 1, 21 + 3)
667    call feedkeys("\<LeftMouse>", "xt")
668    call assert_equal([0, 2, 15, 0, 15], getcurpos())
669    call Ntest_setmouse(row + 1, 21 + 13)
670    call feedkeys("\<LeftMouse>", "xt")
671    call assert_equal([0, 2, 20, 5, 25], getcurpos())
672    sign unplace 1
673    sign unplace 2
674    sign undefine Sign1
675  endif
676
677  wincmd h
678  4wincmd >
679  normal! gg24I.
680  redraw
681  call Ntest_setmouse(row + 1, 12)
682  call feedkeys("\<LeftMouse>", "xt")
683  call assert_equal([0, 1, 24 + 9, 0, 24 + 12], getcurpos())
684  call Ntest_setmouse(row + 1, 13)
685  call feedkeys("\<LeftMouse>", "xt")
686  call assert_equal([0, 1, 24 + 10, 0, 24 + 13], getcurpos())
687  call Ntest_setmouse(row + 1, 15)
688  call feedkeys("\<LeftMouse>", "xt")
689  call assert_equal([0, 1, 24 + 10, 2, 24 + 15], getcurpos())
690  call Ntest_setmouse(row + 1, 20)
691  call feedkeys("\<LeftMouse>", "xt")
692  call assert_equal([0, 1, 24 + 10, 7, 24 + 20], getcurpos())
693
694  bwipe!
695  let &mouse = save_mouse
696  set virtualedit&
697endfunc
698
699" this was replacing the NUL at the end of the line
700func Test_virtualedit_replace_after_tab()
701  new
702  s/\v/	0
703  set ve=all
704  let @" = ''
705  sil! norm vPvr0
706
707  call assert_equal("\t0", getline(1))
708  set ve&
709  bwipe!
710endfunc
711
712" Test that setpos('.') and cursor() behave the same for v:maxcol
713func Test_virtualedit_set_cursor_pos_maxcol()
714  new
715  set virtualedit=all
716
717  call setline(1, 'foobar')
718  exe "normal! V\<Esc>"
719  call assert_equal([0, 1, 1, 0], getpos("'<"))
720  call assert_equal([0, 1, v:maxcol, 0], getpos("'>"))
721  let pos = getpos("'>")
722
723  call cursor(1, 1)
724  call setpos('.', pos)
725  call assert_equal([0, 1, 7, 0], getpos('.'))
726
727  call cursor(1, 1)
728  call cursor(pos[1:])
729  call assert_equal([0, 1, 7, 0], getpos('.'))
730
731  set virtualedit&
732  bwipe!
733endfunc
734
735" Verify that getpos() remains consistent when the cursor is past EOL after
736" toggling Visual mode with virtualedit=all.
737func Test_virtualedit_getpos_stable_past_eol_after_visual()
738  new
739  set virtualedit=all
740  call setline(1, 'abc')
741
742  normal! gg$3l
743  let p1 = getpos('.')
744
745  normal! v
746  redraw
747  exe "normal! \<Esc>"
748
749  let p2 = getpos('.')
750  call assert_equal(p1, p2, 'Position should not be re-encoded after leaving Visual mode')
751
752  set virtualedit&
753  bwipe!
754endfunc
755
756func Test_virtualedit_insert()
757  new
758  set virtualedit=insert
759
760  call feedkeys("ifoobar\<Right>\<Right>\<Right>\<Right>baz\<Esc>", 'tnix')
761  call assert_equal('foobar    baz', getline(1))
762
763  call feedkeys("ccFOOBAR\<Right>\<Right>\<Right>\<Right>BAZ\<Esc>", 'tnix')
764  call assert_equal('FOOBAR    BAZ', getline(1))
765
766  set virtualedit&
767  bwipe!
768endfunc
769
770func Test_set_virtualedit_on_mode_change()
771  new
772  set virtualedit=all
773  augroup testing
774    au ModeChanged n:* set virtualedit=onemore
775    au ModeChanged *:n set virtualedit=all
776    au ModeChanged i:* call cursor(getpos("'^")[1:])
777  augroup END
778
779  call feedkeys("ilkj\<Esc>", 'tnix')
780  call assert_equal([0, 1, 4, 0], getpos('.'))
781
782  call feedkeys("cclkj\<Esc>", 'tnix')
783  call assert_equal([0, 1, 4, 0], getpos('.'))
784
785  au! testing ModeChanged
786  augroup! testing
787  set virtualedit&
788  bwipe!
789endfunc
790
791func Test_strip_autoindent_with_virtualedit_onemore()
792  new
793  setlocal autoindent virtualedit=onemore
794  call feedkeys("i   x\<CR>\<Esc>", 'tnix')
795  call assert_equal(['   x', ''], getline(1, '$'))
796
797  %delete _
798  setlocal virtualedit&
799  call feedkeys("i   x\<CR>\<Esc>", 'tnix')
800  call assert_equal(['   x', ''], getline(1, '$'))
801
802  bwipe!
803endfunc
804
805" vim: shiftwidth=2 sts=2 expandtab