blob: 80ad88c6d4b75cd775d267986e92046e28555474 [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))
Bram Moolenaard93009e2022-10-13 14:35:24 +0100370 call prop_remove(#{id: 2})
371 call assert_equal([], prop_list(1))
372
373 call prop_add_list(#{type: 'one', id: 3},
374 \ [[1, 1, 1, 3], [2, 5, 2, 7, 9]])
375 call assert_equal([#{id: 3, col: 1, type_bufnr: 0, end: 1, type: 'one',
376 \ length: 2, start: 1}], prop_list(1))
377 call assert_equal([#{id: 9, col: 5, type_bufnr: 0, end: 1, type: 'one',
378 \ length: 2, start: 1}], prop_list(2))
379
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200380 call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:')
381 call assert_fails('call prop_add_list({}, {})', 'E1211:')
382 call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:')
383 call assert_fails('call prop_add_list(#{type: "abc"}, [[1, 1, 1, 3]])', 'E971:')
384 call assert_fails('call prop_add_list(#{type: "one"}, [[]])', 'E474:')
385 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 1], {}])', 'E714:')
386 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, "a"]])', 'E474:')
387 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2]])', 'E474:')
388 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 2], [2, 2]])', 'E474:')
389 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 2], [4, 1, 5, 2]])', 'E966:')
390 call assert_fails('call prop_add_list(#{type: "one"}, [[3, 1, 1, 2]])', 'E966:')
391 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
392 call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
393 call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:')
Bram Moolenaard83392a2022-09-01 12:22:46 +0100394 call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E1298:')
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200395 call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:')
Bram Moolenaar4997f2a2022-10-13 14:00:45 +0100396
397 " only one error for multiple wrong values
398 call assert_fails('call prop_add_list(#{type: "one"}, [[{}, [], 0z00, 0.3]])', ['E728:', 'E728:'])
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200399 call DeletePropTypes()
400 bw!
401endfunc
402
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100403func Test_prop_remove()
404 new
405 call AddPropTypes()
406 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100407 let props = Get_expected_props()
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100408 call assert_equal(props, prop_list(1))
409
410 " remove by id
Bram Moolenaara5a78822019-09-04 21:57:18 +0200411 call assert_equal(1, {'id': 12}->prop_remove(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100412 unlet props[2]
413 call assert_equal(props, prop_list(1))
414
415 " remove by type
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200416 call assert_equal(1, prop_remove({'type': 'one'}, 1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100417 unlet props[1]
418 call assert_equal(props, prop_list(1))
419
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200420 " remove from unknown buffer
421 call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:')
422
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100423 call DeletePropTypes()
424 bwipe!
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100425
426 new
427 call AddPropTypes()
428 call SetupPropsInFirstLine()
429 call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
430 let props = Get_expected_props()
Martin Tournoije2390c72021-07-28 13:30:16 +0200431 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 +0100432 call assert_equal(props, prop_list(1))
433 call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
434 unlet props[3]
435 call assert_equal(props, prop_list(1))
436
Bram Moolenaare2e40752020-09-04 21:18:46 +0200437 call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:')
438 call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:')
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100439
440 call DeletePropTypes()
441 bwipe!
Ben Jacksona7704222022-08-20 20:54:51 +0100442
443 new
444 call AddPropTypes()
445 call SetupPropsInFirstLine()
446 let props = Get_expected_props() " [whole, one, two, three]
447 call assert_equal(props, prop_list(1))
448
449 " remove one by types
450 call assert_equal(1, prop_remove({'types': ['one', 'two', 'three']}, 1))
451 unlet props[1] " [whole, two, three]
452 call assert_equal(props, prop_list(1))
453
454 " remove 'all' by types
455 call assert_equal(2, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
456 unlet props[0] " [two, three]
457 unlet props[1] " [three]
458 call assert_equal(props, prop_list(1))
459
460 " remove none by types
461 call assert_equal(0, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
462 call assert_equal(props, prop_list(1))
463
464 " no types
465 call assert_fails("call prop_remove({'types': []}, 1)", 'E968:')
466 call assert_fails("call prop_remove({'types': ['not_a_real_type']}, 1)", 'E971:')
467
468 " only one of types and type can be supplied
469 call assert_fails("call prop_remove({'type': 'one', 'types': ['three'], 'all': 1}, 1)", 'E1295:')
470
471 call DeletePropTypes()
472 bwipe!
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100473endfunc
474
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200475def Test_prop_add_vim9()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100476 prop_type_add('comment', {
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200477 highlight: 'Directory',
478 priority: 123,
479 start_incl: true,
480 end_incl: true,
481 combine: false,
482 })
483 prop_type_delete('comment')
484enddef
485
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200486def Test_prop_remove_vim9()
487 new
Bram Moolenaar62aec932022-01-29 21:45:34 +0000488 g:AddPropTypes()
489 g:SetupPropsInFirstLine()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100490 assert_equal(1, prop_remove({type: 'three', id: 13, both: true, all: true}))
Bram Moolenaar62aec932022-01-29 21:45:34 +0000491 g:DeletePropTypes()
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200492 bwipe!
493enddef
494
Bram Moolenaar196d1572019-01-02 23:47:18 +0100495func SetupOneLine()
496 call setline(1, 'xonex xtwoxx')
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200497 normal gg0
Bram Moolenaar196d1572019-01-02 23:47:18 +0100498 call AddPropTypes()
499 call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'})
500 call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'})
501 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200502 \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1},
503 \ #{type_bufnr: 0, col: 8, length: 3, id: 12, type: 'two', start: 1, end: 1},
Bram Moolenaar196d1572019-01-02 23:47:18 +0100504 \]
505 call assert_equal(expected, prop_list(1))
506 return expected
507endfunc
508
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100509func Test_prop_add_remove_buf()
510 new
511 let bufnr = bufnr('')
512 call AddPropTypes()
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100513 for lnum in range(1, 4)
514 call setline(lnum, 'one two three')
515 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100516 wincmd w
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100517 for lnum in range(1, 4)
518 call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr})
519 call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr})
520 call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr})
521 endfor
522
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100523 let props = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200524 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
525 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
526 \ #{type_bufnr: 0, col: 11, length: 3, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100527 \]
528 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100529
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100530 " remove by id
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100531 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100532 unlet props[1]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100533
534 call prop_remove({'id': 12, 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100535 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100536 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
537 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
538 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
539
540 call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4)
541 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
542 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
543 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
544 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
545
546 call prop_remove({'id': 12, 'bufnr': bufnr})
547 for lnum in range(1, 4)
548 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
549 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100550
551 " remove by type
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100552 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100553 unlet props[0]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100554
555 call prop_remove({'type': 'one', 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100556 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100557 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
558 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
559 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
560
561 call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4)
562 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
563 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
564 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
565 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
566
567 call prop_remove({'type': 'one', 'bufnr': bufnr})
568 for lnum in range(1, 4)
569 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
570 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100571
572 call DeletePropTypes()
573 wincmd w
574 bwipe!
575endfunc
576
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100577func Test_prop_backspace()
578 new
579 set bs=2
Bram Moolenaar196d1572019-01-02 23:47:18 +0100580 let expected = SetupOneLine() " 'xonex xtwoxx'
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100581
582 exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>"
583 call assert_equal('one xtwoxx', getline(1))
584 let expected[0].col = 1
585 let expected[1].col = 6
586 call assert_equal(expected, prop_list(1))
587
588 call DeletePropTypes()
589 bwipe!
590 set bs&
591endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100592
LemonBoyd0b1a092022-05-12 18:45:18 +0100593func Test_prop_change()
594 new
595 let expected = SetupOneLine() " 'xonex xtwoxx'
596
597 " Characterwise.
598 exe "normal 7|c$\<Esc>"
599 call assert_equal('xonex ', getline(1))
600 call assert_equal(expected[:0], prop_list(1))
601 " Linewise.
602 exe "normal cc\<Esc>"
603 call assert_equal('', getline(1))
604 call assert_equal([], prop_list(1))
605
606 call DeletePropTypes()
607 bwipe!
608 set bs&
609endfunc
610
Bram Moolenaar196d1572019-01-02 23:47:18 +0100611func Test_prop_replace()
612 new
613 set bs=2
614 let expected = SetupOneLine() " 'xonex xtwoxx'
615
616 exe "normal 0Ryyy\<Esc>"
617 call assert_equal('yyyex xtwoxx', getline(1))
618 call assert_equal(expected, prop_list(1))
619
620 exe "normal ftRyy\<BS>"
621 call assert_equal('yyyex xywoxx', getline(1))
622 call assert_equal(expected, prop_list(1))
623
624 exe "normal 0fwRyy\<BS>"
625 call assert_equal('yyyex xyyoxx', getline(1))
626 call assert_equal(expected, prop_list(1))
627
628 exe "normal 0foRyy\<BS>\<BS>"
629 call assert_equal('yyyex xyyoxx', getline(1))
630 call assert_equal(expected, prop_list(1))
631
LemonBoy0d534d92022-05-21 11:20:42 +0100632 " Replace three 1-byte chars with three 2-byte ones.
633 exe "normal 0l3rø"
634 call assert_equal('yøøøx xyyoxx', getline(1))
635 let expected[0].length += 3
636 let expected[1].col += 3
637 call assert_equal(expected, prop_list(1))
638
Bram Moolenaar196d1572019-01-02 23:47:18 +0100639 call DeletePropTypes()
640 bwipe!
641 set bs&
642endfunc
643
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200644func Test_prop_open_line()
645 new
646
647 " open new line, props stay in top line
648 let expected = SetupOneLine() " 'xonex xtwoxx'
649 exe "normal o\<Esc>"
650 call assert_equal('xonex xtwoxx', getline(1))
651 call assert_equal('', getline(2))
652 call assert_equal(expected, prop_list(1))
653 call DeletePropTypes()
654
655 " move all props to next line
656 let expected = SetupOneLine() " 'xonex xtwoxx'
657 exe "normal 0i\<CR>\<Esc>"
658 call assert_equal('', getline(1))
659 call assert_equal('xonex xtwoxx', getline(2))
660 call assert_equal(expected, prop_list(2))
661 call DeletePropTypes()
662
663 " split just before prop, move all props to next line
664 let expected = SetupOneLine() " 'xonex xtwoxx'
665 exe "normal 0li\<CR>\<Esc>"
666 call assert_equal('x', getline(1))
667 call assert_equal('onex xtwoxx', getline(2))
668 let expected[0].col -= 1
669 let expected[1].col -= 1
670 call assert_equal(expected, prop_list(2))
671 call DeletePropTypes()
672
673 " split inside prop, split first prop
674 let expected = SetupOneLine() " 'xonex xtwoxx'
675 exe "normal 0lli\<CR>\<Esc>"
676 call assert_equal('xo', getline(1))
677 call assert_equal('nex xtwoxx', getline(2))
678 let exp_first = [deepcopy(expected[0])]
679 let exp_first[0].length = 1
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200680 let exp_first[0].end = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200681 call assert_equal(exp_first, prop_list(1))
682 let expected[0].col = 1
683 let expected[0].length = 2
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200684 let expected[0].start = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200685 let expected[1].col -= 2
686 call assert_equal(expected, prop_list(2))
687 call DeletePropTypes()
688
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200689 " split just after first prop, second prop move to next line
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200690 let expected = SetupOneLine() " 'xonex xtwoxx'
691 exe "normal 0fea\<CR>\<Esc>"
692 call assert_equal('xone', getline(1))
693 call assert_equal('x xtwoxx', getline(2))
694 let exp_first = expected[0:0]
695 call assert_equal(exp_first, prop_list(1))
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200696 let expected = expected[1:1]
697 let expected[0].col -= 4
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200698 call assert_equal(expected, prop_list(2))
699 call DeletePropTypes()
700
LemonBoy788c06a2022-05-14 18:48:05 +0100701 " split at the space character with 'ai' active, the leading space is removed
702 " in the second line and the prop is shifted accordingly.
703 let expected = SetupOneLine() " 'xonex xtwoxx'
704 set ai
705 exe "normal 6|i\<CR>\<Esc>"
706 call assert_equal('xonex', getline(1))
707 call assert_equal('xtwoxx', getline(2))
708 let expected[1].col -= 6
709 call assert_equal(expected, prop_list(1) + prop_list(2))
710 set ai&
711 call DeletePropTypes()
712
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200713 bwipe!
714 set bs&
715endfunc
716
Bram Moolenaarecb00c72022-08-07 14:55:14 +0100717func Test_prop_put()
718 new
719 let expected = SetupOneLine() " 'xonex xtwoxx'
720
721 let @a = 'new'
722 " insert just after the prop
723 normal 03l"ap
724 " insert inside the prop
725 normal 02l"ap
726 " insert just before the prop
727 normal 0"ap
728
729 call assert_equal('xnewonnewenewx xtwoxx', getline(1))
730 let expected[0].col += 3
731 let expected[0].length += 3
732 let expected[1].col += 9
733 call assert_equal(expected, prop_list(1))
734
735 " Visually select 4 chars in the prop and put "AB" to replace them
736 let @a = 'AB'
737 normal 05lv3l"ap
738 call assert_equal('xnewoABenewx xtwoxx', getline(1))
739 let expected[0].length -= 2
740 let expected[1].col -= 2
741 call assert_equal(expected, prop_list(1))
742
743 call DeletePropTypes()
744 bwipe!
745endfunc
746
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100747func Test_prop_clear()
748 new
749 call AddPropTypes()
750 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100751 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100752
Bram Moolenaara5a78822019-09-04 21:57:18 +0200753 eval 1->prop_clear()
754 call assert_equal([], 1->prop_list())
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100755
756 call DeletePropTypes()
757 bwipe!
758endfunc
759
760func Test_prop_clear_buf()
761 new
762 call AddPropTypes()
763 call SetupPropsInFirstLine()
764 let bufnr = bufnr('')
765 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100766 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100767
768 call prop_clear(1, 1, {'bufnr': bufnr})
769 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
770
771 wincmd w
772 call DeletePropTypes()
773 bwipe!
774endfunc
775
Bram Moolenaar21b50382019-01-04 18:07:24 +0100776func Test_prop_setline()
777 new
778 call AddPropTypes()
779 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100780 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100781
782 call setline(1, 'foobar')
783 call assert_equal([], prop_list(1))
784
785 call DeletePropTypes()
786 bwipe!
787endfunc
788
789func Test_prop_setbufline()
790 new
791 call AddPropTypes()
792 call SetupPropsInFirstLine()
793 let bufnr = bufnr('')
794 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100795 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100796
797 call setbufline(bufnr, 1, 'foobar')
798 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
799
800 wincmd w
801 call DeletePropTypes()
802 bwipe!
803endfunc
804
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100805func Test_prop_substitute()
806 new
807 " Set first line to 'one two three'
808 call AddPropTypes()
809 call SetupPropsInFirstLine()
810 let expected_props = Get_expected_props()
811 call assert_equal(expected_props, prop_list(1))
812
813 " Change "n" in "one" to XX: 'oXXe two three'
814 s/n/XX/
815 let expected_props[0].length += 1
816 let expected_props[1].length += 1
817 let expected_props[2].col += 1
818 let expected_props[3].col += 1
819 call assert_equal(expected_props, prop_list(1))
820
821 " Delete "t" in "two" and "three" to XX: 'oXXe wo hree'
822 s/t//g
823 let expected_props[0].length -= 2
824 let expected_props[2].length -= 1
825 let expected_props[3].length -= 1
826 let expected_props[3].col -= 1
827 call assert_equal(expected_props, prop_list(1))
828
829 " Split the line by changing w to line break: 'oXXe ', 'o hree'
830 " The long prop is split and spans both lines.
831 " The props on "two" and "three" move to the next line.
832 s/w/\r/
833 let new_props = [
834 \ copy(expected_props[0]),
835 \ copy(expected_props[2]),
836 \ copy(expected_props[3]),
837 \ ]
838 let expected_props[0].length = 5
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200839 let expected_props[0].end = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100840 unlet expected_props[3]
841 unlet expected_props[2]
842 call assert_equal(expected_props, prop_list(1))
843
844 let new_props[0].length = 6
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200845 let new_props[0].start = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100846 let new_props[1].col = 1
847 let new_props[1].length = 1
848 let new_props[2].col = 3
849 call assert_equal(new_props, prop_list(2))
850
851 call DeletePropTypes()
852 bwipe!
853endfunc
854
Bram Moolenaar663bc892019-01-08 23:07:24 +0100855func Test_prop_change_indent()
856 call prop_type_add('comment', {'highlight': 'Directory'})
857 new
858 call setline(1, [' xxx', 'yyyyy'])
859 call prop_add(2, 2, {'length': 2, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200860 let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0}
Bram Moolenaar663bc892019-01-08 23:07:24 +0100861 call assert_equal([expect], prop_list(2))
862
863 set shiftwidth=3
864 normal 2G>>
865 call assert_equal(' yyyyy', getline(2))
866 let expect.col += 3
867 call assert_equal([expect], prop_list(2))
868
869 normal 2G==
870 call assert_equal(' yyyyy', getline(2))
871 let expect.col = 6
872 call assert_equal([expect], prop_list(2))
873
874 call prop_clear(2)
875 call prop_add(2, 2, {'length': 5, 'type': 'comment'})
876 let expect.col = 2
877 let expect.length = 5
878 call assert_equal([expect], prop_list(2))
879
880 normal 2G<<
881 call assert_equal(' yyyyy', getline(2))
882 let expect.length = 2
883 call assert_equal([expect], prop_list(2))
884
885 set shiftwidth&
886 call prop_type_delete('comment')
887endfunc
888
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100889" Setup a three line prop in lines 2 - 4.
890" Add short props in line 1 and 5.
891func Setup_three_line_prop()
892 new
893 call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five'])
894 call prop_add(1, 2, {'length': 1, 'type': 'comment'})
895 call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'})
896 call prop_add(5, 2, {'length': 1, 'type': 'comment'})
897endfunc
898
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100899func Test_prop_multiline()
Bram Moolenaara5a78822019-09-04 21:57:18 +0200900 eval 'comment'->prop_type_add({'highlight': 'Directory'})
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100901 new
902 call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz'])
903
904 " start halfway line 1, end halfway line 3
905 call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200906 let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100907 call assert_equal([expect1], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200908 let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100909 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200910 let expect3 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100911 call assert_equal([expect3], prop_list(3))
912 call prop_clear(1, 3)
913
914 " include all three lines
915 call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'})
916 let expect1.col = 1
917 let expect1.length = 8
918 call assert_equal([expect1], prop_list(1))
919 call assert_equal([expect2], prop_list(2))
920 let expect3.length = 9
921 call assert_equal([expect3], prop_list(3))
922 call prop_clear(1, 3)
923
924 bwipe!
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100925
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100926 " Test deleting the first line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100927 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200928 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 +0100929 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200930 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100931 call assert_equal([expect2], prop_list(2))
932 2del
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100933 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200934 let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100935 call assert_equal([expect2], prop_list(2))
936 bwipe!
937
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100938 " Test deleting the last line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100939 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200940 let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100941 call assert_equal([expect3], prop_list(3))
Martin Tournoije2390c72021-07-28 13:30:16 +0200942 let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100943 call assert_equal([expect4], prop_list(4))
944 4del
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100945 let expect3.end = 1
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100946 call assert_equal([expect3], prop_list(3))
947 call assert_equal([expect_short], prop_list(4))
948 bwipe!
949
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100950 " Test appending a line below the multi-line text prop start.
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100951 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200952 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100953 call assert_equal([expect2], prop_list(2))
954 call append(2, "new line")
955 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200956 let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100957 call assert_equal([expect3], prop_list(3))
958 bwipe!
959
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100960 call prop_type_delete('comment')
961endfunc
962
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100963func Run_test_with_line2byte(add_props)
964 new
965 setlocal ff=unix
966 if a:add_props
967 call prop_type_add('textprop', #{highlight: 'Search'})
968 endif
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100969 " Add a text prop to every fourth line and then change every fifth line so
970 " that it causes a data block split a few times.
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100971 for nr in range(1, 1000)
972 call setline(nr, 'some longer text here')
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100973 if a:add_props && nr % 4 == 0
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100974 call prop_add(nr, 13, #{type: 'textprop', length: 4})
975 endif
976 endfor
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100977 let expected = 22 * 997 + 1
978 call assert_equal(expected, line2byte(998))
979
980 for nr in range(1, 1000, 5)
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100981 exe nr .. "s/longer/much more/"
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100982 let expected += 3
983 call assert_equal(expected, line2byte(998), 'line ' .. nr)
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100984 endfor
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100985
986 if a:add_props
987 call prop_type_delete('textprop')
988 endif
989 bwipe!
990endfunc
991
Bram Moolenaar9df53b62020-01-13 20:40:51 +0100992func Test_prop_line2byte()
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100993 call prop_type_add('comment', {'highlight': 'Directory'})
994 new
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100995 call setline(1, ['line1', 'second line', ''])
Bram Moolenaar8cf734e2018-12-26 01:09:00 +0100996 set ff=unix
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100997 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100998 call prop_add(1, 1, {'end_col': 3, 'type': 'comment'})
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100999 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01001000 bwipe!
Bram Moolenaar14c75302021-08-15 14:28:40 +02001001
1002 new
Bram Moolenaara401bba2021-08-15 15:04:41 +02001003 setlocal ff=unix
Bram Moolenaar14c75302021-08-15 14:28:40 +02001004 call setline(1, range(500))
1005 call assert_equal(1491, line2byte(401))
1006 call prop_add(2, 1, {'type': 'comment'})
1007 call prop_add(222, 1, {'type': 'comment'})
1008 call assert_equal(1491, line2byte(401))
1009 call prop_remove({'type': 'comment'})
1010 call assert_equal(1491, line2byte(401))
1011 bwipe!
1012
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +02001013 new
Bram Moolenaar49b93042021-08-25 17:02:00 +02001014 setlocal ff=unix
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +02001015 call setline(1, range(520))
1016 call assert_equal(1491, line2byte(401))
1017 call prop_add(2, 1, {'type': 'comment'})
1018 call assert_equal(1491, line2byte(401))
1019 2delete
1020 call assert_equal(1489, line2byte(400))
1021 bwipe!
1022
Bram Moolenaarcf85d972022-08-08 14:59:47 +01001023 " Add many lines so that the data block is split.
1024 " With and without props should give the same result.
1025 call Run_test_with_line2byte(0)
1026 call Run_test_with_line2byte(1)
1027
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01001028 call prop_type_delete('comment')
1029endfunc
1030
Bram Moolenaar9df53b62020-01-13 20:40:51 +01001031func Test_prop_byte2line()
1032 new
1033 set ff=unix
1034 call setline(1, ['one one', 'two two', 'three three', 'four four', 'five'])
1035 call assert_equal(4, byte2line(line2byte(4)))
1036 call assert_equal(5, byte2line(line2byte(5)))
1037
1038 call prop_type_add('prop', {'highlight': 'Directory'})
1039 call prop_add(3, 1, {'length': 5, 'type': 'prop'})
1040 call assert_equal(4, byte2line(line2byte(4)))
1041 call assert_equal(5, byte2line(line2byte(5)))
1042
1043 bwipe!
1044 call prop_type_delete('prop')
1045endfunc
1046
Bram Moolenaar59ff6402021-01-30 17:16:28 +01001047func Test_prop_goto_byte()
1048 new
1049 call setline(1, '')
1050 call setline(2, 'two three')
1051 call setline(3, '')
1052 call setline(4, 'four five')
1053
1054 call prop_type_add('testprop', {'highlight': 'Directory'})
1055 call search('^two')
1056 call prop_add(line('.'), col('.'), {
1057 \ 'length': len('two'),
1058 \ 'type': 'testprop'
1059 \ })
1060
1061 call search('two \zsthree')
1062 let expected_pos = line2byte(line('.')) + col('.') - 1
1063 exe expected_pos .. 'goto'
1064 let actual_pos = line2byte(line('.')) + col('.') - 1
1065 eval actual_pos->assert_equal(expected_pos)
1066
1067 call search('four \zsfive')
1068 let expected_pos = line2byte(line('.')) + col('.') - 1
1069 exe expected_pos .. 'goto'
1070 let actual_pos = line2byte(line('.')) + col('.') - 1
1071 eval actual_pos->assert_equal(expected_pos)
1072
1073 call prop_type_delete('testprop')
1074 bwipe!
1075endfunc
1076
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001077func Test_prop_undo()
1078 new
1079 call prop_type_add('comment', {'highlight': 'Directory'})
1080 call setline(1, ['oneone', 'twotwo', 'three'])
1081 " Set 'undolevels' to break changes into undo-able pieces.
1082 set ul&
1083
1084 call prop_add(1, 3, {'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001085 let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}]
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001086 call assert_equal(expected, prop_list(1))
1087
1088 " Insert a character, then undo.
1089 exe "normal 0lllix\<Esc>"
1090 set ul&
1091 let expected[0].length = 3
1092 call assert_equal(expected, prop_list(1))
1093 undo
1094 let expected[0].length = 2
1095 call assert_equal(expected, prop_list(1))
1096
1097 " Delete a character, then undo
1098 exe "normal 0lllx"
1099 set ul&
1100 let expected[0].length = 1
1101 call assert_equal(expected, prop_list(1))
1102 undo
1103 let expected[0].length = 2
1104 call assert_equal(expected, prop_list(1))
1105
1106 " Delete the line, then undo
1107 1d
1108 set ul&
1109 call assert_equal([], prop_list(1))
1110 undo
1111 call assert_equal(expected, prop_list(1))
1112
1113 " Insert a character, delete two characters, then undo with "U"
1114 exe "normal 0lllix\<Esc>"
1115 set ul&
1116 let expected[0].length = 3
1117 call assert_equal(expected, prop_list(1))
1118 exe "normal 0lllxx"
1119 set ul&
1120 let expected[0].length = 1
1121 call assert_equal(expected, prop_list(1))
1122 normal U
1123 let expected[0].length = 2
1124 call assert_equal(expected, prop_list(1))
1125
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001126 " substitute a word, then undo
1127 call setline(1, 'the number 123 is highlighted.')
1128 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001129 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001130 call assert_equal(expected, prop_list(1))
1131 set ul&
1132 1s/number/foo
1133 let expected[0].col = 9
1134 call assert_equal(expected, prop_list(1))
1135 undo
1136 let expected[0].col = 12
1137 call assert_equal(expected, prop_list(1))
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001138 call prop_clear(1)
1139
1140 " substitute with backslash
1141 call setline(1, 'the number 123 is highlighted.')
1142 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001143 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001144 call assert_equal(expected, prop_list(1))
1145 1s/the/\The
1146 call assert_equal(expected, prop_list(1))
1147 1s/^/\\
1148 let expected[0].col += 1
1149 call assert_equal(expected, prop_list(1))
1150 1s/^/\~
1151 let expected[0].col += 1
1152 call assert_equal(expected, prop_list(1))
1153 1s/123/12\\3
1154 let expected[0].length += 1
1155 call assert_equal(expected, prop_list(1))
1156 call prop_clear(1)
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001157
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001158 bwipe!
1159 call prop_type_delete('comment')
1160endfunc
1161
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001162func Test_prop_delete_text()
1163 new
1164 call prop_type_add('comment', {'highlight': 'Directory'})
1165 call setline(1, ['oneone', 'twotwo', 'three'])
1166
1167 " zero length property
1168 call prop_add(1, 3, {'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001169 let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001170 call assert_equal(expected, prop_list(1))
1171
1172 " delete one char moves the property
1173 normal! x
Martin Tournoije2390c72021-07-28 13:30:16 +02001174 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001175 call assert_equal(expected, prop_list(1))
1176
1177 " delete char of the property has no effect
1178 normal! lx
Martin Tournoije2390c72021-07-28 13:30:16 +02001179 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001180 call assert_equal(expected, prop_list(1))
1181
1182 " delete more chars moves property to first column, is not deleted
1183 normal! 0xxxx
Martin Tournoije2390c72021-07-28 13:30:16 +02001184 let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001185 call assert_equal(expected, prop_list(1))
1186
1187 bwipe!
1188 call prop_type_delete('comment')
1189endfunc
1190
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001191" screenshot test with textprop highlighting
Bram Moolenaar8055d172019-05-17 22:57:26 +02001192func Test_textprop_screenshot_various()
Bram Moolenaar34390282019-10-16 14:38:26 +02001193 CheckScreendump
Bram Moolenaared79d1e2019-02-22 14:38:58 +01001194 " The Vim running in the terminal needs to use utf-8.
Bram Moolenaar34390282019-10-16 14:38:26 +02001195 if g:orig_encoding != 'utf-8'
1196 throw 'Skipped: not using utf-8'
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001197 endif
1198 call writefile([
Bram Moolenaarde24a872019-05-05 15:48:00 +02001199 \ "call setline(1, ["
1200 \ .. "'One two',"
1201 \ .. "'Numbér 123 änd thœn 4¾7.',"
1202 \ .. "'--aa--bb--cc--dd--',"
1203 \ .. "'// comment with error in it',"
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001204 \ .. "'first line',"
1205 \ .. "' second line ',"
1206 \ .. "'third line',"
1207 \ .. "' fourth line',"
Bram Moolenaarde24a872019-05-05 15:48:00 +02001208 \ .. "])",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001209 \ "hi NumberProp ctermfg=blue",
1210 \ "hi LongProp ctermbg=yellow",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001211 \ "hi BackgroundProp ctermbg=lightgrey",
1212 \ "hi UnderlineProp cterm=underline",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001213 \ "call prop_type_add('number', {'highlight': 'NumberProp'})",
Bram Moolenaara5a78822019-09-04 21:57:18 +02001214 \ "call prop_type_add('long', {'highlight': 'NumberProp'})",
1215 \ "call prop_type_change('long', {'highlight': 'LongProp'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001216 \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})",
1217 \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})",
1218 \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001219 \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})",
1220 \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})",
1221 \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})",
Bram Moolenaar58e32ab2019-11-12 22:44:22 +01001222 \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001223 \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001224 \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
1225 \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001226 \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})",
1227 \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})",
1228 \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})",
1229 \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001230 \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})",
1231 \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001232 \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001233 \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})",
1234 \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})",
1235 \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})",
1236 \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})",
Bram Moolenaarbfd45122019-05-17 13:05:07 +02001237 \ "set number cursorline",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001238 \ "hi clear SpellBad",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001239 \ "set spell",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001240 \ "syn match Comment '//.*'",
1241 \ "hi Comment ctermfg=green",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001242 \ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>",
Bram Moolenaar33c8ca92019-01-02 18:00:27 +01001243 \ "normal 3G0lli\<BS>\<Esc>",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001244 \ "normal 6G0i\<BS>\<Esc>",
1245 \ "normal 3J",
1246 \ "normal 3G",
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001247 \], 'XtestProp', 'D')
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001248 let buf = RunVimInTerminal('-S XtestProp', {'rows': 8})
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001249 call VerifyScreenDump(buf, 'Test_textprop_01', {})
Bram Moolenaare3d31b02018-12-24 23:07:04 +01001250
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001251 " clean up
1252 call StopVimInTerminal(buf)
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001253endfunc
Bram Moolenaar8055d172019-05-17 22:57:26 +02001254
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001255func Test_textprop_hl_override()
1256 CheckScreendump
1257
1258 let lines =<< trim END
1259 call setline(1, ['One one one one one', 'Two two two two two', 'Three three three three'])
1260 hi OverProp ctermfg=blue ctermbg=yellow
1261 hi CursorLine cterm=bold,underline ctermfg=red ctermbg=green
1262 hi Vsual ctermfg=cyan ctermbg=grey
1263 call prop_type_add('under', #{highlight: 'OverProp'})
1264 call prop_type_add('over', #{highlight: 'OverProp', override: 1})
1265 call prop_add(1, 5, #{type: 'under', length: 4})
1266 call prop_add(1, 13, #{type: 'over', length: 4})
1267 call prop_add(2, 5, #{type: 'under', length: 4})
1268 call prop_add(2, 13, #{type: 'over', length: 4})
1269 call prop_add(3, 5, #{type: 'under', length: 4})
1270 call prop_add(3, 13, #{type: 'over', length: 4})
1271 set cursorline
1272 2
1273 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001274 call writefile(lines, 'XtestOverProp', 'D')
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001275 let buf = RunVimInTerminal('-S XtestOverProp', {'rows': 8})
1276 call VerifyScreenDump(buf, 'Test_textprop_hl_override_1', {})
1277
1278 call term_sendkeys(buf, "3Gllv$hh")
1279 call VerifyScreenDump(buf, 'Test_textprop_hl_override_2', {})
1280 call term_sendkeys(buf, "\<Esc>")
1281
1282 " clean up
1283 call StopVimInTerminal(buf)
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001284endfunc
1285
Bram Moolenaar8055d172019-05-17 22:57:26 +02001286func RunTestVisualBlock(width, dump)
1287 call writefile([
1288 \ "call setline(1, ["
1289 \ .. "'xxxxxxxxx 123 x',"
1290 \ .. "'xxxxxxxx 123 x',"
1291 \ .. "'xxxxxxx 123 x',"
1292 \ .. "'xxxxxx 123 x',"
1293 \ .. "'xxxxx 123 x',"
1294 \ .. "'xxxx 123 xx',"
1295 \ .. "'xxx 123 xxx',"
1296 \ .. "'xx 123 xxxx',"
1297 \ .. "'x 123 xxxxx',"
1298 \ .. "' 123 xxxxxx',"
1299 \ .. "])",
1300 \ "hi SearchProp ctermbg=yellow",
1301 \ "call prop_type_add('search', {'highlight': 'SearchProp'})",
1302 \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})",
1303 \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})",
1304 \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})",
1305 \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})",
1306 \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})",
1307 \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})",
1308 \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})",
1309 \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})",
1310 \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})",
1311 \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})",
1312 \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx",
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001313 \], 'XtestPropVis', 'D')
Bram Moolenaar8055d172019-05-17 22:57:26 +02001314 let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12})
1315 call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {})
1316
1317 " clean up
1318 call StopVimInTerminal(buf)
Bram Moolenaar8055d172019-05-17 22:57:26 +02001319endfunc
1320
1321" screenshot test with Visual block mode operations
1322func Test_textprop_screenshot_visual()
Bram Moolenaar34390282019-10-16 14:38:26 +02001323 CheckScreendump
Bram Moolenaar8055d172019-05-17 22:57:26 +02001324
1325 " Delete two columns while text props are three chars wide.
1326 call RunTestVisualBlock(2, '01')
1327
1328 " Same, but delete four columns
1329 call RunTestVisualBlock(4, '02')
1330endfunc
Bram Moolenaard79eef22019-05-24 20:41:55 +02001331
Bram Moolenaara956bf62019-06-19 17:34:24 +02001332func Test_textprop_after_tab()
Bram Moolenaar34390282019-10-16 14:38:26 +02001333 CheckScreendump
Bram Moolenaar37e66cf2019-06-19 18:16:10 +02001334
Bram Moolenaara956bf62019-06-19 17:34:24 +02001335 let lines =<< trim END
1336 call setline(1, [
1337 \ "\txxx",
1338 \ "x\txxx",
1339 \ ])
1340 hi SearchProp ctermbg=yellow
1341 call prop_type_add('search', {'highlight': 'SearchProp'})
1342 call prop_add(1, 2, {'length': 3, 'type': 'search'})
1343 call prop_add(2, 3, {'length': 3, 'type': 'search'})
1344 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001345 call writefile(lines, 'XtestPropTab', 'D')
Bram Moolenaara956bf62019-06-19 17:34:24 +02001346 let buf = RunVimInTerminal('-S XtestPropTab', {'rows': 6})
1347 call VerifyScreenDump(buf, 'Test_textprop_tab', {})
1348
1349 " clean up
1350 call StopVimInTerminal(buf)
Bram Moolenaara956bf62019-06-19 17:34:24 +02001351endfunc
1352
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001353func Test_textprop_nowrap_scrolled()
1354 CheckScreendump
1355
1356 let lines =<< trim END
1357 vim9script
1358 set nowrap
1359 setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns))
1360 prop_type_add('number', {'highlight': 'ErrorMsg'})
1361 prop_add(1, 12, {'length': 3, 'type': 'number'})
1362 prop_add(1, 32, {'length': 4, 'type': 'number'})
1363 feedkeys('gg20zl', 'nxt')
1364 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001365 call writefile(lines, 'XtestNowrap', 'D')
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001366 let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6})
1367 call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {})
1368
1369 call term_sendkeys(buf, "$")
1370 call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {})
1371
1372 " clean up
1373 call StopVimInTerminal(buf)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001374endfunc
1375
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001376func Test_textprop_text_priority()
1377 CheckScreendump
1378
1379 let lines =<< trim END
1380 call setline(1, "function( call, argument, here )")
1381
1382 call prop_type_add('one', #{highlight: 'Error'})
1383 call prop_type_add('two', #{highlight: 'Function'})
1384 call prop_type_add('three', #{highlight: 'DiffChange'})
1385 call prop_type_add('arg', #{highlight: 'Search'})
1386
1387 call prop_add(1, 27, #{type: 'arg', length: len('here')})
1388 call prop_add(1, 27, #{type: 'three', text: 'three: '})
1389 call prop_add(1, 11, #{type: 'one', text: 'one: '})
1390 call prop_add(1, 11, #{type: 'arg', length: len('call')})
1391 call prop_add(1, 17, #{type: 'two', text: 'two: '})
1392 call prop_add(1, 17, #{type: 'arg', length: len('argument')})
1393 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001394 call writefile(lines, 'XtestPropPrio', 'D')
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001395 let buf = RunVimInTerminal('-S XtestPropPrio', {'rows': 5})
1396 call VerifyScreenDump(buf, 'Test_prop_at_same_pos', {})
1397
1398 " clean up
1399 call StopVimInTerminal(buf)
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001400endfunc
1401
Bram Moolenaar34390282019-10-16 14:38:26 +02001402func Test_textprop_with_syntax()
1403 CheckScreendump
1404
1405 let lines =<< trim END
1406 call setline(1, [
1407 \ "(abc)",
1408 \ ])
1409 syn match csParens "[()]" display
1410 hi! link csParens MatchParen
1411
1412 call prop_type_add('TPTitle', #{ highlight: 'Title' })
1413 call prop_add(1, 2, #{type: 'TPTitle', end_col: 5})
1414 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001415 call writefile(lines, 'XtestPropSyn', 'D')
Bram Moolenaar34390282019-10-16 14:38:26 +02001416 let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6})
1417 call VerifyScreenDump(buf, 'Test_textprop_syn_1', {})
1418
1419 " clean up
1420 call StopVimInTerminal(buf)
Bram Moolenaar34390282019-10-16 14:38:26 +02001421endfunc
1422
Bram Moolenaard79eef22019-05-24 20:41:55 +02001423" Adding a text property to a new buffer should not fail
1424func Test_textprop_empty_buffer()
1425 call prop_type_add('comment', {'highlight': 'Search'})
1426 new
1427 call prop_add(1, 1, {'type': 'comment'})
1428 close
Bram Moolenaaradfde112019-05-25 22:11:45 +02001429 call prop_type_delete('comment')
1430endfunc
1431
Bram Moolenaard74af422019-06-28 21:38:00 +02001432" Adding a text property with invalid highlight should be ignored.
1433func Test_textprop_invalid_highlight()
1434 call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:')
1435 new
Ben Jacksona7704222022-08-20 20:54:51 +01001436 call setline(1, ['asdf', 'asdf'])
Bram Moolenaard74af422019-06-28 21:38:00 +02001437 call prop_add(1, 1, {'length': 4, 'type': 'dni'})
1438 redraw
1439 bwipe!
1440 call prop_type_delete('dni')
1441endfunc
1442
Bram Moolenaaradfde112019-05-25 22:11:45 +02001443" Adding a text property to an empty buffer and then editing another
1444func Test_textprop_empty_buffer_next()
1445 call prop_type_add("xxx", {})
1446 call prop_add(1, 1, {"type": "xxx"})
1447 next X
1448 call prop_type_delete('xxx')
Bram Moolenaard79eef22019-05-24 20:41:55 +02001449endfunc
Bram Moolenaarf0884c52019-05-24 21:22:29 +02001450
1451func Test_textprop_remove_from_buf()
1452 new
1453 let buf = bufnr('')
1454 call prop_type_add('one', {'bufnr': buf})
1455 call prop_add(1, 1, {'type': 'one', 'id': 234})
1456 file x
1457 edit y
1458 call prop_remove({'id': 234, 'bufnr': buf}, 1)
1459 call prop_type_delete('one', {'bufnr': buf})
1460 bwipe! x
1461 close
1462endfunc
Bram Moolenaar45311b52019-08-13 22:27:32 +02001463
1464func Test_textprop_in_unloaded_buf()
1465 edit Xaaa
1466 call setline(1, 'aaa')
1467 write
1468 edit Xbbb
1469 call setline(1, 'bbb')
1470 write
1471 let bnr = bufnr('')
1472 edit Xaaa
1473
1474 call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'})
1475 call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:')
1476 exe 'buf ' .. bnr
1477 call assert_equal('bbb', getline(1))
1478 call assert_equal(0, prop_list(1)->len())
1479
1480 bwipe! Xaaa
1481 bwipe! Xbbb
1482 cal delete('Xaaa')
1483 cal delete('Xbbb')
1484endfunc
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001485
1486func Test_proptype_substitute2()
1487 new
1488 " text_prop.vim
1489 call setline(1, [
1490 \ 'The num 123 is smaller than 4567.',
1491 \ '123 The number 123 is smaller than 4567.',
1492 \ '123 The number 123 is smaller than 4567.'])
1493
1494 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1495
1496 call prop_add(1, 12, {'length': 3, 'type': 'number'})
1497 call prop_add(2, 1, {'length': 3, 'type': 'number'})
1498 call prop_add(3, 36, {'length': 4, 'type': 'number'})
1499 set ul&
Martin Tournoije2390c72021-07-28 13:30:16 +02001500 let expected = [
1501 \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1},
1502 \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1},
1503 \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}]
1504
1505 " TODO
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001506 if 0
1507 " Add some text in between
1508 %s/\s\+/ /g
1509 call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001510
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001511 " remove some text
1512 :1s/[a-z]\{3\}//g
1513 let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
1514 call assert_equal(expected, prop_list(1))
1515 endif
1516
1517 call prop_type_delete('number')
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001518 bwipe!
1519endfunc
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001520
Bram Moolenaar8902b312020-09-20 21:04:35 +02001521" This was causing property corruption.
1522func Test_proptype_substitute3()
1523 new
1524 call setline(1, ['abcxxx', 'def'])
1525 call prop_type_add("test", {"highlight": "Search"})
1526 call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"})
1527 %s/x\+$//
1528 redraw
1529
1530 call prop_type_delete('test')
1531 bwipe!
1532endfunc
1533
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001534func Test_proptype_substitute_join()
1535 new
1536 call setline(1, [
1537 \ 'This is some end',
1538 \ 'start is highlighted end',
1539 \ 'some is highlighted',
1540 \ 'start is also highlighted'])
1541
1542 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1543
1544 call prop_add(1, 6, {'length': 2, 'type': 'number'})
1545 call prop_add(2, 7, {'length': 2, 'type': 'number'})
1546 call prop_add(3, 6, {'length': 2, 'type': 'number'})
1547 call prop_add(4, 7, {'length': 2, 'type': 'number'})
1548 " The highlighted "is" in line 1, 2 and 4 is kept and ajudsted.
1549 " The highlighted "is" in line 3 is deleted.
1550 let expected = [
1551 \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1},
1552 \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1},
1553 \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}]
1554
1555 s/end\nstart/joined/
1556 s/end\n.*\nstart/joined/
1557 call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1))
1558 call assert_equal(expected, prop_list(1))
1559
1560 call prop_type_delete('number')
1561 bwipe!
1562endfunc
1563
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001564func SaveOptions()
1565 let d = #{tabstop: &tabstop,
1566 \ softtabstop: &softtabstop,
1567 \ shiftwidth: &shiftwidth,
1568 \ expandtab: &expandtab,
1569 \ foldmethod: '"' .. &foldmethod .. '"',
1570 \ }
1571 return d
1572endfunc
1573
1574func RestoreOptions(dict)
1575 for name in keys(a:dict)
1576 exe 'let &' .. name .. ' = ' .. a:dict[name]
1577 endfor
1578endfunc
1579
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001580func Test_textprop_noexpandtab()
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001581 new
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001582 let save_dict = SaveOptions()
1583
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001584 set tabstop=8
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001585 set softtabstop=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001586 set shiftwidth=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001587 set noexpandtab
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001588 set foldmethod=marker
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001589
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001590 call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx")
1591 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1592 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1593 call feedkeys("0i\<tab>", "tx")
1594 call prop_remove({'type': 'test'})
1595 call prop_add(1, 2, {'end_col': 3, 'type': 'test'})
1596 call feedkeys("A\<left>\<tab>", "tx")
1597 call prop_remove({'type': 'test'})
1598 try
1599 " It is correct that this does not pass
1600 call prop_add(1, 6, {'end_col': 7, 'type': 'test'})
1601 " Has already collapsed here, start_col:6 does not result in an error
1602 call feedkeys("A\<left>\<tab>", "tx")
1603 catch /^Vim\%((\a\+)\)\=:E964/
1604 endtry
1605 call prop_remove({'type': 'test'})
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001606 call prop_type_delete('test')
1607
1608 call RestoreOptions(save_dict)
1609 bwipe!
1610endfunc
1611
1612func Test_textprop_noexpandtab_redraw()
1613 new
1614 let save_dict = SaveOptions()
1615
1616 set tabstop=8
1617 set softtabstop=4
1618 set shiftwidth=4
1619 set noexpandtab
1620 set foldmethod=marker
1621
1622 call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx")
1623 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1624 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1625 call feedkeys("0i\<tab>", "tx")
1626 " Internally broken at the next line
1627 call feedkeys("A\<left>\<tab>", "tx")
1628 redraw
1629 " Index calculation failed internally on next line
1630 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1631 call prop_remove({'type': 'test', 'all': v:true})
1632 call prop_type_delete('test')
1633 call prop_type_delete('test')
1634
1635 call RestoreOptions(save_dict)
1636 bwipe!
1637endfunc
1638
1639func Test_textprop_ins_str()
1640 new
1641 call setline(1, 'just some text')
1642 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1643 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001644 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 +01001645
1646 call feedkeys("foi\<F8>\<Esc>", "tx")
1647 call assert_equal('just s<F8>ome text', getline(1))
Martin Tournoije2390c72021-07-28 13:30:16 +02001648 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 +01001649
1650 bwipe!
1651 call prop_remove({'type': 'test'})
1652 call prop_type_delete('test')
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001653endfunc
Bram Moolenaar66b98852020-03-11 19:15:52 +01001654
1655func Test_find_prop_later_in_line()
1656 new
1657 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1658 call setline(1, 'just some text')
1659 call prop_add(1, 1, {'length': 4, 'type': 'test'})
1660 call prop_add(1, 10, {'length': 3, 'type': 'test'})
1661
Martin Tournoije2390c72021-07-28 13:30:16 +02001662 call assert_equal(
1663 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1},
1664 \ prop_find(#{type: 'test', lnum: 1, col: 6}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001665
1666 bwipe!
1667 call prop_type_delete('test')
1668endfunc
1669
1670func Test_find_zerowidth_prop_sol()
1671 new
1672 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1673 call setline(1, 'just some text')
1674 call prop_add(1, 1, {'length': 0, 'type': 'test'})
1675
Martin Tournoije2390c72021-07-28 13:30:16 +02001676 call assert_equal(
1677 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1},
1678 \ prop_find(#{type: 'test', lnum: 1}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001679
1680 bwipe!
1681 call prop_type_delete('test')
1682endfunc
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001683
1684" Test for passing invalid arguments to prop_xxx() functions
1685func Test_prop_func_invalid_args()
1686 call assert_fails('call prop_clear(1, 2, [])', 'E715:')
1687 call assert_fails('call prop_clear(-1, 2)', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001688 call assert_fails('call prop_find(test_null_dict())', 'E1297:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001689 call assert_fails('call prop_find({"bufnr" : []})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001690 call assert_fails('call prop_find({})', 'E968:')
1691 call assert_fails('call prop_find({}, "x")', 'E474:')
1692 call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001693 call assert_fails('call prop_list(1, [])', 'E1206:')
Bram Moolenaar9d489562020-07-30 20:08:50 +02001694 call assert_fails('call prop_list(-1, {})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001695 call assert_fails('call prop_remove([])', 'E1206:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001696 call assert_fails('call prop_remove({}, -2)', 'E16:')
1697 call assert_fails('call prop_remove({})', 'E968:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001698 call assert_fails('call prop_type_add([], {})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001699 call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001700 call assert_fails("call prop_type_delete([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001701 call assert_fails("call prop_type_delete('xyz', [])", 'E715:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001702 call assert_fails("call prop_type_get([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001703 call assert_fails("call prop_type_get('', [])", 'E474:')
1704 call assert_fails("call prop_type_list([])", 'E715:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001705 call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:')
1706 call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:')
1707 call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001708 call assert_fails('call prop_add(1, 1, 0)', 'E1206:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001709
1710 new
1711 call setline(1, ['first', 'second'])
1712 call prop_type_add('xxx', {})
1713
1714 call assert_fails("call prop_type_add('xxx', {})", 'E969:')
1715 call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:')
1716 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:')
1717 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:')
1718 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:')
1719 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:')
1720 call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:')
1721
1722 call prop_type_delete('xxx')
1723 bwipe!
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001724endfunc
1725
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001726func Test_prop_split_join()
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001727 new
1728 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1729 call setline(1, 'just some text')
1730 call prop_add(1, 6, {'length': 4, 'type': 'test'})
1731
1732 " Split in middle of "some"
1733 execute "normal! 8|i\<CR>"
Martin Tournoije2390c72021-07-28 13:30:16 +02001734 call assert_equal(
1735 \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}],
1736 \ prop_list(1))
1737 call assert_equal(
1738 \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}],
1739 \ prop_list(2))
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001740
1741 " Join the two lines back together
1742 normal! 1GJ
Martin Tournoije2390c72021-07-28 13:30:16 +02001743 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 +02001744
1745 bwipe!
1746 call prop_type_delete('test')
1747endfunc
1748
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001749func Test_prop_increment_decrement()
1750 new
1751 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1752 call setline(1, 'its 998 times')
1753 call prop_add(1, 5, {'length': 3, 'type': 'test'})
1754
1755 exe "normal! 0f9\<C-A>"
1756 eval getline(1)->assert_equal('its 999 times')
1757 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001758 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001759
1760 exe "normal! 0f9\<C-A>"
1761 eval getline(1)->assert_equal('its 1000 times')
1762 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001763 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001764
1765 bwipe!
1766 call prop_type_delete('test')
1767endfunc
1768
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001769func Test_prop_block_insert()
1770 new
1771 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1772 call setline(1, ['one ', 'two '])
1773 call prop_add(1, 1, {'length': 3, 'type': 'test'})
1774 call prop_add(2, 1, {'length': 3, 'type': 'test'})
1775
1776 " insert "xx" in the first column of both lines
1777 exe "normal! gg0\<C-V>jIxx\<Esc>"
1778 eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
Martin Tournoije2390c72021-07-28 13:30:16 +02001779 let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001780 eval prop_list(1)->assert_equal(expected)
1781 eval prop_list(2)->assert_equal(expected)
1782
1783 " insert "yy" inside the text props to make them longer
1784 exe "normal! gg03l\<C-V>jIyy\<Esc>"
1785 eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo '])
1786 let expected[0].length = 5
1787 eval prop_list(1)->assert_equal(expected)
1788 eval prop_list(2)->assert_equal(expected)
1789
1790 " insert "zz" after the text props, text props don't change
1791 exe "normal! gg07l\<C-V>jIzz\<Esc>"
1792 eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz '])
1793 eval prop_list(1)->assert_equal(expected)
1794 eval prop_list(2)->assert_equal(expected)
1795
1796 bwipe!
1797 call prop_type_delete('test')
1798endfunc
1799
Bram Moolenaar23999d72020-12-23 14:36:00 +01001800" this was causing an ml_get error because w_botline was wrong
1801func Test_prop_one_line_window()
1802 enew
1803 call range(2)->setline(1)
1804 call prop_type_add('testprop', {})
1805 call prop_add(1, 1, {'type': 'testprop'})
1806 call popup_create('popup', {'textprop': 'testprop'})
1807 $
1808 new
1809 wincmd _
1810 call feedkeys("\r", 'xt')
1811 redraw
1812
1813 call popup_clear()
1814 call prop_type_delete('testprop')
1815 close
1816 bwipe!
1817endfunc
1818
Bram Moolenaarf05a1e52022-08-02 11:48:53 +01001819def Test_prop_column_zero_error()
1820 prop_type_add('proptype', {highlight: 'Search'})
1821 var caught = false
1822 try
1823 popup_create([{
1824 text: 'a',
1825 props: [{col: 0, length: 1, type: 'type'}],
1826 }], {})
1827 catch /E964:/
1828 caught = true
1829 endtry
1830 assert_true(caught)
1831
1832 popup_clear()
1833 prop_type_delete('proptype')
1834enddef
1835
Bram Moolenaar840f91f2021-05-26 22:32:10 +02001836" This was calling ml_append_int() and copy a text property from a previous
1837" line at the wrong moment. Exact text length matters.
1838def Test_prop_splits_data_block()
1839 new
1840 var lines: list<string> = [repeat('x', 35)]->repeat(41)
1841 + [repeat('!', 35)]
1842 + [repeat('x', 35)]->repeat(56)
1843 lines->setline(1)
1844 prop_type_add('someprop', {highlight: 'ErrorMsg'})
1845 prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'})
1846 prop_remove({type: 'someprop'}, 1)
1847 prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'})
1848 prop_remove({type: 'someprop'}, 35, 43)
1849 assert_equal([], prop_list(42))
1850
1851 bwipe!
1852 prop_type_delete('someprop')
1853enddef
1854
Bram Moolenaar4cd5c522021-06-27 13:04:00 +02001855" This was calling ml_delete_int() and try to change text properties.
1856def Test_prop_add_delete_line()
1857 new
1858 var a = 10
1859 var b = 20
1860 repeat([''], a)->append('$')
1861 prop_type_add('Test', {highlight: 'ErrorMsg'})
1862 for lnum in range(1, a)
1863 for col in range(1, b)
1864 prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'})
1865 endfor
1866 endfor
1867
1868 # check deleting lines is OK
1869 :5del
1870 :1del
1871 :$del
1872
1873 prop_type_delete('Test')
1874 bwipe!
1875enddef
1876
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001877" This test is to detect a regression related to #10430. It is not an attempt
1878" fully cover deleting lines in the presence of multi-line properties.
1879def Test_delete_line_within_multiline_prop()
1880 new
1881 setline(1, '# Top.')
1882 append(1, ['some_text = """', 'A string.', '"""', '# Bottom.'])
1883 prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1884 prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1885 prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9})
1886 prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4})
1887
1888 # The property for line 3 should extend into the previous and next lines.
1889 var props = prop_list(3)
1890 var prop = props[0]
1891 assert_equal(1, len(props))
1892 assert_equal(0, prop['start'])
1893 assert_equal(0, prop['end'])
1894
1895 # This deletion should run without raising an exception.
1896 try
1897 :2 del
1898 catch
1899 assert_report('Line delete should have workd, but it raised an error.')
1900 endtry
1901
1902 # The property for line 2 (was 3) should no longer extend into the previous
1903 # line.
1904 props = prop_list(2)
1905 prop = props[0]
1906 assert_equal(1, len(props))
1907 assert_equal(1, prop['start'], 'Property was not changed to start within the line.')
1908
1909 # This deletion should run without raising an exception.
1910 try
1911 :3 del
1912 catch
1913 assert_report('Line delete should have workd, but it raised an error.')
1914 endtry
1915
1916 # The property for line 2 (originally 3) should no longer extend into the next
1917 # line.
1918 props = prop_list(2)
1919 prop = props[0]
1920 assert_equal(1, len(props))
1921 assert_equal(1, prop['end'], 'Property was not changed to end within the line.')
1922
1923 prop_type_delete('Identifier')
1924 prop_type_delete('String')
1925 bwip!
1926enddef
1927
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001928func Test_prop_in_linebreak()
1929 CheckRunVimInTerminal
1930
1931 let lines =<< trim END
1932 set breakindent linebreak breakat+=]
1933 call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1)
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001934 call prop_type_add('test', #{highlight: 'MatchParen'})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001935 call prop_add(1, 51, #{length: 1, type: 'test'})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001936 func AddMatch()
1937 syntax on
1938 syntax match xTest /.*/
1939 hi link xTest Comment
1940 set signcolumn=yes
1941 endfunc
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001942 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001943 call writefile(lines, 'XscriptPropLinebreak', 'D')
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001944 let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001945 call VerifyScreenDump(buf, 'Test_prop_linebreak_1', {})
1946
1947 call term_sendkeys(buf, ":call AddMatch()\<CR>")
1948 call VerifyScreenDump(buf, 'Test_prop_linebreak_2', {})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001949
1950 call StopVimInTerminal(buf)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001951endfunc
1952
Bram Moolenaar52de3a82022-08-10 13:12:03 +01001953func Test_prop_with_linebreak()
1954 CheckRunVimInTerminal
1955
1956 let lines =<< trim END
1957 vim9script
1958 set linebreak
1959 setline(1, 'one twoword')
1960 prop_type_add('test', {highlight: 'Special'})
1961 prop_add(1, 4, {text: ': virtual text', type: 'test', text_wrap: 'wrap'})
1962 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001963 call writefile(lines, 'XscriptPropWithLinebreak', 'D')
Bram Moolenaar52de3a82022-08-10 13:12:03 +01001964 let buf = RunVimInTerminal('-S XscriptPropWithLinebreak', #{rows: 6, cols: 50})
1965 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_1', {})
1966 call term_sendkeys(buf, "iasdf asdf asdf asdf asdf as\<Esc>")
1967 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_2', {})
1968
1969 call StopVimInTerminal(buf)
Bram Moolenaar52de3a82022-08-10 13:12:03 +01001970endfunc
1971
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001972func Test_prop_with_wrap()
1973 CheckRunVimInTerminal
1974
1975 let lines =<< trim END
1976 vim9script
1977 set linebreak
1978 setline(1, 'asdf '->repeat(15))
1979 prop_type_add('test', {highlight: 'Special'})
1980 prop_add(1, 43, {text: 'some virtual text', type: 'test'})
1981 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001982 call writefile(lines, 'XscriptPropWithWrap', 'D')
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001983 let buf = RunVimInTerminal('-S XscriptPropWithWrap', #{rows: 6, cols: 50})
1984 call VerifyScreenDump(buf, 'Test_prop_with_wrap_1', {})
1985
1986 call StopVimInTerminal(buf)
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001987endfunc
1988
Bram Moolenaar42eba042021-11-30 20:22:49 +00001989func Test_prop_after_tab()
1990 CheckRunVimInTerminal
1991
1992 let lines =<< trim END
1993 set breakindent linebreak breakat+=]
1994 call setline(1, "\t[xxx]")
1995 call prop_type_add('test', #{highlight: 'ErrorMsg'})
1996 call prop_add(1, 2, #{length: 1, type: 'test'})
1997 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001998 call writefile(lines, 'XscriptPropAfterTab', 'D')
Bram Moolenaar42eba042021-11-30 20:22:49 +00001999 let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10})
Bram Moolenaar42eba042021-11-30 20:22:49 +00002000 call VerifyScreenDump(buf, 'Test_prop_after_tab', {})
2001
2002 call StopVimInTerminal(buf)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002003endfunc
2004
Bram Moolenaare428fa02022-08-09 16:55:41 +01002005func Test_prop_before_tab()
2006 CheckRunVimInTerminal
2007
2008 let lines =<< trim END
2009 call setline(1, ["\tx"]->repeat(6))
2010 call prop_type_add('test', #{highlight: 'Search'})
2011 call prop_add(1, 1, #{type: 'test', text: '123'})
2012 call prop_add(2, 1, #{type: 'test', text: '1234567'})
2013 call prop_add(3, 1, #{type: 'test', text: '12345678'})
2014 call prop_add(4, 1, #{type: 'test', text: '123456789'})
2015 call prop_add(5, 2, #{type: 'test', text: 'ABC'})
2016 call prop_add(6, 3, #{type: 'test', text: 'ABC'})
2017 normal gg0
2018 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002019 call writefile(lines, 'XscriptPropBeforeTab', 'D')
Bram Moolenaare428fa02022-08-09 16:55:41 +01002020 let buf = RunVimInTerminal('-S XscriptPropBeforeTab', #{rows: 8})
2021 call VerifyScreenDump(buf, 'Test_prop_before_tab_01', {})
2022 call term_sendkeys(buf, "$")
2023 call VerifyScreenDump(buf, 'Test_prop_before_tab_02', {})
2024 call term_sendkeys(buf, "j0")
2025 call VerifyScreenDump(buf, 'Test_prop_before_tab_03', {})
2026 call term_sendkeys(buf, "$")
2027 call VerifyScreenDump(buf, 'Test_prop_before_tab_04', {})
2028 call term_sendkeys(buf, "j0")
2029 call VerifyScreenDump(buf, 'Test_prop_before_tab_05', {})
2030 call term_sendkeys(buf, "$")
2031 call VerifyScreenDump(buf, 'Test_prop_before_tab_06', {})
2032 call term_sendkeys(buf, "j0")
2033 call VerifyScreenDump(buf, 'Test_prop_before_tab_07', {})
2034 call term_sendkeys(buf, "$")
2035 call VerifyScreenDump(buf, 'Test_prop_before_tab_08', {})
2036 call term_sendkeys(buf, "j")
2037 call VerifyScreenDump(buf, 'Test_prop_before_tab_09', {})
2038 call term_sendkeys(buf, "j")
2039 call VerifyScreenDump(buf, 'Test_prop_before_tab_10', {})
2040
2041 call StopVimInTerminal(buf)
Bram Moolenaare428fa02022-08-09 16:55:41 +01002042endfunc
2043
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002044func Test_prop_after_linebreak()
2045 CheckRunVimInTerminal
2046
2047 let lines =<< trim END
2048 set linebreak wrap
2049 call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1)
2050 call prop_type_add('test', #{highlight: 'ErrorMsg'})
2051 call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'})
2052 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002053 call writefile(lines, 'XscriptPropAfterLinebreak', 'D')
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002054 let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10})
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002055 call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {})
2056
2057 call StopVimInTerminal(buf)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002058endfunc
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
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002523 call writefile(lines, 'XscriptPropsWithText', 'D')
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)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002542endfunc
2543
Bram Moolenaare38fc862022-08-11 17:24:50 +01002544func Test_prop_inserts_text_highlight()
2545 CheckRunVimInTerminal
2546
2547 " Just a basic check for now
2548 let lines =<< trim END
2549 call setline(1, 'insert some text (here) and there')
2550 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2551 let bef_prop = prop_add(1, 18, #{type: 'someprop', text: 'BEFORE'})
2552 set hlsearch
2553 let thematch = matchaddpos("DiffAdd", [[1, 18]])
2554 func DoAfter()
2555 call prop_remove(#{id: g:bef_prop})
2556 call prop_add(1, 19, #{type: 'someprop', text: 'AFTER'})
2557 let g:thematch = matchaddpos("DiffAdd", [[1, 18]])
2558 let @/ = ''
2559 endfunc
2560 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002561 call writefile(lines, 'XscriptPropsWithHighlight', 'D')
Bram Moolenaare38fc862022-08-11 17:24:50 +01002562 let buf = RunVimInTerminal('-S XscriptPropsWithHighlight', #{rows: 6, cols: 60})
2563 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_1', {})
2564 call term_sendkeys(buf, "/text (he\<CR>")
2565 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_2', {})
2566 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2567 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_3', {})
2568
2569 call term_sendkeys(buf, ":call DoAfter()\<CR>")
2570 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_4', {})
2571 call term_sendkeys(buf, "/text (he\<CR>")
2572 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_5', {})
2573 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2574 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_6', {})
2575
2576 call StopVimInTerminal(buf)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002577endfunc
2578
Bram Moolenaarfb593c52022-09-17 18:57:36 +01002579func Test_prop_add_with_text_fails()
2580 call prop_type_add('failing', #{highlight: 'ErrorMsg'})
2581 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_lnum: 1})", 'E1305:')
2582 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_col: 1})", 'E1305:')
2583 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', length: 1})", 'E1305:')
2584
2585 call prop_type_delete('failing')
2586endfunc
2587
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002588func Test_props_with_text_right_align_twice()
2589 CheckRunVimInTerminal
2590
2591 let lines =<< trim END
2592 call setline(1, ["some text some text some text some text", 'line two'])
Bram Moolenaarfb593c52022-09-17 18:57:36 +01002593 call prop_type_add('MyErrorText', #{highlight: 'ErrorMsg'})
2594 call prop_type_add('MyPadding', #{highlight: 'DiffChange'})
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002595 call prop_add(1, 0, #{type: 'MyPadding', text: ' nothing here', text_wrap: 'wrap'})
2596 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Some error', text_wrap: 'wrap', text_align: 'right'})
2597 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Another error', text_wrap: 'wrap', text_align: 'right'})
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002598 normal G$
2599 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002600 call writefile(lines, 'XscriptPropsRightAlign', 'D')
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002601 let buf = RunVimInTerminal('-S XscriptPropsRightAlign', #{rows: 8})
2602 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_1', {})
2603
2604 call term_sendkeys(buf, "ggisome more text\<Esc>G$")
2605 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {})
2606
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002607 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2608 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_3', {})
2609
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002610 call StopVimInTerminal(buf)
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002611endfunc
2612
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002613func Test_props_with_text_after()
2614 CheckRunVimInTerminal
2615
2616 let lines =<< trim END
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002617 set showbreak=+++
Bram Moolenaar73c38422022-08-07 11:53:40 +01002618 set breakindent
2619 call setline(1, ' some text here and other text there')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002620 call prop_type_add('rightprop', #{highlight: 'ErrorMsg'})
2621 call prop_type_add('afterprop', #{highlight: 'Search'})
2622 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
2623 call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002624 call prop_add(1, 0, #{type: 'afterprop', text: "\tAFTER\t", text_align: 'after'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002625 call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'})
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002626 call prop_add(1, 0, #{type: 'belowprop', text: ' ALSO BELOW ', text_align: 'below'})
Bram Moolenaar84b247f2022-08-01 11:17:40 +01002627
2628 call setline(2, 'Last line.')
2629 call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'})
2630 normal G$
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002631
2632 call setline(3, 'right here')
2633 call prop_add(3, 0, #{type: 'rightprop', text: 'söme和平téxt', text_align: 'right'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002634 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002635 call writefile(lines, 'XscriptPropsWithTextAfter', 'D')
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002636 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002637 call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {})
2638
2639 call StopVimInTerminal(buf)
Bram Moolenaar82b14c12022-08-10 19:50:47 +01002640
2641 call assert_fails('call prop_add(1, 2, #{text: "yes", text_align: "right", type: "some"})', 'E1294:')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002642endfunc
2643
Bram Moolenaar877151b2022-10-11 15:29:50 +01002644func Test_props_with_text_after_and_list()
2645 CheckRunVimInTerminal
2646
2647 let lines =<< trim END
2648 vim9script
2649 setline(1, ['one', 'two'])
2650 prop_type_add('test', {highlight: 'Special'})
2651 prop_add(1, 0, {
2652 type: 'test',
2653 text: range(50)->join(' '),
2654 text_align: 'after',
2655 text_padding_left: 3
2656 })
2657 prop_add(1, 0, {
2658 type: 'test',
2659 text: range(50)->join('-'),
2660 text_align: 'after',
2661 text_padding_left: 5
2662 })
2663 prop_add(1, 0, {
2664 type: 'test',
2665 text: range(50)->join('.'),
2666 text_align: 'after',
2667 text_padding_left: 1
2668 })
2669 normal G$
2670 END
2671 call writefile(lines, 'XscriptPropsAfter', 'D')
2672 let buf = RunVimInTerminal('-S XscriptPropsAfter', #{rows: 8, cols: 60})
2673 call VerifyScreenDump(buf, 'Test_props_after_1', {})
2674
2675 call term_sendkeys(buf, ":set list\<CR>")
2676 call VerifyScreenDump(buf, 'Test_props_after_2', {})
2677
2678 call StopVimInTerminal(buf)
2679endfunc
2680
Bram Moolenaarcba69522022-08-06 21:03:53 +01002681func Test_props_with_text_after_below_trunc()
2682 CheckRunVimInTerminal
2683
2684 let lines =<< trim END
2685 vim9script
2686 edit foobar
2687 set showbreak=+++
2688 setline(1, ['onasdf asdf asdf asdf asd fas df', 'two'])
2689 prop_type_add('test', {highlight: 'Special'})
2690 prop_add(1, 0, {
2691 type: 'test',
2692 text: 'the quick brown fox jumps over the lazy dog',
2693 text_align: 'after'
2694 })
2695 prop_add(1, 0, {
2696 type: 'test',
2697 text: 'the quick brown fox jumps over the lazy dog',
2698 text_align: 'below'
2699 })
2700 normal G$
2701 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002702 call writefile(lines, 'XscriptPropsAfterTrunc', 'D')
Bram Moolenaarcba69522022-08-06 21:03:53 +01002703 let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60})
2704 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {})
2705
Bram Moolenaarccf28372022-10-10 21:10:03 +01002706 call term_sendkeys(buf, ":set number\<CR>")
2707 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_2', {})
2708
Bram Moolenaarcba69522022-08-06 21:03:53 +01002709 call StopVimInTerminal(buf)
Bram Moolenaarcba69522022-08-06 21:03:53 +01002710endfunc
2711
Bram Moolenaare175dc62022-08-01 22:18:50 +01002712func Test_props_with_text_after_joined()
2713 CheckRunVimInTerminal
2714
2715 let lines =<< trim END
2716 call setline(1, ['one', 'two', 'three', 'four'])
2717 call prop_type_add('afterprop', #{highlight: 'Search'})
2718 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'})
2719 call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'})
2720 normal ggJ
2721 normal GkJ
2722
2723 call setline(3, ['a', 'b', 'c', 'd', 'e', 'f'])
2724 call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'})
2725 call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'})
2726 call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'})
2727 call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'})
2728 normal 3G6J
2729 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002730 call writefile(lines, 'XscriptPropsWithTextAfterJoined', 'D')
Bram Moolenaare175dc62022-08-01 22:18:50 +01002731 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60})
2732 call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {})
2733
2734 call StopVimInTerminal(buf)
Bram Moolenaare175dc62022-08-01 22:18:50 +01002735endfunc
2736
Bram Moolenaar398649e2022-08-04 15:03:48 +01002737func Test_props_with_text_after_truncated()
2738 CheckRunVimInTerminal
2739
2740 let lines =<< trim END
2741 call setline(1, ['one two three four five six seven'])
2742 call prop_type_add('afterprop', #{highlight: 'Search'})
2743 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
2744
2745 call setline(2, ['one two three four five six seven'])
2746 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
2747
2748 call setline(3, ['one two three four five six seven'])
2749 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'})
2750
2751 call setline(4, ['cursor here'])
2752 normal 4Gfh
2753 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002754 call writefile(lines, 'XscriptPropsWithTextAfterTrunc', 'D')
Bram Moolenaar398649e2022-08-04 15:03:48 +01002755 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60})
2756 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {})
2757
2758 call term_sendkeys(buf, ":37vsp\<CR>gg")
2759 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {})
2760
2761 call term_sendkeys(buf, ":36wincmd |\<CR>")
2762 call term_sendkeys(buf, "2G$")
2763 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {})
2764
2765 call term_sendkeys(buf, ":33wincmd |\<CR>")
2766 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {})
2767
2768 call term_sendkeys(buf, ":18wincmd |\<CR>")
2769 call term_sendkeys(buf, "0fx")
2770 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {})
2771
2772 call StopVimInTerminal(buf)
Bram Moolenaar398649e2022-08-04 15:03:48 +01002773endfunc
2774
Bram Moolenaar49a90792022-08-09 18:25:23 +01002775func Test_props_with_text_empty_line()
2776 CheckRunVimInTerminal
2777
2778 let lines =<< trim END
2779 call setline(1, ['', 'aaa', '', 'bbbbbb'])
2780 call prop_type_add('prop1', #{highlight: 'Search'})
2781 call prop_add(1, 1, #{type: 'prop1', text_wrap: 'wrap', text: repeat('X', &columns)})
2782 call prop_add(3, 1, #{type: 'prop1', text_wrap: 'wrap', text: repeat('X', &columns + 1)})
2783 normal gg0
2784 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002785 call writefile(lines, 'XscriptPropsWithTextEmptyLine', 'D')
Bram Moolenaar49a90792022-08-09 18:25:23 +01002786 let buf = RunVimInTerminal('-S XscriptPropsWithTextEmptyLine', #{rows: 8, cols: 60})
2787 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_1', {})
2788 call term_sendkeys(buf, "$")
2789 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_2', {})
2790 call term_sendkeys(buf, "j")
2791 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_3', {})
2792 call term_sendkeys(buf, "j")
2793 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_4', {})
2794 call term_sendkeys(buf, "j")
2795 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_5', {})
2796
2797 call StopVimInTerminal(buf)
Bram Moolenaar49a90792022-08-09 18:25:23 +01002798endfunc
2799
Bram Moolenaar398649e2022-08-04 15:03:48 +01002800func Test_props_with_text_after_wraps()
2801 CheckRunVimInTerminal
2802
2803 let lines =<< trim END
2804 call setline(1, ['one two three four five six seven'])
2805 call prop_type_add('afterprop', #{highlight: 'Search'})
2806 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'})
2807
2808 call setline(2, ['one two three four five six seven'])
2809 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'})
2810
2811 call setline(3, ['one two three four five six seven'])
2812 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'})
2813
2814 call setline(4, ['cursor here'])
2815 normal 4Gfh
2816 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002817 call writefile(lines, 'XscriptPropsWithTextAfterWraps', 'D')
Bram Moolenaar398649e2022-08-04 15:03:48 +01002818 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60})
2819 call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {})
2820
2821 call StopVimInTerminal(buf)
Bram Moolenaar398649e2022-08-04 15:03:48 +01002822endfunc
2823
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824func Test_props_with_text_after_nowrap()
2825 CheckRunVimInTerminal
2826
2827 let lines =<< trim END
2828 set nowrap
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01002829 call setline(1, ['one', 'two', 'three', 'four'])
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002830 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
2831 call prop_type_add('anotherprop', #{highlight: 'Search'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01002832 call prop_type_add('someprop', #{highlight: 'DiffChange'})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002833 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
2834 call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'})
2835 call prop_add(2, 0, #{type: 'belowprop', text: 'One More Here', text_align: 'below'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01002836 call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'})
2837 call prop_add(1, 0, #{type: 'someprop', text: ' After the text', text_align: 'after'})
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01002838 normal 3G$
2839
2840 call prop_add(3, 0, #{type: 'anotherprop', text: 'right aligned', text_align: 'right'})
2841 call prop_add(3, 0, #{type: 'anotherprop', text: 'also right aligned', text_align: 'right'})
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002842 hi CursorLine ctermbg=lightgrey
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002843 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002844 call writefile(lines, 'XscriptPropsAfterNowrap', 'D')
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01002845 let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 12, cols: 60})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002846 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {})
2847
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002848 call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\<CR>")
Bram Moolenaar1306b362022-08-06 15:59:06 +01002849 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {})
2850
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01002851 call term_sendkeys(buf, "j")
2852 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_3', {})
2853
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002854 call StopVimInTerminal(buf)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002855endfunc
2856
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002857func Test_props_with_text_below_nowrap()
2858 CheckRunVimInTerminal
2859
2860 let lines =<< trim END
2861 vim9script
2862 edit foobar
2863 set nowrap
2864 set showbreak=+++\
2865 setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two'])
2866 prop_type_add('test', {highlight: 'Special'})
2867 prop_add(1, 0, {
2868 type: 'test',
2869 text: 'the quick brown fox jumps over the lazy dog',
2870 text_align: 'after'
2871 })
2872 prop_add(1, 0, {
2873 type: 'test',
2874 text: 'the quick brown fox jumps over the lazy dog',
2875 text_align: 'below'
2876 })
2877 normal G$
2878 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002879 call writefile(lines, 'XscriptPropsBelowNowrap', 'D')
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002880 let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60})
2881 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {})
2882
2883 call term_sendkeys(buf, "gg$")
2884 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {})
2885
2886 call StopVimInTerminal(buf)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002887endfunc
2888
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002889func Test_props_with_text_above()
2890 CheckRunVimInTerminal
2891
2892 let lines =<< trim END
2893 call setline(1, ['one two', 'three four', 'five six'])
2894 call prop_type_add('above1', #{highlight: 'Search'})
2895 call prop_type_add('above2', #{highlight: 'DiffChange'})
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002896 call prop_type_add('below', #{highlight: 'DiffAdd'})
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002897 call prop_add(1, 0, #{type: 'above1', text: 'first thing above', text_align: 'above'})
2898 call prop_add(1, 0, #{type: 'above2', text: 'second thing above', text_align: 'above'})
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002899 call prop_add(3, 0, #{type: 'above1', text: 'another thing', text_align: 'above', text_padding_left: 3})
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002900
2901 normal gglllj
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002902 func AddPropBelow()
2903 call prop_add(1, 0, #{type: 'below', text: 'below', text_align: 'below'})
2904 endfunc
Bram Moolenaar9466fb82022-10-11 14:54:42 +01002905 func AddLongPropAbove()
2906 3,4delete
2907 set wrap
2908 call prop_add(1, 0, #{type: 'above1', text: range(50)->join(' '), text_align: 'above', text_padding_left: 2})
2909 endfunc
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002910 END
2911 call writefile(lines, 'XscriptPropsWithTextAbove', 'D')
2912 let buf = RunVimInTerminal('-S XscriptPropsWithTextAbove', #{rows: 9, cols: 60})
2913 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1', {})
2914
Bram Moolenaare24b4ab2022-09-16 20:51:14 +01002915 call term_sendkeys(buf, "ggg$")
2916 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1a', {})
2917 call term_sendkeys(buf, "g0")
2918 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1b', {})
2919
Bram Moolenaar4c7fd4d2022-09-17 17:15:33 +01002920 call term_sendkeys(buf, ":set showbreak=>>\<CR>")
2921 call term_sendkeys(buf, "ggll")
2922 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1c', {})
2923 call term_sendkeys(buf, ":set showbreak=\<CR>")
2924
Bram Moolenaar88b79cb2022-09-10 22:32:14 +01002925 call term_sendkeys(buf, "ggI")
2926 call VerifyScreenDump(buf, 'Test_prop_with_text_above_2', {})
2927 call term_sendkeys(buf, "inserted \<Esc>")
2928 call VerifyScreenDump(buf, 'Test_prop_with_text_above_3', {})
2929
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002930 call term_sendkeys(buf, ":set number signcolumn=yes\<CR>")
2931 call VerifyScreenDump(buf, 'Test_prop_with_text_above_4', {})
2932
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002933 call term_sendkeys(buf, ":set nowrap\<CR>gg$j")
2934 call VerifyScreenDump(buf, 'Test_prop_with_text_above_5', {})
2935
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002936 call term_sendkeys(buf, ":call AddPropBelow()\<CR>")
2937 call term_sendkeys(buf, "ggve")
2938 call VerifyScreenDump(buf, 'Test_prop_with_text_above_6', {})
2939 call term_sendkeys(buf, "V")
2940 call VerifyScreenDump(buf, 'Test_prop_with_text_above_7', {})
2941
Bram Moolenaar3b93cf22022-09-13 18:34:18 +01002942 call term_sendkeys(buf, "\<Esc>ls\<CR>\<Esc>")
2943 call VerifyScreenDump(buf, 'Test_prop_with_text_above_8', {})
2944
Bram Moolenaar9466fb82022-10-11 14:54:42 +01002945 call term_sendkeys(buf, ":call AddLongPropAbove()\<CR>")
2946 call VerifyScreenDump(buf, 'Test_prop_with_text_above_9', {})
2947
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002948 call StopVimInTerminal(buf)
2949endfunc
2950
Bram Moolenaar702bd6c2022-09-14 16:09:57 +01002951func Test_prop_above_with_indent()
2952 new
2953 call setline(1, ['first line', ' second line', ' line below'])
2954 setlocal cindent
2955 call prop_type_add('indented', #{highlight: 'Search'})
2956 call prop_add(3, 0, #{type: 'indented', text: 'here', text_align: 'above', text_padding_left: 4})
2957 call assert_equal(' line below', getline(3))
2958
2959 exe "normal 3G2|a\<CR>"
2960 call assert_equal(' ', getline(3))
2961 call assert_equal(' line below', getline(4))
2962
2963 bwipe!
2964 call prop_type_delete('indented')
2965endfunc
2966
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01002967func Test_prop_above_with_number()
2968 CheckRunVimInTerminal
2969
2970 let lines =<< trim END
2971 vim9script
2972 setline(1, ['one one one', 'two two two', 'three three three'])
2973 set number cpo+=n
2974 prop_type_add('test', {highlight: 'DiffChange'})
2975 prop_add(2, 0, {
2976 text: 'above the text',
2977 type: 'test',
2978 text_align: 'above',
2979 })
2980 def g:OneMore()
2981 prop_add(2, 0, {
2982 text: 'also above the text',
2983 type: 'test',
2984 text_align: 'above',
2985 })
2986 enddef
2987 END
2988 call writefile(lines, 'XscriptPropAboveNr', 'D')
2989 let buf = RunVimInTerminal('-S XscriptPropAboveNr', #{rows: 8})
2990 call VerifyScreenDump(buf, 'Test_prop_above_number_1', {})
2991
2992 call term_sendkeys(buf, ":call OneMore()\<CR>")
2993 call VerifyScreenDump(buf, 'Test_prop_above_number_2', {})
2994
2995 call StopVimInTerminal(buf)
2996endfunc
2997
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01002998func Test_prop_below_split_line()
2999 CheckRunVimInTerminal
3000
3001 let lines =<< trim END
3002 vim9script
3003 setline(1, ['one one one', 'two two two', 'three three three'])
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003004 prop_type_add('test', {highlight: 'Search'})
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003005 prop_add(2, 0, {
3006 text: '└─ Virtual text below the 2nd line',
3007 type: 'test',
3008 text_align: 'below',
3009 text_padding_left: 3
3010 })
3011 END
3012 call writefile(lines, 'XscriptPropBelowSpitLine', 'D')
3013 let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8})
3014 call term_sendkeys(buf, "2GA\<CR>xx")
3015 call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {})
3016
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003017 call term_sendkeys(buf, "\<Esc>:set number\<CR>")
3018 call VerifyScreenDump(buf, 'Test_prop_below_split_line_2', {})
3019
Bram Moolenaarb84d5652022-09-20 17:57:53 +01003020 call term_sendkeys(buf, ":set nowrap\<CR>")
3021 call VerifyScreenDump(buf, 'Test_prop_below_split_line_3', {})
3022
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003023 call StopVimInTerminal(buf)
3024endfunc
3025
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003026func Test_props_with_text_override()
3027 CheckRunVimInTerminal
3028
3029 let lines =<< trim END
3030 vim9script
3031 setline(1, 'some text here')
3032 hi Likethis ctermfg=blue ctermbg=cyan
3033 prop_type_add('prop', {highlight: 'Likethis', override: true})
3034 prop_add(1, 6, {type: 'prop', text: ' inserted '})
3035 hi CursorLine cterm=underline ctermbg=lightgrey
3036 set cursorline
3037 END
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003038 call writefile(lines, 'XscriptPropsOverride', 'D')
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003039 let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60})
3040 call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {})
3041
3042 call term_sendkeys(buf, ":set nocursorline\<CR>")
3043 call term_sendkeys(buf, "0llvfr")
3044 call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {})
3045
3046 call StopVimInTerminal(buf)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003047endfunc
3048
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003049func Test_props_with_text_CursorMoved()
3050 CheckRunVimInTerminal
3051
3052 let lines =<< trim END
3053 call setline(1, ['this is line one', 'this is line two', 'three', 'four', 'five'])
3054
3055 call prop_type_add('prop', #{highlight: 'Error'})
3056 let g:long_text = repeat('x', &columns * 2)
3057
3058 let g:prop_id = v:null
3059 func! Update()
3060 if line('.') == 1
3061 if g:prop_id == v:null
3062 let g:prop_id = prop_add(1, 0, #{type: 'prop', text_wrap: 'wrap', text: g:long_text})
3063 endif
3064 elseif g:prop_id != v:null
3065 call prop_remove(#{id: g:prop_id})
3066 let g:prop_id = v:null
3067 endif
3068 endfunc
3069
3070 autocmd CursorMoved * call Update()
3071 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003072 call writefile(lines, 'XscriptPropsCursorMovec', 'D')
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003073 let buf = RunVimInTerminal('-S XscriptPropsCursorMovec', #{rows: 8, cols: 60})
3074 call term_sendkeys(buf, "gg0w")
3075 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
3076
3077 call term_sendkeys(buf, "j")
3078 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_2', {})
3079
3080 " back to the first state
3081 call term_sendkeys(buf, "k")
3082 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
3083
3084 call StopVimInTerminal(buf)
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003085endfunc
3086
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003087func Test_props_with_text_after_split_join()
3088 CheckRunVimInTerminal
3089
3090 let lines =<< trim END
3091 call setline(1, ['1122'])
3092 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
3093 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
3094 exe "normal f2i\<CR>\<Esc>"
3095
3096 func AddMore()
3097 call prop_type_add('another', #{highlight: 'Search'})
3098 call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'})
3099 call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'})
3100 endfunc
3101 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003102 call writefile(lines, 'XscriptPropsAfterSplitJoin', 'D')
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003103 let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60})
3104 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {})
3105
3106 call term_sendkeys(buf, "ggJ")
3107 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {})
3108
3109 call term_sendkeys(buf, ":call AddMore()\<CR>")
3110 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {})
3111
3112 call term_sendkeys(buf, "ggf s\<CR>\<Esc>")
3113 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {})
3114
3115 call term_sendkeys(buf, "ggJ")
3116 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {})
3117
3118 call StopVimInTerminal(buf)
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003119endfunc
3120
Bram Moolenaar3a4cd392022-07-30 22:17:18 +01003121func Test_removed_prop_with_text_cleans_up_array()
3122 new
3123 call setline(1, 'some text here')
3124 call prop_type_add('some', #{highlight: 'ErrorMsg'})
3125 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
3126 call assert_equal(-1, id1)
3127 let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"})
3128 call assert_equal(-2, id2)
3129
3130 " removing the props resets the index
3131 call prop_remove(#{id: id1})
3132 call prop_remove(#{id: id2})
3133 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
3134 call assert_equal(-1, id1)
3135
3136 call prop_type_delete('some')
3137 bwipe!
3138endfunc
3139
Bram Moolenaar1f4ee192022-08-01 15:52:55 +01003140def Test_insert_text_before_virtual_text()
3141 new foobar
3142 setline(1, '12345678')
3143 prop_type_add('test', {highlight: 'Search'})
3144 prop_add(1, 5, {
3145 type: 'test',
3146 text: ' virtual text '
3147 })
3148 normal! f4axyz
3149 normal! f5iXYZ
3150 assert_equal('1234xyzXYZ5678', getline(1))
3151
3152 prop_type_delete('test')
3153 bwipe!
3154enddef
3155
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003156func Test_insert_text_start_incl()
3157 CheckRunVimInTerminal
3158
3159 let lines =<< trim END
3160 vim9script
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003161 setline(1, ['text one text two', '', 'function(arg)'])
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003162
3163 prop_type_add('propincl', {highlight: 'NonText', start_incl: true})
3164 prop_add(1, 6, {type: 'propincl', text: 'after '})
3165 cursor(1, 6)
3166 prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false})
3167 prop_add(1, 15, {type: 'propnotincl', text: 'before '})
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003168
3169 set cindent sw=4
3170 prop_type_add('argname', {highlight: 'DiffChange', start_incl: true})
3171 prop_add(3, 10, {type: 'argname', text: 'arg: '})
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003172 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003173 call writefile(lines, 'XscriptPropsStartIncl', 'D')
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003174 let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60})
3175 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {})
3176
3177 call term_sendkeys(buf, "i")
3178 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {})
3179 call term_sendkeys(buf, "xx\<Esc>")
3180 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {})
3181
3182 call term_sendkeys(buf, "2wi")
3183 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {})
3184 call term_sendkeys(buf, "yy\<Esc>")
3185 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {})
3186
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003187 call term_sendkeys(buf, "3Gfai\<CR>\<Esc>")
3188 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_6', {})
3189 call term_sendkeys(buf, ">>")
3190 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_7', {})
3191 call term_sendkeys(buf, "<<<<")
3192 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_8', {})
3193
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003194 call StopVimInTerminal(buf)
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003195endfunc
3196
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003197func Test_insert_text_list_mode()
3198 CheckRunVimInTerminal
3199
3200 let lines =<< trim END
3201 vim9script
3202 setline(1, ['This is a line with quite a bit of text here.',
3203 'second line', 'third line'])
3204 set list listchars+=extends:»
3205 prop_type_add('Prop1', {highlight: 'Error'})
3206 prop_add(1, 0, {
3207 type: 'Prop1',
3208 text: 'The quick brown fox jumps over the lazy dog',
3209 text_align: 'right'
3210 })
3211 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003212 call writefile(lines, 'XscriptPropsListMode', 'D')
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003213 let buf = RunVimInTerminal('-S XscriptPropsListMode', #{rows: 8, cols: 60})
3214 call term_sendkeys(buf, "ggj")
3215 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_1', {})
3216
3217 call term_sendkeys(buf, ":set nowrap\<CR>")
3218 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_2', {})
3219
3220 call term_sendkeys(buf, "ggd32l")
3221 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_3', {})
3222
3223 call StopVimInTerminal(buf)
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003224endfunc
3225
Bram Moolenaarf396ce82022-08-23 18:39:37 +01003226func Test_insert_text_with_padding()
3227 CheckRunVimInTerminal
3228
3229 let lines =<< trim END
3230 vim9script
3231 setline(1, ['Some text to add virtual text to.',
3232 'second line',
3233 'Another line with some text to make the wrap.'])
3234 prop_type_add('theprop', {highlight: 'DiffChange'})
3235 prop_add(1, 0, {
3236 type: 'theprop',
3237 text: 'after',
3238 text_align: 'after',
3239 text_padding_left: 3,
3240 })
3241 prop_add(1, 0, {
3242 type: 'theprop',
3243 text: 'right aligned',
3244 text_align: 'right',
3245 text_padding_left: 5,
3246 })
3247 prop_add(1, 0, {
3248 type: 'theprop',
3249 text: 'below the line',
3250 text_align: 'below',
3251 text_padding_left: 4,
3252 })
3253 prop_add(3, 0, {
3254 type: 'theprop',
3255 text: 'rightmost',
3256 text_align: 'right',
3257 text_padding_left: 6,
3258 text_wrap: 'wrap',
3259 })
3260 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003261 call writefile(lines, 'XscriptPropsPadded', 'D')
Bram Moolenaarf396ce82022-08-23 18:39:37 +01003262 let buf = RunVimInTerminal('-S XscriptPropsPadded', #{rows: 8, cols: 60})
3263 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_1', {})
3264
3265 call term_sendkeys(buf, "ggixxxxxxxxxx\<Esc>")
3266 call term_sendkeys(buf, "3Gix\<Esc>")
3267 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_2', {})
3268
3269 call term_sendkeys(buf, "ggix\<Esc>")
3270 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_3', {})
3271
Bram Moolenaara4abe512022-09-15 19:44:09 +01003272 call term_sendkeys(buf, ":set list\<CR>")
3273 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_4', {})
3274
Bram Moolenaarf396ce82022-08-23 18:39:37 +01003275 call StopVimInTerminal(buf)
Bram Moolenaarf396ce82022-08-23 18:39:37 +01003276endfunc
3277
Bram Moolenaar13845c42022-10-09 15:26:03 +01003278func Test_long_text_below_with_padding()
3279 CheckRunVimInTerminal
3280
3281 let lines =<< trim END
3282 vim9script
3283 setline(1, ['first line', 'second line'])
3284 prop_type_add('theprop', {highlight: 'DiffChange'})
3285 prop_add(1, 0, {
3286 type: 'theprop',
3287 text: 'after '->repeat(20),
3288 text_align: 'below',
3289 text_padding_left: 3,
3290 })
3291 prop_add(1, 0, {
3292 type: 'theprop',
3293 text: 'more '->repeat(20),
3294 text_align: 'below',
3295 text_padding_left: 30,
3296 })
3297 normal 2Gw
3298 END
3299 call writefile(lines, 'XlongTextBelowWithPadding', 'D')
3300 let buf = RunVimInTerminal('-S XlongTextBelowWithPadding', #{rows: 8, cols: 60})
3301 call VerifyScreenDump(buf, 'Test_long_text_with_padding_1', {})
3302
Bram Moolenaara9a36482022-10-11 16:47:22 +01003303 call term_sendkeys(buf, ":set list\<CR>")
3304 call VerifyScreenDump(buf, 'Test_long_text_with_padding_2', {})
3305
Bram Moolenaar13845c42022-10-09 15:26:03 +01003306 call StopVimInTerminal(buf)
3307endfunc
3308
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01003309func Test_text_after_nowrap()
3310 CheckRunVimInTerminal
3311
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01003312 let lines =<< trim END
3313 vim9script
Bram Moolenaarcd105412022-10-10 19:50:42 +01003314 setline(1, ['first line', range(80)->join(' '), 'third', 'fourth'])
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01003315 set nowrap
3316 prop_type_add('theprop', {highlight: 'DiffChange'})
3317 prop_add(1, 0, {
3318 type: 'theprop',
Bram Moolenaarcd105412022-10-10 19:50:42 +01003319 text: 'right after the text '->repeat(3),
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01003320 text_align: 'after',
3321 text_padding_left: 2,
3322 })
Bram Moolenaarcd105412022-10-10 19:50:42 +01003323 prop_add(1, 0, {
3324 type: 'theprop',
3325 text: 'in the middle '->repeat(4),
3326 text_align: 'after',
3327 text_padding_left: 3,
3328 })
3329 prop_add(1, 0, {
3330 type: 'theprop',
3331 text: 'the last one '->repeat(3),
3332 text_align: 'after',
3333 text_padding_left: 1,
3334 })
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01003335 normal 2Gw
Bram Moolenaar7e017462022-10-11 21:02:09 +01003336 def g:ChangeText()
3337 prop_clear(1)
3338 set list
3339 prop_add(1, 0, {
3340 type: 'theprop',
3341 text: 'just after txt '->repeat(3),
3342 text_align: 'after',
3343 text_padding_left: 2,
3344 })
3345 prop_add(1, 0, {
3346 type: 'theprop',
3347 text: 'in the middle '->repeat(4),
3348 text_align: 'after',
3349 text_padding_left: 1,
3350 })
3351 enddef
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01003352 END
3353 call writefile(lines, 'XTextAfterNowrap', 'D')
3354 let buf = RunVimInTerminal('-S XTextAfterNowrap', #{rows: 8, cols: 60})
3355 call VerifyScreenDump(buf, 'Test_text_after_nowrap_1', {})
3356
Bram Moolenaarcd105412022-10-10 19:50:42 +01003357 call term_sendkeys(buf, "30w")
3358 call VerifyScreenDump(buf, 'Test_text_after_nowrap_2', {})
3359
3360 call term_sendkeys(buf, "22w")
3361 call VerifyScreenDump(buf, 'Test_text_after_nowrap_3', {})
3362
3363 call term_sendkeys(buf, "$")
3364 call VerifyScreenDump(buf, 'Test_text_after_nowrap_4', {})
3365
Bram Moolenaar7e017462022-10-11 21:02:09 +01003366 call term_sendkeys(buf, "0")
3367 call term_sendkeys(buf, ":call ChangeText()\<CR>")
3368 call VerifyScreenDump(buf, 'Test_text_after_nowrap_5', {})
3369
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01003370 call StopVimInTerminal(buf)
3371endfunc
3372
Bram Moolenaar1206c162022-10-10 15:40:04 +01003373func Test_text_below_nowrap()
3374 CheckRunVimInTerminal
3375
3376 let lines =<< trim END
3377 vim9script
3378 setline(1, ['first line', 'second line '->repeat(50), 'third', 'fourth'])
3379 set nowrap number
3380 prop_type_add('theprop', {highlight: 'DiffChange'})
3381 prop_add(1, 0, {
3382 type: 'theprop',
3383 text: 'one below the text '->repeat(5),
3384 text_align: 'below',
3385 text_padding_left: 2,
3386 })
3387 prop_add(1, 0, {
3388 type: 'theprop',
3389 text: 'two below the text '->repeat(5),
3390 text_align: 'below',
3391 text_padding_left: 2,
3392 })
3393 normal 2Gw
3394 END
3395 call writefile(lines, 'XTextBelowNowrap', 'D')
3396 let buf = RunVimInTerminal('-S XTextBelowNowrap', #{rows: 8, cols: 60})
3397 call VerifyScreenDump(buf, 'Test_text_below_nowrap_1', {})
3398
3399 call StopVimInTerminal(buf)
3400endfunc
3401
Bram Moolenaarf5240b92022-08-24 12:24:37 +01003402func Test_insert_text_change_arg()
3403 CheckRunVimInTerminal
3404
3405 let lines =<< trim END
3406 vim9script
3407 setline(1, ['SetErrorCode( 10, 20 )', 'second line'])
3408 prop_type_add('param', {highlight: 'DiffChange', start_incl: 1})
3409 prop_type_add('padd', {highlight: 'NonText', start_incl: 1})
3410 prop_add(1, 15, {
3411 type: 'param',
3412 text: 'id:',
3413 })
3414 prop_add(1, 15, {
3415 type: 'padd',
3416 text: '-',
3417 })
3418 prop_add(1, 19, {
3419 type: 'param',
3420 text: 'id:',
3421 })
3422 prop_add(1, 19, {
3423 type: 'padd',
3424 text: '-',
3425 })
3426 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003427 call writefile(lines, 'XscriptPropsChange', 'D')
Bram Moolenaarf5240b92022-08-24 12:24:37 +01003428 let buf = RunVimInTerminal('-S XscriptPropsChange', #{rows: 5, cols: 60})
3429 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_1', {})
3430
3431 call term_sendkeys(buf, "ggf1cw1234\<Esc>")
3432 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_2', {})
3433
3434 call StopVimInTerminal(buf)
Bram Moolenaarf5240b92022-08-24 12:24:37 +01003435endfunc
3436
Bram Moolenaar99fa7212020-04-26 15:59:55 +02003437" vim: shiftwidth=2 sts=2 expandtab