blob: 34894d068a2a413c6ef3a9018471578fa2a46b1d [file] [log] [blame]
Bram Moolenaar00b24be2016-07-23 22:04:47 +02001" Test for textobjects
2
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003source check.vim
4CheckFeature textobjects
Bram Moolenaar00b24be2016-07-23 22:04:47 +02005
Bram Moolenaarc5e2b042017-06-05 16:37:07 +02006func CpoM(line, useM, expected)
Bram Moolenaar00b24be2016-07-23 22:04:47 +02007 new
8
9 if a:useM
10 set cpoptions+=M
11 else
12 set cpoptions-=M
13 endif
14
15 call setline(1, a:line)
16
17 call setreg('"', '')
18 normal! ggfrmavi)y
19 call assert_equal(getreg('"'), a:expected[0])
20
21 call setreg('"', '')
22 normal! `afbmavi)y
23 call assert_equal(getreg('"'), a:expected[1])
24
25 call setreg('"', '')
26 normal! `afgmavi)y
27 call assert_equal(getreg('"'), a:expected[2])
28
29 q!
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020030endfunc
Bram Moolenaar00b24be2016-07-23 22:04:47 +020031
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020032func Test_inner_block_without_cpo_M()
Bram Moolenaar00b24be2016-07-23 22:04:47 +020033 call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020034endfunc
Bram Moolenaar00b24be2016-07-23 22:04:47 +020035
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020036func Test_inner_block_with_cpo_M_left_backslash()
Bram Moolenaar00b24be2016-07-23 22:04:47 +020037 call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020038endfunc
Bram Moolenaar00b24be2016-07-23 22:04:47 +020039
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020040func Test_inner_block_with_cpo_M_right_backslash()
Bram Moolenaar00b24be2016-07-23 22:04:47 +020041 call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020042endfunc
43
44func Test_quote_selection_selection_exclusive()
45 new
46 call setline(1, "a 'bcde' f")
47 set selection=exclusive
Bram Moolenaar94d9f4f2019-11-21 20:55:26 +010048
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020049 exe "norm! fdvhi'y"
50 call assert_equal('bcde', @")
Bram Moolenaar94d9f4f2019-11-21 20:55:26 +010051
Bram Moolenaar7170b292019-11-17 17:32:28 +010052 let @"='dummy'
53 exe "norm! $gevi'y"
54 call assert_equal('bcde', @")
Bram Moolenaar94d9f4f2019-11-21 20:55:26 +010055
56 let @"='dummy'
57 exe "norm! 0fbhvi'y"
58 call assert_equal('bcde', @")
59
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020060 set selection&vim
61 bw!
62endfunc
Bram Moolenaardb510072017-09-28 21:52:17 +020063
Bram Moolenaar55d3bdb2019-02-22 15:04:17 +010064func Test_quote_selection_selection_exclusive_abort()
65 new
66 set selection=exclusive
67 call setline(1, "'abzzc'")
68 let exp_curs = [0, 1, 6, 0]
69 call cursor(1,1)
70 exe 'norm! fcdvi"'
71 " make sure to end visual mode to have a clear state
72 exe "norm! \<esc>"
73 call assert_equal(exp_curs, getpos('.'))
74 call cursor(1,1)
75 exe 'norm! fcvi"'
76 exe "norm! \<esc>"
77 call assert_equal(exp_curs, getpos('.'))
78 call cursor(1,2)
79 exe 'norm! vfcoi"'
80 exe "norm! \<esc>"
81 let exp_curs = [0, 1, 2, 0]
82 let exp_visu = [0, 1, 7, 0]
83 call assert_equal(exp_curs, getpos('.'))
84 call assert_equal(exp_visu, getpos("'>"))
85 set selection&vim
86 bw!
87endfunc
88
Bram Moolenaardb510072017-09-28 21:52:17 +020089" Tests for string and html text objects
90func Test_string_html_objects()
Bram Moolenaardb510072017-09-28 21:52:17 +020091
Dominique Pelleaf631f62021-09-03 16:50:16 +020092 for e in ['utf-8', 'latin1', 'cp932']
93 enew!
94 exe 'set enc=' .. e
Bram Moolenaardb510072017-09-28 21:52:17 +020095
Dominique Pelleaf631f62021-09-03 16:50:16 +020096 let t = '"wo\"rd\\" foo'
97 put =t
98 normal! da"
99 call assert_equal('foo', getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200100
Dominique Pelleaf631f62021-09-03 16:50:16 +0200101 let t = "'foo' 'bar' 'piep'"
102 put =t
103 normal! 0va'a'rx
104 call assert_equal("xxxxxxxxxxxx'piep'", getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200105
Dominique Pelleaf631f62021-09-03 16:50:16 +0200106 let t = "bla bla `quote` blah"
107 put =t
108 normal! 02f`da`
109 call assert_equal("bla bla blah", getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200110
Dominique Pelleaf631f62021-09-03 16:50:16 +0200111 let t = 'out " in "noXno"'
112 put =t
113 normal! 0fXdi"
114 call assert_equal('out " in ""', getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200115
Dominique Pelleaf631f62021-09-03 16:50:16 +0200116 let t = "\"'\" 'blah' rep 'buh'"
117 put =t
118 normal! 03f'vi'ry
119 call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200120
Dominique Pelleaf631f62021-09-03 16:50:16 +0200121 set quoteescape=+*-
122 let t = "bla `s*`d-`+++`l**` b`la"
123 put =t
124 normal! di`
125 call assert_equal("bla `` b`la", getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200126
Dominique Pelleaf631f62021-09-03 16:50:16 +0200127 let t = 'voo "nah" sdf " asdf" sdf " sdf" sd'
128 put =t
129 normal! $F"va"oha"i"rz
130 call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200131
Dominique Pelleaf631f62021-09-03 16:50:16 +0200132 let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
133 put =t
134 normal! fXdit
135 call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200136
Dominique Pelleaf631f62021-09-03 16:50:16 +0200137 let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-"
138 put =t
139 normal! 0fXdit
140 call assert_equal('-<b></b>-', getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200141
Dominique Pelleaf631f62021-09-03 16:50:16 +0200142 let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
143 put =t
144 normal! fXdat
145 call assert_equal('-<b>asdfasdf</b>-', getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200146
Dominique Pelleaf631f62021-09-03 16:50:16 +0200147 let t = "-<b>asdX<i>as<b />df</i>asdf</b>-"
148 put =t
149 normal! 0fXdat
150 call assert_equal('--', getline('.'), e)
Bram Moolenaardb510072017-09-28 21:52:17 +0200151
Dominique Pelleaf631f62021-09-03 16:50:16 +0200152 let t = "-<b>\ninnertext object\n</b>"
153 put =t
154 normal! dit
155 call assert_equal('-<b></b>', getline('.'), e)
Bram Moolenaar224a5f12020-04-28 20:29:07 +0200156
Dominique Pelleaf631f62021-09-03 16:50:16 +0200157 " copy the tag block from leading indentation before the start tag
158 let t = " <b>\ntext\n</b>"
159 $put =t
160 normal! 2kvaty
161 call assert_equal("<b>\ntext\n</b>", @", e)
Bram Moolenaar224a5f12020-04-28 20:29:07 +0200162
Dominique Pelleaf631f62021-09-03 16:50:16 +0200163 " copy the tag block from the end tag
164 let t = "<title>\nwelcome\n</title>"
165 $put =t
166 normal! $vaty
167 call assert_equal("<title>\nwelcome\n</title>", @", e)
Bram Moolenaar224a5f12020-04-28 20:29:07 +0200168
Dominique Pelleaf631f62021-09-03 16:50:16 +0200169 " copy the outer tag block from a tag without an end tag
170 let t = "<html>\n<title>welcome\n</html>"
171 $put =t
172 normal! k$vaty
173 call assert_equal("<html>\n<title>welcome\n</html>", @", e)
Bram Moolenaara604ccc2020-10-15 21:23:28 +0200174
Dominique Pelleaf631f62021-09-03 16:50:16 +0200175 " nested tag that has < in a different line from >
176 let t = "<div><div\n></div></div>"
177 $put =t
178 normal! k0vaty
179 call assert_equal("<div><div\n></div></div>", @", e)
Bram Moolenaara604ccc2020-10-15 21:23:28 +0200180
Dominique Pelleaf631f62021-09-03 16:50:16 +0200181 " nested tag with attribute that has < in a different line from >
182 let t = "<div><div\nattr=\"attr\"\n></div></div>"
183 $put =t
184 normal! 2k0vaty
185 call assert_equal("<div><div\nattr=\"attr\"\n></div></div>", @", e)
186
187 set quoteescape&
Bram Moolenaar53a70282022-05-09 13:15:07 +0100188
189 " this was going beyond the end of the line
190 %del
191 sil! norm i"\
192 sil! norm i"\
193 sil! norm i"\
194 call assert_equal('"\', getline(1))
195
196 bwipe!
Dominique Pelleaf631f62021-09-03 16:50:16 +0200197 endfor
198
199 set enc=utf-8
Bram Moolenaardb510072017-09-28 21:52:17 +0200200endfunc
201
Bram Moolenaarb476cb72018-08-16 21:37:50 +0200202func Test_empty_html_tag()
203 new
204 call setline(1, '<div></div>')
205 normal 0citxxx
206 call assert_equal('<div>xxx</div>', getline(1))
207
208 call setline(1, '<div></div>')
209 normal 0f<cityyy
210 call assert_equal('<div>yyy</div>', getline(1))
211
212 call setline(1, '<div></div>')
213 normal 0f<vitsaaa
214 call assert_equal('aaa', getline(1))
215
Dominique Pelle923dce22021-11-21 11:36:04 +0000216 " selecting a tag block in a non-empty blank line should fail
Bram Moolenaar224a5f12020-04-28 20:29:07 +0200217 call setline(1, ' ')
218 call assert_beeps('normal $vaty')
219
Bram Moolenaarb476cb72018-08-16 21:37:50 +0200220 bwipe!
221endfunc
222
Bram Moolenaardb510072017-09-28 21:52:17 +0200223" Tests for match() and matchstr()
224func Test_match()
225 call assert_equal("b", matchstr("abcd", ".", 0, 2))
226 call assert_equal("bc", matchstr("abcd", "..", 0, 2))
227 call assert_equal("c", matchstr("abcd", ".", 2, 0))
228 call assert_equal("a", matchstr("abcd", ".", 0, -1))
229 call assert_equal(-1, match("abcd", ".", 0, 5))
Bram Moolenaar9d489562020-07-30 20:08:50 +0200230 call assert_equal(0, match("abcd", ".", 0, -1))
231 call assert_equal(0, match('abc', '.', 0, 1))
232 call assert_equal(1, match('abc', '.', 0, 2))
233 call assert_equal(2, match('abc', '.', 0, 3))
Bram Moolenaardb510072017-09-28 21:52:17 +0200234 call assert_equal(-1, match('abc', '.', 0, 4))
Bram Moolenaar9d489562020-07-30 20:08:50 +0200235 call assert_equal(1, match('abc', '.', 1, 1))
236 call assert_equal(2, match('abc', '.', 2, 1))
Bram Moolenaardb510072017-09-28 21:52:17 +0200237 call assert_equal(-1, match('abc', '.', 3, 1))
Bram Moolenaar9d489562020-07-30 20:08:50 +0200238 call assert_equal(3, match('abc', '$', 0, 1))
Bram Moolenaardb510072017-09-28 21:52:17 +0200239 call assert_equal(-1, match('abc', '$', 0, 2))
Bram Moolenaar9d489562020-07-30 20:08:50 +0200240 call assert_equal(3, match('abc', '$', 1, 1))
241 call assert_equal(3, match('abc', '$', 2, 1))
242 call assert_equal(3, match('abc', '$', 3, 1))
Bram Moolenaardb510072017-09-28 21:52:17 +0200243 call assert_equal(-1, match('abc', '$', 4, 1))
Bram Moolenaar9d489562020-07-30 20:08:50 +0200244 call assert_equal(0, match('abc', '\zs', 0, 1))
245 call assert_equal(1, match('abc', '\zs', 0, 2))
246 call assert_equal(2, match('abc', '\zs', 0, 3))
247 call assert_equal(3, match('abc', '\zs', 0, 4))
Bram Moolenaardb510072017-09-28 21:52:17 +0200248 call assert_equal(-1, match('abc', '\zs', 0, 5))
Bram Moolenaar9d489562020-07-30 20:08:50 +0200249 call assert_equal(1, match('abc', '\zs', 1, 1))
250 call assert_equal(2, match('abc', '\zs', 2, 1))
251 call assert_equal(3, match('abc', '\zs', 3, 1))
Bram Moolenaardb510072017-09-28 21:52:17 +0200252 call assert_equal(-1, match('abc', '\zs', 4, 1))
253endfunc
Bram Moolenaar82846a02018-02-09 18:09:54 +0100254
255" This was causing an illegal memory access
256func Test_inner_tag()
257 new
258 norm ixxx
259 call feedkeys("v", 'xt')
260 insert
261x
262x
263.
264 norm it
265 q!
266endfunc
Bram Moolenaar85160712018-06-19 18:27:41 +0200267
268func Test_sentence()
269 enew!
270 call setline(1, 'A sentence. A sentence? A sentence!')
271
272 normal yis
273 call assert_equal('A sentence.', @")
274 normal yas
275 call assert_equal('A sentence. ', @")
276
277 normal )
278
279 normal yis
280 call assert_equal('A sentence?', @")
281 normal yas
282 call assert_equal('A sentence? ', @")
283
284 normal )
285
286 normal yis
287 call assert_equal('A sentence!', @")
288 normal yas
289 call assert_equal(' A sentence!', @")
290
291 normal 0
292 normal 2yis
293 call assert_equal('A sentence. ', @")
294 normal 3yis
295 call assert_equal('A sentence. A sentence?', @")
296 normal 2yas
297 call assert_equal('A sentence. A sentence? ', @")
298
299 %delete _
300endfunc
301
302func Test_sentence_with_quotes()
303 enew!
304 call setline(1, 'A "sentence." A sentence.')
305
306 normal yis
307 call assert_equal('A "sentence."', @")
308 normal yas
309 call assert_equal('A "sentence." ', @")
310
311 normal )
312
313 normal yis
314 call assert_equal('A sentence.', @")
315 normal yas
316 call assert_equal(' A sentence.', @")
317
318 %delete _
319endfunc
320
Bram Moolenaar1e115362019-01-09 23:01:02 +0100321func Test_sentence_with_cursor_on_delimiter()
Bram Moolenaar85160712018-06-19 18:27:41 +0200322 enew!
323 call setline(1, "A '([sentence.])' A sentence.")
324
325 normal! 15|yis
326 call assert_equal("A '([sentence.])'", @")
327 normal! 15|yas
328 call assert_equal("A '([sentence.])' ", @")
329
330 normal! 16|yis
331 call assert_equal("A '([sentence.])'", @")
332 normal! 16|yas
333 call assert_equal("A '([sentence.])' ", @")
334
335 normal! 17|yis
336 call assert_equal("A '([sentence.])'", @")
337 normal! 17|yas
338 call assert_equal("A '([sentence.])' ", @")
339
Bram Moolenaar2f03e5a2020-06-18 15:33:25 +0200340 " don't get stuck on a quote at the start of a sentence
341 %delete _
342 call setline(1, ['A sentence.', '"A sentence"?', 'A sentence!'])
343 normal gg))
344 call assert_equal(3, getcurpos()[1])
345
346 %delete _
347 call setline(1, ['A sentence.', "'A sentence'?", 'A sentence!'])
348 normal gg))
349 call assert_equal(3, getcurpos()[1])
350
Bram Moolenaar85160712018-06-19 18:27:41 +0200351 %delete _
352endfunc
Bram Moolenaar224a5f12020-04-28 20:29:07 +0200353
354" Test for the paragraph (ap) text object
355func Test_paragraph()
356 new
357 call setline(1, ['First line.', 'Second line.', 'Third line.'])
358 call cursor(2, 1)
359 normal vapy
360 call assert_equal("First line.\nSecond line.\nThird line.\n", @")
361
362 call cursor(2, 1)
363 call assert_beeps('normal vapapy')
364
365 call setline(1, ['First line.', 'Second line.', ' ', ''])
366 call cursor(1, 1)
367 normal vapy
368 call assert_equal("First line.\nSecond line.\n \n\n", @")
369
370 call setline(1, ['', '', '', 'First line.', 'Second line.'])
371 call cursor(2, 1)
372 normal yap
373 call assert_equal("\n\n\nFirst line.\nSecond line.\n", @")
374 call assert_beeps('normal 3yap')
375 exe "normal \<C-C>"
376
377 %d
378 call setline(1, [' ', ' ', ' '])
379 call cursor(2, 1)
380 normal Vipy
381 call assert_equal(" \n \n \n", @")
382 call cursor(2, 1)
383 call assert_beeps("normal Vipip")
384 exe "normal \<C-C>"
385
386 close!
387endfunc
388
389" Tests for text object aw
390func Test_textobj_a_word()
391 new
392 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo '])
393 " diw
394 norm! 1gg0diw
395 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$'))
396 " daw
397 norm! 2ggEdaw
398 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
399 " daw the last word in a line
400 call setline(1, ['foo bar', 'foo bar', ''])
401 call cursor(1, 5)
402 normal daw
403 call assert_equal('foo', getline(1))
404 " aw in visual mode
405 call cursor(2, 5)
406 normal! vawx
407 call assert_equal('foo', getline(2))
408 %d
409 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
410 " diW
411 norm! 2ggwd2iW
412 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$'))
413 " daW
414 norm! 1ggd2aW
415 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$'))
416
417 %d
418 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
419 " aw in visual line mode switches to characterwise mode
420 norm! 2gg$Vawd
421 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$'))
422 norm! 1gg$Viwd
423 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$'))
424
425 " visually selecting a tab before a word with 'selection' set to 'exclusive'
426 set selection=exclusive
427 normal gg3lvlawy
428 call assert_equal("\teins", @")
429 " visually selecting a tab before a word with 'selection' set to 'inclusive'
430 set selection=inclusive
431 normal gg3lvlawy
432 call assert_equal("\teins\t", @")
433 set selection&
434
435 " selecting a word with no non-space characters in a buffer fails
436 %d
437 call setline(1, ' ')
438 call assert_beeps('normal 3lyaw')
439
440 " visually selecting words backwards with no more words to select
441 call setline(1, 'one two')
442 call assert_beeps('normal 2lvh2aw')
443 exe "normal \<C-C>"
444 call assert_beeps('normal $vh3aw')
445 exe "normal \<C-C>"
446 call setline(1, ['', 'one two'])
447 call assert_beeps('normal 2G2lvh3aw')
448 exe "normal \<C-C>"
449
450 " selecting words forward with no more words to select
451 %d
452 call setline(1, 'one a')
453 call assert_beeps('normal 0y3aw')
454 call setline(1, 'one two ')
455 call assert_beeps('normal 0y3aw')
456 call assert_beeps('normal 03ly2aw')
457
458 " clean up
459 bw!
460endfunc
461
462" Test for is and as text objects
463func Test_textobj_sentence()
464 new
465 call append(0, ['This is a test. With some sentences!', '',
466 \ 'Even with a question? And one more. And no sentence here'])
467 " Test for dis - does not remove trailing whitespace
468 norm! 1gg0dis
469 call assert_equal([' With some sentences!', '',
470 \ 'Even with a question? And one more. And no sentence here', ''],
471 \ getline(1,'$'))
472 " Test for das - removes leading whitespace
473 norm! 3ggf?ldas
474 call assert_equal([' With some sentences!', '',
475 \ 'Even with a question? And no sentence here', ''], getline(1,'$'))
476 " when used in visual mode, is made characterwise
477 norm! 3gg$Visy
478 call assert_equal('v', visualmode())
479 " reset visualmode()
480 norm! 3ggVy
481 norm! 3gg$Vasy
482 call assert_equal('v', visualmode())
483 " basic testing for textobjects a< and at
484 %d
485 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
486 " a<
487 norm! 1gg0da<
488 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
489 norm! 1pj
490 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
491 " at
492 norm! d2at
493 call assert_equal([' '], getline(1,'$'))
494 %d
495 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
496 " i<
497 norm! 1gg0di<
498 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
499 norm! 1Pj
500 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
501 norm! d2it
502 call assert_equal(['<div></div>',' '], getline(1,'$'))
503 " basic testing for a[ and i[ text object
504 %d
505 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
506 norm! 3gg0di[
507 call assert_equal([' ', '[', ']'], getline(1,'$'))
508 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
509 norm! 3gg0ftd2a[
510 call assert_equal([' '], getline(1,'$'))
511
512 " clean up
513 bw!
514endfunc
515
516" Test for quote (', " and `) textobjects
517func Test_textobj_quote()
518 new
519
520 " Test for i" when cursor is in front of a quoted object
521 call append(0, 'foo "bar"')
522 norm! 1gg0di"
523 call assert_equal(['foo ""', ''], getline(1,'$'))
524
525 " Test for visually selecting an inner quote
526 %d
527 " extend visual selection from one quote to the next
528 call setline(1, 'color "red" color "blue"')
529 call cursor(1, 7)
530 normal v4li"y
531 call assert_equal('"red" color "blue', @")
532
533 " try to extend visual selection from one quote to a non-existing quote
534 call setline(1, 'color "red" color blue')
535 call cursor(1, 7)
536 call feedkeys('v4li"y', 'xt')
537 call assert_equal('"red"', @")
538
539 " try to extend visual selection from one quote to a next partial quote
540 call setline(1, 'color "red" color "blue')
541 call cursor(1, 7)
542 normal v4li"y
543 call assert_equal('"red" color ', @")
544
545 " select a quote backwards in visual mode
546 call cursor(1, 12)
547 normal vhi"y
548 call assert_equal('red" ', @")
549 call assert_equal(8, col('.'))
550
551 " select a quote backwards in visual mode from outside the quote
552 call cursor(1, 17)
553 normal v2hi"y
554 call assert_equal('red', @")
555 call assert_equal(8, col('.'))
556
557 " visually selecting a quote with 'selection' set to 'exclusive'
558 call setline(1, 'He said "How are you?"')
559 set selection=exclusive
560 normal 012lv2li"y
561 call assert_equal('How are you?', @")
562 set selection&
563
564 " try copy a quote object with a single quote in the line
565 call setline(1, "Smith's car")
566 call cursor(1, 6)
567 call assert_beeps("normal yi'")
568 call assert_beeps("normal 2lyi'")
569
570 " selecting space before and after a quoted string
571 call setline(1, "some 'special' string")
572 normal 0ya'
573 call assert_equal("'special' ", @")
574 call setline(1, "some 'special'string")
575 normal 0ya'
576 call assert_equal(" 'special'", @")
577
Dominique Pelleaf631f62021-09-03 16:50:16 +0200578 " quoted string with odd or even number of backslashes.
579 call setline(1, 'char *s = "foo\"bar"')
580 normal $hhyi"
581 call assert_equal('foo\"bar', @")
582 call setline(1, 'char *s = "foo\\"bar"')
583 normal $hhyi"
584 call assert_equal('bar', @")
585 call setline(1, 'char *s = "foo\\\"bar"')
586 normal $hhyi"
587 call assert_equal('foo\\\"bar', @")
588 call setline(1, 'char *s = "foo\\\\"bar"')
589 normal $hhyi"
590 call assert_equal('bar', @")
591
Bram Moolenaar224a5f12020-04-28 20:29:07 +0200592 close!
593endfunc
594
Connor Lane Smithb9115da2021-07-31 13:31:42 +0200595" Test for i(, i<, etc. when cursor is in front of a block
596func Test_textobj_find_paren_forward()
597 new
598
599 " i< and a> when cursor is in front of a block
600 call setline(1, '#include <foo.h>')
601 normal 0yi<
602 call assert_equal('foo.h', @")
603 normal 0ya>
604 call assert_equal('<foo.h>', @")
605
606 " 2i(, 3i( in front of a block enters second/third nested '('
607 call setline(1, 'foo (bar (baz (quux)))')
608 normal 0yi)
609 call assert_equal('bar (baz (quux))', @")
610 normal 02yi)
611 call assert_equal('baz (quux)', @")
612 normal 03yi)
613 call assert_equal('quux', @")
614
615 " 3i( in front of a block doesn't enter third but un-nested '('
616 call setline(1, 'foo (bar (baz) (quux))')
617 normal 03di)
618 call assert_equal('foo (bar (baz) (quux))', getline(1))
619 normal 02di)
620 call assert_equal('foo (bar () (quux))', getline(1))
621 normal 0di)
622 call assert_equal('foo ()', getline(1))
623
624 close!
625endfunc
626
Bram Moolenaar224a5f12020-04-28 20:29:07 +0200627" vim: shiftwidth=2 sts=2 expandtab