test_textobjects.vim 20 KB

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