neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_textobjects.vim (20713B)


      1 " Test for textobjects
      2 
      3 source check.vim
      4 
      5 func 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!
     29 endfunc
     30 
     31 func Test_inner_block_without_cpo_M()
     32  call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
     33 endfunc
     34 
     35 func Test_inner_block_with_cpo_M_left_backslash()
     36  call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
     37 endfunc
     38 
     39 func Test_inner_block_with_cpo_M_right_backslash()
     40  call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
     41 endfunc
     42 
     43 func 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!
     59 endfunc
     60 
     61 func 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!
     79 endfunc
     80 
     81 func 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!
    104 endfunc
    105 
    106 " Tests for string and html text objects
    107 func 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
    231 endfunc
    232 
    233 func 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!
    252 endfunc
    253 
    254 " Tests for match() and matchstr()
    255 func 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))
    284 endfunc
    285 
    286 " This was causing an illegal memory access
    287 func Test_inner_tag()
    288  new
    289  norm ixxx
    290  call feedkeys("v", 'xt')
    291  insert
    292 x
    293 x
    294 .
    295  norm it
    296  q!
    297 endfunc
    298 
    299 func 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 _
    331 endfunc
    332 
    333 func 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 _
    350 endfunc
    351 
    352 func 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 _
    383 endfunc
    384 
    385 " Test for the paragraph (ap) text object
    386 func 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!
    418 endfunc
    419 
    420 " Tests for text object aw
    421 func 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!
    491 endfunc
    492 
    493 " Test for is and as text objects
    494 func 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!
    545 endfunc
    546 
    547 " Test for quote (', " and `) textobjects
    548 func 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!
    624 endfunc
    625 
    626 " Test for i(, i<, etc. when cursor is in front of a block
    627 func 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  bw!
    656 endfunc
    657 
    658 func Test_inner_block_empty_paren()
    659  new
    660  call setline(1, ["(text)()", "", "(text)(", ")", "", "()()", "", "text()"])
    661 
    662  " Example 1
    663  call cursor(1, 1)
    664  let @" = ''
    665  call assert_beeps(':call feedkeys("0f(viby","xt")')
    666  call assert_equal(7, getpos('.')[2])
    667  call assert_equal('(', @")
    668 
    669  " Example 2
    670  call cursor(3, 1)
    671  let @" = ''
    672  call assert_beeps('call feedkeys("0f(viby", "xt")')
    673  call assert_equal(7, getpos('.')[2])
    674  call assert_equal('(', @")
    675 
    676  " Example 3
    677  call cursor(6, 1)
    678  let @" = ''
    679  call assert_beeps('call feedkeys("0f(viby", "xt")')
    680  call assert_equal(3, getpos('.')[2])
    681  call assert_equal('(', @")
    682 
    683  " Change empty inner block
    684  call cursor(8, 1)
    685  call feedkeys("0cibtext", "xt")
    686  call assert_equal("text(text)", getline('.'))
    687 
    688  bwipe!
    689 endfunc
    690 
    691 func Test_inner_block_empty_bracket()
    692  new
    693  call setline(1, ["[text][]", "", "[text][", "]", "", "[][]", "", "text[]"])
    694 
    695  " Example 1
    696  call cursor(1, 1)
    697  let @" = ''
    698  call assert_beeps(':call feedkeys("0f[viby","xt")')
    699  call assert_equal(7, getpos('.')[2])
    700  call assert_equal('[', @")
    701 
    702  " Example 2
    703  call cursor(3, 1)
    704  let @" = ''
    705  call assert_beeps('call feedkeys("0f[viby", "xt")')
    706  call assert_equal(7, getpos('.')[2])
    707  call assert_equal('[', @")
    708 
    709  " Example 3
    710  call cursor(6, 1)
    711  let @" = ''
    712  call assert_beeps('call feedkeys("0f[viby", "xt")')
    713  call assert_equal(3, getpos('.')[2])
    714  call assert_equal('[', @")
    715 
    716  " Change empty inner block
    717  call cursor(8, 1)
    718  call feedkeys("0ci[text", "xt")
    719  call assert_equal("text[text]", getline('.'))
    720 
    721  bwipe!
    722 endfunc
    723 
    724 func Test_inner_block_empty_brace()
    725  new
    726  call setline(1, ["{text}{}", "", "{text}{", "}", "", "{}{}", "", "text{}"])
    727 
    728  " Example 1
    729  call cursor(1, 1)
    730  let @" = ''
    731  call assert_beeps(':call feedkeys("0f{viby","xt")')
    732  call assert_equal(7, getpos('.')[2])
    733  call assert_equal('{', @")
    734 
    735  " Example 2
    736  call cursor(3, 1)
    737  let @" = ''
    738  call assert_beeps('call feedkeys("0f{viby", "xt")')
    739  call assert_equal(7, getpos('.')[2])
    740  call assert_equal('{', @")
    741 
    742  " Example 3
    743  call cursor(6, 1)
    744  let @" = ''
    745  call assert_beeps('call feedkeys("0f{viby", "xt")')
    746  call assert_equal(3, getpos('.')[2])
    747  call assert_equal('{', @")
    748 
    749  " Change empty inner block
    750  call cursor(8, 1)
    751  call feedkeys("0ciBtext", "xt")
    752  call assert_equal("text{text}", getline('.'))
    753 
    754  bwipe!
    755 endfunc
    756 
    757 func Test_inner_block_empty_lessthan()
    758  new
    759  call setline(1, ["<text><>", "", "<text><", ">", "", "<><>"])
    760 
    761  " Example 1
    762  call cursor(1, 1)
    763  let @" = ''
    764  call assert_beeps(':call feedkeys("0f<viby","xt")')
    765  call assert_equal(7, getpos('.')[2])
    766  call assert_equal('<', @")
    767 
    768  " Example 2
    769  call cursor(3, 1)
    770  let @" = ''
    771  call assert_beeps('call feedkeys("0f<viby", "xt")')
    772  call assert_equal(7, getpos('.')[2])
    773  call assert_equal('<', @")
    774 
    775  " Example 3
    776  call cursor(6, 1)
    777  let @" = ''
    778  call assert_beeps('call feedkeys("0f<viby", "xt")')
    779  call assert_equal(3, getpos('.')[2])
    780  call assert_equal('<', @")
    781  bwipe!
    782 endfunc
    783 
    784 " vim: shiftwidth=2 sts=2 expandtab