blob: f97772ce63e9e067276e3fc0e57a8027209fd1fb [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
Bram Moolenaar10246902022-08-08 17:08:05 +010074def Test_proptype_add_remove()
75 # add and remove a prop type so that the array is empty
76 prop_type_add('local', {bufnr: bufnr('%')})
77 prop_type_delete('local', {bufnr: bufnr('%')})
78 prop_type_add('global', {highlight: 'ErrorMsg'})
79 prop_add(1, 1, {length: 1, type: 'global'})
80 redraw
81
82 prop_clear(1)
83 prop_type_delete('global')
84enddef
85
Martin Tournoije2390c72021-07-28 13:30:16 +020086def Test_proptype_buf_list()
87 new
88 var bufnr = bufnr('')
89 try
90 prop_type_add('global', {})
91 prop_type_add('local', {bufnr: bufnr})
92
93 prop_add(1, 1, {type: 'global'})
94 prop_add(1, 1, {type: 'local'})
95
96 assert_equal([
97 {type: 'local', type_bufnr: bufnr, id: 0, col: 1, end: 1, length: 0, start: 1},
98 {type: 'global', type_bufnr: 0, id: 0, col: 1, end: 1, length: 0, start: 1},
99 ], prop_list(1))
100 assert_equal(
101 {lnum: 1, id: 0, col: 1, type_bufnr: bufnr, end: 1, type: 'local', length: 0, start: 1},
102 prop_find({lnum: 1, type: 'local'}))
103 assert_equal(
104 {lnum: 1, id: 0, col: 1, type_bufnr: 0, end: 1, type: 'global', length: 0, start: 1},
105 prop_find({lnum: 1, type: 'global'}))
106
107 prop_remove({type: 'global'}, 1)
108 prop_remove({type: 'local'}, 1)
109 finally
110 prop_type_delete('global')
111 prop_type_delete('local', {bufnr: bufnr})
112 bwipe!
113 endtry
114enddef
115
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100116func AddPropTypes()
117 call prop_type_add('one', {})
118 call prop_type_add('two', {})
119 call prop_type_add('three', {})
120 call prop_type_add('whole', {})
121endfunc
122
123func DeletePropTypes()
124 call prop_type_delete('one')
125 call prop_type_delete('two')
126 call prop_type_delete('three')
127 call prop_type_delete('whole')
128endfunc
129
130func SetupPropsInFirstLine()
131 call setline(1, 'one two three')
132 call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'})
Bram Moolenaara5a78822019-09-04 21:57:18 +0200133 eval 1->prop_add(5, {'length': 3, 'id': 12, 'type': 'two'})
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100134 call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'})
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100135 call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'})
136endfunc
137
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100138func Get_expected_props()
139 return [
Martin Tournoije2390c72021-07-28 13:30:16 +0200140 \ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1},
141 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
142 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
143 \ #{type_bufnr: 0, col: 9, length: 5, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100144 \ ]
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100145endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100146
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100147func Test_prop_find()
148 new
149 call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix'])
Martin Tournoije2390c72021-07-28 13:30:16 +0200150
151 " Add two text props on lines 1 and 5, and one spanning lines 2 to 4.
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100152 call prop_type_add('prop_name', {'highlight': 'Directory'})
153 call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3})
154 call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9})
155 call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1})
156
157 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200158 \ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1},
159 \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0},
160 \ #{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 +0100161 \ ]
162
163 " Starting at line 5 col 1 this should find the prop at line 5 col 4.
Ben Jacksona7704222022-08-20 20:54:51 +0100164 call cursor(5, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100165 let result = prop_find({'type': 'prop_name'}, 'f')
166 call assert_equal(expected[2], result)
167
168 " With skipstart left at false (default), this should find the prop at line
169 " 5 col 4.
170 let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4}, 'b')
171 call assert_equal(expected[2], result)
172
173 " With skipstart set to true, this should skip the prop at line 5 col 4.
174 let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4, 'skipstart': 1}, 'b')
175 unlet result.length
176 call assert_equal(expected[1], result)
177
178 " Search backwards from line 1 col 10 to find the prop on the same line.
179 let result = prop_find({'type': 'prop_name', 'lnum': 1, 'col': 10}, 'b')
180 call assert_equal(expected[0], result)
181
182 " with skipstart set to false, if the start position is anywhere between the
183 " start and end lines of a text prop (searching forward or backward), the
184 " result should be the prop on the first line (the line with 'start' set to 1).
Ben Jacksona7704222022-08-20 20:54:51 +0100185 call cursor(3, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100186 let result = prop_find({'type': 'prop_name'}, 'f')
187 unlet result.length
188 call assert_equal(expected[1], result)
189 let result = prop_find({'type': 'prop_name'}, 'b')
190 unlet result.length
191 call assert_equal(expected[1], result)
192
193 " with skipstart set to true, if the start position is anywhere between the
194 " start and end lines of a text prop (searching forward or backward), all lines
195 " of the prop will be skipped.
196 let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'b')
197 call assert_equal(expected[0], result)
198 let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'f')
199 call assert_equal(expected[2], result)
200
201 " Use skipstart to search through all props with type name 'prop_name'.
202 " First forward...
203 let lnum = 1
204 let col = 1
205 let i = 0
206 for exp in expected
207 let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'f')
208 if !has_key(exp, "length")
209 unlet result.length
210 endif
211 call assert_equal(exp, result)
212 let lnum = result.lnum
213 let col = result.col
214 let i = i + 1
215 endfor
216
217 " ...then backwards.
218 let lnum = 6
219 let col = 4
220 let i = 2
221 while i >= 0
222 let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'b')
223 if !has_key(expected[i], "length")
224 unlet result.length
225 endif
226 call assert_equal(expected[i], result)
227 let lnum = result.lnum
228 let col = result.col
229 let i = i - 1
Martin Tournoije2390c72021-07-28 13:30:16 +0200230 endwhile
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100231
232 " Starting from line 6 col 1 search backwards for prop with id 10.
Ben Jacksona7704222022-08-20 20:54:51 +0100233 call cursor(6, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100234 let result = prop_find({'id': 10, 'skipstart': 1}, 'b')
235 call assert_equal(expected[0], result)
236
237 " Starting from line 1 col 1 search forwards for prop with id 12.
Ben Jacksona7704222022-08-20 20:54:51 +0100238 call cursor(1, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100239 let result = prop_find({'id': 12}, 'f')
240 call assert_equal(expected[2], result)
241
242 " Search for a prop with an unknown id.
243 let result = prop_find({'id': 999}, 'f')
244 call assert_equal({}, result)
245
246 " Search backwards from the proceeding position of the prop with id 11
247 " (at line num 2 col 4). This should return an empty dict.
248 let result = prop_find({'id': 11, 'lnum': 2, 'col': 3}, 'b')
249 call assert_equal({}, result)
250
251 " When lnum is given and col is omitted, use column 1.
252 let result = prop_find({'type': 'prop_name', 'lnum': 1}, 'f')
253 call assert_equal(expected[0], result)
254
Bram Moolenaare041dde2021-08-01 21:30:12 +0200255 " Negative ID is possible, just like prop is not found.
Bram Moolenaar8e3fc132021-07-31 18:33:57 +0200256 call assert_equal({}, prop_find({'id': -1}))
Bram Moolenaare041dde2021-08-01 21:30:12 +0200257 call assert_equal({}, prop_find({'id': -2}))
Bram Moolenaar8e3fc132021-07-31 18:33:57 +0200258
Bram Moolenaare041dde2021-08-01 21:30:12 +0200259 call prop_clear(1, 6)
260
261 " Default ID is zero
262 call prop_add(5, 4, {'type': 'prop_name', 'length': 1})
263 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}))
264
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100265 call prop_type_delete('prop_name')
Bram Moolenaare041dde2021-08-01 21:30:12 +0200266 call prop_clear(1, 6)
Bram Moolenaar4da7a252020-09-02 19:59:00 +0200267 bwipe!
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100268endfunc
269
Bram Moolenaareb245562020-09-03 22:33:44 +0200270def Test_prop_find2()
271 # Multiple props per line, start on the first, should find the second.
272 new
273 ['the quikc bronw fox jumsp over the layz dog']->repeat(2)->setline(1)
Bram Moolenaare0de1712020-12-02 17:36:54 +0100274 prop_type_add('misspell', {highlight: 'ErrorMsg'})
Bram Moolenaareb245562020-09-03 22:33:44 +0200275 for lnum in [1, 2]
276 for col in [8, 14, 24, 38]
Bram Moolenaare0de1712020-12-02 17:36:54 +0100277 prop_add(lnum, col, {type: 'misspell', length: 2})
Bram Moolenaareb245562020-09-03 22:33:44 +0200278 endfor
279 endfor
280 cursor(1, 8)
Martin Tournoije2390c72021-07-28 13:30:16 +0200281 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 +0100282 var result = prop_find({type: 'misspell', skipstart: true}, 'f')
Bram Moolenaareb245562020-09-03 22:33:44 +0200283 assert_equal(expected, result)
284
285 prop_type_delete('misspell')
286 bwipe!
287enddef
288
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100289func Test_prop_find_smaller_len_than_match_col()
290 new
291 call prop_type_add('test', {'highlight': 'ErrorMsg'})
292 call setline(1, ['xxxx', 'x'])
293 call prop_add(1, 4, {'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200294 call assert_equal(
295 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 4, type: 'test', length: 0, start: 1, end: 1},
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100296 \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b'))
297 bwipe!
298 call prop_type_delete('test')
299endfunc
300
Bram Moolenaar24f21fd2021-03-27 22:07:29 +0100301func Test_prop_find_with_both_option_enabled()
302 " Initialize
303 new
304 call AddPropTypes()
305 call SetupPropsInFirstLine()
306 let props = Get_expected_props()->map({_, v -> extend(v, {'lnum': 1})})
307 " Test
308 call assert_fails("call prop_find({'both': 1})", 'E968:')
309 call assert_fails("call prop_find({'id': 11, 'both': 1})", 'E860:')
310 call assert_fails("call prop_find({'type': 'three', 'both': 1})", 'E860:')
311 call assert_equal({}, prop_find({'id': 11, 'type': 'three', 'both': 1}))
312 call assert_equal({}, prop_find({'id': 130000, 'type': 'one', 'both': 1}))
313 call assert_equal(props[2], prop_find({'id': 12, 'type': 'two', 'both': 1}))
314 call assert_equal(props[0], prop_find({'id': 14, 'type': 'whole', 'both': 1}))
315 " Clean up
316 call DeletePropTypes()
317 bwipe!
318endfunc
319
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100320func Test_prop_add()
321 new
322 call AddPropTypes()
323 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100324 let expected_props = Get_expected_props()
325 call assert_equal(expected_props, prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100326 call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:')
327 call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:')
Martin Tournoije2390c72021-07-28 13:30:16 +0200328
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100329 " Insert a line above, text props must still be there.
330 call append(0, 'empty')
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100331 call assert_equal(expected_props, prop_list(2))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100332 " Delete a line above, text props must still be there.
333 1del
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100334 call assert_equal(expected_props, prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100335
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100336 " Prop without length or end column is zero length
337 call prop_clear(1)
Bram Moolenaar12f20032020-02-26 22:06:00 +0100338 call prop_type_add('included', {'start_incl': 1, 'end_incl': 1})
339 call prop_add(1, 5, #{type: 'included'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200340 let expected = [#{type_bufnr: 0, col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}]
Bram Moolenaar12f20032020-02-26 22:06:00 +0100341 call assert_equal(expected, prop_list(1))
342
343 " Inserting text makes the prop bigger.
344 exe "normal 5|ixx\<Esc>"
Martin Tournoije2390c72021-07-28 13:30:16 +0200345 let expected = [#{type_bufnr: 0, col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}]
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100346 call assert_equal(expected, prop_list(1))
347
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200348 call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
349
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100350 call DeletePropTypes()
Bram Moolenaar12f20032020-02-26 22:06:00 +0100351 call prop_type_delete('included')
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100352 bwipe!
353endfunc
354
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200355" Test for the prop_add_list() function
356func Test_prop_add_list()
357 new
358 call AddPropTypes()
359 call setline(1, ['one one one', 'two two two', 'six six six', 'ten ten ten'])
360 call prop_add_list(#{type: 'one', id: 2},
361 \ [[1, 1, 1, 3], [2, 5, 2, 7], [3, 6, 4, 6]])
362 call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
363 \ length: 2, start: 1}], prop_list(1))
364 call assert_equal([#{id: 2, col: 5, type_bufnr: 0, end: 1, type: 'one',
365 \ length: 2, start: 1}], prop_list(2))
366 call assert_equal([#{id: 2, col: 6, type_bufnr: 0, end: 0, type: 'one',
367 \ length: 7, start: 1}], prop_list(3))
368 call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
369 \ length: 5, start: 0}], prop_list(4))
370 call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:')
371 call assert_fails('call prop_add_list({}, {})', 'E1211:')
372 call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:')
373 call assert_fails('call prop_add_list(#{type: "abc"}, [[1, 1, 1, 3]])', 'E971:')
374 call assert_fails('call prop_add_list(#{type: "one"}, [[]])', 'E474:')
375 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 1], {}])', 'E714:')
376 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, "a"]])', 'E474:')
377 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2]])', 'E474:')
378 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 2], [2, 2]])', 'E474:')
379 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 2], [4, 1, 5, 2]])', 'E966:')
380 call assert_fails('call prop_add_list(#{type: "one"}, [[3, 1, 1, 2]])', 'E966:')
381 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
382 call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
383 call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:')
Bram Moolenaard83392a2022-09-01 12:22:46 +0100384 call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E1298:')
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200385 call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:')
386 call DeletePropTypes()
387 bw!
388endfunc
389
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100390func Test_prop_remove()
391 new
392 call AddPropTypes()
393 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100394 let props = Get_expected_props()
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100395 call assert_equal(props, prop_list(1))
396
397 " remove by id
Bram Moolenaara5a78822019-09-04 21:57:18 +0200398 call assert_equal(1, {'id': 12}->prop_remove(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100399 unlet props[2]
400 call assert_equal(props, prop_list(1))
401
402 " remove by type
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200403 call assert_equal(1, prop_remove({'type': 'one'}, 1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100404 unlet props[1]
405 call assert_equal(props, prop_list(1))
406
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200407 " remove from unknown buffer
408 call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:')
409
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100410 call DeletePropTypes()
411 bwipe!
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100412
413 new
414 call AddPropTypes()
415 call SetupPropsInFirstLine()
416 call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
417 let props = Get_expected_props()
Martin Tournoije2390c72021-07-28 13:30:16 +0200418 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 +0100419 call assert_equal(props, prop_list(1))
420 call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
421 unlet props[3]
422 call assert_equal(props, prop_list(1))
423
Bram Moolenaare2e40752020-09-04 21:18:46 +0200424 call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:')
425 call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:')
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100426
427 call DeletePropTypes()
428 bwipe!
Ben Jacksona7704222022-08-20 20:54:51 +0100429
430 new
431 call AddPropTypes()
432 call SetupPropsInFirstLine()
433 let props = Get_expected_props() " [whole, one, two, three]
434 call assert_equal(props, prop_list(1))
435
436 " remove one by types
437 call assert_equal(1, prop_remove({'types': ['one', 'two', 'three']}, 1))
438 unlet props[1] " [whole, two, three]
439 call assert_equal(props, prop_list(1))
440
441 " remove 'all' by types
442 call assert_equal(2, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
443 unlet props[0] " [two, three]
444 unlet props[1] " [three]
445 call assert_equal(props, prop_list(1))
446
447 " remove none by types
448 call assert_equal(0, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
449 call assert_equal(props, prop_list(1))
450
451 " no types
452 call assert_fails("call prop_remove({'types': []}, 1)", 'E968:')
453 call assert_fails("call prop_remove({'types': ['not_a_real_type']}, 1)", 'E971:')
454
455 " only one of types and type can be supplied
456 call assert_fails("call prop_remove({'type': 'one', 'types': ['three'], 'all': 1}, 1)", 'E1295:')
457
458 call DeletePropTypes()
459 bwipe!
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100460endfunc
461
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200462def Test_prop_add_vim9()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100463 prop_type_add('comment', {
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200464 highlight: 'Directory',
465 priority: 123,
466 start_incl: true,
467 end_incl: true,
468 combine: false,
469 })
470 prop_type_delete('comment')
471enddef
472
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200473def Test_prop_remove_vim9()
474 new
Bram Moolenaar62aec932022-01-29 21:45:34 +0000475 g:AddPropTypes()
476 g:SetupPropsInFirstLine()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100477 assert_equal(1, prop_remove({type: 'three', id: 13, both: true, all: true}))
Bram Moolenaar62aec932022-01-29 21:45:34 +0000478 g:DeletePropTypes()
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200479 bwipe!
480enddef
481
Bram Moolenaar196d1572019-01-02 23:47:18 +0100482func SetupOneLine()
483 call setline(1, 'xonex xtwoxx')
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200484 normal gg0
Bram Moolenaar196d1572019-01-02 23:47:18 +0100485 call AddPropTypes()
486 call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'})
487 call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'})
488 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200489 \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1},
490 \ #{type_bufnr: 0, col: 8, length: 3, id: 12, type: 'two', start: 1, end: 1},
Bram Moolenaar196d1572019-01-02 23:47:18 +0100491 \]
492 call assert_equal(expected, prop_list(1))
493 return expected
494endfunc
495
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100496func Test_prop_add_remove_buf()
497 new
498 let bufnr = bufnr('')
499 call AddPropTypes()
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100500 for lnum in range(1, 4)
501 call setline(lnum, 'one two three')
502 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100503 wincmd w
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100504 for lnum in range(1, 4)
505 call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr})
506 call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr})
507 call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr})
508 endfor
509
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100510 let props = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200511 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
512 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
513 \ #{type_bufnr: 0, col: 11, length: 3, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100514 \]
515 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100516
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100517 " remove by id
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100518 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100519 unlet props[1]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100520
521 call prop_remove({'id': 12, 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100522 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100523 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
524 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
525 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
526
527 call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4)
528 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
529 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
530 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
531 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
532
533 call prop_remove({'id': 12, 'bufnr': bufnr})
534 for lnum in range(1, 4)
535 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
536 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100537
538 " remove by type
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100539 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100540 unlet props[0]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100541
542 call prop_remove({'type': 'one', 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100543 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100544 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
545 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
546 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
547
548 call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4)
549 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
550 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
551 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
552 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
553
554 call prop_remove({'type': 'one', 'bufnr': bufnr})
555 for lnum in range(1, 4)
556 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
557 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100558
559 call DeletePropTypes()
560 wincmd w
561 bwipe!
562endfunc
563
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100564func Test_prop_backspace()
565 new
566 set bs=2
Bram Moolenaar196d1572019-01-02 23:47:18 +0100567 let expected = SetupOneLine() " 'xonex xtwoxx'
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100568
569 exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>"
570 call assert_equal('one xtwoxx', getline(1))
571 let expected[0].col = 1
572 let expected[1].col = 6
573 call assert_equal(expected, prop_list(1))
574
575 call DeletePropTypes()
576 bwipe!
577 set bs&
578endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100579
LemonBoyd0b1a092022-05-12 18:45:18 +0100580func Test_prop_change()
581 new
582 let expected = SetupOneLine() " 'xonex xtwoxx'
583
584 " Characterwise.
585 exe "normal 7|c$\<Esc>"
586 call assert_equal('xonex ', getline(1))
587 call assert_equal(expected[:0], prop_list(1))
588 " Linewise.
589 exe "normal cc\<Esc>"
590 call assert_equal('', getline(1))
591 call assert_equal([], prop_list(1))
592
593 call DeletePropTypes()
594 bwipe!
595 set bs&
596endfunc
597
Bram Moolenaar196d1572019-01-02 23:47:18 +0100598func Test_prop_replace()
599 new
600 set bs=2
601 let expected = SetupOneLine() " 'xonex xtwoxx'
602
603 exe "normal 0Ryyy\<Esc>"
604 call assert_equal('yyyex xtwoxx', getline(1))
605 call assert_equal(expected, prop_list(1))
606
607 exe "normal ftRyy\<BS>"
608 call assert_equal('yyyex xywoxx', getline(1))
609 call assert_equal(expected, prop_list(1))
610
611 exe "normal 0fwRyy\<BS>"
612 call assert_equal('yyyex xyyoxx', getline(1))
613 call assert_equal(expected, prop_list(1))
614
615 exe "normal 0foRyy\<BS>\<BS>"
616 call assert_equal('yyyex xyyoxx', getline(1))
617 call assert_equal(expected, prop_list(1))
618
LemonBoy0d534d92022-05-21 11:20:42 +0100619 " Replace three 1-byte chars with three 2-byte ones.
620 exe "normal 0l3rรธ"
621 call assert_equal('yรธรธรธx xyyoxx', getline(1))
622 let expected[0].length += 3
623 let expected[1].col += 3
624 call assert_equal(expected, prop_list(1))
625
Bram Moolenaar196d1572019-01-02 23:47:18 +0100626 call DeletePropTypes()
627 bwipe!
628 set bs&
629endfunc
630
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200631func Test_prop_open_line()
632 new
633
634 " open new line, props stay in top line
635 let expected = SetupOneLine() " 'xonex xtwoxx'
636 exe "normal o\<Esc>"
637 call assert_equal('xonex xtwoxx', getline(1))
638 call assert_equal('', getline(2))
639 call assert_equal(expected, prop_list(1))
640 call DeletePropTypes()
641
642 " move all props to next line
643 let expected = SetupOneLine() " 'xonex xtwoxx'
644 exe "normal 0i\<CR>\<Esc>"
645 call assert_equal('', getline(1))
646 call assert_equal('xonex xtwoxx', getline(2))
647 call assert_equal(expected, prop_list(2))
648 call DeletePropTypes()
649
650 " split just before prop, move all props to next line
651 let expected = SetupOneLine() " 'xonex xtwoxx'
652 exe "normal 0li\<CR>\<Esc>"
653 call assert_equal('x', getline(1))
654 call assert_equal('onex xtwoxx', getline(2))
655 let expected[0].col -= 1
656 let expected[1].col -= 1
657 call assert_equal(expected, prop_list(2))
658 call DeletePropTypes()
659
660 " split inside prop, split first prop
661 let expected = SetupOneLine() " 'xonex xtwoxx'
662 exe "normal 0lli\<CR>\<Esc>"
663 call assert_equal('xo', getline(1))
664 call assert_equal('nex xtwoxx', getline(2))
665 let exp_first = [deepcopy(expected[0])]
666 let exp_first[0].length = 1
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200667 let exp_first[0].end = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200668 call assert_equal(exp_first, prop_list(1))
669 let expected[0].col = 1
670 let expected[0].length = 2
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200671 let expected[0].start = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200672 let expected[1].col -= 2
673 call assert_equal(expected, prop_list(2))
674 call DeletePropTypes()
675
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200676 " split just after first prop, second prop move to next line
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200677 let expected = SetupOneLine() " 'xonex xtwoxx'
678 exe "normal 0fea\<CR>\<Esc>"
679 call assert_equal('xone', getline(1))
680 call assert_equal('x xtwoxx', getline(2))
681 let exp_first = expected[0:0]
682 call assert_equal(exp_first, prop_list(1))
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200683 let expected = expected[1:1]
684 let expected[0].col -= 4
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200685 call assert_equal(expected, prop_list(2))
686 call DeletePropTypes()
687
LemonBoy788c06a2022-05-14 18:48:05 +0100688 " split at the space character with 'ai' active, the leading space is removed
689 " in the second line and the prop is shifted accordingly.
690 let expected = SetupOneLine() " 'xonex xtwoxx'
691 set ai
692 exe "normal 6|i\<CR>\<Esc>"
693 call assert_equal('xonex', getline(1))
694 call assert_equal('xtwoxx', getline(2))
695 let expected[1].col -= 6
696 call assert_equal(expected, prop_list(1) + prop_list(2))
697 set ai&
698 call DeletePropTypes()
699
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200700 bwipe!
701 set bs&
702endfunc
703
Bram Moolenaarecb00c72022-08-07 14:55:14 +0100704func Test_prop_put()
705 new
706 let expected = SetupOneLine() " 'xonex xtwoxx'
707
708 let @a = 'new'
709 " insert just after the prop
710 normal 03l"ap
711 " insert inside the prop
712 normal 02l"ap
713 " insert just before the prop
714 normal 0"ap
715
716 call assert_equal('xnewonnewenewx xtwoxx', getline(1))
717 let expected[0].col += 3
718 let expected[0].length += 3
719 let expected[1].col += 9
720 call assert_equal(expected, prop_list(1))
721
722 " Visually select 4 chars in the prop and put "AB" to replace them
723 let @a = 'AB'
724 normal 05lv3l"ap
725 call assert_equal('xnewoABenewx xtwoxx', getline(1))
726 let expected[0].length -= 2
727 let expected[1].col -= 2
728 call assert_equal(expected, prop_list(1))
729
730 call DeletePropTypes()
731 bwipe!
732endfunc
733
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100734func Test_prop_clear()
735 new
736 call AddPropTypes()
737 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100738 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100739
Bram Moolenaara5a78822019-09-04 21:57:18 +0200740 eval 1->prop_clear()
741 call assert_equal([], 1->prop_list())
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100742
743 call DeletePropTypes()
744 bwipe!
745endfunc
746
747func Test_prop_clear_buf()
748 new
749 call AddPropTypes()
750 call SetupPropsInFirstLine()
751 let bufnr = bufnr('')
752 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100753 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100754
755 call prop_clear(1, 1, {'bufnr': bufnr})
756 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
757
758 wincmd w
759 call DeletePropTypes()
760 bwipe!
761endfunc
762
Bram Moolenaar21b50382019-01-04 18:07:24 +0100763func Test_prop_setline()
764 new
765 call AddPropTypes()
766 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100767 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100768
769 call setline(1, 'foobar')
770 call assert_equal([], prop_list(1))
771
772 call DeletePropTypes()
773 bwipe!
774endfunc
775
776func Test_prop_setbufline()
777 new
778 call AddPropTypes()
779 call SetupPropsInFirstLine()
780 let bufnr = bufnr('')
781 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100782 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100783
784 call setbufline(bufnr, 1, 'foobar')
785 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
786
787 wincmd w
788 call DeletePropTypes()
789 bwipe!
790endfunc
791
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100792func Test_prop_substitute()
793 new
794 " Set first line to 'one two three'
795 call AddPropTypes()
796 call SetupPropsInFirstLine()
797 let expected_props = Get_expected_props()
798 call assert_equal(expected_props, prop_list(1))
799
800 " Change "n" in "one" to XX: 'oXXe two three'
801 s/n/XX/
802 let expected_props[0].length += 1
803 let expected_props[1].length += 1
804 let expected_props[2].col += 1
805 let expected_props[3].col += 1
806 call assert_equal(expected_props, prop_list(1))
807
808 " Delete "t" in "two" and "three" to XX: 'oXXe wo hree'
809 s/t//g
810 let expected_props[0].length -= 2
811 let expected_props[2].length -= 1
812 let expected_props[3].length -= 1
813 let expected_props[3].col -= 1
814 call assert_equal(expected_props, prop_list(1))
815
816 " Split the line by changing w to line break: 'oXXe ', 'o hree'
817 " The long prop is split and spans both lines.
818 " The props on "two" and "three" move to the next line.
819 s/w/\r/
820 let new_props = [
821 \ copy(expected_props[0]),
822 \ copy(expected_props[2]),
823 \ copy(expected_props[3]),
824 \ ]
825 let expected_props[0].length = 5
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200826 let expected_props[0].end = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100827 unlet expected_props[3]
828 unlet expected_props[2]
829 call assert_equal(expected_props, prop_list(1))
830
831 let new_props[0].length = 6
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200832 let new_props[0].start = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100833 let new_props[1].col = 1
834 let new_props[1].length = 1
835 let new_props[2].col = 3
836 call assert_equal(new_props, prop_list(2))
837
838 call DeletePropTypes()
839 bwipe!
840endfunc
841
Bram Moolenaar663bc892019-01-08 23:07:24 +0100842func Test_prop_change_indent()
843 call prop_type_add('comment', {'highlight': 'Directory'})
844 new
845 call setline(1, [' xxx', 'yyyyy'])
846 call prop_add(2, 2, {'length': 2, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200847 let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0}
Bram Moolenaar663bc892019-01-08 23:07:24 +0100848 call assert_equal([expect], prop_list(2))
849
850 set shiftwidth=3
851 normal 2G>>
852 call assert_equal(' yyyyy', getline(2))
853 let expect.col += 3
854 call assert_equal([expect], prop_list(2))
855
856 normal 2G==
857 call assert_equal(' yyyyy', getline(2))
858 let expect.col = 6
859 call assert_equal([expect], prop_list(2))
860
861 call prop_clear(2)
862 call prop_add(2, 2, {'length': 5, 'type': 'comment'})
863 let expect.col = 2
864 let expect.length = 5
865 call assert_equal([expect], prop_list(2))
866
867 normal 2G<<
868 call assert_equal(' yyyyy', getline(2))
869 let expect.length = 2
870 call assert_equal([expect], prop_list(2))
871
872 set shiftwidth&
873 call prop_type_delete('comment')
874endfunc
875
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100876" Setup a three line prop in lines 2 - 4.
877" Add short props in line 1 and 5.
878func Setup_three_line_prop()
879 new
880 call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five'])
881 call prop_add(1, 2, {'length': 1, 'type': 'comment'})
882 call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'})
883 call prop_add(5, 2, {'length': 1, 'type': 'comment'})
884endfunc
885
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100886func Test_prop_multiline()
Bram Moolenaara5a78822019-09-04 21:57:18 +0200887 eval 'comment'->prop_type_add({'highlight': 'Directory'})
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100888 new
889 call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz'])
890
891 " start halfway line 1, end halfway line 3
892 call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200893 let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100894 call assert_equal([expect1], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200895 let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100896 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200897 let expect3 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100898 call assert_equal([expect3], prop_list(3))
899 call prop_clear(1, 3)
900
901 " include all three lines
902 call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'})
903 let expect1.col = 1
904 let expect1.length = 8
905 call assert_equal([expect1], prop_list(1))
906 call assert_equal([expect2], prop_list(2))
907 let expect3.length = 9
908 call assert_equal([expect3], prop_list(3))
909 call prop_clear(1, 3)
910
911 bwipe!
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100912
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100913 " Test deleting the first line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100914 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200915 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 +0100916 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200917 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100918 call assert_equal([expect2], prop_list(2))
919 2del
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100920 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200921 let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100922 call assert_equal([expect2], prop_list(2))
923 bwipe!
924
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100925 " Test deleting the last line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100926 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200927 let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100928 call assert_equal([expect3], prop_list(3))
Martin Tournoije2390c72021-07-28 13:30:16 +0200929 let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100930 call assert_equal([expect4], prop_list(4))
931 4del
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100932 let expect3.end = 1
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100933 call assert_equal([expect3], prop_list(3))
934 call assert_equal([expect_short], prop_list(4))
935 bwipe!
936
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100937 " Test appending a line below the multi-line text prop start.
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100938 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200939 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100940 call assert_equal([expect2], prop_list(2))
941 call append(2, "new line")
942 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200943 let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100944 call assert_equal([expect3], prop_list(3))
945 bwipe!
946
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100947 call prop_type_delete('comment')
948endfunc
949
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100950func Run_test_with_line2byte(add_props)
951 new
952 setlocal ff=unix
953 if a:add_props
954 call prop_type_add('textprop', #{highlight: 'Search'})
955 endif
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100956 " Add a text prop to every fourth line and then change every fifth line so
957 " that it causes a data block split a few times.
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100958 for nr in range(1, 1000)
959 call setline(nr, 'some longer text here')
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100960 if a:add_props && nr % 4 == 0
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100961 call prop_add(nr, 13, #{type: 'textprop', length: 4})
962 endif
963 endfor
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100964 let expected = 22 * 997 + 1
965 call assert_equal(expected, line2byte(998))
966
967 for nr in range(1, 1000, 5)
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100968 exe nr .. "s/longer/much more/"
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100969 let expected += 3
970 call assert_equal(expected, line2byte(998), 'line ' .. nr)
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100971 endfor
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100972
973 if a:add_props
974 call prop_type_delete('textprop')
975 endif
976 bwipe!
977endfunc
978
Bram Moolenaar9df53b62020-01-13 20:40:51 +0100979func Test_prop_line2byte()
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100980 call prop_type_add('comment', {'highlight': 'Directory'})
981 new
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100982 call setline(1, ['line1', 'second line', ''])
Bram Moolenaar8cf734e2018-12-26 01:09:00 +0100983 set ff=unix
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100984 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100985 call prop_add(1, 1, {'end_col': 3, 'type': 'comment'})
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100986 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100987 bwipe!
Bram Moolenaar14c75302021-08-15 14:28:40 +0200988
989 new
Bram Moolenaara401bba2021-08-15 15:04:41 +0200990 setlocal ff=unix
Bram Moolenaar14c75302021-08-15 14:28:40 +0200991 call setline(1, range(500))
992 call assert_equal(1491, line2byte(401))
993 call prop_add(2, 1, {'type': 'comment'})
994 call prop_add(222, 1, {'type': 'comment'})
995 call assert_equal(1491, line2byte(401))
996 call prop_remove({'type': 'comment'})
997 call assert_equal(1491, line2byte(401))
998 bwipe!
999
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +02001000 new
Bram Moolenaar49b93042021-08-25 17:02:00 +02001001 setlocal ff=unix
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +02001002 call setline(1, range(520))
1003 call assert_equal(1491, line2byte(401))
1004 call prop_add(2, 1, {'type': 'comment'})
1005 call assert_equal(1491, line2byte(401))
1006 2delete
1007 call assert_equal(1489, line2byte(400))
1008 bwipe!
1009
Bram Moolenaarcf85d972022-08-08 14:59:47 +01001010 " Add many lines so that the data block is split.
1011 " With and without props should give the same result.
1012 call Run_test_with_line2byte(0)
1013 call Run_test_with_line2byte(1)
1014
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01001015 call prop_type_delete('comment')
1016endfunc
1017
Bram Moolenaar9df53b62020-01-13 20:40:51 +01001018func Test_prop_byte2line()
1019 new
1020 set ff=unix
1021 call setline(1, ['one one', 'two two', 'three three', 'four four', 'five'])
1022 call assert_equal(4, byte2line(line2byte(4)))
1023 call assert_equal(5, byte2line(line2byte(5)))
1024
1025 call prop_type_add('prop', {'highlight': 'Directory'})
1026 call prop_add(3, 1, {'length': 5, 'type': 'prop'})
1027 call assert_equal(4, byte2line(line2byte(4)))
1028 call assert_equal(5, byte2line(line2byte(5)))
1029
1030 bwipe!
1031 call prop_type_delete('prop')
1032endfunc
1033
Bram Moolenaar59ff6402021-01-30 17:16:28 +01001034func Test_prop_goto_byte()
1035 new
1036 call setline(1, '')
1037 call setline(2, 'two three')
1038 call setline(3, '')
1039 call setline(4, 'four five')
1040
1041 call prop_type_add('testprop', {'highlight': 'Directory'})
1042 call search('^two')
1043 call prop_add(line('.'), col('.'), {
1044 \ 'length': len('two'),
1045 \ 'type': 'testprop'
1046 \ })
1047
1048 call search('two \zsthree')
1049 let expected_pos = line2byte(line('.')) + col('.') - 1
1050 exe expected_pos .. 'goto'
1051 let actual_pos = line2byte(line('.')) + col('.') - 1
1052 eval actual_pos->assert_equal(expected_pos)
1053
1054 call search('four \zsfive')
1055 let expected_pos = line2byte(line('.')) + col('.') - 1
1056 exe expected_pos .. 'goto'
1057 let actual_pos = line2byte(line('.')) + col('.') - 1
1058 eval actual_pos->assert_equal(expected_pos)
1059
1060 call prop_type_delete('testprop')
1061 bwipe!
1062endfunc
1063
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001064func Test_prop_undo()
1065 new
1066 call prop_type_add('comment', {'highlight': 'Directory'})
1067 call setline(1, ['oneone', 'twotwo', 'three'])
1068 " Set 'undolevels' to break changes into undo-able pieces.
1069 set ul&
1070
1071 call prop_add(1, 3, {'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001072 let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}]
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001073 call assert_equal(expected, prop_list(1))
1074
1075 " Insert a character, then undo.
1076 exe "normal 0lllix\<Esc>"
1077 set ul&
1078 let expected[0].length = 3
1079 call assert_equal(expected, prop_list(1))
1080 undo
1081 let expected[0].length = 2
1082 call assert_equal(expected, prop_list(1))
1083
1084 " Delete a character, then undo
1085 exe "normal 0lllx"
1086 set ul&
1087 let expected[0].length = 1
1088 call assert_equal(expected, prop_list(1))
1089 undo
1090 let expected[0].length = 2
1091 call assert_equal(expected, prop_list(1))
1092
1093 " Delete the line, then undo
1094 1d
1095 set ul&
1096 call assert_equal([], prop_list(1))
1097 undo
1098 call assert_equal(expected, prop_list(1))
1099
1100 " Insert a character, delete two characters, then undo with "U"
1101 exe "normal 0lllix\<Esc>"
1102 set ul&
1103 let expected[0].length = 3
1104 call assert_equal(expected, prop_list(1))
1105 exe "normal 0lllxx"
1106 set ul&
1107 let expected[0].length = 1
1108 call assert_equal(expected, prop_list(1))
1109 normal U
1110 let expected[0].length = 2
1111 call assert_equal(expected, prop_list(1))
1112
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001113 " substitute a word, then undo
1114 call setline(1, 'the number 123 is highlighted.')
1115 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001116 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001117 call assert_equal(expected, prop_list(1))
1118 set ul&
1119 1s/number/foo
1120 let expected[0].col = 9
1121 call assert_equal(expected, prop_list(1))
1122 undo
1123 let expected[0].col = 12
1124 call assert_equal(expected, prop_list(1))
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001125 call prop_clear(1)
1126
1127 " substitute with backslash
1128 call setline(1, 'the number 123 is highlighted.')
1129 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001130 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001131 call assert_equal(expected, prop_list(1))
1132 1s/the/\The
1133 call assert_equal(expected, prop_list(1))
1134 1s/^/\\
1135 let expected[0].col += 1
1136 call assert_equal(expected, prop_list(1))
1137 1s/^/\~
1138 let expected[0].col += 1
1139 call assert_equal(expected, prop_list(1))
1140 1s/123/12\\3
1141 let expected[0].length += 1
1142 call assert_equal(expected, prop_list(1))
1143 call prop_clear(1)
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001144
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001145 bwipe!
1146 call prop_type_delete('comment')
1147endfunc
1148
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001149func Test_prop_delete_text()
1150 new
1151 call prop_type_add('comment', {'highlight': 'Directory'})
1152 call setline(1, ['oneone', 'twotwo', 'three'])
1153
1154 " zero length property
1155 call prop_add(1, 3, {'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001156 let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001157 call assert_equal(expected, prop_list(1))
1158
1159 " delete one char moves the property
1160 normal! x
Martin Tournoije2390c72021-07-28 13:30:16 +02001161 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001162 call assert_equal(expected, prop_list(1))
1163
1164 " delete char of the property has no effect
1165 normal! lx
Martin Tournoije2390c72021-07-28 13:30:16 +02001166 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001167 call assert_equal(expected, prop_list(1))
1168
1169 " delete more chars moves property to first column, is not deleted
1170 normal! 0xxxx
Martin Tournoije2390c72021-07-28 13:30:16 +02001171 let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001172 call assert_equal(expected, prop_list(1))
1173
1174 bwipe!
1175 call prop_type_delete('comment')
1176endfunc
1177
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001178" screenshot test with textprop highlighting
Bram Moolenaar8055d172019-05-17 22:57:26 +02001179func Test_textprop_screenshot_various()
Bram Moolenaar34390282019-10-16 14:38:26 +02001180 CheckScreendump
Bram Moolenaared79d1e2019-02-22 14:38:58 +01001181 " The Vim running in the terminal needs to use utf-8.
Bram Moolenaar34390282019-10-16 14:38:26 +02001182 if g:orig_encoding != 'utf-8'
1183 throw 'Skipped: not using utf-8'
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001184 endif
1185 call writefile([
Bram Moolenaarde24a872019-05-05 15:48:00 +02001186 \ "call setline(1, ["
1187 \ .. "'One two',"
1188 \ .. "'Numbรฉr 123 รคnd thล“n 4ยพ7.',"
1189 \ .. "'--aa--bb--cc--dd--',"
1190 \ .. "'// comment with error in it',"
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001191 \ .. "'first line',"
1192 \ .. "' second line ',"
1193 \ .. "'third line',"
1194 \ .. "' fourth line',"
Bram Moolenaarde24a872019-05-05 15:48:00 +02001195 \ .. "])",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001196 \ "hi NumberProp ctermfg=blue",
1197 \ "hi LongProp ctermbg=yellow",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001198 \ "hi BackgroundProp ctermbg=lightgrey",
1199 \ "hi UnderlineProp cterm=underline",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001200 \ "call prop_type_add('number', {'highlight': 'NumberProp'})",
Bram Moolenaara5a78822019-09-04 21:57:18 +02001201 \ "call prop_type_add('long', {'highlight': 'NumberProp'})",
1202 \ "call prop_type_change('long', {'highlight': 'LongProp'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001203 \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})",
1204 \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})",
1205 \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001206 \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})",
1207 \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})",
1208 \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})",
Bram Moolenaar58e32ab2019-11-12 22:44:22 +01001209 \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001210 \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001211 \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
1212 \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001213 \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})",
1214 \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})",
1215 \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})",
1216 \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001217 \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})",
1218 \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001219 \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001220 \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})",
1221 \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})",
1222 \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})",
1223 \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})",
Bram Moolenaarbfd45122019-05-17 13:05:07 +02001224 \ "set number cursorline",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001225 \ "hi clear SpellBad",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001226 \ "set spell",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001227 \ "syn match Comment '//.*'",
1228 \ "hi Comment ctermfg=green",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001229 \ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>",
Bram Moolenaar33c8ca92019-01-02 18:00:27 +01001230 \ "normal 3G0lli\<BS>\<Esc>",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001231 \ "normal 6G0i\<BS>\<Esc>",
1232 \ "normal 3J",
1233 \ "normal 3G",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001234 \], 'XtestProp')
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001235 let buf = RunVimInTerminal('-S XtestProp', {'rows': 8})
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001236 call VerifyScreenDump(buf, 'Test_textprop_01', {})
Bram Moolenaare3d31b02018-12-24 23:07:04 +01001237
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001238 " clean up
1239 call StopVimInTerminal(buf)
Bram Moolenaar2f21fa82018-12-31 20:05:56 +01001240 call delete('XtestProp')
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001241endfunc
Bram Moolenaar8055d172019-05-17 22:57:26 +02001242
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001243func Test_textprop_hl_override()
1244 CheckScreendump
1245
1246 let lines =<< trim END
1247 call setline(1, ['One one one one one', 'Two two two two two', 'Three three three three'])
1248 hi OverProp ctermfg=blue ctermbg=yellow
1249 hi CursorLine cterm=bold,underline ctermfg=red ctermbg=green
1250 hi Vsual ctermfg=cyan ctermbg=grey
1251 call prop_type_add('under', #{highlight: 'OverProp'})
1252 call prop_type_add('over', #{highlight: 'OverProp', override: 1})
1253 call prop_add(1, 5, #{type: 'under', length: 4})
1254 call prop_add(1, 13, #{type: 'over', length: 4})
1255 call prop_add(2, 5, #{type: 'under', length: 4})
1256 call prop_add(2, 13, #{type: 'over', length: 4})
1257 call prop_add(3, 5, #{type: 'under', length: 4})
1258 call prop_add(3, 13, #{type: 'over', length: 4})
1259 set cursorline
1260 2
1261 END
1262 call writefile(lines, 'XtestOverProp')
1263 let buf = RunVimInTerminal('-S XtestOverProp', {'rows': 8})
1264 call VerifyScreenDump(buf, 'Test_textprop_hl_override_1', {})
1265
1266 call term_sendkeys(buf, "3Gllv$hh")
1267 call VerifyScreenDump(buf, 'Test_textprop_hl_override_2', {})
1268 call term_sendkeys(buf, "\<Esc>")
1269
1270 " clean up
1271 call StopVimInTerminal(buf)
1272 call delete('XtestOverProp')
1273endfunc
1274
Bram Moolenaar8055d172019-05-17 22:57:26 +02001275func RunTestVisualBlock(width, dump)
1276 call writefile([
1277 \ "call setline(1, ["
1278 \ .. "'xxxxxxxxx 123 x',"
1279 \ .. "'xxxxxxxx 123 x',"
1280 \ .. "'xxxxxxx 123 x',"
1281 \ .. "'xxxxxx 123 x',"
1282 \ .. "'xxxxx 123 x',"
1283 \ .. "'xxxx 123 xx',"
1284 \ .. "'xxx 123 xxx',"
1285 \ .. "'xx 123 xxxx',"
1286 \ .. "'x 123 xxxxx',"
1287 \ .. "' 123 xxxxxx',"
1288 \ .. "])",
1289 \ "hi SearchProp ctermbg=yellow",
1290 \ "call prop_type_add('search', {'highlight': 'SearchProp'})",
1291 \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})",
1292 \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})",
1293 \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})",
1294 \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})",
1295 \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})",
1296 \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})",
1297 \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})",
1298 \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})",
1299 \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})",
1300 \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})",
1301 \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx",
1302 \], 'XtestPropVis')
1303 let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12})
1304 call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {})
1305
1306 " clean up
1307 call StopVimInTerminal(buf)
1308 call delete('XtestPropVis')
1309endfunc
1310
1311" screenshot test with Visual block mode operations
1312func Test_textprop_screenshot_visual()
Bram Moolenaar34390282019-10-16 14:38:26 +02001313 CheckScreendump
Bram Moolenaar8055d172019-05-17 22:57:26 +02001314
1315 " Delete two columns while text props are three chars wide.
1316 call RunTestVisualBlock(2, '01')
1317
1318 " Same, but delete four columns
1319 call RunTestVisualBlock(4, '02')
1320endfunc
Bram Moolenaard79eef22019-05-24 20:41:55 +02001321
Bram Moolenaara956bf62019-06-19 17:34:24 +02001322func Test_textprop_after_tab()
Bram Moolenaar34390282019-10-16 14:38:26 +02001323 CheckScreendump
Bram Moolenaar37e66cf2019-06-19 18:16:10 +02001324
Bram Moolenaara956bf62019-06-19 17:34:24 +02001325 let lines =<< trim END
1326 call setline(1, [
1327 \ "\txxx",
1328 \ "x\txxx",
1329 \ ])
1330 hi SearchProp ctermbg=yellow
1331 call prop_type_add('search', {'highlight': 'SearchProp'})
1332 call prop_add(1, 2, {'length': 3, 'type': 'search'})
1333 call prop_add(2, 3, {'length': 3, 'type': 'search'})
1334 END
1335 call writefile(lines, 'XtestPropTab')
1336 let buf = RunVimInTerminal('-S XtestPropTab', {'rows': 6})
1337 call VerifyScreenDump(buf, 'Test_textprop_tab', {})
1338
1339 " clean up
1340 call StopVimInTerminal(buf)
1341 call delete('XtestPropTab')
1342endfunc
1343
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001344func Test_textprop_nowrap_scrolled()
1345 CheckScreendump
1346
1347 let lines =<< trim END
1348 vim9script
1349 set nowrap
1350 setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns))
1351 prop_type_add('number', {'highlight': 'ErrorMsg'})
1352 prop_add(1, 12, {'length': 3, 'type': 'number'})
1353 prop_add(1, 32, {'length': 4, 'type': 'number'})
1354 feedkeys('gg20zl', 'nxt')
1355 END
1356 call writefile(lines, 'XtestNowrap')
1357 let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6})
1358 call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {})
1359
1360 call term_sendkeys(buf, "$")
1361 call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {})
1362
1363 " clean up
1364 call StopVimInTerminal(buf)
1365 call delete('XtestNowrap')
1366endfunc
1367
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001368func Test_textprop_text_priority()
1369 CheckScreendump
1370
1371 let lines =<< trim END
1372 call setline(1, "function( call, argument, here )")
1373
1374 call prop_type_add('one', #{highlight: 'Error'})
1375 call prop_type_add('two', #{highlight: 'Function'})
1376 call prop_type_add('three', #{highlight: 'DiffChange'})
1377 call prop_type_add('arg', #{highlight: 'Search'})
1378
1379 call prop_add(1, 27, #{type: 'arg', length: len('here')})
1380 call prop_add(1, 27, #{type: 'three', text: 'three: '})
1381 call prop_add(1, 11, #{type: 'one', text: 'one: '})
1382 call prop_add(1, 11, #{type: 'arg', length: len('call')})
1383 call prop_add(1, 17, #{type: 'two', text: 'two: '})
1384 call prop_add(1, 17, #{type: 'arg', length: len('argument')})
1385 END
1386 call writefile(lines, 'XtestPropPrio')
1387 let buf = RunVimInTerminal('-S XtestPropPrio', {'rows': 5})
1388 call VerifyScreenDump(buf, 'Test_prop_at_same_pos', {})
1389
1390 " clean up
1391 call StopVimInTerminal(buf)
1392 call delete('XtestPropPrio')
1393endfunc
1394
Bram Moolenaar34390282019-10-16 14:38:26 +02001395func Test_textprop_with_syntax()
1396 CheckScreendump
1397
1398 let lines =<< trim END
1399 call setline(1, [
1400 \ "(abc)",
1401 \ ])
1402 syn match csParens "[()]" display
1403 hi! link csParens MatchParen
1404
1405 call prop_type_add('TPTitle', #{ highlight: 'Title' })
1406 call prop_add(1, 2, #{type: 'TPTitle', end_col: 5})
1407 END
1408 call writefile(lines, 'XtestPropSyn')
1409 let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6})
1410 call VerifyScreenDump(buf, 'Test_textprop_syn_1', {})
1411
1412 " clean up
1413 call StopVimInTerminal(buf)
1414 call delete('XtestPropSyn')
1415endfunc
1416
Bram Moolenaard79eef22019-05-24 20:41:55 +02001417" Adding a text property to a new buffer should not fail
1418func Test_textprop_empty_buffer()
1419 call prop_type_add('comment', {'highlight': 'Search'})
1420 new
1421 call prop_add(1, 1, {'type': 'comment'})
1422 close
Bram Moolenaaradfde112019-05-25 22:11:45 +02001423 call prop_type_delete('comment')
1424endfunc
1425
Bram Moolenaard74af422019-06-28 21:38:00 +02001426" Adding a text property with invalid highlight should be ignored.
1427func Test_textprop_invalid_highlight()
1428 call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:')
1429 new
Ben Jacksona7704222022-08-20 20:54:51 +01001430 call setline(1, ['asdf', 'asdf'])
Bram Moolenaard74af422019-06-28 21:38:00 +02001431 call prop_add(1, 1, {'length': 4, 'type': 'dni'})
1432 redraw
1433 bwipe!
1434 call prop_type_delete('dni')
1435endfunc
1436
Bram Moolenaaradfde112019-05-25 22:11:45 +02001437" Adding a text property to an empty buffer and then editing another
1438func Test_textprop_empty_buffer_next()
1439 call prop_type_add("xxx", {})
1440 call prop_add(1, 1, {"type": "xxx"})
1441 next X
1442 call prop_type_delete('xxx')
Bram Moolenaard79eef22019-05-24 20:41:55 +02001443endfunc
Bram Moolenaarf0884c52019-05-24 21:22:29 +02001444
1445func Test_textprop_remove_from_buf()
1446 new
1447 let buf = bufnr('')
1448 call prop_type_add('one', {'bufnr': buf})
1449 call prop_add(1, 1, {'type': 'one', 'id': 234})
1450 file x
1451 edit y
1452 call prop_remove({'id': 234, 'bufnr': buf}, 1)
1453 call prop_type_delete('one', {'bufnr': buf})
1454 bwipe! x
1455 close
1456endfunc
Bram Moolenaar45311b52019-08-13 22:27:32 +02001457
1458func Test_textprop_in_unloaded_buf()
1459 edit Xaaa
1460 call setline(1, 'aaa')
1461 write
1462 edit Xbbb
1463 call setline(1, 'bbb')
1464 write
1465 let bnr = bufnr('')
1466 edit Xaaa
1467
1468 call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'})
1469 call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:')
1470 exe 'buf ' .. bnr
1471 call assert_equal('bbb', getline(1))
1472 call assert_equal(0, prop_list(1)->len())
1473
1474 bwipe! Xaaa
1475 bwipe! Xbbb
1476 cal delete('Xaaa')
1477 cal delete('Xbbb')
1478endfunc
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001479
1480func Test_proptype_substitute2()
1481 new
1482 " text_prop.vim
1483 call setline(1, [
1484 \ 'The num 123 is smaller than 4567.',
1485 \ '123 The number 123 is smaller than 4567.',
1486 \ '123 The number 123 is smaller than 4567.'])
1487
1488 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1489
1490 call prop_add(1, 12, {'length': 3, 'type': 'number'})
1491 call prop_add(2, 1, {'length': 3, 'type': 'number'})
1492 call prop_add(3, 36, {'length': 4, 'type': 'number'})
1493 set ul&
Martin Tournoije2390c72021-07-28 13:30:16 +02001494 let expected = [
1495 \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1},
1496 \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1},
1497 \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}]
1498
1499 " TODO
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001500 if 0
1501 " Add some text in between
1502 %s/\s\+/ /g
1503 call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001504
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001505 " remove some text
1506 :1s/[a-z]\{3\}//g
1507 let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
1508 call assert_equal(expected, prop_list(1))
1509 endif
1510
1511 call prop_type_delete('number')
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001512 bwipe!
1513endfunc
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001514
Bram Moolenaar8902b312020-09-20 21:04:35 +02001515" This was causing property corruption.
1516func Test_proptype_substitute3()
1517 new
1518 call setline(1, ['abcxxx', 'def'])
1519 call prop_type_add("test", {"highlight": "Search"})
1520 call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"})
1521 %s/x\+$//
1522 redraw
1523
1524 call prop_type_delete('test')
1525 bwipe!
1526endfunc
1527
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001528func Test_proptype_substitute_join()
1529 new
1530 call setline(1, [
1531 \ 'This is some end',
1532 \ 'start is highlighted end',
1533 \ 'some is highlighted',
1534 \ 'start is also highlighted'])
1535
1536 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1537
1538 call prop_add(1, 6, {'length': 2, 'type': 'number'})
1539 call prop_add(2, 7, {'length': 2, 'type': 'number'})
1540 call prop_add(3, 6, {'length': 2, 'type': 'number'})
1541 call prop_add(4, 7, {'length': 2, 'type': 'number'})
1542 " The highlighted "is" in line 1, 2 and 4 is kept and ajudsted.
1543 " The highlighted "is" in line 3 is deleted.
1544 let expected = [
1545 \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1},
1546 \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1},
1547 \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}]
1548
1549 s/end\nstart/joined/
1550 s/end\n.*\nstart/joined/
1551 call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1))
1552 call assert_equal(expected, prop_list(1))
1553
1554 call prop_type_delete('number')
1555 bwipe!
1556endfunc
1557
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001558func SaveOptions()
1559 let d = #{tabstop: &tabstop,
1560 \ softtabstop: &softtabstop,
1561 \ shiftwidth: &shiftwidth,
1562 \ expandtab: &expandtab,
1563 \ foldmethod: '"' .. &foldmethod .. '"',
1564 \ }
1565 return d
1566endfunc
1567
1568func RestoreOptions(dict)
1569 for name in keys(a:dict)
1570 exe 'let &' .. name .. ' = ' .. a:dict[name]
1571 endfor
1572endfunc
1573
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001574func Test_textprop_noexpandtab()
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001575 new
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001576 let save_dict = SaveOptions()
1577
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001578 set tabstop=8
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001579 set softtabstop=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001580 set shiftwidth=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001581 set noexpandtab
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001582 set foldmethod=marker
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001583
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001584 call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx")
1585 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1586 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1587 call feedkeys("0i\<tab>", "tx")
1588 call prop_remove({'type': 'test'})
1589 call prop_add(1, 2, {'end_col': 3, 'type': 'test'})
1590 call feedkeys("A\<left>\<tab>", "tx")
1591 call prop_remove({'type': 'test'})
1592 try
1593 " It is correct that this does not pass
1594 call prop_add(1, 6, {'end_col': 7, 'type': 'test'})
1595 " Has already collapsed here, start_col:6 does not result in an error
1596 call feedkeys("A\<left>\<tab>", "tx")
1597 catch /^Vim\%((\a\+)\)\=:E964/
1598 endtry
1599 call prop_remove({'type': 'test'})
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001600 call prop_type_delete('test')
1601
1602 call RestoreOptions(save_dict)
1603 bwipe!
1604endfunc
1605
1606func Test_textprop_noexpandtab_redraw()
1607 new
1608 let save_dict = SaveOptions()
1609
1610 set tabstop=8
1611 set softtabstop=4
1612 set shiftwidth=4
1613 set noexpandtab
1614 set foldmethod=marker
1615
1616 call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx")
1617 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1618 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1619 call feedkeys("0i\<tab>", "tx")
1620 " Internally broken at the next line
1621 call feedkeys("A\<left>\<tab>", "tx")
1622 redraw
1623 " Index calculation failed internally on next line
1624 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1625 call prop_remove({'type': 'test', 'all': v:true})
1626 call prop_type_delete('test')
1627 call prop_type_delete('test')
1628
1629 call RestoreOptions(save_dict)
1630 bwipe!
1631endfunc
1632
1633func Test_textprop_ins_str()
1634 new
1635 call setline(1, 'just some text')
1636 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1637 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001638 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 +01001639
1640 call feedkeys("foi\<F8>\<Esc>", "tx")
1641 call assert_equal('just s<F8>ome text', getline(1))
Martin Tournoije2390c72021-07-28 13:30:16 +02001642 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 +01001643
1644 bwipe!
1645 call prop_remove({'type': 'test'})
1646 call prop_type_delete('test')
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001647endfunc
Bram Moolenaar66b98852020-03-11 19:15:52 +01001648
1649func Test_find_prop_later_in_line()
1650 new
1651 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1652 call setline(1, 'just some text')
1653 call prop_add(1, 1, {'length': 4, 'type': 'test'})
1654 call prop_add(1, 10, {'length': 3, 'type': 'test'})
1655
Martin Tournoije2390c72021-07-28 13:30:16 +02001656 call assert_equal(
1657 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1},
1658 \ prop_find(#{type: 'test', lnum: 1, col: 6}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001659
1660 bwipe!
1661 call prop_type_delete('test')
1662endfunc
1663
1664func Test_find_zerowidth_prop_sol()
1665 new
1666 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1667 call setline(1, 'just some text')
1668 call prop_add(1, 1, {'length': 0, 'type': 'test'})
1669
Martin Tournoije2390c72021-07-28 13:30:16 +02001670 call assert_equal(
1671 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1},
1672 \ prop_find(#{type: 'test', lnum: 1}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001673
1674 bwipe!
1675 call prop_type_delete('test')
1676endfunc
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001677
1678" Test for passing invalid arguments to prop_xxx() functions
1679func Test_prop_func_invalid_args()
1680 call assert_fails('call prop_clear(1, 2, [])', 'E715:')
1681 call assert_fails('call prop_clear(-1, 2)', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001682 call assert_fails('call prop_find(test_null_dict())', 'E1297:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001683 call assert_fails('call prop_find({"bufnr" : []})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001684 call assert_fails('call prop_find({})', 'E968:')
1685 call assert_fails('call prop_find({}, "x")', 'E474:')
1686 call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001687 call assert_fails('call prop_list(1, [])', 'E1206:')
Bram Moolenaar9d489562020-07-30 20:08:50 +02001688 call assert_fails('call prop_list(-1, {})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001689 call assert_fails('call prop_remove([])', 'E1206:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001690 call assert_fails('call prop_remove({}, -2)', 'E16:')
1691 call assert_fails('call prop_remove({})', 'E968:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001692 call assert_fails('call prop_type_add([], {})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001693 call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001694 call assert_fails("call prop_type_delete([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001695 call assert_fails("call prop_type_delete('xyz', [])", 'E715:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001696 call assert_fails("call prop_type_get([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001697 call assert_fails("call prop_type_get('', [])", 'E474:')
1698 call assert_fails("call prop_type_list([])", 'E715:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001699 call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:')
1700 call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:')
1701 call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001702 call assert_fails('call prop_add(1, 1, 0)', 'E1206:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001703
1704 new
1705 call setline(1, ['first', 'second'])
1706 call prop_type_add('xxx', {})
1707
1708 call assert_fails("call prop_type_add('xxx', {})", 'E969:')
1709 call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:')
1710 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:')
1711 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:')
1712 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:')
1713 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:')
1714 call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:')
1715
1716 call prop_type_delete('xxx')
1717 bwipe!
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001718endfunc
1719
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001720func Test_prop_split_join()
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001721 new
1722 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1723 call setline(1, 'just some text')
1724 call prop_add(1, 6, {'length': 4, 'type': 'test'})
1725
1726 " Split in middle of "some"
1727 execute "normal! 8|i\<CR>"
Martin Tournoije2390c72021-07-28 13:30:16 +02001728 call assert_equal(
1729 \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}],
1730 \ prop_list(1))
1731 call assert_equal(
1732 \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}],
1733 \ prop_list(2))
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001734
1735 " Join the two lines back together
1736 normal! 1GJ
Martin Tournoije2390c72021-07-28 13:30:16 +02001737 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 +02001738
1739 bwipe!
1740 call prop_type_delete('test')
1741endfunc
1742
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001743func Test_prop_increment_decrement()
1744 new
1745 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1746 call setline(1, 'its 998 times')
1747 call prop_add(1, 5, {'length': 3, 'type': 'test'})
1748
1749 exe "normal! 0f9\<C-A>"
1750 eval getline(1)->assert_equal('its 999 times')
1751 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001752 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001753
1754 exe "normal! 0f9\<C-A>"
1755 eval getline(1)->assert_equal('its 1000 times')
1756 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001757 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001758
1759 bwipe!
1760 call prop_type_delete('test')
1761endfunc
1762
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001763func Test_prop_block_insert()
1764 new
1765 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1766 call setline(1, ['one ', 'two '])
1767 call prop_add(1, 1, {'length': 3, 'type': 'test'})
1768 call prop_add(2, 1, {'length': 3, 'type': 'test'})
1769
1770 " insert "xx" in the first column of both lines
1771 exe "normal! gg0\<C-V>jIxx\<Esc>"
1772 eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
Martin Tournoije2390c72021-07-28 13:30:16 +02001773 let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001774 eval prop_list(1)->assert_equal(expected)
1775 eval prop_list(2)->assert_equal(expected)
1776
1777 " insert "yy" inside the text props to make them longer
1778 exe "normal! gg03l\<C-V>jIyy\<Esc>"
1779 eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo '])
1780 let expected[0].length = 5
1781 eval prop_list(1)->assert_equal(expected)
1782 eval prop_list(2)->assert_equal(expected)
1783
1784 " insert "zz" after the text props, text props don't change
1785 exe "normal! gg07l\<C-V>jIzz\<Esc>"
1786 eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz '])
1787 eval prop_list(1)->assert_equal(expected)
1788 eval prop_list(2)->assert_equal(expected)
1789
1790 bwipe!
1791 call prop_type_delete('test')
1792endfunc
1793
Bram Moolenaar23999d72020-12-23 14:36:00 +01001794" this was causing an ml_get error because w_botline was wrong
1795func Test_prop_one_line_window()
1796 enew
1797 call range(2)->setline(1)
1798 call prop_type_add('testprop', {})
1799 call prop_add(1, 1, {'type': 'testprop'})
1800 call popup_create('popup', {'textprop': 'testprop'})
1801 $
1802 new
1803 wincmd _
1804 call feedkeys("\r", 'xt')
1805 redraw
1806
1807 call popup_clear()
1808 call prop_type_delete('testprop')
1809 close
1810 bwipe!
1811endfunc
1812
Bram Moolenaarf05a1e52022-08-02 11:48:53 +01001813def Test_prop_column_zero_error()
1814 prop_type_add('proptype', {highlight: 'Search'})
1815 var caught = false
1816 try
1817 popup_create([{
1818 text: 'a',
1819 props: [{col: 0, length: 1, type: 'type'}],
1820 }], {})
1821 catch /E964:/
1822 caught = true
1823 endtry
1824 assert_true(caught)
1825
1826 popup_clear()
1827 prop_type_delete('proptype')
1828enddef
1829
Bram Moolenaar840f91f2021-05-26 22:32:10 +02001830" This was calling ml_append_int() and copy a text property from a previous
1831" line at the wrong moment. Exact text length matters.
1832def Test_prop_splits_data_block()
1833 new
1834 var lines: list<string> = [repeat('x', 35)]->repeat(41)
1835 + [repeat('!', 35)]
1836 + [repeat('x', 35)]->repeat(56)
1837 lines->setline(1)
1838 prop_type_add('someprop', {highlight: 'ErrorMsg'})
1839 prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'})
1840 prop_remove({type: 'someprop'}, 1)
1841 prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'})
1842 prop_remove({type: 'someprop'}, 35, 43)
1843 assert_equal([], prop_list(42))
1844
1845 bwipe!
1846 prop_type_delete('someprop')
1847enddef
1848
Bram Moolenaar4cd5c522021-06-27 13:04:00 +02001849" This was calling ml_delete_int() and try to change text properties.
1850def Test_prop_add_delete_line()
1851 new
1852 var a = 10
1853 var b = 20
1854 repeat([''], a)->append('$')
1855 prop_type_add('Test', {highlight: 'ErrorMsg'})
1856 for lnum in range(1, a)
1857 for col in range(1, b)
1858 prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'})
1859 endfor
1860 endfor
1861
1862 # check deleting lines is OK
1863 :5del
1864 :1del
1865 :$del
1866
1867 prop_type_delete('Test')
1868 bwipe!
1869enddef
1870
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001871" This test is to detect a regression related to #10430. It is not an attempt
1872" fully cover deleting lines in the presence of multi-line properties.
1873def Test_delete_line_within_multiline_prop()
1874 new
1875 setline(1, '# Top.')
1876 append(1, ['some_text = """', 'A string.', '"""', '# Bottom.'])
1877 prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1878 prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1879 prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9})
1880 prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4})
1881
1882 # The property for line 3 should extend into the previous and next lines.
1883 var props = prop_list(3)
1884 var prop = props[0]
1885 assert_equal(1, len(props))
1886 assert_equal(0, prop['start'])
1887 assert_equal(0, prop['end'])
1888
1889 # This deletion should run without raising an exception.
1890 try
1891 :2 del
1892 catch
1893 assert_report('Line delete should have workd, but it raised an error.')
1894 endtry
1895
1896 # The property for line 2 (was 3) should no longer extend into the previous
1897 # line.
1898 props = prop_list(2)
1899 prop = props[0]
1900 assert_equal(1, len(props))
1901 assert_equal(1, prop['start'], 'Property was not changed to start within the line.')
1902
1903 # This deletion should run without raising an exception.
1904 try
1905 :3 del
1906 catch
1907 assert_report('Line delete should have workd, but it raised an error.')
1908 endtry
1909
1910 # The property for line 2 (originally 3) should no longer extend into the next
1911 # line.
1912 props = prop_list(2)
1913 prop = props[0]
1914 assert_equal(1, len(props))
1915 assert_equal(1, prop['end'], 'Property was not changed to end within the line.')
1916
1917 prop_type_delete('Identifier')
1918 prop_type_delete('String')
1919 bwip!
1920enddef
1921
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001922func Test_prop_in_linebreak()
1923 CheckRunVimInTerminal
1924
1925 let lines =<< trim END
1926 set breakindent linebreak breakat+=]
1927 call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1)
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001928 call prop_type_add('test', #{highlight: 'MatchParen'})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001929 call prop_add(1, 51, #{length: 1, type: 'test'})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001930 func AddMatch()
1931 syntax on
1932 syntax match xTest /.*/
1933 hi link xTest Comment
1934 set signcolumn=yes
1935 endfunc
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001936 END
1937 call writefile(lines, 'XscriptPropLinebreak')
1938 let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001939 call VerifyScreenDump(buf, 'Test_prop_linebreak_1', {})
1940
1941 call term_sendkeys(buf, ":call AddMatch()\<CR>")
1942 call VerifyScreenDump(buf, 'Test_prop_linebreak_2', {})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001943
1944 call StopVimInTerminal(buf)
1945 call delete('XscriptPropLinebreak')
1946endfunc
1947
Bram Moolenaar52de3a82022-08-10 13:12:03 +01001948func Test_prop_with_linebreak()
1949 CheckRunVimInTerminal
1950
1951 let lines =<< trim END
1952 vim9script
1953 set linebreak
1954 setline(1, 'one twoword')
1955 prop_type_add('test', {highlight: 'Special'})
1956 prop_add(1, 4, {text: ': virtual text', type: 'test', text_wrap: 'wrap'})
1957 END
1958 call writefile(lines, 'XscriptPropWithLinebreak')
1959 let buf = RunVimInTerminal('-S XscriptPropWithLinebreak', #{rows: 6, cols: 50})
1960 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_1', {})
1961 call term_sendkeys(buf, "iasdf asdf asdf asdf asdf as\<Esc>")
1962 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_2', {})
1963
1964 call StopVimInTerminal(buf)
1965 call delete('XscriptPropWithLinebreak')
1966endfunc
1967
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001968func Test_prop_with_wrap()
1969 CheckRunVimInTerminal
1970
1971 let lines =<< trim END
1972 vim9script
1973 set linebreak
1974 setline(1, 'asdf '->repeat(15))
1975 prop_type_add('test', {highlight: 'Special'})
1976 prop_add(1, 43, {text: 'some virtual text', type: 'test'})
1977 END
1978 call writefile(lines, 'XscriptPropWithWrap')
1979 let buf = RunVimInTerminal('-S XscriptPropWithWrap', #{rows: 6, cols: 50})
1980 call VerifyScreenDump(buf, 'Test_prop_with_wrap_1', {})
1981
1982 call StopVimInTerminal(buf)
1983 call delete('XscriptPropWithWrap')
1984endfunc
1985
Bram Moolenaar42eba042021-11-30 20:22:49 +00001986func Test_prop_after_tab()
1987 CheckRunVimInTerminal
1988
1989 let lines =<< trim END
1990 set breakindent linebreak breakat+=]
1991 call setline(1, "\t[xxx]")
1992 call prop_type_add('test', #{highlight: 'ErrorMsg'})
1993 call prop_add(1, 2, #{length: 1, type: 'test'})
1994 END
1995 call writefile(lines, 'XscriptPropAfterTab')
1996 let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10})
Bram Moolenaar42eba042021-11-30 20:22:49 +00001997 call VerifyScreenDump(buf, 'Test_prop_after_tab', {})
1998
1999 call StopVimInTerminal(buf)
2000 call delete('XscriptPropAfterTab')
2001endfunc
2002
Bram Moolenaare428fa02022-08-09 16:55:41 +01002003func Test_prop_before_tab()
2004 CheckRunVimInTerminal
2005
2006 let lines =<< trim END
2007 call setline(1, ["\tx"]->repeat(6))
2008 call prop_type_add('test', #{highlight: 'Search'})
2009 call prop_add(1, 1, #{type: 'test', text: '123'})
2010 call prop_add(2, 1, #{type: 'test', text: '1234567'})
2011 call prop_add(3, 1, #{type: 'test', text: '12345678'})
2012 call prop_add(4, 1, #{type: 'test', text: '123456789'})
2013 call prop_add(5, 2, #{type: 'test', text: 'ABC'})
2014 call prop_add(6, 3, #{type: 'test', text: 'ABC'})
2015 normal gg0
2016 END
2017 call writefile(lines, 'XscriptPropBeforeTab')
2018 let buf = RunVimInTerminal('-S XscriptPropBeforeTab', #{rows: 8})
2019 call VerifyScreenDump(buf, 'Test_prop_before_tab_01', {})
2020 call term_sendkeys(buf, "$")
2021 call VerifyScreenDump(buf, 'Test_prop_before_tab_02', {})
2022 call term_sendkeys(buf, "j0")
2023 call VerifyScreenDump(buf, 'Test_prop_before_tab_03', {})
2024 call term_sendkeys(buf, "$")
2025 call VerifyScreenDump(buf, 'Test_prop_before_tab_04', {})
2026 call term_sendkeys(buf, "j0")
2027 call VerifyScreenDump(buf, 'Test_prop_before_tab_05', {})
2028 call term_sendkeys(buf, "$")
2029 call VerifyScreenDump(buf, 'Test_prop_before_tab_06', {})
2030 call term_sendkeys(buf, "j0")
2031 call VerifyScreenDump(buf, 'Test_prop_before_tab_07', {})
2032 call term_sendkeys(buf, "$")
2033 call VerifyScreenDump(buf, 'Test_prop_before_tab_08', {})
2034 call term_sendkeys(buf, "j")
2035 call VerifyScreenDump(buf, 'Test_prop_before_tab_09', {})
2036 call term_sendkeys(buf, "j")
2037 call VerifyScreenDump(buf, 'Test_prop_before_tab_10', {})
2038
2039 call StopVimInTerminal(buf)
2040 call delete('XscriptPropBeforeTab')
2041endfunc
2042
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002043func Test_prop_after_linebreak()
2044 CheckRunVimInTerminal
2045
2046 let lines =<< trim END
2047 set linebreak wrap
2048 call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1)
2049 call prop_type_add('test', #{highlight: 'ErrorMsg'})
2050 call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'})
2051 END
2052 call writefile(lines, 'XscriptPropAfterLinebreak')
2053 let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10})
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002054 call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {})
2055
2056 call StopVimInTerminal(buf)
2057 call delete('XscriptPropAfterLinebreak')
2058endfunc
2059
Martin Tournoije2390c72021-07-28 13:30:16 +02002060" Buffer number of 0 should be ignored, as if the parameter wasn't passed.
2061def Test_prop_bufnr_zero()
2062 new
2063 try
2064 var bufnr = bufnr('')
2065 setline(1, 'hello')
2066 prop_type_add('bufnr-global', {highlight: 'ErrorMsg'})
2067 prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr})
2068
2069 prop_add(1, 1, {type: 'bufnr-global', length: 1})
2070 prop_add(1, 2, {type: 'bufnr-buffer', length: 1})
2071
2072 var list = prop_list(1)
2073 assert_equal([
2074 {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1},
2075 {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1},
2076 ], list)
2077
2078 assert_equal(
2079 {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1},
2080 prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr}))
2081
2082 assert_equal(
2083 {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1},
2084 prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr}))
2085 finally
2086 bwipe!
2087 prop_type_delete('bufnr-global')
2088 endtry
2089enddef
2090
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002091" Tests for the prop_list() function
2092func Test_prop_list()
2093 let lines =<< trim END
2094 new
Bram Moolenaar62aec932022-01-29 21:45:34 +00002095 call g:AddPropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002096 call setline(1, repeat([repeat('a', 60)], 10))
2097 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2098 call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7})
2099 call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14})
2100 call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15})
2101 call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22})
2102 call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23})
2103 call assert_equal([
2104 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2105 \ 'type': 'one', 'length': 2, 'start': 1},
2106 \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2107 \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1))
2108 #" text properties between a few lines
2109 call assert_equal([
2110 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2111 \ 'type': 'one', 'length': 2, 'start': 1},
2112 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2113 \ 'type': 'two', 'length': 2, 'start': 1},
2114 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
2115 \ 'type': 'one', 'length': 2, 'start': 1},
2116 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
2117 \ 'type': 'two', 'length': 2, 'start': 1}],
2118 \ prop_list(2, {'end_lnum': 5}))
2119 #" text properties across all the lines
2120 call assert_equal([
2121 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2122 \ 'type': 'one', 'length': 2, 'start': 1},
2123 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2124 \ 'type': 'one', 'length': 2, 'start': 1},
2125 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
2126 \ 'type': 'one', 'length': 2, 'start': 1}],
2127 \ prop_list(1, {'types': ['one'], 'end_lnum': -1}))
2128 #" text properties with the specified identifier
2129 call assert_equal([
2130 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2131 \ 'type': 'one', 'length': 2, 'start': 1},
2132 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
2133 \ 'type': 'two', 'length': 2, 'start': 1}],
2134 \ prop_list(1, {'ids': [20], 'end_lnum': 10}))
2135 #" text properties of the specified type and id
2136 call assert_equal([
2137 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2138 \ 'type': 'two', 'length': 2, 'start': 1},
2139 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2140 \ 'type': 'two', 'length': 2, 'start': 1}],
2141 \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20}))
2142 call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10}))
2143 call assert_equal([], prop_list(6, {'end_lnum': 10}))
2144 call assert_equal([], prop_list(2, {'end_lnum': 2}))
2145 #" error cases
2146 call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:')
2147 call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:')
2148 call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:')
2149 call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})",
2150 \ 'E971:')
2151 call assert_fails("echo prop_list(1, {'types': ['one', 'blue'],
2152 \ 'end_lnum': 10})", 'E971:')
2153 call assert_fails("echo prop_list(1, {'types': ['one', 10],
2154 \ 'end_lnum': 10})", 'E928:')
2155 call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:')
2156 call assert_equal([], prop_list(2, {'types': []}))
2157 call assert_equal([], prop_list(2, {'types': test_null_list()}))
2158 call assert_fails("call prop_list(1, {'types': {}})", 'E714:')
2159 call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:')
2160 call assert_equal([], prop_list(2, {'types': ['one'],
2161 \ 'ids': test_null_list()}))
2162 call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []}))
2163 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})",
2164 \ 'E714:')
2165 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})",
2166 \ 'E714:')
2167 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})",
2168 \ 'E745:')
2169 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})",
2170 \ 'E745:')
Martin Tournoije2390c72021-07-28 13:30:16 +02002171
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002172 #" get text properties from a non-current buffer
2173 wincmd w
2174 call assert_equal([
2175 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2176 \ 'type': 'one', 'length': 2, 'start': 1},
2177 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2178 \ 'type': 'two', 'length': 2, 'start': 1},
2179 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2180 \ 'type': 'one', 'length': 2, 'start': 1},
2181 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2182 \ 'type': 'two', 'length': 2, 'start': 1}],
2183 \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4}))
2184 wincmd w
2185
2186 #" get text properties after clearing all the properties
2187 call prop_clear(1, line('$'))
2188 call assert_equal([], prop_list(1, {'end_lnum': 10}))
2189
2190 call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2191 call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6})
2192 call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6})
2193 #" get text properties with a list of types
2194 call assert_equal([
2195 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2196 \ 'type': 'two', 'length': 2, 'start': 1},
2197 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2198 \ 'type': 'one', 'length': 2, 'start': 1}],
2199 \ prop_list(2, {'types': ['one', 'two']}))
2200 call assert_equal([
2201 \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1,
2202 \ 'type': 'three', 'length': 2, 'start': 1},
2203 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2204 \ 'type': 'one', 'length': 2, 'start': 1}],
2205 \ prop_list(2, {'types': ['one', 'three']}))
2206 #" get text properties with a list of identifiers
2207 call assert_equal([
2208 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2209 \ 'type': 'two', 'length': 2, 'start': 1},
2210 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2211 \ 'type': 'one', 'length': 2, 'start': 1}],
2212 \ prop_list(2, {'ids': [5, 10, 20]}))
2213 call prop_clear(1, line('$'))
2214 call assert_equal([], prop_list(2, {'types': ['one', 'two']}))
2215 call assert_equal([], prop_list(2, {'ids': [5, 10, 20]}))
2216
2217 #" get text properties from a hidden buffer
2218 edit! Xaaa
2219 call setline(1, repeat([repeat('b', 60)], 10))
2220 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2221 call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10})
2222 VAR bnr = bufnr()
2223 hide edit Xbbb
2224 call assert_equal([
2225 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2226 \ 'type': 'one', 'length': 2, 'start': 1},
2227 \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1,
2228 \ 'type': 'two', 'length': 2, 'start': 1}],
2229 \ prop_list(1, {'bufnr': bnr,
2230 \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1}))
2231 #" get text properties from an unloaded buffer
2232 bunload! Xaaa
2233 call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1}))
2234
Bram Moolenaar62aec932022-01-29 21:45:34 +00002235 call g:DeletePropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002236 :%bw!
2237 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00002238 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002239endfunc
Bram Moolenaar23999d72020-12-23 14:36:00 +01002240
LemonBoy9bd3ce22022-04-18 21:54:02 +01002241func Test_prop_find_prev_on_same_line()
2242 new
2243
2244 call setline(1, 'the quikc bronw fox jumsp over the layz dog')
2245 call prop_type_add('misspell', #{highlight: 'ErrorMsg'})
2246 for col in [8, 14, 24, 38]
2247 call prop_add(1, col, #{type: 'misspell', length: 2})
2248 endfor
2249
Ben Jacksona7704222022-08-20 20:54:51 +01002250 call cursor(1, 18)
LemonBoy9bd3ce22022-04-18 21:54:02 +01002251 let expected = [
2252 \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1},
2253 \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}
2254 \ ]
2255
2256 let result = prop_find(#{type: 'misspell'}, 'b')
2257 call assert_equal(expected[0], result)
2258 let result = prop_find(#{type: 'misspell'}, 'f')
2259 call assert_equal(expected[1], result)
2260
2261 call prop_type_delete('misspell')
2262 bwipe!
2263endfunc
2264
LemonBoyb7a70122022-05-13 12:41:50 +01002265func Test_prop_spell()
2266 new
2267 set spell
2268 call AddPropTypes()
2269
2270 call setline(1, ["helo world", "helo helo helo"])
2271 call prop_add(1, 1, #{type: 'one', length: 4})
2272 call prop_add(1, 6, #{type: 'two', length: 5})
2273 call prop_add(2, 1, #{type: 'three', length: 4})
2274 call prop_add(2, 6, #{type: 'three', length: 4})
2275 call prop_add(2, 11, #{type: 'three', length: 4})
2276
2277 " The first prop over 'helo' increases its length after the word is corrected
2278 " to 'Hello', the second one is shifted to the right.
2279 let expected = [
2280 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2281 \ 'length': 5, 'start': 1},
2282 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2283 \ 'length': 5, 'start': 1}
2284 \ ]
2285 call feedkeys("z=1\<CR>", 'xt')
2286
2287 call assert_equal('Hello world', getline(1))
2288 call assert_equal(expected, prop_list(1))
2289
2290 " Repeat the replacement done by z=
2291 spellrepall
2292
2293 let expected = [
2294 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2295 \ 'length': 5, 'start': 1},
2296 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2297 \ 'length': 5, 'start': 1},
2298 \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2299 \ 'length': 5, 'start': 1}
2300 \ ]
2301 call assert_equal('Hello Hello Hello', getline(2))
2302 call assert_equal(expected, prop_list(2))
2303
2304 call DeletePropTypes()
2305 set spell&
2306 bwipe!
2307endfunc
2308
LemonBoy4b936742022-05-13 21:56:28 +01002309func Test_prop_shift_block()
2310 new
2311 call AddPropTypes()
2312
2313 call setline(1, ['some highlighted text']->repeat(2))
2314 call prop_add(1, 10, #{type: 'one', length: 11})
2315 call prop_add(2, 10, #{type: 'two', length: 11})
2316
2317 call cursor(1, 1)
2318 call feedkeys("5l\<c-v>>", 'nxt')
2319 call cursor(2, 1)
2320 call feedkeys("5l\<c-v><", 'nxt')
2321
2322 let expected = [
2323 \ {'lnum': 1, 'id': 0, 'col': 8, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2324 \ 'length': 11, 'start' : 1},
2325 \ {'lnum': 2, 'id': 0, 'col': 6, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2326 \ 'length': 11, 'start' : 1}
2327 \ ]
2328 call assert_equal(expected, prop_list(1, #{end_lnum: 2}))
2329
2330 call DeletePropTypes()
2331 bwipe!
2332endfunc
LemonBoyb7a70122022-05-13 12:41:50 +01002333
LemonBoy698cb4c2022-05-14 18:10:15 +01002334func Test_prop_insert_multiline()
2335 new
2336 call AddPropTypes()
2337
2338 call setline(1, ['foobar', 'barbaz'])
2339 call prop_add(1, 4, #{end_lnum: 2, end_col: 4, type: 'one'})
2340
2341 call feedkeys("1Goquxqux\<Esc>", 'nxt')
2342 call feedkeys("2GOquxqux\<Esc>", 'nxt')
2343
2344 let lines =<< trim END
2345 foobar
2346 quxqux
2347 quxqux
2348 barbaz
2349 END
2350 call assert_equal(lines, getline(1, '$'))
2351 let expected = [
2352 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one',
Ben Jacksona7704222022-08-20 20:54:51 +01002353 \ 'length': 4 , 'start': 1},
LemonBoy698cb4c2022-05-14 18:10:15 +01002354 \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2355 \ 'length': 7, 'start': 0},
2356 \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2357 \ 'length': 7, 'start': 0},
2358 \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2359 \ 'length': 3, 'start': 0}
2360 \ ]
2361 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2362
2363 call DeletePropTypes()
2364 bwipe!
2365endfunc
2366
LemonBoyb559b302022-05-15 13:08:02 +01002367func Test_prop_blockwise_change()
2368 new
2369 call AddPropTypes()
2370
2371 call setline(1, ['foooooo', 'bar', 'baaaaz'])
2372 call prop_add(1, 1, #{end_col: 3, type: 'one'})
2373 call prop_add(2, 1, #{end_col: 3, type: 'two'})
2374 call prop_add(3, 1, #{end_col: 3, type: 'three'})
2375
2376 " Replace the first two columns with '123', since 'start_incl' is false the
2377 " prop is not extended.
2378 call feedkeys("gg\<c-v>2jc123\<Esc>", 'nxt')
2379
2380 let lines =<< trim END
2381 123oooooo
2382 123ar
2383 123aaaaz
2384 END
2385 call assert_equal(lines, getline(1, '$'))
2386 let expected = [
2387 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2388 \ 'length': 1, 'start': 1},
2389 \ {'lnum': 2, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2390 \ 'length': 1, 'start': 1},
2391 \ {'lnum': 3, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1 ,
2392 \ 'type': 'three', 'length': 1, 'start': 1}
2393 \ ]
2394 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2395
2396 call DeletePropTypes()
2397 bwipe!
2398endfunc
2399
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002400func Do_test_props_do_not_affect_byte_offsets(ff, increment)
2401 new
2402 let lcount = 410
2403
2404 " File format affects byte-offset calculations, so make sure it is known.
2405 exec 'setlocal fileformat=' . a:ff
2406
2407 " Fill the buffer with varying length lines. We need a suitably large number
2408 " to force Vim code through paths wehere previous error have occurred. This
2409 " is more 'art' than 'science'.
2410 let text = 'a'
2411 call setline(1, text)
2412 let offsets = [1]
2413 for idx in range(lcount)
2414 call add(offsets, offsets[idx] + len(text) + a:increment)
2415 if (idx % 6) == 0
2416 let text = text . 'a'
2417 endif
2418 call append(line('$'), text)
2419 endfor
2420
2421 " Set a property that spans a few lines to cause Vim's internal buffer code
2422 " to perform a reasonable amount of rearrangement.
2423 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2424 call prop_add(1, 1, {'type': 'one', 'end_lnum': 6, 'end_col': 2})
2425
2426 for idx in range(lcount)
2427 let boff = line2byte(idx + 1)
2428 call assert_equal(offsets[idx], boff, 'Bad byte offset at line ' . (idx + 1))
2429 endfor
2430
2431 call prop_type_delete('one')
2432 bwipe!
2433endfunc
2434
2435func Test_props_do_not_affect_byte_offsets()
2436 call Do_test_props_do_not_affect_byte_offsets('unix', 1)
2437endfunc
2438
2439func Test_props_do_not_affect_byte_offsets_dos()
2440 call Do_test_props_do_not_affect_byte_offsets('dos', 2)
2441endfunc
2442
2443func Test_props_do_not_affect_byte_offsets_editline()
2444 new
2445 let lcount = 410
2446
2447 " File format affects byte-offset calculations, so make sure it is known.
2448 setlocal fileformat=unix
2449
2450 " Fill the buffer with varying length lines. We need a suitably large number
2451 " to force Vim code through paths wehere previous error have occurred. This
2452 " is more 'art' than 'science'.
2453 let text = 'aa'
2454 call setline(1, text)
2455 let offsets = [1]
2456 for idx in range(lcount)
2457 call add(offsets, offsets[idx] + len(text) + 1)
2458 if (idx % 6) == 0
2459 let text = text . 'a'
2460 endif
2461 call append(line('$'), text)
2462 endfor
2463
2464 " Set a property that just covers the first line. When this test was
2465 " developed, this did not trigger a byte-offset error.
2466 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2467 call prop_add(1, 1, {'type': 'one', 'end_lnum': 1, 'end_col': 3})
2468
2469 for idx in range(lcount)
2470 let boff = line2byte(idx + 1)
2471 call assert_equal(offsets[idx], boff,
2472 \ 'Confounding bad byte offset at line ' . (idx + 1))
2473 endfor
2474
2475 " Insert text in the middle of the first line, keeping the property
2476 " unchanged.
2477 :1
2478 normal aHello
2479 for idx in range(1, lcount)
2480 let offsets[idx] = offsets[idx] + 5
2481 endfor
2482
2483 for idx in range(lcount)
2484 let boff = line2byte(idx + 1)
2485 call assert_equal(offsets[idx], boff,
2486 \ 'Bad byte offset at line ' . (idx + 1))
2487 endfor
2488
2489 call prop_type_delete('one')
2490 bwipe!
2491endfunc
2492
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002493func Test_prop_inserts_text()
2494 CheckRunVimInTerminal
2495
2496 " Just a basic check for now
2497 let lines =<< trim END
2498 call setline(1, 'insert some text here and other text there and some more text after wrapping')
2499 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2500 call prop_type_add('otherprop', #{highlight: 'Search'})
2501 call prop_type_add('moreprop', #{highlight: 'DiffAdd'})
2502 call prop_add(1, 18, #{type: 'someprop', text: 'SOME '})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002503 call prop_add(1, 38, #{type: 'otherprop', text: "OTHER\t"})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002504 call prop_add(1, 69, #{type: 'moreprop', text: 'MORE '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002505 normal $
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002506
2507 call setline(2, 'prepost')
2508 call prop_type_add('multibyte', #{highlight: 'Visual'})
2509 call prop_add(2, 4, #{type: 'multibyte', text: 'sรถmeๅ’Œๅนณtรฉxt'})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002510
Bram Moolenaar25463612022-08-08 11:07:47 +01002511 call setline(3, 'Foo foo = { 1, 2 };')
Bram Moolenaar3331dd02022-08-10 16:49:02 +01002512 call prop_type_add('testprop', #{highlight: 'Comment'})
Bram Moolenaar25463612022-08-08 11:07:47 +01002513 call prop_add(3, 13, #{type: 'testprop', text: '.x='})
2514 call prop_add(3, 16, #{type: 'testprop', text: '.y='})
2515
2516 call setline(4, '')
2517 call prop_add(4, 1, #{type: 'someprop', text: 'empty line'})
Bram Moolenaar3331dd02022-08-10 16:49:02 +01002518
2519 call setline(5, 'look highlight')
2520 call prop_type_add('nohi', #{})
2521 call prop_add(5, 6, #{type: 'nohi', text: 'no '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002522 END
2523 call writefile(lines, 'XscriptPropsWithText')
Bram Moolenaar25463612022-08-08 11:07:47 +01002524 let buf = RunVimInTerminal('-S XscriptPropsWithText', #{rows: 8, cols: 60})
Bram Moolenaar711483c2022-07-30 21:33:46 +01002525 call VerifyScreenDump(buf, 'Test_prop_inserts_text_1', {})
2526
2527 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2528 call VerifyScreenDump(buf, 'Test_prop_inserts_text_2', {})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002529
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002530 call term_sendkeys(buf, "2G$")
2531 call VerifyScreenDump(buf, 'Test_prop_inserts_text_3', {})
2532
Bram Moolenaar25463612022-08-08 11:07:47 +01002533 call term_sendkeys(buf, "3Gf1")
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002534 call VerifyScreenDump(buf, 'Test_prop_inserts_text_4', {})
Bram Moolenaar25463612022-08-08 11:07:47 +01002535 call term_sendkeys(buf, "f2")
2536 call VerifyScreenDump(buf, 'Test_prop_inserts_text_5', {})
2537
2538 call term_sendkeys(buf, "4G")
2539 call VerifyScreenDump(buf, 'Test_prop_inserts_text_6', {})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002540
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002541 call StopVimInTerminal(buf)
2542 call delete('XscriptPropsWithText')
2543endfunc
2544
Bram Moolenaare38fc862022-08-11 17:24:50 +01002545func Test_prop_inserts_text_highlight()
2546 CheckRunVimInTerminal
2547
2548 " Just a basic check for now
2549 let lines =<< trim END
2550 call setline(1, 'insert some text (here) and there')
2551 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2552 let bef_prop = prop_add(1, 18, #{type: 'someprop', text: 'BEFORE'})
2553 set hlsearch
2554 let thematch = matchaddpos("DiffAdd", [[1, 18]])
2555 func DoAfter()
2556 call prop_remove(#{id: g:bef_prop})
2557 call prop_add(1, 19, #{type: 'someprop', text: 'AFTER'})
2558 let g:thematch = matchaddpos("DiffAdd", [[1, 18]])
2559 let @/ = ''
2560 endfunc
2561 END
2562 call writefile(lines, 'XscriptPropsWithHighlight')
2563 let buf = RunVimInTerminal('-S XscriptPropsWithHighlight', #{rows: 6, cols: 60})
2564 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_1', {})
2565 call term_sendkeys(buf, "/text (he\<CR>")
2566 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_2', {})
2567 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2568 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_3', {})
2569
2570 call term_sendkeys(buf, ":call DoAfter()\<CR>")
2571 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_4', {})
2572 call term_sendkeys(buf, "/text (he\<CR>")
2573 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_5', {})
2574 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2575 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_6', {})
2576
2577 call StopVimInTerminal(buf)
2578 call delete('XscriptPropsWithHighlight')
2579endfunc
2580
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002581func Test_props_with_text_right_align_twice()
2582 CheckRunVimInTerminal
2583
2584 let lines =<< trim END
2585 call setline(1, ["some text some text some text some text", 'line two'])
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002586 call prop_type_add('MyErrorText', #{ highlight: 'ErrorMsg'})
2587 call prop_type_add('MyPadding', #{ highlight: 'DiffChange'})
2588 call prop_add(1, 0, #{type: 'MyPadding', text: ' nothing here', text_wrap: 'wrap'})
2589 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Some error', text_wrap: 'wrap', text_align: 'right'})
2590 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Another error', text_wrap: 'wrap', text_align: 'right'})
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002591 normal G$
2592 END
2593 call writefile(lines, 'XscriptPropsRightAlign')
2594 let buf = RunVimInTerminal('-S XscriptPropsRightAlign', #{rows: 8})
2595 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_1', {})
2596
2597 call term_sendkeys(buf, "ggisome more text\<Esc>G$")
2598 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {})
2599
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002600 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2601 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_3', {})
2602
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002603 call StopVimInTerminal(buf)
2604 call delete('XscriptPropsRightAlign')
2605endfunc
2606
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002607func Test_props_with_text_after()
2608 CheckRunVimInTerminal
2609
2610 let lines =<< trim END
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002611 set showbreak=+++
Bram Moolenaar73c38422022-08-07 11:53:40 +01002612 set breakindent
2613 call setline(1, ' some text here and other text there')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002614 call prop_type_add('rightprop', #{highlight: 'ErrorMsg'})
2615 call prop_type_add('afterprop', #{highlight: 'Search'})
2616 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
2617 call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002618 call prop_add(1, 0, #{type: 'afterprop', text: "\tAFTER\t", text_align: 'after'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002619 call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'})
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002620 call prop_add(1, 0, #{type: 'belowprop', text: ' ALSO BELOW ', text_align: 'below'})
Bram Moolenaar84b247f2022-08-01 11:17:40 +01002621
2622 call setline(2, 'Last line.')
2623 call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'})
2624 normal G$
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002625
2626 call setline(3, 'right here')
2627 call prop_add(3, 0, #{type: 'rightprop', text: 'sรถmeๅ’Œๅนณtรฉxt', text_align: 'right'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002628 END
2629 call writefile(lines, 'XscriptPropsWithTextAfter')
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002630 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002631 call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {})
2632
2633 call StopVimInTerminal(buf)
2634 call delete('XscriptPropsWithTextAfter')
Bram Moolenaar82b14c12022-08-10 19:50:47 +01002635
2636 call assert_fails('call prop_add(1, 2, #{text: "yes", text_align: "right", type: "some"})', 'E1294:')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002637endfunc
2638
Bram Moolenaarcba69522022-08-06 21:03:53 +01002639func Test_props_with_text_after_below_trunc()
2640 CheckRunVimInTerminal
2641
2642 let lines =<< trim END
2643 vim9script
2644 edit foobar
2645 set showbreak=+++
2646 setline(1, ['onasdf asdf asdf asdf asd fas df', 'two'])
2647 prop_type_add('test', {highlight: 'Special'})
2648 prop_add(1, 0, {
2649 type: 'test',
2650 text: 'the quick brown fox jumps over the lazy dog',
2651 text_align: 'after'
2652 })
2653 prop_add(1, 0, {
2654 type: 'test',
2655 text: 'the quick brown fox jumps over the lazy dog',
2656 text_align: 'below'
2657 })
2658 normal G$
2659 END
2660 call writefile(lines, 'XscriptPropsAfterTrunc')
2661 let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60})
2662 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {})
2663
2664 call StopVimInTerminal(buf)
2665 call delete('XscriptPropsAfterTrunc')
2666endfunc
2667
Bram Moolenaare175dc62022-08-01 22:18:50 +01002668func Test_props_with_text_after_joined()
2669 CheckRunVimInTerminal
2670
2671 let lines =<< trim END
2672 call setline(1, ['one', 'two', 'three', 'four'])
2673 call prop_type_add('afterprop', #{highlight: 'Search'})
2674 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'})
2675 call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'})
2676 normal ggJ
2677 normal GkJ
2678
2679 call setline(3, ['a', 'b', 'c', 'd', 'e', 'f'])
2680 call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'})
2681 call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'})
2682 call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'})
2683 call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'})
2684 normal 3G6J
2685 END
2686 call writefile(lines, 'XscriptPropsWithTextAfterJoined')
2687 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60})
2688 call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {})
2689
2690 call StopVimInTerminal(buf)
2691 call delete('XscriptPropsWithTextAfterJoined')
2692endfunc
2693
Bram Moolenaar398649e2022-08-04 15:03:48 +01002694func Test_props_with_text_after_truncated()
2695 CheckRunVimInTerminal
2696
2697 let lines =<< trim END
2698 call setline(1, ['one two three four five six seven'])
2699 call prop_type_add('afterprop', #{highlight: 'Search'})
2700 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
2701
2702 call setline(2, ['one two three four five six seven'])
2703 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
2704
2705 call setline(3, ['one two three four five six seven'])
2706 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'})
2707
2708 call setline(4, ['cursor here'])
2709 normal 4Gfh
2710 END
2711 call writefile(lines, 'XscriptPropsWithTextAfterTrunc')
2712 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60})
2713 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {})
2714
2715 call term_sendkeys(buf, ":37vsp\<CR>gg")
2716 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {})
2717
2718 call term_sendkeys(buf, ":36wincmd |\<CR>")
2719 call term_sendkeys(buf, "2G$")
2720 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {})
2721
2722 call term_sendkeys(buf, ":33wincmd |\<CR>")
2723 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {})
2724
2725 call term_sendkeys(buf, ":18wincmd |\<CR>")
2726 call term_sendkeys(buf, "0fx")
2727 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {})
2728
2729 call StopVimInTerminal(buf)
2730 call delete('XscriptPropsWithTextAfterTrunc')
2731endfunc
2732
Bram Moolenaar49a90792022-08-09 18:25:23 +01002733func Test_props_with_text_empty_line()
2734 CheckRunVimInTerminal
2735
2736 let lines =<< trim END
2737 call setline(1, ['', 'aaa', '', 'bbbbbb'])
2738 call prop_type_add('prop1', #{highlight: 'Search'})
2739 call prop_add(1, 1, #{type: 'prop1', text_wrap: 'wrap', text: repeat('X', &columns)})
2740 call prop_add(3, 1, #{type: 'prop1', text_wrap: 'wrap', text: repeat('X', &columns + 1)})
2741 normal gg0
2742 END
2743 call writefile(lines, 'XscriptPropsWithTextEmptyLine')
2744 let buf = RunVimInTerminal('-S XscriptPropsWithTextEmptyLine', #{rows: 8, cols: 60})
2745 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_1', {})
2746 call term_sendkeys(buf, "$")
2747 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_2', {})
2748 call term_sendkeys(buf, "j")
2749 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_3', {})
2750 call term_sendkeys(buf, "j")
2751 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_4', {})
2752 call term_sendkeys(buf, "j")
2753 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_5', {})
2754
2755 call StopVimInTerminal(buf)
2756 call delete('XscriptPropsWithTextEmptyLine')
2757endfunc
2758
Bram Moolenaar398649e2022-08-04 15:03:48 +01002759func Test_props_with_text_after_wraps()
2760 CheckRunVimInTerminal
2761
2762 let lines =<< trim END
2763 call setline(1, ['one two three four five six seven'])
2764 call prop_type_add('afterprop', #{highlight: 'Search'})
2765 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'})
2766
2767 call setline(2, ['one two three four five six seven'])
2768 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'})
2769
2770 call setline(3, ['one two three four five six seven'])
2771 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'})
2772
2773 call setline(4, ['cursor here'])
2774 normal 4Gfh
2775 END
2776 call writefile(lines, 'XscriptPropsWithTextAfterWraps')
2777 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60})
2778 call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {})
2779
2780 call StopVimInTerminal(buf)
2781 call delete('XscriptPropsWithTextAfterWraps')
2782endfunc
2783
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002784func Test_props_with_text_after_nowrap()
2785 CheckRunVimInTerminal
2786
2787 let lines =<< trim END
2788 set nowrap
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01002789 call setline(1, ['one', 'two', 'three', 'four'])
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002790 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
2791 call prop_type_add('anotherprop', #{highlight: 'Search'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01002792 call prop_type_add('someprop', #{highlight: 'DiffChange'})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002793 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
2794 call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'})
2795 call prop_add(2, 0, #{type: 'belowprop', text: 'One More Here', text_align: 'below'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01002796 call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'})
2797 call prop_add(1, 0, #{type: 'someprop', text: ' After the text', text_align: 'after'})
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01002798 normal 3G$
2799
2800 call prop_add(3, 0, #{type: 'anotherprop', text: 'right aligned', text_align: 'right'})
2801 call prop_add(3, 0, #{type: 'anotherprop', text: 'also right aligned', text_align: 'right'})
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002802 hi CursorLine ctermbg=lightgrey
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002803 END
2804 call writefile(lines, 'XscriptPropsAfterNowrap')
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01002805 let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 12, cols: 60})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002806 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {})
2807
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002808 call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\<CR>")
Bram Moolenaar1306b362022-08-06 15:59:06 +01002809 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {})
2810
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01002811 call term_sendkeys(buf, "j")
2812 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_3', {})
2813
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002814 call StopVimInTerminal(buf)
2815 call delete('XscriptPropsAfterNowrap')
2816endfunc
2817
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002818func Test_props_with_text_below_nowrap()
2819 CheckRunVimInTerminal
2820
2821 let lines =<< trim END
2822 vim9script
2823 edit foobar
2824 set nowrap
2825 set showbreak=+++\
2826 setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two'])
2827 prop_type_add('test', {highlight: 'Special'})
2828 prop_add(1, 0, {
2829 type: 'test',
2830 text: 'the quick brown fox jumps over the lazy dog',
2831 text_align: 'after'
2832 })
2833 prop_add(1, 0, {
2834 type: 'test',
2835 text: 'the quick brown fox jumps over the lazy dog',
2836 text_align: 'below'
2837 })
2838 normal G$
2839 END
2840 call writefile(lines, 'XscriptPropsBelowNowrap')
2841 let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60})
2842 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {})
2843
2844 call term_sendkeys(buf, "gg$")
2845 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {})
2846
2847 call StopVimInTerminal(buf)
2848 call delete('XscriptPropsBelowNowrap')
2849endfunc
2850
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002851func Test_props_with_text_above()
2852 CheckRunVimInTerminal
2853
2854 let lines =<< trim END
2855 call setline(1, ['one two', 'three four', 'five six'])
2856 call prop_type_add('above1', #{highlight: 'Search'})
2857 call prop_type_add('above2', #{highlight: 'DiffChange'})
2858 call prop_add(1, 0, #{type: 'above1', text: 'first thing above', text_align: 'above'})
2859 call prop_add(1, 0, #{type: 'above2', text: 'second thing above', text_align: 'above'})
2860 call prop_add(3, 0, #{type: 'above1', text: 'another thing', text_align: 'above'})
2861
2862 normal gglllj
2863 END
2864 call writefile(lines, 'XscriptPropsWithTextAbove', 'D')
2865 let buf = RunVimInTerminal('-S XscriptPropsWithTextAbove', #{rows: 9, cols: 60})
2866 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1', {})
2867
Bram Moolenaar88b79cb2022-09-10 22:32:14 +01002868 call term_sendkeys(buf, "ggI")
2869 call VerifyScreenDump(buf, 'Test_prop_with_text_above_2', {})
2870 call term_sendkeys(buf, "inserted \<Esc>")
2871 call VerifyScreenDump(buf, 'Test_prop_with_text_above_3', {})
2872
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002873 call StopVimInTerminal(buf)
2874endfunc
2875
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002876func Test_props_with_text_override()
2877 CheckRunVimInTerminal
2878
2879 let lines =<< trim END
2880 vim9script
2881 setline(1, 'some text here')
2882 hi Likethis ctermfg=blue ctermbg=cyan
2883 prop_type_add('prop', {highlight: 'Likethis', override: true})
2884 prop_add(1, 6, {type: 'prop', text: ' inserted '})
2885 hi CursorLine cterm=underline ctermbg=lightgrey
2886 set cursorline
2887 END
2888 call writefile(lines, 'XscriptPropsOverride')
2889 let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60})
2890 call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {})
2891
2892 call term_sendkeys(buf, ":set nocursorline\<CR>")
2893 call term_sendkeys(buf, "0llvfr")
2894 call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {})
2895
2896 call StopVimInTerminal(buf)
2897 call delete('XscriptPropsOverride')
2898endfunc
2899
Bram Moolenaar326c5d32022-08-12 13:05:49 +01002900func Test_props_with_text_CursorMoved()
2901 CheckRunVimInTerminal
2902
2903 let lines =<< trim END
2904 call setline(1, ['this is line one', 'this is line two', 'three', 'four', 'five'])
2905
2906 call prop_type_add('prop', #{highlight: 'Error'})
2907 let g:long_text = repeat('x', &columns * 2)
2908
2909 let g:prop_id = v:null
2910 func! Update()
2911 if line('.') == 1
2912 if g:prop_id == v:null
2913 let g:prop_id = prop_add(1, 0, #{type: 'prop', text_wrap: 'wrap', text: g:long_text})
2914 endif
2915 elseif g:prop_id != v:null
2916 call prop_remove(#{id: g:prop_id})
2917 let g:prop_id = v:null
2918 endif
2919 endfunc
2920
2921 autocmd CursorMoved * call Update()
2922 END
2923 call writefile(lines, 'XscriptPropsCursorMovec')
2924 let buf = RunVimInTerminal('-S XscriptPropsCursorMovec', #{rows: 8, cols: 60})
2925 call term_sendkeys(buf, "gg0w")
2926 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
2927
2928 call term_sendkeys(buf, "j")
2929 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_2', {})
2930
2931 " back to the first state
2932 call term_sendkeys(buf, "k")
2933 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
2934
2935 call StopVimInTerminal(buf)
2936 call delete('XscriptPropsCursorMovec')
2937endfunc
2938
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01002939func Test_props_with_text_after_split_join()
2940 CheckRunVimInTerminal
2941
2942 let lines =<< trim END
2943 call setline(1, ['1122'])
2944 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
2945 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
2946 exe "normal f2i\<CR>\<Esc>"
2947
2948 func AddMore()
2949 call prop_type_add('another', #{highlight: 'Search'})
2950 call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'})
2951 call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'})
2952 endfunc
2953 END
2954 call writefile(lines, 'XscriptPropsAfterSplitJoin')
2955 let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60})
2956 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {})
2957
2958 call term_sendkeys(buf, "ggJ")
2959 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {})
2960
2961 call term_sendkeys(buf, ":call AddMore()\<CR>")
2962 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {})
2963
2964 call term_sendkeys(buf, "ggf s\<CR>\<Esc>")
2965 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {})
2966
2967 call term_sendkeys(buf, "ggJ")
2968 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {})
2969
2970 call StopVimInTerminal(buf)
2971 call delete('XscriptPropsAfterSplitJoin')
2972endfunc
2973
Bram Moolenaar3a4cd392022-07-30 22:17:18 +01002974func Test_removed_prop_with_text_cleans_up_array()
2975 new
2976 call setline(1, 'some text here')
2977 call prop_type_add('some', #{highlight: 'ErrorMsg'})
2978 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
2979 call assert_equal(-1, id1)
2980 let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"})
2981 call assert_equal(-2, id2)
2982
2983 " removing the props resets the index
2984 call prop_remove(#{id: id1})
2985 call prop_remove(#{id: id2})
2986 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
2987 call assert_equal(-1, id1)
2988
2989 call prop_type_delete('some')
2990 bwipe!
2991endfunc
2992
Bram Moolenaar1f4ee192022-08-01 15:52:55 +01002993def Test_insert_text_before_virtual_text()
2994 new foobar
2995 setline(1, '12345678')
2996 prop_type_add('test', {highlight: 'Search'})
2997 prop_add(1, 5, {
2998 type: 'test',
2999 text: ' virtual text '
3000 })
3001 normal! f4axyz
3002 normal! f5iXYZ
3003 assert_equal('1234xyzXYZ5678', getline(1))
3004
3005 prop_type_delete('test')
3006 bwipe!
3007enddef
3008
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003009func Test_insert_text_start_incl()
3010 CheckRunVimInTerminal
3011
3012 let lines =<< trim END
3013 vim9script
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003014 setline(1, ['text one text two', '', 'function(arg)'])
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003015
3016 prop_type_add('propincl', {highlight: 'NonText', start_incl: true})
3017 prop_add(1, 6, {type: 'propincl', text: 'after '})
3018 cursor(1, 6)
3019 prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false})
3020 prop_add(1, 15, {type: 'propnotincl', text: 'before '})
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003021
3022 set cindent sw=4
3023 prop_type_add('argname', {highlight: 'DiffChange', start_incl: true})
3024 prop_add(3, 10, {type: 'argname', text: 'arg: '})
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003025 END
3026 call writefile(lines, 'XscriptPropsStartIncl')
3027 let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60})
3028 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {})
3029
3030 call term_sendkeys(buf, "i")
3031 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {})
3032 call term_sendkeys(buf, "xx\<Esc>")
3033 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {})
3034
3035 call term_sendkeys(buf, "2wi")
3036 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {})
3037 call term_sendkeys(buf, "yy\<Esc>")
3038 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {})
3039
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003040 call term_sendkeys(buf, "3Gfai\<CR>\<Esc>")
3041 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_6', {})
3042 call term_sendkeys(buf, ">>")
3043 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_7', {})
3044 call term_sendkeys(buf, "<<<<")
3045 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_8', {})
3046
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003047 call StopVimInTerminal(buf)
3048 call delete('XscriptPropsStartIncl')
3049endfunc
3050
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003051func Test_insert_text_list_mode()
3052 CheckRunVimInTerminal
3053
3054 let lines =<< trim END
3055 vim9script
3056 setline(1, ['This is a line with quite a bit of text here.',
3057 'second line', 'third line'])
3058 set list listchars+=extends:ยป
3059 prop_type_add('Prop1', {highlight: 'Error'})
3060 prop_add(1, 0, {
3061 type: 'Prop1',
3062 text: 'The quick brown fox jumps over the lazy dog',
3063 text_align: 'right'
3064 })
3065 END
3066 call writefile(lines, 'XscriptPropsListMode')
3067 let buf = RunVimInTerminal('-S XscriptPropsListMode', #{rows: 8, cols: 60})
3068 call term_sendkeys(buf, "ggj")
3069 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_1', {})
3070
3071 call term_sendkeys(buf, ":set nowrap\<CR>")
3072 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_2', {})
3073
3074 call term_sendkeys(buf, "ggd32l")
3075 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_3', {})
3076
3077 call StopVimInTerminal(buf)
3078 call delete('XscriptPropsListMode')
3079endfunc
3080
Bram Moolenaarf396ce82022-08-23 18:39:37 +01003081func Test_insert_text_with_padding()
3082 CheckRunVimInTerminal
3083
3084 let lines =<< trim END
3085 vim9script
3086 setline(1, ['Some text to add virtual text to.',
3087 'second line',
3088 'Another line with some text to make the wrap.'])
3089 prop_type_add('theprop', {highlight: 'DiffChange'})
3090 prop_add(1, 0, {
3091 type: 'theprop',
3092 text: 'after',
3093 text_align: 'after',
3094 text_padding_left: 3,
3095 })
3096 prop_add(1, 0, {
3097 type: 'theprop',
3098 text: 'right aligned',
3099 text_align: 'right',
3100 text_padding_left: 5,
3101 })
3102 prop_add(1, 0, {
3103 type: 'theprop',
3104 text: 'below the line',
3105 text_align: 'below',
3106 text_padding_left: 4,
3107 })
3108 prop_add(3, 0, {
3109 type: 'theprop',
3110 text: 'rightmost',
3111 text_align: 'right',
3112 text_padding_left: 6,
3113 text_wrap: 'wrap',
3114 })
3115 END
3116 call writefile(lines, 'XscriptPropsPadded')
3117 let buf = RunVimInTerminal('-S XscriptPropsPadded', #{rows: 8, cols: 60})
3118 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_1', {})
3119
3120 call term_sendkeys(buf, "ggixxxxxxxxxx\<Esc>")
3121 call term_sendkeys(buf, "3Gix\<Esc>")
3122 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_2', {})
3123
3124 call term_sendkeys(buf, "ggix\<Esc>")
3125 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_3', {})
3126
3127 call StopVimInTerminal(buf)
3128 call delete('XscriptPropsPadded')
3129endfunc
3130
Bram Moolenaarf5240b92022-08-24 12:24:37 +01003131func Test_insert_text_change_arg()
3132 CheckRunVimInTerminal
3133
3134 let lines =<< trim END
3135 vim9script
3136 setline(1, ['SetErrorCode( 10, 20 )', 'second line'])
3137 prop_type_add('param', {highlight: 'DiffChange', start_incl: 1})
3138 prop_type_add('padd', {highlight: 'NonText', start_incl: 1})
3139 prop_add(1, 15, {
3140 type: 'param',
3141 text: 'id:',
3142 })
3143 prop_add(1, 15, {
3144 type: 'padd',
3145 text: '-',
3146 })
3147 prop_add(1, 19, {
3148 type: 'param',
3149 text: 'id:',
3150 })
3151 prop_add(1, 19, {
3152 type: 'padd',
3153 text: '-',
3154 })
3155 END
3156 call writefile(lines, 'XscriptPropsChange')
3157 let buf = RunVimInTerminal('-S XscriptPropsChange', #{rows: 5, cols: 60})
3158 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_1', {})
3159
3160 call term_sendkeys(buf, "ggf1cw1234\<Esc>")
3161 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_2', {})
3162
3163 call StopVimInTerminal(buf)
3164 call delete('XscriptPropsChange')
3165endfunc
3166
Bram Moolenaar99fa7212020-04-26 15:59:55 +02003167" vim: shiftwidth=2 sts=2 expandtab