blob: 22c7e4651bf481ebbf99b807e1cc8e12300cbded [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 Moolenaar51b2fc22023-01-21 15:54:59 +00001345 call writefile(lines, 'XtextPropTab', 'D')
1346 let buf = RunVimInTerminal('-S XtextPropTab', {'rows': 6})
Bram Moolenaara956bf62019-06-19 17:34:24 +02001347 call VerifyScreenDump(buf, 'Test_textprop_tab', {})
1348
1349 " clean up
1350 call StopVimInTerminal(buf)
Bram Moolenaara956bf62019-06-19 17:34:24 +02001351endfunc
1352
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00001353func Test_textprop_nesting()
1354 CheckScreendump
1355
1356 let lines =<< trim END
1357 vim9script
1358 var lines =<< trim LINESEND
1359
1360 const func: func.IFunction = ({
1361 setLoading
1362 }) => {
1363 LINESEND
1364 setline(1, lines)
1365 prop_type_add('prop_add_test', {highlight: "ErrorMsg"})
1366 prop_add(2, 31, {type: 'prop_add_test', end_lnum: 4, end_col: 2})
1367 var text = 'text long enough to wrap line, text long enough to wrap line, text long enough to wrap line...'
1368 prop_add(2, 0, {type: 'prop_add_test', text_wrap: 'truncate', text_align: 'after', text: text})
1369 END
1370 call writefile(lines, 'XtextpropNesting', 'D')
1371 let buf = RunVimInTerminal('-S XtextpropNesting', {'rows': 8})
1372 call VerifyScreenDump(buf, 'Test_textprop_nesting', {})
1373
1374 " clean up
1375 call StopVimInTerminal(buf)
1376endfunc
1377
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001378func Test_textprop_nowrap_scrolled()
1379 CheckScreendump
1380
1381 let lines =<< trim END
1382 vim9script
1383 set nowrap
1384 setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns))
1385 prop_type_add('number', {'highlight': 'ErrorMsg'})
1386 prop_add(1, 12, {'length': 3, 'type': 'number'})
1387 prop_add(1, 32, {'length': 4, 'type': 'number'})
1388 feedkeys('gg20zl', 'nxt')
1389 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001390 call writefile(lines, 'XtestNowrap', 'D')
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001391 let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6})
1392 call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {})
1393
1394 call term_sendkeys(buf, "$")
1395 call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {})
1396
1397 " clean up
1398 call StopVimInTerminal(buf)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001399endfunc
1400
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001401func Test_textprop_text_priority()
1402 CheckScreendump
1403
1404 let lines =<< trim END
1405 call setline(1, "function( call, argument, here )")
1406
1407 call prop_type_add('one', #{highlight: 'Error'})
1408 call prop_type_add('two', #{highlight: 'Function'})
1409 call prop_type_add('three', #{highlight: 'DiffChange'})
1410 call prop_type_add('arg', #{highlight: 'Search'})
1411
1412 call prop_add(1, 27, #{type: 'arg', length: len('here')})
1413 call prop_add(1, 27, #{type: 'three', text: 'three: '})
1414 call prop_add(1, 11, #{type: 'one', text: 'one: '})
1415 call prop_add(1, 11, #{type: 'arg', length: len('call')})
1416 call prop_add(1, 17, #{type: 'two', text: 'two: '})
1417 call prop_add(1, 17, #{type: 'arg', length: len('argument')})
1418 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001419 call writefile(lines, 'XtestPropPrio', 'D')
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001420 let buf = RunVimInTerminal('-S XtestPropPrio', {'rows': 5})
1421 call VerifyScreenDump(buf, 'Test_prop_at_same_pos', {})
1422
1423 " clean up
1424 call StopVimInTerminal(buf)
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001425endfunc
1426
zeertzjq4e26a9a2023-12-03 17:50:47 +01001427func Test_textprop_in_empty_popup()
1428 CheckScreendump
1429
1430 let lines =<< trim END
1431 vim9script
1432
1433 hi def link FilterMenuMatch Constant
1434 prop_type_add('FilterMenuMatch', {
1435 highlight: "FilterMenuMatch",
1436 override: true,
1437 priority: 1000,
1438 combine: true,
1439 })
1440
1441 var winid = popup_create([{text: "hello", props: [
1442 {col: 1, length: 1, type: 'FilterMenuMatch'},
1443 {col: 2, length: 1, type: 'FilterMenuMatch'},
1444 ]}], {
1445 minwidth: 20,
1446 minheight: 10,
1447 cursorline: false,
1448 highlight: "None",
1449 border: [],
1450 })
1451
1452 win_execute(winid, "setl nu cursorline cursorlineopt=both")
1453 popup_settext(winid, [])
1454 redraw
1455 END
1456 call writefile(lines, 'XtestPropEmptyPopup', 'D')
1457 let buf = RunVimInTerminal('-S XtestPropEmptyPopup', #{rows: 20, cols: 40})
1458 call VerifyScreenDump(buf, 'Test_prop_in_empty_popup', {})
1459
1460 " clean up
1461 call StopVimInTerminal(buf)
1462endfunc
1463
Bram Moolenaar34390282019-10-16 14:38:26 +02001464func Test_textprop_with_syntax()
1465 CheckScreendump
1466
1467 let lines =<< trim END
1468 call setline(1, [
1469 \ "(abc)",
1470 \ ])
1471 syn match csParens "[()]" display
1472 hi! link csParens MatchParen
1473
1474 call prop_type_add('TPTitle', #{ highlight: 'Title' })
1475 call prop_add(1, 2, #{type: 'TPTitle', end_col: 5})
1476 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001477 call writefile(lines, 'XtestPropSyn', 'D')
Bram Moolenaar34390282019-10-16 14:38:26 +02001478 let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6})
1479 call VerifyScreenDump(buf, 'Test_textprop_syn_1', {})
1480
1481 " clean up
1482 call StopVimInTerminal(buf)
Bram Moolenaar34390282019-10-16 14:38:26 +02001483endfunc
1484
Bram Moolenaard79eef22019-05-24 20:41:55 +02001485" Adding a text property to a new buffer should not fail
1486func Test_textprop_empty_buffer()
1487 call prop_type_add('comment', {'highlight': 'Search'})
1488 new
1489 call prop_add(1, 1, {'type': 'comment'})
1490 close
Bram Moolenaaradfde112019-05-25 22:11:45 +02001491 call prop_type_delete('comment')
1492endfunc
1493
Bram Moolenaard74af422019-06-28 21:38:00 +02001494" Adding a text property with invalid highlight should be ignored.
1495func Test_textprop_invalid_highlight()
1496 call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:')
1497 new
Ben Jacksona7704222022-08-20 20:54:51 +01001498 call setline(1, ['asdf', 'asdf'])
Bram Moolenaard74af422019-06-28 21:38:00 +02001499 call prop_add(1, 1, {'length': 4, 'type': 'dni'})
1500 redraw
1501 bwipe!
1502 call prop_type_delete('dni')
1503endfunc
1504
Bram Moolenaaradfde112019-05-25 22:11:45 +02001505" Adding a text property to an empty buffer and then editing another
1506func Test_textprop_empty_buffer_next()
1507 call prop_type_add("xxx", {})
1508 call prop_add(1, 1, {"type": "xxx"})
1509 next X
1510 call prop_type_delete('xxx')
Bram Moolenaard79eef22019-05-24 20:41:55 +02001511endfunc
Bram Moolenaarf0884c52019-05-24 21:22:29 +02001512
1513func Test_textprop_remove_from_buf()
1514 new
1515 let buf = bufnr('')
1516 call prop_type_add('one', {'bufnr': buf})
1517 call prop_add(1, 1, {'type': 'one', 'id': 234})
1518 file x
1519 edit y
1520 call prop_remove({'id': 234, 'bufnr': buf}, 1)
1521 call prop_type_delete('one', {'bufnr': buf})
1522 bwipe! x
1523 close
1524endfunc
Bram Moolenaar45311b52019-08-13 22:27:32 +02001525
1526func Test_textprop_in_unloaded_buf()
1527 edit Xaaa
1528 call setline(1, 'aaa')
1529 write
1530 edit Xbbb
1531 call setline(1, 'bbb')
1532 write
1533 let bnr = bufnr('')
1534 edit Xaaa
1535
1536 call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'})
1537 call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:')
1538 exe 'buf ' .. bnr
1539 call assert_equal('bbb', getline(1))
1540 call assert_equal(0, prop_list(1)->len())
1541
1542 bwipe! Xaaa
1543 bwipe! Xbbb
1544 cal delete('Xaaa')
1545 cal delete('Xbbb')
1546endfunc
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001547
1548func Test_proptype_substitute2()
1549 new
1550 " text_prop.vim
1551 call setline(1, [
1552 \ 'The num 123 is smaller than 4567.',
1553 \ '123 The number 123 is smaller than 4567.',
1554 \ '123 The number 123 is smaller than 4567.'])
1555
1556 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1557
1558 call prop_add(1, 12, {'length': 3, 'type': 'number'})
1559 call prop_add(2, 1, {'length': 3, 'type': 'number'})
1560 call prop_add(3, 36, {'length': 4, 'type': 'number'})
1561 set ul&
Martin Tournoije2390c72021-07-28 13:30:16 +02001562 let expected = [
1563 \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1},
1564 \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1},
1565 \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}]
1566
1567 " TODO
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001568 if 0
1569 " Add some text in between
1570 %s/\s\+/ /g
1571 call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001572
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001573 " remove some text
1574 :1s/[a-z]\{3\}//g
1575 let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
1576 call assert_equal(expected, prop_list(1))
1577 endif
1578
1579 call prop_type_delete('number')
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001580 bwipe!
1581endfunc
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001582
Bram Moolenaar8902b312020-09-20 21:04:35 +02001583" This was causing property corruption.
1584func Test_proptype_substitute3()
1585 new
1586 call setline(1, ['abcxxx', 'def'])
1587 call prop_type_add("test", {"highlight": "Search"})
1588 call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"})
1589 %s/x\+$//
1590 redraw
1591
1592 call prop_type_delete('test')
1593 bwipe!
1594endfunc
1595
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001596func Test_proptype_substitute_join()
1597 new
1598 call setline(1, [
1599 \ 'This is some end',
1600 \ 'start is highlighted end',
1601 \ 'some is highlighted',
1602 \ 'start is also highlighted'])
1603
1604 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1605
1606 call prop_add(1, 6, {'length': 2, 'type': 'number'})
1607 call prop_add(2, 7, {'length': 2, 'type': 'number'})
1608 call prop_add(3, 6, {'length': 2, 'type': 'number'})
1609 call prop_add(4, 7, {'length': 2, 'type': 'number'})
Dominique Pelleb49dfd02023-04-14 21:54:25 +01001610 " The highlighted "is" in line 1, 2 and 4 is kept and adjusted.
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001611 " The highlighted "is" in line 3 is deleted.
1612 let expected = [
1613 \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1},
1614 \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1},
1615 \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}]
1616
1617 s/end\nstart/joined/
1618 s/end\n.*\nstart/joined/
1619 call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1))
1620 call assert_equal(expected, prop_list(1))
1621
1622 call prop_type_delete('number')
1623 bwipe!
1624endfunc
1625
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001626func SaveOptions()
1627 let d = #{tabstop: &tabstop,
1628 \ softtabstop: &softtabstop,
1629 \ shiftwidth: &shiftwidth,
1630 \ expandtab: &expandtab,
1631 \ foldmethod: '"' .. &foldmethod .. '"',
1632 \ }
1633 return d
1634endfunc
1635
1636func RestoreOptions(dict)
1637 for name in keys(a:dict)
1638 exe 'let &' .. name .. ' = ' .. a:dict[name]
1639 endfor
1640endfunc
1641
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001642func Test_textprop_noexpandtab()
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001643 new
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001644 let save_dict = SaveOptions()
1645
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001646 set tabstop=8
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001647 set softtabstop=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001648 set shiftwidth=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001649 set noexpandtab
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001650 set foldmethod=marker
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001651
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001652 call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx")
1653 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1654 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1655 call feedkeys("0i\<tab>", "tx")
1656 call prop_remove({'type': 'test'})
1657 call prop_add(1, 2, {'end_col': 3, 'type': 'test'})
1658 call feedkeys("A\<left>\<tab>", "tx")
1659 call prop_remove({'type': 'test'})
1660 try
1661 " It is correct that this does not pass
1662 call prop_add(1, 6, {'end_col': 7, 'type': 'test'})
1663 " Has already collapsed here, start_col:6 does not result in an error
1664 call feedkeys("A\<left>\<tab>", "tx")
1665 catch /^Vim\%((\a\+)\)\=:E964/
1666 endtry
1667 call prop_remove({'type': 'test'})
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001668 call prop_type_delete('test')
1669
1670 call RestoreOptions(save_dict)
1671 bwipe!
1672endfunc
1673
1674func Test_textprop_noexpandtab_redraw()
1675 new
1676 let save_dict = SaveOptions()
1677
1678 set tabstop=8
1679 set softtabstop=4
1680 set shiftwidth=4
1681 set noexpandtab
1682 set foldmethod=marker
1683
1684 call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx")
1685 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1686 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1687 call feedkeys("0i\<tab>", "tx")
1688 " Internally broken at the next line
1689 call feedkeys("A\<left>\<tab>", "tx")
1690 redraw
1691 " Index calculation failed internally on next line
1692 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1693 call prop_remove({'type': 'test', 'all': v:true})
1694 call prop_type_delete('test')
1695 call prop_type_delete('test')
1696
1697 call RestoreOptions(save_dict)
1698 bwipe!
1699endfunc
1700
1701func Test_textprop_ins_str()
1702 new
1703 call setline(1, 'just some text')
1704 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1705 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001706 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 +01001707
1708 call feedkeys("foi\<F8>\<Esc>", "tx")
1709 call assert_equal('just s<F8>ome text', getline(1))
Martin Tournoije2390c72021-07-28 13:30:16 +02001710 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 +01001711
1712 bwipe!
1713 call prop_remove({'type': 'test'})
1714 call prop_type_delete('test')
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001715endfunc
Bram Moolenaar66b98852020-03-11 19:15:52 +01001716
1717func Test_find_prop_later_in_line()
1718 new
1719 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1720 call setline(1, 'just some text')
1721 call prop_add(1, 1, {'length': 4, 'type': 'test'})
1722 call prop_add(1, 10, {'length': 3, 'type': 'test'})
1723
Martin Tournoije2390c72021-07-28 13:30:16 +02001724 call assert_equal(
1725 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1},
1726 \ prop_find(#{type: 'test', lnum: 1, col: 6}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001727
1728 bwipe!
1729 call prop_type_delete('test')
1730endfunc
1731
1732func Test_find_zerowidth_prop_sol()
1733 new
1734 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1735 call setline(1, 'just some text')
1736 call prop_add(1, 1, {'length': 0, 'type': 'test'})
1737
Martin Tournoije2390c72021-07-28 13:30:16 +02001738 call assert_equal(
1739 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1},
1740 \ prop_find(#{type: 'test', lnum: 1}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001741
1742 bwipe!
1743 call prop_type_delete('test')
1744endfunc
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001745
1746" Test for passing invalid arguments to prop_xxx() functions
1747func Test_prop_func_invalid_args()
1748 call assert_fails('call prop_clear(1, 2, [])', 'E715:')
1749 call assert_fails('call prop_clear(-1, 2)', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001750 call assert_fails('call prop_find(test_null_dict())', 'E1297:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001751 call assert_fails('call prop_find({"bufnr" : []})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001752 call assert_fails('call prop_find({})', 'E968:')
1753 call assert_fails('call prop_find({}, "x")', 'E474:')
1754 call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001755 call assert_fails('call prop_list(1, [])', 'E1206:')
Bram Moolenaar9d489562020-07-30 20:08:50 +02001756 call assert_fails('call prop_list(-1, {})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001757 call assert_fails('call prop_remove([])', 'E1206:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001758 call assert_fails('call prop_remove({}, -2)', 'E16:')
1759 call assert_fails('call prop_remove({})', 'E968:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001760 call assert_fails('call prop_type_add([], {})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001761 call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001762 call assert_fails("call prop_type_delete([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001763 call assert_fails("call prop_type_delete('xyz', [])", 'E715:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001764 call assert_fails("call prop_type_get([])", 'E730:')
Bram Moolenaar89469d12022-12-02 20:46:26 +00001765 call assert_fails("call prop_type_get('', [])", 'E475:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001766 call assert_fails("call prop_type_list([])", 'E715:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001767 call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:')
1768 call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:')
1769 call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001770 call assert_fails('call prop_add(1, 1, 0)', 'E1206:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001771
1772 new
1773 call setline(1, ['first', 'second'])
1774 call prop_type_add('xxx', {})
1775
1776 call assert_fails("call prop_type_add('xxx', {})", 'E969:')
1777 call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:')
1778 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:')
1779 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:')
1780 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:')
1781 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:')
1782 call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:')
1783
1784 call prop_type_delete('xxx')
1785 bwipe!
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001786endfunc
1787
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001788func Test_prop_split_join()
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001789 new
1790 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1791 call setline(1, 'just some text')
1792 call prop_add(1, 6, {'length': 4, 'type': 'test'})
1793
1794 " Split in middle of "some"
1795 execute "normal! 8|i\<CR>"
Martin Tournoije2390c72021-07-28 13:30:16 +02001796 call assert_equal(
1797 \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}],
1798 \ prop_list(1))
1799 call assert_equal(
1800 \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}],
1801 \ prop_list(2))
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001802
1803 " Join the two lines back together
1804 normal! 1GJ
Martin Tournoije2390c72021-07-28 13:30:16 +02001805 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 +02001806
1807 bwipe!
1808 call prop_type_delete('test')
1809endfunc
1810
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001811func Test_prop_increment_decrement()
1812 new
1813 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1814 call setline(1, 'its 998 times')
1815 call prop_add(1, 5, {'length': 3, 'type': 'test'})
1816
1817 exe "normal! 0f9\<C-A>"
1818 eval getline(1)->assert_equal('its 999 times')
1819 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001820 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001821
1822 exe "normal! 0f9\<C-A>"
1823 eval getline(1)->assert_equal('its 1000 times')
1824 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001825 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001826
1827 bwipe!
1828 call prop_type_delete('test')
1829endfunc
1830
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001831func Test_prop_block_insert()
1832 new
1833 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1834 call setline(1, ['one ', 'two '])
1835 call prop_add(1, 1, {'length': 3, 'type': 'test'})
1836 call prop_add(2, 1, {'length': 3, 'type': 'test'})
1837
1838 " insert "xx" in the first column of both lines
1839 exe "normal! gg0\<C-V>jIxx\<Esc>"
1840 eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
Martin Tournoije2390c72021-07-28 13:30:16 +02001841 let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001842 eval prop_list(1)->assert_equal(expected)
1843 eval prop_list(2)->assert_equal(expected)
1844
1845 " insert "yy" inside the text props to make them longer
1846 exe "normal! gg03l\<C-V>jIyy\<Esc>"
1847 eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo '])
1848 let expected[0].length = 5
1849 eval prop_list(1)->assert_equal(expected)
1850 eval prop_list(2)->assert_equal(expected)
1851
1852 " insert "zz" after the text props, text props don't change
1853 exe "normal! gg07l\<C-V>jIzz\<Esc>"
1854 eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz '])
1855 eval prop_list(1)->assert_equal(expected)
1856 eval prop_list(2)->assert_equal(expected)
1857
1858 bwipe!
1859 call prop_type_delete('test')
1860endfunc
1861
Bram Moolenaar23999d72020-12-23 14:36:00 +01001862" this was causing an ml_get error because w_botline was wrong
1863func Test_prop_one_line_window()
1864 enew
1865 call range(2)->setline(1)
1866 call prop_type_add('testprop', {})
1867 call prop_add(1, 1, {'type': 'testprop'})
1868 call popup_create('popup', {'textprop': 'testprop'})
1869 $
1870 new
1871 wincmd _
1872 call feedkeys("\r", 'xt')
1873 redraw
1874
1875 call popup_clear()
1876 call prop_type_delete('testprop')
1877 close
1878 bwipe!
1879endfunc
1880
Bram Moolenaarf05a1e52022-08-02 11:48:53 +01001881def Test_prop_column_zero_error()
1882 prop_type_add('proptype', {highlight: 'Search'})
1883 var caught = false
1884 try
1885 popup_create([{
1886 text: 'a',
1887 props: [{col: 0, length: 1, type: 'type'}],
1888 }], {})
1889 catch /E964:/
1890 caught = true
1891 endtry
1892 assert_true(caught)
1893
1894 popup_clear()
1895 prop_type_delete('proptype')
1896enddef
1897
Bram Moolenaar840f91f2021-05-26 22:32:10 +02001898" This was calling ml_append_int() and copy a text property from a previous
1899" line at the wrong moment. Exact text length matters.
1900def Test_prop_splits_data_block()
1901 new
1902 var lines: list<string> = [repeat('x', 35)]->repeat(41)
1903 + [repeat('!', 35)]
1904 + [repeat('x', 35)]->repeat(56)
1905 lines->setline(1)
1906 prop_type_add('someprop', {highlight: 'ErrorMsg'})
1907 prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'})
1908 prop_remove({type: 'someprop'}, 1)
1909 prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'})
1910 prop_remove({type: 'someprop'}, 35, 43)
1911 assert_equal([], prop_list(42))
1912
1913 bwipe!
1914 prop_type_delete('someprop')
1915enddef
1916
Bram Moolenaar4cd5c522021-06-27 13:04:00 +02001917" This was calling ml_delete_int() and try to change text properties.
1918def Test_prop_add_delete_line()
1919 new
1920 var a = 10
1921 var b = 20
1922 repeat([''], a)->append('$')
1923 prop_type_add('Test', {highlight: 'ErrorMsg'})
1924 for lnum in range(1, a)
1925 for col in range(1, b)
1926 prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'})
1927 endfor
1928 endfor
1929
1930 # check deleting lines is OK
1931 :5del
1932 :1del
1933 :$del
1934
1935 prop_type_delete('Test')
1936 bwipe!
1937enddef
1938
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001939" This test is to detect a regression related to #10430. It is not an attempt
1940" fully cover deleting lines in the presence of multi-line properties.
1941def Test_delete_line_within_multiline_prop()
1942 new
1943 setline(1, '# Top.')
1944 append(1, ['some_text = """', 'A string.', '"""', '# Bottom.'])
1945 prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1946 prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1947 prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9})
1948 prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4})
1949
1950 # The property for line 3 should extend into the previous and next lines.
1951 var props = prop_list(3)
1952 var prop = props[0]
1953 assert_equal(1, len(props))
1954 assert_equal(0, prop['start'])
1955 assert_equal(0, prop['end'])
1956
1957 # This deletion should run without raising an exception.
1958 try
1959 :2 del
1960 catch
dundargocc57b5bc2022-11-02 13:30:51 +00001961 assert_report('Line delete should have worked, but it raised an error.')
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001962 endtry
1963
1964 # The property for line 2 (was 3) should no longer extend into the previous
1965 # line.
1966 props = prop_list(2)
1967 prop = props[0]
1968 assert_equal(1, len(props))
1969 assert_equal(1, prop['start'], 'Property was not changed to start within the line.')
1970
1971 # This deletion should run without raising an exception.
1972 try
1973 :3 del
1974 catch
dundargocc57b5bc2022-11-02 13:30:51 +00001975 assert_report('Line delete should have worked, but it raised an error.')
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001976 endtry
1977
1978 # The property for line 2 (originally 3) should no longer extend into the next
1979 # line.
1980 props = prop_list(2)
1981 prop = props[0]
1982 assert_equal(1, len(props))
1983 assert_equal(1, prop['end'], 'Property was not changed to end within the line.')
1984
1985 prop_type_delete('Identifier')
1986 prop_type_delete('String')
1987 bwip!
1988enddef
1989
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001990func Test_prop_in_linebreak()
1991 CheckRunVimInTerminal
1992
1993 let lines =<< trim END
1994 set breakindent linebreak breakat+=]
1995 call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1)
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001996 call prop_type_add('test', #{highlight: 'MatchParen'})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001997 call prop_add(1, 51, #{length: 1, type: 'test'})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001998 func AddMatch()
1999 syntax on
2000 syntax match xTest /.*/
2001 hi link xTest Comment
2002 set signcolumn=yes
2003 endfunc
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002004 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002005 call writefile(lines, 'XscriptPropLinebreak', 'D')
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002006 let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002007 call VerifyScreenDump(buf, 'Test_prop_linebreak_1', {})
2008
2009 call term_sendkeys(buf, ":call AddMatch()\<CR>")
2010 call VerifyScreenDump(buf, 'Test_prop_linebreak_2', {})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002011
2012 call StopVimInTerminal(buf)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002013endfunc
2014
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002015func Test_prop_with_linebreak()
2016 CheckRunVimInTerminal
2017
2018 let lines =<< trim END
2019 vim9script
2020 set linebreak
2021 setline(1, 'one twoword')
2022 prop_type_add('test', {highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002023 prop_add(1, 4, {text: ': virtual text', type: 'test'})
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002024 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002025 call writefile(lines, 'XscriptPropWithLinebreak', 'D')
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002026 let buf = RunVimInTerminal('-S XscriptPropWithLinebreak', #{rows: 6, cols: 50})
2027 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_1', {})
2028 call term_sendkeys(buf, "iasdf asdf asdf asdf asdf as\<Esc>")
2029 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_2', {})
2030
2031 call StopVimInTerminal(buf)
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002032endfunc
2033
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002034func Test_prop_with_wrap()
2035 CheckRunVimInTerminal
2036
2037 let lines =<< trim END
2038 vim9script
2039 set linebreak
2040 setline(1, 'asdf '->repeat(15))
2041 prop_type_add('test', {highlight: 'Special'})
2042 prop_add(1, 43, {text: 'some virtual text', type: 'test'})
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +00002043 normal G$
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002044 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002045 call writefile(lines, 'XscriptPropWithWrap', 'D')
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002046 let buf = RunVimInTerminal('-S XscriptPropWithWrap', #{rows: 6, cols: 50})
2047 call VerifyScreenDump(buf, 'Test_prop_with_wrap_1', {})
2048
2049 call StopVimInTerminal(buf)
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002050endfunc
2051
Bram Moolenaar42eba042021-11-30 20:22:49 +00002052func Test_prop_after_tab()
2053 CheckRunVimInTerminal
2054
2055 let lines =<< trim END
2056 set breakindent linebreak breakat+=]
2057 call setline(1, "\t[xxx]")
2058 call prop_type_add('test', #{highlight: 'ErrorMsg'})
2059 call prop_add(1, 2, #{length: 1, type: 'test'})
2060 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002061 call writefile(lines, 'XscriptPropAfterTab', 'D')
Bram Moolenaar42eba042021-11-30 20:22:49 +00002062 let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10})
Bram Moolenaar42eba042021-11-30 20:22:49 +00002063 call VerifyScreenDump(buf, 'Test_prop_after_tab', {})
2064
2065 call StopVimInTerminal(buf)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002066endfunc
2067
Bram Moolenaare428fa02022-08-09 16:55:41 +01002068func Test_prop_before_tab()
2069 CheckRunVimInTerminal
2070
2071 let lines =<< trim END
2072 call setline(1, ["\tx"]->repeat(6))
2073 call prop_type_add('test', #{highlight: 'Search'})
2074 call prop_add(1, 1, #{type: 'test', text: '123'})
2075 call prop_add(2, 1, #{type: 'test', text: '1234567'})
2076 call prop_add(3, 1, #{type: 'test', text: '12345678'})
2077 call prop_add(4, 1, #{type: 'test', text: '123456789'})
2078 call prop_add(5, 2, #{type: 'test', text: 'ABC'})
2079 call prop_add(6, 3, #{type: 'test', text: 'ABC'})
2080 normal gg0
2081 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002082 call writefile(lines, 'XscriptPropBeforeTab', 'D')
Bram Moolenaare428fa02022-08-09 16:55:41 +01002083 let buf = RunVimInTerminal('-S XscriptPropBeforeTab', #{rows: 8})
2084 call VerifyScreenDump(buf, 'Test_prop_before_tab_01', {})
2085 call term_sendkeys(buf, "$")
2086 call VerifyScreenDump(buf, 'Test_prop_before_tab_02', {})
2087 call term_sendkeys(buf, "j0")
2088 call VerifyScreenDump(buf, 'Test_prop_before_tab_03', {})
2089 call term_sendkeys(buf, "$")
2090 call VerifyScreenDump(buf, 'Test_prop_before_tab_04', {})
2091 call term_sendkeys(buf, "j0")
2092 call VerifyScreenDump(buf, 'Test_prop_before_tab_05', {})
2093 call term_sendkeys(buf, "$")
2094 call VerifyScreenDump(buf, 'Test_prop_before_tab_06', {})
2095 call term_sendkeys(buf, "j0")
2096 call VerifyScreenDump(buf, 'Test_prop_before_tab_07', {})
2097 call term_sendkeys(buf, "$")
2098 call VerifyScreenDump(buf, 'Test_prop_before_tab_08', {})
2099 call term_sendkeys(buf, "j")
2100 call VerifyScreenDump(buf, 'Test_prop_before_tab_09', {})
2101 call term_sendkeys(buf, "j")
2102 call VerifyScreenDump(buf, 'Test_prop_before_tab_10', {})
2103
2104 call StopVimInTerminal(buf)
Bram Moolenaare428fa02022-08-09 16:55:41 +01002105endfunc
2106
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002107func Test_prop_after_linebreak()
2108 CheckRunVimInTerminal
2109
2110 let lines =<< trim END
2111 set linebreak wrap
2112 call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1)
2113 call prop_type_add('test', #{highlight: 'ErrorMsg'})
2114 call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'})
2115 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002116 call writefile(lines, 'XscriptPropAfterLinebreak', 'D')
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002117 let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10})
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002118 call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {})
2119
2120 call StopVimInTerminal(buf)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002121endfunc
2122
Martin Tournoije2390c72021-07-28 13:30:16 +02002123" Buffer number of 0 should be ignored, as if the parameter wasn't passed.
2124def Test_prop_bufnr_zero()
2125 new
2126 try
2127 var bufnr = bufnr('')
2128 setline(1, 'hello')
2129 prop_type_add('bufnr-global', {highlight: 'ErrorMsg'})
2130 prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr})
2131
2132 prop_add(1, 1, {type: 'bufnr-global', length: 1})
2133 prop_add(1, 2, {type: 'bufnr-buffer', length: 1})
2134
2135 var list = prop_list(1)
2136 assert_equal([
2137 {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1},
2138 {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1},
2139 ], list)
2140
2141 assert_equal(
2142 {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1},
2143 prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr}))
2144
2145 assert_equal(
2146 {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1},
2147 prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr}))
2148 finally
2149 bwipe!
2150 prop_type_delete('bufnr-global')
2151 endtry
2152enddef
2153
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002154" Tests for the prop_list() function
2155func Test_prop_list()
2156 let lines =<< trim END
2157 new
Bram Moolenaar62aec932022-01-29 21:45:34 +00002158 call g:AddPropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002159 call setline(1, repeat([repeat('a', 60)], 10))
2160 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2161 call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7})
2162 call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14})
2163 call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15})
2164 call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22})
2165 call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23})
2166 call assert_equal([
2167 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2168 \ 'type': 'one', 'length': 2, 'start': 1},
2169 \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2170 \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1))
2171 #" text properties between a few lines
2172 call assert_equal([
2173 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2174 \ 'type': 'one', 'length': 2, 'start': 1},
2175 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2176 \ 'type': 'two', 'length': 2, 'start': 1},
2177 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
2178 \ 'type': 'one', 'length': 2, 'start': 1},
2179 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
2180 \ 'type': 'two', 'length': 2, 'start': 1}],
2181 \ prop_list(2, {'end_lnum': 5}))
2182 #" text properties across all the lines
2183 call assert_equal([
2184 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2185 \ 'type': 'one', 'length': 2, 'start': 1},
2186 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2187 \ 'type': 'one', 'length': 2, 'start': 1},
2188 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
2189 \ 'type': 'one', 'length': 2, 'start': 1}],
2190 \ prop_list(1, {'types': ['one'], 'end_lnum': -1}))
2191 #" text properties with the specified identifier
2192 call assert_equal([
2193 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2194 \ 'type': 'one', 'length': 2, 'start': 1},
2195 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
2196 \ 'type': 'two', 'length': 2, 'start': 1}],
2197 \ prop_list(1, {'ids': [20], 'end_lnum': 10}))
2198 #" text properties of the specified type and id
2199 call assert_equal([
2200 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2201 \ 'type': 'two', 'length': 2, 'start': 1},
2202 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2203 \ 'type': 'two', 'length': 2, 'start': 1}],
2204 \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20}))
2205 call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10}))
2206 call assert_equal([], prop_list(6, {'end_lnum': 10}))
2207 call assert_equal([], prop_list(2, {'end_lnum': 2}))
2208 #" error cases
2209 call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:')
2210 call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:')
2211 call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:')
2212 call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})",
2213 \ 'E971:')
2214 call assert_fails("echo prop_list(1, {'types': ['one', 'blue'],
2215 \ 'end_lnum': 10})", 'E971:')
2216 call assert_fails("echo prop_list(1, {'types': ['one', 10],
2217 \ 'end_lnum': 10})", 'E928:')
2218 call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:')
2219 call assert_equal([], prop_list(2, {'types': []}))
2220 call assert_equal([], prop_list(2, {'types': test_null_list()}))
2221 call assert_fails("call prop_list(1, {'types': {}})", 'E714:')
2222 call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:')
2223 call assert_equal([], prop_list(2, {'types': ['one'],
2224 \ 'ids': test_null_list()}))
2225 call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []}))
2226 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})",
2227 \ 'E714:')
2228 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})",
2229 \ 'E714:')
2230 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})",
2231 \ 'E745:')
2232 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})",
2233 \ 'E745:')
Martin Tournoije2390c72021-07-28 13:30:16 +02002234
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002235 #" get text properties from a non-current buffer
2236 wincmd w
2237 call assert_equal([
2238 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2239 \ 'type': 'one', 'length': 2, 'start': 1},
2240 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2241 \ 'type': 'two', 'length': 2, 'start': 1},
2242 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2243 \ 'type': 'one', 'length': 2, 'start': 1},
2244 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2245 \ 'type': 'two', 'length': 2, 'start': 1}],
2246 \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4}))
2247 wincmd w
2248
2249 #" get text properties after clearing all the properties
2250 call prop_clear(1, line('$'))
2251 call assert_equal([], prop_list(1, {'end_lnum': 10}))
2252
2253 call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2254 call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6})
2255 call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6})
2256 #" get text properties with a list of types
2257 call assert_equal([
2258 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2259 \ 'type': 'two', 'length': 2, 'start': 1},
2260 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2261 \ 'type': 'one', 'length': 2, 'start': 1}],
2262 \ prop_list(2, {'types': ['one', 'two']}))
2263 call assert_equal([
2264 \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1,
2265 \ 'type': 'three', 'length': 2, 'start': 1},
2266 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2267 \ 'type': 'one', 'length': 2, 'start': 1}],
2268 \ prop_list(2, {'types': ['one', 'three']}))
2269 #" get text properties with a list of identifiers
2270 call assert_equal([
2271 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2272 \ 'type': 'two', 'length': 2, 'start': 1},
2273 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2274 \ 'type': 'one', 'length': 2, 'start': 1}],
2275 \ prop_list(2, {'ids': [5, 10, 20]}))
2276 call prop_clear(1, line('$'))
2277 call assert_equal([], prop_list(2, {'types': ['one', 'two']}))
2278 call assert_equal([], prop_list(2, {'ids': [5, 10, 20]}))
2279
2280 #" get text properties from a hidden buffer
2281 edit! Xaaa
2282 call setline(1, repeat([repeat('b', 60)], 10))
2283 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2284 call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10})
2285 VAR bnr = bufnr()
2286 hide edit Xbbb
2287 call assert_equal([
2288 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2289 \ 'type': 'one', 'length': 2, 'start': 1},
2290 \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1,
2291 \ 'type': 'two', 'length': 2, 'start': 1}],
2292 \ prop_list(1, {'bufnr': bnr,
2293 \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1}))
2294 #" get text properties from an unloaded buffer
2295 bunload! Xaaa
2296 call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1}))
2297
Bram Moolenaar62aec932022-01-29 21:45:34 +00002298 call g:DeletePropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002299 :%bw!
2300 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00002301 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002302endfunc
Bram Moolenaar23999d72020-12-23 14:36:00 +01002303
LemonBoy9bd3ce22022-04-18 21:54:02 +01002304func Test_prop_find_prev_on_same_line()
2305 new
2306
2307 call setline(1, 'the quikc bronw fox jumsp over the layz dog')
2308 call prop_type_add('misspell', #{highlight: 'ErrorMsg'})
2309 for col in [8, 14, 24, 38]
2310 call prop_add(1, col, #{type: 'misspell', length: 2})
2311 endfor
2312
Ben Jacksona7704222022-08-20 20:54:51 +01002313 call cursor(1, 18)
LemonBoy9bd3ce22022-04-18 21:54:02 +01002314 let expected = [
2315 \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1},
2316 \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}
2317 \ ]
2318
2319 let result = prop_find(#{type: 'misspell'}, 'b')
2320 call assert_equal(expected[0], result)
2321 let result = prop_find(#{type: 'misspell'}, 'f')
2322 call assert_equal(expected[1], result)
2323
2324 call prop_type_delete('misspell')
2325 bwipe!
2326endfunc
2327
LemonBoyb7a70122022-05-13 12:41:50 +01002328func Test_prop_spell()
2329 new
2330 set spell
2331 call AddPropTypes()
2332
2333 call setline(1, ["helo world", "helo helo helo"])
2334 call prop_add(1, 1, #{type: 'one', length: 4})
2335 call prop_add(1, 6, #{type: 'two', length: 5})
2336 call prop_add(2, 1, #{type: 'three', length: 4})
2337 call prop_add(2, 6, #{type: 'three', length: 4})
2338 call prop_add(2, 11, #{type: 'three', length: 4})
2339
2340 " The first prop over 'helo' increases its length after the word is corrected
2341 " to 'Hello', the second one is shifted to the right.
2342 let expected = [
2343 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2344 \ 'length': 5, 'start': 1},
2345 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2346 \ 'length': 5, 'start': 1}
2347 \ ]
2348 call feedkeys("z=1\<CR>", 'xt')
2349
2350 call assert_equal('Hello world', getline(1))
2351 call assert_equal(expected, prop_list(1))
2352
2353 " Repeat the replacement done by z=
2354 spellrepall
2355
2356 let expected = [
2357 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2358 \ 'length': 5, 'start': 1},
2359 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2360 \ 'length': 5, 'start': 1},
2361 \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2362 \ 'length': 5, 'start': 1}
2363 \ ]
2364 call assert_equal('Hello Hello Hello', getline(2))
2365 call assert_equal(expected, prop_list(2))
2366
2367 call DeletePropTypes()
2368 set spell&
2369 bwipe!
2370endfunc
2371
LemonBoy4b936742022-05-13 21:56:28 +01002372func Test_prop_shift_block()
2373 new
2374 call AddPropTypes()
2375
2376 call setline(1, ['some highlighted text']->repeat(2))
2377 call prop_add(1, 10, #{type: 'one', length: 11})
2378 call prop_add(2, 10, #{type: 'two', length: 11})
2379
2380 call cursor(1, 1)
2381 call feedkeys("5l\<c-v>>", 'nxt')
2382 call cursor(2, 1)
2383 call feedkeys("5l\<c-v><", 'nxt')
2384
2385 let expected = [
2386 \ {'lnum': 1, 'id': 0, 'col': 8, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2387 \ 'length': 11, 'start' : 1},
2388 \ {'lnum': 2, 'id': 0, 'col': 6, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2389 \ 'length': 11, 'start' : 1}
2390 \ ]
2391 call assert_equal(expected, prop_list(1, #{end_lnum: 2}))
2392
2393 call DeletePropTypes()
2394 bwipe!
2395endfunc
LemonBoyb7a70122022-05-13 12:41:50 +01002396
LemonBoy698cb4c2022-05-14 18:10:15 +01002397func Test_prop_insert_multiline()
2398 new
2399 call AddPropTypes()
2400
2401 call setline(1, ['foobar', 'barbaz'])
2402 call prop_add(1, 4, #{end_lnum: 2, end_col: 4, type: 'one'})
2403
2404 call feedkeys("1Goquxqux\<Esc>", 'nxt')
2405 call feedkeys("2GOquxqux\<Esc>", 'nxt')
2406
2407 let lines =<< trim END
2408 foobar
2409 quxqux
2410 quxqux
2411 barbaz
2412 END
2413 call assert_equal(lines, getline(1, '$'))
2414 let expected = [
2415 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one',
Ben Jacksona7704222022-08-20 20:54:51 +01002416 \ 'length': 4 , 'start': 1},
LemonBoy698cb4c2022-05-14 18:10:15 +01002417 \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2418 \ 'length': 7, 'start': 0},
2419 \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2420 \ 'length': 7, 'start': 0},
2421 \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2422 \ 'length': 3, 'start': 0}
2423 \ ]
2424 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2425
2426 call DeletePropTypes()
2427 bwipe!
2428endfunc
2429
LemonBoyb559b302022-05-15 13:08:02 +01002430func Test_prop_blockwise_change()
2431 new
2432 call AddPropTypes()
2433
2434 call setline(1, ['foooooo', 'bar', 'baaaaz'])
2435 call prop_add(1, 1, #{end_col: 3, type: 'one'})
2436 call prop_add(2, 1, #{end_col: 3, type: 'two'})
2437 call prop_add(3, 1, #{end_col: 3, type: 'three'})
2438
2439 " Replace the first two columns with '123', since 'start_incl' is false the
2440 " prop is not extended.
2441 call feedkeys("gg\<c-v>2jc123\<Esc>", 'nxt')
2442
2443 let lines =<< trim END
2444 123oooooo
2445 123ar
2446 123aaaaz
2447 END
2448 call assert_equal(lines, getline(1, '$'))
2449 let expected = [
2450 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2451 \ 'length': 1, 'start': 1},
2452 \ {'lnum': 2, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2453 \ 'length': 1, 'start': 1},
2454 \ {'lnum': 3, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1 ,
2455 \ 'type': 'three', 'length': 1, 'start': 1}
2456 \ ]
2457 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2458
2459 call DeletePropTypes()
2460 bwipe!
2461endfunc
2462
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002463func Do_test_props_do_not_affect_byte_offsets(ff, increment)
2464 new
2465 let lcount = 410
2466
2467 " File format affects byte-offset calculations, so make sure it is known.
2468 exec 'setlocal fileformat=' . a:ff
2469
2470 " Fill the buffer with varying length lines. We need a suitably large number
dundargocc57b5bc2022-11-02 13:30:51 +00002471 " to force Vim code through paths where previous error have occurred. This
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002472 " is more 'art' than 'science'.
2473 let text = 'a'
2474 call setline(1, text)
2475 let offsets = [1]
2476 for idx in range(lcount)
2477 call add(offsets, offsets[idx] + len(text) + a:increment)
2478 if (idx % 6) == 0
2479 let text = text . 'a'
2480 endif
2481 call append(line('$'), text)
2482 endfor
2483
2484 " Set a property that spans a few lines to cause Vim's internal buffer code
2485 " to perform a reasonable amount of rearrangement.
2486 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2487 call prop_add(1, 1, {'type': 'one', 'end_lnum': 6, 'end_col': 2})
2488
2489 for idx in range(lcount)
2490 let boff = line2byte(idx + 1)
2491 call assert_equal(offsets[idx], boff, 'Bad byte offset at line ' . (idx + 1))
2492 endfor
2493
2494 call prop_type_delete('one')
2495 bwipe!
2496endfunc
2497
2498func Test_props_do_not_affect_byte_offsets()
2499 call Do_test_props_do_not_affect_byte_offsets('unix', 1)
2500endfunc
2501
2502func Test_props_do_not_affect_byte_offsets_dos()
2503 call Do_test_props_do_not_affect_byte_offsets('dos', 2)
2504endfunc
2505
2506func Test_props_do_not_affect_byte_offsets_editline()
2507 new
2508 let lcount = 410
2509
2510 " File format affects byte-offset calculations, so make sure it is known.
2511 setlocal fileformat=unix
2512
2513 " Fill the buffer with varying length lines. We need a suitably large number
dundargocc57b5bc2022-11-02 13:30:51 +00002514 " to force Vim code through paths where previous error have occurred. This
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002515 " is more 'art' than 'science'.
2516 let text = 'aa'
2517 call setline(1, text)
2518 let offsets = [1]
2519 for idx in range(lcount)
2520 call add(offsets, offsets[idx] + len(text) + 1)
2521 if (idx % 6) == 0
2522 let text = text . 'a'
2523 endif
2524 call append(line('$'), text)
2525 endfor
2526
2527 " Set a property that just covers the first line. When this test was
2528 " developed, this did not trigger a byte-offset error.
2529 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2530 call prop_add(1, 1, {'type': 'one', 'end_lnum': 1, 'end_col': 3})
2531
2532 for idx in range(lcount)
2533 let boff = line2byte(idx + 1)
2534 call assert_equal(offsets[idx], boff,
2535 \ 'Confounding bad byte offset at line ' . (idx + 1))
2536 endfor
2537
2538 " Insert text in the middle of the first line, keeping the property
2539 " unchanged.
2540 :1
2541 normal aHello
2542 for idx in range(1, lcount)
2543 let offsets[idx] = offsets[idx] + 5
2544 endfor
2545
2546 for idx in range(lcount)
2547 let boff = line2byte(idx + 1)
2548 call assert_equal(offsets[idx], boff,
2549 \ 'Bad byte offset at line ' . (idx + 1))
2550 endfor
2551
2552 call prop_type_delete('one')
2553 bwipe!
2554endfunc
2555
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002556func Test_prop_inserts_text()
2557 CheckRunVimInTerminal
2558
2559 " Just a basic check for now
2560 let lines =<< trim END
2561 call setline(1, 'insert some text here and other text there and some more text after wrapping')
2562 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2563 call prop_type_add('otherprop', #{highlight: 'Search'})
2564 call prop_type_add('moreprop', #{highlight: 'DiffAdd'})
2565 call prop_add(1, 18, #{type: 'someprop', text: 'SOME '})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002566 call prop_add(1, 38, #{type: 'otherprop', text: "OTHER\t"})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002567 call prop_add(1, 69, #{type: 'moreprop', text: 'MORE '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002568 normal $
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002569
2570 call setline(2, 'prepost')
2571 call prop_type_add('multibyte', #{highlight: 'Visual'})
2572 call prop_add(2, 4, #{type: 'multibyte', text: 'sΓΆmeε’ŒεΉ³tΓ©xt'})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002573
Bram Moolenaar25463612022-08-08 11:07:47 +01002574 call setline(3, 'Foo foo = { 1, 2 };')
Bram Moolenaar3331dd02022-08-10 16:49:02 +01002575 call prop_type_add('testprop', #{highlight: 'Comment'})
Bram Moolenaar25463612022-08-08 11:07:47 +01002576 call prop_add(3, 13, #{type: 'testprop', text: '.x='})
2577 call prop_add(3, 16, #{type: 'testprop', text: '.y='})
2578
2579 call setline(4, '')
2580 call prop_add(4, 1, #{type: 'someprop', text: 'empty line'})
Bram Moolenaar3331dd02022-08-10 16:49:02 +01002581
2582 call setline(5, 'look highlight')
2583 call prop_type_add('nohi', #{})
2584 call prop_add(5, 6, #{type: 'nohi', text: 'no '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002585 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002586 call writefile(lines, 'XscriptPropsWithText', 'D')
Bram Moolenaar25463612022-08-08 11:07:47 +01002587 let buf = RunVimInTerminal('-S XscriptPropsWithText', #{rows: 8, cols: 60})
Bram Moolenaar711483c2022-07-30 21:33:46 +01002588 call VerifyScreenDump(buf, 'Test_prop_inserts_text_1', {})
2589
2590 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2591 call VerifyScreenDump(buf, 'Test_prop_inserts_text_2', {})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002592
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002593 call term_sendkeys(buf, "2G$")
2594 call VerifyScreenDump(buf, 'Test_prop_inserts_text_3', {})
2595
Bram Moolenaar25463612022-08-08 11:07:47 +01002596 call term_sendkeys(buf, "3Gf1")
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002597 call VerifyScreenDump(buf, 'Test_prop_inserts_text_4', {})
Bram Moolenaar25463612022-08-08 11:07:47 +01002598 call term_sendkeys(buf, "f2")
2599 call VerifyScreenDump(buf, 'Test_prop_inserts_text_5', {})
2600
2601 call term_sendkeys(buf, "4G")
2602 call VerifyScreenDump(buf, 'Test_prop_inserts_text_6', {})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002603
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002604 call StopVimInTerminal(buf)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002605endfunc
2606
Bram Moolenaare38fc862022-08-11 17:24:50 +01002607func Test_prop_inserts_text_highlight()
2608 CheckRunVimInTerminal
2609
2610 " Just a basic check for now
2611 let lines =<< trim END
2612 call setline(1, 'insert some text (here) and there')
2613 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2614 let bef_prop = prop_add(1, 18, #{type: 'someprop', text: 'BEFORE'})
2615 set hlsearch
2616 let thematch = matchaddpos("DiffAdd", [[1, 18]])
2617 func DoAfter()
2618 call prop_remove(#{id: g:bef_prop})
2619 call prop_add(1, 19, #{type: 'someprop', text: 'AFTER'})
2620 let g:thematch = matchaddpos("DiffAdd", [[1, 18]])
2621 let @/ = ''
2622 endfunc
2623 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002624 call writefile(lines, 'XscriptPropsWithHighlight', 'D')
Bram Moolenaare38fc862022-08-11 17:24:50 +01002625 let buf = RunVimInTerminal('-S XscriptPropsWithHighlight', #{rows: 6, cols: 60})
2626 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_1', {})
2627 call term_sendkeys(buf, "/text (he\<CR>")
2628 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_2', {})
2629 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2630 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_3', {})
2631
2632 call term_sendkeys(buf, ":call DoAfter()\<CR>")
2633 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_4', {})
2634 call term_sendkeys(buf, "/text (he\<CR>")
2635 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_5', {})
2636 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2637 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_6', {})
2638
2639 call StopVimInTerminal(buf)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002640endfunc
2641
zeertzjqd809c0a2023-08-27 11:17:39 +02002642func Test_prop_inserts_text_normal_gM()
2643 CheckRunVimInTerminal
2644
2645 let lines =<< trim END
2646 call setline(1, '123456789')
2647 call prop_type_add('theprop', #{highlight: 'Special'})
2648 call prop_add(1, 3, {'type': 'theprop', 'text': 'bbb'})
2649 call prop_add(1, 8, {'type': 'theprop', 'text': 'bbb'})
2650 END
2651 call writefile(lines, 'XscriptPropsNormal_gM', 'D')
2652 let buf = RunVimInTerminal('-S XscriptPropsNormal_gM', #{rows: 3, cols: 60})
2653 call term_sendkeys(buf, "gM")
2654 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gM', {})
2655
2656 call StopVimInTerminal(buf)
2657endfunc
2658
2659func Run_test_prop_inserts_text_normal_gj_gk(cmd)
2660 CheckRunVimInTerminal
2661
2662 let lines =<< trim END
2663 call setline(1, repeat([repeat('a', 55)], 2))
2664 call prop_type_add('theprop', {})
2665 call prop_add(1, 41, {'type': 'theprop', 'text': repeat('b', 10)})
2666 call prop_add(2, 41, {'type': 'theprop', 'text': repeat('b', 10)})
2667 END
2668 let lines = insert(lines, a:cmd)
2669 call writefile(lines, 'XscriptPropsNormal_gj_gk', 'D')
2670 let buf = RunVimInTerminal('-S XscriptPropsNormal_gj_gk', #{rows: 6, cols: 60})
2671 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_1', {})
2672 call term_sendkeys(buf, "gj")
2673 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_2', {})
2674 call term_sendkeys(buf, "gj")
2675 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_3', {})
2676 call term_sendkeys(buf, "gj")
2677 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_4', {})
2678 call term_sendkeys(buf, "gk")
2679 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_5', {})
2680 call term_sendkeys(buf, "gk")
2681 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_6', {})
2682 call term_sendkeys(buf, "gk")
2683 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_7', {})
2684
2685 call StopVimInTerminal(buf)
2686endfunc
2687
2688func Test_prop_inserts_text_normal_gj_gk()
2689 call Run_test_prop_inserts_text_normal_gj_gk('')
2690 call Run_test_prop_inserts_text_normal_gj_gk('set virtualedit=all')
2691endfunc
2692
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002693func Test_prop_normal_gj_gk_gM_with_outer_virtual_text()
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002694 CheckRunVimInTerminal
2695
2696 let lines =<< trim END
2697 vim9script
2698 setlocal number
2699 setline(1, ['First line fits on screen line.', '', 'Third line fits on screen line.'])
2700
2701 var vt = 'test'
2702 prop_type_add(vt, {highlight: 'ToDo'})
2703 for ln in range(1, line('$'))
2704 prop_add(ln, 0, {type: vt, text: 'Above', text_align: 'above'})
2705 prop_add(ln, 0, {type: vt, text: 'After text wraps to next line.', text_align: 'after', text_wrap: 'wrap'})
2706 prop_add(ln, 0, {type: vt, text: 'Right text wraps to next line.', text_align: 'right', text_wrap: 'wrap'})
2707 prop_add(ln, 0, {type: vt, text: 'Below', text_align: 'below'})
2708 endfor
2709 normal 3l
2710 END
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002711 call writefile(lines, 'XscriptPropsNormal_gj_gk_gM_with_outer_text', 'D')
2712 let buf = RunVimInTerminal('-S XscriptPropsNormal_gj_gk_gM_with_outer_text', #{rows: 16, cols: 40})
2713 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002714
2715 call term_sendkeys(buf, "gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002716 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_2', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002717 call term_sendkeys(buf, "gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002718 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_3', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002719 call term_sendkeys(buf, "gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002720 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_2', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002721 call term_sendkeys(buf, "gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002722 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002723
2724 call term_sendkeys(buf, "2gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002725 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_3', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002726 call term_sendkeys(buf, "2gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002727 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
2728
2729 call term_sendkeys(buf, "gM")
2730 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_4', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002731
2732 call StopVimInTerminal(buf)
2733endfunc
2734
zeertzjq6e940d92023-08-17 23:21:40 +02002735func Test_prop_inserts_text_visual_block()
2736 CheckRunVimInTerminal
2737
2738 let lines =<< trim END
zeertzjqfc305842023-08-19 13:27:03 +02002739 call setline(1, repeat(['123456789'], 4))
zeertzjq6e940d92023-08-17 23:21:40 +02002740 call prop_type_add('theprop', #{highlight: 'Special'})
2741 call prop_add(2, 2, {'type': 'theprop', 'text': '-口-'})
zeertzjqfc305842023-08-19 13:27:03 +02002742 call prop_add(3, 3, {'type': 'theprop', 'text': '口'})
zeertzjq6e940d92023-08-17 23:21:40 +02002743 END
2744 call writefile(lines, 'XscriptPropsVisualBlock', 'D')
2745 let buf = RunVimInTerminal('-S XscriptPropsVisualBlock', #{rows: 6, cols: 60})
2746 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_1', {})
zeertzjqfc305842023-08-19 13:27:03 +02002747 call term_sendkeys(buf, "\<C-V>3jl")
zeertzjq6e940d92023-08-17 23:21:40 +02002748 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_2', {})
2749 call term_sendkeys(buf, "l")
2750 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_3', {})
2751 call term_sendkeys(buf, "4l")
2752 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_4', {})
2753 call term_sendkeys(buf, "Ol")
2754 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_5', {})
2755 call term_sendkeys(buf, "l")
2756 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_6', {})
2757 call term_sendkeys(buf, "l")
2758 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_7', {})
2759
2760 call StopVimInTerminal(buf)
2761endfunc
2762
zeertzjqb557f482023-08-22 22:07:34 +02002763func Run_test_prop_inserts_text_showbreak(cmd)
2764 CheckRunVimInTerminal
2765
2766 let lines =<< trim END
2767 highlight! link LineNr Normal
zeertzjq6a389722023-08-27 19:04:14 +02002768 setlocal number showbreak=+ breakindent breakindentopt=shift:2
2769 setlocal scrolloff=0 smoothscroll
zeertzjqb557f482023-08-22 22:07:34 +02002770 call setline(1, repeat('a', 28))
2771 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002772 call prop_add(1, 28, #{type: 'theprop', text: repeat('123', 23)})
zeertzjqb557f482023-08-22 22:07:34 +02002773 normal! $
2774 END
2775 let lines = insert(lines, a:cmd)
2776 call writefile(lines, 'XscriptPropsShowbreak', 'D')
2777 let buf = RunVimInTerminal('-S XscriptPropsShowbreak', #{rows: 6, cols: 30})
2778 call term_sendkeys(buf, ":set noruler\<CR>")
2779 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_1', {})
2780 call term_sendkeys(buf, "\<C-E>")
2781 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_2', {})
2782 call term_sendkeys(buf, "\<C-E>")
2783 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_3', {})
2784 call term_sendkeys(buf, "\<C-E>")
2785 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_4', {})
2786 call term_sendkeys(buf, "\<C-E>")
2787 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_5', {})
2788 call term_sendkeys(buf, "zbi")
2789 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_6', {})
2790 call term_sendkeys(buf, "\<BS>")
2791 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_7', {})
2792 call term_sendkeys(buf, "\<Esc>l")
2793 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_8', {})
2794 call term_sendkeys(buf, "\<C-E>")
2795 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_9', {})
2796 call term_sendkeys(buf, "\<C-E>")
2797 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_10', {})
2798 call term_sendkeys(buf, "\<C-E>")
2799 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_11', {})
2800 call term_sendkeys(buf, "\<C-E>")
2801 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_12', {})
2802 call term_sendkeys(buf, "023x$")
2803 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_13', {})
2804 call term_sendkeys(buf, "\<C-E>")
2805 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_14', {})
2806 call term_sendkeys(buf, "\<C-E>")
2807 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_15', {})
2808 call term_sendkeys(buf, "\<C-E>")
2809 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_16', {})
2810 call term_sendkeys(buf, "zbi")
2811 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_17', {})
2812 call term_sendkeys(buf, "\<C-U>")
2813 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_18', {})
2814 call term_sendkeys(buf, "\<Esc>")
2815 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_19', {})
2816 call term_sendkeys(buf, "\<C-E>")
2817 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_20', {})
2818 call term_sendkeys(buf, "\<C-E>")
2819 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_21', {})
zeertzjq11939512023-08-23 20:58:01 +02002820 call term_sendkeys(buf, "zbx")
2821 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_22', {})
zeertzjq6a389722023-08-27 19:04:14 +02002822 call term_sendkeys(buf, "26ia\<Esc>a")
2823 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_23', {})
2824 call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal breakindentopt=\<CR>")
2825 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_24', {})
zeertzjqb557f482023-08-22 22:07:34 +02002826
2827 call StopVimInTerminal(buf)
2828endfunc
2829
2830func Test_prop_inserts_text_showbreak()
2831 call Run_test_prop_inserts_text_showbreak('')
2832 " because of 'breakindent' the screendumps are the same
2833 call Run_test_prop_inserts_text_showbreak('set cpoptions+=n')
2834endfunc
2835
2836func Test_prop_before_tab_skipcol()
2837 CheckRunVimInTerminal
2838
2839 let lines =<< trim END
zeertzjq6a389722023-08-27 19:04:14 +02002840 setlocal list listchars=tab:<-> scrolloff=0 smoothscroll
zeertzjqb557f482023-08-22 22:07:34 +02002841 call setline(1, repeat("\t", 4) .. 'a')
2842 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002843 call prop_add(1, 4, #{type: 'theprop', text: repeat('12', 32)})
zeertzjqb557f482023-08-22 22:07:34 +02002844 normal! $
2845 END
2846 call writefile(lines, 'XscriptPropsBeforeTabSkipcol', 'D')
2847 let buf = RunVimInTerminal('-S XscriptPropsBeforeTabSkipcol', #{rows: 6, cols: 30})
2848 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_1', {})
2849 call term_sendkeys(buf, "\<C-E>")
2850 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_2', {})
2851 call term_sendkeys(buf, "\<C-E>")
2852 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_3', {})
2853 call term_sendkeys(buf, "\<C-E>")
2854 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_4', {})
2855 call term_sendkeys(buf, "zbh")
2856 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_5', {})
2857 call term_sendkeys(buf, "i")
2858 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_6', {})
2859 call term_sendkeys(buf, "\<C-O>:setlocal nolist\<CR>")
2860 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_7', {})
2861 call term_sendkeys(buf, "\<Esc>l")
2862 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_8', {})
2863 call term_sendkeys(buf, "\<C-E>")
2864 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_9', {})
2865 call term_sendkeys(buf, "\<C-E>")
2866 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_10', {})
2867 call term_sendkeys(buf, "\<C-E>")
2868 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_11', {})
2869
2870 call StopVimInTerminal(buf)
2871endfunc
2872
zeertzjq6e55e852023-08-30 16:55:09 +02002873func Test_prop_inserts_text_before_linebreak()
2874 CheckRunVimInTerminal
2875
2876 let lines =<< trim END
2877 setlocal linebreak showbreak=+ breakindent breakindentopt=shift:2
2878 call setline(1, repeat('a', 50) .. ' ' .. repeat('c', 45))
2879 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002880 call prop_add(1, 51, #{type: 'theprop', text: repeat('b', 10)})
zeertzjq6e55e852023-08-30 16:55:09 +02002881 normal! $
2882 END
2883 call writefile(lines, 'XscriptPropsBeforeLinebreak', 'D')
2884 let buf = RunVimInTerminal('-S XscriptPropsBeforeLinebreak', #{rows: 6, cols: 50})
2885 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_linebreak_1', {})
2886 call term_sendkeys(buf, '05x$')
2887 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_linebreak_2', {})
2888
2889 call StopVimInTerminal(buf)
2890endfunc
2891
zeertzjqac2d8812023-08-31 18:07:30 +02002892func Test_prop_inserts_text_before_double_width_wrap()
2893 CheckRunVimInTerminal
2894
2895 let lines =<< trim END
2896 call setline(1, repeat('a', 40) .. '口' .. '12345')
2897 call prop_type_add('theprop', #{highlight: 'Special'})
2898 call prop_add(1, 41, #{type: 'theprop', text: repeat('b', 9)})
2899 normal! $
2900 END
2901 call writefile(lines, 'XscriptPropsBeforeDoubleWidthWrap', 'D')
2902 let buf = RunVimInTerminal('-S XscriptPropsBeforeDoubleWidthWrap', #{rows: 3, cols: 50})
2903 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_1', {})
2904
2905 call StopVimInTerminal(buf)
2906endfunc
2907
zeertzjq6a389722023-08-27 19:04:14 +02002908func Test_prop_inserts_text_lcs_extends()
2909 CheckRunVimInTerminal
2910
2911 let lines =<< trim END
2912 setlocal nowrap list listchars=extends:!
2913 call setline(1, repeat('a', &columns + 1))
2914 call prop_type_add('theprop', #{highlight: 'Special'})
2915 call prop_add(1, &columns + 2, #{type: 'theprop', text: 'bbb'})
2916 END
2917 call writefile(lines, 'XscriptPropsListExtends', 'D')
2918 let buf = RunVimInTerminal('-S XscriptPropsListExtends', #{rows: 3, cols: 50})
2919 call term_sendkeys(buf, '20l')
2920 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_1', {})
2921 call term_sendkeys(buf, 'zl')
2922 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_2', {})
2923 call term_sendkeys(buf, 'zl')
2924 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_3', {})
2925 call term_sendkeys(buf, 'zl')
2926 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_4', {})
2927 call term_sendkeys(buf, 'zl')
2928 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_5', {})
2929
2930 call StopVimInTerminal(buf)
2931endfunc
2932
Bram Moolenaarfb593c52022-09-17 18:57:36 +01002933func Test_prop_add_with_text_fails()
2934 call prop_type_add('failing', #{highlight: 'ErrorMsg'})
2935 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_lnum: 1})", 'E1305:')
2936 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_col: 1})", 'E1305:')
2937 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', length: 1})", 'E1305:')
2938
2939 call prop_type_delete('failing')
2940endfunc
2941
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002942func Test_props_with_text_right_align_twice()
2943 CheckRunVimInTerminal
2944
2945 let lines =<< trim END
2946 call setline(1, ["some text some text some text some text", 'line two'])
Bram Moolenaarfb593c52022-09-17 18:57:36 +01002947 call prop_type_add('MyErrorText', #{highlight: 'ErrorMsg'})
2948 call prop_type_add('MyPadding', #{highlight: 'DiffChange'})
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002949 call prop_add(1, 0, #{type: 'MyPadding', text: ' nothing here', text_wrap: 'wrap'})
2950 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Some error', text_wrap: 'wrap', text_align: 'right'})
2951 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Another error', text_wrap: 'wrap', text_align: 'right'})
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002952 normal G$
2953 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002954 call writefile(lines, 'XscriptPropsRightAlign', 'D')
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002955 let buf = RunVimInTerminal('-S XscriptPropsRightAlign', #{rows: 8})
2956 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_1', {})
2957
2958 call term_sendkeys(buf, "ggisome more text\<Esc>G$")
2959 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {})
2960
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002961 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2962 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_3', {})
2963
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002964 call StopVimInTerminal(buf)
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002965endfunc
2966
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002967func Test_props_with_text_after()
2968 CheckRunVimInTerminal
2969
2970 let lines =<< trim END
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002971 set showbreak=+++
Bram Moolenaar73c38422022-08-07 11:53:40 +01002972 set breakindent
2973 call setline(1, ' some text here and other text there')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002974 call prop_type_add('rightprop', #{highlight: 'ErrorMsg'})
2975 call prop_type_add('afterprop', #{highlight: 'Search'})
2976 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
2977 call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002978 call prop_add(1, 0, #{type: 'afterprop', text: "\tAFTER\t", text_align: 'after'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002979 call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'})
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002980 call prop_add(1, 0, #{type: 'belowprop', text: ' ALSO BELOW ', text_align: 'below'})
Bram Moolenaar84b247f2022-08-01 11:17:40 +01002981
2982 call setline(2, 'Last line.')
2983 call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'})
2984 normal G$
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002985
2986 call setline(3, 'right here')
2987 call prop_add(3, 0, #{type: 'rightprop', text: 'sΓΆmeε’ŒεΉ³tΓ©xt', text_align: 'right'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002988 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002989 call writefile(lines, 'XscriptPropsWithTextAfter', 'D')
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002990 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002991 call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {})
2992
2993 call StopVimInTerminal(buf)
Bram Moolenaar82b14c12022-08-10 19:50:47 +01002994
2995 call assert_fails('call prop_add(1, 2, #{text: "yes", text_align: "right", type: "some"})', 'E1294:')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002996endfunc
2997
Bram Moolenaar877151b2022-10-11 15:29:50 +01002998func Test_props_with_text_after_and_list()
2999 CheckRunVimInTerminal
3000
3001 let lines =<< trim END
3002 vim9script
3003 setline(1, ['one', 'two'])
3004 prop_type_add('test', {highlight: 'Special'})
3005 prop_add(1, 0, {
3006 type: 'test',
3007 text: range(50)->join(' '),
3008 text_align: 'after',
3009 text_padding_left: 3
3010 })
3011 prop_add(1, 0, {
3012 type: 'test',
3013 text: range(50)->join('-'),
3014 text_align: 'after',
3015 text_padding_left: 5
3016 })
3017 prop_add(1, 0, {
3018 type: 'test',
3019 text: range(50)->join('.'),
3020 text_align: 'after',
3021 text_padding_left: 1
3022 })
3023 normal G$
3024 END
3025 call writefile(lines, 'XscriptPropsAfter', 'D')
3026 let buf = RunVimInTerminal('-S XscriptPropsAfter', #{rows: 8, cols: 60})
3027 call VerifyScreenDump(buf, 'Test_props_after_1', {})
3028
3029 call term_sendkeys(buf, ":set list\<CR>")
3030 call VerifyScreenDump(buf, 'Test_props_after_2', {})
3031
3032 call StopVimInTerminal(buf)
3033endfunc
3034
Bram Moolenaarcba69522022-08-06 21:03:53 +01003035func Test_props_with_text_after_below_trunc()
3036 CheckRunVimInTerminal
3037
3038 let lines =<< trim END
3039 vim9script
3040 edit foobar
3041 set showbreak=+++
3042 setline(1, ['onasdf asdf asdf asdf asd fas df', 'two'])
3043 prop_type_add('test', {highlight: 'Special'})
3044 prop_add(1, 0, {
3045 type: 'test',
3046 text: 'the quick brown fox jumps over the lazy dog',
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003047 text_align: 'after',
Bram Moolenaarcba69522022-08-06 21:03:53 +01003048 })
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003049 prop_type_add('another', {highlight: 'DiffChange'})
Bram Moolenaarcba69522022-08-06 21:03:53 +01003050 prop_add(1, 0, {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003051 type: 'another',
Bram Moolenaarcba69522022-08-06 21:03:53 +01003052 text: 'the quick brown fox jumps over the lazy dog',
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003053 text_align: 'below',
3054 text_padding_left: 4,
Bram Moolenaarcba69522022-08-06 21:03:53 +01003055 })
3056 normal G$
3057 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003058 call writefile(lines, 'XscriptPropsAfterTrunc', 'D')
Bram Moolenaarcba69522022-08-06 21:03:53 +01003059 let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60})
3060 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {})
3061
Bram Moolenaarccf28372022-10-10 21:10:03 +01003062 call term_sendkeys(buf, ":set number\<CR>")
3063 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_2', {})
3064
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003065 call term_sendkeys(buf, ":set cursorline\<CR>gg")
3066 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_3', {})
3067
Bram Moolenaarcba69522022-08-06 21:03:53 +01003068 call StopVimInTerminal(buf)
Bram Moolenaarcba69522022-08-06 21:03:53 +01003069endfunc
3070
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003071func Test_props_with_text_truncated_just_before_after()
3072 CheckRunVimInTerminal
3073
3074 let lines =<< trim END
3075 vim9script
3076 set showbreak=+++
3077 set list listchars=extends:>
3078 set nowrap
3079
3080 setline(1, [
3081 'here is text long enough to fill the row',
3082 'second line',
3083 ])
3084
3085 prop_type_add("test", {"highlight": "Error"})
3086 prop_add(1, 0, {type: "test", text: "after text", text_padding_left: 1})
3087 def g:AddPropBelow()
3088 prop_add(1, 0, {type: "test", text_align: "below", text: "below text"})
3089 enddef
3090 def g:AddPropRight()
3091 prop_add(1, 0, {type: "test", text_align: "right", text: "right text"})
3092 enddef
3093 normal G$
3094 END
3095 call writefile(lines, 'XscriptPropsWithTextTruncatedJustBeforeAfter', 'D')
3096 let buf = RunVimInTerminal('-S XscriptPropsWithTextTruncatedJustBeforeAfter', #{rows: 8, cols: 40})
3097 call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_1', {})
3098
3099 call term_sendkeys(buf, ":call AddPropBelow()\<CR>")
3100 call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_2', {})
3101
3102 call StopVimInTerminal(buf)
3103endfunc
3104
porygonisaduck38854b52022-11-27 20:55:05 +00003105func Test_prop_with_text_below_after_empty()
3106 CheckRunVimInTerminal
3107
3108 let lines =<< trim END
3109 vim9script
Bram Moolenaar94722c52023-01-28 19:19:03 +00003110
porygonisaduck38854b52022-11-27 20:55:05 +00003111 setline(1, ['vim9script', '', 'three', ''])
3112
3113 # Add text prop below empty line 2 with padding.
3114 prop_type_add('test', {highlight: 'ErrorMsg'})
3115 prop_add(2, 0, {
3116 type: 'test',
3117 text: 'The quick brown fox jumps over the lazy dog',
3118 text_align: 'below',
3119 text_padding_left: 1,
3120 })
3121
3122 # Add text prop below empty line 4 without padding.
3123 prop_type_add('other', {highlight: 'DiffChange'})
3124 prop_add(4, 0, {
3125 type: 'other',
3126 text: 'The slow fox bumps into the lazy dog',
3127 text_align: 'below',
3128 text_padding_left: 0,
3129 })
3130 END
3131 call writefile(lines, 'XscriptPropBelowAfterEmpty', 'D')
3132 let buf = RunVimInTerminal('-S XscriptPropBelowAfterEmpty', #{rows: 8, cols: 60})
Bram Moolenaar94722c52023-01-28 19:19:03 +00003133 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_1', {})
porygonisaduck38854b52022-11-27 20:55:05 +00003134
Bram Moolenaar7c02ad92022-11-29 21:37:13 +00003135 call term_sendkeys(buf, ":set number\<CR>")
Bram Moolenaar94722c52023-01-28 19:19:03 +00003136 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_2', {})
Bram Moolenaar7c02ad92022-11-29 21:37:13 +00003137
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003138 call term_sendkeys(buf, ":set nowrap\<CR>")
Bram Moolenaar94722c52023-01-28 19:19:03 +00003139 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_3', {})
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003140
porygonisaduck38854b52022-11-27 20:55:05 +00003141 call StopVimInTerminal(buf)
3142endfunc
3143
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003144func Test_prop_with_text_above_below_empty()
3145 CheckRunVimInTerminal
3146
3147 let lines =<< trim END
3148 setlocal number
3149 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3150
3151 let vt = 'test'
3152 call prop_type_add(vt, {'highlight': 'ToDo'})
3153 for ln in range(1, line('$'))
Dylan Thacker-Smithda0c9132024-02-27 20:25:10 +01003154 " use 1 character text to test for off-by-one regressions
3155 call prop_add(ln, 0, {'type': vt, 'text': '-', 'text_align': 'above'})
3156 call prop_add(ln, 0, {'type': vt, 'text': '+', 'text_align': 'below'})
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003157 endfor
3158 normal G
zeertzjq918b92b2024-03-20 19:49:20 +01003159
3160 func AddMore()
3161 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3162 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3163 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3164 endfunc
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003165 END
3166 call writefile(lines, 'XscriptPropAboveBelowEmpty', 'D')
3167 let buf = RunVimInTerminal('-S XscriptPropAboveBelowEmpty', #{rows: 16, cols: 60})
3168 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_1', {})
3169
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003170 call term_sendkeys(buf, ":set list\<CR>")
3171 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_2', {})
3172
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003173 call term_sendkeys(buf, ":set nolist\<CR>")
3174 call term_sendkeys(buf, ":set colorcolumn=10\<CR>")
3175 call term_sendkeys(buf, ":\<CR>")
3176 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_3', {})
3177
Bram Moolenaara572b932023-02-19 14:34:37 +00003178 call term_sendkeys(buf, ":set colorcolumn=\<CR>")
3179 call term_sendkeys(buf, ":set relativenumber\<CR>")
3180 call term_sendkeys(buf, ":\<CR>")
3181 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_4', {})
3182
3183 call term_sendkeys(buf, "kk")
3184 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_5', {})
3185
zeertzjq918b92b2024-03-20 19:49:20 +01003186 " This was drawing line number over cmdline and leaking memory.
3187 call term_sendkeys(buf, ":call AddMore()\<CR>")
3188 call term_sendkeys(buf, "gg")
3189 call term_sendkeys(buf, "j")
3190 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_6', {})
3191
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003192 call StopVimInTerminal(buf)
3193endfunc
3194
Bram Moolenaarea62cee2023-02-19 18:36:41 +00003195func Test_prop_with_multibyte_below()
3196 CheckRunVimInTerminal
3197
3198 let lines =<< trim END
3199 setlocal number
3200 call setline(1, ['Β©', 'Β©', 'Β©'])
3201
3202 let vt = 'test'
3203 call prop_type_add(vt, {'highlight': 'ToDo'})
3204 for ln in range(1, line('$'))
3205 call prop_add(ln, 0, {'type': vt, 'text': '+++', 'text_align': 'below'})
3206 endfor
3207 normal G
3208 END
3209 call writefile(lines, 'XscriptPropMultibyteBelow', 'D')
3210 let buf = RunVimInTerminal('-S XscriptPropMultibyteBelow', #{rows: 10, cols: 60})
3211 call VerifyScreenDump(buf, 'Test_prop_multibyte_below_1', {})
3212
3213 call StopVimInTerminal(buf)
3214endfunc
3215
zeertzjq6b9c2022023-09-11 20:01:17 +02003216func Test_prop_with_text_below_rightleft()
3217 CheckRunVimInTerminal
3218 CheckFeature rightleft
3219
3220 let lines =<< trim END
3221 setlocal number rightleft
3222 call setline(1, 'abcde')
3223 call prop_type_add('theprop', #{highlight: 'Special'})
3224 call prop_add(1, 0, #{type: 'theprop', text: '12345', text_align: 'below'})
3225 END
3226 call writefile(lines, 'XscriptPropBelowRightleft', 'D')
3227 let buf = RunVimInTerminal('-S XscriptPropBelowRightleft', #{rows: 6, cols: 60})
3228 call VerifyScreenDump(buf, 'Test_prop_below_rightleft_1', {})
3229
3230 call StopVimInTerminal(buf)
3231endfunc
3232
Bram Moolenaar5ceb8152023-02-12 18:11:21 +00003233func Test_prop_with_text_above_empty()
3234 CheckRunVimInTerminal
3235
3236 " check the cursor is in the correct line
3237 let lines =<< trim END
3238 setlocal number
3239 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3240
3241 let vt = 'test'
3242 call prop_type_add(vt, {'highlight': 'ToDo'})
3243 for ln in range(1, line('$'))
3244 call prop_add(ln, 0, {'type': vt, 'text': '---', 'text_align': 'above'})
3245 endfor
3246 normal G
3247 END
3248 call writefile(lines, 'XscriptPropAboveEmpty', 'D')
3249 let buf = RunVimInTerminal('-S XscriptPropAboveEmpty', #{rows: 16, cols: 60})
3250 call VerifyScreenDump(buf, 'Test_prop_above_empty_1', {})
3251
3252 call term_sendkeys(buf, ":set list\<CR>")
3253 call VerifyScreenDump(buf, 'Test_prop_above_empty_2', {})
3254
3255 call StopVimInTerminal(buf)
3256endfunc
3257
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003258func Test_prop_with_text_below_after_match()
3259 CheckRunVimInTerminal
3260
3261 let lines =<< trim END
3262 vim9script
3263
3264 setline(1, ['vim9script', 'some text'])
3265 set signcolumn=yes
3266 matchaddpos('Search', [[1, 10]])
3267 prop_type_add('test', {highlight: 'Error'})
3268 prop_add(1, 0, {
3269 type: 'test',
3270 text: 'The quick brown fox',
3271 text_align: 'below'
3272 })
3273 END
3274 call writefile(lines, 'XscriptPropsBelow', 'D')
3275 let buf = RunVimInTerminal('-S XscriptPropsBelow', #{rows: 8, cols: 60})
3276 call VerifyScreenDump(buf, 'Test_prop_with_text_below_after_match_1', {})
3277
3278 call StopVimInTerminal(buf)
3279endfunc
3280
Bram Moolenaare175dc62022-08-01 22:18:50 +01003281func Test_props_with_text_after_joined()
3282 CheckRunVimInTerminal
3283
3284 let lines =<< trim END
3285 call setline(1, ['one', 'two', 'three', 'four'])
3286 call prop_type_add('afterprop', #{highlight: 'Search'})
3287 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'})
3288 call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'})
3289 normal ggJ
3290 normal GkJ
3291
3292 call setline(3, ['a', 'b', 'c', 'd', 'e', 'f'])
3293 call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'})
3294 call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'})
3295 call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'})
3296 call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'})
3297 normal 3G6J
3298 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003299 call writefile(lines, 'XscriptPropsWithTextAfterJoined', 'D')
Bram Moolenaare175dc62022-08-01 22:18:50 +01003300 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60})
3301 call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {})
3302
3303 call StopVimInTerminal(buf)
Bram Moolenaare175dc62022-08-01 22:18:50 +01003304endfunc
3305
Bram Moolenaar398649e2022-08-04 15:03:48 +01003306func Test_props_with_text_after_truncated()
3307 CheckRunVimInTerminal
3308
3309 let lines =<< trim END
3310 call setline(1, ['one two three four five six seven'])
3311 call prop_type_add('afterprop', #{highlight: 'Search'})
3312 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3313
3314 call setline(2, ['one two three four five six seven'])
3315 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3316
3317 call setline(3, ['one two three four five six seven'])
3318 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'})
3319
3320 call setline(4, ['cursor here'])
3321 normal 4Gfh
3322 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003323 call writefile(lines, 'XscriptPropsWithTextAfterTrunc', 'D')
Bram Moolenaar398649e2022-08-04 15:03:48 +01003324 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60})
3325 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {})
3326
3327 call term_sendkeys(buf, ":37vsp\<CR>gg")
3328 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {})
3329
3330 call term_sendkeys(buf, ":36wincmd |\<CR>")
3331 call term_sendkeys(buf, "2G$")
3332 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {})
3333
3334 call term_sendkeys(buf, ":33wincmd |\<CR>")
3335 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {})
3336
3337 call term_sendkeys(buf, ":18wincmd |\<CR>")
3338 call term_sendkeys(buf, "0fx")
3339 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {})
3340
3341 call StopVimInTerminal(buf)
Bram Moolenaar398649e2022-08-04 15:03:48 +01003342endfunc
3343
h-east4c42c7e2023-04-17 21:44:57 +01003344func Test_props_with_text_after_truncated_and_ambiwidth_is_double()
3345 CheckRunVimInTerminal
3346
3347 let lines =<< trim END
3348 set ambiwidth=double
3349 call setline(1, ['one two three four five six seven'])
3350 call prop_type_add('afterprop', #{highlight: 'Search'})
3351 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3352
3353 call setline(2, ['one two three four five six seven'])
3354 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3355
3356 call setline(3, ['one two three four five six seven'])
3357 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'})
3358
3359 call setline(4, ['cursor here'])
3360 normal 4Gfh
3361 END
3362 call writefile(lines, 'XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', 'D')
3363 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', #{rows: 9, cols: 60})
3364 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_ambiw_d_1', {})
3365
3366 call StopVimInTerminal(buf)
3367endfunc
3368
3369
3370func Test_props_with_text_after_truncated_not_utf8()
3371 CheckRunVimInTerminal
3372
3373 let lines =<< trim END
3374 set enc=cp932 tenc=utf-8
3375 call setline(1, ['one two three four five six seven'])
3376 call prop_type_add('afterprop', #{highlight: 'Search'})
3377 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3378
3379 call setline(2, ['one two three four five six seven'])
3380 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3381
3382 call setline(3, ['one two three four five six seven'])
3383 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'})
3384
3385 call setline(4, ['cursor here'])
3386 normal 4Gfh
3387 END
3388 call writefile(lines, 'XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', 'D')
3389 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', #{rows: 9, cols: 60})
3390 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_not_utf8', {})
3391
3392 call StopVimInTerminal(buf)
3393endfunc
3394
Bram Moolenaar49a90792022-08-09 18:25:23 +01003395func Test_props_with_text_empty_line()
3396 CheckRunVimInTerminal
3397
3398 let lines =<< trim END
3399 call setline(1, ['', 'aaa', '', 'bbbbbb'])
3400 call prop_type_add('prop1', #{highlight: 'Search'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02003401 call prop_add(1, 1, #{type: 'prop1', text: repeat('X', &columns)})
3402 call prop_add(3, 1, #{type: 'prop1', text: repeat('X', &columns + 1)})
Bram Moolenaar49a90792022-08-09 18:25:23 +01003403 normal gg0
3404 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003405 call writefile(lines, 'XscriptPropsWithTextEmptyLine', 'D')
Bram Moolenaar49a90792022-08-09 18:25:23 +01003406 let buf = RunVimInTerminal('-S XscriptPropsWithTextEmptyLine', #{rows: 8, cols: 60})
3407 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_1', {})
3408 call term_sendkeys(buf, "$")
3409 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_2', {})
3410 call term_sendkeys(buf, "j")
3411 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_3', {})
3412 call term_sendkeys(buf, "j")
3413 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_4', {})
3414 call term_sendkeys(buf, "j")
3415 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_5', {})
zeertzjqe3daa062023-08-27 19:11:46 +02003416 call term_sendkeys(buf, "0\<C-V>2l2k")
3417 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_6', {})
3418 call term_sendkeys(buf, "\<Esc>/aaa\\n\\%V\<CR>")
3419 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_7', {})
3420 call term_sendkeys(buf, "3ggic")
3421 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_8', {})
3422 call term_sendkeys(buf, "\<Esc>/aaa\\nc\\%V\<CR>")
3423 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_9', {})
Bram Moolenaar49a90792022-08-09 18:25:23 +01003424
3425 call StopVimInTerminal(buf)
Bram Moolenaar49a90792022-08-09 18:25:23 +01003426endfunc
3427
Bram Moolenaar398649e2022-08-04 15:03:48 +01003428func Test_props_with_text_after_wraps()
3429 CheckRunVimInTerminal
3430
3431 let lines =<< trim END
3432 call setline(1, ['one two three four five six seven'])
3433 call prop_type_add('afterprop', #{highlight: 'Search'})
3434 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'})
3435
3436 call setline(2, ['one two three four five six seven'])
3437 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'})
3438
3439 call setline(3, ['one two three four five six seven'])
3440 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'})
3441
3442 call setline(4, ['cursor here'])
3443 normal 4Gfh
3444 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003445 call writefile(lines, 'XscriptPropsWithTextAfterWraps', 'D')
Bram Moolenaar398649e2022-08-04 15:03:48 +01003446 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60})
3447 call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {})
3448
3449 call StopVimInTerminal(buf)
Bram Moolenaar398649e2022-08-04 15:03:48 +01003450endfunc
3451
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003452func Test_props_with_text_after_nowrap()
3453 CheckRunVimInTerminal
3454
3455 let lines =<< trim END
3456 set nowrap
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003457 call setline(1, ['one', 'two', 'three', 'four'])
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003458 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
3459 call prop_type_add('anotherprop', #{highlight: 'Search'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01003460 call prop_type_add('someprop', #{highlight: 'DiffChange'})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003461 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
3462 call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'})
3463 call prop_add(2, 0, #{type: 'belowprop', text: 'One More Here', text_align: 'below'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01003464 call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'})
3465 call prop_add(1, 0, #{type: 'someprop', text: ' After the text', text_align: 'after'})
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003466 normal 3G$
3467
3468 call prop_add(3, 0, #{type: 'anotherprop', text: 'right aligned', text_align: 'right'})
3469 call prop_add(3, 0, #{type: 'anotherprop', text: 'also right aligned', text_align: 'right'})
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003470 hi CursorLine ctermbg=lightgrey
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003471 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003472 call writefile(lines, 'XscriptPropsAfterNowrap', 'D')
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003473 let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 12, cols: 60})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003474 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {})
3475
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003476 call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\<CR>")
Bram Moolenaar1306b362022-08-06 15:59:06 +01003477 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {})
3478
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003479 call term_sendkeys(buf, "j")
3480 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_3', {})
3481
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 call StopVimInTerminal(buf)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483endfunc
3484
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003485func Test_prop_with_text_below_cul()
3486 CheckRunVimInTerminal
3487
3488 let lines =<< trim END
3489 vim9script
3490
3491 setline(1, ['some text', 'last line'])
3492 set cursorline nowrap
3493 prop_type_add('test', {highlight: 'DiffChange'})
3494 prop_add(1, 0, {
3495 type: 'test',
3496 text: 'The quick brown fox jumps over the lazy dog',
3497 text_align: 'below',
3498 text_padding_left: 4,
3499 })
3500 END
3501 call writefile(lines, 'XscriptPropsBelowCurline', 'D')
3502 let buf = RunVimInTerminal('-S XscriptPropsBelowCurline', #{rows: 6, cols: 60})
3503 call VerifyScreenDump(buf, 'Test_prop_with_text_below_cul_1', {})
3504
3505 call StopVimInTerminal(buf)
3506endfunc
3507
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003508func Test_props_with_text_below_nowrap()
3509 CheckRunVimInTerminal
3510
3511 let lines =<< trim END
3512 vim9script
3513 edit foobar
3514 set nowrap
3515 set showbreak=+++\
3516 setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two'])
3517 prop_type_add('test', {highlight: 'Special'})
3518 prop_add(1, 0, {
3519 type: 'test',
3520 text: 'the quick brown fox jumps over the lazy dog',
3521 text_align: 'after'
3522 })
3523 prop_add(1, 0, {
3524 type: 'test',
3525 text: 'the quick brown fox jumps over the lazy dog',
3526 text_align: 'below'
3527 })
3528 normal G$
3529 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003530 call writefile(lines, 'XscriptPropsBelowNowrap', 'D')
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003531 let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60})
3532 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {})
3533
3534 call term_sendkeys(buf, "gg$")
3535 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {})
3536
3537 call StopVimInTerminal(buf)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003538endfunc
3539
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003540func Test_props_with_text_above()
3541 CheckRunVimInTerminal
3542
3543 let lines =<< trim END
3544 call setline(1, ['one two', 'three four', 'five six'])
3545 call prop_type_add('above1', #{highlight: 'Search'})
3546 call prop_type_add('above2', #{highlight: 'DiffChange'})
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003547 call prop_type_add('below', #{highlight: 'DiffAdd'})
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003548 call prop_add(1, 0, #{type: 'above1', text: 'first thing above', text_align: 'above'})
3549 call prop_add(1, 0, #{type: 'above2', text: 'second thing above', text_align: 'above'})
Bram Moolenaar79f8b842022-09-11 13:31:01 +01003550 call prop_add(3, 0, #{type: 'above1', text: 'another thing', text_align: 'above', text_padding_left: 3})
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003551
3552 normal gglllj
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003553 func AddPropBelow()
3554 call prop_add(1, 0, #{type: 'below', text: 'below', text_align: 'below'})
3555 endfunc
Bram Moolenaar9466fb82022-10-11 14:54:42 +01003556 func AddLongPropAbove()
3557 3,4delete
3558 set wrap
3559 call prop_add(1, 0, #{type: 'above1', text: range(50)->join(' '), text_align: 'above', text_padding_left: 2})
3560 endfunc
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003561 END
3562 call writefile(lines, 'XscriptPropsWithTextAbove', 'D')
3563 let buf = RunVimInTerminal('-S XscriptPropsWithTextAbove', #{rows: 9, cols: 60})
3564 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1', {})
3565
Bram Moolenaare24b4ab2022-09-16 20:51:14 +01003566 call term_sendkeys(buf, "ggg$")
3567 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1a', {})
3568 call term_sendkeys(buf, "g0")
3569 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1b', {})
3570
Bram Moolenaar4c7fd4d2022-09-17 17:15:33 +01003571 call term_sendkeys(buf, ":set showbreak=>>\<CR>")
3572 call term_sendkeys(buf, "ggll")
3573 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1c', {})
3574 call term_sendkeys(buf, ":set showbreak=\<CR>")
3575
Bram Moolenaar88b79cb2022-09-10 22:32:14 +01003576 call term_sendkeys(buf, "ggI")
3577 call VerifyScreenDump(buf, 'Test_prop_with_text_above_2', {})
3578 call term_sendkeys(buf, "inserted \<Esc>")
3579 call VerifyScreenDump(buf, 'Test_prop_with_text_above_3', {})
3580
Bram Moolenaar79f8b842022-09-11 13:31:01 +01003581 call term_sendkeys(buf, ":set number signcolumn=yes\<CR>")
3582 call VerifyScreenDump(buf, 'Test_prop_with_text_above_4', {})
3583
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003584 call term_sendkeys(buf, ":set nowrap\<CR>gg$j")
3585 call VerifyScreenDump(buf, 'Test_prop_with_text_above_5', {})
3586
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003587 call term_sendkeys(buf, ":call AddPropBelow()\<CR>")
3588 call term_sendkeys(buf, "ggve")
3589 call VerifyScreenDump(buf, 'Test_prop_with_text_above_6', {})
3590 call term_sendkeys(buf, "V")
3591 call VerifyScreenDump(buf, 'Test_prop_with_text_above_7', {})
3592
Bram Moolenaar3b93cf22022-09-13 18:34:18 +01003593 call term_sendkeys(buf, "\<Esc>ls\<CR>\<Esc>")
3594 call VerifyScreenDump(buf, 'Test_prop_with_text_above_8', {})
3595
Bram Moolenaar9466fb82022-10-11 14:54:42 +01003596 call term_sendkeys(buf, ":call AddLongPropAbove()\<CR>")
3597 call VerifyScreenDump(buf, 'Test_prop_with_text_above_9', {})
3598
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003599 call StopVimInTerminal(buf)
3600endfunc
3601
Bram Moolenaar2354b662023-04-23 21:42:25 +01003602func Test_prop_with_text_above_padding()
3603 CheckRunVimInTerminal
3604
3605 let lines =<< trim END
3606 vim9script
3607
3608 setlocal tabstop=8 noexpandtab
3609 setline(1, ['', 'sky is blue', 'ocean is blue'])
3610 prop_type_add('DiagVirtualText', {highlight: 'Search', override: true})
3611 prop_add(3, 0, {text: "β”Œβ”€ start", text_align: "above",
3612 type: 'DiagVirtualText',
3613 text_padding_left: 200})
3614 END
3615 call writefile(lines, 'XscriptAbovePadding', 'D')
3616 let buf = RunVimInTerminal('-S XscriptAbovePadding', #{rows: 8})
3617 call VerifyScreenDump(buf, 'Test_prop_above_padding_1', {})
3618
3619 call StopVimInTerminal(buf)
3620endfunc
3621
Bram Moolenaar702bd6c2022-09-14 16:09:57 +01003622func Test_prop_above_with_indent()
3623 new
3624 call setline(1, ['first line', ' second line', ' line below'])
3625 setlocal cindent
3626 call prop_type_add('indented', #{highlight: 'Search'})
3627 call prop_add(3, 0, #{type: 'indented', text: 'here', text_align: 'above', text_padding_left: 4})
3628 call assert_equal(' line below', getline(3))
3629
3630 exe "normal 3G2|a\<CR>"
3631 call assert_equal(' ', getline(3))
3632 call assert_equal(' line below', getline(4))
3633
3634 bwipe!
3635 call prop_type_delete('indented')
3636endfunc
3637
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01003638func Test_prop_above_with_number()
3639 CheckRunVimInTerminal
3640
3641 let lines =<< trim END
3642 vim9script
3643 setline(1, ['one one one', 'two two two', 'three three three'])
3644 set number cpo+=n
3645 prop_type_add('test', {highlight: 'DiffChange'})
3646 prop_add(2, 0, {
3647 text: 'above the text',
3648 type: 'test',
3649 text_align: 'above',
3650 })
3651 def g:OneMore()
3652 prop_add(2, 0, {
3653 text: 'also above the text',
3654 type: 'test',
3655 text_align: 'above',
3656 })
3657 enddef
3658 END
3659 call writefile(lines, 'XscriptPropAboveNr', 'D')
3660 let buf = RunVimInTerminal('-S XscriptPropAboveNr', #{rows: 8})
3661 call VerifyScreenDump(buf, 'Test_prop_above_number_1', {})
3662
3663 call term_sendkeys(buf, ":call OneMore()\<CR>")
3664 call VerifyScreenDump(buf, 'Test_prop_above_number_2', {})
3665
3666 call StopVimInTerminal(buf)
3667endfunc
3668
zeertzjqce53e3e2023-09-01 18:49:30 +02003669func Test_prop_above_with_linebreak()
3670 CheckRunVimInTerminal
3671
3672 let lines =<< trim END
3673 setlocal linebreak breakindent breakindentopt=shift:4
3674 call setline(1, ["a b", "c d"])
3675 call prop_type_add('theprop' , #{highlight: 'Special'})
3676 call prop_add(1, 0, #{type: 'theprop', text: '123', text_align: 'above'})
3677 normal! 2gg$
3678 END
3679 call writefile(lines, 'XscriptPropAboveLinebreak', 'D')
3680 let buf = RunVimInTerminal('-S XscriptPropAboveLinebreak', #{rows: 6})
3681 call VerifyScreenDump(buf, 'Test_prop_above_linebreak_1', {})
3682 call term_sendkeys(buf, 'k')
3683 call VerifyScreenDump(buf, 'Test_prop_above_linebreak_2', {})
3684
3685 call StopVimInTerminal(buf)
3686endfunc
3687
3688func Test_prop_above_and_before()
3689 CheckRunVimInTerminal
3690
3691 let lines =<< trim END
3692 setlocal linebreak breakindent breakindentopt=shift:2
3693 call setline(1, ["a", " b c"])
3694 call prop_type_add('theprop' , #{highlight: 'Special'})
3695 call prop_add(2, 0, #{type: 'theprop', text: ' 123', text_align: 'above'})
3696 call prop_add(2, 4, #{type: 'theprop', text: ': 456'} )
3697 normal! 2gg$
3698 END
3699 call writefile(lines, 'XscriptPropAboveAndBefore', 'D')
3700 let buf = RunVimInTerminal('-S XscriptPropAboveAndBefore', #{rows: 6})
3701 call VerifyScreenDump(buf, 'Test_prop_above_and_before_1', {})
3702 call term_sendkeys(buf, 'h')
3703 call VerifyScreenDump(buf, 'Test_prop_above_and_before_2', {})
3704 call term_sendkeys(buf, 'h')
3705 call VerifyScreenDump(buf, 'Test_prop_above_and_before_3', {})
3706 call term_sendkeys(buf, 'h')
3707 call VerifyScreenDump(buf, 'Test_prop_above_and_before_4', {})
3708 call term_sendkeys(buf, 'h')
3709 call VerifyScreenDump(buf, 'Test_prop_above_and_before_5', {})
3710
3711 call StopVimInTerminal(buf)
3712endfunc
3713
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003714func Test_prop_below_split_line()
3715 CheckRunVimInTerminal
3716
3717 let lines =<< trim END
3718 vim9script
3719 setline(1, ['one one one', 'two two two', 'three three three'])
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003720 prop_type_add('test', {highlight: 'Search'})
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003721 prop_add(2, 0, {
3722 text: '└─ Virtual text below the 2nd line',
3723 type: 'test',
3724 text_align: 'below',
3725 text_padding_left: 3
3726 })
3727 END
3728 call writefile(lines, 'XscriptPropBelowSpitLine', 'D')
3729 let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8})
3730 call term_sendkeys(buf, "2GA\<CR>xx")
3731 call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {})
3732
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003733 call term_sendkeys(buf, "\<Esc>:set number\<CR>")
3734 call VerifyScreenDump(buf, 'Test_prop_below_split_line_2', {})
3735
Bram Moolenaarb84d5652022-09-20 17:57:53 +01003736 call term_sendkeys(buf, ":set nowrap\<CR>")
3737 call VerifyScreenDump(buf, 'Test_prop_below_split_line_3', {})
3738
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003739 call StopVimInTerminal(buf)
3740endfunc
3741
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00003742func Test_prop_above_below_smoothscroll()
3743 CheckRunVimInTerminal
3744
3745 let lines =<< trim END
3746 vim9script
3747 setline(1, range(1, 10)->mapnew((_, v) => '" line ' .. v))
3748
3749 set smoothscroll wrap
3750 call prop_type_add('mytype', {highlight: 'DiffChange'})
3751 call prop_add(3, 0, {text: "insert above", type: "mytype", text_align: 'above'})
3752 call prop_add(5, 0, {text: "insert above 1", type: "mytype", text_align: 'above'})
3753 call prop_add(5, 0, {text: "insert above 2", type: "mytype", text_align: 'above'})
3754 call prop_add(7, 0, {text: "insert below", type: "mytype", text_align: 'below'})
3755 call prop_add(9, 0, {text: "insert below 1", type: "mytype", text_align: 'below'})
3756 call prop_add(9, 0, {text: "insert below 2", type: "mytype", text_align: 'below'})
3757 END
3758 call writefile(lines, 'XscriptPropsSmoothscroll', 'D')
3759 let buf = RunVimInTerminal('-S XscriptPropsSmoothscroll', #{rows: 8, cols: 60})
3760 call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_1', {})
3761
3762 for nr in range(2, 16)
3763 call term_sendkeys(buf, "\<C-E>")
3764 call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_' .. nr, {})
3765 endfor
3766
3767 call StopVimInTerminal(buf)
3768endfunc
3769
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003770func Test_props_with_text_override()
3771 CheckRunVimInTerminal
3772
3773 let lines =<< trim END
3774 vim9script
3775 setline(1, 'some text here')
3776 hi Likethis ctermfg=blue ctermbg=cyan
3777 prop_type_add('prop', {highlight: 'Likethis', override: true})
3778 prop_add(1, 6, {type: 'prop', text: ' inserted '})
3779 hi CursorLine cterm=underline ctermbg=lightgrey
3780 set cursorline
3781 END
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003782 call writefile(lines, 'XscriptPropsOverride', 'D')
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003783 let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60})
3784 call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {})
3785
3786 call term_sendkeys(buf, ":set nocursorline\<CR>")
3787 call term_sendkeys(buf, "0llvfr")
3788 call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {})
3789
3790 call StopVimInTerminal(buf)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003791endfunc
3792
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003793func Test_props_with_text_CursorMoved()
3794 CheckRunVimInTerminal
3795
3796 let lines =<< trim END
3797 call setline(1, ['this is line one', 'this is line two', 'three', 'four', 'five'])
3798
3799 call prop_type_add('prop', #{highlight: 'Error'})
3800 let g:long_text = repeat('x', &columns * 2)
3801
3802 let g:prop_id = v:null
3803 func! Update()
3804 if line('.') == 1
3805 if g:prop_id == v:null
3806 let g:prop_id = prop_add(1, 0, #{type: 'prop', text_wrap: 'wrap', text: g:long_text})
3807 endif
3808 elseif g:prop_id != v:null
3809 call prop_remove(#{id: g:prop_id})
3810 let g:prop_id = v:null
3811 endif
3812 endfunc
3813
3814 autocmd CursorMoved * call Update()
3815 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003816 call writefile(lines, 'XscriptPropsCursorMovec', 'D')
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003817 let buf = RunVimInTerminal('-S XscriptPropsCursorMovec', #{rows: 8, cols: 60})
3818 call term_sendkeys(buf, "gg0w")
3819 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
3820
3821 call term_sendkeys(buf, "j")
3822 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_2', {})
3823
3824 " back to the first state
3825 call term_sendkeys(buf, "k")
3826 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
3827
3828 call StopVimInTerminal(buf)
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003829endfunc
3830
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003831func Test_props_with_text_after_split_join()
3832 CheckRunVimInTerminal
3833
3834 let lines =<< trim END
3835 call setline(1, ['1122'])
3836 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
3837 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
3838 exe "normal f2i\<CR>\<Esc>"
3839
3840 func AddMore()
3841 call prop_type_add('another', #{highlight: 'Search'})
3842 call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'})
3843 call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'})
3844 endfunc
3845 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003846 call writefile(lines, 'XscriptPropsAfterSplitJoin', 'D')
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003847 let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60})
3848 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {})
3849
3850 call term_sendkeys(buf, "ggJ")
3851 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {})
3852
3853 call term_sendkeys(buf, ":call AddMore()\<CR>")
3854 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {})
3855
3856 call term_sendkeys(buf, "ggf s\<CR>\<Esc>")
3857 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {})
3858
3859 call term_sendkeys(buf, "ggJ")
3860 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {})
3861
3862 call StopVimInTerminal(buf)
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003863endfunc
3864
Bram Moolenaar3a4cd392022-07-30 22:17:18 +01003865func Test_removed_prop_with_text_cleans_up_array()
3866 new
3867 call setline(1, 'some text here')
3868 call prop_type_add('some', #{highlight: 'ErrorMsg'})
3869 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
3870 call assert_equal(-1, id1)
3871 let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"})
3872 call assert_equal(-2, id2)
3873
3874 " removing the props resets the index
3875 call prop_remove(#{id: id1})
3876 call prop_remove(#{id: id2})
3877 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
3878 call assert_equal(-1, id1)
3879
3880 call prop_type_delete('some')
3881 bwipe!
3882endfunc
3883
Bram Moolenaar1f4ee192022-08-01 15:52:55 +01003884def Test_insert_text_before_virtual_text()
3885 new foobar
3886 setline(1, '12345678')
3887 prop_type_add('test', {highlight: 'Search'})
3888 prop_add(1, 5, {
3889 type: 'test',
3890 text: ' virtual text '
3891 })
3892 normal! f4axyz
3893 normal! f5iXYZ
3894 assert_equal('1234xyzXYZ5678', getline(1))
3895
3896 prop_type_delete('test')
3897 bwipe!
3898enddef
3899
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003900func Test_insert_text_start_incl()
3901 CheckRunVimInTerminal
3902
3903 let lines =<< trim END
3904 vim9script
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003905 setline(1, ['text one text two', '', 'function(arg)'])
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003906
3907 prop_type_add('propincl', {highlight: 'NonText', start_incl: true})
3908 prop_add(1, 6, {type: 'propincl', text: 'after '})
3909 cursor(1, 6)
3910 prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false})
3911 prop_add(1, 15, {type: 'propnotincl', text: 'before '})
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003912
Bram Moolenaar94722c52023-01-28 19:19:03 +00003913 set cindent sw=4
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003914 prop_type_add('argname', {highlight: 'DiffChange', start_incl: true})
3915 prop_add(3, 10, {type: 'argname', text: 'arg: '})
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003916 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003917 call writefile(lines, 'XscriptPropsStartIncl', 'D')
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003918 let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60})
3919 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {})
3920
3921 call term_sendkeys(buf, "i")
3922 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {})
3923 call term_sendkeys(buf, "xx\<Esc>")
3924 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {})
3925
3926 call term_sendkeys(buf, "2wi")
3927 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {})
3928 call term_sendkeys(buf, "yy\<Esc>")
3929 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {})
3930
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003931 call term_sendkeys(buf, "3Gfai\<CR>\<Esc>")
3932 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_6', {})
3933 call term_sendkeys(buf, ">>")
3934 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_7', {})
3935 call term_sendkeys(buf, "<<<<")
3936 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_8', {})
3937
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003938 call StopVimInTerminal(buf)
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003939endfunc
3940
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003941func Test_insert_text_list_mode()
3942 CheckRunVimInTerminal
3943
3944 let lines =<< trim END
3945 vim9script
3946 setline(1, ['This is a line with quite a bit of text here.',
3947 'second line', 'third line'])
3948 set list listchars+=extends:Β»
3949 prop_type_add('Prop1', {highlight: 'Error'})
3950 prop_add(1, 0, {
3951 type: 'Prop1',
3952 text: 'The quick brown fox jumps over the lazy dog',
3953 text_align: 'right'
3954 })
3955 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003956 call writefile(lines, 'XscriptPropsListMode', 'D')
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003957 let buf = RunVimInTerminal('-S XscriptPropsListMode', #{rows: 8, cols: 60})
3958 call term_sendkeys(buf, "ggj")
3959 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_1', {})
3960
3961 call term_sendkeys(buf, ":set nowrap\<CR>")
3962 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_2', {})
3963
3964 call term_sendkeys(buf, "ggd32l")
3965 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_3', {})
3966
3967 call StopVimInTerminal(buf)
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003968endfunc
3969
Bram Moolenaarf396ce82022-08-23 18:39:37 +01003970func Test_insert_text_with_padding()
3971 CheckRunVimInTerminal
3972
3973 let lines =<< trim END
3974 vim9script
3975 setline(1, ['Some text to add virtual text to.',
3976 'second line',
3977 'Another line with some text to make the wrap.'])
3978 prop_type_add('theprop', {highlight: 'DiffChange'})
3979 prop_add(1, 0, {
3980 type: 'theprop',
3981 text: 'after',
3982 text_align: 'after',
3983 text_padding_left: 3,
3984 })
3985 prop_add(1, 0, {
3986 type: 'theprop',
3987 text: 'right aligned',
3988 text_align: 'right',
3989 text_padding_left: 5,
3990 })
3991 prop_add(1, 0, {
3992 type: 'theprop',
3993 text: 'below the line',
3994 text_align: 'below',
3995 text_padding_left: 4,
3996 })
3997 prop_add(3, 0, {
3998 type: 'theprop',
3999 text: 'rightmost',
4000 text_align: 'right',
4001 text_padding_left: 6,
4002 text_wrap: 'wrap',
4003 })
4004 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004005 call writefile(lines, 'XscriptPropsPadded', 'D')
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004006 let buf = RunVimInTerminal('-S XscriptPropsPadded', #{rows: 8, cols: 60})
4007 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_1', {})
4008
4009 call term_sendkeys(buf, "ggixxxxxxxxxx\<Esc>")
4010 call term_sendkeys(buf, "3Gix\<Esc>")
4011 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_2', {})
4012
4013 call term_sendkeys(buf, "ggix\<Esc>")
4014 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_3', {})
4015
Bram Moolenaara4abe512022-09-15 19:44:09 +01004016 call term_sendkeys(buf, ":set list\<CR>")
4017 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_4', {})
4018
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004019 call StopVimInTerminal(buf)
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004020endfunc
4021
Bram Moolenaar13845c42022-10-09 15:26:03 +01004022func Test_long_text_below_with_padding()
4023 CheckRunVimInTerminal
4024
4025 let lines =<< trim END
4026 vim9script
4027 setline(1, ['first line', 'second line'])
4028 prop_type_add('theprop', {highlight: 'DiffChange'})
4029 prop_add(1, 0, {
4030 type: 'theprop',
4031 text: 'after '->repeat(20),
4032 text_align: 'below',
4033 text_padding_left: 3,
4034 })
4035 prop_add(1, 0, {
4036 type: 'theprop',
4037 text: 'more '->repeat(20),
4038 text_align: 'below',
4039 text_padding_left: 30,
4040 })
4041 normal 2Gw
4042 END
4043 call writefile(lines, 'XlongTextBelowWithPadding', 'D')
4044 let buf = RunVimInTerminal('-S XlongTextBelowWithPadding', #{rows: 8, cols: 60})
4045 call VerifyScreenDump(buf, 'Test_long_text_with_padding_1', {})
4046
Bram Moolenaara9a36482022-10-11 16:47:22 +01004047 call term_sendkeys(buf, ":set list\<CR>")
4048 call VerifyScreenDump(buf, 'Test_long_text_with_padding_2', {})
4049
Bram Moolenaar13845c42022-10-09 15:26:03 +01004050 call StopVimInTerminal(buf)
4051endfunc
4052
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004053func Test_text_after_nowrap()
4054 CheckRunVimInTerminal
4055
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004056 let lines =<< trim END
4057 vim9script
Bram Moolenaarcd105412022-10-10 19:50:42 +01004058 setline(1, ['first line', range(80)->join(' '), 'third', 'fourth'])
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004059 set nowrap
4060 prop_type_add('theprop', {highlight: 'DiffChange'})
4061 prop_add(1, 0, {
4062 type: 'theprop',
Bram Moolenaarcd105412022-10-10 19:50:42 +01004063 text: 'right after the text '->repeat(3),
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004064 text_align: 'after',
4065 text_padding_left: 2,
4066 })
Bram Moolenaarcd105412022-10-10 19:50:42 +01004067 prop_add(1, 0, {
4068 type: 'theprop',
4069 text: 'in the middle '->repeat(4),
4070 text_align: 'after',
4071 text_padding_left: 3,
4072 })
4073 prop_add(1, 0, {
4074 type: 'theprop',
4075 text: 'the last one '->repeat(3),
4076 text_align: 'after',
4077 text_padding_left: 1,
4078 })
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004079 normal 2Gw
Bram Moolenaar7e017462022-10-11 21:02:09 +01004080 def g:ChangeText()
4081 prop_clear(1)
4082 set list
4083 prop_add(1, 0, {
4084 type: 'theprop',
4085 text: 'just after txt '->repeat(3),
4086 text_align: 'after',
4087 text_padding_left: 2,
4088 })
4089 prop_add(1, 0, {
4090 type: 'theprop',
4091 text: 'in the middle '->repeat(4),
4092 text_align: 'after',
4093 text_padding_left: 1,
4094 })
4095 enddef
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004096 END
4097 call writefile(lines, 'XTextAfterNowrap', 'D')
4098 let buf = RunVimInTerminal('-S XTextAfterNowrap', #{rows: 8, cols: 60})
4099 call VerifyScreenDump(buf, 'Test_text_after_nowrap_1', {})
4100
Bram Moolenaarcd105412022-10-10 19:50:42 +01004101 call term_sendkeys(buf, "30w")
4102 call VerifyScreenDump(buf, 'Test_text_after_nowrap_2', {})
4103
4104 call term_sendkeys(buf, "22w")
4105 call VerifyScreenDump(buf, 'Test_text_after_nowrap_3', {})
4106
4107 call term_sendkeys(buf, "$")
4108 call VerifyScreenDump(buf, 'Test_text_after_nowrap_4', {})
4109
Bram Moolenaar7e017462022-10-11 21:02:09 +01004110 call term_sendkeys(buf, "0")
4111 call term_sendkeys(buf, ":call ChangeText()\<CR>")
4112 call VerifyScreenDump(buf, 'Test_text_after_nowrap_5', {})
4113
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004114 call StopVimInTerminal(buf)
4115endfunc
4116
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00004117func Test_text_after_nowrap_list()
4118 CheckRunVimInTerminal
4119
4120 let lines =<< trim END
4121 vim9script
4122
4123 set nowrap
4124 set listchars+=extends:>
4125 set list
4126 setline(1, ['some text here', '', 'last line'])
4127
4128 prop_type_add('test', {highlight: 'DiffChange'})
4129 prop_add(1, 0, {
4130 type: 'test',
4131 text: 'The quick brown fox jumps.',
4132 text_padding_left: 2,
4133 })
4134 prop_add(1, 0, {
4135 type: 'test',
4136 text: 'β–  The fox jumps over the lazy dog.',
4137 text_padding_left: 2,
4138 })
4139 prop_add(1, 0, {
4140 type: 'test',
4141 text: 'β–  The lazy dog.',
4142 text_padding_left: 2,
4143 })
4144 normal 3G$
4145 END
4146 call writefile(lines, 'XTextAfterNowrapList', 'D')
4147 let buf = RunVimInTerminal('-S XTextAfterNowrapList', #{rows: 6, cols: 60})
4148 call VerifyScreenDump(buf, 'Test_text_after_nowrap_list_1', {})
4149
4150 call StopVimInTerminal(buf)
4151endfunc
4152
Bram Moolenaar1206c162022-10-10 15:40:04 +01004153func Test_text_below_nowrap()
4154 CheckRunVimInTerminal
4155
4156 let lines =<< trim END
4157 vim9script
4158 setline(1, ['first line', 'second line '->repeat(50), 'third', 'fourth'])
4159 set nowrap number
4160 prop_type_add('theprop', {highlight: 'DiffChange'})
4161 prop_add(1, 0, {
4162 type: 'theprop',
4163 text: 'one below the text '->repeat(5),
4164 text_align: 'below',
4165 text_padding_left: 2,
4166 })
4167 prop_add(1, 0, {
4168 type: 'theprop',
4169 text: 'two below the text '->repeat(5),
4170 text_align: 'below',
4171 text_padding_left: 2,
4172 })
4173 normal 2Gw
4174 END
4175 call writefile(lines, 'XTextBelowNowrap', 'D')
4176 let buf = RunVimInTerminal('-S XTextBelowNowrap', #{rows: 8, cols: 60})
4177 call VerifyScreenDump(buf, 'Test_text_below_nowrap_1', {})
4178
4179 call StopVimInTerminal(buf)
4180endfunc
4181
Dylan Thacker-Smith80557212024-02-21 21:00:59 +01004182func Test_virtual_text_overlap_with_highlight()
4183 CheckRunVimInTerminal
4184
4185 let lines =<< trim END
4186 vim9script
4187 setline(1, ['one', 'two', 'three', 'four', 'five'])
4188 set number
4189
4190 prop_type_add('demo_highlight_warning', {highlight: 'WarningMsg'})
4191 prop_type_add('demo_virtual_text_error', {highlight: 'Error'})
4192
4193 prop_add(2, 4, {
4194 type: 'demo_highlight_warning',
4195 end_col: 4,
4196 })
4197 prop_add(2, 0, {
4198 type: 'demo_virtual_text_error',
4199 text: 'syntax error',
4200 text_align: 'below',
4201 })
4202 normal 2j
4203
4204 prop_add(4, 4, {
4205 type: 'demo_highlight_warning',
4206 end_lnum: 5,
4207 end_col: 1,
4208 })
4209 prop_add(4, 0, {
4210 type: 'demo_virtual_text_error',
4211 text: 'other error',
4212 text_align: 'right',
4213 })
4214 END
4215 call writefile(lines, 'XVirtualTextOverlapWithHighlight', 'D')
4216 let buf = RunVimInTerminal('-S XVirtualTextOverlapWithHighlight', #{rows: 8, cols: 60})
4217 call VerifyScreenDump(buf, 'Test_virtual_text_overlap_with_highlight_1', {})
4218
4219 call StopVimInTerminal(buf)
4220endfunc
4221
Bram Moolenaaree28c702022-11-17 14:56:00 +00004222func Test_virtual_text_in_popup_highlight()
4223 CheckRunVimInTerminal
4224
4225 let lines =<< trim END
4226 vim9script
4227
4228 # foreground highlight only, popup background is used
4229 prop_type_add('Prop1', {'highlight': 'SpecialKey'})
4230 # foreground and background highlight, popup background is not used
4231 prop_type_add('Prop2', {'highlight': 'DiffDelete'})
4232
4233 var popupText = [{
4234 text: 'Some text',
4235 props: [
4236 {
4237 col: 1,
4238 type: 'Prop1',
4239 text: ' + '
4240 },
4241 {
4242 col: 6,
4243 type: 'Prop2',
4244 text: ' x '
4245 },
4246 ]
4247 }]
4248 var popupArgs = {
4249 line: 3,
4250 col: 20,
4251 maxwidth: 80,
4252 highlight: 'PMenu',
4253 border: [],
4254 borderchars: [' '],
4255 }
4256
4257 popup_create(popupText, popupArgs)
4258 END
4259 call writefile(lines, 'XscriptVirtualHighlight', 'D')
4260 let buf = RunVimInTerminal('-S XscriptVirtualHighlight', #{rows: 8})
4261 call VerifyScreenDump(buf, 'Test_virtual_text_in_popup_highlight_1', {})
4262
4263 call StopVimInTerminal(buf)
4264endfunc
4265
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004266func Test_insert_text_change_arg()
4267 CheckRunVimInTerminal
4268
4269 let lines =<< trim END
4270 vim9script
4271 setline(1, ['SetErrorCode( 10, 20 )', 'second line'])
4272 prop_type_add('param', {highlight: 'DiffChange', start_incl: 1})
4273 prop_type_add('padd', {highlight: 'NonText', start_incl: 1})
4274 prop_add(1, 15, {
4275 type: 'param',
4276 text: 'id:',
4277 })
4278 prop_add(1, 15, {
4279 type: 'padd',
4280 text: '-',
4281 })
4282 prop_add(1, 19, {
4283 type: 'param',
4284 text: 'id:',
4285 })
4286 prop_add(1, 19, {
4287 type: 'padd',
4288 text: '-',
4289 })
4290 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004291 call writefile(lines, 'XscriptPropsChange', 'D')
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004292 let buf = RunVimInTerminal('-S XscriptPropsChange', #{rows: 5, cols: 60})
4293 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_1', {})
4294
4295 call term_sendkeys(buf, "ggf1cw1234\<Esc>")
4296 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_2', {})
4297
4298 call StopVimInTerminal(buf)
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004299endfunc
4300
Bram Moolenaar2f7bfe62022-11-13 12:54:50 +00004301def Test_textprop_in_quickfix_window()
4302 enew!
4303 var prop_type = 'my_prop'
4304 prop_type_add(prop_type, {})
4305
4306 for lnum in range(1, 10)
4307 setline(lnum, 'hello world')
4308 endfor
4309
4310 cgetbuffer
4311 copen
4312
4313 var bufnr = bufnr()
4314 for lnum in range(1, line('$', bufnr->bufwinid()))
4315 prop_add(lnum, 1, {
4316 id: 1000 + lnum,
4317 type: prop_type,
4318 bufnr: bufnr,
4319 })
4320 endfor
4321
4322 prop_type_delete(prop_type)
4323 cclose
4324 bwipe!
4325enddef
4326
Bram Moolenaar89469d12022-12-02 20:46:26 +00004327func Test_text_prop_delete_updates()
4328 CheckRunVimInTerminal
4329
4330 let lines =<< trim END
4331 vim9script
4332
4333 setline(1, ['some text', 'more text', 'the end'])
4334 prop_type_add('test', {highlight: 'DiffChange'})
4335 prop_add(1, 0, {
4336 type: 'test',
4337 text: 'The quick brown fox jumps over the lazy dog',
4338 text_align: 'below',
4339 text_padding_left: 3,
4340 })
4341 prop_add(1, 0, {
4342 type: 'test',
4343 text: 'The quick brown fox jumps over the lazy dog',
4344 text_align: 'below',
4345 text_padding_left: 5,
4346 })
4347
4348 normal! G
4349 END
4350 call writefile(lines, 'XtextPropDelete', 'D')
4351 let buf = RunVimInTerminal('-S XtextPropDelete', #{rows: 10, cols: 60})
4352 call VerifyScreenDump(buf, 'Test_prop_delete_updates_1', {})
4353
4354 " Check that after deleting the text prop type the text properties using
4355 " this type no longer show and are not counted for cursor positioning.
4356 call term_sendkeys(buf, ":call prop_type_delete('test')\<CR>")
4357 call VerifyScreenDump(buf, 'Test_prop_delete_updates_2', {})
4358
4359 call term_sendkeys(buf, "ggj")
4360 call VerifyScreenDump(buf, 'Test_prop_delete_updates_3', {})
4361
4362 call StopVimInTerminal(buf)
4363endfunc
4364
Bram Moolenaard097af72022-12-17 11:33:00 +00004365func Test_text_prop_diff_mode()
4366 CheckRunVimInTerminal
4367
4368 let lines =<< trim END
4369 call setline(1, ['9000', '0009', '0009', '9000', '0009'])
4370
4371 let type = 'test'
4372 call prop_type_add(type, {})
4373 let text = '<text>'
4374 call prop_add(1, 1, {'type': type, 'text': text})
4375 call prop_add(2, 0, {'type': type, 'text': text, 'text_align': 'after'})
4376 call prop_add(3, 0, {'type': type, 'text': text, 'text_align': 'right'})
4377 call prop_add(4, 0, {'type': type, 'text': text, 'text_align': 'above'})
4378 call prop_add(5, 0, {'type': type, 'text': text, 'text_align': 'below'})
4379 set diff
4380
4381 vnew
4382 call setline(1, ['000', '000', '000', '000', '000'])
4383 set diff
4384 END
4385 call writefile(lines, 'XtextPropDiff', 'D')
4386 let buf = RunVimInTerminal('-S XtextPropDiff', #{rows: 10, cols: 60})
4387 call VerifyScreenDump(buf, 'Test_prop_diff_mode_1', {})
4388
4389 call term_sendkeys(buf, ":windo set number\<CR>")
4390 call VerifyScreenDump(buf, 'Test_prop_diff_mode_2', {})
4391
4392 call StopVimInTerminal(buf)
4393endfunc
Bram Moolenaar94722c52023-01-28 19:19:03 +00004394
Bram Moolenaar4ce1f992022-12-19 13:31:06 +00004395func Test_error_when_using_negative_id()
4396 call prop_type_add('test1', #{highlight: 'ErrorMsg'})
4397 call prop_add(1, 1, #{type: 'test1', text: 'virtual'})
4398 call assert_fails("call prop_add(1, 1, #{type: 'test1', length: 1, id: -1})", 'E1293:')
4399
4400 call prop_type_delete('test1')
4401endfunc
4402
4403func Test_error_after_using_negative_id()
4404 " This needs to run a separate Vim instance because the
4405 " "did_use_negative_pop_id" will be set.
4406 CheckRunVimInTerminal
4407
4408 let lines =<< trim END
4409 vim9script
4410
4411 setline(1, ['one', 'two', 'three'])
4412 prop_type_add('test_1', {highlight: 'Error'})
4413 prop_type_add('test_2', {highlight: 'WildMenu'})
4414
4415 prop_add(3, 1, {
4416 type: 'test_1',
4417 length: 5,
4418 id: -1
4419 })
4420
4421 def g:AddTextprop()
4422 prop_add(1, 0, {
4423 type: 'test_2',
4424 text: 'The quick fox',
4425 text_padding_left: 2
4426 })
4427 enddef
4428 END
4429 call writefile(lines, 'XtextPropError', 'D')
4430 let buf = RunVimInTerminal('-S XtextPropError', #{rows: 8, cols: 60})
4431 call VerifyScreenDump(buf, 'Test_prop_negative_error_1', {})
4432
4433 call term_sendkeys(buf, ":call AddTextprop()\<CR>")
4434 call VerifyScreenDump(buf, 'Test_prop_negative_error_2', {})
4435
4436 call StopVimInTerminal(buf)
4437endfunc
Bram Moolenaard097af72022-12-17 11:33:00 +00004438
Ibbya6ab5e62023-08-20 20:24:18 +02004439func Test_modify_text_before_prop()
4440 CheckRunVimInTerminal
4441
4442 let lines =<< trim END
4443 vim9script
4444 setline(1, ['test_words', 'second line', 'third line', 'fourth line'])
4445 set number
4446 prop_type_add('text', {highlight: 'DiffChange'})
4447 prop_type_add('below', {highlight: 'NonText'})
4448 prop_add(1, 11, {type: 'text', text: repeat('a', 65)})
4449 prop_add(1, 0, {type: 'below', text: repeat('a', 65), text_align: 'below'})
4450 END
4451 call writefile(lines, 'XtextPropModifyBefore', 'D')
4452 let buf = RunVimInTerminal('-S XtextPropModifyBefore', #{rows: 5, cols: 60})
4453 call VerifyScreenDump(buf, 'Test_modify_text_before_prop_1', {})
4454
4455 call term_sendkeys(buf, "xxia\<Esc>")
4456 call VerifyScreenDump(buf, 'Test_modify_text_before_prop_2', {})
4457
4458 call StopVimInTerminal(buf)
4459endfunc
4460
Christian Brabandtf1cc4d52023-08-12 00:14:14 +02004461func Test_overlong_textprop_above_crash()
4462 CheckRunVimInTerminal
Bram Moolenaar2f7bfe62022-11-13 12:54:50 +00004463
Christian Brabandtf1cc4d52023-08-12 00:14:14 +02004464 let lines =<< trim END
4465 vim9script
4466 prop_type_add('PropType', {highlight: 'Error'})
4467 setline(1, ['xxx ', 'yyy'])
4468 prop_add(1, 0, {
4469 type: 'PropType',
4470 text: 'the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog.',
4471 text_align: 'above',
4472 text_wrap: 'wrap',
4473 })
4474 END
4475 call writefile(lines, 'XtextPropLongAbove', 'D')
4476 let buf = RunVimInTerminal('-S XtextPropLongAbove', #{rows: 8, cols: 60})
4477 call VerifyScreenDump(buf, 'Test_prop_long_above_1', {})
4478
4479 call StopVimInTerminal(buf)
4480endfunc
Christian Brabandtdbeadf02023-08-19 15:35:04 +02004481
4482func Test_text_prop_list_hl_and_sign_highlight()
4483 CheckRunVimInTerminal
4484
4485 let lines =<< trim END
4486 func Test()
4487 split Xbuffer
4488 call setline(1, ['one', "\ttab", ' space', 'three', 'four', 'five'])
4489 call prop_type_add('Prop1', #{highlight: 'Search', override: v:true})
4490 sign define sign1 text=>> linehl=DiffAdd
4491 sign place 10 line=2 name=sign1
4492 sign place 20 line=3 name=sign1
4493 call prop_add(1, 1, #{end_lnum: 4, end_col: 5, type: 'Prop1'})
4494 sign place 30 line=5 name=sign1
4495 endfunc
4496 call Test()
4497 END
4498 call writefile(lines, 'XtextPropSignTab', 'D')
4499 let buf = RunVimInTerminal('-S XtextPropSignTab', #{rows: 8, cols: 60})
4500 call VerifyScreenDump(buf, 'Test_prop_sign_tab_1', {})
4501
4502 call term_sendkeys(buf, ":setl list listchars=eol:ΒΆ,tab:>-\<CR>")
4503 call VerifyScreenDump(buf, 'Test_prop_sign_tab_2', {})
4504
4505 call StopVimInTerminal(buf)
4506endfunc
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004507
4508" Test for getting the virtual text properties
4509func Test_virtual_text_get()
4510 new foobar
4511 call setline(1, '12345678')
4512 call prop_type_add('test', #{highlight: 'Search'})
4513 call prop_add(1, 2, #{type: 'test', text: ' virtual text1 '})
4514 call prop_add(1, 3, #{type: 'test'})
4515 call prop_add(1, 0, #{type: 'test', text: ' virtual text2 ',
4516 \ text_align: 'right'})
4517 call prop_add(1, 5, #{type: 'test'})
4518 call prop_add(1, 6, #{type: 'test', text: ' virtual text3 ',
4519 \ text_wrap: 'wrap'})
4520
4521 let p = prop_list(1, #{end_lnum: -1})
4522 call assert_equal(
Yegappan Lakshmanan171c5b92023-08-22 21:48:50 +02004523 \ #{lnum: 1, col: 2, type_bufnr: 0, end: 1,
4524 \ type: 'test', start: 1,
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004525 \ text: ' virtual text1 '}, p[0])
4526 call assert_equal(
4527 \ #{lnum: 1, id: 0, col: 3, type_bufnr: 0, end: 1,
4528 \ type: 'test', length: 0, start: 1}, p[1])
4529 call assert_equal(
4530 \ #{lnum: 1, id: 0, col: 5, type_bufnr: 0, end: 1,
4531 \ type: 'test', length: 0, start: 1}, p[2])
4532 call assert_equal(
Yegappan Lakshmanan171c5b92023-08-22 21:48:50 +02004533 \ #{lnum: 1, col: 6, type_bufnr: 0, end: 1, type: 'test',
4534 \ text_wrap: 'wrap', start: 1, text: ' virtual text3 '},
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004535 \ p[3])
4536 call assert_equal('right', p[4].text_align)
4537
4538 call prop_type_delete('test')
4539 bwipe!
4540endfunc
4541
Christian Brabandt0d0b3b12023-12-03 17:56:43 +01004542" This used to throw: E967
4543func Test_textprop_notype_join()
4544 new Xtextprop_no_type_join
4545 call setline(1, range(1, 3))
4546 call cursor(1, 1)
4547 let name = 'a'
4548 call prop_type_add(name, {})
4549 call prop_add(line('.'), col('.'), { 'type': name })
4550 call prop_type_delete(name, {})
4551 join
4552 call assert_equal(["1 2", "3"], getline(1, '$'))
4553
4554 bwipe!
4555endfunc
4556
zeertzjq7ac11452024-03-06 20:54:22 +01004557" This was causing text property corruption.
4558func Test_textprop_backspace_fo_aw()
4559 new
4560 call setline(1, 'foobar')
4561 call prop_type_add('test', {'highlight': 'ErrorMsg'})
4562 call prop_add(1, 1, {'type': 'test', 'length': 3})
4563 set backspace=indent,eol,start
4564 setlocal formatoptions+=aw
4565 call feedkeys("A \<CR>\<BS>\<Esc>", 'tx')
4566 call assert_equal('foobar', getline(1))
4567 call assert_equal([
4568 \ #{id: 0, col: 1, start: 1, end: 1, type_bufnr: 0,
4569 \ type: 'test', length: 3}], prop_list(1))
4570
4571 bwipe!
4572 set backspace&
4573 call prop_type_delete('test')
4574endfunc
4575
zeertzjq9352c282024-03-14 18:16:56 +01004576func Test_textprop_with_wincolor()
4577 CheckRunVimInTerminal
4578
4579 let lines =<< trim END
4580 call setline(1, 'some text here')
4581 call setline(2, 'some much longer text here')
4582 call setline(3, 'more text here')
4583 call prop_type_add('afterprop', #{highlight: 'Search'})
4584 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
4585 call prop_add(3, 0, #{type: 'afterprop', text: 'AFTER',
4586 \ text_align: 'after', text_padding_left: 3})
4587 call prop_add(1, 0, #{type: 'belowprop', text: 'BELOW',
4588 \ text_align: 'below', text_padding_left: 3})
4589 set wincolor=DiffChange wrap
4590 END
4591 call writefile(lines, 'XtextPropWincolor', 'D')
4592 let buf = RunVimInTerminal('-S XtextPropWincolor', #{rows: 8, cols: 60})
4593
4594 call term_sendkeys(buf, ":\<CR>")
4595 call VerifyScreenDump(buf, 'Test_prop_wincolor_1', {})
4596
4597 call term_sendkeys(buf, ":set cursorline\<CR>:\<CR>")
4598 call VerifyScreenDump(buf, 'Test_prop_wincolor_2', {})
4599
4600 call term_sendkeys(buf, ":set nowrap\<CR>:\<CR>")
4601 call VerifyScreenDump(buf, 'Test_prop_wincolor_2', {})
4602
4603 call term_sendkeys(buf, ":set nocursorline\<CR>:\<CR>")
4604 call VerifyScreenDump(buf, 'Test_prop_wincolor_1', {})
4605
4606 call term_sendkeys(buf, ":set cursorline colorcolumn=30\<CR>:\<CR>")
4607 call VerifyScreenDump(buf, 'Test_prop_wincolor_3', {})
4608
4609 call term_sendkeys(buf, ":hi CursorLine ctermbg=Brown\<CR>:\<CR>")
4610 call VerifyScreenDump(buf, 'Test_prop_wincolor_4', {})
4611
4612 call term_sendkeys(buf, ":set cursorcolumn\<CR>:\<CR>")
4613 call term_sendkeys(buf, '$')
4614 call VerifyScreenDump(buf, 'Test_prop_wincolor_5', {})
4615
4616 call term_sendkeys(buf, 'j')
4617 call VerifyScreenDump(buf, 'Test_prop_wincolor_6', {})
4618
4619 call term_sendkeys(buf, ":set virtualedit=all\<CR>:\<CR>")
4620 call term_sendkeys(buf, 'l')
4621 call VerifyScreenDump(buf, 'Test_prop_wincolor_7', {})
4622
4623 call term_sendkeys(buf, 'k')
4624 call VerifyScreenDump(buf, 'Test_prop_wincolor_8', {})
4625
zeertzjqf6272552024-03-17 10:01:47 +01004626 if has('rightleft')
4627 call term_sendkeys(buf, ":set rightleft\<CR>:\<CR>")
4628 call VerifyScreenDump(buf, 'Test_prop_wincolor_9', {})
4629 endif
4630
zeertzjq9352c282024-03-14 18:16:56 +01004631 call StopVimInTerminal(buf)
4632endfunc
4633
Bram Moolenaar99fa7212020-04-26 15:59:55 +02004634" vim: shiftwidth=2 sts=2 expandtab