robin/laufey

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

zeertzjqvim-patch:9.2.0729: % skips parens on continued quoted lines (#40440)4adf961148

master
20.4 KiB794 linesraw
1" Test for textobjects
2
3source check.vim
4
5func CpoM(line, useM, expected)
6  new
7
8  if a:useM
9    set cpoptions+=M
10  else
11    set cpoptions-=M
12  endif
13
14  call setline(1, a:line)
15
16  call setreg('"', '')
17  normal! ggfrmavi)y
18  call assert_equal(getreg('"'), a:expected[0])
19
20  call setreg('"', '')
21  normal! `afbmavi)y
22  call assert_equal(getreg('"'), a:expected[1])
23
24  call setreg('"', '')
25  normal! `afgmavi)y
26  call assert_equal(getreg('"'), a:expected[2])
27
28  q!
29endfunc
30
31func Test_inner_block_without_cpo_M()
32  call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
33endfunc
34
35func Test_inner_block_with_cpo_M_left_backslash()
36  call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
37endfunc
38
39func Test_inner_block_with_cpo_M_right_backslash()
40  call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
41endfunc
42
43func Test_inner_block_single_char()
44  new
45  call setline(1, "(a)")
46
47  set selection=inclusive
48  let @" = ''
49  call assert_nobeep('norm! 0faviby')
50  call assert_equal('a', @")
51
52  set selection=exclusive
53  let @" = ''
54  call assert_nobeep('norm! 0faviby')
55  call assert_equal('a', @")
56
57  set selection&
58  bwipe!
59endfunc
60
61func Test_quote_selection_selection_exclusive()
62  new
63  call setline(1, "a 'bcde' f")
64  set selection=exclusive
65
66  exe "norm! fdvhi'y"
67  call assert_equal('bcde', @")
68
69  let @" = 'dummy'
70  exe "norm! $gevi'y"
71  call assert_equal('bcde', @")
72
73  let @" = 'dummy'
74  exe "norm! 0fbhvi'y"
75  call assert_equal('bcde', @")
76
77  set selection&vim
78  bw!
79endfunc
80
81func Test_quote_selection_selection_exclusive_abort()
82  new
83  set selection=exclusive
84  call setline(1, "'abzzc'")
85  let exp_curs = [0, 1, 6, 0]
86  call cursor(1,1)
87  exe 'norm! fcdvi"'
88  " make sure to end visual mode to have a clear state
89  exe "norm! \<esc>"
90  call assert_equal(exp_curs, getpos('.'))
91  call cursor(1,1)
92  exe 'norm! fcvi"'
93  exe "norm! \<esc>"
94  call assert_equal(exp_curs, getpos('.'))
95  call cursor(1,2)
96  exe 'norm! vfcoi"'
97  exe "norm! \<esc>"
98  let exp_curs = [0, 1, 2, 0]
99  let exp_visu = [0, 1, 7, 0]
100  call assert_equal(exp_curs, getpos('.'))
101  call assert_equal(exp_visu, getpos("'>"))
102  set selection&vim
103  bw!
104endfunc
105
106" Tests for string and html text objects
107func Test_string_html_objects()
108
109  " Nvim only supports set encoding=utf-8
110  " for e in ['utf-8', 'latin1', 'cp932']
111  for e in ['utf-8']
112    enew!
113    exe 'set enc=' .. e
114
115    let t = '"wo\"rd\\" foo'
116    put =t
117    normal! da"
118    call assert_equal('foo', getline('.'), e)
119
120    let t = "'foo' 'bar' 'piep'"
121    put =t
122    normal! 0va'a'rx
123    call assert_equal("xxxxxxxxxxxx'piep'", getline('.'), e)
124
125    let t = "bla bla `quote` blah"
126    put =t
127    normal! 02f`da`
128    call assert_equal("bla bla blah", getline('.'), e)
129
130    let t = 'out " in "noXno"'
131    put =t
132    normal! 0fXdi"
133    call assert_equal('out " in ""', getline('.'), e)
134
135    let t = "\"'\" 'blah' rep 'buh'"
136    put =t
137    normal! 03f'vi'ry
138    call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'), e)
139
140    set quoteescape=+*-
141    let t = "bla `s*`d-`+++`l**` b`la"
142    put =t
143    normal! di`
144    call assert_equal("bla `` b`la", getline('.'), e)
145
146    let t = 'voo "nah" sdf " asdf" sdf " sdf" sd'
147    put =t
148    normal! $F"va"oha"i"rz
149    call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'), e)
150
151    let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
152    put =t
153    normal! fXdit
154    call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'), e)
155
156    let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-"
157    put =t
158    normal! 0fXdit
159    call assert_equal('-<b></b>-', getline('.'), e)
160
161    let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
162    put =t
163    normal! fXdat
164    call assert_equal('-<b>asdfasdf</b>-', getline('.'), e)
165
166    let t = "-<b>asdX<i>as<b />df</i>asdf</b>-"
167    put =t
168    normal! 0fXdat
169    call assert_equal('--', getline('.'), e)
170
171    let t = "-<b>\ninnertext object\n</b>"
172    put =t
173    normal! dit
174    call assert_equal('-<b></b>', getline('.'), e)
175
176    " copy the tag block from leading indentation before the start tag
177    let t = "    <b>\ntext\n</b>"
178    $put =t
179    normal! 2kvaty
180    call assert_equal("<b>\ntext\n</b>", @", e)
181
182    " copy the tag block from the end tag
183    let t = "<title>\nwelcome\n</title>"
184    $put =t
185    normal! $vaty
186    call assert_equal("<title>\nwelcome\n</title>", @", e)
187
188    " copy the outer tag block from a tag without an end tag
189    let t = "<html>\n<title>welcome\n</html>"
190    $put =t
191    normal! k$vaty
192    call assert_equal("<html>\n<title>welcome\n</html>", @", e)
193
194    " nested tag that has < in a different line from >
195    let t = "<div><div\n></div></div>"
196    $put =t
197    normal! k0vaty
198    call assert_equal("<div><div\n></div></div>", @", e)
199
200    " nested tag with attribute that has < in a different line from >
201    let t = "<div><div\nattr=\"attr\"\n></div></div>"
202    $put =t
203    normal! 2k0vaty
204    call assert_equal("<div><div\nattr=\"attr\"\n></div></div>", @", e)
205
206    " tag, that includes a > in some attribute
207    let t = "<div attr=\"attr >> foo >> bar \">Hello</div>"
208    $put =t
209    normal! fHyit
210    call assert_equal("Hello", @", e)
211
212    " tag, that includes a > in some attribute
213    let t = "<div attr='attr >> foo >> bar '>Hello 123</div>"
214    $put =t
215    normal! fHyit
216    call assert_equal("Hello 123", @", e)
217
218    set quoteescape&
219
220    " this was going beyond the end of the line
221    %del
222    sil! norm i"\
223    sil! norm i"\
224    sil! norm i"\
225    call assert_equal('"\', getline(1))
226
227    bwipe!
228  endfor
229
230  set enc=utf-8
231endfunc
232
233func Test_empty_html_tag()
234  new
235  call setline(1, '<div></div>')
236  normal 0citxxx
237  call assert_equal('<div>xxx</div>', getline(1))
238
239  call setline(1, '<div></div>')
240  normal 0f<cityyy
241  call assert_equal('<div>yyy</div>', getline(1))
242
243  call setline(1, '<div></div>')
244  normal 0f<vitsaaa
245  call assert_equal('aaa', getline(1))
246
247  " selecting a tag block in a non-empty blank line should fail
248  call setline(1, '    ')
249  call assert_beeps('normal $vaty')
250
251  bwipe!
252endfunc
253
254" Tests for match() and matchstr()
255func Test_match()
256  call assert_equal("b", matchstr("abcd", ".", 0, 2))
257  call assert_equal("bc", matchstr("abcd", "..", 0, 2))
258  call assert_equal("c", matchstr("abcd", ".", 2, 0))
259  call assert_equal("a", matchstr("abcd", ".", 0, -1))
260  call assert_equal(-1, match("abcd", ".", 0, 5))
261  call assert_equal(0 , match("abcd", ".", 0, -1))
262  call assert_equal(0 , match('abc', '.', 0, 1))
263  call assert_equal(1 , match('abc', '.', 0, 2))
264  call assert_equal(2 , match('abc', '.', 0, 3))
265  call assert_equal(-1, match('abc', '.', 0, 4))
266  call assert_equal(1 , match('abc', '.', 1, 1))
267  call assert_equal(2 , match('abc', '.', 2, 1))
268  call assert_equal(-1, match('abc', '.', 3, 1))
269  call assert_equal(3 , match('abc', '$', 0, 1))
270  call assert_equal(-1, match('abc', '$', 0, 2))
271  call assert_equal(3 , match('abc', '$', 1, 1))
272  call assert_equal(3 , match('abc', '$', 2, 1))
273  call assert_equal(3 , match('abc', '$', 3, 1))
274  call assert_equal(-1, match('abc', '$', 4, 1))
275  call assert_equal(0 , match('abc', '\zs', 0, 1))
276  call assert_equal(1 , match('abc', '\zs', 0, 2))
277  call assert_equal(2 , match('abc', '\zs', 0, 3))
278  call assert_equal(3 , match('abc', '\zs', 0, 4))
279  call assert_equal(-1, match('abc', '\zs', 0, 5))
280  call assert_equal(1 , match('abc', '\zs', 1, 1))
281  call assert_equal(2 , match('abc', '\zs', 2, 1))
282  call assert_equal(3 , match('abc', '\zs', 3, 1))
283  call assert_equal(-1, match('abc', '\zs', 4, 1))
284endfunc
285
286" This was causing an illegal memory access
287func Test_inner_tag()
288  new
289  norm ixxx
290  call feedkeys("v", 'xt')
291  insert
292x
293x
294.
295  norm it
296  q!
297endfunc
298
299func Test_sentence()
300  enew!
301  call setline(1, 'A sentence.  A sentence?  A sentence!')
302
303  normal yis
304  call assert_equal('A sentence.', @")
305  normal yas
306  call assert_equal('A sentence.  ', @")
307
308  normal )
309
310  normal yis
311  call assert_equal('A sentence?', @")
312  normal yas
313  call assert_equal('A sentence?  ', @")
314
315  normal )
316
317  normal yis
318  call assert_equal('A sentence!', @")
319  normal yas
320  call assert_equal('  A sentence!', @")
321
322  normal 0
323  normal 2yis
324  call assert_equal('A sentence.  ', @")
325  normal 3yis
326  call assert_equal('A sentence.  A sentence?', @")
327  normal 2yas
328  call assert_equal('A sentence.  A sentence?  ', @")
329
330  %delete _
331endfunc
332
333func Test_sentence_with_quotes()
334  enew!
335  call setline(1, 'A "sentence."  A sentence.')
336
337  normal yis
338  call assert_equal('A "sentence."', @")
339  normal yas
340  call assert_equal('A "sentence."  ', @")
341
342  normal )
343
344  normal yis
345  call assert_equal('A sentence.', @")
346  normal yas
347  call assert_equal('  A sentence.', @")
348
349  %delete _
350endfunc
351
352func Test_sentence_with_cursor_on_delimiter()
353  enew!
354  call setline(1, "A '([sentence.])'  A sentence.")
355
356  normal! 15|yis
357  call assert_equal("A '([sentence.])'", @")
358  normal! 15|yas
359  call assert_equal("A '([sentence.])'  ", @")
360
361  normal! 16|yis
362  call assert_equal("A '([sentence.])'", @")
363  normal! 16|yas
364  call assert_equal("A '([sentence.])'  ", @")
365
366  normal! 17|yis
367  call assert_equal("A '([sentence.])'", @")
368  normal! 17|yas
369  call assert_equal("A '([sentence.])'  ", @")
370
371  " don't get stuck on a quote at the start of a sentence
372  %delete _
373  call setline(1, ['A sentence.', '"A sentence"?', 'A sentence!'])
374  normal gg))
375  call assert_equal(3, getcurpos()[1])
376
377  %delete _
378  call setline(1, ['A sentence.', "'A sentence'?", 'A sentence!'])
379  normal gg))
380  call assert_equal(3, getcurpos()[1])
381
382  %delete _
383endfunc
384
385" Test for the paragraph (ap) text object
386func Test_paragraph()
387  new
388  call setline(1, ['First line.', 'Second line.', 'Third line.'])
389  call cursor(2, 1)
390  normal vapy
391  call assert_equal("First line.\nSecond line.\nThird line.\n", @")
392
393  call cursor(2, 1)
394  call assert_beeps('normal vapapy')
395
396  call setline(1, ['First line.', 'Second line.', '  ', ''])
397  call cursor(1, 1)
398  normal vapy
399  call assert_equal("First line.\nSecond line.\n  \n\n", @")
400
401  call setline(1, ['', '', '', 'First line.', 'Second line.'])
402  call cursor(2, 1)
403  normal yap
404  call assert_equal("\n\n\nFirst line.\nSecond line.\n", @")
405  call assert_beeps('normal 3yap')
406  exe "normal \<C-C>"
407
408  %d
409  call setline(1, ['  ', '  ', '  '])
410  call cursor(2, 1)
411  normal Vipy
412  call assert_equal("  \n  \n  \n", @")
413  call cursor(2, 1)
414  call assert_beeps("normal Vipip")
415  exe "normal \<C-C>"
416
417  bw!
418endfunc
419
420" Tests for text object aw
421func Test_textobj_a_word()
422  new
423  call append(0, ['foobar,eins,foobar', 'foo,zwei,foo    '])
424  " diw
425  norm! 1gg0diw
426  call assert_equal([',eins,foobar', 'foo,zwei,foo    ', ''], getline(1,'$'))
427  " daw
428  norm! 2ggEdaw
429  call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
430  " daw the last word in a line
431  call setline(1, ['foo bar', 'foo bar', ''])
432  call cursor(1, 5)
433  normal daw
434  call assert_equal('foo', getline(1))
435  " aw in visual mode
436  call cursor(2, 5)
437  normal! vawx
438  call assert_equal('foo', getline(2))
439  %d
440  call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo   "])
441  " diW
442  norm! 2ggwd2iW
443  call assert_equal(['foo	eins	foobar', 'foo	foo   ', ''], getline(1,'$'))
444  " daW
445  norm! 1ggd2aW
446  call assert_equal(['foobar', 'foo	foo   ', ''], getline(1,'$'))
447
448  %d
449  call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo   "])
450  " aw in visual line mode switches to characterwise mode
451  norm! 2gg$Vawd
452  call assert_equal(['foo	eins	foobar', 'foo	zwei	foo'], getline(1,'$'))
453  norm! 1gg$Viwd
454  call assert_equal(['foo	eins	', 'foo	zwei	foo'], getline(1,'$'))
455
456  " visually selecting a tab before a word with 'selection' set to 'exclusive'
457  set selection=exclusive
458  normal gg3lvlawy
459  call assert_equal("\teins", @")
460  " visually selecting a tab before a word with 'selection' set to 'inclusive'
461  set selection=inclusive
462  normal gg3lvlawy
463  call assert_equal("\teins\t", @")
464  set selection&
465
466  " selecting a word with no non-space characters in a buffer fails
467  %d
468  call setline(1, '    ')
469  call assert_beeps('normal 3lyaw')
470
471  " visually selecting words backwards with no more words to select
472  call setline(1, 'one two')
473  call assert_beeps('normal 2lvh2aw')
474  exe "normal \<C-C>"
475  call assert_beeps('normal $vh3aw')
476  exe "normal \<C-C>"
477  call setline(1, ['', 'one two'])
478  call assert_beeps('normal 2G2lvh3aw')
479  exe "normal \<C-C>"
480
481  " selecting words forward with no more words to select
482  %d
483  call setline(1, 'one a')
484  call assert_beeps('normal 0y3aw')
485  call setline(1, 'one two ')
486  call assert_beeps('normal 0y3aw')
487  call assert_beeps('normal 03ly2aw')
488
489  " clean up
490  bw!
491endfunc
492
493" Test for is and as text objects
494func Test_textobj_sentence()
495  new
496  call append(0, ['This is a test. With some sentences!', '',
497        \ 'Even with a question? And one more. And no sentence here'])
498  " Test for dis - does not remove trailing whitespace
499  norm! 1gg0dis
500  call assert_equal([' With some sentences!', '',
501        \ 'Even with a question? And one more. And no sentence here', ''],
502        \ getline(1,'$'))
503  " Test for das - removes leading whitespace
504  norm! 3ggf?ldas
505  call assert_equal([' With some sentences!', '',
506        \ 'Even with a question? And no sentence here', ''], getline(1,'$'))
507  " when used in visual mode, is made characterwise
508  norm! 3gg$Visy
509  call assert_equal('v', visualmode())
510  " reset visualmode()
511  norm! 3ggVy
512  norm! 3gg$Vasy
513  call assert_equal('v', visualmode())
514  " basic testing for textobjects a< and at
515  %d
516  call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>','    </div>', ' '])
517  " a<
518  norm! 1gg0da<
519  call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', '    </div>', ' '], getline(1,'$'))
520  norm! 1pj
521  call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', '    </div>', ' '], getline(1,'$'))
522  " at
523  norm! d2at
524  call assert_equal([' '], getline(1,'$'))
525  %d
526  call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>','    </div>', ' '])
527  " i<
528  norm! 1gg0di<
529  call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', '    </div>', ' '], getline(1,'$'))
530  norm! 1Pj
531  call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', '    </div>', ' '], getline(1,'$'))
532  norm! d2it
533  call assert_equal(['<div></div>',' '], getline(1,'$'))
534  " basic testing for a[ and i[ text object
535  %d
536  call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
537  norm! 3gg0di[
538  call assert_equal([' ', '[', ']'], getline(1,'$'))
539  call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
540  norm! 3gg0ftd2a[
541  call assert_equal([' '], getline(1,'$'))
542
543  " clean up
544  bw!
545endfunc
546
547" Test for quote (', " and `) textobjects
548func Test_textobj_quote()
549  new
550
551  " Test for i" when cursor is in front of a quoted object
552  call append(0, 'foo "bar"')
553  norm! 1gg0di"
554  call assert_equal(['foo ""', ''], getline(1,'$'))
555
556  " Test for visually selecting an inner quote
557  %d
558  " extend visual selection from one quote to the next
559  call setline(1, 'color "red" color "blue"')
560  call cursor(1, 7)
561  normal v4li"y
562  call assert_equal('"red" color "blue', @")
563
564  " try to extend visual selection from one quote to a non-existing quote
565  call setline(1, 'color "red" color blue')
566  call cursor(1, 7)
567  call feedkeys('v4li"y', 'xt')
568  call assert_equal('"red"', @")
569
570  " try to extend visual selection from one quote to a next partial quote
571  call setline(1, 'color "red" color "blue')
572  call cursor(1, 7)
573  normal v4li"y
574  call assert_equal('"red" color ', @")
575
576  " select a quote backwards in visual mode
577  call cursor(1, 12)
578  normal vhi"y
579  call assert_equal('red" ', @")
580  call assert_equal(8, col('.'))
581
582  " select a quote backwards in visual mode from outside the quote
583  call cursor(1, 17)
584  normal v2hi"y
585  call assert_equal('red', @")
586  call assert_equal(8, col('.'))
587
588  " visually selecting a quote with 'selection' set to 'exclusive'
589  call setline(1, 'He said "How are you?"')
590  set selection=exclusive
591  normal 012lv2li"y
592  call assert_equal('How are you?', @")
593  set selection&
594
595  " try copy a quote object with a single quote in the line
596  call setline(1, "Smith's car")
597  call cursor(1, 6)
598  call assert_beeps("normal yi'")
599  call assert_beeps("normal 2lyi'")
600
601  " selecting space before and after a quoted string
602  call setline(1, "some    'special'    string")
603  normal 0ya'
604  call assert_equal("'special'    ", @")
605  call setline(1, "some    'special'string")
606  normal 0ya'
607  call assert_equal("    'special'", @")
608
609  " quoted string with odd or even number of backslashes.
610  call setline(1, 'char *s = "foo\"bar"')
611  normal $hhyi"
612  call assert_equal('foo\"bar', @")
613  call setline(1, 'char *s = "foo\\"bar"')
614  normal $hhyi"
615  call assert_equal('bar', @")
616  call setline(1, 'char *s = "foo\\\"bar"')
617  normal $hhyi"
618  call assert_equal('foo\\\"bar', @")
619  call setline(1, 'char *s = "foo\\\\"bar"')
620  normal $hhyi"
621  call assert_equal('bar', @")
622
623  bw!
624endfunc
625
626" Test for i(, i<, etc. when cursor is in front of a block
627func Test_textobj_find_paren_forward()
628  new
629
630  " i< and a> when cursor is in front of a block
631  call setline(1, '#include <foo.h>')
632  normal 0yi<
633  call assert_equal('foo.h', @")
634  normal 0ya>
635  call assert_equal('<foo.h>', @")
636
637  " 2i(, 3i( in front of a block enters second/third nested '('
638  call setline(1, 'foo (bar (baz (quux)))')
639  normal 0yi)
640  call assert_equal('bar (baz (quux))', @")
641  normal 02yi)
642  call assert_equal('baz (quux)', @")
643  normal 03yi)
644  call assert_equal('quux', @")
645
646  " 3i( in front of a block doesn't enter third but un-nested '('
647  call setline(1, 'foo (bar (baz) (quux))')
648  normal 03di)
649  call assert_equal('foo (bar (baz) (quux))', getline(1))
650  normal 02di)
651  call assert_equal('foo (bar () (quux))', getline(1))
652  normal 0di)
653  call assert_equal('foo ()', getline(1))
654
655  call setline(1, ['x" (a "b" )\', '")'])
656  call cursor(1, 6)
657  normal va)y
658  call assert_equal('(a "b" )', @")
659
660  call setline(1, ['x" [a "b" ]\', '"]'])
661  call cursor(1, 6)
662  normal va]y
663  call assert_equal('[a "b" ]', @")
664
665  bw!
666endfunc
667
668func Test_inner_block_empty_paren()
669  new
670  call setline(1, ["(text)()", "", "(text)(", ")", "", "()()", "", "text()"])
671
672  " Example 1
673  call cursor(1, 1)
674  let @" = ''
675  call assert_beeps(':call feedkeys("0f(viby","xt")')
676  call assert_equal(7, getpos('.')[2])
677  call assert_equal('(', @")
678
679  " Example 2
680  call cursor(3, 1)
681  let @" = ''
682  call assert_beeps('call feedkeys("0f(viby", "xt")')
683  call assert_equal(7, getpos('.')[2])
684  call assert_equal('(', @")
685
686  " Example 3
687  call cursor(6, 1)
688  let @" = ''
689  call assert_beeps('call feedkeys("0f(viby", "xt")')
690  call assert_equal(3, getpos('.')[2])
691  call assert_equal('(', @")
692
693  " Change empty inner block
694  call cursor(8, 1)
695  call feedkeys("0cibtext", "xt")
696  call assert_equal("text(text)", getline('.'))
697
698  bwipe!
699endfunc
700
701func Test_inner_block_empty_bracket()
702  new
703  call setline(1, ["[text][]", "", "[text][", "]", "", "[][]", "", "text[]"])
704
705  " Example 1
706  call cursor(1, 1)
707  let @" = ''
708  call assert_beeps(':call feedkeys("0f[viby","xt")')
709  call assert_equal(7, getpos('.')[2])
710  call assert_equal('[', @")
711
712  " Example 2
713  call cursor(3, 1)
714  let @" = ''
715  call assert_beeps('call feedkeys("0f[viby", "xt")')
716  call assert_equal(7, getpos('.')[2])
717  call assert_equal('[', @")
718
719  " Example 3
720  call cursor(6, 1)
721  let @" = ''
722  call assert_beeps('call feedkeys("0f[viby", "xt")')
723  call assert_equal(3, getpos('.')[2])
724  call assert_equal('[', @")
725
726  " Change empty inner block
727  call cursor(8, 1)
728  call feedkeys("0ci[text", "xt")
729  call assert_equal("text[text]", getline('.'))
730
731  bwipe!
732endfunc
733
734func Test_inner_block_empty_brace()
735  new
736  call setline(1, ["{text}{}", "", "{text}{", "}", "", "{}{}", "", "text{}"])
737
738  " Example 1
739  call cursor(1, 1)
740  let @" = ''
741  call assert_beeps(':call feedkeys("0f{viby","xt")')
742  call assert_equal(7, getpos('.')[2])
743  call assert_equal('{', @")
744
745  " Example 2
746  call cursor(3, 1)
747  let @" = ''
748  call assert_beeps('call feedkeys("0f{viby", "xt")')
749  call assert_equal(7, getpos('.')[2])
750  call assert_equal('{', @")
751
752  " Example 3
753  call cursor(6, 1)
754  let @" = ''
755  call assert_beeps('call feedkeys("0f{viby", "xt")')
756  call assert_equal(3, getpos('.')[2])
757  call assert_equal('{', @")
758
759  " Change empty inner block
760  call cursor(8, 1)
761  call feedkeys("0ciBtext", "xt")
762  call assert_equal("text{text}", getline('.'))
763
764  bwipe!
765endfunc
766
767func Test_inner_block_empty_lessthan()
768  new
769  call setline(1, ["<text><>", "", "<text><", ">", "", "<><>"])
770
771  " Example 1
772  call cursor(1, 1)
773  let @" = ''
774  call assert_beeps(':call feedkeys("0f<viby","xt")')
775  call assert_equal(7, getpos('.')[2])
776  call assert_equal('<', @")
777
778  " Example 2
779  call cursor(3, 1)
780  let @" = ''
781  call assert_beeps('call feedkeys("0f<viby", "xt")')
782  call assert_equal(7, getpos('.')[2])
783  call assert_equal('<', @")
784
785  " Example 3
786  call cursor(6, 1)
787  let @" = ''
788  call assert_beeps('call feedkeys("0f<viby", "xt")')
789  call assert_equal(3, getpos('.')[2])
790  call assert_equal('<', @")
791  bwipe!
792endfunc
793
794" vim: shiftwidth=2 sts=2 expandtab