blob: f02619fc09ded28c80434295b4c8f1743a2d07e9 [file] [log] [blame]
Bram Moolenaar00b24be2016-07-23 22:04:47 +02001" Test for textobjects
2
3if !has('textobjects')
4 finish
5endif
6
Bram Moolenaarc5e2b042017-06-05 16:37:07 +02007func CpoM(line, useM, expected)
Bram Moolenaar00b24be2016-07-23 22:04:47 +02008 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!
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020031endfunc
Bram Moolenaar00b24be2016-07-23 22:04:47 +020032
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020033func Test_inner_block_without_cpo_M()
Bram Moolenaar00b24be2016-07-23 22:04:47 +020034 call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020035endfunc
Bram Moolenaar00b24be2016-07-23 22:04:47 +020036
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020037func Test_inner_block_with_cpo_M_left_backslash()
Bram Moolenaar00b24be2016-07-23 22:04:47 +020038 call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020039endfunc
Bram Moolenaar00b24be2016-07-23 22:04:47 +020040
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020041func Test_inner_block_with_cpo_M_right_backslash()
Bram Moolenaar00b24be2016-07-23 22:04:47 +020042 call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
Bram Moolenaarc5e2b042017-06-05 16:37:07 +020043endfunc
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
Bram Moolenaardb510072017-09-28 21:52:17 +020054
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
124" Tests for match() and matchstr()
125func Test_match()
126 call assert_equal("b", matchstr("abcd", ".", 0, 2))
127 call assert_equal("bc", matchstr("abcd", "..", 0, 2))
128 call assert_equal("c", matchstr("abcd", ".", 2, 0))
129 call assert_equal("a", matchstr("abcd", ".", 0, -1))
130 call assert_equal(-1, match("abcd", ".", 0, 5))
131 call assert_equal(0 , match("abcd", ".", 0, -1))
132 call assert_equal(0 , match('abc', '.', 0, 1))
133 call assert_equal(1 , match('abc', '.', 0, 2))
134 call assert_equal(2 , match('abc', '.', 0, 3))
135 call assert_equal(-1, match('abc', '.', 0, 4))
136 call assert_equal(1 , match('abc', '.', 1, 1))
137 call assert_equal(2 , match('abc', '.', 2, 1))
138 call assert_equal(-1, match('abc', '.', 3, 1))
139 call assert_equal(3 , match('abc', '$', 0, 1))
140 call assert_equal(-1, match('abc', '$', 0, 2))
141 call assert_equal(3 , match('abc', '$', 1, 1))
142 call assert_equal(3 , match('abc', '$', 2, 1))
143 call assert_equal(3 , match('abc', '$', 3, 1))
144 call assert_equal(-1, match('abc', '$', 4, 1))
145 call assert_equal(0 , match('abc', '\zs', 0, 1))
146 call assert_equal(1 , match('abc', '\zs', 0, 2))
147 call assert_equal(2 , match('abc', '\zs', 0, 3))
148 call assert_equal(3 , match('abc', '\zs', 0, 4))
149 call assert_equal(-1, match('abc', '\zs', 0, 5))
150 call assert_equal(1 , match('abc', '\zs', 1, 1))
151 call assert_equal(2 , match('abc', '\zs', 2, 1))
152 call assert_equal(3 , match('abc', '\zs', 3, 1))
153 call assert_equal(-1, match('abc', '\zs', 4, 1))
154endfunc
Bram Moolenaar82846a02018-02-09 18:09:54 +0100155
156" This was causing an illegal memory access
157func Test_inner_tag()
158 new
159 norm ixxx
160 call feedkeys("v", 'xt')
161 insert
162x
163x
164.
165 norm it
166 q!
167endfunc
Bram Moolenaar85160712018-06-19 18:27:41 +0200168
169func Test_sentence()
170 enew!
171 call setline(1, 'A sentence. A sentence? A sentence!')
172
173 normal yis
174 call assert_equal('A sentence.', @")
175 normal yas
176 call assert_equal('A sentence. ', @")
177
178 normal )
179
180 normal yis
181 call assert_equal('A sentence?', @")
182 normal yas
183 call assert_equal('A sentence? ', @")
184
185 normal )
186
187 normal yis
188 call assert_equal('A sentence!', @")
189 normal yas
190 call assert_equal(' A sentence!', @")
191
192 normal 0
193 normal 2yis
194 call assert_equal('A sentence. ', @")
195 normal 3yis
196 call assert_equal('A sentence. A sentence?', @")
197 normal 2yas
198 call assert_equal('A sentence. A sentence? ', @")
199
200 %delete _
201endfunc
202
203func Test_sentence_with_quotes()
204 enew!
205 call setline(1, 'A "sentence." A sentence.')
206
207 normal yis
208 call assert_equal('A "sentence."', @")
209 normal yas
210 call assert_equal('A "sentence." ', @")
211
212 normal )
213
214 normal yis
215 call assert_equal('A sentence.', @")
216 normal yas
217 call assert_equal(' A sentence.', @")
218
219 %delete _
220endfunc
221
222func! Test_sentence_with_cursor_on_delimiter()
223 enew!
224 call setline(1, "A '([sentence.])' A sentence.")
225
226 normal! 15|yis
227 call assert_equal("A '([sentence.])'", @")
228 normal! 15|yas
229 call assert_equal("A '([sentence.])' ", @")
230
231 normal! 16|yis
232 call assert_equal("A '([sentence.])'", @")
233 normal! 16|yas
234 call assert_equal("A '([sentence.])' ", @")
235
236 normal! 17|yis
237 call assert_equal("A '([sentence.])'", @")
238 normal! 17|yas
239 call assert_equal("A '([sentence.])' ", @")
240
241 %delete _
242endfunc