blob: 9fae8070abea019c4e1350ed79256e08c69142d7 [file] [log] [blame]
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001" Tests for defining text property types and adding text properties to the
2" buffer.
3
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02004source check.vim
5CheckFeature textprop
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01007source screendump.vim
Bram Moolenaar62aec932022-01-29 21:45:34 +00008import './vim9.vim' as v9
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01009
Bram Moolenaar98aefe72018-12-13 22:20:09 +010010func Test_proptype_global()
11 call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1})
12 let proptypes = prop_type_list()
13 call assert_equal(1, len(proptypes))
14 call assert_equal('comment', proptypes[0])
15
16 let proptype = prop_type_get('comment')
17 call assert_equal('Directory', proptype['highlight'])
18 call assert_equal(123, proptype['priority'])
19 call assert_equal(1, proptype['start_incl'])
20 call assert_equal(1, proptype['end_incl'])
21
22 call prop_type_delete('comment')
23 call assert_equal(0, len(prop_type_list()))
24
25 call prop_type_add('one', {})
26 call assert_equal(1, len(prop_type_list()))
Bram Moolenaara5a78822019-09-04 21:57:18 +020027 let proptype = 'one'->prop_type_get()
Bram Moolenaar98aefe72018-12-13 22:20:09 +010028 call assert_false(has_key(proptype, 'highlight'))
29 call assert_equal(0, proptype['priority'])
30 call assert_equal(0, proptype['start_incl'])
31 call assert_equal(0, proptype['end_incl'])
32
33 call prop_type_add('two', {})
34 call assert_equal(2, len(prop_type_list()))
35 call prop_type_delete('one')
36 call assert_equal(1, len(prop_type_list()))
37 call prop_type_delete('two')
38 call assert_equal(0, len(prop_type_list()))
39endfunc
40
41func Test_proptype_buf()
42 let bufnr = bufnr('')
Martin Tournoije2390c72021-07-28 13:30:16 +020043 call prop_type_add('comment', #{bufnr: bufnr, highlight: 'Directory', priority: 123, start_incl: 1, end_incl: 1})
Bram Moolenaar98aefe72018-12-13 22:20:09 +010044 let proptypes = prop_type_list({'bufnr': bufnr})
45 call assert_equal(1, len(proptypes))
46 call assert_equal('comment', proptypes[0])
47
48 let proptype = prop_type_get('comment', {'bufnr': bufnr})
49 call assert_equal('Directory', proptype['highlight'])
50 call assert_equal(123, proptype['priority'])
51 call assert_equal(1, proptype['start_incl'])
52 call assert_equal(1, proptype['end_incl'])
53
54 call prop_type_delete('comment', {'bufnr': bufnr})
Bram Moolenaara5a78822019-09-04 21:57:18 +020055 call assert_equal(0, len({'bufnr': bufnr}->prop_type_list()))
Bram Moolenaar98aefe72018-12-13 22:20:09 +010056
57 call prop_type_add('one', {'bufnr': bufnr})
58 let proptype = prop_type_get('one', {'bufnr': bufnr})
59 call assert_false(has_key(proptype, 'highlight'))
60 call assert_equal(0, proptype['priority'])
61 call assert_equal(0, proptype['start_incl'])
62 call assert_equal(0, proptype['end_incl'])
63
64 call prop_type_add('two', {'bufnr': bufnr})
65 call assert_equal(2, len(prop_type_list({'bufnr': bufnr})))
66 call prop_type_delete('one', {'bufnr': bufnr})
67 call assert_equal(1, len(prop_type_list({'bufnr': bufnr})))
68 call prop_type_delete('two', {'bufnr': bufnr})
69 call assert_equal(0, len(prop_type_list({'bufnr': bufnr})))
Bram Moolenaarf0884c52019-05-24 21:22:29 +020070
71 call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
Bram Moolenaar98aefe72018-12-13 22:20:09 +010072endfunc
73
Martin Tournoije2390c72021-07-28 13:30:16 +020074def Test_proptype_buf_list()
75 new
76 var bufnr = bufnr('')
77 try
78 prop_type_add('global', {})
79 prop_type_add('local', {bufnr: bufnr})
80
81 prop_add(1, 1, {type: 'global'})
82 prop_add(1, 1, {type: 'local'})
83
84 assert_equal([
85 {type: 'local', type_bufnr: bufnr, id: 0, col: 1, end: 1, length: 0, start: 1},
86 {type: 'global', type_bufnr: 0, id: 0, col: 1, end: 1, length: 0, start: 1},
87 ], prop_list(1))
88 assert_equal(
89 {lnum: 1, id: 0, col: 1, type_bufnr: bufnr, end: 1, type: 'local', length: 0, start: 1},
90 prop_find({lnum: 1, type: 'local'}))
91 assert_equal(
92 {lnum: 1, id: 0, col: 1, type_bufnr: 0, end: 1, type: 'global', length: 0, start: 1},
93 prop_find({lnum: 1, type: 'global'}))
94
95 prop_remove({type: 'global'}, 1)
96 prop_remove({type: 'local'}, 1)
97 finally
98 prop_type_delete('global')
99 prop_type_delete('local', {bufnr: bufnr})
100 bwipe!
101 endtry
102enddef
103
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100104func AddPropTypes()
105 call prop_type_add('one', {})
106 call prop_type_add('two', {})
107 call prop_type_add('three', {})
108 call prop_type_add('whole', {})
109endfunc
110
111func DeletePropTypes()
112 call prop_type_delete('one')
113 call prop_type_delete('two')
114 call prop_type_delete('three')
115 call prop_type_delete('whole')
116endfunc
117
118func SetupPropsInFirstLine()
119 call setline(1, 'one two three')
120 call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'})
Bram Moolenaara5a78822019-09-04 21:57:18 +0200121 eval 1->prop_add(5, {'length': 3, 'id': 12, 'type': 'two'})
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100122 call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'})
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100123 call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'})
124endfunc
125
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100126func Get_expected_props()
127 return [
Martin Tournoije2390c72021-07-28 13:30:16 +0200128 \ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1},
129 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
130 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
131 \ #{type_bufnr: 0, col: 9, length: 5, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100132 \ ]
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100133endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100134
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100135func Test_prop_find()
136 new
137 call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix'])
Martin Tournoije2390c72021-07-28 13:30:16 +0200138
139 " Add two text props on lines 1 and 5, and one spanning lines 2 to 4.
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100140 call prop_type_add('prop_name', {'highlight': 'Directory'})
141 call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3})
142 call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9})
143 call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1})
144
145 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200146 \ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1},
147 \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0},
148 \ #{type_bufnr: 0, lnum: 5, col: 4, length: 1, id: 12, type: 'prop_name', start: 1, end: 1}
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100149 \ ]
150
151 " Starting at line 5 col 1 this should find the prop at line 5 col 4.
152 call cursor(5,1)
153 let result = prop_find({'type': 'prop_name'}, 'f')
154 call assert_equal(expected[2], result)
155
156 " With skipstart left at false (default), this should find the prop at line
157 " 5 col 4.
158 let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4}, 'b')
159 call assert_equal(expected[2], result)
160
161 " With skipstart set to true, this should skip the prop at line 5 col 4.
162 let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4, 'skipstart': 1}, 'b')
163 unlet result.length
164 call assert_equal(expected[1], result)
165
166 " Search backwards from line 1 col 10 to find the prop on the same line.
167 let result = prop_find({'type': 'prop_name', 'lnum': 1, 'col': 10}, 'b')
168 call assert_equal(expected[0], result)
169
170 " with skipstart set to false, if the start position is anywhere between the
171 " start and end lines of a text prop (searching forward or backward), the
172 " result should be the prop on the first line (the line with 'start' set to 1).
173 call cursor(3,1)
174 let result = prop_find({'type': 'prop_name'}, 'f')
175 unlet result.length
176 call assert_equal(expected[1], result)
177 let result = prop_find({'type': 'prop_name'}, 'b')
178 unlet result.length
179 call assert_equal(expected[1], result)
180
181 " with skipstart set to true, if the start position is anywhere between the
182 " start and end lines of a text prop (searching forward or backward), all lines
183 " of the prop will be skipped.
184 let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'b')
185 call assert_equal(expected[0], result)
186 let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'f')
187 call assert_equal(expected[2], result)
188
189 " Use skipstart to search through all props with type name 'prop_name'.
190 " First forward...
191 let lnum = 1
192 let col = 1
193 let i = 0
194 for exp in expected
195 let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'f')
196 if !has_key(exp, "length")
197 unlet result.length
198 endif
199 call assert_equal(exp, result)
200 let lnum = result.lnum
201 let col = result.col
202 let i = i + 1
203 endfor
204
205 " ...then backwards.
206 let lnum = 6
207 let col = 4
208 let i = 2
209 while i >= 0
210 let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'b')
211 if !has_key(expected[i], "length")
212 unlet result.length
213 endif
214 call assert_equal(expected[i], result)
215 let lnum = result.lnum
216 let col = result.col
217 let i = i - 1
Martin Tournoije2390c72021-07-28 13:30:16 +0200218 endwhile
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100219
220 " Starting from line 6 col 1 search backwards for prop with id 10.
221 call cursor(6,1)
222 let result = prop_find({'id': 10, 'skipstart': 1}, 'b')
223 call assert_equal(expected[0], result)
224
225 " Starting from line 1 col 1 search forwards for prop with id 12.
226 call cursor(1,1)
227 let result = prop_find({'id': 12}, 'f')
228 call assert_equal(expected[2], result)
229
230 " Search for a prop with an unknown id.
231 let result = prop_find({'id': 999}, 'f')
232 call assert_equal({}, result)
233
234 " Search backwards from the proceeding position of the prop with id 11
235 " (at line num 2 col 4). This should return an empty dict.
236 let result = prop_find({'id': 11, 'lnum': 2, 'col': 3}, 'b')
237 call assert_equal({}, result)
238
239 " When lnum is given and col is omitted, use column 1.
240 let result = prop_find({'type': 'prop_name', 'lnum': 1}, 'f')
241 call assert_equal(expected[0], result)
242
Bram Moolenaare041dde2021-08-01 21:30:12 +0200243 " Negative ID is possible, just like prop is not found.
Bram Moolenaar8e3fc132021-07-31 18:33:57 +0200244 call assert_equal({}, prop_find({'id': -1}))
Bram Moolenaare041dde2021-08-01 21:30:12 +0200245 call assert_equal({}, prop_find({'id': -2}))
Bram Moolenaar8e3fc132021-07-31 18:33:57 +0200246
Bram Moolenaare041dde2021-08-01 21:30:12 +0200247 call prop_clear(1, 6)
248
249 " Default ID is zero
250 call prop_add(5, 4, {'type': 'prop_name', 'length': 1})
251 call assert_equal(#{lnum: 5, id: 0, col: 4, type_bufnr: 0, end: 1, type: 'prop_name', length: 1, start: 1}, prop_find({'id': 0}))
252
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100253 call prop_type_delete('prop_name')
Bram Moolenaare041dde2021-08-01 21:30:12 +0200254 call prop_clear(1, 6)
Bram Moolenaar4da7a252020-09-02 19:59:00 +0200255 bwipe!
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100256endfunc
257
Bram Moolenaareb245562020-09-03 22:33:44 +0200258def Test_prop_find2()
259 # Multiple props per line, start on the first, should find the second.
260 new
261 ['the quikc bronw fox jumsp over the layz dog']->repeat(2)->setline(1)
Bram Moolenaare0de1712020-12-02 17:36:54 +0100262 prop_type_add('misspell', {highlight: 'ErrorMsg'})
Bram Moolenaareb245562020-09-03 22:33:44 +0200263 for lnum in [1, 2]
264 for col in [8, 14, 24, 38]
Bram Moolenaare0de1712020-12-02 17:36:54 +0100265 prop_add(lnum, col, {type: 'misspell', length: 2})
Bram Moolenaareb245562020-09-03 22:33:44 +0200266 endfor
267 endfor
268 cursor(1, 8)
Martin Tournoije2390c72021-07-28 13:30:16 +0200269 var expected = {type_bufnr: 0, lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1}
Bram Moolenaare0de1712020-12-02 17:36:54 +0100270 var result = prop_find({type: 'misspell', skipstart: true}, 'f')
Bram Moolenaareb245562020-09-03 22:33:44 +0200271 assert_equal(expected, result)
272
273 prop_type_delete('misspell')
274 bwipe!
275enddef
276
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100277func Test_prop_find_smaller_len_than_match_col()
278 new
279 call prop_type_add('test', {'highlight': 'ErrorMsg'})
280 call setline(1, ['xxxx', 'x'])
281 call prop_add(1, 4, {'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200282 call assert_equal(
283 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 4, type: 'test', length: 0, start: 1, end: 1},
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100284 \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b'))
285 bwipe!
286 call prop_type_delete('test')
287endfunc
288
Bram Moolenaar24f21fd2021-03-27 22:07:29 +0100289func Test_prop_find_with_both_option_enabled()
290 " Initialize
291 new
292 call AddPropTypes()
293 call SetupPropsInFirstLine()
294 let props = Get_expected_props()->map({_, v -> extend(v, {'lnum': 1})})
295 " Test
296 call assert_fails("call prop_find({'both': 1})", 'E968:')
297 call assert_fails("call prop_find({'id': 11, 'both': 1})", 'E860:')
298 call assert_fails("call prop_find({'type': 'three', 'both': 1})", 'E860:')
299 call assert_equal({}, prop_find({'id': 11, 'type': 'three', 'both': 1}))
300 call assert_equal({}, prop_find({'id': 130000, 'type': 'one', 'both': 1}))
301 call assert_equal(props[2], prop_find({'id': 12, 'type': 'two', 'both': 1}))
302 call assert_equal(props[0], prop_find({'id': 14, 'type': 'whole', 'both': 1}))
303 " Clean up
304 call DeletePropTypes()
305 bwipe!
306endfunc
307
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100308func Test_prop_add()
309 new
310 call AddPropTypes()
311 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100312 let expected_props = Get_expected_props()
313 call assert_equal(expected_props, prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100314 call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:')
315 call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:')
Martin Tournoije2390c72021-07-28 13:30:16 +0200316
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100317 " Insert a line above, text props must still be there.
318 call append(0, 'empty')
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100319 call assert_equal(expected_props, prop_list(2))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100320 " Delete a line above, text props must still be there.
321 1del
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100322 call assert_equal(expected_props, prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100323
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100324 " Prop without length or end column is zero length
325 call prop_clear(1)
Bram Moolenaar12f20032020-02-26 22:06:00 +0100326 call prop_type_add('included', {'start_incl': 1, 'end_incl': 1})
327 call prop_add(1, 5, #{type: 'included'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200328 let expected = [#{type_bufnr: 0, col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}]
Bram Moolenaar12f20032020-02-26 22:06:00 +0100329 call assert_equal(expected, prop_list(1))
330
331 " Inserting text makes the prop bigger.
332 exe "normal 5|ixx\<Esc>"
Martin Tournoije2390c72021-07-28 13:30:16 +0200333 let expected = [#{type_bufnr: 0, col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}]
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100334 call assert_equal(expected, prop_list(1))
335
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200336 call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
337
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100338 call DeletePropTypes()
Bram Moolenaar12f20032020-02-26 22:06:00 +0100339 call prop_type_delete('included')
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100340 bwipe!
341endfunc
342
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200343" Test for the prop_add_list() function
344func Test_prop_add_list()
345 new
346 call AddPropTypes()
347 call setline(1, ['one one one', 'two two two', 'six six six', 'ten ten ten'])
348 call prop_add_list(#{type: 'one', id: 2},
349 \ [[1, 1, 1, 3], [2, 5, 2, 7], [3, 6, 4, 6]])
350 call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
351 \ length: 2, start: 1}], prop_list(1))
352 call assert_equal([#{id: 2, col: 5, type_bufnr: 0, end: 1, type: 'one',
353 \ length: 2, start: 1}], prop_list(2))
354 call assert_equal([#{id: 2, col: 6, type_bufnr: 0, end: 0, type: 'one',
355 \ length: 7, start: 1}], prop_list(3))
356 call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
357 \ length: 5, start: 0}], prop_list(4))
358 call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:')
359 call assert_fails('call prop_add_list({}, {})', 'E1211:')
360 call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:')
361 call assert_fails('call prop_add_list(#{type: "abc"}, [[1, 1, 1, 3]])', 'E971:')
362 call assert_fails('call prop_add_list(#{type: "one"}, [[]])', 'E474:')
363 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 1], {}])', 'E714:')
364 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, "a"]])', 'E474:')
365 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2]])', 'E474:')
366 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 2], [2, 2]])', 'E474:')
367 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 2], [4, 1, 5, 2]])', 'E966:')
368 call assert_fails('call prop_add_list(#{type: "one"}, [[3, 1, 1, 2]])', 'E966:')
369 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
370 call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
371 call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:')
372 call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E714:')
373 call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:')
374 call DeletePropTypes()
375 bw!
376endfunc
377
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100378func Test_prop_remove()
379 new
380 call AddPropTypes()
381 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100382 let props = Get_expected_props()
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100383 call assert_equal(props, prop_list(1))
384
385 " remove by id
Bram Moolenaara5a78822019-09-04 21:57:18 +0200386 call assert_equal(1, {'id': 12}->prop_remove(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100387 unlet props[2]
388 call assert_equal(props, prop_list(1))
389
390 " remove by type
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200391 call assert_equal(1, prop_remove({'type': 'one'}, 1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100392 unlet props[1]
393 call assert_equal(props, prop_list(1))
394
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200395 " remove from unknown buffer
396 call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:')
397
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100398 call DeletePropTypes()
399 bwipe!
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100400
401 new
402 call AddPropTypes()
403 call SetupPropsInFirstLine()
404 call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
405 let props = Get_expected_props()
Martin Tournoije2390c72021-07-28 13:30:16 +0200406 call insert(props, #{type_bufnr: 0, col: 6, length: 2, id: 11, type: 'three', start: 1, end: 1}, 3)
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100407 call assert_equal(props, prop_list(1))
408 call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
409 unlet props[3]
410 call assert_equal(props, prop_list(1))
411
Bram Moolenaare2e40752020-09-04 21:18:46 +0200412 call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:')
413 call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:')
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100414
415 call DeletePropTypes()
416 bwipe!
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100417endfunc
418
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200419def Test_prop_add_vim9()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100420 prop_type_add('comment', {
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200421 highlight: 'Directory',
422 priority: 123,
423 start_incl: true,
424 end_incl: true,
425 combine: false,
426 })
427 prop_type_delete('comment')
428enddef
429
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200430def Test_prop_remove_vim9()
431 new
Bram Moolenaar62aec932022-01-29 21:45:34 +0000432 g:AddPropTypes()
433 g:SetupPropsInFirstLine()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100434 assert_equal(1, prop_remove({type: 'three', id: 13, both: true, all: true}))
Bram Moolenaar62aec932022-01-29 21:45:34 +0000435 g:DeletePropTypes()
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200436 bwipe!
437enddef
438
Bram Moolenaar196d1572019-01-02 23:47:18 +0100439func SetupOneLine()
440 call setline(1, 'xonex xtwoxx')
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200441 normal gg0
Bram Moolenaar196d1572019-01-02 23:47:18 +0100442 call AddPropTypes()
443 call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'})
444 call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'})
445 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200446 \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1},
447 \ #{type_bufnr: 0, col: 8, length: 3, id: 12, type: 'two', start: 1, end: 1},
Bram Moolenaar196d1572019-01-02 23:47:18 +0100448 \]
449 call assert_equal(expected, prop_list(1))
450 return expected
451endfunc
452
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100453func Test_prop_add_remove_buf()
454 new
455 let bufnr = bufnr('')
456 call AddPropTypes()
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100457 for lnum in range(1, 4)
458 call setline(lnum, 'one two three')
459 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100460 wincmd w
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100461 for lnum in range(1, 4)
462 call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr})
463 call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr})
464 call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr})
465 endfor
466
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100467 let props = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200468 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
469 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
470 \ #{type_bufnr: 0, col: 11, length: 3, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100471 \]
472 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100473
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100474 " remove by id
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100475 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100476 unlet props[1]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100477
478 call prop_remove({'id': 12, 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100479 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100480 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
481 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
482 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
483
484 call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4)
485 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
486 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
487 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
488 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
489
490 call prop_remove({'id': 12, 'bufnr': bufnr})
491 for lnum in range(1, 4)
492 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
493 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100494
495 " remove by type
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100496 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100497 unlet props[0]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100498
499 call prop_remove({'type': 'one', 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100500 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100501 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
502 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
503 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
504
505 call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4)
506 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
507 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
508 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
509 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
510
511 call prop_remove({'type': 'one', 'bufnr': bufnr})
512 for lnum in range(1, 4)
513 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
514 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100515
516 call DeletePropTypes()
517 wincmd w
518 bwipe!
519endfunc
520
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100521func Test_prop_backspace()
522 new
523 set bs=2
Bram Moolenaar196d1572019-01-02 23:47:18 +0100524 let expected = SetupOneLine() " 'xonex xtwoxx'
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100525
526 exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>"
527 call assert_equal('one xtwoxx', getline(1))
528 let expected[0].col = 1
529 let expected[1].col = 6
530 call assert_equal(expected, prop_list(1))
531
532 call DeletePropTypes()
533 bwipe!
534 set bs&
535endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100536
LemonBoyd0b1a092022-05-12 18:45:18 +0100537func Test_prop_change()
538 new
539 let expected = SetupOneLine() " 'xonex xtwoxx'
540
541 " Characterwise.
542 exe "normal 7|c$\<Esc>"
543 call assert_equal('xonex ', getline(1))
544 call assert_equal(expected[:0], prop_list(1))
545 " Linewise.
546 exe "normal cc\<Esc>"
547 call assert_equal('', getline(1))
548 call assert_equal([], prop_list(1))
549
550 call DeletePropTypes()
551 bwipe!
552 set bs&
553endfunc
554
Bram Moolenaar196d1572019-01-02 23:47:18 +0100555func Test_prop_replace()
556 new
557 set bs=2
558 let expected = SetupOneLine() " 'xonex xtwoxx'
559
560 exe "normal 0Ryyy\<Esc>"
561 call assert_equal('yyyex xtwoxx', getline(1))
562 call assert_equal(expected, prop_list(1))
563
564 exe "normal ftRyy\<BS>"
565 call assert_equal('yyyex xywoxx', getline(1))
566 call assert_equal(expected, prop_list(1))
567
568 exe "normal 0fwRyy\<BS>"
569 call assert_equal('yyyex xyyoxx', getline(1))
570 call assert_equal(expected, prop_list(1))
571
572 exe "normal 0foRyy\<BS>\<BS>"
573 call assert_equal('yyyex xyyoxx', getline(1))
574 call assert_equal(expected, prop_list(1))
575
LemonBoy0d534d92022-05-21 11:20:42 +0100576 " Replace three 1-byte chars with three 2-byte ones.
577 exe "normal 0l3rø"
578 call assert_equal('yøøøx xyyoxx', getline(1))
579 let expected[0].length += 3
580 let expected[1].col += 3
581 call assert_equal(expected, prop_list(1))
582
Bram Moolenaar196d1572019-01-02 23:47:18 +0100583 call DeletePropTypes()
584 bwipe!
585 set bs&
586endfunc
587
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200588func Test_prop_open_line()
589 new
590
591 " open new line, props stay in top line
592 let expected = SetupOneLine() " 'xonex xtwoxx'
593 exe "normal o\<Esc>"
594 call assert_equal('xonex xtwoxx', getline(1))
595 call assert_equal('', getline(2))
596 call assert_equal(expected, prop_list(1))
597 call DeletePropTypes()
598
599 " move all props to next line
600 let expected = SetupOneLine() " 'xonex xtwoxx'
601 exe "normal 0i\<CR>\<Esc>"
602 call assert_equal('', getline(1))
603 call assert_equal('xonex xtwoxx', getline(2))
604 call assert_equal(expected, prop_list(2))
605 call DeletePropTypes()
606
607 " split just before prop, move all props to next line
608 let expected = SetupOneLine() " 'xonex xtwoxx'
609 exe "normal 0li\<CR>\<Esc>"
610 call assert_equal('x', getline(1))
611 call assert_equal('onex xtwoxx', getline(2))
612 let expected[0].col -= 1
613 let expected[1].col -= 1
614 call assert_equal(expected, prop_list(2))
615 call DeletePropTypes()
616
617 " split inside prop, split first prop
618 let expected = SetupOneLine() " 'xonex xtwoxx'
619 exe "normal 0lli\<CR>\<Esc>"
620 call assert_equal('xo', getline(1))
621 call assert_equal('nex xtwoxx', getline(2))
622 let exp_first = [deepcopy(expected[0])]
623 let exp_first[0].length = 1
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200624 let exp_first[0].end = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200625 call assert_equal(exp_first, prop_list(1))
626 let expected[0].col = 1
627 let expected[0].length = 2
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200628 let expected[0].start = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200629 let expected[1].col -= 2
630 call assert_equal(expected, prop_list(2))
631 call DeletePropTypes()
632
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200633 " split just after first prop, second prop move to next line
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200634 let expected = SetupOneLine() " 'xonex xtwoxx'
635 exe "normal 0fea\<CR>\<Esc>"
636 call assert_equal('xone', getline(1))
637 call assert_equal('x xtwoxx', getline(2))
638 let exp_first = expected[0:0]
639 call assert_equal(exp_first, prop_list(1))
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200640 let expected = expected[1:1]
641 let expected[0].col -= 4
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200642 call assert_equal(expected, prop_list(2))
643 call DeletePropTypes()
644
LemonBoy788c06a2022-05-14 18:48:05 +0100645 " split at the space character with 'ai' active, the leading space is removed
646 " in the second line and the prop is shifted accordingly.
647 let expected = SetupOneLine() " 'xonex xtwoxx'
648 set ai
649 exe "normal 6|i\<CR>\<Esc>"
650 call assert_equal('xonex', getline(1))
651 call assert_equal('xtwoxx', getline(2))
652 let expected[1].col -= 6
653 call assert_equal(expected, prop_list(1) + prop_list(2))
654 set ai&
655 call DeletePropTypes()
656
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200657 bwipe!
658 set bs&
659endfunc
660
Bram Moolenaarecb00c72022-08-07 14:55:14 +0100661func Test_prop_put()
662 new
663 let expected = SetupOneLine() " 'xonex xtwoxx'
664
665 let @a = 'new'
666 " insert just after the prop
667 normal 03l"ap
668 " insert inside the prop
669 normal 02l"ap
670 " insert just before the prop
671 normal 0"ap
672
673 call assert_equal('xnewonnewenewx xtwoxx', getline(1))
674 let expected[0].col += 3
675 let expected[0].length += 3
676 let expected[1].col += 9
677 call assert_equal(expected, prop_list(1))
678
679 " Visually select 4 chars in the prop and put "AB" to replace them
680 let @a = 'AB'
681 normal 05lv3l"ap
682 call assert_equal('xnewoABenewx xtwoxx', getline(1))
683 let expected[0].length -= 2
684 let expected[1].col -= 2
685 call assert_equal(expected, prop_list(1))
686
687 call DeletePropTypes()
688 bwipe!
689endfunc
690
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100691func Test_prop_clear()
692 new
693 call AddPropTypes()
694 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100695 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100696
Bram Moolenaara5a78822019-09-04 21:57:18 +0200697 eval 1->prop_clear()
698 call assert_equal([], 1->prop_list())
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100699
700 call DeletePropTypes()
701 bwipe!
702endfunc
703
704func Test_prop_clear_buf()
705 new
706 call AddPropTypes()
707 call SetupPropsInFirstLine()
708 let bufnr = bufnr('')
709 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100710 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100711
712 call prop_clear(1, 1, {'bufnr': bufnr})
713 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
714
715 wincmd w
716 call DeletePropTypes()
717 bwipe!
718endfunc
719
Bram Moolenaar21b50382019-01-04 18:07:24 +0100720func Test_prop_setline()
721 new
722 call AddPropTypes()
723 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100724 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100725
726 call setline(1, 'foobar')
727 call assert_equal([], prop_list(1))
728
729 call DeletePropTypes()
730 bwipe!
731endfunc
732
733func Test_prop_setbufline()
734 new
735 call AddPropTypes()
736 call SetupPropsInFirstLine()
737 let bufnr = bufnr('')
738 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100739 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100740
741 call setbufline(bufnr, 1, 'foobar')
742 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
743
744 wincmd w
745 call DeletePropTypes()
746 bwipe!
747endfunc
748
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100749func Test_prop_substitute()
750 new
751 " Set first line to 'one two three'
752 call AddPropTypes()
753 call SetupPropsInFirstLine()
754 let expected_props = Get_expected_props()
755 call assert_equal(expected_props, prop_list(1))
756
757 " Change "n" in "one" to XX: 'oXXe two three'
758 s/n/XX/
759 let expected_props[0].length += 1
760 let expected_props[1].length += 1
761 let expected_props[2].col += 1
762 let expected_props[3].col += 1
763 call assert_equal(expected_props, prop_list(1))
764
765 " Delete "t" in "two" and "three" to XX: 'oXXe wo hree'
766 s/t//g
767 let expected_props[0].length -= 2
768 let expected_props[2].length -= 1
769 let expected_props[3].length -= 1
770 let expected_props[3].col -= 1
771 call assert_equal(expected_props, prop_list(1))
772
773 " Split the line by changing w to line break: 'oXXe ', 'o hree'
774 " The long prop is split and spans both lines.
775 " The props on "two" and "three" move to the next line.
776 s/w/\r/
777 let new_props = [
778 \ copy(expected_props[0]),
779 \ copy(expected_props[2]),
780 \ copy(expected_props[3]),
781 \ ]
782 let expected_props[0].length = 5
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200783 let expected_props[0].end = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100784 unlet expected_props[3]
785 unlet expected_props[2]
786 call assert_equal(expected_props, prop_list(1))
787
788 let new_props[0].length = 6
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200789 let new_props[0].start = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100790 let new_props[1].col = 1
791 let new_props[1].length = 1
792 let new_props[2].col = 3
793 call assert_equal(new_props, prop_list(2))
794
795 call DeletePropTypes()
796 bwipe!
797endfunc
798
Bram Moolenaar663bc892019-01-08 23:07:24 +0100799func Test_prop_change_indent()
800 call prop_type_add('comment', {'highlight': 'Directory'})
801 new
802 call setline(1, [' xxx', 'yyyyy'])
803 call prop_add(2, 2, {'length': 2, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200804 let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0}
Bram Moolenaar663bc892019-01-08 23:07:24 +0100805 call assert_equal([expect], prop_list(2))
806
807 set shiftwidth=3
808 normal 2G>>
809 call assert_equal(' yyyyy', getline(2))
810 let expect.col += 3
811 call assert_equal([expect], prop_list(2))
812
813 normal 2G==
814 call assert_equal(' yyyyy', getline(2))
815 let expect.col = 6
816 call assert_equal([expect], prop_list(2))
817
818 call prop_clear(2)
819 call prop_add(2, 2, {'length': 5, 'type': 'comment'})
820 let expect.col = 2
821 let expect.length = 5
822 call assert_equal([expect], prop_list(2))
823
824 normal 2G<<
825 call assert_equal(' yyyyy', getline(2))
826 let expect.length = 2
827 call assert_equal([expect], prop_list(2))
828
829 set shiftwidth&
830 call prop_type_delete('comment')
831endfunc
832
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100833" Setup a three line prop in lines 2 - 4.
834" Add short props in line 1 and 5.
835func Setup_three_line_prop()
836 new
837 call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five'])
838 call prop_add(1, 2, {'length': 1, 'type': 'comment'})
839 call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'})
840 call prop_add(5, 2, {'length': 1, 'type': 'comment'})
841endfunc
842
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100843func Test_prop_multiline()
Bram Moolenaara5a78822019-09-04 21:57:18 +0200844 eval 'comment'->prop_type_add({'highlight': 'Directory'})
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100845 new
846 call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz'])
847
848 " start halfway line 1, end halfway line 3
849 call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200850 let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100851 call assert_equal([expect1], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200852 let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100853 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200854 let expect3 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100855 call assert_equal([expect3], prop_list(3))
856 call prop_clear(1, 3)
857
858 " include all three lines
859 call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'})
860 let expect1.col = 1
861 let expect1.length = 8
862 call assert_equal([expect1], prop_list(1))
863 call assert_equal([expect2], prop_list(2))
864 let expect3.length = 9
865 call assert_equal([expect3], prop_list(3))
866 call prop_clear(1, 3)
867
868 bwipe!
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100869
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100870 " Test deleting the first line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100871 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200872 let expect_short = #{type_bufnr: 0, col: 2, length: 1, type: 'comment', start: 1, end: 1, id: 0}
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100873 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200874 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100875 call assert_equal([expect2], prop_list(2))
876 2del
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100877 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200878 let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100879 call assert_equal([expect2], prop_list(2))
880 bwipe!
881
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100882 " Test deleting the last line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100883 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200884 let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100885 call assert_equal([expect3], prop_list(3))
Martin Tournoije2390c72021-07-28 13:30:16 +0200886 let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100887 call assert_equal([expect4], prop_list(4))
888 4del
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100889 let expect3.end = 1
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100890 call assert_equal([expect3], prop_list(3))
891 call assert_equal([expect_short], prop_list(4))
892 bwipe!
893
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100894 " Test appending a line below the multi-line text prop start.
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100895 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200896 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100897 call assert_equal([expect2], prop_list(2))
898 call append(2, "new line")
899 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200900 let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100901 call assert_equal([expect3], prop_list(3))
902 bwipe!
903
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100904 call prop_type_delete('comment')
905endfunc
906
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100907func Run_test_with_line2byte(add_props)
908 new
909 setlocal ff=unix
910 if a:add_props
911 call prop_type_add('textprop', #{highlight: 'Search'})
912 endif
913 for nr in range(1, 1000)
914 call setline(nr, 'some longer text here')
915 if a:add_props && nr % 17 == 0
916 call prop_add(nr, 13, #{type: 'textprop', length: 4})
917 endif
918 endfor
919 call assert_equal(21935, line2byte(998))
920 for nr in range(1, 1000, 7)
921 exe nr .. "s/longer/much more/"
922 endfor
923 call assert_equal(22364, line2byte(998))
924
925 if a:add_props
926 call prop_type_delete('textprop')
927 endif
928 bwipe!
929endfunc
930
Bram Moolenaar9df53b62020-01-13 20:40:51 +0100931func Test_prop_line2byte()
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100932 call prop_type_add('comment', {'highlight': 'Directory'})
933 new
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100934 call setline(1, ['line1', 'second line', ''])
Bram Moolenaar8cf734e2018-12-26 01:09:00 +0100935 set ff=unix
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100936 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100937 call prop_add(1, 1, {'end_col': 3, 'type': 'comment'})
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100938 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100939 bwipe!
Bram Moolenaar14c75302021-08-15 14:28:40 +0200940
941 new
Bram Moolenaara401bba2021-08-15 15:04:41 +0200942 setlocal ff=unix
Bram Moolenaar14c75302021-08-15 14:28:40 +0200943 call setline(1, range(500))
944 call assert_equal(1491, line2byte(401))
945 call prop_add(2, 1, {'type': 'comment'})
946 call prop_add(222, 1, {'type': 'comment'})
947 call assert_equal(1491, line2byte(401))
948 call prop_remove({'type': 'comment'})
949 call assert_equal(1491, line2byte(401))
950 bwipe!
951
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +0200952 new
Bram Moolenaar49b93042021-08-25 17:02:00 +0200953 setlocal ff=unix
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +0200954 call setline(1, range(520))
955 call assert_equal(1491, line2byte(401))
956 call prop_add(2, 1, {'type': 'comment'})
957 call assert_equal(1491, line2byte(401))
958 2delete
959 call assert_equal(1489, line2byte(400))
960 bwipe!
961
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100962 " Add many lines so that the data block is split.
963 " With and without props should give the same result.
964 call Run_test_with_line2byte(0)
965 call Run_test_with_line2byte(1)
966
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100967 call prop_type_delete('comment')
968endfunc
969
Bram Moolenaar9df53b62020-01-13 20:40:51 +0100970func Test_prop_byte2line()
971 new
972 set ff=unix
973 call setline(1, ['one one', 'two two', 'three three', 'four four', 'five'])
974 call assert_equal(4, byte2line(line2byte(4)))
975 call assert_equal(5, byte2line(line2byte(5)))
976
977 call prop_type_add('prop', {'highlight': 'Directory'})
978 call prop_add(3, 1, {'length': 5, 'type': 'prop'})
979 call assert_equal(4, byte2line(line2byte(4)))
980 call assert_equal(5, byte2line(line2byte(5)))
981
982 bwipe!
983 call prop_type_delete('prop')
984endfunc
985
Bram Moolenaar59ff6402021-01-30 17:16:28 +0100986func Test_prop_goto_byte()
987 new
988 call setline(1, '')
989 call setline(2, 'two three')
990 call setline(3, '')
991 call setline(4, 'four five')
992
993 call prop_type_add('testprop', {'highlight': 'Directory'})
994 call search('^two')
995 call prop_add(line('.'), col('.'), {
996 \ 'length': len('two'),
997 \ 'type': 'testprop'
998 \ })
999
1000 call search('two \zsthree')
1001 let expected_pos = line2byte(line('.')) + col('.') - 1
1002 exe expected_pos .. 'goto'
1003 let actual_pos = line2byte(line('.')) + col('.') - 1
1004 eval actual_pos->assert_equal(expected_pos)
1005
1006 call search('four \zsfive')
1007 let expected_pos = line2byte(line('.')) + col('.') - 1
1008 exe expected_pos .. 'goto'
1009 let actual_pos = line2byte(line('.')) + col('.') - 1
1010 eval actual_pos->assert_equal(expected_pos)
1011
1012 call prop_type_delete('testprop')
1013 bwipe!
1014endfunc
1015
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001016func Test_prop_undo()
1017 new
1018 call prop_type_add('comment', {'highlight': 'Directory'})
1019 call setline(1, ['oneone', 'twotwo', 'three'])
1020 " Set 'undolevels' to break changes into undo-able pieces.
1021 set ul&
1022
1023 call prop_add(1, 3, {'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001024 let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}]
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001025 call assert_equal(expected, prop_list(1))
1026
1027 " Insert a character, then undo.
1028 exe "normal 0lllix\<Esc>"
1029 set ul&
1030 let expected[0].length = 3
1031 call assert_equal(expected, prop_list(1))
1032 undo
1033 let expected[0].length = 2
1034 call assert_equal(expected, prop_list(1))
1035
1036 " Delete a character, then undo
1037 exe "normal 0lllx"
1038 set ul&
1039 let expected[0].length = 1
1040 call assert_equal(expected, prop_list(1))
1041 undo
1042 let expected[0].length = 2
1043 call assert_equal(expected, prop_list(1))
1044
1045 " Delete the line, then undo
1046 1d
1047 set ul&
1048 call assert_equal([], prop_list(1))
1049 undo
1050 call assert_equal(expected, prop_list(1))
1051
1052 " Insert a character, delete two characters, then undo with "U"
1053 exe "normal 0lllix\<Esc>"
1054 set ul&
1055 let expected[0].length = 3
1056 call assert_equal(expected, prop_list(1))
1057 exe "normal 0lllxx"
1058 set ul&
1059 let expected[0].length = 1
1060 call assert_equal(expected, prop_list(1))
1061 normal U
1062 let expected[0].length = 2
1063 call assert_equal(expected, prop_list(1))
1064
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001065 " substitute a word, then undo
1066 call setline(1, 'the number 123 is highlighted.')
1067 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001068 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001069 call assert_equal(expected, prop_list(1))
1070 set ul&
1071 1s/number/foo
1072 let expected[0].col = 9
1073 call assert_equal(expected, prop_list(1))
1074 undo
1075 let expected[0].col = 12
1076 call assert_equal(expected, prop_list(1))
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001077 call prop_clear(1)
1078
1079 " substitute with backslash
1080 call setline(1, 'the number 123 is highlighted.')
1081 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001082 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001083 call assert_equal(expected, prop_list(1))
1084 1s/the/\The
1085 call assert_equal(expected, prop_list(1))
1086 1s/^/\\
1087 let expected[0].col += 1
1088 call assert_equal(expected, prop_list(1))
1089 1s/^/\~
1090 let expected[0].col += 1
1091 call assert_equal(expected, prop_list(1))
1092 1s/123/12\\3
1093 let expected[0].length += 1
1094 call assert_equal(expected, prop_list(1))
1095 call prop_clear(1)
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001096
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001097 bwipe!
1098 call prop_type_delete('comment')
1099endfunc
1100
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001101func Test_prop_delete_text()
1102 new
1103 call prop_type_add('comment', {'highlight': 'Directory'})
1104 call setline(1, ['oneone', 'twotwo', 'three'])
1105
1106 " zero length property
1107 call prop_add(1, 3, {'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001108 let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001109 call assert_equal(expected, prop_list(1))
1110
1111 " delete one char moves the property
1112 normal! x
Martin Tournoije2390c72021-07-28 13:30:16 +02001113 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001114 call assert_equal(expected, prop_list(1))
1115
1116 " delete char of the property has no effect
1117 normal! lx
Martin Tournoije2390c72021-07-28 13:30:16 +02001118 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001119 call assert_equal(expected, prop_list(1))
1120
1121 " delete more chars moves property to first column, is not deleted
1122 normal! 0xxxx
Martin Tournoije2390c72021-07-28 13:30:16 +02001123 let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001124 call assert_equal(expected, prop_list(1))
1125
1126 bwipe!
1127 call prop_type_delete('comment')
1128endfunc
1129
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001130" screenshot test with textprop highlighting
Bram Moolenaar8055d172019-05-17 22:57:26 +02001131func Test_textprop_screenshot_various()
Bram Moolenaar34390282019-10-16 14:38:26 +02001132 CheckScreendump
Bram Moolenaared79d1e2019-02-22 14:38:58 +01001133 " The Vim running in the terminal needs to use utf-8.
Bram Moolenaar34390282019-10-16 14:38:26 +02001134 if g:orig_encoding != 'utf-8'
1135 throw 'Skipped: not using utf-8'
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001136 endif
1137 call writefile([
Bram Moolenaarde24a872019-05-05 15:48:00 +02001138 \ "call setline(1, ["
1139 \ .. "'One two',"
1140 \ .. "'Numbér 123 änd thœn 4¾7.',"
1141 \ .. "'--aa--bb--cc--dd--',"
1142 \ .. "'// comment with error in it',"
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001143 \ .. "'first line',"
1144 \ .. "' second line ',"
1145 \ .. "'third line',"
1146 \ .. "' fourth line',"
Bram Moolenaarde24a872019-05-05 15:48:00 +02001147 \ .. "])",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001148 \ "hi NumberProp ctermfg=blue",
1149 \ "hi LongProp ctermbg=yellow",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001150 \ "hi BackgroundProp ctermbg=lightgrey",
1151 \ "hi UnderlineProp cterm=underline",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001152 \ "call prop_type_add('number', {'highlight': 'NumberProp'})",
Bram Moolenaara5a78822019-09-04 21:57:18 +02001153 \ "call prop_type_add('long', {'highlight': 'NumberProp'})",
1154 \ "call prop_type_change('long', {'highlight': 'LongProp'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001155 \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})",
1156 \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})",
1157 \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001158 \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})",
1159 \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})",
1160 \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})",
Bram Moolenaar58e32ab2019-11-12 22:44:22 +01001161 \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001162 \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001163 \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
1164 \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001165 \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})",
1166 \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})",
1167 \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})",
1168 \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001169 \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})",
1170 \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001171 \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001172 \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})",
1173 \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})",
1174 \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})",
1175 \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})",
Bram Moolenaarbfd45122019-05-17 13:05:07 +02001176 \ "set number cursorline",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001177 \ "hi clear SpellBad",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001178 \ "set spell",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001179 \ "syn match Comment '//.*'",
1180 \ "hi Comment ctermfg=green",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001181 \ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>",
Bram Moolenaar33c8ca92019-01-02 18:00:27 +01001182 \ "normal 3G0lli\<BS>\<Esc>",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001183 \ "normal 6G0i\<BS>\<Esc>",
1184 \ "normal 3J",
1185 \ "normal 3G",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001186 \], 'XtestProp')
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001187 let buf = RunVimInTerminal('-S XtestProp', {'rows': 8})
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001188 call VerifyScreenDump(buf, 'Test_textprop_01', {})
Bram Moolenaare3d31b02018-12-24 23:07:04 +01001189
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001190 " clean up
1191 call StopVimInTerminal(buf)
Bram Moolenaar2f21fa82018-12-31 20:05:56 +01001192 call delete('XtestProp')
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001193endfunc
Bram Moolenaar8055d172019-05-17 22:57:26 +02001194
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001195func Test_textprop_hl_override()
1196 CheckScreendump
1197
1198 let lines =<< trim END
1199 call setline(1, ['One one one one one', 'Two two two two two', 'Three three three three'])
1200 hi OverProp ctermfg=blue ctermbg=yellow
1201 hi CursorLine cterm=bold,underline ctermfg=red ctermbg=green
1202 hi Vsual ctermfg=cyan ctermbg=grey
1203 call prop_type_add('under', #{highlight: 'OverProp'})
1204 call prop_type_add('over', #{highlight: 'OverProp', override: 1})
1205 call prop_add(1, 5, #{type: 'under', length: 4})
1206 call prop_add(1, 13, #{type: 'over', length: 4})
1207 call prop_add(2, 5, #{type: 'under', length: 4})
1208 call prop_add(2, 13, #{type: 'over', length: 4})
1209 call prop_add(3, 5, #{type: 'under', length: 4})
1210 call prop_add(3, 13, #{type: 'over', length: 4})
1211 set cursorline
1212 2
1213 END
1214 call writefile(lines, 'XtestOverProp')
1215 let buf = RunVimInTerminal('-S XtestOverProp', {'rows': 8})
1216 call VerifyScreenDump(buf, 'Test_textprop_hl_override_1', {})
1217
1218 call term_sendkeys(buf, "3Gllv$hh")
1219 call VerifyScreenDump(buf, 'Test_textprop_hl_override_2', {})
1220 call term_sendkeys(buf, "\<Esc>")
1221
1222 " clean up
1223 call StopVimInTerminal(buf)
1224 call delete('XtestOverProp')
1225endfunc
1226
Bram Moolenaar8055d172019-05-17 22:57:26 +02001227func RunTestVisualBlock(width, dump)
1228 call writefile([
1229 \ "call setline(1, ["
1230 \ .. "'xxxxxxxxx 123 x',"
1231 \ .. "'xxxxxxxx 123 x',"
1232 \ .. "'xxxxxxx 123 x',"
1233 \ .. "'xxxxxx 123 x',"
1234 \ .. "'xxxxx 123 x',"
1235 \ .. "'xxxx 123 xx',"
1236 \ .. "'xxx 123 xxx',"
1237 \ .. "'xx 123 xxxx',"
1238 \ .. "'x 123 xxxxx',"
1239 \ .. "' 123 xxxxxx',"
1240 \ .. "])",
1241 \ "hi SearchProp ctermbg=yellow",
1242 \ "call prop_type_add('search', {'highlight': 'SearchProp'})",
1243 \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})",
1244 \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})",
1245 \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})",
1246 \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})",
1247 \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})",
1248 \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})",
1249 \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})",
1250 \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})",
1251 \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})",
1252 \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})",
1253 \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx",
1254 \], 'XtestPropVis')
1255 let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12})
1256 call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {})
1257
1258 " clean up
1259 call StopVimInTerminal(buf)
1260 call delete('XtestPropVis')
1261endfunc
1262
1263" screenshot test with Visual block mode operations
1264func Test_textprop_screenshot_visual()
Bram Moolenaar34390282019-10-16 14:38:26 +02001265 CheckScreendump
Bram Moolenaar8055d172019-05-17 22:57:26 +02001266
1267 " Delete two columns while text props are three chars wide.
1268 call RunTestVisualBlock(2, '01')
1269
1270 " Same, but delete four columns
1271 call RunTestVisualBlock(4, '02')
1272endfunc
Bram Moolenaard79eef22019-05-24 20:41:55 +02001273
Bram Moolenaara956bf62019-06-19 17:34:24 +02001274func Test_textprop_after_tab()
Bram Moolenaar34390282019-10-16 14:38:26 +02001275 CheckScreendump
Bram Moolenaar37e66cf2019-06-19 18:16:10 +02001276
Bram Moolenaara956bf62019-06-19 17:34:24 +02001277 let lines =<< trim END
1278 call setline(1, [
1279 \ "\txxx",
1280 \ "x\txxx",
1281 \ ])
1282 hi SearchProp ctermbg=yellow
1283 call prop_type_add('search', {'highlight': 'SearchProp'})
1284 call prop_add(1, 2, {'length': 3, 'type': 'search'})
1285 call prop_add(2, 3, {'length': 3, 'type': 'search'})
1286 END
1287 call writefile(lines, 'XtestPropTab')
1288 let buf = RunVimInTerminal('-S XtestPropTab', {'rows': 6})
1289 call VerifyScreenDump(buf, 'Test_textprop_tab', {})
1290
1291 " clean up
1292 call StopVimInTerminal(buf)
1293 call delete('XtestPropTab')
1294endfunc
1295
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001296func Test_textprop_nowrap_scrolled()
1297 CheckScreendump
1298
1299 let lines =<< trim END
1300 vim9script
1301 set nowrap
1302 setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns))
1303 prop_type_add('number', {'highlight': 'ErrorMsg'})
1304 prop_add(1, 12, {'length': 3, 'type': 'number'})
1305 prop_add(1, 32, {'length': 4, 'type': 'number'})
1306 feedkeys('gg20zl', 'nxt')
1307 END
1308 call writefile(lines, 'XtestNowrap')
1309 let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6})
1310 call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {})
1311
1312 call term_sendkeys(buf, "$")
1313 call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {})
1314
1315 " clean up
1316 call StopVimInTerminal(buf)
1317 call delete('XtestNowrap')
1318endfunc
1319
Bram Moolenaar34390282019-10-16 14:38:26 +02001320func Test_textprop_with_syntax()
1321 CheckScreendump
1322
1323 let lines =<< trim END
1324 call setline(1, [
1325 \ "(abc)",
1326 \ ])
1327 syn match csParens "[()]" display
1328 hi! link csParens MatchParen
1329
1330 call prop_type_add('TPTitle', #{ highlight: 'Title' })
1331 call prop_add(1, 2, #{type: 'TPTitle', end_col: 5})
1332 END
1333 call writefile(lines, 'XtestPropSyn')
1334 let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6})
1335 call VerifyScreenDump(buf, 'Test_textprop_syn_1', {})
1336
1337 " clean up
1338 call StopVimInTerminal(buf)
1339 call delete('XtestPropSyn')
1340endfunc
1341
Bram Moolenaard79eef22019-05-24 20:41:55 +02001342" Adding a text property to a new buffer should not fail
1343func Test_textprop_empty_buffer()
1344 call prop_type_add('comment', {'highlight': 'Search'})
1345 new
1346 call prop_add(1, 1, {'type': 'comment'})
1347 close
Bram Moolenaaradfde112019-05-25 22:11:45 +02001348 call prop_type_delete('comment')
1349endfunc
1350
Bram Moolenaard74af422019-06-28 21:38:00 +02001351" Adding a text property with invalid highlight should be ignored.
1352func Test_textprop_invalid_highlight()
1353 call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:')
1354 new
1355 call setline(1, ['asdf','asdf'])
1356 call prop_add(1, 1, {'length': 4, 'type': 'dni'})
1357 redraw
1358 bwipe!
1359 call prop_type_delete('dni')
1360endfunc
1361
Bram Moolenaaradfde112019-05-25 22:11:45 +02001362" Adding a text property to an empty buffer and then editing another
1363func Test_textprop_empty_buffer_next()
1364 call prop_type_add("xxx", {})
1365 call prop_add(1, 1, {"type": "xxx"})
1366 next X
1367 call prop_type_delete('xxx')
Bram Moolenaard79eef22019-05-24 20:41:55 +02001368endfunc
Bram Moolenaarf0884c52019-05-24 21:22:29 +02001369
1370func Test_textprop_remove_from_buf()
1371 new
1372 let buf = bufnr('')
1373 call prop_type_add('one', {'bufnr': buf})
1374 call prop_add(1, 1, {'type': 'one', 'id': 234})
1375 file x
1376 edit y
1377 call prop_remove({'id': 234, 'bufnr': buf}, 1)
1378 call prop_type_delete('one', {'bufnr': buf})
1379 bwipe! x
1380 close
1381endfunc
Bram Moolenaar45311b52019-08-13 22:27:32 +02001382
1383func Test_textprop_in_unloaded_buf()
1384 edit Xaaa
1385 call setline(1, 'aaa')
1386 write
1387 edit Xbbb
1388 call setline(1, 'bbb')
1389 write
1390 let bnr = bufnr('')
1391 edit Xaaa
1392
1393 call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'})
1394 call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:')
1395 exe 'buf ' .. bnr
1396 call assert_equal('bbb', getline(1))
1397 call assert_equal(0, prop_list(1)->len())
1398
1399 bwipe! Xaaa
1400 bwipe! Xbbb
1401 cal delete('Xaaa')
1402 cal delete('Xbbb')
1403endfunc
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001404
1405func Test_proptype_substitute2()
1406 new
1407 " text_prop.vim
1408 call setline(1, [
1409 \ 'The num 123 is smaller than 4567.',
1410 \ '123 The number 123 is smaller than 4567.',
1411 \ '123 The number 123 is smaller than 4567.'])
1412
1413 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1414
1415 call prop_add(1, 12, {'length': 3, 'type': 'number'})
1416 call prop_add(2, 1, {'length': 3, 'type': 'number'})
1417 call prop_add(3, 36, {'length': 4, 'type': 'number'})
1418 set ul&
Martin Tournoije2390c72021-07-28 13:30:16 +02001419 let expected = [
1420 \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1},
1421 \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1},
1422 \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}]
1423
1424 " TODO
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001425 if 0
1426 " Add some text in between
1427 %s/\s\+/ /g
1428 call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001429
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001430 " remove some text
1431 :1s/[a-z]\{3\}//g
1432 let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
1433 call assert_equal(expected, prop_list(1))
1434 endif
1435
1436 call prop_type_delete('number')
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001437 bwipe!
1438endfunc
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001439
Bram Moolenaar8902b312020-09-20 21:04:35 +02001440" This was causing property corruption.
1441func Test_proptype_substitute3()
1442 new
1443 call setline(1, ['abcxxx', 'def'])
1444 call prop_type_add("test", {"highlight": "Search"})
1445 call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"})
1446 %s/x\+$//
1447 redraw
1448
1449 call prop_type_delete('test')
1450 bwipe!
1451endfunc
1452
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001453func Test_proptype_substitute_join()
1454 new
1455 call setline(1, [
1456 \ 'This is some end',
1457 \ 'start is highlighted end',
1458 \ 'some is highlighted',
1459 \ 'start is also highlighted'])
1460
1461 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1462
1463 call prop_add(1, 6, {'length': 2, 'type': 'number'})
1464 call prop_add(2, 7, {'length': 2, 'type': 'number'})
1465 call prop_add(3, 6, {'length': 2, 'type': 'number'})
1466 call prop_add(4, 7, {'length': 2, 'type': 'number'})
1467 " The highlighted "is" in line 1, 2 and 4 is kept and ajudsted.
1468 " The highlighted "is" in line 3 is deleted.
1469 let expected = [
1470 \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1},
1471 \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1},
1472 \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}]
1473
1474 s/end\nstart/joined/
1475 s/end\n.*\nstart/joined/
1476 call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1))
1477 call assert_equal(expected, prop_list(1))
1478
1479 call prop_type_delete('number')
1480 bwipe!
1481endfunc
1482
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001483func SaveOptions()
1484 let d = #{tabstop: &tabstop,
1485 \ softtabstop: &softtabstop,
1486 \ shiftwidth: &shiftwidth,
1487 \ expandtab: &expandtab,
1488 \ foldmethod: '"' .. &foldmethod .. '"',
1489 \ }
1490 return d
1491endfunc
1492
1493func RestoreOptions(dict)
1494 for name in keys(a:dict)
1495 exe 'let &' .. name .. ' = ' .. a:dict[name]
1496 endfor
1497endfunc
1498
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001499func Test_textprop_noexpandtab()
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001500 new
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001501 let save_dict = SaveOptions()
1502
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001503 set tabstop=8
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001504 set softtabstop=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001505 set shiftwidth=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001506 set noexpandtab
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001507 set foldmethod=marker
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001508
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001509 call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx")
1510 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1511 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1512 call feedkeys("0i\<tab>", "tx")
1513 call prop_remove({'type': 'test'})
1514 call prop_add(1, 2, {'end_col': 3, 'type': 'test'})
1515 call feedkeys("A\<left>\<tab>", "tx")
1516 call prop_remove({'type': 'test'})
1517 try
1518 " It is correct that this does not pass
1519 call prop_add(1, 6, {'end_col': 7, 'type': 'test'})
1520 " Has already collapsed here, start_col:6 does not result in an error
1521 call feedkeys("A\<left>\<tab>", "tx")
1522 catch /^Vim\%((\a\+)\)\=:E964/
1523 endtry
1524 call prop_remove({'type': 'test'})
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001525 call prop_type_delete('test')
1526
1527 call RestoreOptions(save_dict)
1528 bwipe!
1529endfunc
1530
1531func Test_textprop_noexpandtab_redraw()
1532 new
1533 let save_dict = SaveOptions()
1534
1535 set tabstop=8
1536 set softtabstop=4
1537 set shiftwidth=4
1538 set noexpandtab
1539 set foldmethod=marker
1540
1541 call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx")
1542 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1543 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1544 call feedkeys("0i\<tab>", "tx")
1545 " Internally broken at the next line
1546 call feedkeys("A\<left>\<tab>", "tx")
1547 redraw
1548 " Index calculation failed internally on next line
1549 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1550 call prop_remove({'type': 'test', 'all': v:true})
1551 call prop_type_delete('test')
1552 call prop_type_delete('test')
1553
1554 call RestoreOptions(save_dict)
1555 bwipe!
1556endfunc
1557
1558func Test_textprop_ins_str()
1559 new
1560 call setline(1, 'just some text')
1561 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1562 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001563 call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1))
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001564
1565 call feedkeys("foi\<F8>\<Esc>", "tx")
1566 call assert_equal('just s<F8>ome text', getline(1))
Martin Tournoije2390c72021-07-28 13:30:16 +02001567 call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1))
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001568
1569 bwipe!
1570 call prop_remove({'type': 'test'})
1571 call prop_type_delete('test')
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001572endfunc
Bram Moolenaar66b98852020-03-11 19:15:52 +01001573
1574func Test_find_prop_later_in_line()
1575 new
1576 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1577 call setline(1, 'just some text')
1578 call prop_add(1, 1, {'length': 4, 'type': 'test'})
1579 call prop_add(1, 10, {'length': 3, 'type': 'test'})
1580
Martin Tournoije2390c72021-07-28 13:30:16 +02001581 call assert_equal(
1582 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1},
1583 \ prop_find(#{type: 'test', lnum: 1, col: 6}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001584
1585 bwipe!
1586 call prop_type_delete('test')
1587endfunc
1588
1589func Test_find_zerowidth_prop_sol()
1590 new
1591 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1592 call setline(1, 'just some text')
1593 call prop_add(1, 1, {'length': 0, 'type': 'test'})
1594
Martin Tournoije2390c72021-07-28 13:30:16 +02001595 call assert_equal(
1596 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1},
1597 \ prop_find(#{type: 'test', lnum: 1}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001598
1599 bwipe!
1600 call prop_type_delete('test')
1601endfunc
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001602
1603" Test for passing invalid arguments to prop_xxx() functions
1604func Test_prop_func_invalid_args()
1605 call assert_fails('call prop_clear(1, 2, [])', 'E715:')
1606 call assert_fails('call prop_clear(-1, 2)', 'E16:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001607 call assert_fails('call prop_find(test_null_dict())', 'E715:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001608 call assert_fails('call prop_find({"bufnr" : []})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001609 call assert_fails('call prop_find({})', 'E968:')
1610 call assert_fails('call prop_find({}, "x")', 'E474:')
1611 call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
1612 call assert_fails('call prop_list(1, [])', 'E715:')
Bram Moolenaar9d489562020-07-30 20:08:50 +02001613 call assert_fails('call prop_list(-1, {})', 'E16:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001614 call assert_fails('call prop_remove([])', 'E474:')
1615 call assert_fails('call prop_remove({}, -2)', 'E16:')
1616 call assert_fails('call prop_remove({})', 'E968:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001617 call assert_fails('call prop_type_add([], {})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001618 call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001619 call assert_fails("call prop_type_delete([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001620 call assert_fails("call prop_type_delete('xyz', [])", 'E715:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001621 call assert_fails("call prop_type_get([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001622 call assert_fails("call prop_type_get('', [])", 'E474:')
1623 call assert_fails("call prop_type_list([])", 'E715:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001624 call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:')
1625 call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:')
1626 call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:')
1627 call assert_fails('call prop_add(1, 1, 0)', 'E715:')
1628
1629 new
1630 call setline(1, ['first', 'second'])
1631 call prop_type_add('xxx', {})
1632
1633 call assert_fails("call prop_type_add('xxx', {})", 'E969:')
1634 call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:')
1635 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:')
1636 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:')
1637 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:')
1638 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:')
1639 call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:')
1640
1641 call prop_type_delete('xxx')
1642 bwipe!
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001643endfunc
1644
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001645func Test_prop_split_join()
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001646 new
1647 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1648 call setline(1, 'just some text')
1649 call prop_add(1, 6, {'length': 4, 'type': 'test'})
1650
1651 " Split in middle of "some"
1652 execute "normal! 8|i\<CR>"
Martin Tournoije2390c72021-07-28 13:30:16 +02001653 call assert_equal(
1654 \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}],
1655 \ prop_list(1))
1656 call assert_equal(
1657 \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}],
1658 \ prop_list(2))
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001659
1660 " Join the two lines back together
1661 normal! 1GJ
Martin Tournoije2390c72021-07-28 13:30:16 +02001662 call assert_equal([#{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'test', length: 5, start: 1}], prop_list(1))
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001663
1664 bwipe!
1665 call prop_type_delete('test')
1666endfunc
1667
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001668func Test_prop_increment_decrement()
1669 new
1670 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1671 call setline(1, 'its 998 times')
1672 call prop_add(1, 5, {'length': 3, 'type': 'test'})
1673
1674 exe "normal! 0f9\<C-A>"
1675 eval getline(1)->assert_equal('its 999 times')
1676 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001677 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001678
1679 exe "normal! 0f9\<C-A>"
1680 eval getline(1)->assert_equal('its 1000 times')
1681 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001682 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001683
1684 bwipe!
1685 call prop_type_delete('test')
1686endfunc
1687
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001688func Test_prop_block_insert()
1689 new
1690 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1691 call setline(1, ['one ', 'two '])
1692 call prop_add(1, 1, {'length': 3, 'type': 'test'})
1693 call prop_add(2, 1, {'length': 3, 'type': 'test'})
1694
1695 " insert "xx" in the first column of both lines
1696 exe "normal! gg0\<C-V>jIxx\<Esc>"
1697 eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
Martin Tournoije2390c72021-07-28 13:30:16 +02001698 let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001699 eval prop_list(1)->assert_equal(expected)
1700 eval prop_list(2)->assert_equal(expected)
1701
1702 " insert "yy" inside the text props to make them longer
1703 exe "normal! gg03l\<C-V>jIyy\<Esc>"
1704 eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo '])
1705 let expected[0].length = 5
1706 eval prop_list(1)->assert_equal(expected)
1707 eval prop_list(2)->assert_equal(expected)
1708
1709 " insert "zz" after the text props, text props don't change
1710 exe "normal! gg07l\<C-V>jIzz\<Esc>"
1711 eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz '])
1712 eval prop_list(1)->assert_equal(expected)
1713 eval prop_list(2)->assert_equal(expected)
1714
1715 bwipe!
1716 call prop_type_delete('test')
1717endfunc
1718
Bram Moolenaar23999d72020-12-23 14:36:00 +01001719" this was causing an ml_get error because w_botline was wrong
1720func Test_prop_one_line_window()
1721 enew
1722 call range(2)->setline(1)
1723 call prop_type_add('testprop', {})
1724 call prop_add(1, 1, {'type': 'testprop'})
1725 call popup_create('popup', {'textprop': 'testprop'})
1726 $
1727 new
1728 wincmd _
1729 call feedkeys("\r", 'xt')
1730 redraw
1731
1732 call popup_clear()
1733 call prop_type_delete('testprop')
1734 close
1735 bwipe!
1736endfunc
1737
Bram Moolenaarf05a1e52022-08-02 11:48:53 +01001738def Test_prop_column_zero_error()
1739 prop_type_add('proptype', {highlight: 'Search'})
1740 var caught = false
1741 try
1742 popup_create([{
1743 text: 'a',
1744 props: [{col: 0, length: 1, type: 'type'}],
1745 }], {})
1746 catch /E964:/
1747 caught = true
1748 endtry
1749 assert_true(caught)
1750
1751 popup_clear()
1752 prop_type_delete('proptype')
1753enddef
1754
Bram Moolenaar840f91f2021-05-26 22:32:10 +02001755" This was calling ml_append_int() and copy a text property from a previous
1756" line at the wrong moment. Exact text length matters.
1757def Test_prop_splits_data_block()
1758 new
1759 var lines: list<string> = [repeat('x', 35)]->repeat(41)
1760 + [repeat('!', 35)]
1761 + [repeat('x', 35)]->repeat(56)
1762 lines->setline(1)
1763 prop_type_add('someprop', {highlight: 'ErrorMsg'})
1764 prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'})
1765 prop_remove({type: 'someprop'}, 1)
1766 prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'})
1767 prop_remove({type: 'someprop'}, 35, 43)
1768 assert_equal([], prop_list(42))
1769
1770 bwipe!
1771 prop_type_delete('someprop')
1772enddef
1773
Bram Moolenaar4cd5c522021-06-27 13:04:00 +02001774" This was calling ml_delete_int() and try to change text properties.
1775def Test_prop_add_delete_line()
1776 new
1777 var a = 10
1778 var b = 20
1779 repeat([''], a)->append('$')
1780 prop_type_add('Test', {highlight: 'ErrorMsg'})
1781 for lnum in range(1, a)
1782 for col in range(1, b)
1783 prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'})
1784 endfor
1785 endfor
1786
1787 # check deleting lines is OK
1788 :5del
1789 :1del
1790 :$del
1791
1792 prop_type_delete('Test')
1793 bwipe!
1794enddef
1795
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001796" This test is to detect a regression related to #10430. It is not an attempt
1797" fully cover deleting lines in the presence of multi-line properties.
1798def Test_delete_line_within_multiline_prop()
1799 new
1800 setline(1, '# Top.')
1801 append(1, ['some_text = """', 'A string.', '"""', '# Bottom.'])
1802 prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1803 prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1804 prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9})
1805 prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4})
1806
1807 # The property for line 3 should extend into the previous and next lines.
1808 var props = prop_list(3)
1809 var prop = props[0]
1810 assert_equal(1, len(props))
1811 assert_equal(0, prop['start'])
1812 assert_equal(0, prop['end'])
1813
1814 # This deletion should run without raising an exception.
1815 try
1816 :2 del
1817 catch
1818 assert_report('Line delete should have workd, but it raised an error.')
1819 endtry
1820
1821 # The property for line 2 (was 3) should no longer extend into the previous
1822 # line.
1823 props = prop_list(2)
1824 prop = props[0]
1825 assert_equal(1, len(props))
1826 assert_equal(1, prop['start'], 'Property was not changed to start within the line.')
1827
1828 # This deletion should run without raising an exception.
1829 try
1830 :3 del
1831 catch
1832 assert_report('Line delete should have workd, but it raised an error.')
1833 endtry
1834
1835 # The property for line 2 (originally 3) should no longer extend into the next
1836 # line.
1837 props = prop_list(2)
1838 prop = props[0]
1839 assert_equal(1, len(props))
1840 assert_equal(1, prop['end'], 'Property was not changed to end within the line.')
1841
1842 prop_type_delete('Identifier')
1843 prop_type_delete('String')
1844 bwip!
1845enddef
1846
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001847func Test_prop_in_linebreak()
1848 CheckRunVimInTerminal
1849
1850 let lines =<< trim END
1851 set breakindent linebreak breakat+=]
1852 call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1)
1853 call prop_type_add('test', #{highlight: 'ErrorMsg'})
1854 call prop_add(1, 51, #{length: 1, type: 'test'})
1855 END
1856 call writefile(lines, 'XscriptPropLinebreak')
1857 let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001858 call VerifyScreenDump(buf, 'Test_prop_linebreak', {})
1859
1860 call StopVimInTerminal(buf)
1861 call delete('XscriptPropLinebreak')
1862endfunc
1863
Bram Moolenaar42eba042021-11-30 20:22:49 +00001864func Test_prop_after_tab()
1865 CheckRunVimInTerminal
1866
1867 let lines =<< trim END
1868 set breakindent linebreak breakat+=]
1869 call setline(1, "\t[xxx]")
1870 call prop_type_add('test', #{highlight: 'ErrorMsg'})
1871 call prop_add(1, 2, #{length: 1, type: 'test'})
1872 END
1873 call writefile(lines, 'XscriptPropAfterTab')
1874 let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10})
Bram Moolenaar42eba042021-11-30 20:22:49 +00001875 call VerifyScreenDump(buf, 'Test_prop_after_tab', {})
1876
1877 call StopVimInTerminal(buf)
1878 call delete('XscriptPropAfterTab')
1879endfunc
1880
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001881func Test_prop_after_linebreak()
1882 CheckRunVimInTerminal
1883
1884 let lines =<< trim END
1885 set linebreak wrap
1886 call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1)
1887 call prop_type_add('test', #{highlight: 'ErrorMsg'})
1888 call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'})
1889 END
1890 call writefile(lines, 'XscriptPropAfterLinebreak')
1891 let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10})
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001892 call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {})
1893
1894 call StopVimInTerminal(buf)
1895 call delete('XscriptPropAfterLinebreak')
1896endfunc
1897
Martin Tournoije2390c72021-07-28 13:30:16 +02001898" Buffer number of 0 should be ignored, as if the parameter wasn't passed.
1899def Test_prop_bufnr_zero()
1900 new
1901 try
1902 var bufnr = bufnr('')
1903 setline(1, 'hello')
1904 prop_type_add('bufnr-global', {highlight: 'ErrorMsg'})
1905 prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr})
1906
1907 prop_add(1, 1, {type: 'bufnr-global', length: 1})
1908 prop_add(1, 2, {type: 'bufnr-buffer', length: 1})
1909
1910 var list = prop_list(1)
1911 assert_equal([
1912 {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1},
1913 {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1},
1914 ], list)
1915
1916 assert_equal(
1917 {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1},
1918 prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr}))
1919
1920 assert_equal(
1921 {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1},
1922 prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr}))
1923 finally
1924 bwipe!
1925 prop_type_delete('bufnr-global')
1926 endtry
1927enddef
1928
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00001929" Tests for the prop_list() function
1930func Test_prop_list()
1931 let lines =<< trim END
1932 new
Bram Moolenaar62aec932022-01-29 21:45:34 +00001933 call g:AddPropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00001934 call setline(1, repeat([repeat('a', 60)], 10))
1935 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
1936 call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7})
1937 call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14})
1938 call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15})
1939 call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22})
1940 call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23})
1941 call assert_equal([
1942 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1943 \ 'type': 'one', 'length': 2, 'start': 1},
1944 \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
1945 \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1))
1946 #" text properties between a few lines
1947 call assert_equal([
1948 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
1949 \ 'type': 'one', 'length': 2, 'start': 1},
1950 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
1951 \ 'type': 'two', 'length': 2, 'start': 1},
1952 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
1953 \ 'type': 'one', 'length': 2, 'start': 1},
1954 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
1955 \ 'type': 'two', 'length': 2, 'start': 1}],
1956 \ prop_list(2, {'end_lnum': 5}))
1957 #" text properties across all the lines
1958 call assert_equal([
1959 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1960 \ 'type': 'one', 'length': 2, 'start': 1},
1961 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
1962 \ 'type': 'one', 'length': 2, 'start': 1},
1963 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
1964 \ 'type': 'one', 'length': 2, 'start': 1}],
1965 \ prop_list(1, {'types': ['one'], 'end_lnum': -1}))
1966 #" text properties with the specified identifier
1967 call assert_equal([
1968 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
1969 \ 'type': 'one', 'length': 2, 'start': 1},
1970 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
1971 \ 'type': 'two', 'length': 2, 'start': 1}],
1972 \ prop_list(1, {'ids': [20], 'end_lnum': 10}))
1973 #" text properties of the specified type and id
1974 call assert_equal([
1975 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
1976 \ 'type': 'two', 'length': 2, 'start': 1},
1977 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
1978 \ 'type': 'two', 'length': 2, 'start': 1}],
1979 \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20}))
1980 call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10}))
1981 call assert_equal([], prop_list(6, {'end_lnum': 10}))
1982 call assert_equal([], prop_list(2, {'end_lnum': 2}))
1983 #" error cases
1984 call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:')
1985 call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:')
1986 call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:')
1987 call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})",
1988 \ 'E971:')
1989 call assert_fails("echo prop_list(1, {'types': ['one', 'blue'],
1990 \ 'end_lnum': 10})", 'E971:')
1991 call assert_fails("echo prop_list(1, {'types': ['one', 10],
1992 \ 'end_lnum': 10})", 'E928:')
1993 call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:')
1994 call assert_equal([], prop_list(2, {'types': []}))
1995 call assert_equal([], prop_list(2, {'types': test_null_list()}))
1996 call assert_fails("call prop_list(1, {'types': {}})", 'E714:')
1997 call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:')
1998 call assert_equal([], prop_list(2, {'types': ['one'],
1999 \ 'ids': test_null_list()}))
2000 call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []}))
2001 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})",
2002 \ 'E714:')
2003 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})",
2004 \ 'E714:')
2005 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})",
2006 \ 'E745:')
2007 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})",
2008 \ 'E745:')
Martin Tournoije2390c72021-07-28 13:30:16 +02002009
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002010 #" get text properties from a non-current buffer
2011 wincmd w
2012 call assert_equal([
2013 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2014 \ 'type': 'one', 'length': 2, 'start': 1},
2015 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2016 \ 'type': 'two', 'length': 2, 'start': 1},
2017 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2018 \ 'type': 'one', 'length': 2, 'start': 1},
2019 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2020 \ 'type': 'two', 'length': 2, 'start': 1}],
2021 \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4}))
2022 wincmd w
2023
2024 #" get text properties after clearing all the properties
2025 call prop_clear(1, line('$'))
2026 call assert_equal([], prop_list(1, {'end_lnum': 10}))
2027
2028 call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2029 call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6})
2030 call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6})
2031 #" get text properties with a list of types
2032 call assert_equal([
2033 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2034 \ 'type': 'two', 'length': 2, 'start': 1},
2035 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2036 \ 'type': 'one', 'length': 2, 'start': 1}],
2037 \ prop_list(2, {'types': ['one', 'two']}))
2038 call assert_equal([
2039 \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1,
2040 \ 'type': 'three', 'length': 2, 'start': 1},
2041 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2042 \ 'type': 'one', 'length': 2, 'start': 1}],
2043 \ prop_list(2, {'types': ['one', 'three']}))
2044 #" get text properties with a list of identifiers
2045 call assert_equal([
2046 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2047 \ 'type': 'two', 'length': 2, 'start': 1},
2048 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2049 \ 'type': 'one', 'length': 2, 'start': 1}],
2050 \ prop_list(2, {'ids': [5, 10, 20]}))
2051 call prop_clear(1, line('$'))
2052 call assert_equal([], prop_list(2, {'types': ['one', 'two']}))
2053 call assert_equal([], prop_list(2, {'ids': [5, 10, 20]}))
2054
2055 #" get text properties from a hidden buffer
2056 edit! Xaaa
2057 call setline(1, repeat([repeat('b', 60)], 10))
2058 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2059 call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10})
2060 VAR bnr = bufnr()
2061 hide edit Xbbb
2062 call assert_equal([
2063 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2064 \ 'type': 'one', 'length': 2, 'start': 1},
2065 \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1,
2066 \ 'type': 'two', 'length': 2, 'start': 1}],
2067 \ prop_list(1, {'bufnr': bnr,
2068 \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1}))
2069 #" get text properties from an unloaded buffer
2070 bunload! Xaaa
2071 call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1}))
2072
Bram Moolenaar62aec932022-01-29 21:45:34 +00002073 call g:DeletePropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002074 :%bw!
2075 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00002076 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002077endfunc
Bram Moolenaar23999d72020-12-23 14:36:00 +01002078
LemonBoy9bd3ce22022-04-18 21:54:02 +01002079func Test_prop_find_prev_on_same_line()
2080 new
2081
2082 call setline(1, 'the quikc bronw fox jumsp over the layz dog')
2083 call prop_type_add('misspell', #{highlight: 'ErrorMsg'})
2084 for col in [8, 14, 24, 38]
2085 call prop_add(1, col, #{type: 'misspell', length: 2})
2086 endfor
2087
2088 call cursor(1,18)
2089 let expected = [
2090 \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1},
2091 \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}
2092 \ ]
2093
2094 let result = prop_find(#{type: 'misspell'}, 'b')
2095 call assert_equal(expected[0], result)
2096 let result = prop_find(#{type: 'misspell'}, 'f')
2097 call assert_equal(expected[1], result)
2098
2099 call prop_type_delete('misspell')
2100 bwipe!
2101endfunc
2102
LemonBoyb7a70122022-05-13 12:41:50 +01002103func Test_prop_spell()
2104 new
2105 set spell
2106 call AddPropTypes()
2107
2108 call setline(1, ["helo world", "helo helo helo"])
2109 call prop_add(1, 1, #{type: 'one', length: 4})
2110 call prop_add(1, 6, #{type: 'two', length: 5})
2111 call prop_add(2, 1, #{type: 'three', length: 4})
2112 call prop_add(2, 6, #{type: 'three', length: 4})
2113 call prop_add(2, 11, #{type: 'three', length: 4})
2114
2115 " The first prop over 'helo' increases its length after the word is corrected
2116 " to 'Hello', the second one is shifted to the right.
2117 let expected = [
2118 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2119 \ 'length': 5, 'start': 1},
2120 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2121 \ 'length': 5, 'start': 1}
2122 \ ]
2123 call feedkeys("z=1\<CR>", 'xt')
2124
2125 call assert_equal('Hello world', getline(1))
2126 call assert_equal(expected, prop_list(1))
2127
2128 " Repeat the replacement done by z=
2129 spellrepall
2130
2131 let expected = [
2132 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2133 \ 'length': 5, 'start': 1},
2134 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2135 \ 'length': 5, 'start': 1},
2136 \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2137 \ 'length': 5, 'start': 1}
2138 \ ]
2139 call assert_equal('Hello Hello Hello', getline(2))
2140 call assert_equal(expected, prop_list(2))
2141
2142 call DeletePropTypes()
2143 set spell&
2144 bwipe!
2145endfunc
2146
LemonBoy4b936742022-05-13 21:56:28 +01002147func Test_prop_shift_block()
2148 new
2149 call AddPropTypes()
2150
2151 call setline(1, ['some highlighted text']->repeat(2))
2152 call prop_add(1, 10, #{type: 'one', length: 11})
2153 call prop_add(2, 10, #{type: 'two', length: 11})
2154
2155 call cursor(1, 1)
2156 call feedkeys("5l\<c-v>>", 'nxt')
2157 call cursor(2, 1)
2158 call feedkeys("5l\<c-v><", 'nxt')
2159
2160 let expected = [
2161 \ {'lnum': 1, 'id': 0, 'col': 8, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2162 \ 'length': 11, 'start' : 1},
2163 \ {'lnum': 2, 'id': 0, 'col': 6, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2164 \ 'length': 11, 'start' : 1}
2165 \ ]
2166 call assert_equal(expected, prop_list(1, #{end_lnum: 2}))
2167
2168 call DeletePropTypes()
2169 bwipe!
2170endfunc
LemonBoyb7a70122022-05-13 12:41:50 +01002171
LemonBoy698cb4c2022-05-14 18:10:15 +01002172func Test_prop_insert_multiline()
2173 new
2174 call AddPropTypes()
2175
2176 call setline(1, ['foobar', 'barbaz'])
2177 call prop_add(1, 4, #{end_lnum: 2, end_col: 4, type: 'one'})
2178
2179 call feedkeys("1Goquxqux\<Esc>", 'nxt')
2180 call feedkeys("2GOquxqux\<Esc>", 'nxt')
2181
2182 let lines =<< trim END
2183 foobar
2184 quxqux
2185 quxqux
2186 barbaz
2187 END
2188 call assert_equal(lines, getline(1, '$'))
2189 let expected = [
2190 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2191 \ 'length': 4 ,'start': 1},
2192 \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2193 \ 'length': 7, 'start': 0},
2194 \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2195 \ 'length': 7, 'start': 0},
2196 \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2197 \ 'length': 3, 'start': 0}
2198 \ ]
2199 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2200
2201 call DeletePropTypes()
2202 bwipe!
2203endfunc
2204
LemonBoyb559b302022-05-15 13:08:02 +01002205func Test_prop_blockwise_change()
2206 new
2207 call AddPropTypes()
2208
2209 call setline(1, ['foooooo', 'bar', 'baaaaz'])
2210 call prop_add(1, 1, #{end_col: 3, type: 'one'})
2211 call prop_add(2, 1, #{end_col: 3, type: 'two'})
2212 call prop_add(3, 1, #{end_col: 3, type: 'three'})
2213
2214 " Replace the first two columns with '123', since 'start_incl' is false the
2215 " prop is not extended.
2216 call feedkeys("gg\<c-v>2jc123\<Esc>", 'nxt')
2217
2218 let lines =<< trim END
2219 123oooooo
2220 123ar
2221 123aaaaz
2222 END
2223 call assert_equal(lines, getline(1, '$'))
2224 let expected = [
2225 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2226 \ 'length': 1, 'start': 1},
2227 \ {'lnum': 2, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2228 \ 'length': 1, 'start': 1},
2229 \ {'lnum': 3, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1 ,
2230 \ 'type': 'three', 'length': 1, 'start': 1}
2231 \ ]
2232 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2233
2234 call DeletePropTypes()
2235 bwipe!
2236endfunc
2237
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002238func Do_test_props_do_not_affect_byte_offsets(ff, increment)
2239 new
2240 let lcount = 410
2241
2242 " File format affects byte-offset calculations, so make sure it is known.
2243 exec 'setlocal fileformat=' . a:ff
2244
2245 " Fill the buffer with varying length lines. We need a suitably large number
2246 " to force Vim code through paths wehere previous error have occurred. This
2247 " is more 'art' than 'science'.
2248 let text = 'a'
2249 call setline(1, text)
2250 let offsets = [1]
2251 for idx in range(lcount)
2252 call add(offsets, offsets[idx] + len(text) + a:increment)
2253 if (idx % 6) == 0
2254 let text = text . 'a'
2255 endif
2256 call append(line('$'), text)
2257 endfor
2258
2259 " Set a property that spans a few lines to cause Vim's internal buffer code
2260 " to perform a reasonable amount of rearrangement.
2261 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2262 call prop_add(1, 1, {'type': 'one', 'end_lnum': 6, 'end_col': 2})
2263
2264 for idx in range(lcount)
2265 let boff = line2byte(idx + 1)
2266 call assert_equal(offsets[idx], boff, 'Bad byte offset at line ' . (idx + 1))
2267 endfor
2268
2269 call prop_type_delete('one')
2270 bwipe!
2271endfunc
2272
2273func Test_props_do_not_affect_byte_offsets()
2274 call Do_test_props_do_not_affect_byte_offsets('unix', 1)
2275endfunc
2276
2277func Test_props_do_not_affect_byte_offsets_dos()
2278 call Do_test_props_do_not_affect_byte_offsets('dos', 2)
2279endfunc
2280
2281func Test_props_do_not_affect_byte_offsets_editline()
2282 new
2283 let lcount = 410
2284
2285 " File format affects byte-offset calculations, so make sure it is known.
2286 setlocal fileformat=unix
2287
2288 " Fill the buffer with varying length lines. We need a suitably large number
2289 " to force Vim code through paths wehere previous error have occurred. This
2290 " is more 'art' than 'science'.
2291 let text = 'aa'
2292 call setline(1, text)
2293 let offsets = [1]
2294 for idx in range(lcount)
2295 call add(offsets, offsets[idx] + len(text) + 1)
2296 if (idx % 6) == 0
2297 let text = text . 'a'
2298 endif
2299 call append(line('$'), text)
2300 endfor
2301
2302 " Set a property that just covers the first line. When this test was
2303 " developed, this did not trigger a byte-offset error.
2304 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2305 call prop_add(1, 1, {'type': 'one', 'end_lnum': 1, 'end_col': 3})
2306
2307 for idx in range(lcount)
2308 let boff = line2byte(idx + 1)
2309 call assert_equal(offsets[idx], boff,
2310 \ 'Confounding bad byte offset at line ' . (idx + 1))
2311 endfor
2312
2313 " Insert text in the middle of the first line, keeping the property
2314 " unchanged.
2315 :1
2316 normal aHello
2317 for idx in range(1, lcount)
2318 let offsets[idx] = offsets[idx] + 5
2319 endfor
2320
2321 for idx in range(lcount)
2322 let boff = line2byte(idx + 1)
2323 call assert_equal(offsets[idx], boff,
2324 \ 'Bad byte offset at line ' . (idx + 1))
2325 endfor
2326
2327 call prop_type_delete('one')
2328 bwipe!
2329endfunc
2330
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002331func Test_prop_inserts_text()
2332 CheckRunVimInTerminal
2333
2334 " Just a basic check for now
2335 let lines =<< trim END
2336 call setline(1, 'insert some text here and other text there and some more text after wrapping')
2337 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2338 call prop_type_add('otherprop', #{highlight: 'Search'})
2339 call prop_type_add('moreprop', #{highlight: 'DiffAdd'})
2340 call prop_add(1, 18, #{type: 'someprop', text: 'SOME '})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002341 call prop_add(1, 38, #{type: 'otherprop', text: "OTHER\t"})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002342 call prop_add(1, 69, #{type: 'moreprop', text: 'MORE '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002343 normal $
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002344
2345 call setline(2, 'prepost')
2346 call prop_type_add('multibyte', #{highlight: 'Visual'})
2347 call prop_add(2, 4, #{type: 'multibyte', text: 'söme和平téxt'})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002348
Bram Moolenaar25463612022-08-08 11:07:47 +01002349 call setline(3, 'Foo foo = { 1, 2 };')
2350 call prop_type_add( 'testprop', #{highlight: 'Comment'})
2351 call prop_add(3, 13, #{type: 'testprop', text: '.x='})
2352 call prop_add(3, 16, #{type: 'testprop', text: '.y='})
2353
2354 call setline(4, '')
2355 call prop_add(4, 1, #{type: 'someprop', text: 'empty line'})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002356 END
2357 call writefile(lines, 'XscriptPropsWithText')
Bram Moolenaar25463612022-08-08 11:07:47 +01002358 let buf = RunVimInTerminal('-S XscriptPropsWithText', #{rows: 8, cols: 60})
Bram Moolenaar711483c2022-07-30 21:33:46 +01002359 call VerifyScreenDump(buf, 'Test_prop_inserts_text_1', {})
2360
2361 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2362 call VerifyScreenDump(buf, 'Test_prop_inserts_text_2', {})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002363
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002364 call term_sendkeys(buf, "2G$")
2365 call VerifyScreenDump(buf, 'Test_prop_inserts_text_3', {})
2366
Bram Moolenaar25463612022-08-08 11:07:47 +01002367 call term_sendkeys(buf, "3Gf1")
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002368 call VerifyScreenDump(buf, 'Test_prop_inserts_text_4', {})
Bram Moolenaar25463612022-08-08 11:07:47 +01002369 call term_sendkeys(buf, "f2")
2370 call VerifyScreenDump(buf, 'Test_prop_inserts_text_5', {})
2371
2372 call term_sendkeys(buf, "4G")
2373 call VerifyScreenDump(buf, 'Test_prop_inserts_text_6', {})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002374
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002375 call StopVimInTerminal(buf)
2376 call delete('XscriptPropsWithText')
2377endfunc
2378
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002379func Test_props_with_text_after()
2380 CheckRunVimInTerminal
2381
2382 let lines =<< trim END
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002383 set showbreak=+++
Bram Moolenaar73c38422022-08-07 11:53:40 +01002384 set breakindent
2385 call setline(1, ' some text here and other text there')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002386 call prop_type_add('rightprop', #{highlight: 'ErrorMsg'})
2387 call prop_type_add('afterprop', #{highlight: 'Search'})
2388 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
2389 call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002390 call prop_add(1, 0, #{type: 'afterprop', text: "\tAFTER\t", text_align: 'after'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002391 call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'})
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002392 call prop_add(1, 0, #{type: 'belowprop', text: ' ALSO BELOW ', text_align: 'below'})
Bram Moolenaar84b247f2022-08-01 11:17:40 +01002393
2394 call setline(2, 'Last line.')
2395 call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'})
2396 normal G$
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002397
2398 call setline(3, 'right here')
2399 call prop_add(3, 0, #{type: 'rightprop', text: 'söme和平téxt', text_align: 'right'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002400 END
2401 call writefile(lines, 'XscriptPropsWithTextAfter')
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002402 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002403 call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {})
2404
2405 call StopVimInTerminal(buf)
2406 call delete('XscriptPropsWithTextAfter')
2407endfunc
2408
Bram Moolenaarcba69522022-08-06 21:03:53 +01002409func Test_props_with_text_after_below_trunc()
2410 CheckRunVimInTerminal
2411
2412 let lines =<< trim END
2413 vim9script
2414 edit foobar
2415 set showbreak=+++
2416 setline(1, ['onasdf asdf asdf asdf asd fas df', 'two'])
2417 prop_type_add('test', {highlight: 'Special'})
2418 prop_add(1, 0, {
2419 type: 'test',
2420 text: 'the quick brown fox jumps over the lazy dog',
2421 text_align: 'after'
2422 })
2423 prop_add(1, 0, {
2424 type: 'test',
2425 text: 'the quick brown fox jumps over the lazy dog',
2426 text_align: 'below'
2427 })
2428 normal G$
2429 END
2430 call writefile(lines, 'XscriptPropsAfterTrunc')
2431 let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60})
2432 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {})
2433
2434 call StopVimInTerminal(buf)
2435 call delete('XscriptPropsAfterTrunc')
2436endfunc
2437
Bram Moolenaare175dc62022-08-01 22:18:50 +01002438func Test_props_with_text_after_joined()
2439 CheckRunVimInTerminal
2440
2441 let lines =<< trim END
2442 call setline(1, ['one', 'two', 'three', 'four'])
2443 call prop_type_add('afterprop', #{highlight: 'Search'})
2444 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'})
2445 call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'})
2446 normal ggJ
2447 normal GkJ
2448
2449 call setline(3, ['a', 'b', 'c', 'd', 'e', 'f'])
2450 call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'})
2451 call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'})
2452 call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'})
2453 call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'})
2454 normal 3G6J
2455 END
2456 call writefile(lines, 'XscriptPropsWithTextAfterJoined')
2457 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60})
2458 call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {})
2459
2460 call StopVimInTerminal(buf)
2461 call delete('XscriptPropsWithTextAfterJoined')
2462endfunc
2463
Bram Moolenaar398649e2022-08-04 15:03:48 +01002464func Test_props_with_text_after_truncated()
2465 CheckRunVimInTerminal
2466
2467 let lines =<< trim END
2468 call setline(1, ['one two three four five six seven'])
2469 call prop_type_add('afterprop', #{highlight: 'Search'})
2470 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
2471
2472 call setline(2, ['one two three four five six seven'])
2473 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
2474
2475 call setline(3, ['one two three four five six seven'])
2476 call prop_add(3, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five lets wrap after some more text', text_align: 'below'})
2477
2478 call setline(4, ['cursor here'])
2479 normal 4Gfh
2480 END
2481 call writefile(lines, 'XscriptPropsWithTextAfterTrunc')
2482 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60})
2483 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {})
2484
2485 call term_sendkeys(buf, ":37vsp\<CR>gg")
2486 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {})
2487
2488 call term_sendkeys(buf, ":36wincmd |\<CR>")
2489 call term_sendkeys(buf, "2G$")
2490 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {})
2491
2492 call term_sendkeys(buf, ":33wincmd |\<CR>")
2493 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {})
2494
2495 call term_sendkeys(buf, ":18wincmd |\<CR>")
2496 call term_sendkeys(buf, "0fx")
2497 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {})
2498
2499 call StopVimInTerminal(buf)
2500 call delete('XscriptPropsWithTextAfterTrunc')
2501endfunc
2502
2503func Test_props_with_text_after_wraps()
2504 CheckRunVimInTerminal
2505
2506 let lines =<< trim END
2507 call setline(1, ['one two three four five six seven'])
2508 call prop_type_add('afterprop', #{highlight: 'Search'})
2509 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'})
2510
2511 call setline(2, ['one two three four five six seven'])
2512 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'})
2513
2514 call setline(3, ['one two three four five six seven'])
2515 call prop_add(3, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five lets wrap after some more text', text_align: 'below', text_wrap: 'wrap'})
2516
2517 call setline(4, ['cursor here'])
2518 normal 4Gfh
2519 END
2520 call writefile(lines, 'XscriptPropsWithTextAfterWraps')
2521 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60})
2522 call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {})
2523
2524 call StopVimInTerminal(buf)
2525 call delete('XscriptPropsWithTextAfterWraps')
2526endfunc
2527
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002528func Test_props_with_text_after_nowrap()
2529 CheckRunVimInTerminal
2530
2531 let lines =<< trim END
2532 set nowrap
2533 call setline(1, ['one', 'two', 'three'])
2534 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
2535 call prop_type_add('anotherprop', #{highlight: 'Search'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01002536 call prop_type_add('someprop', #{highlight: 'DiffChange'})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002537 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
2538 call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'})
2539 call prop_add(2, 0, #{type: 'belowprop', text: 'One More Here', text_align: 'below'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01002540 call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'})
2541 call prop_add(1, 0, #{type: 'someprop', text: ' After the text', text_align: 'after'})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002542 normal G$
2543 END
2544 call writefile(lines, 'XscriptPropsAfterNowrap')
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01002545 let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 10, cols: 60})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002546 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {})
2547
Bram Moolenaar1306b362022-08-06 15:59:06 +01002548 call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3\<CR>")
2549 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {})
2550
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002551 call StopVimInTerminal(buf)
2552 call delete('XscriptPropsAfterNowrap')
2553endfunc
2554
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002555func Test_props_with_text_below_nowrap()
2556 CheckRunVimInTerminal
2557
2558 let lines =<< trim END
2559 vim9script
2560 edit foobar
2561 set nowrap
2562 set showbreak=+++\
2563 setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two'])
2564 prop_type_add('test', {highlight: 'Special'})
2565 prop_add(1, 0, {
2566 type: 'test',
2567 text: 'the quick brown fox jumps over the lazy dog',
2568 text_align: 'after'
2569 })
2570 prop_add(1, 0, {
2571 type: 'test',
2572 text: 'the quick brown fox jumps over the lazy dog',
2573 text_align: 'below'
2574 })
2575 normal G$
2576 END
2577 call writefile(lines, 'XscriptPropsBelowNowrap')
2578 let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60})
2579 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {})
2580
2581 call term_sendkeys(buf, "gg$")
2582 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {})
2583
2584 call StopVimInTerminal(buf)
2585 call delete('XscriptPropsBelowNowrap')
2586endfunc
2587
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01002588func Test_props_with_text_after_split_join()
2589 CheckRunVimInTerminal
2590
2591 let lines =<< trim END
2592 call setline(1, ['1122'])
2593 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
2594 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
2595 exe "normal f2i\<CR>\<Esc>"
2596
2597 func AddMore()
2598 call prop_type_add('another', #{highlight: 'Search'})
2599 call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'})
2600 call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'})
2601 endfunc
2602 END
2603 call writefile(lines, 'XscriptPropsAfterSplitJoin')
2604 let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60})
2605 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {})
2606
2607 call term_sendkeys(buf, "ggJ")
2608 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {})
2609
2610 call term_sendkeys(buf, ":call AddMore()\<CR>")
2611 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {})
2612
2613 call term_sendkeys(buf, "ggf s\<CR>\<Esc>")
2614 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {})
2615
2616 call term_sendkeys(buf, "ggJ")
2617 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {})
2618
2619 call StopVimInTerminal(buf)
2620 call delete('XscriptPropsAfterSplitJoin')
2621endfunc
2622
Bram Moolenaar3a4cd392022-07-30 22:17:18 +01002623func Test_removed_prop_with_text_cleans_up_array()
2624 new
2625 call setline(1, 'some text here')
2626 call prop_type_add('some', #{highlight: 'ErrorMsg'})
2627 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
2628 call assert_equal(-1, id1)
2629 let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"})
2630 call assert_equal(-2, id2)
2631
2632 " removing the props resets the index
2633 call prop_remove(#{id: id1})
2634 call prop_remove(#{id: id2})
2635 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
2636 call assert_equal(-1, id1)
2637
2638 call prop_type_delete('some')
2639 bwipe!
2640endfunc
2641
Bram Moolenaar1f4ee192022-08-01 15:52:55 +01002642def Test_insert_text_before_virtual_text()
2643 new foobar
2644 setline(1, '12345678')
2645 prop_type_add('test', {highlight: 'Search'})
2646 prop_add(1, 5, {
2647 type: 'test',
2648 text: ' virtual text '
2649 })
2650 normal! f4axyz
2651 normal! f5iXYZ
2652 assert_equal('1234xyzXYZ5678', getline(1))
2653
2654 prop_type_delete('test')
2655 bwipe!
2656enddef
2657
Bram Moolenaar99fa7212020-04-26 15:59:55 +02002658" vim: shiftwidth=2 sts=2 expandtab