1" Test for textobjects
2
3if !has('textobjects')
4  finish
5endif
6
7func CpoM(line, useM, expected)
8  new
9
10  if a:useM
11    set cpoptions+=M
12  else
13    set cpoptions-=M
14  endif
15
16  call setline(1, a:line)
17
18  call setreg('"', '')
19  normal! ggfrmavi)y
20  call assert_equal(getreg('"'), a:expected[0])
21
22  call setreg('"', '')
23  normal! `afbmavi)y
24  call assert_equal(getreg('"'), a:expected[1])
25
26  call setreg('"', '')
27  normal! `afgmavi)y
28  call assert_equal(getreg('"'), a:expected[2])
29
30  q!
31endfunc
32
33func Test_inner_block_without_cpo_M()
34  call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
35endfunc
36
37func Test_inner_block_with_cpo_M_left_backslash()
38  call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
39endfunc
40
41func Test_inner_block_with_cpo_M_right_backslash()
42  call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
43endfunc
44
45func 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  set selection&vim
52  bw!
53endfunc
54
55" Tests for string and html text objects
56func Test_string_html_objects()
57  enew!
58
59  let t = '"wo\"rd\\" foo'
60  put =t
61  normal! da"
62  call assert_equal('foo', getline('.'))
63
64  let t = "'foo' 'bar' 'piep'"
65  put =t
66  normal! 0va'a'rx
67  call assert_equal("xxxxxxxxxxxx'piep'", getline('.'))
68
69  let t = "bla bla `quote` blah"
70  put =t
71  normal! 02f`da`
72  call assert_equal("bla bla blah", getline('.'))
73
74  let t = 'out " in "noXno"'
75  put =t
76  normal! 0fXdi"
77  call assert_equal('out " in ""', getline('.'))
78
79  let t = "\"'\" 'blah' rep 'buh'"
80  put =t
81  normal! 03f'vi'ry
82  call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'))
83
84  set quoteescape=+*-
85  let t = "bla `s*`d-`+++`l**` b`la"
86  put =t
87  normal! di`
88  call assert_equal("bla `` b`la", getline('.'))
89
90  let t = 'voo "nah" sdf " asdf" sdf " sdf" sd'
91  put =t
92  normal! $F"va"oha"i"rz
93  call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'))
94
95  let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
96  put =t
97  normal! fXdit
98  call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'))
99
100  let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-"
101  put =t
102  normal! 0fXdit
103  call assert_equal('-<b></b>-', getline('.'))
104
105  let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
106  put =t
107  normal! fXdat
108  call assert_equal('-<b>asdfasdf</b>-', getline('.'))
109
110  let t = "-<b>asdX<i>as<b />df</i>asdf</b>-"
111  put =t
112  normal! 0fXdat
113  call assert_equal('--', getline('.'))
114
115  let t = "-<b>\ninnertext object\n</b>"
116  put =t
117  normal! dit
118  call assert_equal('-<b></b>', getline('.'))
119
120  set quoteescape&
121  enew!
122endfunc
123
124func Test_empty_html_tag()
125  new
126  call setline(1, '<div></div>')
127  normal 0citxxx
128  call assert_equal('<div>xxx</div>', getline(1))
129
130  call setline(1, '<div></div>')
131  normal 0f<cityyy
132  call assert_equal('<div>yyy</div>', getline(1))
133
134  call setline(1, '<div></div>')
135  normal 0f<vitsaaa
136  call assert_equal('aaa', getline(1))
137
138  bwipe!
139endfunc
140
141" Tests for match() and matchstr()
142func Test_match()
143  call assert_equal("b", matchstr("abcd", ".", 0, 2))
144  call assert_equal("bc", matchstr("abcd", "..", 0, 2))
145  call assert_equal("c", matchstr("abcd", ".", 2, 0))
146  call assert_equal("a", matchstr("abcd", ".", 0, -1))
147  call assert_equal(-1, match("abcd", ".", 0, 5))
148  call assert_equal(0 , match("abcd", ".", 0, -1))
149  call assert_equal(0 , match('abc', '.', 0, 1))
150  call assert_equal(1 , match('abc', '.', 0, 2))
151  call assert_equal(2 , match('abc', '.', 0, 3))
152  call assert_equal(-1, match('abc', '.', 0, 4))
153  call assert_equal(1 , match('abc', '.', 1, 1))
154  call assert_equal(2 , match('abc', '.', 2, 1))
155  call assert_equal(-1, match('abc', '.', 3, 1))
156  call assert_equal(3 , match('abc', '$', 0, 1))
157  call assert_equal(-1, match('abc', '$', 0, 2))
158  call assert_equal(3 , match('abc', '$', 1, 1))
159  call assert_equal(3 , match('abc', '$', 2, 1))
160  call assert_equal(3 , match('abc', '$', 3, 1))
161  call assert_equal(-1, match('abc', '$', 4, 1))
162  call assert_equal(0 , match('abc', '\zs', 0, 1))
163  call assert_equal(1 , match('abc', '\zs', 0, 2))
164  call assert_equal(2 , match('abc', '\zs', 0, 3))
165  call assert_equal(3 , match('abc', '\zs', 0, 4))
166  call assert_equal(-1, match('abc', '\zs', 0, 5))
167  call assert_equal(1 , match('abc', '\zs', 1, 1))
168  call assert_equal(2 , match('abc', '\zs', 2, 1))
169  call assert_equal(3 , match('abc', '\zs', 3, 1))
170  call assert_equal(-1, match('abc', '\zs', 4, 1))
171endfunc
172
173" This was causing an illegal memory access
174func Test_inner_tag()
175  new
176  norm ixxx
177  call feedkeys("v", 'xt')
178  insert
179x
180x
181.
182  norm it
183  q!
184endfunc
185
186func Test_sentence()
187  enew!
188  call setline(1, 'A sentence.  A sentence?  A sentence!')
189
190  normal yis
191  call assert_equal('A sentence.', @")
192  normal yas
193  call assert_equal('A sentence.  ', @")
194
195  normal )
196
197  normal yis
198  call assert_equal('A sentence?', @")
199  normal yas
200  call assert_equal('A sentence?  ', @")
201
202  normal )
203
204  normal yis
205  call assert_equal('A sentence!', @")
206  normal yas
207  call assert_equal('  A sentence!', @")
208
209  normal 0
210  normal 2yis
211  call assert_equal('A sentence.  ', @")
212  normal 3yis
213  call assert_equal('A sentence.  A sentence?', @")
214  normal 2yas
215  call assert_equal('A sentence.  A sentence?  ', @")
216
217  %delete _
218endfunc
219
220func Test_sentence_with_quotes()
221  enew!
222  call setline(1, 'A "sentence."  A sentence.')
223
224  normal yis
225  call assert_equal('A "sentence."', @")
226  normal yas
227  call assert_equal('A "sentence."  ', @")
228
229  normal )
230
231  normal yis
232  call assert_equal('A sentence.', @")
233  normal yas
234  call assert_equal('  A sentence.', @")
235
236  %delete _
237endfunc
238
239func Test_sentence_with_cursor_on_delimiter()
240  enew!
241  call setline(1, "A '([sentence.])'  A sentence.")
242
243  normal! 15|yis
244  call assert_equal("A '([sentence.])'", @")
245  normal! 15|yas
246  call assert_equal("A '([sentence.])'  ", @")
247
248  normal! 16|yis
249  call assert_equal("A '([sentence.])'", @")
250  normal! 16|yas
251  call assert_equal("A '([sentence.])'  ", @")
252
253  normal! 17|yis
254  call assert_equal("A '([sentence.])'", @")
255  normal! 17|yas
256  call assert_equal("A '([sentence.])'  ", @")
257
258  %delete _
259endfunc
260