blob: b5c9f63f652f8d9e11df02da02d29ecfbc27df7d [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 +02004CheckFeature textprop
Bram Moolenaar98aefe72018-12-13 22:20:09 +01005
Christian Brabandteb380b92025-07-07 20:53:55 +02006source util/screendump.vim
7import './util/vim9.vim' as v9
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01008
Bram Moolenaar98aefe72018-12-13 22:20:09 +01009func Test_proptype_global()
10 call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1})
11 let proptypes = prop_type_list()
12 call assert_equal(1, len(proptypes))
13 call assert_equal('comment', proptypes[0])
14
15 let proptype = prop_type_get('comment')
16 call assert_equal('Directory', proptype['highlight'])
17 call assert_equal(123, proptype['priority'])
18 call assert_equal(1, proptype['start_incl'])
19 call assert_equal(1, proptype['end_incl'])
20
21 call prop_type_delete('comment')
22 call assert_equal(0, len(prop_type_list()))
23
24 call prop_type_add('one', {})
25 call assert_equal(1, len(prop_type_list()))
Bram Moolenaara5a78822019-09-04 21:57:18 +020026 let proptype = 'one'->prop_type_get()
Bram Moolenaar98aefe72018-12-13 22:20:09 +010027 call assert_false(has_key(proptype, 'highlight'))
28 call assert_equal(0, proptype['priority'])
29 call assert_equal(0, proptype['start_incl'])
30 call assert_equal(0, proptype['end_incl'])
31
32 call prop_type_add('two', {})
33 call assert_equal(2, len(prop_type_list()))
34 call prop_type_delete('one')
35 call assert_equal(1, len(prop_type_list()))
36 call prop_type_delete('two')
37 call assert_equal(0, len(prop_type_list()))
38endfunc
39
40func Test_proptype_buf()
41 let bufnr = bufnr('')
Martin Tournoije2390c72021-07-28 13:30:16 +020042 call prop_type_add('comment', #{bufnr: bufnr, highlight: 'Directory', priority: 123, start_incl: 1, end_incl: 1})
Bram Moolenaar98aefe72018-12-13 22:20:09 +010043 let proptypes = prop_type_list({'bufnr': bufnr})
44 call assert_equal(1, len(proptypes))
45 call assert_equal('comment', proptypes[0])
46
47 let proptype = prop_type_get('comment', {'bufnr': bufnr})
48 call assert_equal('Directory', proptype['highlight'])
49 call assert_equal(123, proptype['priority'])
50 call assert_equal(1, proptype['start_incl'])
51 call assert_equal(1, proptype['end_incl'])
52
53 call prop_type_delete('comment', {'bufnr': bufnr})
Bram Moolenaara5a78822019-09-04 21:57:18 +020054 call assert_equal(0, len({'bufnr': bufnr}->prop_type_list()))
Bram Moolenaar98aefe72018-12-13 22:20:09 +010055
56 call prop_type_add('one', {'bufnr': bufnr})
57 let proptype = prop_type_get('one', {'bufnr': bufnr})
58 call assert_false(has_key(proptype, 'highlight'))
59 call assert_equal(0, proptype['priority'])
60 call assert_equal(0, proptype['start_incl'])
61 call assert_equal(0, proptype['end_incl'])
62
63 call prop_type_add('two', {'bufnr': bufnr})
64 call assert_equal(2, len(prop_type_list({'bufnr': bufnr})))
65 call prop_type_delete('one', {'bufnr': bufnr})
66 call assert_equal(1, len(prop_type_list({'bufnr': bufnr})))
67 call prop_type_delete('two', {'bufnr': bufnr})
68 call assert_equal(0, len(prop_type_list({'bufnr': bufnr})))
Bram Moolenaarf0884c52019-05-24 21:22:29 +020069
70 call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
Bram Moolenaar98aefe72018-12-13 22:20:09 +010071endfunc
72
Bram Moolenaar10246902022-08-08 17:08:05 +010073def Test_proptype_add_remove()
74 # add and remove a prop type so that the array is empty
75 prop_type_add('local', {bufnr: bufnr('%')})
76 prop_type_delete('local', {bufnr: bufnr('%')})
77 prop_type_add('global', {highlight: 'ErrorMsg'})
78 prop_add(1, 1, {length: 1, type: 'global'})
79 redraw
80
81 prop_clear(1)
82 prop_type_delete('global')
83enddef
84
Martin Tournoije2390c72021-07-28 13:30:16 +020085def Test_proptype_buf_list()
86 new
87 var bufnr = bufnr('')
88 try
89 prop_type_add('global', {})
90 prop_type_add('local', {bufnr: bufnr})
91
92 prop_add(1, 1, {type: 'global'})
93 prop_add(1, 1, {type: 'local'})
94
95 assert_equal([
96 {type: 'local', type_bufnr: bufnr, id: 0, col: 1, end: 1, length: 0, start: 1},
97 {type: 'global', type_bufnr: 0, id: 0, col: 1, end: 1, length: 0, start: 1},
98 ], prop_list(1))
99 assert_equal(
100 {lnum: 1, id: 0, col: 1, type_bufnr: bufnr, end: 1, type: 'local', length: 0, start: 1},
101 prop_find({lnum: 1, type: 'local'}))
102 assert_equal(
103 {lnum: 1, id: 0, col: 1, type_bufnr: 0, end: 1, type: 'global', length: 0, start: 1},
104 prop_find({lnum: 1, type: 'global'}))
105
106 prop_remove({type: 'global'}, 1)
107 prop_remove({type: 'local'}, 1)
108 finally
109 prop_type_delete('global')
110 prop_type_delete('local', {bufnr: bufnr})
111 bwipe!
112 endtry
113enddef
114
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100115func AddPropTypes()
116 call prop_type_add('one', {})
117 call prop_type_add('two', {})
118 call prop_type_add('three', {})
119 call prop_type_add('whole', {})
120endfunc
121
122func DeletePropTypes()
123 call prop_type_delete('one')
124 call prop_type_delete('two')
125 call prop_type_delete('three')
126 call prop_type_delete('whole')
127endfunc
128
129func SetupPropsInFirstLine()
130 call setline(1, 'one two three')
131 call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'})
Bram Moolenaara5a78822019-09-04 21:57:18 +0200132 eval 1->prop_add(5, {'length': 3, 'id': 12, 'type': 'two'})
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100133 call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'})
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100134 call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'})
135endfunc
136
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100137func Get_expected_props()
138 return [
Martin Tournoije2390c72021-07-28 13:30:16 +0200139 \ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1},
140 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
141 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
142 \ #{type_bufnr: 0, col: 9, length: 5, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100143 \ ]
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100144endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100145
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100146func Test_prop_find()
147 new
148 call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix'])
Martin Tournoije2390c72021-07-28 13:30:16 +0200149
150 " Add two text props on lines 1 and 5, and one spanning lines 2 to 4.
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100151 call prop_type_add('prop_name', {'highlight': 'Directory'})
152 call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3})
153 call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9})
154 call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1})
155
156 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200157 \ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1},
158 \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0},
159 \ #{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 +0100160 \ ]
161
162 " Starting at line 5 col 1 this should find the prop at line 5 col 4.
Ben Jacksona7704222022-08-20 20:54:51 +0100163 call cursor(5, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100164 let result = prop_find({'type': 'prop_name'}, 'f')
165 call assert_equal(expected[2], result)
166
167 " With skipstart left at false (default), this should find the prop at line
168 " 5 col 4.
169 let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4}, 'b')
170 call assert_equal(expected[2], result)
171
172 " With skipstart set to true, this should skip the prop at line 5 col 4.
173 let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4, 'skipstart': 1}, 'b')
174 unlet result.length
175 call assert_equal(expected[1], result)
176
177 " Search backwards from line 1 col 10 to find the prop on the same line.
178 let result = prop_find({'type': 'prop_name', 'lnum': 1, 'col': 10}, 'b')
179 call assert_equal(expected[0], result)
180
181 " with skipstart set to false, if the start position is anywhere between the
182 " start and end lines of a text prop (searching forward or backward), the
183 " result should be the prop on the first line (the line with 'start' set to 1).
Ben Jacksona7704222022-08-20 20:54:51 +0100184 call cursor(3, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100185 let result = prop_find({'type': 'prop_name'}, 'f')
186 unlet result.length
187 call assert_equal(expected[1], result)
188 let result = prop_find({'type': 'prop_name'}, 'b')
189 unlet result.length
190 call assert_equal(expected[1], result)
191
192 " with skipstart set to true, if the start position is anywhere between the
193 " start and end lines of a text prop (searching forward or backward), all lines
194 " of the prop will be skipped.
195 let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'b')
196 call assert_equal(expected[0], result)
197 let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'f')
198 call assert_equal(expected[2], result)
199
200 " Use skipstart to search through all props with type name 'prop_name'.
201 " First forward...
202 let lnum = 1
203 let col = 1
204 let i = 0
205 for exp in expected
206 let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'f')
207 if !has_key(exp, "length")
208 unlet result.length
209 endif
210 call assert_equal(exp, result)
211 let lnum = result.lnum
212 let col = result.col
213 let i = i + 1
214 endfor
215
216 " ...then backwards.
217 let lnum = 6
218 let col = 4
219 let i = 2
220 while i >= 0
221 let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'b')
222 if !has_key(expected[i], "length")
223 unlet result.length
224 endif
225 call assert_equal(expected[i], result)
226 let lnum = result.lnum
227 let col = result.col
228 let i = i - 1
Martin Tournoije2390c72021-07-28 13:30:16 +0200229 endwhile
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100230
231 " Starting from line 6 col 1 search backwards for prop with id 10.
Ben Jacksona7704222022-08-20 20:54:51 +0100232 call cursor(6, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100233 let result = prop_find({'id': 10, 'skipstart': 1}, 'b')
234 call assert_equal(expected[0], result)
235
236 " Starting from line 1 col 1 search forwards for prop with id 12.
Ben Jacksona7704222022-08-20 20:54:51 +0100237 call cursor(1, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100238 let result = prop_find({'id': 12}, 'f')
239 call assert_equal(expected[2], result)
240
241 " Search for a prop with an unknown id.
242 let result = prop_find({'id': 999}, 'f')
243 call assert_equal({}, result)
244
245 " Search backwards from the proceeding position of the prop with id 11
246 " (at line num 2 col 4). This should return an empty dict.
247 let result = prop_find({'id': 11, 'lnum': 2, 'col': 3}, 'b')
248 call assert_equal({}, result)
249
250 " When lnum is given and col is omitted, use column 1.
251 let result = prop_find({'type': 'prop_name', 'lnum': 1}, 'f')
252 call assert_equal(expected[0], result)
253
Bram Moolenaare041dde2021-08-01 21:30:12 +0200254 " Negative ID is possible, just like prop is not found.
Bram Moolenaar8e3fc132021-07-31 18:33:57 +0200255 call assert_equal({}, prop_find({'id': -1}))
Bram Moolenaare041dde2021-08-01 21:30:12 +0200256 call assert_equal({}, prop_find({'id': -2}))
Bram Moolenaar8e3fc132021-07-31 18:33:57 +0200257
Bram Moolenaare041dde2021-08-01 21:30:12 +0200258 call prop_clear(1, 6)
259
260 " Default ID is zero
261 call prop_add(5, 4, {'type': 'prop_name', 'length': 1})
262 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}))
263
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100264 call prop_type_delete('prop_name')
Bram Moolenaare041dde2021-08-01 21:30:12 +0200265 call prop_clear(1, 6)
Bram Moolenaar4da7a252020-09-02 19:59:00 +0200266 bwipe!
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100267endfunc
268
Bram Moolenaareb245562020-09-03 22:33:44 +0200269def Test_prop_find2()
270 # Multiple props per line, start on the first, should find the second.
271 new
272 ['the quikc bronw fox jumsp over the layz dog']->repeat(2)->setline(1)
Bram Moolenaare0de1712020-12-02 17:36:54 +0100273 prop_type_add('misspell', {highlight: 'ErrorMsg'})
Bram Moolenaareb245562020-09-03 22:33:44 +0200274 for lnum in [1, 2]
275 for col in [8, 14, 24, 38]
Bram Moolenaare0de1712020-12-02 17:36:54 +0100276 prop_add(lnum, col, {type: 'misspell', length: 2})
Bram Moolenaareb245562020-09-03 22:33:44 +0200277 endfor
278 endfor
279 cursor(1, 8)
Martin Tournoije2390c72021-07-28 13:30:16 +0200280 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 +0100281 var result = prop_find({type: 'misspell', skipstart: true}, 'f')
Bram Moolenaareb245562020-09-03 22:33:44 +0200282 assert_equal(expected, result)
283
284 prop_type_delete('misspell')
285 bwipe!
286enddef
287
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100288func Test_prop_find_smaller_len_than_match_col()
289 new
290 call prop_type_add('test', {'highlight': 'ErrorMsg'})
291 call setline(1, ['xxxx', 'x'])
292 call prop_add(1, 4, {'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200293 call assert_equal(
294 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 4, type: 'test', length: 0, start: 1, end: 1},
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100295 \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b'))
296 bwipe!
297 call prop_type_delete('test')
298endfunc
299
Bram Moolenaar24f21fd2021-03-27 22:07:29 +0100300func Test_prop_find_with_both_option_enabled()
301 " Initialize
302 new
303 call AddPropTypes()
304 call SetupPropsInFirstLine()
305 let props = Get_expected_props()->map({_, v -> extend(v, {'lnum': 1})})
306 " Test
307 call assert_fails("call prop_find({'both': 1})", 'E968:')
308 call assert_fails("call prop_find({'id': 11, 'both': 1})", 'E860:')
309 call assert_fails("call prop_find({'type': 'three', 'both': 1})", 'E860:')
310 call assert_equal({}, prop_find({'id': 11, 'type': 'three', 'both': 1}))
311 call assert_equal({}, prop_find({'id': 130000, 'type': 'one', 'both': 1}))
312 call assert_equal(props[2], prop_find({'id': 12, 'type': 'two', 'both': 1}))
313 call assert_equal(props[0], prop_find({'id': 14, 'type': 'whole', 'both': 1}))
314 " Clean up
315 call DeletePropTypes()
316 bwipe!
317endfunc
318
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100319func Test_prop_add()
320 new
321 call AddPropTypes()
322 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100323 let expected_props = Get_expected_props()
324 call assert_equal(expected_props, prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100325 call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:')
326 call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:')
Martin Tournoije2390c72021-07-28 13:30:16 +0200327
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100328 " Insert a line above, text props must still be there.
329 call append(0, 'empty')
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100330 call assert_equal(expected_props, prop_list(2))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100331 " Delete a line above, text props must still be there.
332 1del
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100333 call assert_equal(expected_props, prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100334
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100335 " Prop without length or end column is zero length
336 call prop_clear(1)
Bram Moolenaar12f20032020-02-26 22:06:00 +0100337 call prop_type_add('included', {'start_incl': 1, 'end_incl': 1})
338 call prop_add(1, 5, #{type: 'included'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200339 let expected = [#{type_bufnr: 0, col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}]
Bram Moolenaar12f20032020-02-26 22:06:00 +0100340 call assert_equal(expected, prop_list(1))
341
342 " Inserting text makes the prop bigger.
343 exe "normal 5|ixx\<Esc>"
Martin Tournoije2390c72021-07-28 13:30:16 +0200344 let expected = [#{type_bufnr: 0, col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}]
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100345 call assert_equal(expected, prop_list(1))
346
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200347 call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
348
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100349 call DeletePropTypes()
Bram Moolenaar12f20032020-02-26 22:06:00 +0100350 call prop_type_delete('included')
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100351 bwipe!
352endfunc
353
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200354" Test for the prop_add_list() function
355func Test_prop_add_list()
356 new
357 call AddPropTypes()
358 call setline(1, ['one one one', 'two two two', 'six six six', 'ten ten ten'])
359 call prop_add_list(#{type: 'one', id: 2},
360 \ [[1, 1, 1, 3], [2, 5, 2, 7], [3, 6, 4, 6]])
361 call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
362 \ length: 2, start: 1}], prop_list(1))
363 call assert_equal([#{id: 2, col: 5, type_bufnr: 0, end: 1, type: 'one',
364 \ length: 2, start: 1}], prop_list(2))
365 call assert_equal([#{id: 2, col: 6, type_bufnr: 0, end: 0, type: 'one',
366 \ length: 7, start: 1}], prop_list(3))
367 call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
368 \ length: 5, start: 0}], prop_list(4))
Bram Moolenaard93009e2022-10-13 14:35:24 +0100369 call prop_remove(#{id: 2})
370 call assert_equal([], prop_list(1))
371
372 call prop_add_list(#{type: 'one', id: 3},
373 \ [[1, 1, 1, 3], [2, 5, 2, 7, 9]])
374 call assert_equal([#{id: 3, col: 1, type_bufnr: 0, end: 1, type: 'one',
375 \ length: 2, start: 1}], prop_list(1))
376 call assert_equal([#{id: 9, col: 5, type_bufnr: 0, end: 1, type: 'one',
377 \ length: 2, start: 1}], prop_list(2))
378
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200379 call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:')
380 call assert_fails('call prop_add_list({}, {})', 'E1211:')
381 call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:')
382 call assert_fails('call prop_add_list(#{type: "abc"}, [[1, 1, 1, 3]])', 'E971:')
383 call assert_fails('call prop_add_list(#{type: "one"}, [[]])', 'E474:')
384 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 1], {}])', 'E714:')
385 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, "a"]])', 'E474:')
386 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2]])', 'E474:')
387 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 2], [2, 2]])', 'E474:')
388 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 2], [4, 1, 5, 2]])', 'E966:')
389 call assert_fails('call prop_add_list(#{type: "one"}, [[3, 1, 1, 2]])', 'E966:')
390 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
391 call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
392 call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:')
Bram Moolenaard83392a2022-09-01 12:22:46 +0100393 call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E1298:')
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200394 call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:')
Christian Brabandt701c8632024-09-08 20:05:23 +0200395 call assert_fails('call prop_add_list(#{type: "one", id: 2147483648}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E1510:')
396 call assert_fails('call prop_add_list(#{type: "one", id: -2147483648}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E1510:')
Bram Moolenaar4997f2a2022-10-13 14:00:45 +0100397
398 " only one error for multiple wrong values
399 call assert_fails('call prop_add_list(#{type: "one"}, [[{}, [], 0z00, 0.3]])', ['E728:', 'E728:'])
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200400 call DeletePropTypes()
401 bw!
402endfunc
403
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100404func Test_prop_remove()
405 new
406 call AddPropTypes()
407 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100408 let props = Get_expected_props()
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100409 call assert_equal(props, prop_list(1))
410
411 " remove by id
Bram Moolenaara5a78822019-09-04 21:57:18 +0200412 call assert_equal(1, {'id': 12}->prop_remove(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100413 unlet props[2]
414 call assert_equal(props, prop_list(1))
415
416 " remove by type
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200417 call assert_equal(1, prop_remove({'type': 'one'}, 1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100418 unlet props[1]
419 call assert_equal(props, prop_list(1))
420
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200421 " remove from unknown buffer
422 call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:')
423
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100424 call DeletePropTypes()
425 bwipe!
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100426
427 new
428 call AddPropTypes()
429 call SetupPropsInFirstLine()
430 call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
431 let props = Get_expected_props()
Martin Tournoije2390c72021-07-28 13:30:16 +0200432 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 +0100433 call assert_equal(props, prop_list(1))
434 call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
435 unlet props[3]
436 call assert_equal(props, prop_list(1))
437
Bram Moolenaare2e40752020-09-04 21:18:46 +0200438 call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:')
439 call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:')
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100440
441 call DeletePropTypes()
442 bwipe!
Ben Jacksona7704222022-08-20 20:54:51 +0100443
444 new
445 call AddPropTypes()
446 call SetupPropsInFirstLine()
447 let props = Get_expected_props() " [whole, one, two, three]
448 call assert_equal(props, prop_list(1))
449
450 " remove one by types
451 call assert_equal(1, prop_remove({'types': ['one', 'two', 'three']}, 1))
452 unlet props[1] " [whole, two, three]
453 call assert_equal(props, prop_list(1))
454
455 " remove 'all' by types
456 call assert_equal(2, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
457 unlet props[0] " [two, three]
458 unlet props[1] " [three]
459 call assert_equal(props, prop_list(1))
460
461 " remove none by types
462 call assert_equal(0, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
463 call assert_equal(props, prop_list(1))
464
465 " no types
466 call assert_fails("call prop_remove({'types': []}, 1)", 'E968:')
467 call assert_fails("call prop_remove({'types': ['not_a_real_type']}, 1)", 'E971:')
468
469 " only one of types and type can be supplied
470 call assert_fails("call prop_remove({'type': 'one', 'types': ['three'], 'all': 1}, 1)", 'E1295:')
471
472 call DeletePropTypes()
473 bwipe!
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100474endfunc
475
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200476def Test_prop_add_vim9()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100477 prop_type_add('comment', {
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200478 highlight: 'Directory',
479 priority: 123,
480 start_incl: true,
481 end_incl: true,
482 combine: false,
483 })
484 prop_type_delete('comment')
485enddef
486
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200487def Test_prop_remove_vim9()
488 new
Bram Moolenaar62aec932022-01-29 21:45:34 +0000489 g:AddPropTypes()
490 g:SetupPropsInFirstLine()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100491 assert_equal(1, prop_remove({type: 'three', id: 13, both: true, all: true}))
Bram Moolenaar62aec932022-01-29 21:45:34 +0000492 g:DeletePropTypes()
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200493 bwipe!
494enddef
495
Bram Moolenaar196d1572019-01-02 23:47:18 +0100496func SetupOneLine()
497 call setline(1, 'xonex xtwoxx')
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200498 normal gg0
Bram Moolenaar196d1572019-01-02 23:47:18 +0100499 call AddPropTypes()
500 call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'})
501 call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'})
502 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200503 \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1},
504 \ #{type_bufnr: 0, col: 8, length: 3, id: 12, type: 'two', start: 1, end: 1},
Bram Moolenaar196d1572019-01-02 23:47:18 +0100505 \]
506 call assert_equal(expected, prop_list(1))
507 return expected
508endfunc
509
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100510func Test_prop_add_remove_buf()
511 new
512 let bufnr = bufnr('')
513 call AddPropTypes()
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100514 for lnum in range(1, 4)
515 call setline(lnum, 'one two three')
516 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100517 wincmd w
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100518 for lnum in range(1, 4)
519 call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr})
520 call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr})
521 call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr})
522 endfor
523
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100524 let props = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200525 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
526 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
527 \ #{type_bufnr: 0, col: 11, length: 3, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100528 \]
529 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100530
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100531 " remove by id
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100532 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100533 unlet props[1]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100534
535 call prop_remove({'id': 12, 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100536 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100537 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
538 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
539 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
540
541 call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4)
542 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
543 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
544 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
545 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
546
547 call prop_remove({'id': 12, 'bufnr': bufnr})
548 for lnum in range(1, 4)
549 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
550 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100551
552 " remove by type
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100553 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100554 unlet props[0]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100555
556 call prop_remove({'type': 'one', 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100557 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100558 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
559 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
560 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
561
562 call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4)
563 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
564 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
565 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
566 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
567
568 call prop_remove({'type': 'one', 'bufnr': bufnr})
569 for lnum in range(1, 4)
570 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
571 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100572
573 call DeletePropTypes()
574 wincmd w
575 bwipe!
576endfunc
577
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100578func Test_prop_backspace()
579 new
580 set bs=2
Bram Moolenaar196d1572019-01-02 23:47:18 +0100581 let expected = SetupOneLine() " 'xonex xtwoxx'
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100582
583 exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>"
584 call assert_equal('one xtwoxx', getline(1))
585 let expected[0].col = 1
586 let expected[1].col = 6
587 call assert_equal(expected, prop_list(1))
588
589 call DeletePropTypes()
590 bwipe!
591 set bs&
592endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100593
LemonBoyd0b1a092022-05-12 18:45:18 +0100594func Test_prop_change()
595 new
596 let expected = SetupOneLine() " 'xonex xtwoxx'
597
598 " Characterwise.
599 exe "normal 7|c$\<Esc>"
600 call assert_equal('xonex ', getline(1))
601 call assert_equal(expected[:0], prop_list(1))
602 " Linewise.
603 exe "normal cc\<Esc>"
604 call assert_equal('', getline(1))
605 call assert_equal([], prop_list(1))
606
607 call DeletePropTypes()
608 bwipe!
609 set bs&
610endfunc
611
Bram Moolenaar196d1572019-01-02 23:47:18 +0100612func Test_prop_replace()
613 new
614 set bs=2
615 let expected = SetupOneLine() " 'xonex xtwoxx'
616
617 exe "normal 0Ryyy\<Esc>"
618 call assert_equal('yyyex xtwoxx', getline(1))
619 call assert_equal(expected, prop_list(1))
620
621 exe "normal ftRyy\<BS>"
622 call assert_equal('yyyex xywoxx', getline(1))
623 call assert_equal(expected, prop_list(1))
624
625 exe "normal 0fwRyy\<BS>"
626 call assert_equal('yyyex xyyoxx', getline(1))
627 call assert_equal(expected, prop_list(1))
628
629 exe "normal 0foRyy\<BS>\<BS>"
630 call assert_equal('yyyex xyyoxx', getline(1))
631 call assert_equal(expected, prop_list(1))
632
LemonBoy0d534d92022-05-21 11:20:42 +0100633 " Replace three 1-byte chars with three 2-byte ones.
634 exe "normal 0l3rΓΈ"
635 call assert_equal('yΓΈΓΈΓΈx xyyoxx', getline(1))
636 let expected[0].length += 3
637 let expected[1].col += 3
638 call assert_equal(expected, prop_list(1))
639
Bram Moolenaar196d1572019-01-02 23:47:18 +0100640 call DeletePropTypes()
641 bwipe!
642 set bs&
643endfunc
644
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200645func Test_prop_open_line()
646 new
647
648 " open new line, props stay in top line
649 let expected = SetupOneLine() " 'xonex xtwoxx'
650 exe "normal o\<Esc>"
651 call assert_equal('xonex xtwoxx', getline(1))
652 call assert_equal('', getline(2))
653 call assert_equal(expected, prop_list(1))
654 call DeletePropTypes()
655
656 " move all props to next line
657 let expected = SetupOneLine() " 'xonex xtwoxx'
658 exe "normal 0i\<CR>\<Esc>"
659 call assert_equal('', getline(1))
660 call assert_equal('xonex xtwoxx', getline(2))
661 call assert_equal(expected, prop_list(2))
662 call DeletePropTypes()
663
664 " split just before prop, move all props to next line
665 let expected = SetupOneLine() " 'xonex xtwoxx'
666 exe "normal 0li\<CR>\<Esc>"
667 call assert_equal('x', getline(1))
668 call assert_equal('onex xtwoxx', getline(2))
669 let expected[0].col -= 1
670 let expected[1].col -= 1
671 call assert_equal(expected, prop_list(2))
672 call DeletePropTypes()
673
674 " split inside prop, split first prop
675 let expected = SetupOneLine() " 'xonex xtwoxx'
676 exe "normal 0lli\<CR>\<Esc>"
677 call assert_equal('xo', getline(1))
678 call assert_equal('nex xtwoxx', getline(2))
679 let exp_first = [deepcopy(expected[0])]
680 let exp_first[0].length = 1
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200681 let exp_first[0].end = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200682 call assert_equal(exp_first, prop_list(1))
683 let expected[0].col = 1
684 let expected[0].length = 2
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200685 let expected[0].start = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200686 let expected[1].col -= 2
687 call assert_equal(expected, prop_list(2))
688 call DeletePropTypes()
689
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200690 " split just after first prop, second prop move to next line
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200691 let expected = SetupOneLine() " 'xonex xtwoxx'
692 exe "normal 0fea\<CR>\<Esc>"
693 call assert_equal('xone', getline(1))
694 call assert_equal('x xtwoxx', getline(2))
695 let exp_first = expected[0:0]
696 call assert_equal(exp_first, prop_list(1))
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200697 let expected = expected[1:1]
698 let expected[0].col -= 4
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200699 call assert_equal(expected, prop_list(2))
700 call DeletePropTypes()
701
LemonBoy788c06a2022-05-14 18:48:05 +0100702 " split at the space character with 'ai' active, the leading space is removed
703 " in the second line and the prop is shifted accordingly.
704 let expected = SetupOneLine() " 'xonex xtwoxx'
705 set ai
706 exe "normal 6|i\<CR>\<Esc>"
707 call assert_equal('xonex', getline(1))
708 call assert_equal('xtwoxx', getline(2))
709 let expected[1].col -= 6
710 call assert_equal(expected, prop_list(1) + prop_list(2))
711 set ai&
712 call DeletePropTypes()
713
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200714 bwipe!
715 set bs&
716endfunc
717
Bram Moolenaarecb00c72022-08-07 14:55:14 +0100718func Test_prop_put()
719 new
720 let expected = SetupOneLine() " 'xonex xtwoxx'
721
722 let @a = 'new'
723 " insert just after the prop
724 normal 03l"ap
725 " insert inside the prop
726 normal 02l"ap
727 " insert just before the prop
728 normal 0"ap
729
730 call assert_equal('xnewonnewenewx xtwoxx', getline(1))
731 let expected[0].col += 3
732 let expected[0].length += 3
733 let expected[1].col += 9
734 call assert_equal(expected, prop_list(1))
735
736 " Visually select 4 chars in the prop and put "AB" to replace them
737 let @a = 'AB'
738 normal 05lv3l"ap
739 call assert_equal('xnewoABenewx xtwoxx', getline(1))
740 let expected[0].length -= 2
741 let expected[1].col -= 2
742 call assert_equal(expected, prop_list(1))
743
744 call DeletePropTypes()
745 bwipe!
746endfunc
747
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100748func Test_prop_clear()
749 new
750 call AddPropTypes()
751 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100752 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100753
Bram Moolenaara5a78822019-09-04 21:57:18 +0200754 eval 1->prop_clear()
755 call assert_equal([], 1->prop_list())
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100756
757 call DeletePropTypes()
758 bwipe!
759endfunc
760
761func Test_prop_clear_buf()
762 new
763 call AddPropTypes()
764 call SetupPropsInFirstLine()
765 let bufnr = bufnr('')
766 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100767 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100768
769 call prop_clear(1, 1, {'bufnr': bufnr})
770 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
771
772 wincmd w
773 call DeletePropTypes()
774 bwipe!
775endfunc
776
Bram Moolenaar21b50382019-01-04 18:07:24 +0100777func Test_prop_setline()
778 new
779 call AddPropTypes()
780 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100781 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100782
783 call setline(1, 'foobar')
784 call assert_equal([], prop_list(1))
785
786 call DeletePropTypes()
787 bwipe!
788endfunc
789
790func Test_prop_setbufline()
791 new
792 call AddPropTypes()
793 call SetupPropsInFirstLine()
794 let bufnr = bufnr('')
795 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100796 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100797
798 call setbufline(bufnr, 1, 'foobar')
799 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
800
801 wincmd w
802 call DeletePropTypes()
803 bwipe!
804endfunc
805
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100806func Test_prop_substitute()
807 new
808 " Set first line to 'one two three'
809 call AddPropTypes()
810 call SetupPropsInFirstLine()
811 let expected_props = Get_expected_props()
812 call assert_equal(expected_props, prop_list(1))
813
814 " Change "n" in "one" to XX: 'oXXe two three'
815 s/n/XX/
816 let expected_props[0].length += 1
817 let expected_props[1].length += 1
818 let expected_props[2].col += 1
819 let expected_props[3].col += 1
820 call assert_equal(expected_props, prop_list(1))
821
822 " Delete "t" in "two" and "three" to XX: 'oXXe wo hree'
823 s/t//g
824 let expected_props[0].length -= 2
825 let expected_props[2].length -= 1
826 let expected_props[3].length -= 1
827 let expected_props[3].col -= 1
828 call assert_equal(expected_props, prop_list(1))
829
830 " Split the line by changing w to line break: 'oXXe ', 'o hree'
831 " The long prop is split and spans both lines.
832 " The props on "two" and "three" move to the next line.
833 s/w/\r/
834 let new_props = [
835 \ copy(expected_props[0]),
836 \ copy(expected_props[2]),
837 \ copy(expected_props[3]),
838 \ ]
839 let expected_props[0].length = 5
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200840 let expected_props[0].end = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100841 unlet expected_props[3]
842 unlet expected_props[2]
843 call assert_equal(expected_props, prop_list(1))
844
845 let new_props[0].length = 6
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200846 let new_props[0].start = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100847 let new_props[1].col = 1
848 let new_props[1].length = 1
849 let new_props[2].col = 3
850 call assert_equal(new_props, prop_list(2))
851
852 call DeletePropTypes()
853 bwipe!
854endfunc
855
Bram Moolenaar663bc892019-01-08 23:07:24 +0100856func Test_prop_change_indent()
857 call prop_type_add('comment', {'highlight': 'Directory'})
858 new
859 call setline(1, [' xxx', 'yyyyy'])
860 call prop_add(2, 2, {'length': 2, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200861 let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0}
Bram Moolenaar663bc892019-01-08 23:07:24 +0100862 call assert_equal([expect], prop_list(2))
863
864 set shiftwidth=3
865 normal 2G>>
866 call assert_equal(' yyyyy', getline(2))
867 let expect.col += 3
868 call assert_equal([expect], prop_list(2))
869
870 normal 2G==
871 call assert_equal(' yyyyy', getline(2))
872 let expect.col = 6
873 call assert_equal([expect], prop_list(2))
874
875 call prop_clear(2)
876 call prop_add(2, 2, {'length': 5, 'type': 'comment'})
877 let expect.col = 2
878 let expect.length = 5
879 call assert_equal([expect], prop_list(2))
880
881 normal 2G<<
882 call assert_equal(' yyyyy', getline(2))
883 let expect.length = 2
884 call assert_equal([expect], prop_list(2))
885
886 set shiftwidth&
887 call prop_type_delete('comment')
888endfunc
889
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100890" Setup a three line prop in lines 2 - 4.
891" Add short props in line 1 and 5.
892func Setup_three_line_prop()
893 new
894 call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five'])
895 call prop_add(1, 2, {'length': 1, 'type': 'comment'})
896 call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'})
897 call prop_add(5, 2, {'length': 1, 'type': 'comment'})
898endfunc
899
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100900func Test_prop_multiline()
Bram Moolenaara5a78822019-09-04 21:57:18 +0200901 eval 'comment'->prop_type_add({'highlight': 'Directory'})
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100902 new
903 call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz'])
904
905 " start halfway line 1, end halfway line 3
906 call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200907 let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100908 call assert_equal([expect1], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200909 let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100910 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200911 let expect3 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100912 call assert_equal([expect3], prop_list(3))
913 call prop_clear(1, 3)
914
915 " include all three lines
916 call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'})
917 let expect1.col = 1
918 let expect1.length = 8
919 call assert_equal([expect1], prop_list(1))
920 call assert_equal([expect2], prop_list(2))
921 let expect3.length = 9
922 call assert_equal([expect3], prop_list(3))
923 call prop_clear(1, 3)
924
925 bwipe!
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100926
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100927 " Test deleting the first line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100928 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200929 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 +0100930 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200931 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100932 call assert_equal([expect2], prop_list(2))
933 2del
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100934 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200935 let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100936 call assert_equal([expect2], prop_list(2))
937 bwipe!
938
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100939 " Test deleting the last line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100940 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200941 let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100942 call assert_equal([expect3], prop_list(3))
Martin Tournoije2390c72021-07-28 13:30:16 +0200943 let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100944 call assert_equal([expect4], prop_list(4))
945 4del
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100946 let expect3.end = 1
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100947 call assert_equal([expect3], prop_list(3))
948 call assert_equal([expect_short], prop_list(4))
949 bwipe!
950
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100951 " Test appending a line below the multi-line text prop start.
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100952 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200953 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100954 call assert_equal([expect2], prop_list(2))
955 call append(2, "new line")
956 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200957 let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100958 call assert_equal([expect3], prop_list(3))
959 bwipe!
960
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100961 call prop_type_delete('comment')
962endfunc
963
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100964func Run_test_with_line2byte(add_props)
965 new
966 setlocal ff=unix
967 if a:add_props
968 call prop_type_add('textprop', #{highlight: 'Search'})
969 endif
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100970 " Add a text prop to every fourth line and then change every fifth line so
971 " that it causes a data block split a few times.
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100972 for nr in range(1, 1000)
973 call setline(nr, 'some longer text here')
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100974 if a:add_props && nr % 4 == 0
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100975 call prop_add(nr, 13, #{type: 'textprop', length: 4})
976 endif
977 endfor
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100978 let expected = 22 * 997 + 1
979 call assert_equal(expected, line2byte(998))
980
981 for nr in range(1, 1000, 5)
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100982 exe nr .. "s/longer/much more/"
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100983 let expected += 3
984 call assert_equal(expected, line2byte(998), 'line ' .. nr)
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100985 endfor
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100986
987 if a:add_props
988 call prop_type_delete('textprop')
989 endif
990 bwipe!
991endfunc
992
Bram Moolenaar9df53b62020-01-13 20:40:51 +0100993func Test_prop_line2byte()
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100994 call prop_type_add('comment', {'highlight': 'Directory'})
995 new
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100996 call setline(1, ['line1', 'second line', ''])
Bram Moolenaar8cf734e2018-12-26 01:09:00 +0100997 set ff=unix
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100998 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100999 call prop_add(1, 1, {'end_col': 3, 'type': 'comment'})
Bram Moolenaar00b1e042018-12-26 23:42:10 +01001000 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01001001 bwipe!
Bram Moolenaar14c75302021-08-15 14:28:40 +02001002
1003 new
Bram Moolenaara401bba2021-08-15 15:04:41 +02001004 setlocal ff=unix
Bram Moolenaar14c75302021-08-15 14:28:40 +02001005 call setline(1, range(500))
1006 call assert_equal(1491, line2byte(401))
1007 call prop_add(2, 1, {'type': 'comment'})
1008 call prop_add(222, 1, {'type': 'comment'})
1009 call assert_equal(1491, line2byte(401))
1010 call prop_remove({'type': 'comment'})
1011 call assert_equal(1491, line2byte(401))
1012 bwipe!
1013
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +02001014 new
Bram Moolenaar49b93042021-08-25 17:02:00 +02001015 setlocal ff=unix
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +02001016 call setline(1, range(520))
1017 call assert_equal(1491, line2byte(401))
1018 call prop_add(2, 1, {'type': 'comment'})
1019 call assert_equal(1491, line2byte(401))
1020 2delete
1021 call assert_equal(1489, line2byte(400))
1022 bwipe!
1023
Bram Moolenaarcf85d972022-08-08 14:59:47 +01001024 " Add many lines so that the data block is split.
1025 " With and without props should give the same result.
1026 call Run_test_with_line2byte(0)
1027 call Run_test_with_line2byte(1)
1028
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01001029 call prop_type_delete('comment')
1030endfunc
1031
Bram Moolenaar9df53b62020-01-13 20:40:51 +01001032func Test_prop_byte2line()
1033 new
1034 set ff=unix
1035 call setline(1, ['one one', 'two two', 'three three', 'four four', 'five'])
1036 call assert_equal(4, byte2line(line2byte(4)))
1037 call assert_equal(5, byte2line(line2byte(5)))
1038
1039 call prop_type_add('prop', {'highlight': 'Directory'})
1040 call prop_add(3, 1, {'length': 5, 'type': 'prop'})
1041 call assert_equal(4, byte2line(line2byte(4)))
1042 call assert_equal(5, byte2line(line2byte(5)))
1043
1044 bwipe!
1045 call prop_type_delete('prop')
1046endfunc
1047
Bram Moolenaar59ff6402021-01-30 17:16:28 +01001048func Test_prop_goto_byte()
1049 new
1050 call setline(1, '')
1051 call setline(2, 'two three')
1052 call setline(3, '')
1053 call setline(4, 'four five')
1054
1055 call prop_type_add('testprop', {'highlight': 'Directory'})
1056 call search('^two')
1057 call prop_add(line('.'), col('.'), {
1058 \ 'length': len('two'),
1059 \ 'type': 'testprop'
1060 \ })
1061
1062 call search('two \zsthree')
1063 let expected_pos = line2byte(line('.')) + col('.') - 1
1064 exe expected_pos .. 'goto'
1065 let actual_pos = line2byte(line('.')) + col('.') - 1
1066 eval actual_pos->assert_equal(expected_pos)
1067
1068 call search('four \zsfive')
1069 let expected_pos = line2byte(line('.')) + col('.') - 1
1070 exe expected_pos .. 'goto'
1071 let actual_pos = line2byte(line('.')) + col('.') - 1
1072 eval actual_pos->assert_equal(expected_pos)
1073
1074 call prop_type_delete('testprop')
1075 bwipe!
1076endfunc
1077
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001078func Test_prop_undo()
1079 new
1080 call prop_type_add('comment', {'highlight': 'Directory'})
1081 call setline(1, ['oneone', 'twotwo', 'three'])
1082 " Set 'undolevels' to break changes into undo-able pieces.
1083 set ul&
1084
1085 call prop_add(1, 3, {'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001086 let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}]
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001087 call assert_equal(expected, prop_list(1))
1088
1089 " Insert a character, then undo.
1090 exe "normal 0lllix\<Esc>"
1091 set ul&
1092 let expected[0].length = 3
1093 call assert_equal(expected, prop_list(1))
1094 undo
1095 let expected[0].length = 2
1096 call assert_equal(expected, prop_list(1))
1097
1098 " Delete a character, then undo
1099 exe "normal 0lllx"
1100 set ul&
1101 let expected[0].length = 1
1102 call assert_equal(expected, prop_list(1))
1103 undo
1104 let expected[0].length = 2
1105 call assert_equal(expected, prop_list(1))
1106
1107 " Delete the line, then undo
1108 1d
1109 set ul&
1110 call assert_equal([], prop_list(1))
1111 undo
1112 call assert_equal(expected, prop_list(1))
1113
1114 " Insert a character, delete two characters, then undo with "U"
1115 exe "normal 0lllix\<Esc>"
1116 set ul&
1117 let expected[0].length = 3
1118 call assert_equal(expected, prop_list(1))
1119 exe "normal 0lllxx"
1120 set ul&
1121 let expected[0].length = 1
1122 call assert_equal(expected, prop_list(1))
1123 normal U
1124 let expected[0].length = 2
1125 call assert_equal(expected, prop_list(1))
1126
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001127 " substitute a word, then undo
1128 call setline(1, 'the number 123 is highlighted.')
1129 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001130 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001131 call assert_equal(expected, prop_list(1))
1132 set ul&
1133 1s/number/foo
1134 let expected[0].col = 9
1135 call assert_equal(expected, prop_list(1))
1136 undo
1137 let expected[0].col = 12
1138 call assert_equal(expected, prop_list(1))
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001139 call prop_clear(1)
1140
1141 " substitute with backslash
1142 call setline(1, 'the number 123 is highlighted.')
1143 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001144 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001145 call assert_equal(expected, prop_list(1))
1146 1s/the/\The
1147 call assert_equal(expected, prop_list(1))
1148 1s/^/\\
1149 let expected[0].col += 1
1150 call assert_equal(expected, prop_list(1))
1151 1s/^/\~
1152 let expected[0].col += 1
1153 call assert_equal(expected, prop_list(1))
1154 1s/123/12\\3
1155 let expected[0].length += 1
1156 call assert_equal(expected, prop_list(1))
1157 call prop_clear(1)
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001158
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001159 bwipe!
1160 call prop_type_delete('comment')
1161endfunc
1162
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001163func Test_prop_delete_text()
1164 new
1165 call prop_type_add('comment', {'highlight': 'Directory'})
1166 call setline(1, ['oneone', 'twotwo', 'three'])
1167
1168 " zero length property
1169 call prop_add(1, 3, {'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001170 let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001171 call assert_equal(expected, prop_list(1))
1172
1173 " delete one char moves the property
1174 normal! x
Martin Tournoije2390c72021-07-28 13:30:16 +02001175 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001176 call assert_equal(expected, prop_list(1))
1177
1178 " delete char of the property has no effect
1179 normal! lx
Martin Tournoije2390c72021-07-28 13:30:16 +02001180 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001181 call assert_equal(expected, prop_list(1))
1182
1183 " delete more chars moves property to first column, is not deleted
1184 normal! 0xxxx
Martin Tournoije2390c72021-07-28 13:30:16 +02001185 let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001186 call assert_equal(expected, prop_list(1))
1187
1188 bwipe!
1189 call prop_type_delete('comment')
1190endfunc
1191
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001192" screenshot test with textprop highlighting
Bram Moolenaar8055d172019-05-17 22:57:26 +02001193func Test_textprop_screenshot_various()
Bram Moolenaar34390282019-10-16 14:38:26 +02001194 CheckScreendump
Bram Moolenaared79d1e2019-02-22 14:38:58 +01001195 " The Vim running in the terminal needs to use utf-8.
Bram Moolenaar34390282019-10-16 14:38:26 +02001196 if g:orig_encoding != 'utf-8'
1197 throw 'Skipped: not using utf-8'
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001198 endif
1199 call writefile([
Bram Moolenaarde24a872019-05-05 15:48:00 +02001200 \ "call setline(1, ["
1201 \ .. "'One two',"
1202 \ .. "'NumbΓ©r 123 Γ€nd thΕ“n 4ΒΎ7.',"
1203 \ .. "'--aa--bb--cc--dd--',"
1204 \ .. "'// comment with error in it',"
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001205 \ .. "'first line',"
1206 \ .. "' second line ',"
1207 \ .. "'third line',"
1208 \ .. "' fourth line',"
Bram Moolenaarde24a872019-05-05 15:48:00 +02001209 \ .. "])",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001210 \ "hi NumberProp ctermfg=blue",
1211 \ "hi LongProp ctermbg=yellow",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001212 \ "hi BackgroundProp ctermbg=lightgrey",
1213 \ "hi UnderlineProp cterm=underline",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001214 \ "call prop_type_add('number', {'highlight': 'NumberProp'})",
Bram Moolenaara5a78822019-09-04 21:57:18 +02001215 \ "call prop_type_add('long', {'highlight': 'NumberProp'})",
1216 \ "call prop_type_change('long', {'highlight': 'LongProp'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001217 \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})",
1218 \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})",
1219 \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001220 \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})",
1221 \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})",
1222 \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})",
Bram Moolenaar58e32ab2019-11-12 22:44:22 +01001223 \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001224 \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001225 \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
1226 \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001227 \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})",
1228 \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})",
1229 \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})",
1230 \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001231 \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})",
1232 \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001233 \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001234 \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})",
1235 \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})",
1236 \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})",
1237 \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})",
Bram Moolenaarbfd45122019-05-17 13:05:07 +02001238 \ "set number cursorline",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001239 \ "hi clear SpellBad",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001240 \ "set spell",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001241 \ "syn match Comment '//.*'",
1242 \ "hi Comment ctermfg=green",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001243 \ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>",
Bram Moolenaar33c8ca92019-01-02 18:00:27 +01001244 \ "normal 3G0lli\<BS>\<Esc>",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001245 \ "normal 6G0i\<BS>\<Esc>",
1246 \ "normal 3J",
1247 \ "normal 3G",
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001248 \], 'XtestProp', 'D')
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001249 let buf = RunVimInTerminal('-S XtestProp', {'rows': 8})
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001250 call VerifyScreenDump(buf, 'Test_textprop_01', {})
Bram Moolenaare3d31b02018-12-24 23:07:04 +01001251
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001252 " clean up
1253 call StopVimInTerminal(buf)
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001254endfunc
Bram Moolenaar8055d172019-05-17 22:57:26 +02001255
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001256func Test_textprop_hl_override()
1257 CheckScreendump
Drew Vogelea67ba72025-05-07 22:05:17 +02001258 CheckRunVimInTerminal
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001259
1260 let lines =<< trim END
1261 call setline(1, ['One one one one one', 'Two two two two two', 'Three three three three'])
1262 hi OverProp ctermfg=blue ctermbg=yellow
1263 hi CursorLine cterm=bold,underline ctermfg=red ctermbg=green
1264 hi Vsual ctermfg=cyan ctermbg=grey
1265 call prop_type_add('under', #{highlight: 'OverProp'})
1266 call prop_type_add('over', #{highlight: 'OverProp', override: 1})
1267 call prop_add(1, 5, #{type: 'under', length: 4})
1268 call prop_add(1, 13, #{type: 'over', length: 4})
1269 call prop_add(2, 5, #{type: 'under', length: 4})
1270 call prop_add(2, 13, #{type: 'over', length: 4})
1271 call prop_add(3, 5, #{type: 'under', length: 4})
1272 call prop_add(3, 13, #{type: 'over', length: 4})
1273 set cursorline
1274 2
1275 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001276 call writefile(lines, 'XtestOverProp', 'D')
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001277 let buf = RunVimInTerminal('-S XtestOverProp', {'rows': 8})
1278 call VerifyScreenDump(buf, 'Test_textprop_hl_override_1', {})
1279
1280 call term_sendkeys(buf, "3Gllv$hh")
1281 call VerifyScreenDump(buf, 'Test_textprop_hl_override_2', {})
1282 call term_sendkeys(buf, "\<Esc>")
1283
1284 " clean up
1285 call StopVimInTerminal(buf)
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001286endfunc
1287
Bram Moolenaar8055d172019-05-17 22:57:26 +02001288func RunTestVisualBlock(width, dump)
Drew Vogelea67ba72025-05-07 22:05:17 +02001289 CheckScreendump
Bram Moolenaar8055d172019-05-17 22:57:26 +02001290 call writefile([
1291 \ "call setline(1, ["
1292 \ .. "'xxxxxxxxx 123 x',"
1293 \ .. "'xxxxxxxx 123 x',"
1294 \ .. "'xxxxxxx 123 x',"
1295 \ .. "'xxxxxx 123 x',"
1296 \ .. "'xxxxx 123 x',"
1297 \ .. "'xxxx 123 xx',"
1298 \ .. "'xxx 123 xxx',"
1299 \ .. "'xx 123 xxxx',"
1300 \ .. "'x 123 xxxxx',"
1301 \ .. "' 123 xxxxxx',"
1302 \ .. "])",
1303 \ "hi SearchProp ctermbg=yellow",
1304 \ "call prop_type_add('search', {'highlight': 'SearchProp'})",
1305 \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})",
1306 \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})",
1307 \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})",
1308 \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})",
1309 \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})",
1310 \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})",
1311 \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})",
1312 \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})",
1313 \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})",
1314 \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})",
1315 \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx",
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001316 \], 'XtestPropVis', 'D')
Bram Moolenaar8055d172019-05-17 22:57:26 +02001317 let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12})
1318 call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {})
1319
1320 " clean up
1321 call StopVimInTerminal(buf)
Bram Moolenaar8055d172019-05-17 22:57:26 +02001322endfunc
1323
1324" screenshot test with Visual block mode operations
1325func Test_textprop_screenshot_visual()
Bram Moolenaar34390282019-10-16 14:38:26 +02001326 CheckScreendump
Bram Moolenaar8055d172019-05-17 22:57:26 +02001327
1328 " Delete two columns while text props are three chars wide.
1329 call RunTestVisualBlock(2, '01')
1330
1331 " Same, but delete four columns
1332 call RunTestVisualBlock(4, '02')
1333endfunc
Bram Moolenaard79eef22019-05-24 20:41:55 +02001334
Bram Moolenaara956bf62019-06-19 17:34:24 +02001335func Test_textprop_after_tab()
Bram Moolenaar34390282019-10-16 14:38:26 +02001336 CheckScreendump
Bram Moolenaar37e66cf2019-06-19 18:16:10 +02001337
Bram Moolenaara956bf62019-06-19 17:34:24 +02001338 let lines =<< trim END
1339 call setline(1, [
1340 \ "\txxx",
1341 \ "x\txxx",
1342 \ ])
1343 hi SearchProp ctermbg=yellow
1344 call prop_type_add('search', {'highlight': 'SearchProp'})
1345 call prop_add(1, 2, {'length': 3, 'type': 'search'})
1346 call prop_add(2, 3, {'length': 3, 'type': 'search'})
1347 END
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00001348 call writefile(lines, 'XtextPropTab', 'D')
1349 let buf = RunVimInTerminal('-S XtextPropTab', {'rows': 6})
Bram Moolenaara956bf62019-06-19 17:34:24 +02001350 call VerifyScreenDump(buf, 'Test_textprop_tab', {})
1351
1352 " clean up
1353 call StopVimInTerminal(buf)
Bram Moolenaara956bf62019-06-19 17:34:24 +02001354endfunc
1355
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00001356func Test_textprop_nesting()
1357 CheckScreendump
1358
1359 let lines =<< trim END
1360 vim9script
1361 var lines =<< trim LINESEND
1362
1363 const func: func.IFunction = ({
1364 setLoading
1365 }) => {
1366 LINESEND
1367 setline(1, lines)
1368 prop_type_add('prop_add_test', {highlight: "ErrorMsg"})
1369 prop_add(2, 31, {type: 'prop_add_test', end_lnum: 4, end_col: 2})
1370 var text = 'text long enough to wrap line, text long enough to wrap line, text long enough to wrap line...'
1371 prop_add(2, 0, {type: 'prop_add_test', text_wrap: 'truncate', text_align: 'after', text: text})
1372 END
1373 call writefile(lines, 'XtextpropNesting', 'D')
1374 let buf = RunVimInTerminal('-S XtextpropNesting', {'rows': 8})
1375 call VerifyScreenDump(buf, 'Test_textprop_nesting', {})
1376
1377 " clean up
1378 call StopVimInTerminal(buf)
1379endfunc
1380
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001381func Test_textprop_nowrap_scrolled()
1382 CheckScreendump
1383
1384 let lines =<< trim END
1385 vim9script
1386 set nowrap
1387 setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns))
1388 prop_type_add('number', {'highlight': 'ErrorMsg'})
1389 prop_add(1, 12, {'length': 3, 'type': 'number'})
1390 prop_add(1, 32, {'length': 4, 'type': 'number'})
1391 feedkeys('gg20zl', 'nxt')
1392 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001393 call writefile(lines, 'XtestNowrap', 'D')
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001394 let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6})
1395 call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {})
1396
1397 call term_sendkeys(buf, "$")
1398 call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {})
1399
1400 " clean up
1401 call StopVimInTerminal(buf)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001402endfunc
1403
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001404func Test_textprop_text_priority()
1405 CheckScreendump
1406
1407 let lines =<< trim END
1408 call setline(1, "function( call, argument, here )")
1409
1410 call prop_type_add('one', #{highlight: 'Error'})
1411 call prop_type_add('two', #{highlight: 'Function'})
1412 call prop_type_add('three', #{highlight: 'DiffChange'})
1413 call prop_type_add('arg', #{highlight: 'Search'})
1414
1415 call prop_add(1, 27, #{type: 'arg', length: len('here')})
1416 call prop_add(1, 27, #{type: 'three', text: 'three: '})
1417 call prop_add(1, 11, #{type: 'one', text: 'one: '})
1418 call prop_add(1, 11, #{type: 'arg', length: len('call')})
1419 call prop_add(1, 17, #{type: 'two', text: 'two: '})
1420 call prop_add(1, 17, #{type: 'arg', length: len('argument')})
1421 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001422 call writefile(lines, 'XtestPropPrio', 'D')
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001423 let buf = RunVimInTerminal('-S XtestPropPrio', {'rows': 5})
1424 call VerifyScreenDump(buf, 'Test_prop_at_same_pos', {})
1425
1426 " clean up
1427 call StopVimInTerminal(buf)
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001428endfunc
1429
zeertzjq4e26a9a2023-12-03 17:50:47 +01001430func Test_textprop_in_empty_popup()
1431 CheckScreendump
1432
1433 let lines =<< trim END
1434 vim9script
1435
1436 hi def link FilterMenuMatch Constant
1437 prop_type_add('FilterMenuMatch', {
1438 highlight: "FilterMenuMatch",
1439 override: true,
1440 priority: 1000,
1441 combine: true,
1442 })
1443
1444 var winid = popup_create([{text: "hello", props: [
1445 {col: 1, length: 1, type: 'FilterMenuMatch'},
1446 {col: 2, length: 1, type: 'FilterMenuMatch'},
1447 ]}], {
1448 minwidth: 20,
1449 minheight: 10,
1450 cursorline: false,
1451 highlight: "None",
1452 border: [],
1453 })
1454
1455 win_execute(winid, "setl nu cursorline cursorlineopt=both")
1456 popup_settext(winid, [])
1457 redraw
1458 END
1459 call writefile(lines, 'XtestPropEmptyPopup', 'D')
1460 let buf = RunVimInTerminal('-S XtestPropEmptyPopup', #{rows: 20, cols: 40})
1461 call VerifyScreenDump(buf, 'Test_prop_in_empty_popup', {})
1462
1463 " clean up
1464 call StopVimInTerminal(buf)
1465endfunc
1466
Bram Moolenaar34390282019-10-16 14:38:26 +02001467func Test_textprop_with_syntax()
1468 CheckScreendump
1469
1470 let lines =<< trim END
1471 call setline(1, [
1472 \ "(abc)",
1473 \ ])
1474 syn match csParens "[()]" display
1475 hi! link csParens MatchParen
1476
1477 call prop_type_add('TPTitle', #{ highlight: 'Title' })
1478 call prop_add(1, 2, #{type: 'TPTitle', end_col: 5})
1479 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001480 call writefile(lines, 'XtestPropSyn', 'D')
Bram Moolenaar34390282019-10-16 14:38:26 +02001481 let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6})
1482 call VerifyScreenDump(buf, 'Test_textprop_syn_1', {})
1483
1484 " clean up
1485 call StopVimInTerminal(buf)
Bram Moolenaar34390282019-10-16 14:38:26 +02001486endfunc
1487
Bram Moolenaard79eef22019-05-24 20:41:55 +02001488" Adding a text property to a new buffer should not fail
1489func Test_textprop_empty_buffer()
1490 call prop_type_add('comment', {'highlight': 'Search'})
1491 new
1492 call prop_add(1, 1, {'type': 'comment'})
1493 close
Bram Moolenaaradfde112019-05-25 22:11:45 +02001494 call prop_type_delete('comment')
1495endfunc
1496
Bram Moolenaard74af422019-06-28 21:38:00 +02001497" Adding a text property with invalid highlight should be ignored.
1498func Test_textprop_invalid_highlight()
1499 call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:')
1500 new
Ben Jacksona7704222022-08-20 20:54:51 +01001501 call setline(1, ['asdf', 'asdf'])
Bram Moolenaard74af422019-06-28 21:38:00 +02001502 call prop_add(1, 1, {'length': 4, 'type': 'dni'})
1503 redraw
1504 bwipe!
1505 call prop_type_delete('dni')
1506endfunc
1507
Bram Moolenaaradfde112019-05-25 22:11:45 +02001508" Adding a text property to an empty buffer and then editing another
1509func Test_textprop_empty_buffer_next()
1510 call prop_type_add("xxx", {})
1511 call prop_add(1, 1, {"type": "xxx"})
1512 next X
1513 call prop_type_delete('xxx')
Bram Moolenaard79eef22019-05-24 20:41:55 +02001514endfunc
Bram Moolenaarf0884c52019-05-24 21:22:29 +02001515
1516func Test_textprop_remove_from_buf()
1517 new
1518 let buf = bufnr('')
1519 call prop_type_add('one', {'bufnr': buf})
1520 call prop_add(1, 1, {'type': 'one', 'id': 234})
1521 file x
1522 edit y
1523 call prop_remove({'id': 234, 'bufnr': buf}, 1)
1524 call prop_type_delete('one', {'bufnr': buf})
1525 bwipe! x
1526 close
1527endfunc
Bram Moolenaar45311b52019-08-13 22:27:32 +02001528
1529func Test_textprop_in_unloaded_buf()
1530 edit Xaaa
1531 call setline(1, 'aaa')
1532 write
1533 edit Xbbb
1534 call setline(1, 'bbb')
1535 write
1536 let bnr = bufnr('')
1537 edit Xaaa
1538
1539 call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'})
1540 call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:')
1541 exe 'buf ' .. bnr
1542 call assert_equal('bbb', getline(1))
1543 call assert_equal(0, prop_list(1)->len())
1544
1545 bwipe! Xaaa
1546 bwipe! Xbbb
1547 cal delete('Xaaa')
1548 cal delete('Xbbb')
1549endfunc
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001550
1551func Test_proptype_substitute2()
1552 new
1553 " text_prop.vim
1554 call setline(1, [
1555 \ 'The num 123 is smaller than 4567.',
1556 \ '123 The number 123 is smaller than 4567.',
1557 \ '123 The number 123 is smaller than 4567.'])
1558
1559 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1560
1561 call prop_add(1, 12, {'length': 3, 'type': 'number'})
1562 call prop_add(2, 1, {'length': 3, 'type': 'number'})
1563 call prop_add(3, 36, {'length': 4, 'type': 'number'})
1564 set ul&
Martin Tournoije2390c72021-07-28 13:30:16 +02001565 let expected = [
1566 \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1},
1567 \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1},
1568 \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}]
1569
1570 " TODO
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001571 if 0
1572 " Add some text in between
1573 %s/\s\+/ /g
1574 call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001575
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001576 " remove some text
1577 :1s/[a-z]\{3\}//g
1578 let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
1579 call assert_equal(expected, prop_list(1))
1580 endif
1581
1582 call prop_type_delete('number')
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001583 bwipe!
1584endfunc
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001585
Bram Moolenaar8902b312020-09-20 21:04:35 +02001586" This was causing property corruption.
1587func Test_proptype_substitute3()
1588 new
1589 call setline(1, ['abcxxx', 'def'])
1590 call prop_type_add("test", {"highlight": "Search"})
1591 call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"})
1592 %s/x\+$//
1593 redraw
1594
1595 call prop_type_delete('test')
1596 bwipe!
1597endfunc
1598
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001599func Test_proptype_substitute_join()
1600 new
1601 call setline(1, [
1602 \ 'This is some end',
1603 \ 'start is highlighted end',
1604 \ 'some is highlighted',
1605 \ 'start is also highlighted'])
1606
1607 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1608
1609 call prop_add(1, 6, {'length': 2, 'type': 'number'})
1610 call prop_add(2, 7, {'length': 2, 'type': 'number'})
1611 call prop_add(3, 6, {'length': 2, 'type': 'number'})
1612 call prop_add(4, 7, {'length': 2, 'type': 'number'})
Dominique Pelleb49dfd02023-04-14 21:54:25 +01001613 " The highlighted "is" in line 1, 2 and 4 is kept and adjusted.
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001614 " The highlighted "is" in line 3 is deleted.
1615 let expected = [
1616 \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1},
1617 \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1},
1618 \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}]
1619
1620 s/end\nstart/joined/
1621 s/end\n.*\nstart/joined/
1622 call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1))
1623 call assert_equal(expected, prop_list(1))
1624
1625 call prop_type_delete('number')
1626 bwipe!
1627endfunc
1628
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001629func SaveOptions()
1630 let d = #{tabstop: &tabstop,
1631 \ softtabstop: &softtabstop,
1632 \ shiftwidth: &shiftwidth,
1633 \ expandtab: &expandtab,
1634 \ foldmethod: '"' .. &foldmethod .. '"',
1635 \ }
1636 return d
1637endfunc
1638
1639func RestoreOptions(dict)
1640 for name in keys(a:dict)
1641 exe 'let &' .. name .. ' = ' .. a:dict[name]
1642 endfor
1643endfunc
1644
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001645func Test_textprop_noexpandtab()
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001646 new
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001647 let save_dict = SaveOptions()
1648
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001649 set tabstop=8
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001650 set softtabstop=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001651 set shiftwidth=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001652 set noexpandtab
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001653 set foldmethod=marker
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001654
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001655 call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx")
1656 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1657 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1658 call feedkeys("0i\<tab>", "tx")
1659 call prop_remove({'type': 'test'})
1660 call prop_add(1, 2, {'end_col': 3, 'type': 'test'})
1661 call feedkeys("A\<left>\<tab>", "tx")
1662 call prop_remove({'type': 'test'})
1663 try
1664 " It is correct that this does not pass
1665 call prop_add(1, 6, {'end_col': 7, 'type': 'test'})
1666 " Has already collapsed here, start_col:6 does not result in an error
1667 call feedkeys("A\<left>\<tab>", "tx")
1668 catch /^Vim\%((\a\+)\)\=:E964/
1669 endtry
1670 call prop_remove({'type': 'test'})
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001671 call prop_type_delete('test')
1672
1673 call RestoreOptions(save_dict)
1674 bwipe!
1675endfunc
1676
1677func Test_textprop_noexpandtab_redraw()
1678 new
1679 let save_dict = SaveOptions()
1680
1681 set tabstop=8
1682 set softtabstop=4
1683 set shiftwidth=4
1684 set noexpandtab
1685 set foldmethod=marker
1686
1687 call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx")
1688 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1689 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1690 call feedkeys("0i\<tab>", "tx")
1691 " Internally broken at the next line
1692 call feedkeys("A\<left>\<tab>", "tx")
1693 redraw
1694 " Index calculation failed internally on next line
1695 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1696 call prop_remove({'type': 'test', 'all': v:true})
1697 call prop_type_delete('test')
1698 call prop_type_delete('test')
1699
1700 call RestoreOptions(save_dict)
1701 bwipe!
1702endfunc
1703
1704func Test_textprop_ins_str()
1705 new
1706 call setline(1, 'just some text')
1707 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1708 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001709 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 +01001710
1711 call feedkeys("foi\<F8>\<Esc>", "tx")
1712 call assert_equal('just s<F8>ome text', getline(1))
Martin Tournoije2390c72021-07-28 13:30:16 +02001713 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 +01001714
1715 bwipe!
1716 call prop_remove({'type': 'test'})
1717 call prop_type_delete('test')
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001718endfunc
Bram Moolenaar66b98852020-03-11 19:15:52 +01001719
1720func Test_find_prop_later_in_line()
1721 new
1722 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1723 call setline(1, 'just some text')
1724 call prop_add(1, 1, {'length': 4, 'type': 'test'})
1725 call prop_add(1, 10, {'length': 3, 'type': 'test'})
1726
Martin Tournoije2390c72021-07-28 13:30:16 +02001727 call assert_equal(
1728 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1},
1729 \ prop_find(#{type: 'test', lnum: 1, col: 6}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001730
1731 bwipe!
1732 call prop_type_delete('test')
1733endfunc
1734
1735func Test_find_zerowidth_prop_sol()
1736 new
1737 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1738 call setline(1, 'just some text')
1739 call prop_add(1, 1, {'length': 0, 'type': 'test'})
1740
Martin Tournoije2390c72021-07-28 13:30:16 +02001741 call assert_equal(
1742 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1},
1743 \ prop_find(#{type: 'test', lnum: 1}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001744
1745 bwipe!
1746 call prop_type_delete('test')
1747endfunc
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001748
1749" Test for passing invalid arguments to prop_xxx() functions
1750func Test_prop_func_invalid_args()
1751 call assert_fails('call prop_clear(1, 2, [])', 'E715:')
1752 call assert_fails('call prop_clear(-1, 2)', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001753 call assert_fails('call prop_find(test_null_dict())', 'E1297:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001754 call assert_fails('call prop_find({"bufnr" : []})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001755 call assert_fails('call prop_find({})', 'E968:')
1756 call assert_fails('call prop_find({}, "x")', 'E474:')
1757 call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001758 call assert_fails('call prop_list(1, [])', 'E1206:')
Bram Moolenaar9d489562020-07-30 20:08:50 +02001759 call assert_fails('call prop_list(-1, {})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001760 call assert_fails('call prop_remove([])', 'E1206:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001761 call assert_fails('call prop_remove({}, -2)', 'E16:')
1762 call assert_fails('call prop_remove({})', 'E968:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001763 call assert_fails('call prop_type_add([], {})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001764 call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001765 call assert_fails("call prop_type_delete([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001766 call assert_fails("call prop_type_delete('xyz', [])", 'E715:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001767 call assert_fails("call prop_type_get([])", 'E730:')
Bram Moolenaar89469d12022-12-02 20:46:26 +00001768 call assert_fails("call prop_type_get('', [])", 'E475:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001769 call assert_fails("call prop_type_list([])", 'E715:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001770 call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:')
1771 call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:')
1772 call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001773 call assert_fails('call prop_add(1, 1, 0)', 'E1206:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001774
1775 new
1776 call setline(1, ['first', 'second'])
1777 call prop_type_add('xxx', {})
1778
1779 call assert_fails("call prop_type_add('xxx', {})", 'E969:')
1780 call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:')
1781 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:')
1782 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:')
1783 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:')
1784 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:')
1785 call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:')
Christian Brabandt701c8632024-09-08 20:05:23 +02001786 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'id': 2147483648})", 'E1510:')
1787 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'id': -2147483648})", 'E1510:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001788
1789 call prop_type_delete('xxx')
1790 bwipe!
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001791endfunc
1792
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001793func Test_prop_split_join()
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001794 new
1795 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1796 call setline(1, 'just some text')
1797 call prop_add(1, 6, {'length': 4, 'type': 'test'})
1798
1799 " Split in middle of "some"
1800 execute "normal! 8|i\<CR>"
Martin Tournoije2390c72021-07-28 13:30:16 +02001801 call assert_equal(
1802 \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}],
1803 \ prop_list(1))
1804 call assert_equal(
1805 \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}],
1806 \ prop_list(2))
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001807
1808 " Join the two lines back together
1809 normal! 1GJ
Martin Tournoije2390c72021-07-28 13:30:16 +02001810 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 +02001811
1812 bwipe!
1813 call prop_type_delete('test')
1814endfunc
1815
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001816func Test_prop_increment_decrement()
1817 new
1818 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1819 call setline(1, 'its 998 times')
1820 call prop_add(1, 5, {'length': 3, 'type': 'test'})
1821
1822 exe "normal! 0f9\<C-A>"
1823 eval getline(1)->assert_equal('its 999 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: 3, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001826
1827 exe "normal! 0f9\<C-A>"
1828 eval getline(1)->assert_equal('its 1000 times')
1829 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001830 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001831
1832 bwipe!
1833 call prop_type_delete('test')
1834endfunc
1835
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001836func Test_prop_block_insert()
1837 new
1838 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1839 call setline(1, ['one ', 'two '])
1840 call prop_add(1, 1, {'length': 3, 'type': 'test'})
1841 call prop_add(2, 1, {'length': 3, 'type': 'test'})
1842
1843 " insert "xx" in the first column of both lines
1844 exe "normal! gg0\<C-V>jIxx\<Esc>"
1845 eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
Martin Tournoije2390c72021-07-28 13:30:16 +02001846 let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001847 eval prop_list(1)->assert_equal(expected)
1848 eval prop_list(2)->assert_equal(expected)
1849
1850 " insert "yy" inside the text props to make them longer
1851 exe "normal! gg03l\<C-V>jIyy\<Esc>"
1852 eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo '])
1853 let expected[0].length = 5
1854 eval prop_list(1)->assert_equal(expected)
1855 eval prop_list(2)->assert_equal(expected)
1856
1857 " insert "zz" after the text props, text props don't change
1858 exe "normal! gg07l\<C-V>jIzz\<Esc>"
1859 eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz '])
1860 eval prop_list(1)->assert_equal(expected)
1861 eval prop_list(2)->assert_equal(expected)
1862
1863 bwipe!
1864 call prop_type_delete('test')
1865endfunc
1866
Bram Moolenaar23999d72020-12-23 14:36:00 +01001867" this was causing an ml_get error because w_botline was wrong
1868func Test_prop_one_line_window()
1869 enew
1870 call range(2)->setline(1)
1871 call prop_type_add('testprop', {})
1872 call prop_add(1, 1, {'type': 'testprop'})
1873 call popup_create('popup', {'textprop': 'testprop'})
1874 $
1875 new
1876 wincmd _
1877 call feedkeys("\r", 'xt')
1878 redraw
1879
1880 call popup_clear()
1881 call prop_type_delete('testprop')
1882 close
1883 bwipe!
1884endfunc
1885
Bram Moolenaarf05a1e52022-08-02 11:48:53 +01001886def Test_prop_column_zero_error()
1887 prop_type_add('proptype', {highlight: 'Search'})
1888 var caught = false
1889 try
1890 popup_create([{
1891 text: 'a',
1892 props: [{col: 0, length: 1, type: 'type'}],
1893 }], {})
1894 catch /E964:/
1895 caught = true
1896 endtry
1897 assert_true(caught)
1898
1899 popup_clear()
1900 prop_type_delete('proptype')
1901enddef
1902
Bram Moolenaar840f91f2021-05-26 22:32:10 +02001903" This was calling ml_append_int() and copy a text property from a previous
1904" line at the wrong moment. Exact text length matters.
1905def Test_prop_splits_data_block()
1906 new
1907 var lines: list<string> = [repeat('x', 35)]->repeat(41)
1908 + [repeat('!', 35)]
1909 + [repeat('x', 35)]->repeat(56)
1910 lines->setline(1)
1911 prop_type_add('someprop', {highlight: 'ErrorMsg'})
1912 prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'})
1913 prop_remove({type: 'someprop'}, 1)
1914 prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'})
1915 prop_remove({type: 'someprop'}, 35, 43)
1916 assert_equal([], prop_list(42))
1917
1918 bwipe!
1919 prop_type_delete('someprop')
1920enddef
1921
Bram Moolenaar4cd5c522021-06-27 13:04:00 +02001922" This was calling ml_delete_int() and try to change text properties.
1923def Test_prop_add_delete_line()
1924 new
1925 var a = 10
1926 var b = 20
1927 repeat([''], a)->append('$')
1928 prop_type_add('Test', {highlight: 'ErrorMsg'})
1929 for lnum in range(1, a)
1930 for col in range(1, b)
1931 prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'})
1932 endfor
1933 endfor
1934
1935 # check deleting lines is OK
1936 :5del
1937 :1del
1938 :$del
1939
1940 prop_type_delete('Test')
1941 bwipe!
1942enddef
1943
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001944" This test is to detect a regression related to #10430. It is not an attempt
1945" fully cover deleting lines in the presence of multi-line properties.
1946def Test_delete_line_within_multiline_prop()
1947 new
1948 setline(1, '# Top.')
1949 append(1, ['some_text = """', 'A string.', '"""', '# Bottom.'])
1950 prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1951 prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1952 prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9})
1953 prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4})
1954
1955 # The property for line 3 should extend into the previous and next lines.
1956 var props = prop_list(3)
1957 var prop = props[0]
1958 assert_equal(1, len(props))
1959 assert_equal(0, prop['start'])
1960 assert_equal(0, prop['end'])
1961
1962 # This deletion should run without raising an exception.
1963 try
1964 :2 del
1965 catch
dundargocc57b5bc2022-11-02 13:30:51 +00001966 assert_report('Line delete should have worked, but it raised an error.')
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001967 endtry
1968
1969 # The property for line 2 (was 3) should no longer extend into the previous
1970 # line.
1971 props = prop_list(2)
1972 prop = props[0]
1973 assert_equal(1, len(props))
1974 assert_equal(1, prop['start'], 'Property was not changed to start within the line.')
1975
1976 # This deletion should run without raising an exception.
1977 try
1978 :3 del
1979 catch
dundargocc57b5bc2022-11-02 13:30:51 +00001980 assert_report('Line delete should have worked, but it raised an error.')
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001981 endtry
1982
1983 # The property for line 2 (originally 3) should no longer extend into the next
1984 # line.
1985 props = prop_list(2)
1986 prop = props[0]
1987 assert_equal(1, len(props))
1988 assert_equal(1, prop['end'], 'Property was not changed to end within the line.')
1989
1990 prop_type_delete('Identifier')
1991 prop_type_delete('String')
1992 bwip!
1993enddef
1994
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001995func Test_prop_in_linebreak()
Drew Vogelea67ba72025-05-07 22:05:17 +02001996 CheckScreendump
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001997 CheckRunVimInTerminal
1998
1999 let lines =<< trim END
2000 set breakindent linebreak breakat+=]
2001 call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1)
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002002 call prop_type_add('test', #{highlight: 'MatchParen'})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002003 call prop_add(1, 51, #{length: 1, type: 'test'})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002004 func AddMatch()
2005 syntax on
2006 syntax match xTest /.*/
2007 hi link xTest Comment
2008 set signcolumn=yes
2009 endfunc
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002010 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002011 call writefile(lines, 'XscriptPropLinebreak', 'D')
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002012 let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002013 call VerifyScreenDump(buf, 'Test_prop_linebreak_1', {})
2014
2015 call term_sendkeys(buf, ":call AddMatch()\<CR>")
2016 call VerifyScreenDump(buf, 'Test_prop_linebreak_2', {})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002017
2018 call StopVimInTerminal(buf)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002019endfunc
2020
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002021func Test_prop_with_linebreak()
Drew Vogelea67ba72025-05-07 22:05:17 +02002022 CheckScreendump
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002023 CheckRunVimInTerminal
2024
2025 let lines =<< trim END
2026 vim9script
2027 set linebreak
2028 setline(1, 'one twoword')
2029 prop_type_add('test', {highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002030 prop_add(1, 4, {text: ': virtual text', type: 'test'})
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002031 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002032 call writefile(lines, 'XscriptPropWithLinebreak', 'D')
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002033 let buf = RunVimInTerminal('-S XscriptPropWithLinebreak', #{rows: 6, cols: 50})
2034 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_1', {})
2035 call term_sendkeys(buf, "iasdf asdf asdf asdf asdf as\<Esc>")
2036 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_2', {})
2037
2038 call StopVimInTerminal(buf)
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002039endfunc
2040
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002041func Test_prop_with_wrap()
Drew Vogelea67ba72025-05-07 22:05:17 +02002042 CheckScreendump
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002043 CheckRunVimInTerminal
2044
2045 let lines =<< trim END
2046 vim9script
2047 set linebreak
2048 setline(1, 'asdf '->repeat(15))
2049 prop_type_add('test', {highlight: 'Special'})
2050 prop_add(1, 43, {text: 'some virtual text', type: 'test'})
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +00002051 normal G$
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002052 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002053 call writefile(lines, 'XscriptPropWithWrap', 'D')
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002054 let buf = RunVimInTerminal('-S XscriptPropWithWrap', #{rows: 6, cols: 50})
2055 call VerifyScreenDump(buf, 'Test_prop_with_wrap_1', {})
2056
2057 call StopVimInTerminal(buf)
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002058endfunc
2059
Bram Moolenaar42eba042021-11-30 20:22:49 +00002060func Test_prop_after_tab()
Drew Vogelea67ba72025-05-07 22:05:17 +02002061 CheckScreendump
Bram Moolenaar42eba042021-11-30 20:22:49 +00002062 CheckRunVimInTerminal
2063
2064 let lines =<< trim END
2065 set breakindent linebreak breakat+=]
2066 call setline(1, "\t[xxx]")
2067 call prop_type_add('test', #{highlight: 'ErrorMsg'})
2068 call prop_add(1, 2, #{length: 1, type: 'test'})
2069 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002070 call writefile(lines, 'XscriptPropAfterTab', 'D')
Bram Moolenaar42eba042021-11-30 20:22:49 +00002071 let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10})
Bram Moolenaar42eba042021-11-30 20:22:49 +00002072 call VerifyScreenDump(buf, 'Test_prop_after_tab', {})
2073
2074 call StopVimInTerminal(buf)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002075endfunc
2076
Bram Moolenaare428fa02022-08-09 16:55:41 +01002077func Test_prop_before_tab()
Drew Vogelea67ba72025-05-07 22:05:17 +02002078 CheckScreendump
Bram Moolenaare428fa02022-08-09 16:55:41 +01002079 CheckRunVimInTerminal
2080
2081 let lines =<< trim END
2082 call setline(1, ["\tx"]->repeat(6))
2083 call prop_type_add('test', #{highlight: 'Search'})
2084 call prop_add(1, 1, #{type: 'test', text: '123'})
2085 call prop_add(2, 1, #{type: 'test', text: '1234567'})
2086 call prop_add(3, 1, #{type: 'test', text: '12345678'})
2087 call prop_add(4, 1, #{type: 'test', text: '123456789'})
2088 call prop_add(5, 2, #{type: 'test', text: 'ABC'})
2089 call prop_add(6, 3, #{type: 'test', text: 'ABC'})
2090 normal gg0
2091 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002092 call writefile(lines, 'XscriptPropBeforeTab', 'D')
Bram Moolenaare428fa02022-08-09 16:55:41 +01002093 let buf = RunVimInTerminal('-S XscriptPropBeforeTab', #{rows: 8})
2094 call VerifyScreenDump(buf, 'Test_prop_before_tab_01', {})
2095 call term_sendkeys(buf, "$")
2096 call VerifyScreenDump(buf, 'Test_prop_before_tab_02', {})
2097 call term_sendkeys(buf, "j0")
2098 call VerifyScreenDump(buf, 'Test_prop_before_tab_03', {})
2099 call term_sendkeys(buf, "$")
2100 call VerifyScreenDump(buf, 'Test_prop_before_tab_04', {})
2101 call term_sendkeys(buf, "j0")
2102 call VerifyScreenDump(buf, 'Test_prop_before_tab_05', {})
2103 call term_sendkeys(buf, "$")
2104 call VerifyScreenDump(buf, 'Test_prop_before_tab_06', {})
2105 call term_sendkeys(buf, "j0")
2106 call VerifyScreenDump(buf, 'Test_prop_before_tab_07', {})
2107 call term_sendkeys(buf, "$")
2108 call VerifyScreenDump(buf, 'Test_prop_before_tab_08', {})
2109 call term_sendkeys(buf, "j")
2110 call VerifyScreenDump(buf, 'Test_prop_before_tab_09', {})
2111 call term_sendkeys(buf, "j")
2112 call VerifyScreenDump(buf, 'Test_prop_before_tab_10', {})
2113
2114 call StopVimInTerminal(buf)
Bram Moolenaare428fa02022-08-09 16:55:41 +01002115endfunc
2116
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002117func Test_prop_after_linebreak()
Drew Vogelea67ba72025-05-07 22:05:17 +02002118 CheckScreendump
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002119 CheckRunVimInTerminal
2120
2121 let lines =<< trim END
2122 set linebreak wrap
2123 call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1)
2124 call prop_type_add('test', #{highlight: 'ErrorMsg'})
2125 call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'})
2126 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002127 call writefile(lines, 'XscriptPropAfterLinebreak', 'D')
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002128 let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10})
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002129 call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {})
2130
2131 call StopVimInTerminal(buf)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002132endfunc
2133
Martin Tournoije2390c72021-07-28 13:30:16 +02002134" Buffer number of 0 should be ignored, as if the parameter wasn't passed.
2135def Test_prop_bufnr_zero()
2136 new
2137 try
2138 var bufnr = bufnr('')
2139 setline(1, 'hello')
2140 prop_type_add('bufnr-global', {highlight: 'ErrorMsg'})
2141 prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr})
2142
2143 prop_add(1, 1, {type: 'bufnr-global', length: 1})
2144 prop_add(1, 2, {type: 'bufnr-buffer', length: 1})
2145
2146 var list = prop_list(1)
2147 assert_equal([
2148 {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1},
2149 {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1},
2150 ], list)
2151
2152 assert_equal(
2153 {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1},
2154 prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr}))
2155
2156 assert_equal(
2157 {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1},
2158 prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr}))
2159 finally
2160 bwipe!
2161 prop_type_delete('bufnr-global')
2162 endtry
2163enddef
2164
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002165" Tests for the prop_list() function
2166func Test_prop_list()
2167 let lines =<< trim END
2168 new
Bram Moolenaar62aec932022-01-29 21:45:34 +00002169 call g:AddPropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002170 call setline(1, repeat([repeat('a', 60)], 10))
2171 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2172 call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7})
2173 call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14})
2174 call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15})
2175 call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22})
2176 call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23})
2177 call assert_equal([
2178 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2179 \ 'type': 'one', 'length': 2, 'start': 1},
2180 \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2181 \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1))
2182 #" text properties between a few lines
2183 call assert_equal([
2184 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2185 \ 'type': 'one', 'length': 2, 'start': 1},
2186 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2187 \ 'type': 'two', 'length': 2, 'start': 1},
2188 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
2189 \ 'type': 'one', 'length': 2, 'start': 1},
2190 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
2191 \ 'type': 'two', 'length': 2, 'start': 1}],
2192 \ prop_list(2, {'end_lnum': 5}))
2193 #" text properties across all the lines
2194 call assert_equal([
2195 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2196 \ 'type': 'one', 'length': 2, 'start': 1},
2197 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2198 \ 'type': 'one', 'length': 2, 'start': 1},
2199 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
2200 \ 'type': 'one', 'length': 2, 'start': 1}],
2201 \ prop_list(1, {'types': ['one'], 'end_lnum': -1}))
2202 #" text properties with the specified identifier
2203 call assert_equal([
2204 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2205 \ 'type': 'one', 'length': 2, 'start': 1},
2206 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
2207 \ 'type': 'two', 'length': 2, 'start': 1}],
2208 \ prop_list(1, {'ids': [20], 'end_lnum': 10}))
2209 #" text properties of the specified type and id
2210 call assert_equal([
2211 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2212 \ 'type': 'two', 'length': 2, 'start': 1},
2213 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2214 \ 'type': 'two', 'length': 2, 'start': 1}],
2215 \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20}))
2216 call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10}))
2217 call assert_equal([], prop_list(6, {'end_lnum': 10}))
2218 call assert_equal([], prop_list(2, {'end_lnum': 2}))
2219 #" error cases
2220 call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:')
2221 call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:')
2222 call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:')
2223 call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})",
2224 \ 'E971:')
2225 call assert_fails("echo prop_list(1, {'types': ['one', 'blue'],
2226 \ 'end_lnum': 10})", 'E971:')
2227 call assert_fails("echo prop_list(1, {'types': ['one', 10],
2228 \ 'end_lnum': 10})", 'E928:')
2229 call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:')
2230 call assert_equal([], prop_list(2, {'types': []}))
2231 call assert_equal([], prop_list(2, {'types': test_null_list()}))
2232 call assert_fails("call prop_list(1, {'types': {}})", 'E714:')
2233 call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:')
2234 call assert_equal([], prop_list(2, {'types': ['one'],
2235 \ 'ids': test_null_list()}))
2236 call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []}))
2237 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})",
2238 \ 'E714:')
2239 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})",
2240 \ 'E714:')
2241 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})",
2242 \ 'E745:')
2243 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})",
2244 \ 'E745:')
Martin Tournoije2390c72021-07-28 13:30:16 +02002245
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002246 #" get text properties from a non-current buffer
2247 wincmd w
2248 call assert_equal([
2249 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2250 \ 'type': 'one', 'length': 2, 'start': 1},
2251 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2252 \ 'type': 'two', 'length': 2, 'start': 1},
2253 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2254 \ 'type': 'one', 'length': 2, 'start': 1},
2255 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2256 \ 'type': 'two', 'length': 2, 'start': 1}],
2257 \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4}))
2258 wincmd w
2259
2260 #" get text properties after clearing all the properties
2261 call prop_clear(1, line('$'))
2262 call assert_equal([], prop_list(1, {'end_lnum': 10}))
2263
2264 call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2265 call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6})
2266 call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6})
2267 #" get text properties with a list of types
2268 call assert_equal([
2269 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2270 \ 'type': 'two', 'length': 2, 'start': 1},
2271 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2272 \ 'type': 'one', 'length': 2, 'start': 1}],
2273 \ prop_list(2, {'types': ['one', 'two']}))
2274 call assert_equal([
2275 \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1,
2276 \ 'type': 'three', 'length': 2, 'start': 1},
2277 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2278 \ 'type': 'one', 'length': 2, 'start': 1}],
2279 \ prop_list(2, {'types': ['one', 'three']}))
2280 #" get text properties with a list of identifiers
2281 call assert_equal([
2282 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2283 \ 'type': 'two', 'length': 2, 'start': 1},
2284 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2285 \ 'type': 'one', 'length': 2, 'start': 1}],
2286 \ prop_list(2, {'ids': [5, 10, 20]}))
2287 call prop_clear(1, line('$'))
2288 call assert_equal([], prop_list(2, {'types': ['one', 'two']}))
2289 call assert_equal([], prop_list(2, {'ids': [5, 10, 20]}))
2290
2291 #" get text properties from a hidden buffer
2292 edit! Xaaa
2293 call setline(1, repeat([repeat('b', 60)], 10))
2294 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2295 call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10})
2296 VAR bnr = bufnr()
2297 hide edit Xbbb
2298 call assert_equal([
2299 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2300 \ 'type': 'one', 'length': 2, 'start': 1},
2301 \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1,
2302 \ 'type': 'two', 'length': 2, 'start': 1}],
2303 \ prop_list(1, {'bufnr': bnr,
2304 \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1}))
2305 #" get text properties from an unloaded buffer
2306 bunload! Xaaa
2307 call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1}))
2308
Bram Moolenaar62aec932022-01-29 21:45:34 +00002309 call g:DeletePropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002310 :%bw!
2311 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00002312 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002313endfunc
Bram Moolenaar23999d72020-12-23 14:36:00 +01002314
LemonBoy9bd3ce22022-04-18 21:54:02 +01002315func Test_prop_find_prev_on_same_line()
2316 new
2317
2318 call setline(1, 'the quikc bronw fox jumsp over the layz dog')
2319 call prop_type_add('misspell', #{highlight: 'ErrorMsg'})
2320 for col in [8, 14, 24, 38]
2321 call prop_add(1, col, #{type: 'misspell', length: 2})
2322 endfor
2323
Ben Jacksona7704222022-08-20 20:54:51 +01002324 call cursor(1, 18)
LemonBoy9bd3ce22022-04-18 21:54:02 +01002325 let expected = [
2326 \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1},
2327 \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}
2328 \ ]
2329
2330 let result = prop_find(#{type: 'misspell'}, 'b')
2331 call assert_equal(expected[0], result)
2332 let result = prop_find(#{type: 'misspell'}, 'f')
2333 call assert_equal(expected[1], result)
2334
2335 call prop_type_delete('misspell')
2336 bwipe!
2337endfunc
2338
LemonBoyb7a70122022-05-13 12:41:50 +01002339func Test_prop_spell()
2340 new
2341 set spell
2342 call AddPropTypes()
2343
2344 call setline(1, ["helo world", "helo helo helo"])
2345 call prop_add(1, 1, #{type: 'one', length: 4})
2346 call prop_add(1, 6, #{type: 'two', length: 5})
2347 call prop_add(2, 1, #{type: 'three', length: 4})
2348 call prop_add(2, 6, #{type: 'three', length: 4})
2349 call prop_add(2, 11, #{type: 'three', length: 4})
2350
2351 " The first prop over 'helo' increases its length after the word is corrected
2352 " to 'Hello', the second one is shifted to the right.
2353 let expected = [
2354 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2355 \ 'length': 5, 'start': 1},
2356 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2357 \ 'length': 5, 'start': 1}
2358 \ ]
2359 call feedkeys("z=1\<CR>", 'xt')
2360
2361 call assert_equal('Hello world', getline(1))
2362 call assert_equal(expected, prop_list(1))
2363
2364 " Repeat the replacement done by z=
2365 spellrepall
2366
2367 let expected = [
2368 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2369 \ 'length': 5, 'start': 1},
2370 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2371 \ 'length': 5, 'start': 1},
2372 \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2373 \ 'length': 5, 'start': 1}
2374 \ ]
2375 call assert_equal('Hello Hello Hello', getline(2))
2376 call assert_equal(expected, prop_list(2))
2377
2378 call DeletePropTypes()
2379 set spell&
2380 bwipe!
2381endfunc
2382
LemonBoy4b936742022-05-13 21:56:28 +01002383func Test_prop_shift_block()
2384 new
2385 call AddPropTypes()
2386
2387 call setline(1, ['some highlighted text']->repeat(2))
2388 call prop_add(1, 10, #{type: 'one', length: 11})
2389 call prop_add(2, 10, #{type: 'two', length: 11})
2390
2391 call cursor(1, 1)
2392 call feedkeys("5l\<c-v>>", 'nxt')
2393 call cursor(2, 1)
2394 call feedkeys("5l\<c-v><", 'nxt')
2395
2396 let expected = [
2397 \ {'lnum': 1, 'id': 0, 'col': 8, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2398 \ 'length': 11, 'start' : 1},
2399 \ {'lnum': 2, 'id': 0, 'col': 6, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2400 \ 'length': 11, 'start' : 1}
2401 \ ]
2402 call assert_equal(expected, prop_list(1, #{end_lnum: 2}))
2403
2404 call DeletePropTypes()
2405 bwipe!
2406endfunc
LemonBoyb7a70122022-05-13 12:41:50 +01002407
LemonBoy698cb4c2022-05-14 18:10:15 +01002408func Test_prop_insert_multiline()
2409 new
2410 call AddPropTypes()
2411
2412 call setline(1, ['foobar', 'barbaz'])
2413 call prop_add(1, 4, #{end_lnum: 2, end_col: 4, type: 'one'})
2414
2415 call feedkeys("1Goquxqux\<Esc>", 'nxt')
2416 call feedkeys("2GOquxqux\<Esc>", 'nxt')
2417
2418 let lines =<< trim END
2419 foobar
2420 quxqux
2421 quxqux
2422 barbaz
2423 END
2424 call assert_equal(lines, getline(1, '$'))
2425 let expected = [
2426 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one',
Ben Jacksona7704222022-08-20 20:54:51 +01002427 \ 'length': 4 , 'start': 1},
LemonBoy698cb4c2022-05-14 18:10:15 +01002428 \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2429 \ 'length': 7, 'start': 0},
2430 \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2431 \ 'length': 7, 'start': 0},
2432 \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2433 \ 'length': 3, 'start': 0}
2434 \ ]
2435 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2436
2437 call DeletePropTypes()
2438 bwipe!
2439endfunc
2440
LemonBoyb559b302022-05-15 13:08:02 +01002441func Test_prop_blockwise_change()
2442 new
2443 call AddPropTypes()
2444
2445 call setline(1, ['foooooo', 'bar', 'baaaaz'])
2446 call prop_add(1, 1, #{end_col: 3, type: 'one'})
2447 call prop_add(2, 1, #{end_col: 3, type: 'two'})
2448 call prop_add(3, 1, #{end_col: 3, type: 'three'})
2449
2450 " Replace the first two columns with '123', since 'start_incl' is false the
2451 " prop is not extended.
2452 call feedkeys("gg\<c-v>2jc123\<Esc>", 'nxt')
2453
2454 let lines =<< trim END
2455 123oooooo
2456 123ar
2457 123aaaaz
2458 END
2459 call assert_equal(lines, getline(1, '$'))
2460 let expected = [
2461 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2462 \ 'length': 1, 'start': 1},
2463 \ {'lnum': 2, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2464 \ 'length': 1, 'start': 1},
2465 \ {'lnum': 3, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1 ,
2466 \ 'type': 'three', 'length': 1, 'start': 1}
2467 \ ]
2468 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2469
2470 call DeletePropTypes()
2471 bwipe!
2472endfunc
2473
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002474func Do_test_props_do_not_affect_byte_offsets(ff, increment)
2475 new
2476 let lcount = 410
2477
2478 " File format affects byte-offset calculations, so make sure it is known.
2479 exec 'setlocal fileformat=' . a:ff
2480
2481 " Fill the buffer with varying length lines. We need a suitably large number
dundargocc57b5bc2022-11-02 13:30:51 +00002482 " to force Vim code through paths where previous error have occurred. This
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002483 " is more 'art' than 'science'.
2484 let text = 'a'
2485 call setline(1, text)
2486 let offsets = [1]
2487 for idx in range(lcount)
2488 call add(offsets, offsets[idx] + len(text) + a:increment)
2489 if (idx % 6) == 0
2490 let text = text . 'a'
2491 endif
2492 call append(line('$'), text)
2493 endfor
2494
2495 " Set a property that spans a few lines to cause Vim's internal buffer code
2496 " to perform a reasonable amount of rearrangement.
2497 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2498 call prop_add(1, 1, {'type': 'one', 'end_lnum': 6, 'end_col': 2})
2499
2500 for idx in range(lcount)
2501 let boff = line2byte(idx + 1)
2502 call assert_equal(offsets[idx], boff, 'Bad byte offset at line ' . (idx + 1))
2503 endfor
2504
2505 call prop_type_delete('one')
2506 bwipe!
2507endfunc
2508
2509func Test_props_do_not_affect_byte_offsets()
2510 call Do_test_props_do_not_affect_byte_offsets('unix', 1)
2511endfunc
2512
2513func Test_props_do_not_affect_byte_offsets_dos()
2514 call Do_test_props_do_not_affect_byte_offsets('dos', 2)
2515endfunc
2516
2517func Test_props_do_not_affect_byte_offsets_editline()
2518 new
2519 let lcount = 410
2520
2521 " File format affects byte-offset calculations, so make sure it is known.
2522 setlocal fileformat=unix
2523
2524 " Fill the buffer with varying length lines. We need a suitably large number
dundargocc57b5bc2022-11-02 13:30:51 +00002525 " to force Vim code through paths where previous error have occurred. This
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002526 " is more 'art' than 'science'.
2527 let text = 'aa'
2528 call setline(1, text)
2529 let offsets = [1]
2530 for idx in range(lcount)
2531 call add(offsets, offsets[idx] + len(text) + 1)
2532 if (idx % 6) == 0
2533 let text = text . 'a'
2534 endif
2535 call append(line('$'), text)
2536 endfor
2537
2538 " Set a property that just covers the first line. When this test was
2539 " developed, this did not trigger a byte-offset error.
2540 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2541 call prop_add(1, 1, {'type': 'one', 'end_lnum': 1, 'end_col': 3})
2542
2543 for idx in range(lcount)
2544 let boff = line2byte(idx + 1)
2545 call assert_equal(offsets[idx], boff,
2546 \ 'Confounding bad byte offset at line ' . (idx + 1))
2547 endfor
2548
2549 " Insert text in the middle of the first line, keeping the property
2550 " unchanged.
2551 :1
2552 normal aHello
2553 for idx in range(1, lcount)
2554 let offsets[idx] = offsets[idx] + 5
2555 endfor
2556
2557 for idx in range(lcount)
2558 let boff = line2byte(idx + 1)
2559 call assert_equal(offsets[idx], boff,
2560 \ 'Bad byte offset at line ' . (idx + 1))
2561 endfor
2562
2563 call prop_type_delete('one')
2564 bwipe!
2565endfunc
2566
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002567func Test_prop_inserts_text()
Drew Vogelea67ba72025-05-07 22:05:17 +02002568 CheckScreendump
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002569 CheckRunVimInTerminal
2570
2571 " Just a basic check for now
2572 let lines =<< trim END
2573 call setline(1, 'insert some text here and other text there and some more text after wrapping')
2574 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2575 call prop_type_add('otherprop', #{highlight: 'Search'})
2576 call prop_type_add('moreprop', #{highlight: 'DiffAdd'})
2577 call prop_add(1, 18, #{type: 'someprop', text: 'SOME '})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002578 call prop_add(1, 38, #{type: 'otherprop', text: "OTHER\t"})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002579 call prop_add(1, 69, #{type: 'moreprop', text: 'MORE '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002580 normal $
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002581
2582 call setline(2, 'prepost')
2583 call prop_type_add('multibyte', #{highlight: 'Visual'})
2584 call prop_add(2, 4, #{type: 'multibyte', text: 'sΓΆmeε’ŒεΉ³tΓ©xt'})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002585
Bram Moolenaar25463612022-08-08 11:07:47 +01002586 call setline(3, 'Foo foo = { 1, 2 };')
Bram Moolenaar3331dd02022-08-10 16:49:02 +01002587 call prop_type_add('testprop', #{highlight: 'Comment'})
Bram Moolenaar25463612022-08-08 11:07:47 +01002588 call prop_add(3, 13, #{type: 'testprop', text: '.x='})
2589 call prop_add(3, 16, #{type: 'testprop', text: '.y='})
2590
2591 call setline(4, '')
2592 call prop_add(4, 1, #{type: 'someprop', text: 'empty line'})
Bram Moolenaar3331dd02022-08-10 16:49:02 +01002593
2594 call setline(5, 'look highlight')
2595 call prop_type_add('nohi', #{})
2596 call prop_add(5, 6, #{type: 'nohi', text: 'no '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002597 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002598 call writefile(lines, 'XscriptPropsWithText', 'D')
Bram Moolenaar25463612022-08-08 11:07:47 +01002599 let buf = RunVimInTerminal('-S XscriptPropsWithText', #{rows: 8, cols: 60})
Bram Moolenaar711483c2022-07-30 21:33:46 +01002600 call VerifyScreenDump(buf, 'Test_prop_inserts_text_1', {})
2601
2602 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2603 call VerifyScreenDump(buf, 'Test_prop_inserts_text_2', {})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002604
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002605 call term_sendkeys(buf, "2G$")
2606 call VerifyScreenDump(buf, 'Test_prop_inserts_text_3', {})
2607
Bram Moolenaar25463612022-08-08 11:07:47 +01002608 call term_sendkeys(buf, "3Gf1")
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002609 call VerifyScreenDump(buf, 'Test_prop_inserts_text_4', {})
Bram Moolenaar25463612022-08-08 11:07:47 +01002610 call term_sendkeys(buf, "f2")
2611 call VerifyScreenDump(buf, 'Test_prop_inserts_text_5', {})
2612
2613 call term_sendkeys(buf, "4G")
2614 call VerifyScreenDump(buf, 'Test_prop_inserts_text_6', {})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002615
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002616 call StopVimInTerminal(buf)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002617endfunc
2618
Bram Moolenaare38fc862022-08-11 17:24:50 +01002619func Test_prop_inserts_text_highlight()
Drew Vogelea67ba72025-05-07 22:05:17 +02002620 CheckScreendump
Bram Moolenaare38fc862022-08-11 17:24:50 +01002621 CheckRunVimInTerminal
2622
2623 " Just a basic check for now
2624 let lines =<< trim END
2625 call setline(1, 'insert some text (here) and there')
2626 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2627 let bef_prop = prop_add(1, 18, #{type: 'someprop', text: 'BEFORE'})
2628 set hlsearch
2629 let thematch = matchaddpos("DiffAdd", [[1, 18]])
2630 func DoAfter()
2631 call prop_remove(#{id: g:bef_prop})
2632 call prop_add(1, 19, #{type: 'someprop', text: 'AFTER'})
2633 let g:thematch = matchaddpos("DiffAdd", [[1, 18]])
2634 let @/ = ''
2635 endfunc
2636 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002637 call writefile(lines, 'XscriptPropsWithHighlight', 'D')
Bram Moolenaare38fc862022-08-11 17:24:50 +01002638 let buf = RunVimInTerminal('-S XscriptPropsWithHighlight', #{rows: 6, cols: 60})
2639 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_1', {})
2640 call term_sendkeys(buf, "/text (he\<CR>")
2641 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_2', {})
2642 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2643 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_3', {})
2644
2645 call term_sendkeys(buf, ":call DoAfter()\<CR>")
2646 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_4', {})
2647 call term_sendkeys(buf, "/text (he\<CR>")
2648 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_5', {})
2649 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2650 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_6', {})
2651
2652 call StopVimInTerminal(buf)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002653endfunc
2654
zeertzjqd809c0a2023-08-27 11:17:39 +02002655func Test_prop_inserts_text_normal_gM()
Drew Vogelea67ba72025-05-07 22:05:17 +02002656 CheckScreendump
zeertzjqd809c0a2023-08-27 11:17:39 +02002657 CheckRunVimInTerminal
2658
2659 let lines =<< trim END
2660 call setline(1, '123456789')
2661 call prop_type_add('theprop', #{highlight: 'Special'})
2662 call prop_add(1, 3, {'type': 'theprop', 'text': 'bbb'})
2663 call prop_add(1, 8, {'type': 'theprop', 'text': 'bbb'})
2664 END
2665 call writefile(lines, 'XscriptPropsNormal_gM', 'D')
2666 let buf = RunVimInTerminal('-S XscriptPropsNormal_gM', #{rows: 3, cols: 60})
2667 call term_sendkeys(buf, "gM")
2668 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gM', {})
2669
2670 call StopVimInTerminal(buf)
2671endfunc
2672
2673func Run_test_prop_inserts_text_normal_gj_gk(cmd)
Drew Vogelea67ba72025-05-07 22:05:17 +02002674 CheckScreendump
zeertzjqd809c0a2023-08-27 11:17:39 +02002675 CheckRunVimInTerminal
2676
2677 let lines =<< trim END
2678 call setline(1, repeat([repeat('a', 55)], 2))
2679 call prop_type_add('theprop', {})
2680 call prop_add(1, 41, {'type': 'theprop', 'text': repeat('b', 10)})
2681 call prop_add(2, 41, {'type': 'theprop', 'text': repeat('b', 10)})
2682 END
2683 let lines = insert(lines, a:cmd)
2684 call writefile(lines, 'XscriptPropsNormal_gj_gk', 'D')
2685 let buf = RunVimInTerminal('-S XscriptPropsNormal_gj_gk', #{rows: 6, cols: 60})
2686 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_1', {})
2687 call term_sendkeys(buf, "gj")
2688 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_2', {})
2689 call term_sendkeys(buf, "gj")
2690 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_3', {})
2691 call term_sendkeys(buf, "gj")
2692 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_4', {})
2693 call term_sendkeys(buf, "gk")
2694 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_5', {})
2695 call term_sendkeys(buf, "gk")
2696 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_6', {})
2697 call term_sendkeys(buf, "gk")
2698 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_7', {})
2699
2700 call StopVimInTerminal(buf)
2701endfunc
2702
2703func Test_prop_inserts_text_normal_gj_gk()
2704 call Run_test_prop_inserts_text_normal_gj_gk('')
2705 call Run_test_prop_inserts_text_normal_gj_gk('set virtualedit=all')
2706endfunc
2707
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002708func Test_prop_normal_gj_gk_gM_with_outer_virtual_text()
Drew Vogelea67ba72025-05-07 22:05:17 +02002709 CheckScreendump
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002710 CheckRunVimInTerminal
2711
2712 let lines =<< trim END
2713 vim9script
2714 setlocal number
2715 setline(1, ['First line fits on screen line.', '', 'Third line fits on screen line.'])
2716
2717 var vt = 'test'
2718 prop_type_add(vt, {highlight: 'ToDo'})
2719 for ln in range(1, line('$'))
2720 prop_add(ln, 0, {type: vt, text: 'Above', text_align: 'above'})
2721 prop_add(ln, 0, {type: vt, text: 'After text wraps to next line.', text_align: 'after', text_wrap: 'wrap'})
2722 prop_add(ln, 0, {type: vt, text: 'Right text wraps to next line.', text_align: 'right', text_wrap: 'wrap'})
2723 prop_add(ln, 0, {type: vt, text: 'Below', text_align: 'below'})
2724 endfor
2725 normal 3l
2726 END
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002727 call writefile(lines, 'XscriptPropsNormal_gj_gk_gM_with_outer_text', 'D')
2728 let buf = RunVimInTerminal('-S XscriptPropsNormal_gj_gk_gM_with_outer_text', #{rows: 16, cols: 40})
2729 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002730
2731 call term_sendkeys(buf, "gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002732 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_2', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002733 call term_sendkeys(buf, "gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002734 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_3', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002735 call term_sendkeys(buf, "gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002736 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_2', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002737 call term_sendkeys(buf, "gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002738 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002739
2740 call term_sendkeys(buf, "2gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002741 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_3', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002742 call term_sendkeys(buf, "2gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002743 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
2744
2745 call term_sendkeys(buf, "gM")
2746 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_4', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002747
2748 call StopVimInTerminal(buf)
2749endfunc
2750
zeertzjq6e940d92023-08-17 23:21:40 +02002751func Test_prop_inserts_text_visual_block()
Drew Vogelea67ba72025-05-07 22:05:17 +02002752 CheckScreendump
zeertzjq6e940d92023-08-17 23:21:40 +02002753 CheckRunVimInTerminal
2754
2755 let lines =<< trim END
zeertzjqfc305842023-08-19 13:27:03 +02002756 call setline(1, repeat(['123456789'], 4))
zeertzjq6e940d92023-08-17 23:21:40 +02002757 call prop_type_add('theprop', #{highlight: 'Special'})
2758 call prop_add(2, 2, {'type': 'theprop', 'text': '-口-'})
zeertzjqfc305842023-08-19 13:27:03 +02002759 call prop_add(3, 3, {'type': 'theprop', 'text': '口'})
zeertzjq6e940d92023-08-17 23:21:40 +02002760 END
2761 call writefile(lines, 'XscriptPropsVisualBlock', 'D')
2762 let buf = RunVimInTerminal('-S XscriptPropsVisualBlock', #{rows: 6, cols: 60})
2763 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_1', {})
zeertzjqfc305842023-08-19 13:27:03 +02002764 call term_sendkeys(buf, "\<C-V>3jl")
zeertzjq6e940d92023-08-17 23:21:40 +02002765 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_2', {})
2766 call term_sendkeys(buf, "l")
2767 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_3', {})
2768 call term_sendkeys(buf, "4l")
2769 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_4', {})
2770 call term_sendkeys(buf, "Ol")
2771 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_5', {})
2772 call term_sendkeys(buf, "l")
2773 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_6', {})
2774 call term_sendkeys(buf, "l")
2775 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_7', {})
2776
2777 call StopVimInTerminal(buf)
2778endfunc
2779
zeertzjqb557f482023-08-22 22:07:34 +02002780func Run_test_prop_inserts_text_showbreak(cmd)
Drew Vogelea67ba72025-05-07 22:05:17 +02002781 CheckScreendump
zeertzjqb557f482023-08-22 22:07:34 +02002782 CheckRunVimInTerminal
2783
2784 let lines =<< trim END
2785 highlight! link LineNr Normal
zeertzjq6a389722023-08-27 19:04:14 +02002786 setlocal number showbreak=+ breakindent breakindentopt=shift:2
2787 setlocal scrolloff=0 smoothscroll
zeertzjqb557f482023-08-22 22:07:34 +02002788 call setline(1, repeat('a', 28))
2789 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002790 call prop_add(1, 28, #{type: 'theprop', text: repeat('123', 23)})
zeertzjqb557f482023-08-22 22:07:34 +02002791 normal! $
2792 END
2793 let lines = insert(lines, a:cmd)
2794 call writefile(lines, 'XscriptPropsShowbreak', 'D')
2795 let buf = RunVimInTerminal('-S XscriptPropsShowbreak', #{rows: 6, cols: 30})
2796 call term_sendkeys(buf, ":set noruler\<CR>")
2797 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_1', {})
2798 call term_sendkeys(buf, "\<C-E>")
2799 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_2', {})
2800 call term_sendkeys(buf, "\<C-E>")
2801 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_3', {})
2802 call term_sendkeys(buf, "\<C-E>")
2803 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_4', {})
2804 call term_sendkeys(buf, "\<C-E>")
2805 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_5', {})
2806 call term_sendkeys(buf, "zbi")
2807 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_6', {})
2808 call term_sendkeys(buf, "\<BS>")
2809 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_7', {})
2810 call term_sendkeys(buf, "\<Esc>l")
2811 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_8', {})
2812 call term_sendkeys(buf, "\<C-E>")
2813 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_9', {})
2814 call term_sendkeys(buf, "\<C-E>")
2815 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_10', {})
2816 call term_sendkeys(buf, "\<C-E>")
2817 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_11', {})
2818 call term_sendkeys(buf, "\<C-E>")
2819 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_12', {})
2820 call term_sendkeys(buf, "023x$")
2821 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_13', {})
2822 call term_sendkeys(buf, "\<C-E>")
2823 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_14', {})
2824 call term_sendkeys(buf, "\<C-E>")
2825 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_15', {})
2826 call term_sendkeys(buf, "\<C-E>")
2827 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_16', {})
2828 call term_sendkeys(buf, "zbi")
2829 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_17', {})
2830 call term_sendkeys(buf, "\<C-U>")
2831 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_18', {})
2832 call term_sendkeys(buf, "\<Esc>")
2833 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_19', {})
2834 call term_sendkeys(buf, "\<C-E>")
2835 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_20', {})
2836 call term_sendkeys(buf, "\<C-E>")
2837 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_21', {})
zeertzjq11939512023-08-23 20:58:01 +02002838 call term_sendkeys(buf, "zbx")
2839 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_22', {})
zeertzjq6a389722023-08-27 19:04:14 +02002840 call term_sendkeys(buf, "26ia\<Esc>a")
2841 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_23', {})
2842 call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal breakindentopt=\<CR>")
2843 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_24', {})
zeertzjqb557f482023-08-22 22:07:34 +02002844
2845 call StopVimInTerminal(buf)
2846endfunc
2847
2848func Test_prop_inserts_text_showbreak()
2849 call Run_test_prop_inserts_text_showbreak('')
2850 " because of 'breakindent' the screendumps are the same
2851 call Run_test_prop_inserts_text_showbreak('set cpoptions+=n')
2852endfunc
2853
2854func Test_prop_before_tab_skipcol()
Drew Vogelea67ba72025-05-07 22:05:17 +02002855 CheckScreendump
zeertzjqb557f482023-08-22 22:07:34 +02002856 CheckRunVimInTerminal
2857
2858 let lines =<< trim END
zeertzjq6a389722023-08-27 19:04:14 +02002859 setlocal list listchars=tab:<-> scrolloff=0 smoothscroll
zeertzjqb557f482023-08-22 22:07:34 +02002860 call setline(1, repeat("\t", 4) .. 'a')
2861 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002862 call prop_add(1, 4, #{type: 'theprop', text: repeat('12', 32)})
zeertzjqb557f482023-08-22 22:07:34 +02002863 normal! $
2864 END
2865 call writefile(lines, 'XscriptPropsBeforeTabSkipcol', 'D')
2866 let buf = RunVimInTerminal('-S XscriptPropsBeforeTabSkipcol', #{rows: 6, cols: 30})
2867 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_1', {})
2868 call term_sendkeys(buf, "\<C-E>")
2869 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_2', {})
2870 call term_sendkeys(buf, "\<C-E>")
2871 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_3', {})
2872 call term_sendkeys(buf, "\<C-E>")
2873 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_4', {})
2874 call term_sendkeys(buf, "zbh")
2875 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_5', {})
2876 call term_sendkeys(buf, "i")
2877 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_6', {})
2878 call term_sendkeys(buf, "\<C-O>:setlocal nolist\<CR>")
2879 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_7', {})
2880 call term_sendkeys(buf, "\<Esc>l")
2881 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_8', {})
2882 call term_sendkeys(buf, "\<C-E>")
2883 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_9', {})
2884 call term_sendkeys(buf, "\<C-E>")
2885 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_10', {})
2886 call term_sendkeys(buf, "\<C-E>")
2887 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_11', {})
2888
2889 call StopVimInTerminal(buf)
2890endfunc
2891
zeertzjq6e55e852023-08-30 16:55:09 +02002892func Test_prop_inserts_text_before_linebreak()
Drew Vogelea67ba72025-05-07 22:05:17 +02002893 CheckScreendump
zeertzjq6e55e852023-08-30 16:55:09 +02002894 CheckRunVimInTerminal
2895
2896 let lines =<< trim END
2897 setlocal linebreak showbreak=+ breakindent breakindentopt=shift:2
2898 call setline(1, repeat('a', 50) .. ' ' .. repeat('c', 45))
2899 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002900 call prop_add(1, 51, #{type: 'theprop', text: repeat('b', 10)})
zeertzjq6e55e852023-08-30 16:55:09 +02002901 normal! $
2902 END
2903 call writefile(lines, 'XscriptPropsBeforeLinebreak', 'D')
2904 let buf = RunVimInTerminal('-S XscriptPropsBeforeLinebreak', #{rows: 6, cols: 50})
2905 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_linebreak_1', {})
2906 call term_sendkeys(buf, '05x$')
2907 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_linebreak_2', {})
2908
2909 call StopVimInTerminal(buf)
2910endfunc
2911
zeertzjqac2d8812023-08-31 18:07:30 +02002912func Test_prop_inserts_text_before_double_width_wrap()
Drew Vogelea67ba72025-05-07 22:05:17 +02002913 CheckScreendump
zeertzjqac2d8812023-08-31 18:07:30 +02002914 CheckRunVimInTerminal
2915
2916 let lines =<< trim END
2917 call setline(1, repeat('a', 40) .. '口' .. '12345')
2918 call prop_type_add('theprop', #{highlight: 'Special'})
2919 call prop_add(1, 41, #{type: 'theprop', text: repeat('b', 9)})
2920 normal! $
2921 END
2922 call writefile(lines, 'XscriptPropsBeforeDoubleWidthWrap', 'D')
2923 let buf = RunVimInTerminal('-S XscriptPropsBeforeDoubleWidthWrap', #{rows: 3, cols: 50})
2924 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_1', {})
zeertzjqb5d6b5c2024-07-18 21:13:31 +02002925 call term_sendkeys(buf, 'g0')
2926 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_2', {})
2927 call term_sendkeys(buf, ":set showbreak=+++\<CR>")
2928 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_3', {})
zeertzjqac2d8812023-08-31 18:07:30 +02002929
2930 call StopVimInTerminal(buf)
2931endfunc
2932
zeertzjq6a389722023-08-27 19:04:14 +02002933func Test_prop_inserts_text_lcs_extends()
Drew Vogelea67ba72025-05-07 22:05:17 +02002934 CheckScreendump
zeertzjq6a389722023-08-27 19:04:14 +02002935 CheckRunVimInTerminal
2936
2937 let lines =<< trim END
2938 setlocal nowrap list listchars=extends:!
2939 call setline(1, repeat('a', &columns + 1))
2940 call prop_type_add('theprop', #{highlight: 'Special'})
2941 call prop_add(1, &columns + 2, #{type: 'theprop', text: 'bbb'})
2942 END
2943 call writefile(lines, 'XscriptPropsListExtends', 'D')
2944 let buf = RunVimInTerminal('-S XscriptPropsListExtends', #{rows: 3, cols: 50})
2945 call term_sendkeys(buf, '20l')
2946 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_1', {})
2947 call term_sendkeys(buf, 'zl')
2948 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_2', {})
2949 call term_sendkeys(buf, 'zl')
2950 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_3', {})
2951 call term_sendkeys(buf, 'zl')
2952 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_4', {})
2953 call term_sendkeys(buf, 'zl')
2954 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_5', {})
2955
2956 call StopVimInTerminal(buf)
2957endfunc
2958
Bram Moolenaarfb593c52022-09-17 18:57:36 +01002959func Test_prop_add_with_text_fails()
2960 call prop_type_add('failing', #{highlight: 'ErrorMsg'})
2961 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_lnum: 1})", 'E1305:')
2962 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_col: 1})", 'E1305:')
2963 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', length: 1})", 'E1305:')
2964
2965 call prop_type_delete('failing')
2966endfunc
2967
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002968func Test_props_with_text_right_align_twice()
Drew Vogelea67ba72025-05-07 22:05:17 +02002969 CheckScreendump
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002970 CheckRunVimInTerminal
2971
2972 let lines =<< trim END
2973 call setline(1, ["some text some text some text some text", 'line two'])
Bram Moolenaarfb593c52022-09-17 18:57:36 +01002974 call prop_type_add('MyErrorText', #{highlight: 'ErrorMsg'})
2975 call prop_type_add('MyPadding', #{highlight: 'DiffChange'})
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002976 call prop_add(1, 0, #{type: 'MyPadding', text: ' nothing here', text_wrap: 'wrap'})
2977 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Some error', text_wrap: 'wrap', text_align: 'right'})
2978 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Another error', text_wrap: 'wrap', text_align: 'right'})
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002979 normal G$
2980 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002981 call writefile(lines, 'XscriptPropsRightAlign', 'D')
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002982 let buf = RunVimInTerminal('-S XscriptPropsRightAlign', #{rows: 8})
2983 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_1', {})
2984
2985 call term_sendkeys(buf, "ggisome more text\<Esc>G$")
2986 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {})
2987
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002988 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2989 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_3', {})
2990
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002991 call StopVimInTerminal(buf)
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002992endfunc
2993
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002994func Test_props_with_text_after()
Drew Vogelea67ba72025-05-07 22:05:17 +02002995 CheckScreendump
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002996 CheckRunVimInTerminal
2997
2998 let lines =<< trim END
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002999 set showbreak=+++
Bram Moolenaar73c38422022-08-07 11:53:40 +01003000 set breakindent
3001 call setline(1, ' some text here and other text there')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003002 call prop_type_add('rightprop', #{highlight: 'ErrorMsg'})
3003 call prop_type_add('afterprop', #{highlight: 'Search'})
3004 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
3005 call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'})
Bram Moolenaar783ef722022-08-01 16:11:06 +01003006 call prop_add(1, 0, #{type: 'afterprop', text: "\tAFTER\t", text_align: 'after'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003007 call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'})
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01003008 call prop_add(1, 0, #{type: 'belowprop', text: ' ALSO BELOW ', text_align: 'below'})
Bram Moolenaar84b247f2022-08-01 11:17:40 +01003009
3010 call setline(2, 'Last line.')
3011 call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'})
3012 normal G$
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01003013
3014 call setline(3, 'right here')
3015 call prop_add(3, 0, #{type: 'rightprop', text: 'sΓΆmeε’ŒεΉ³tΓ©xt', text_align: 'right'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003016 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003017 call writefile(lines, 'XscriptPropsWithTextAfter', 'D')
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01003018 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003019 call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {})
3020
3021 call StopVimInTerminal(buf)
Bram Moolenaar82b14c12022-08-10 19:50:47 +01003022
3023 call assert_fails('call prop_add(1, 2, #{text: "yes", text_align: "right", type: "some"})', 'E1294:')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003024endfunc
3025
Bram Moolenaar877151b2022-10-11 15:29:50 +01003026func Test_props_with_text_after_and_list()
Drew Vogelea67ba72025-05-07 22:05:17 +02003027 CheckScreendump
Bram Moolenaar877151b2022-10-11 15:29:50 +01003028 CheckRunVimInTerminal
3029
3030 let lines =<< trim END
3031 vim9script
3032 setline(1, ['one', 'two'])
3033 prop_type_add('test', {highlight: 'Special'})
3034 prop_add(1, 0, {
3035 type: 'test',
3036 text: range(50)->join(' '),
3037 text_align: 'after',
3038 text_padding_left: 3
3039 })
3040 prop_add(1, 0, {
3041 type: 'test',
3042 text: range(50)->join('-'),
3043 text_align: 'after',
3044 text_padding_left: 5
3045 })
3046 prop_add(1, 0, {
3047 type: 'test',
3048 text: range(50)->join('.'),
3049 text_align: 'after',
3050 text_padding_left: 1
3051 })
3052 normal G$
3053 END
3054 call writefile(lines, 'XscriptPropsAfter', 'D')
3055 let buf = RunVimInTerminal('-S XscriptPropsAfter', #{rows: 8, cols: 60})
3056 call VerifyScreenDump(buf, 'Test_props_after_1', {})
3057
3058 call term_sendkeys(buf, ":set list\<CR>")
3059 call VerifyScreenDump(buf, 'Test_props_after_2', {})
3060
3061 call StopVimInTerminal(buf)
3062endfunc
3063
Bram Moolenaarcba69522022-08-06 21:03:53 +01003064func Test_props_with_text_after_below_trunc()
Drew Vogelea67ba72025-05-07 22:05:17 +02003065 CheckScreendump
Bram Moolenaarcba69522022-08-06 21:03:53 +01003066 CheckRunVimInTerminal
3067
3068 let lines =<< trim END
3069 vim9script
3070 edit foobar
3071 set showbreak=+++
3072 setline(1, ['onasdf asdf asdf asdf asd fas df', 'two'])
3073 prop_type_add('test', {highlight: 'Special'})
3074 prop_add(1, 0, {
3075 type: 'test',
3076 text: 'the quick brown fox jumps over the lazy dog',
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003077 text_align: 'after',
Bram Moolenaarcba69522022-08-06 21:03:53 +01003078 })
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003079 prop_type_add('another', {highlight: 'DiffChange'})
Bram Moolenaarcba69522022-08-06 21:03:53 +01003080 prop_add(1, 0, {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003081 type: 'another',
Bram Moolenaarcba69522022-08-06 21:03:53 +01003082 text: 'the quick brown fox jumps over the lazy dog',
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003083 text_align: 'below',
3084 text_padding_left: 4,
Bram Moolenaarcba69522022-08-06 21:03:53 +01003085 })
3086 normal G$
3087 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003088 call writefile(lines, 'XscriptPropsAfterTrunc', 'D')
Bram Moolenaarcba69522022-08-06 21:03:53 +01003089 let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60})
3090 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {})
3091
Bram Moolenaarccf28372022-10-10 21:10:03 +01003092 call term_sendkeys(buf, ":set number\<CR>")
3093 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_2', {})
3094
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003095 call term_sendkeys(buf, ":set cursorline\<CR>gg")
3096 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_3', {})
3097
Bram Moolenaarcba69522022-08-06 21:03:53 +01003098 call StopVimInTerminal(buf)
Bram Moolenaarcba69522022-08-06 21:03:53 +01003099endfunc
3100
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003101func Test_props_with_text_truncated_just_before_after()
Drew Vogelea67ba72025-05-07 22:05:17 +02003102 CheckScreendump
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003103 CheckRunVimInTerminal
3104
3105 let lines =<< trim END
3106 vim9script
3107 set showbreak=+++
3108 set list listchars=extends:>
3109 set nowrap
3110
3111 setline(1, [
3112 'here is text long enough to fill the row',
3113 'second line',
3114 ])
3115
3116 prop_type_add("test", {"highlight": "Error"})
Dylan Thacker-Smith515f7342024-03-28 12:01:14 +01003117 prop_add(1, 0, {type: "test", text_align: "right", text: "right text"})
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003118 def g:AddPropBelow()
3119 prop_add(1, 0, {type: "test", text_align: "below", text: "below text"})
3120 enddef
Dylan Thacker-Smith515f7342024-03-28 12:01:14 +01003121 def g:AddPropAfter()
3122 prop_add(1, 0, {type: "test", text: "after text", text_padding_left: 1})
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003123 enddef
3124 normal G$
3125 END
3126 call writefile(lines, 'XscriptPropsWithTextTruncatedJustBeforeAfter', 'D')
3127 let buf = RunVimInTerminal('-S XscriptPropsWithTextTruncatedJustBeforeAfter', #{rows: 8, cols: 40})
3128 call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_1', {})
3129
3130 call term_sendkeys(buf, ":call AddPropBelow()\<CR>")
3131 call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_2', {})
3132
Dylan Thacker-Smith515f7342024-03-28 12:01:14 +01003133 call term_sendkeys(buf, ":call AddPropAfter()\<CR>:\<Esc>")
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01003134 call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_2', {})
3135
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003136 call StopVimInTerminal(buf)
3137endfunc
3138
porygonisaduck38854b52022-11-27 20:55:05 +00003139func Test_prop_with_text_below_after_empty()
Drew Vogelea67ba72025-05-07 22:05:17 +02003140 CheckScreendump
porygonisaduck38854b52022-11-27 20:55:05 +00003141 CheckRunVimInTerminal
3142
3143 let lines =<< trim END
3144 vim9script
Bram Moolenaar94722c52023-01-28 19:19:03 +00003145
porygonisaduck38854b52022-11-27 20:55:05 +00003146 setline(1, ['vim9script', '', 'three', ''])
3147
3148 # Add text prop below empty line 2 with padding.
3149 prop_type_add('test', {highlight: 'ErrorMsg'})
3150 prop_add(2, 0, {
3151 type: 'test',
3152 text: 'The quick brown fox jumps over the lazy dog',
3153 text_align: 'below',
3154 text_padding_left: 1,
3155 })
3156
3157 # Add text prop below empty line 4 without padding.
3158 prop_type_add('other', {highlight: 'DiffChange'})
3159 prop_add(4, 0, {
3160 type: 'other',
3161 text: 'The slow fox bumps into the lazy dog',
3162 text_align: 'below',
3163 text_padding_left: 0,
3164 })
3165 END
3166 call writefile(lines, 'XscriptPropBelowAfterEmpty', 'D')
3167 let buf = RunVimInTerminal('-S XscriptPropBelowAfterEmpty', #{rows: 8, cols: 60})
Bram Moolenaar94722c52023-01-28 19:19:03 +00003168 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_1', {})
porygonisaduck38854b52022-11-27 20:55:05 +00003169
Bram Moolenaar7c02ad92022-11-29 21:37:13 +00003170 call term_sendkeys(buf, ":set number\<CR>")
Bram Moolenaar94722c52023-01-28 19:19:03 +00003171 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_2', {})
Bram Moolenaar7c02ad92022-11-29 21:37:13 +00003172
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003173 call term_sendkeys(buf, ":set nowrap\<CR>")
Bram Moolenaar94722c52023-01-28 19:19:03 +00003174 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_3', {})
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003175
porygonisaduck38854b52022-11-27 20:55:05 +00003176 call StopVimInTerminal(buf)
3177endfunc
3178
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003179func Test_prop_with_text_above_below_empty()
Drew Vogelea67ba72025-05-07 22:05:17 +02003180 CheckScreendump
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003181 CheckRunVimInTerminal
3182
3183 let lines =<< trim END
3184 setlocal number
3185 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3186
3187 let vt = 'test'
3188 call prop_type_add(vt, {'highlight': 'ToDo'})
3189 for ln in range(1, line('$'))
Dylan Thacker-Smithda0c9132024-02-27 20:25:10 +01003190 " use 1 character text to test for off-by-one regressions
3191 call prop_add(ln, 0, {'type': vt, 'text': '-', 'text_align': 'above'})
3192 call prop_add(ln, 0, {'type': vt, 'text': '+', 'text_align': 'below'})
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003193 endfor
3194 normal G
zeertzjq918b92b2024-03-20 19:49:20 +01003195
3196 func AddMore()
3197 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3198 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3199 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3200 endfunc
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003201 END
3202 call writefile(lines, 'XscriptPropAboveBelowEmpty', 'D')
3203 let buf = RunVimInTerminal('-S XscriptPropAboveBelowEmpty', #{rows: 16, cols: 60})
3204 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_1', {})
3205
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003206 call term_sendkeys(buf, ":set list\<CR>")
3207 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_2', {})
3208
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003209 call term_sendkeys(buf, ":set nolist\<CR>")
3210 call term_sendkeys(buf, ":set colorcolumn=10\<CR>")
3211 call term_sendkeys(buf, ":\<CR>")
3212 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_3', {})
3213
Bram Moolenaara572b932023-02-19 14:34:37 +00003214 call term_sendkeys(buf, ":set colorcolumn=\<CR>")
3215 call term_sendkeys(buf, ":set relativenumber\<CR>")
3216 call term_sendkeys(buf, ":\<CR>")
3217 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_4', {})
3218
3219 call term_sendkeys(buf, "kk")
3220 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_5', {})
3221
zeertzjq918b92b2024-03-20 19:49:20 +01003222 " This was drawing line number over cmdline and leaking memory.
3223 call term_sendkeys(buf, ":call AddMore()\<CR>")
3224 call term_sendkeys(buf, "gg")
3225 call term_sendkeys(buf, "j")
3226 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_6', {})
3227
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003228 call StopVimInTerminal(buf)
3229endfunc
3230
Matthias2c9f49b2025-03-16 19:27:51 +01003231func Test_prop_multiple_lines_above()
Drew Vogelea67ba72025-05-07 22:05:17 +02003232 CheckScreendump
Matthias2c9f49b2025-03-16 19:27:51 +01003233 CheckRunVimInTerminal
3234
3235 let lines =<< trim END
3236 setlocal number colorcolumn=10
3237 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3238
3239 let vt = 'test'
3240 call prop_type_add(vt, {'highlight': 'ToDo'})
3241 for ln in range(1, line('$'))
3242 call prop_add(ln, 0, {'type': vt, 'text': 'above1', 'text_align': 'above'})
3243 call prop_add(ln, 0, {'type': vt, 'text': 'above2', 'text_align': 'above'})
3244 endfor
3245 normal G
3246 END
3247 call writefile(lines, 'XscriptPropMultipleLinesAbove', 'D')
3248 let buf = RunVimInTerminal('-S XscriptPropMultipleLinesAbove', #{rows: 16, cols: 60})
3249 call VerifyScreenDump(buf, 'Test_prop_multiple_lines_above_1', {})
3250
3251 call StopVimInTerminal(buf)
3252endfunc
3253
zeertzjq91d26aa2024-10-27 19:23:34 +01003254func Test_prop_with_multibyte_above()
Drew Vogelea67ba72025-05-07 22:05:17 +02003255 CheckScreendump
zeertzjq91d26aa2024-10-27 19:23:34 +01003256 CheckRunVimInTerminal
3257
3258 let lines =<< trim END
3259 setlocal number colorcolumn=10
3260 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3261
3262 let vt = 'test'
3263 call prop_type_add(vt, {'highlight': 'ToDo'})
3264 for ln in range(1, line('$'))
3265 call prop_add(ln, 0, {'type': vt, 'text': '…', 'text_align': 'above'})
3266 endfor
3267 normal G
3268 END
3269 call writefile(lines, 'XscriptPropMultibyteAbove', 'D')
3270 let buf = RunVimInTerminal('-S XscriptPropMultibyteAbove', #{rows: 16, cols: 60})
3271 call VerifyScreenDump(buf, 'Test_prop_multibyte_above_1', {})
3272
3273 call StopVimInTerminal(buf)
3274endfunc
3275
Bram Moolenaarea62cee2023-02-19 18:36:41 +00003276func Test_prop_with_multibyte_below()
Drew Vogelea67ba72025-05-07 22:05:17 +02003277 CheckScreendump
Bram Moolenaarea62cee2023-02-19 18:36:41 +00003278 CheckRunVimInTerminal
3279
3280 let lines =<< trim END
3281 setlocal number
3282 call setline(1, ['Β©', 'Β©', 'Β©'])
3283
3284 let vt = 'test'
3285 call prop_type_add(vt, {'highlight': 'ToDo'})
3286 for ln in range(1, line('$'))
3287 call prop_add(ln, 0, {'type': vt, 'text': '+++', 'text_align': 'below'})
3288 endfor
3289 normal G
3290 END
3291 call writefile(lines, 'XscriptPropMultibyteBelow', 'D')
3292 let buf = RunVimInTerminal('-S XscriptPropMultibyteBelow', #{rows: 10, cols: 60})
3293 call VerifyScreenDump(buf, 'Test_prop_multibyte_below_1', {})
3294
3295 call StopVimInTerminal(buf)
3296endfunc
3297
zeertzjq6b9c2022023-09-11 20:01:17 +02003298func Test_prop_with_text_below_rightleft()
Drew Vogelea67ba72025-05-07 22:05:17 +02003299 CheckScreendump
zeertzjq6b9c2022023-09-11 20:01:17 +02003300 CheckRunVimInTerminal
3301 CheckFeature rightleft
3302
3303 let lines =<< trim END
3304 setlocal number rightleft
3305 call setline(1, 'abcde')
3306 call prop_type_add('theprop', #{highlight: 'Special'})
3307 call prop_add(1, 0, #{type: 'theprop', text: '12345', text_align: 'below'})
3308 END
3309 call writefile(lines, 'XscriptPropBelowRightleft', 'D')
3310 let buf = RunVimInTerminal('-S XscriptPropBelowRightleft', #{rows: 6, cols: 60})
3311 call VerifyScreenDump(buf, 'Test_prop_below_rightleft_1', {})
3312
3313 call StopVimInTerminal(buf)
3314endfunc
3315
Bram Moolenaar5ceb8152023-02-12 18:11:21 +00003316func Test_prop_with_text_above_empty()
Drew Vogelea67ba72025-05-07 22:05:17 +02003317 CheckScreendump
Bram Moolenaar5ceb8152023-02-12 18:11:21 +00003318 CheckRunVimInTerminal
3319
3320 " check the cursor is in the correct line
3321 let lines =<< trim END
3322 setlocal number
3323 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3324
3325 let vt = 'test'
3326 call prop_type_add(vt, {'highlight': 'ToDo'})
3327 for ln in range(1, line('$'))
3328 call prop_add(ln, 0, {'type': vt, 'text': '---', 'text_align': 'above'})
3329 endfor
3330 normal G
3331 END
3332 call writefile(lines, 'XscriptPropAboveEmpty', 'D')
3333 let buf = RunVimInTerminal('-S XscriptPropAboveEmpty', #{rows: 16, cols: 60})
3334 call VerifyScreenDump(buf, 'Test_prop_above_empty_1', {})
3335
3336 call term_sendkeys(buf, ":set list\<CR>")
3337 call VerifyScreenDump(buf, 'Test_prop_above_empty_2', {})
3338
3339 call StopVimInTerminal(buf)
3340endfunc
3341
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003342func Test_prop_with_text_below_after_match()
Drew Vogelea67ba72025-05-07 22:05:17 +02003343 CheckScreendump
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003344 CheckRunVimInTerminal
3345
3346 let lines =<< trim END
3347 vim9script
3348
3349 setline(1, ['vim9script', 'some text'])
3350 set signcolumn=yes
3351 matchaddpos('Search', [[1, 10]])
3352 prop_type_add('test', {highlight: 'Error'})
3353 prop_add(1, 0, {
3354 type: 'test',
3355 text: 'The quick brown fox',
3356 text_align: 'below'
3357 })
3358 END
3359 call writefile(lines, 'XscriptPropsBelow', 'D')
3360 let buf = RunVimInTerminal('-S XscriptPropsBelow', #{rows: 8, cols: 60})
3361 call VerifyScreenDump(buf, 'Test_prop_with_text_below_after_match_1', {})
3362
3363 call StopVimInTerminal(buf)
3364endfunc
3365
Bram Moolenaare175dc62022-08-01 22:18:50 +01003366func Test_props_with_text_after_joined()
Drew Vogelea67ba72025-05-07 22:05:17 +02003367 CheckScreendump
Bram Moolenaare175dc62022-08-01 22:18:50 +01003368 CheckRunVimInTerminal
3369
3370 let lines =<< trim END
3371 call setline(1, ['one', 'two', 'three', 'four'])
3372 call prop_type_add('afterprop', #{highlight: 'Search'})
3373 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'})
3374 call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'})
3375 normal ggJ
3376 normal GkJ
3377
3378 call setline(3, ['a', 'b', 'c', 'd', 'e', 'f'])
3379 call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'})
3380 call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'})
3381 call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'})
3382 call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'})
3383 normal 3G6J
3384 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003385 call writefile(lines, 'XscriptPropsWithTextAfterJoined', 'D')
Bram Moolenaare175dc62022-08-01 22:18:50 +01003386 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60})
3387 call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {})
3388
3389 call StopVimInTerminal(buf)
Bram Moolenaare175dc62022-08-01 22:18:50 +01003390endfunc
3391
Bram Moolenaar398649e2022-08-04 15:03:48 +01003392func Test_props_with_text_after_truncated()
Drew Vogelea67ba72025-05-07 22:05:17 +02003393 CheckScreendump
Bram Moolenaar398649e2022-08-04 15:03:48 +01003394 CheckRunVimInTerminal
3395
3396 let lines =<< trim END
3397 call setline(1, ['one two three four five six seven'])
3398 call prop_type_add('afterprop', #{highlight: 'Search'})
3399 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3400
3401 call setline(2, ['one two three four five six seven'])
3402 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3403
3404 call setline(3, ['one two three four five six seven'])
3405 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'})
3406
3407 call setline(4, ['cursor here'])
3408 normal 4Gfh
3409 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003410 call writefile(lines, 'XscriptPropsWithTextAfterTrunc', 'D')
Bram Moolenaar398649e2022-08-04 15:03:48 +01003411 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60})
3412 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {})
3413
3414 call term_sendkeys(buf, ":37vsp\<CR>gg")
3415 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {})
3416
3417 call term_sendkeys(buf, ":36wincmd |\<CR>")
3418 call term_sendkeys(buf, "2G$")
3419 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {})
3420
3421 call term_sendkeys(buf, ":33wincmd |\<CR>")
3422 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {})
3423
3424 call term_sendkeys(buf, ":18wincmd |\<CR>")
3425 call term_sendkeys(buf, "0fx")
3426 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {})
3427
3428 call StopVimInTerminal(buf)
Bram Moolenaar398649e2022-08-04 15:03:48 +01003429endfunc
3430
h-east4c42c7e2023-04-17 21:44:57 +01003431func Test_props_with_text_after_truncated_and_ambiwidth_is_double()
Drew Vogelea67ba72025-05-07 22:05:17 +02003432 CheckScreendump
h-east4c42c7e2023-04-17 21:44:57 +01003433 CheckRunVimInTerminal
3434
3435 let lines =<< trim END
3436 set ambiwidth=double
3437 call setline(1, ['one two three four five six seven'])
3438 call prop_type_add('afterprop', #{highlight: 'Search'})
3439 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3440
3441 call setline(2, ['one two three four five six seven'])
3442 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3443
3444 call setline(3, ['one two three four five six seven'])
3445 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'})
3446
3447 call setline(4, ['cursor here'])
3448 normal 4Gfh
3449 END
3450 call writefile(lines, 'XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', 'D')
3451 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', #{rows: 9, cols: 60})
3452 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_ambiw_d_1', {})
3453
3454 call StopVimInTerminal(buf)
3455endfunc
3456
3457
3458func Test_props_with_text_after_truncated_not_utf8()
Drew Vogelea67ba72025-05-07 22:05:17 +02003459 CheckScreendump
h-east4c42c7e2023-04-17 21:44:57 +01003460 CheckRunVimInTerminal
3461
3462 let lines =<< trim END
3463 set enc=cp932 tenc=utf-8
3464 call setline(1, ['one two three four five six seven'])
3465 call prop_type_add('afterprop', #{highlight: 'Search'})
3466 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3467
3468 call setline(2, ['one two three four five six seven'])
3469 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3470
3471 call setline(3, ['one two three four five six seven'])
3472 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'})
3473
3474 call setline(4, ['cursor here'])
3475 normal 4Gfh
3476 END
3477 call writefile(lines, 'XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', 'D')
3478 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', #{rows: 9, cols: 60})
3479 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_not_utf8', {})
3480
3481 call StopVimInTerminal(buf)
3482endfunc
3483
Bram Moolenaar49a90792022-08-09 18:25:23 +01003484func Test_props_with_text_empty_line()
Drew Vogelea67ba72025-05-07 22:05:17 +02003485 CheckScreendump
Bram Moolenaar49a90792022-08-09 18:25:23 +01003486 CheckRunVimInTerminal
3487
3488 let lines =<< trim END
3489 call setline(1, ['', 'aaa', '', 'bbbbbb'])
3490 call prop_type_add('prop1', #{highlight: 'Search'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02003491 call prop_add(1, 1, #{type: 'prop1', text: repeat('X', &columns)})
3492 call prop_add(3, 1, #{type: 'prop1', text: repeat('X', &columns + 1)})
Bram Moolenaar49a90792022-08-09 18:25:23 +01003493 normal gg0
3494 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003495 call writefile(lines, 'XscriptPropsWithTextEmptyLine', 'D')
Bram Moolenaar49a90792022-08-09 18:25:23 +01003496 let buf = RunVimInTerminal('-S XscriptPropsWithTextEmptyLine', #{rows: 8, cols: 60})
3497 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_1', {})
3498 call term_sendkeys(buf, "$")
3499 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_2', {})
3500 call term_sendkeys(buf, "j")
3501 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_3', {})
3502 call term_sendkeys(buf, "j")
3503 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_4', {})
3504 call term_sendkeys(buf, "j")
3505 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_5', {})
zeertzjqe3daa062023-08-27 19:11:46 +02003506 call term_sendkeys(buf, "0\<C-V>2l2k")
3507 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_6', {})
3508 call term_sendkeys(buf, "\<Esc>/aaa\\n\\%V\<CR>")
3509 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_7', {})
3510 call term_sendkeys(buf, "3ggic")
3511 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_8', {})
3512 call term_sendkeys(buf, "\<Esc>/aaa\\nc\\%V\<CR>")
3513 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_9', {})
Bram Moolenaar49a90792022-08-09 18:25:23 +01003514
3515 call StopVimInTerminal(buf)
Bram Moolenaar49a90792022-08-09 18:25:23 +01003516endfunc
3517
Bram Moolenaar398649e2022-08-04 15:03:48 +01003518func Test_props_with_text_after_wraps()
Drew Vogelea67ba72025-05-07 22:05:17 +02003519 CheckScreendump
Bram Moolenaar398649e2022-08-04 15:03:48 +01003520 CheckRunVimInTerminal
3521
3522 let lines =<< trim END
3523 call setline(1, ['one two three four five six seven'])
3524 call prop_type_add('afterprop', #{highlight: 'Search'})
3525 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'})
3526
3527 call setline(2, ['one two three four five six seven'])
3528 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'})
3529
3530 call setline(3, ['one two three four five six seven'])
3531 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'})
3532
3533 call setline(4, ['cursor here'])
3534 normal 4Gfh
3535 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003536 call writefile(lines, 'XscriptPropsWithTextAfterWraps', 'D')
Bram Moolenaar398649e2022-08-04 15:03:48 +01003537 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60})
3538 call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {})
3539
3540 call StopVimInTerminal(buf)
Bram Moolenaar398649e2022-08-04 15:03:48 +01003541endfunc
3542
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003543func Test_props_with_text_after_nowrap()
Drew Vogelea67ba72025-05-07 22:05:17 +02003544 CheckScreendump
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 CheckRunVimInTerminal
3546
3547 let lines =<< trim END
3548 set nowrap
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003549 call setline(1, ['one', 'two', 'three', 'four'])
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003550 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
3551 call prop_type_add('anotherprop', #{highlight: 'Search'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01003552 call prop_type_add('someprop', #{highlight: 'DiffChange'})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003553 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
3554 call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'})
3555 call prop_add(2, 0, #{type: 'belowprop', text: 'One More Here', text_align: 'below'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01003556 call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'})
3557 call prop_add(1, 0, #{type: 'someprop', text: ' After the text', text_align: 'after'})
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003558 normal 3G$
3559
3560 call prop_add(3, 0, #{type: 'anotherprop', text: 'right aligned', text_align: 'right'})
3561 call prop_add(3, 0, #{type: 'anotherprop', text: 'also right aligned', text_align: 'right'})
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003562 hi CursorLine ctermbg=lightgrey
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003564 call writefile(lines, 'XscriptPropsAfterNowrap', 'D')
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003565 let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 12, cols: 60})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003566 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {})
3567
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003568 call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\<CR>")
Bram Moolenaar1306b362022-08-06 15:59:06 +01003569 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {})
3570
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003571 call term_sendkeys(buf, "j")
3572 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_3', {})
3573
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003574 call StopVimInTerminal(buf)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575endfunc
3576
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003577func Test_prop_with_text_below_cul()
Drew Vogelea67ba72025-05-07 22:05:17 +02003578 CheckScreendump
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003579 CheckRunVimInTerminal
3580
3581 let lines =<< trim END
3582 vim9script
3583
3584 setline(1, ['some text', 'last line'])
3585 set cursorline nowrap
3586 prop_type_add('test', {highlight: 'DiffChange'})
3587 prop_add(1, 0, {
3588 type: 'test',
3589 text: 'The quick brown fox jumps over the lazy dog',
3590 text_align: 'below',
3591 text_padding_left: 4,
3592 })
3593 END
3594 call writefile(lines, 'XscriptPropsBelowCurline', 'D')
3595 let buf = RunVimInTerminal('-S XscriptPropsBelowCurline', #{rows: 6, cols: 60})
3596 call VerifyScreenDump(buf, 'Test_prop_with_text_below_cul_1', {})
3597
3598 call StopVimInTerminal(buf)
3599endfunc
3600
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003601func Test_props_with_text_below_nowrap()
Drew Vogelea67ba72025-05-07 22:05:17 +02003602 CheckScreendump
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003603 CheckRunVimInTerminal
3604
3605 let lines =<< trim END
3606 vim9script
3607 edit foobar
3608 set nowrap
3609 set showbreak=+++\
3610 setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two'])
3611 prop_type_add('test', {highlight: 'Special'})
3612 prop_add(1, 0, {
3613 type: 'test',
3614 text: 'the quick brown fox jumps over the lazy dog',
3615 text_align: 'after'
3616 })
3617 prop_add(1, 0, {
3618 type: 'test',
3619 text: 'the quick brown fox jumps over the lazy dog',
3620 text_align: 'below'
3621 })
3622 normal G$
3623 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003624 call writefile(lines, 'XscriptPropsBelowNowrap', 'D')
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003625 let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60})
3626 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {})
3627
3628 call term_sendkeys(buf, "gg$")
3629 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {})
3630
3631 call StopVimInTerminal(buf)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003632endfunc
3633
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003634func Test_props_with_text_above()
Drew Vogelea67ba72025-05-07 22:05:17 +02003635 CheckScreendump
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003636 CheckRunVimInTerminal
3637
3638 let lines =<< trim END
3639 call setline(1, ['one two', 'three four', 'five six'])
3640 call prop_type_add('above1', #{highlight: 'Search'})
3641 call prop_type_add('above2', #{highlight: 'DiffChange'})
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003642 call prop_type_add('below', #{highlight: 'DiffAdd'})
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003643 call prop_add(1, 0, #{type: 'above1', text: 'first thing above', text_align: 'above'})
3644 call prop_add(1, 0, #{type: 'above2', text: 'second thing above', text_align: 'above'})
Bram Moolenaar79f8b842022-09-11 13:31:01 +01003645 call prop_add(3, 0, #{type: 'above1', text: 'another thing', text_align: 'above', text_padding_left: 3})
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003646
3647 normal gglllj
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003648 func AddPropBelow()
3649 call prop_add(1, 0, #{type: 'below', text: 'below', text_align: 'below'})
3650 endfunc
Bram Moolenaar9466fb82022-10-11 14:54:42 +01003651 func AddLongPropAbove()
3652 3,4delete
3653 set wrap
3654 call prop_add(1, 0, #{type: 'above1', text: range(50)->join(' '), text_align: 'above', text_padding_left: 2})
3655 endfunc
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003656 END
3657 call writefile(lines, 'XscriptPropsWithTextAbove', 'D')
3658 let buf = RunVimInTerminal('-S XscriptPropsWithTextAbove', #{rows: 9, cols: 60})
3659 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1', {})
3660
Bram Moolenaare24b4ab2022-09-16 20:51:14 +01003661 call term_sendkeys(buf, "ggg$")
3662 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1a', {})
3663 call term_sendkeys(buf, "g0")
3664 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1b', {})
3665
Bram Moolenaar4c7fd4d2022-09-17 17:15:33 +01003666 call term_sendkeys(buf, ":set showbreak=>>\<CR>")
3667 call term_sendkeys(buf, "ggll")
3668 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1c', {})
3669 call term_sendkeys(buf, ":set showbreak=\<CR>")
3670
Bram Moolenaar88b79cb2022-09-10 22:32:14 +01003671 call term_sendkeys(buf, "ggI")
3672 call VerifyScreenDump(buf, 'Test_prop_with_text_above_2', {})
3673 call term_sendkeys(buf, "inserted \<Esc>")
3674 call VerifyScreenDump(buf, 'Test_prop_with_text_above_3', {})
3675
Bram Moolenaar79f8b842022-09-11 13:31:01 +01003676 call term_sendkeys(buf, ":set number signcolumn=yes\<CR>")
3677 call VerifyScreenDump(buf, 'Test_prop_with_text_above_4', {})
3678
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003679 call term_sendkeys(buf, ":set nowrap\<CR>gg$j")
3680 call VerifyScreenDump(buf, 'Test_prop_with_text_above_5', {})
3681
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003682 call term_sendkeys(buf, ":call AddPropBelow()\<CR>")
3683 call term_sendkeys(buf, "ggve")
3684 call VerifyScreenDump(buf, 'Test_prop_with_text_above_6', {})
3685 call term_sendkeys(buf, "V")
3686 call VerifyScreenDump(buf, 'Test_prop_with_text_above_7', {})
3687
Bram Moolenaar3b93cf22022-09-13 18:34:18 +01003688 call term_sendkeys(buf, "\<Esc>ls\<CR>\<Esc>")
3689 call VerifyScreenDump(buf, 'Test_prop_with_text_above_8', {})
3690
Bram Moolenaar9466fb82022-10-11 14:54:42 +01003691 call term_sendkeys(buf, ":call AddLongPropAbove()\<CR>")
3692 call VerifyScreenDump(buf, 'Test_prop_with_text_above_9', {})
3693
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003694 call StopVimInTerminal(buf)
3695endfunc
3696
Bram Moolenaar2354b662023-04-23 21:42:25 +01003697func Test_prop_with_text_above_padding()
Drew Vogelea67ba72025-05-07 22:05:17 +02003698 CheckScreendump
Bram Moolenaar2354b662023-04-23 21:42:25 +01003699 CheckRunVimInTerminal
3700
3701 let lines =<< trim END
3702 vim9script
3703
3704 setlocal tabstop=8 noexpandtab
3705 setline(1, ['', 'sky is blue', 'ocean is blue'])
3706 prop_type_add('DiagVirtualText', {highlight: 'Search', override: true})
3707 prop_add(3, 0, {text: "β”Œβ”€ start", text_align: "above",
3708 type: 'DiagVirtualText',
3709 text_padding_left: 200})
3710 END
3711 call writefile(lines, 'XscriptAbovePadding', 'D')
3712 let buf = RunVimInTerminal('-S XscriptAbovePadding', #{rows: 8})
3713 call VerifyScreenDump(buf, 'Test_prop_above_padding_1', {})
3714
3715 call StopVimInTerminal(buf)
3716endfunc
3717
Bram Moolenaar702bd6c2022-09-14 16:09:57 +01003718func Test_prop_above_with_indent()
3719 new
3720 call setline(1, ['first line', ' second line', ' line below'])
3721 setlocal cindent
3722 call prop_type_add('indented', #{highlight: 'Search'})
3723 call prop_add(3, 0, #{type: 'indented', text: 'here', text_align: 'above', text_padding_left: 4})
3724 call assert_equal(' line below', getline(3))
3725
3726 exe "normal 3G2|a\<CR>"
3727 call assert_equal(' ', getline(3))
3728 call assert_equal(' line below', getline(4))
3729
3730 bwipe!
3731 call prop_type_delete('indented')
3732endfunc
3733
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01003734func Test_prop_above_with_number()
Drew Vogelea67ba72025-05-07 22:05:17 +02003735 CheckScreendump
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01003736 CheckRunVimInTerminal
3737
3738 let lines =<< trim END
3739 vim9script
3740 setline(1, ['one one one', 'two two two', 'three three three'])
3741 set number cpo+=n
3742 prop_type_add('test', {highlight: 'DiffChange'})
3743 prop_add(2, 0, {
3744 text: 'above the text',
3745 type: 'test',
3746 text_align: 'above',
3747 })
3748 def g:OneMore()
3749 prop_add(2, 0, {
3750 text: 'also above the text',
3751 type: 'test',
3752 text_align: 'above',
3753 })
3754 enddef
3755 END
3756 call writefile(lines, 'XscriptPropAboveNr', 'D')
3757 let buf = RunVimInTerminal('-S XscriptPropAboveNr', #{rows: 8})
3758 call VerifyScreenDump(buf, 'Test_prop_above_number_1', {})
3759
3760 call term_sendkeys(buf, ":call OneMore()\<CR>")
3761 call VerifyScreenDump(buf, 'Test_prop_above_number_2', {})
3762
zeertzjq62f19542025-03-08 16:27:37 +01003763 call term_sendkeys(buf, ":setlocal cursorline cursorlineopt=number\<CR>")
3764 call term_sendkeys(buf, 'j')
3765 call VerifyScreenDump(buf, 'Test_prop_above_number_3', {})
3766
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01003767 call StopVimInTerminal(buf)
3768endfunc
3769
zeertzjqce53e3e2023-09-01 18:49:30 +02003770func Test_prop_above_with_linebreak()
Drew Vogelea67ba72025-05-07 22:05:17 +02003771 CheckScreendump
zeertzjqce53e3e2023-09-01 18:49:30 +02003772 CheckRunVimInTerminal
3773
3774 let lines =<< trim END
3775 setlocal linebreak breakindent breakindentopt=shift:4
3776 call setline(1, ["a b", "c d"])
3777 call prop_type_add('theprop' , #{highlight: 'Special'})
3778 call prop_add(1, 0, #{type: 'theprop', text: '123', text_align: 'above'})
3779 normal! 2gg$
3780 END
3781 call writefile(lines, 'XscriptPropAboveLinebreak', 'D')
3782 let buf = RunVimInTerminal('-S XscriptPropAboveLinebreak', #{rows: 6})
3783 call VerifyScreenDump(buf, 'Test_prop_above_linebreak_1', {})
3784 call term_sendkeys(buf, 'k')
3785 call VerifyScreenDump(buf, 'Test_prop_above_linebreak_2', {})
3786
3787 call StopVimInTerminal(buf)
3788endfunc
3789
3790func Test_prop_above_and_before()
Drew Vogelea67ba72025-05-07 22:05:17 +02003791 CheckScreendump
zeertzjqce53e3e2023-09-01 18:49:30 +02003792 CheckRunVimInTerminal
3793
3794 let lines =<< trim END
3795 setlocal linebreak breakindent breakindentopt=shift:2
3796 call setline(1, ["a", " b c"])
3797 call prop_type_add('theprop' , #{highlight: 'Special'})
3798 call prop_add(2, 0, #{type: 'theprop', text: ' 123', text_align: 'above'})
3799 call prop_add(2, 4, #{type: 'theprop', text: ': 456'} )
3800 normal! 2gg$
3801 END
3802 call writefile(lines, 'XscriptPropAboveAndBefore', 'D')
3803 let buf = RunVimInTerminal('-S XscriptPropAboveAndBefore', #{rows: 6})
3804 call VerifyScreenDump(buf, 'Test_prop_above_and_before_1', {})
3805 call term_sendkeys(buf, 'h')
3806 call VerifyScreenDump(buf, 'Test_prop_above_and_before_2', {})
3807 call term_sendkeys(buf, 'h')
3808 call VerifyScreenDump(buf, 'Test_prop_above_and_before_3', {})
3809 call term_sendkeys(buf, 'h')
3810 call VerifyScreenDump(buf, 'Test_prop_above_and_before_4', {})
3811 call term_sendkeys(buf, 'h')
3812 call VerifyScreenDump(buf, 'Test_prop_above_and_before_5', {})
3813
3814 call StopVimInTerminal(buf)
3815endfunc
3816
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003817func Test_prop_below_split_line()
Drew Vogelea67ba72025-05-07 22:05:17 +02003818 CheckScreendump
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003819 CheckRunVimInTerminal
3820
3821 let lines =<< trim END
3822 vim9script
3823 setline(1, ['one one one', 'two two two', 'three three three'])
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003824 prop_type_add('test', {highlight: 'Search'})
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003825 prop_add(2, 0, {
3826 text: '└─ Virtual text below the 2nd line',
3827 type: 'test',
3828 text_align: 'below',
3829 text_padding_left: 3
3830 })
3831 END
3832 call writefile(lines, 'XscriptPropBelowSpitLine', 'D')
3833 let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8})
3834 call term_sendkeys(buf, "2GA\<CR>xx")
3835 call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {})
3836
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003837 call term_sendkeys(buf, "\<Esc>:set number\<CR>")
3838 call VerifyScreenDump(buf, 'Test_prop_below_split_line_2', {})
3839
Bram Moolenaarb84d5652022-09-20 17:57:53 +01003840 call term_sendkeys(buf, ":set nowrap\<CR>")
3841 call VerifyScreenDump(buf, 'Test_prop_below_split_line_3', {})
3842
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003843 call StopVimInTerminal(buf)
3844endfunc
3845
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00003846func Test_prop_above_below_smoothscroll()
Drew Vogelea67ba72025-05-07 22:05:17 +02003847 CheckScreendump
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00003848 CheckRunVimInTerminal
3849
3850 let lines =<< trim END
3851 vim9script
3852 setline(1, range(1, 10)->mapnew((_, v) => '" line ' .. v))
3853
3854 set smoothscroll wrap
3855 call prop_type_add('mytype', {highlight: 'DiffChange'})
3856 call prop_add(3, 0, {text: "insert above", type: "mytype", text_align: 'above'})
3857 call prop_add(5, 0, {text: "insert above 1", type: "mytype", text_align: 'above'})
3858 call prop_add(5, 0, {text: "insert above 2", type: "mytype", text_align: 'above'})
3859 call prop_add(7, 0, {text: "insert below", type: "mytype", text_align: 'below'})
3860 call prop_add(9, 0, {text: "insert below 1", type: "mytype", text_align: 'below'})
3861 call prop_add(9, 0, {text: "insert below 2", type: "mytype", text_align: 'below'})
3862 END
3863 call writefile(lines, 'XscriptPropsSmoothscroll', 'D')
3864 let buf = RunVimInTerminal('-S XscriptPropsSmoothscroll', #{rows: 8, cols: 60})
3865 call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_1', {})
3866
3867 for nr in range(2, 16)
3868 call term_sendkeys(buf, "\<C-E>")
3869 call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_' .. nr, {})
3870 endfor
3871
3872 call StopVimInTerminal(buf)
3873endfunc
3874
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003875func Test_props_with_text_override()
Drew Vogelea67ba72025-05-07 22:05:17 +02003876 CheckScreendump
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003877 CheckRunVimInTerminal
3878
3879 let lines =<< trim END
3880 vim9script
3881 setline(1, 'some text here')
3882 hi Likethis ctermfg=blue ctermbg=cyan
3883 prop_type_add('prop', {highlight: 'Likethis', override: true})
3884 prop_add(1, 6, {type: 'prop', text: ' inserted '})
3885 hi CursorLine cterm=underline ctermbg=lightgrey
3886 set cursorline
3887 END
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003888 call writefile(lines, 'XscriptPropsOverride', 'D')
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003889 let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60})
3890 call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {})
3891
3892 call term_sendkeys(buf, ":set nocursorline\<CR>")
3893 call term_sendkeys(buf, "0llvfr")
3894 call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {})
3895
3896 call StopVimInTerminal(buf)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003897endfunc
3898
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003899func Test_props_with_text_CursorMoved()
Drew Vogelea67ba72025-05-07 22:05:17 +02003900 CheckScreendump
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003901 CheckRunVimInTerminal
3902
3903 let lines =<< trim END
3904 call setline(1, ['this is line one', 'this is line two', 'three', 'four', 'five'])
3905
3906 call prop_type_add('prop', #{highlight: 'Error'})
3907 let g:long_text = repeat('x', &columns * 2)
3908
3909 let g:prop_id = v:null
3910 func! Update()
3911 if line('.') == 1
3912 if g:prop_id == v:null
3913 let g:prop_id = prop_add(1, 0, #{type: 'prop', text_wrap: 'wrap', text: g:long_text})
3914 endif
3915 elseif g:prop_id != v:null
3916 call prop_remove(#{id: g:prop_id})
3917 let g:prop_id = v:null
3918 endif
3919 endfunc
3920
3921 autocmd CursorMoved * call Update()
3922 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003923 call writefile(lines, 'XscriptPropsCursorMovec', 'D')
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003924 let buf = RunVimInTerminal('-S XscriptPropsCursorMovec', #{rows: 8, cols: 60})
3925 call term_sendkeys(buf, "gg0w")
3926 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
3927
3928 call term_sendkeys(buf, "j")
3929 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_2', {})
3930
3931 " back to the first state
3932 call term_sendkeys(buf, "k")
3933 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
3934
3935 call StopVimInTerminal(buf)
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003936endfunc
3937
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003938func Test_props_with_text_after_split_join()
Drew Vogelea67ba72025-05-07 22:05:17 +02003939 CheckScreendump
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003940 CheckRunVimInTerminal
3941
3942 let lines =<< trim END
3943 call setline(1, ['1122'])
3944 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
3945 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
3946 exe "normal f2i\<CR>\<Esc>"
3947
3948 func AddMore()
3949 call prop_type_add('another', #{highlight: 'Search'})
3950 call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'})
3951 call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'})
3952 endfunc
3953 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003954 call writefile(lines, 'XscriptPropsAfterSplitJoin', 'D')
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003955 let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60})
3956 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {})
3957
3958 call term_sendkeys(buf, "ggJ")
3959 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {})
3960
3961 call term_sendkeys(buf, ":call AddMore()\<CR>")
3962 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {})
3963
3964 call term_sendkeys(buf, "ggf s\<CR>\<Esc>")
3965 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {})
3966
3967 call term_sendkeys(buf, "ggJ")
3968 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {})
3969
3970 call StopVimInTerminal(buf)
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003971endfunc
3972
Bram Moolenaar3a4cd392022-07-30 22:17:18 +01003973func Test_removed_prop_with_text_cleans_up_array()
3974 new
3975 call setline(1, 'some text here')
3976 call prop_type_add('some', #{highlight: 'ErrorMsg'})
3977 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
3978 call assert_equal(-1, id1)
3979 let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"})
3980 call assert_equal(-2, id2)
3981
3982 " removing the props resets the index
3983 call prop_remove(#{id: id1})
3984 call prop_remove(#{id: id2})
3985 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
3986 call assert_equal(-1, id1)
3987
3988 call prop_type_delete('some')
3989 bwipe!
3990endfunc
3991
Bram Moolenaar1f4ee192022-08-01 15:52:55 +01003992def Test_insert_text_before_virtual_text()
3993 new foobar
3994 setline(1, '12345678')
3995 prop_type_add('test', {highlight: 'Search'})
3996 prop_add(1, 5, {
3997 type: 'test',
3998 text: ' virtual text '
3999 })
4000 normal! f4axyz
4001 normal! f5iXYZ
4002 assert_equal('1234xyzXYZ5678', getline(1))
4003
4004 prop_type_delete('test')
4005 bwipe!
4006enddef
4007
Bram Moolenaar28c9f892022-08-14 13:28:55 +01004008func Test_insert_text_start_incl()
Drew Vogelea67ba72025-05-07 22:05:17 +02004009 CheckScreendump
Bram Moolenaar28c9f892022-08-14 13:28:55 +01004010 CheckRunVimInTerminal
4011
4012 let lines =<< trim END
4013 vim9script
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01004014 setline(1, ['text one text two', '', 'function(arg)'])
Bram Moolenaar28c9f892022-08-14 13:28:55 +01004015
4016 prop_type_add('propincl', {highlight: 'NonText', start_incl: true})
4017 prop_add(1, 6, {type: 'propincl', text: 'after '})
4018 cursor(1, 6)
4019 prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false})
4020 prop_add(1, 15, {type: 'propnotincl', text: 'before '})
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01004021
Bram Moolenaar94722c52023-01-28 19:19:03 +00004022 set cindent sw=4
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01004023 prop_type_add('argname', {highlight: 'DiffChange', start_incl: true})
4024 prop_add(3, 10, {type: 'argname', text: 'arg: '})
Bram Moolenaar28c9f892022-08-14 13:28:55 +01004025 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004026 call writefile(lines, 'XscriptPropsStartIncl', 'D')
Bram Moolenaar28c9f892022-08-14 13:28:55 +01004027 let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60})
4028 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {})
4029
4030 call term_sendkeys(buf, "i")
4031 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {})
4032 call term_sendkeys(buf, "xx\<Esc>")
4033 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {})
4034
4035 call term_sendkeys(buf, "2wi")
4036 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {})
4037 call term_sendkeys(buf, "yy\<Esc>")
4038 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {})
4039
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01004040 call term_sendkeys(buf, "3Gfai\<CR>\<Esc>")
4041 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_6', {})
4042 call term_sendkeys(buf, ">>")
4043 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_7', {})
4044 call term_sendkeys(buf, "<<<<")
4045 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_8', {})
4046
Bram Moolenaar28c9f892022-08-14 13:28:55 +01004047 call StopVimInTerminal(buf)
Bram Moolenaar28c9f892022-08-14 13:28:55 +01004048endfunc
4049
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01004050func Test_insert_text_list_mode()
Drew Vogelea67ba72025-05-07 22:05:17 +02004051 CheckScreendump
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01004052 CheckRunVimInTerminal
4053
4054 let lines =<< trim END
4055 vim9script
4056 setline(1, ['This is a line with quite a bit of text here.',
4057 'second line', 'third line'])
4058 set list listchars+=extends:Β»
4059 prop_type_add('Prop1', {highlight: 'Error'})
4060 prop_add(1, 0, {
4061 type: 'Prop1',
4062 text: 'The quick brown fox jumps over the lazy dog',
4063 text_align: 'right'
4064 })
4065 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004066 call writefile(lines, 'XscriptPropsListMode', 'D')
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01004067 let buf = RunVimInTerminal('-S XscriptPropsListMode', #{rows: 8, cols: 60})
4068 call term_sendkeys(buf, "ggj")
4069 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_1', {})
4070
4071 call term_sendkeys(buf, ":set nowrap\<CR>")
4072 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_2', {})
4073
4074 call term_sendkeys(buf, "ggd32l")
4075 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_3', {})
4076
4077 call StopVimInTerminal(buf)
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01004078endfunc
4079
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004080func Test_insert_text_with_padding()
Drew Vogelea67ba72025-05-07 22:05:17 +02004081 CheckScreendump
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004082 CheckRunVimInTerminal
4083
4084 let lines =<< trim END
4085 vim9script
4086 setline(1, ['Some text to add virtual text to.',
4087 'second line',
4088 'Another line with some text to make the wrap.'])
4089 prop_type_add('theprop', {highlight: 'DiffChange'})
4090 prop_add(1, 0, {
4091 type: 'theprop',
4092 text: 'after',
4093 text_align: 'after',
4094 text_padding_left: 3,
4095 })
4096 prop_add(1, 0, {
4097 type: 'theprop',
4098 text: 'right aligned',
4099 text_align: 'right',
4100 text_padding_left: 5,
4101 })
4102 prop_add(1, 0, {
4103 type: 'theprop',
4104 text: 'below the line',
4105 text_align: 'below',
4106 text_padding_left: 4,
4107 })
4108 prop_add(3, 0, {
4109 type: 'theprop',
4110 text: 'rightmost',
4111 text_align: 'right',
4112 text_padding_left: 6,
4113 text_wrap: 'wrap',
4114 })
4115 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004116 call writefile(lines, 'XscriptPropsPadded', 'D')
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004117 let buf = RunVimInTerminal('-S XscriptPropsPadded', #{rows: 8, cols: 60})
4118 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_1', {})
4119
4120 call term_sendkeys(buf, "ggixxxxxxxxxx\<Esc>")
4121 call term_sendkeys(buf, "3Gix\<Esc>")
4122 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_2', {})
4123
4124 call term_sendkeys(buf, "ggix\<Esc>")
4125 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_3', {})
4126
Bram Moolenaara4abe512022-09-15 19:44:09 +01004127 call term_sendkeys(buf, ":set list\<CR>")
4128 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_4', {})
4129
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004130 call StopVimInTerminal(buf)
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004131endfunc
4132
Bram Moolenaar13845c42022-10-09 15:26:03 +01004133func Test_long_text_below_with_padding()
Drew Vogelea67ba72025-05-07 22:05:17 +02004134 CheckScreendump
Bram Moolenaar13845c42022-10-09 15:26:03 +01004135 CheckRunVimInTerminal
4136
4137 let lines =<< trim END
4138 vim9script
4139 setline(1, ['first line', 'second line'])
4140 prop_type_add('theprop', {highlight: 'DiffChange'})
4141 prop_add(1, 0, {
4142 type: 'theprop',
4143 text: 'after '->repeat(20),
4144 text_align: 'below',
4145 text_padding_left: 3,
4146 })
4147 prop_add(1, 0, {
4148 type: 'theprop',
4149 text: 'more '->repeat(20),
4150 text_align: 'below',
4151 text_padding_left: 30,
4152 })
4153 normal 2Gw
4154 END
4155 call writefile(lines, 'XlongTextBelowWithPadding', 'D')
4156 let buf = RunVimInTerminal('-S XlongTextBelowWithPadding', #{rows: 8, cols: 60})
4157 call VerifyScreenDump(buf, 'Test_long_text_with_padding_1', {})
4158
Bram Moolenaara9a36482022-10-11 16:47:22 +01004159 call term_sendkeys(buf, ":set list\<CR>")
4160 call VerifyScreenDump(buf, 'Test_long_text_with_padding_2', {})
4161
Bram Moolenaar13845c42022-10-09 15:26:03 +01004162 call StopVimInTerminal(buf)
4163endfunc
4164
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004165func Test_text_after_nowrap()
Drew Vogelea67ba72025-05-07 22:05:17 +02004166 CheckScreendump
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004167 CheckRunVimInTerminal
4168
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004169 let lines =<< trim END
4170 vim9script
Bram Moolenaarcd105412022-10-10 19:50:42 +01004171 setline(1, ['first line', range(80)->join(' '), 'third', 'fourth'])
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004172 set nowrap
4173 prop_type_add('theprop', {highlight: 'DiffChange'})
4174 prop_add(1, 0, {
4175 type: 'theprop',
Bram Moolenaarcd105412022-10-10 19:50:42 +01004176 text: 'right after the text '->repeat(3),
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004177 text_align: 'after',
4178 text_padding_left: 2,
4179 })
Bram Moolenaarcd105412022-10-10 19:50:42 +01004180 prop_add(1, 0, {
4181 type: 'theprop',
4182 text: 'in the middle '->repeat(4),
4183 text_align: 'after',
4184 text_padding_left: 3,
4185 })
4186 prop_add(1, 0, {
4187 type: 'theprop',
4188 text: 'the last one '->repeat(3),
4189 text_align: 'after',
4190 text_padding_left: 1,
4191 })
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004192 normal 2Gw
Bram Moolenaar7e017462022-10-11 21:02:09 +01004193 def g:ChangeText()
4194 prop_clear(1)
4195 set list
4196 prop_add(1, 0, {
4197 type: 'theprop',
4198 text: 'just after txt '->repeat(3),
4199 text_align: 'after',
4200 text_padding_left: 2,
4201 })
4202 prop_add(1, 0, {
4203 type: 'theprop',
4204 text: 'in the middle '->repeat(4),
4205 text_align: 'after',
4206 text_padding_left: 1,
4207 })
4208 enddef
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004209 END
4210 call writefile(lines, 'XTextAfterNowrap', 'D')
4211 let buf = RunVimInTerminal('-S XTextAfterNowrap', #{rows: 8, cols: 60})
4212 call VerifyScreenDump(buf, 'Test_text_after_nowrap_1', {})
4213
Bram Moolenaarcd105412022-10-10 19:50:42 +01004214 call term_sendkeys(buf, "30w")
4215 call VerifyScreenDump(buf, 'Test_text_after_nowrap_2', {})
4216
4217 call term_sendkeys(buf, "22w")
4218 call VerifyScreenDump(buf, 'Test_text_after_nowrap_3', {})
4219
4220 call term_sendkeys(buf, "$")
4221 call VerifyScreenDump(buf, 'Test_text_after_nowrap_4', {})
4222
Bram Moolenaar7e017462022-10-11 21:02:09 +01004223 call term_sendkeys(buf, "0")
4224 call term_sendkeys(buf, ":call ChangeText()\<CR>")
4225 call VerifyScreenDump(buf, 'Test_text_after_nowrap_5', {})
4226
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004227 call StopVimInTerminal(buf)
4228endfunc
4229
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00004230func Test_text_after_nowrap_list()
Drew Vogelea67ba72025-05-07 22:05:17 +02004231 CheckScreendump
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00004232 CheckRunVimInTerminal
4233
4234 let lines =<< trim END
4235 vim9script
4236
4237 set nowrap
4238 set listchars+=extends:>
4239 set list
4240 setline(1, ['some text here', '', 'last line'])
4241
4242 prop_type_add('test', {highlight: 'DiffChange'})
4243 prop_add(1, 0, {
4244 type: 'test',
4245 text: 'The quick brown fox jumps.',
4246 text_padding_left: 2,
4247 })
4248 prop_add(1, 0, {
4249 type: 'test',
4250 text: 'β–  The fox jumps over the lazy dog.',
4251 text_padding_left: 2,
4252 })
4253 prop_add(1, 0, {
4254 type: 'test',
4255 text: 'β–  The lazy dog.',
4256 text_padding_left: 2,
4257 })
4258 normal 3G$
4259 END
4260 call writefile(lines, 'XTextAfterNowrapList', 'D')
4261 let buf = RunVimInTerminal('-S XTextAfterNowrapList', #{rows: 6, cols: 60})
4262 call VerifyScreenDump(buf, 'Test_text_after_nowrap_list_1', {})
4263
4264 call StopVimInTerminal(buf)
4265endfunc
4266
Bram Moolenaar1206c162022-10-10 15:40:04 +01004267func Test_text_below_nowrap()
Drew Vogelea67ba72025-05-07 22:05:17 +02004268 CheckScreendump
Bram Moolenaar1206c162022-10-10 15:40:04 +01004269 CheckRunVimInTerminal
4270
4271 let lines =<< trim END
4272 vim9script
4273 setline(1, ['first line', 'second line '->repeat(50), 'third', 'fourth'])
4274 set nowrap number
4275 prop_type_add('theprop', {highlight: 'DiffChange'})
4276 prop_add(1, 0, {
4277 type: 'theprop',
4278 text: 'one below the text '->repeat(5),
4279 text_align: 'below',
4280 text_padding_left: 2,
4281 })
4282 prop_add(1, 0, {
4283 type: 'theprop',
4284 text: 'two below the text '->repeat(5),
4285 text_align: 'below',
4286 text_padding_left: 2,
4287 })
4288 normal 2Gw
4289 END
4290 call writefile(lines, 'XTextBelowNowrap', 'D')
4291 let buf = RunVimInTerminal('-S XTextBelowNowrap', #{rows: 8, cols: 60})
4292 call VerifyScreenDump(buf, 'Test_text_below_nowrap_1', {})
4293
4294 call StopVimInTerminal(buf)
4295endfunc
4296
Dylan Thacker-Smith80557212024-02-21 21:00:59 +01004297func Test_virtual_text_overlap_with_highlight()
Drew Vogelea67ba72025-05-07 22:05:17 +02004298 CheckScreendump
Dylan Thacker-Smith80557212024-02-21 21:00:59 +01004299 CheckRunVimInTerminal
4300
4301 let lines =<< trim END
4302 vim9script
4303 setline(1, ['one', 'two', 'three', 'four', 'five'])
4304 set number
4305
4306 prop_type_add('demo_highlight_warning', {highlight: 'WarningMsg'})
4307 prop_type_add('demo_virtual_text_error', {highlight: 'Error'})
4308
4309 prop_add(2, 4, {
4310 type: 'demo_highlight_warning',
4311 end_col: 4,
4312 })
4313 prop_add(2, 0, {
4314 type: 'demo_virtual_text_error',
4315 text: 'syntax error',
4316 text_align: 'below',
4317 })
4318 normal 2j
4319
4320 prop_add(4, 4, {
4321 type: 'demo_highlight_warning',
4322 end_lnum: 5,
4323 end_col: 1,
4324 })
4325 prop_add(4, 0, {
4326 type: 'demo_virtual_text_error',
4327 text: 'other error',
4328 text_align: 'right',
4329 })
4330 END
4331 call writefile(lines, 'XVirtualTextOverlapWithHighlight', 'D')
4332 let buf = RunVimInTerminal('-S XVirtualTextOverlapWithHighlight', #{rows: 8, cols: 60})
4333 call VerifyScreenDump(buf, 'Test_virtual_text_overlap_with_highlight_1', {})
4334
4335 call StopVimInTerminal(buf)
4336endfunc
4337
Bram Moolenaaree28c702022-11-17 14:56:00 +00004338func Test_virtual_text_in_popup_highlight()
Drew Vogelea67ba72025-05-07 22:05:17 +02004339 CheckScreendump
Bram Moolenaaree28c702022-11-17 14:56:00 +00004340 CheckRunVimInTerminal
4341
4342 let lines =<< trim END
4343 vim9script
4344
4345 # foreground highlight only, popup background is used
4346 prop_type_add('Prop1', {'highlight': 'SpecialKey'})
4347 # foreground and background highlight, popup background is not used
4348 prop_type_add('Prop2', {'highlight': 'DiffDelete'})
4349
4350 var popupText = [{
4351 text: 'Some text',
4352 props: [
4353 {
4354 col: 1,
4355 type: 'Prop1',
4356 text: ' + '
4357 },
4358 {
4359 col: 6,
4360 type: 'Prop2',
4361 text: ' x '
4362 },
4363 ]
4364 }]
4365 var popupArgs = {
4366 line: 3,
4367 col: 20,
4368 maxwidth: 80,
4369 highlight: 'PMenu',
4370 border: [],
4371 borderchars: [' '],
4372 }
4373
4374 popup_create(popupText, popupArgs)
4375 END
4376 call writefile(lines, 'XscriptVirtualHighlight', 'D')
4377 let buf = RunVimInTerminal('-S XscriptVirtualHighlight', #{rows: 8})
4378 call VerifyScreenDump(buf, 'Test_virtual_text_in_popup_highlight_1', {})
4379
4380 call StopVimInTerminal(buf)
4381endfunc
4382
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004383func Test_insert_text_change_arg()
Drew Vogelea67ba72025-05-07 22:05:17 +02004384 CheckScreendump
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004385 CheckRunVimInTerminal
4386
4387 let lines =<< trim END
4388 vim9script
4389 setline(1, ['SetErrorCode( 10, 20 )', 'second line'])
4390 prop_type_add('param', {highlight: 'DiffChange', start_incl: 1})
4391 prop_type_add('padd', {highlight: 'NonText', start_incl: 1})
4392 prop_add(1, 15, {
4393 type: 'param',
4394 text: 'id:',
4395 })
4396 prop_add(1, 15, {
4397 type: 'padd',
4398 text: '-',
4399 })
4400 prop_add(1, 19, {
4401 type: 'param',
4402 text: 'id:',
4403 })
4404 prop_add(1, 19, {
4405 type: 'padd',
4406 text: '-',
4407 })
4408 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004409 call writefile(lines, 'XscriptPropsChange', 'D')
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004410 let buf = RunVimInTerminal('-S XscriptPropsChange', #{rows: 5, cols: 60})
4411 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_1', {})
4412
4413 call term_sendkeys(buf, "ggf1cw1234\<Esc>")
4414 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_2', {})
4415
4416 call StopVimInTerminal(buf)
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004417endfunc
4418
Bram Moolenaar2f7bfe62022-11-13 12:54:50 +00004419def Test_textprop_in_quickfix_window()
4420 enew!
4421 var prop_type = 'my_prop'
4422 prop_type_add(prop_type, {})
4423
4424 for lnum in range(1, 10)
4425 setline(lnum, 'hello world')
4426 endfor
4427
4428 cgetbuffer
4429 copen
4430
4431 var bufnr = bufnr()
4432 for lnum in range(1, line('$', bufnr->bufwinid()))
4433 prop_add(lnum, 1, {
4434 id: 1000 + lnum,
4435 type: prop_type,
4436 bufnr: bufnr,
4437 })
4438 endfor
4439
4440 prop_type_delete(prop_type)
4441 cclose
4442 bwipe!
4443enddef
4444
Bram Moolenaar89469d12022-12-02 20:46:26 +00004445func Test_text_prop_delete_updates()
Drew Vogelea67ba72025-05-07 22:05:17 +02004446 CheckScreendump
Bram Moolenaar89469d12022-12-02 20:46:26 +00004447 CheckRunVimInTerminal
4448
4449 let lines =<< trim END
4450 vim9script
4451
4452 setline(1, ['some text', 'more text', 'the end'])
4453 prop_type_add('test', {highlight: 'DiffChange'})
4454 prop_add(1, 0, {
4455 type: 'test',
4456 text: 'The quick brown fox jumps over the lazy dog',
4457 text_align: 'below',
4458 text_padding_left: 3,
4459 })
4460 prop_add(1, 0, {
4461 type: 'test',
4462 text: 'The quick brown fox jumps over the lazy dog',
4463 text_align: 'below',
4464 text_padding_left: 5,
4465 })
4466
4467 normal! G
4468 END
4469 call writefile(lines, 'XtextPropDelete', 'D')
4470 let buf = RunVimInTerminal('-S XtextPropDelete', #{rows: 10, cols: 60})
4471 call VerifyScreenDump(buf, 'Test_prop_delete_updates_1', {})
4472
4473 " Check that after deleting the text prop type the text properties using
4474 " this type no longer show and are not counted for cursor positioning.
4475 call term_sendkeys(buf, ":call prop_type_delete('test')\<CR>")
4476 call VerifyScreenDump(buf, 'Test_prop_delete_updates_2', {})
4477
4478 call term_sendkeys(buf, "ggj")
4479 call VerifyScreenDump(buf, 'Test_prop_delete_updates_3', {})
4480
4481 call StopVimInTerminal(buf)
4482endfunc
4483
Bram Moolenaard097af72022-12-17 11:33:00 +00004484func Test_text_prop_diff_mode()
Drew Vogelea67ba72025-05-07 22:05:17 +02004485 CheckScreendump
Bram Moolenaard097af72022-12-17 11:33:00 +00004486 CheckRunVimInTerminal
4487
4488 let lines =<< trim END
4489 call setline(1, ['9000', '0009', '0009', '9000', '0009'])
4490
4491 let type = 'test'
4492 call prop_type_add(type, {})
4493 let text = '<text>'
4494 call prop_add(1, 1, {'type': type, 'text': text})
4495 call prop_add(2, 0, {'type': type, 'text': text, 'text_align': 'after'})
4496 call prop_add(3, 0, {'type': type, 'text': text, 'text_align': 'right'})
4497 call prop_add(4, 0, {'type': type, 'text': text, 'text_align': 'above'})
4498 call prop_add(5, 0, {'type': type, 'text': text, 'text_align': 'below'})
4499 set diff
4500
4501 vnew
4502 call setline(1, ['000', '000', '000', '000', '000'])
4503 set diff
4504 END
4505 call writefile(lines, 'XtextPropDiff', 'D')
4506 let buf = RunVimInTerminal('-S XtextPropDiff', #{rows: 10, cols: 60})
4507 call VerifyScreenDump(buf, 'Test_prop_diff_mode_1', {})
4508
4509 call term_sendkeys(buf, ":windo set number\<CR>")
4510 call VerifyScreenDump(buf, 'Test_prop_diff_mode_2', {})
4511
4512 call StopVimInTerminal(buf)
4513endfunc
Bram Moolenaar94722c52023-01-28 19:19:03 +00004514
Bram Moolenaar4ce1f992022-12-19 13:31:06 +00004515func Test_error_when_using_negative_id()
4516 call prop_type_add('test1', #{highlight: 'ErrorMsg'})
4517 call prop_add(1, 1, #{type: 'test1', text: 'virtual'})
4518 call assert_fails("call prop_add(1, 1, #{type: 'test1', length: 1, id: -1})", 'E1293:')
4519
4520 call prop_type_delete('test1')
4521endfunc
4522
4523func Test_error_after_using_negative_id()
Drew Vogelea67ba72025-05-07 22:05:17 +02004524 CheckScreendump
Bram Moolenaar4ce1f992022-12-19 13:31:06 +00004525 " This needs to run a separate Vim instance because the
4526 " "did_use_negative_pop_id" will be set.
4527 CheckRunVimInTerminal
4528
4529 let lines =<< trim END
4530 vim9script
4531
4532 setline(1, ['one', 'two', 'three'])
4533 prop_type_add('test_1', {highlight: 'Error'})
4534 prop_type_add('test_2', {highlight: 'WildMenu'})
4535
4536 prop_add(3, 1, {
4537 type: 'test_1',
4538 length: 5,
4539 id: -1
4540 })
4541
4542 def g:AddTextprop()
4543 prop_add(1, 0, {
4544 type: 'test_2',
4545 text: 'The quick fox',
4546 text_padding_left: 2
4547 })
4548 enddef
4549 END
4550 call writefile(lines, 'XtextPropError', 'D')
4551 let buf = RunVimInTerminal('-S XtextPropError', #{rows: 8, cols: 60})
4552 call VerifyScreenDump(buf, 'Test_prop_negative_error_1', {})
4553
4554 call term_sendkeys(buf, ":call AddTextprop()\<CR>")
4555 call VerifyScreenDump(buf, 'Test_prop_negative_error_2', {})
4556
4557 call StopVimInTerminal(buf)
4558endfunc
Bram Moolenaard097af72022-12-17 11:33:00 +00004559
Ibbya6ab5e62023-08-20 20:24:18 +02004560func Test_modify_text_before_prop()
Drew Vogelea67ba72025-05-07 22:05:17 +02004561 CheckScreendump
Ibbya6ab5e62023-08-20 20:24:18 +02004562 CheckRunVimInTerminal
4563
4564 let lines =<< trim END
4565 vim9script
4566 setline(1, ['test_words', 'second line', 'third line', 'fourth line'])
4567 set number
4568 prop_type_add('text', {highlight: 'DiffChange'})
4569 prop_type_add('below', {highlight: 'NonText'})
4570 prop_add(1, 11, {type: 'text', text: repeat('a', 65)})
4571 prop_add(1, 0, {type: 'below', text: repeat('a', 65), text_align: 'below'})
4572 END
4573 call writefile(lines, 'XtextPropModifyBefore', 'D')
4574 let buf = RunVimInTerminal('-S XtextPropModifyBefore', #{rows: 5, cols: 60})
4575 call VerifyScreenDump(buf, 'Test_modify_text_before_prop_1', {})
4576
4577 call term_sendkeys(buf, "xxia\<Esc>")
4578 call VerifyScreenDump(buf, 'Test_modify_text_before_prop_2', {})
4579
4580 call StopVimInTerminal(buf)
4581endfunc
4582
Christian Brabandtf1cc4d52023-08-12 00:14:14 +02004583func Test_overlong_textprop_above_crash()
Drew Vogelea67ba72025-05-07 22:05:17 +02004584 CheckScreendump
Christian Brabandtf1cc4d52023-08-12 00:14:14 +02004585 CheckRunVimInTerminal
Bram Moolenaar2f7bfe62022-11-13 12:54:50 +00004586
Christian Brabandtf1cc4d52023-08-12 00:14:14 +02004587 let lines =<< trim END
4588 vim9script
4589 prop_type_add('PropType', {highlight: 'Error'})
4590 setline(1, ['xxx ', 'yyy'])
4591 prop_add(1, 0, {
4592 type: 'PropType',
4593 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.',
4594 text_align: 'above',
4595 text_wrap: 'wrap',
4596 })
4597 END
4598 call writefile(lines, 'XtextPropLongAbove', 'D')
4599 let buf = RunVimInTerminal('-S XtextPropLongAbove', #{rows: 8, cols: 60})
4600 call VerifyScreenDump(buf, 'Test_prop_long_above_1', {})
4601
4602 call StopVimInTerminal(buf)
4603endfunc
Christian Brabandtdbeadf02023-08-19 15:35:04 +02004604
4605func Test_text_prop_list_hl_and_sign_highlight()
Drew Vogelea67ba72025-05-07 22:05:17 +02004606 CheckScreendump
Christian Brabandtdbeadf02023-08-19 15:35:04 +02004607 CheckRunVimInTerminal
4608
4609 let lines =<< trim END
4610 func Test()
4611 split Xbuffer
4612 call setline(1, ['one', "\ttab", ' space', 'three', 'four', 'five'])
4613 call prop_type_add('Prop1', #{highlight: 'Search', override: v:true})
4614 sign define sign1 text=>> linehl=DiffAdd
4615 sign place 10 line=2 name=sign1
4616 sign place 20 line=3 name=sign1
4617 call prop_add(1, 1, #{end_lnum: 4, end_col: 5, type: 'Prop1'})
4618 sign place 30 line=5 name=sign1
4619 endfunc
4620 call Test()
4621 END
4622 call writefile(lines, 'XtextPropSignTab', 'D')
4623 let buf = RunVimInTerminal('-S XtextPropSignTab', #{rows: 8, cols: 60})
4624 call VerifyScreenDump(buf, 'Test_prop_sign_tab_1', {})
4625
4626 call term_sendkeys(buf, ":setl list listchars=eol:ΒΆ,tab:>-\<CR>")
4627 call VerifyScreenDump(buf, 'Test_prop_sign_tab_2', {})
4628
4629 call StopVimInTerminal(buf)
4630endfunc
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004631
4632" Test for getting the virtual text properties
4633func Test_virtual_text_get()
4634 new foobar
4635 call setline(1, '12345678')
4636 call prop_type_add('test', #{highlight: 'Search'})
4637 call prop_add(1, 2, #{type: 'test', text: ' virtual text1 '})
4638 call prop_add(1, 3, #{type: 'test'})
4639 call prop_add(1, 0, #{type: 'test', text: ' virtual text2 ',
4640 \ text_align: 'right'})
4641 call prop_add(1, 5, #{type: 'test'})
4642 call prop_add(1, 6, #{type: 'test', text: ' virtual text3 ',
4643 \ text_wrap: 'wrap'})
4644
4645 let p = prop_list(1, #{end_lnum: -1})
4646 call assert_equal(
Yegappan Lakshmanan171c5b92023-08-22 21:48:50 +02004647 \ #{lnum: 1, col: 2, type_bufnr: 0, end: 1,
4648 \ type: 'test', start: 1,
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004649 \ text: ' virtual text1 '}, p[0])
4650 call assert_equal(
4651 \ #{lnum: 1, id: 0, col: 3, type_bufnr: 0, end: 1,
4652 \ type: 'test', length: 0, start: 1}, p[1])
4653 call assert_equal(
4654 \ #{lnum: 1, id: 0, col: 5, type_bufnr: 0, end: 1,
4655 \ type: 'test', length: 0, start: 1}, p[2])
4656 call assert_equal(
Yegappan Lakshmanan171c5b92023-08-22 21:48:50 +02004657 \ #{lnum: 1, col: 6, type_bufnr: 0, end: 1, type: 'test',
4658 \ text_wrap: 'wrap', start: 1, text: ' virtual text3 '},
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004659 \ p[3])
4660 call assert_equal('right', p[4].text_align)
4661
4662 call prop_type_delete('test')
4663 bwipe!
4664endfunc
4665
Christian Brabandt0d0b3b12023-12-03 17:56:43 +01004666" This used to throw: E967
4667func Test_textprop_notype_join()
4668 new Xtextprop_no_type_join
4669 call setline(1, range(1, 3))
4670 call cursor(1, 1)
4671 let name = 'a'
4672 call prop_type_add(name, {})
4673 call prop_add(line('.'), col('.'), { 'type': name })
4674 call prop_type_delete(name, {})
4675 join
4676 call assert_equal(["1 2", "3"], getline(1, '$'))
4677
4678 bwipe!
4679endfunc
4680
zeertzjq7ac11452024-03-06 20:54:22 +01004681" This was causing text property corruption.
4682func Test_textprop_backspace_fo_aw()
4683 new
4684 call setline(1, 'foobar')
4685 call prop_type_add('test', {'highlight': 'ErrorMsg'})
4686 call prop_add(1, 1, {'type': 'test', 'length': 3})
4687 set backspace=indent,eol,start
4688 setlocal formatoptions+=aw
4689 call feedkeys("A \<CR>\<BS>\<Esc>", 'tx')
4690 call assert_equal('foobar', getline(1))
4691 call assert_equal([
4692 \ #{id: 0, col: 1, start: 1, end: 1, type_bufnr: 0,
4693 \ type: 'test', length: 3}], prop_list(1))
4694
4695 bwipe!
4696 set backspace&
4697 call prop_type_delete('test')
4698endfunc
4699
zeertzjq9352c282024-03-14 18:16:56 +01004700func Test_textprop_with_wincolor()
Drew Vogelea67ba72025-05-07 22:05:17 +02004701 CheckScreendump
zeertzjq9352c282024-03-14 18:16:56 +01004702 CheckRunVimInTerminal
4703
4704 let lines =<< trim END
4705 call setline(1, 'some text here')
4706 call setline(2, 'some much longer text here')
4707 call setline(3, 'more text here')
4708 call prop_type_add('afterprop', #{highlight: 'Search'})
4709 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
4710 call prop_add(3, 0, #{type: 'afterprop', text: 'AFTER',
4711 \ text_align: 'after', text_padding_left: 3})
4712 call prop_add(1, 0, #{type: 'belowprop', text: 'BELOW',
4713 \ text_align: 'below', text_padding_left: 3})
4714 set wincolor=DiffChange wrap
4715 END
4716 call writefile(lines, 'XtextPropWincolor', 'D')
4717 let buf = RunVimInTerminal('-S XtextPropWincolor', #{rows: 8, cols: 60})
4718
4719 call term_sendkeys(buf, ":\<CR>")
4720 call VerifyScreenDump(buf, 'Test_prop_wincolor_1', {})
4721
4722 call term_sendkeys(buf, ":set cursorline\<CR>:\<CR>")
4723 call VerifyScreenDump(buf, 'Test_prop_wincolor_2', {})
4724
4725 call term_sendkeys(buf, ":set nowrap\<CR>:\<CR>")
4726 call VerifyScreenDump(buf, 'Test_prop_wincolor_2', {})
4727
4728 call term_sendkeys(buf, ":set nocursorline\<CR>:\<CR>")
4729 call VerifyScreenDump(buf, 'Test_prop_wincolor_1', {})
4730
4731 call term_sendkeys(buf, ":set cursorline colorcolumn=30\<CR>:\<CR>")
4732 call VerifyScreenDump(buf, 'Test_prop_wincolor_3', {})
4733
4734 call term_sendkeys(buf, ":hi CursorLine ctermbg=Brown\<CR>:\<CR>")
4735 call VerifyScreenDump(buf, 'Test_prop_wincolor_4', {})
4736
4737 call term_sendkeys(buf, ":set cursorcolumn\<CR>:\<CR>")
4738 call term_sendkeys(buf, '$')
4739 call VerifyScreenDump(buf, 'Test_prop_wincolor_5', {})
4740
4741 call term_sendkeys(buf, 'j')
4742 call VerifyScreenDump(buf, 'Test_prop_wincolor_6', {})
4743
4744 call term_sendkeys(buf, ":set virtualedit=all\<CR>:\<CR>")
4745 call term_sendkeys(buf, 'l')
4746 call VerifyScreenDump(buf, 'Test_prop_wincolor_7', {})
4747
4748 call term_sendkeys(buf, 'k')
4749 call VerifyScreenDump(buf, 'Test_prop_wincolor_8', {})
4750
zeertzjqf6272552024-03-17 10:01:47 +01004751 if has('rightleft')
4752 call term_sendkeys(buf, ":set rightleft\<CR>:\<CR>")
4753 call VerifyScreenDump(buf, 'Test_prop_wincolor_9', {})
4754 endif
4755
zeertzjq9352c282024-03-14 18:16:56 +01004756 call StopVimInTerminal(buf)
4757endfunc
4758
Christian Brabandt56b12072025-05-21 21:01:40 +02004759func Test_textprop_materialize_list()
4760 let ids = range(3)
4761 call assert_equal([], prop_list(1, #{ids: ids}))
4762
4763 let ids = range(3) + []
4764 call assert_equal([], prop_list(1, #{ids: ids}))
4765
4766 let ids = range(3)
4767 let ids[0] = ids[0]
4768 call assert_equal([], prop_list(1, #{ids: ids}))
4769
4770 let ids = range(3)
4771 call assert_equal([], prop_list(1, #{ids: ids}))
4772
4773 call assert_equal([], prop_list(1, #{ids: range(3) + [] }))
4774
4775 let ids = range(3)
4776 call assert_equal([], prop_list(1, #{ids: ids}))
4777
4778 let ids = range(0, 3)
4779 call assert_equal([], prop_list(1, #{ids: ids}))
4780
4781 call assert_equal([], prop_list(1, #{ids: 3->range()}))
4782endfunc
4783
Bram Moolenaar99fa7212020-04-26 15:59:55 +02004784" vim: shiftwidth=2 sts=2 expandtab