blob: abc63652ec1778af24dd1df5b23fb46c4d5c3b6a [file] [log] [blame]
Bram Moolenaar98aefe72018-12-13 22:20:09 +01001" Tests for defining text property types and adding text properties to the
2" buffer.
3
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02004source check.vim
5CheckFeature textprop
Bram Moolenaar98aefe72018-12-13 22:20:09 +01006
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01007source screendump.vim
Bram Moolenaar62aec932022-01-29 21:45:34 +00008import './vim9.vim' as v9
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01009
Bram Moolenaar98aefe72018-12-13 22:20:09 +010010func Test_proptype_global()
11 call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1})
12 let proptypes = prop_type_list()
13 call assert_equal(1, len(proptypes))
14 call assert_equal('comment', proptypes[0])
15
16 let proptype = prop_type_get('comment')
17 call assert_equal('Directory', proptype['highlight'])
18 call assert_equal(123, proptype['priority'])
19 call assert_equal(1, proptype['start_incl'])
20 call assert_equal(1, proptype['end_incl'])
21
22 call prop_type_delete('comment')
23 call assert_equal(0, len(prop_type_list()))
24
25 call prop_type_add('one', {})
26 call assert_equal(1, len(prop_type_list()))
Bram Moolenaara5a78822019-09-04 21:57:18 +020027 let proptype = 'one'->prop_type_get()
Bram Moolenaar98aefe72018-12-13 22:20:09 +010028 call assert_false(has_key(proptype, 'highlight'))
29 call assert_equal(0, proptype['priority'])
30 call assert_equal(0, proptype['start_incl'])
31 call assert_equal(0, proptype['end_incl'])
32
33 call prop_type_add('two', {})
34 call assert_equal(2, len(prop_type_list()))
35 call prop_type_delete('one')
36 call assert_equal(1, len(prop_type_list()))
37 call prop_type_delete('two')
38 call assert_equal(0, len(prop_type_list()))
39endfunc
40
41func Test_proptype_buf()
42 let bufnr = bufnr('')
Martin Tournoije2390c72021-07-28 13:30:16 +020043 call prop_type_add('comment', #{bufnr: bufnr, highlight: 'Directory', priority: 123, start_incl: 1, end_incl: 1})
Bram Moolenaar98aefe72018-12-13 22:20:09 +010044 let proptypes = prop_type_list({'bufnr': bufnr})
45 call assert_equal(1, len(proptypes))
46 call assert_equal('comment', proptypes[0])
47
48 let proptype = prop_type_get('comment', {'bufnr': bufnr})
49 call assert_equal('Directory', proptype['highlight'])
50 call assert_equal(123, proptype['priority'])
51 call assert_equal(1, proptype['start_incl'])
52 call assert_equal(1, proptype['end_incl'])
53
54 call prop_type_delete('comment', {'bufnr': bufnr})
Bram Moolenaara5a78822019-09-04 21:57:18 +020055 call assert_equal(0, len({'bufnr': bufnr}->prop_type_list()))
Bram Moolenaar98aefe72018-12-13 22:20:09 +010056
57 call prop_type_add('one', {'bufnr': bufnr})
58 let proptype = prop_type_get('one', {'bufnr': bufnr})
59 call assert_false(has_key(proptype, 'highlight'))
60 call assert_equal(0, proptype['priority'])
61 call assert_equal(0, proptype['start_incl'])
62 call assert_equal(0, proptype['end_incl'])
63
64 call prop_type_add('two', {'bufnr': bufnr})
65 call assert_equal(2, len(prop_type_list({'bufnr': bufnr})))
66 call prop_type_delete('one', {'bufnr': bufnr})
67 call assert_equal(1, len(prop_type_list({'bufnr': bufnr})))
68 call prop_type_delete('two', {'bufnr': bufnr})
69 call assert_equal(0, len(prop_type_list({'bufnr': bufnr})))
Bram Moolenaarf0884c52019-05-24 21:22:29 +020070
71 call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
Bram Moolenaar98aefe72018-12-13 22:20:09 +010072endfunc
73
Bram Moolenaar10246902022-08-08 17:08:05 +010074def Test_proptype_add_remove()
75 # add and remove a prop type so that the array is empty
76 prop_type_add('local', {bufnr: bufnr('%')})
77 prop_type_delete('local', {bufnr: bufnr('%')})
78 prop_type_add('global', {highlight: 'ErrorMsg'})
79 prop_add(1, 1, {length: 1, type: 'global'})
80 redraw
81
82 prop_clear(1)
83 prop_type_delete('global')
84enddef
85
Martin Tournoije2390c72021-07-28 13:30:16 +020086def Test_proptype_buf_list()
87 new
88 var bufnr = bufnr('')
89 try
90 prop_type_add('global', {})
91 prop_type_add('local', {bufnr: bufnr})
92
93 prop_add(1, 1, {type: 'global'})
94 prop_add(1, 1, {type: 'local'})
95
96 assert_equal([
97 {type: 'local', type_bufnr: bufnr, id: 0, col: 1, end: 1, length: 0, start: 1},
98 {type: 'global', type_bufnr: 0, id: 0, col: 1, end: 1, length: 0, start: 1},
99 ], prop_list(1))
100 assert_equal(
101 {lnum: 1, id: 0, col: 1, type_bufnr: bufnr, end: 1, type: 'local', length: 0, start: 1},
102 prop_find({lnum: 1, type: 'local'}))
103 assert_equal(
104 {lnum: 1, id: 0, col: 1, type_bufnr: 0, end: 1, type: 'global', length: 0, start: 1},
105 prop_find({lnum: 1, type: 'global'}))
106
107 prop_remove({type: 'global'}, 1)
108 prop_remove({type: 'local'}, 1)
109 finally
110 prop_type_delete('global')
111 prop_type_delete('local', {bufnr: bufnr})
112 bwipe!
113 endtry
114enddef
115
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100116func AddPropTypes()
117 call prop_type_add('one', {})
118 call prop_type_add('two', {})
119 call prop_type_add('three', {})
120 call prop_type_add('whole', {})
121endfunc
122
123func DeletePropTypes()
124 call prop_type_delete('one')
125 call prop_type_delete('two')
126 call prop_type_delete('three')
127 call prop_type_delete('whole')
128endfunc
129
130func SetupPropsInFirstLine()
131 call setline(1, 'one two three')
132 call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'})
Bram Moolenaara5a78822019-09-04 21:57:18 +0200133 eval 1->prop_add(5, {'length': 3, 'id': 12, 'type': 'two'})
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100134 call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'})
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100135 call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'})
136endfunc
137
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100138func Get_expected_props()
139 return [
Martin Tournoije2390c72021-07-28 13:30:16 +0200140 \ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1},
141 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
142 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
143 \ #{type_bufnr: 0, col: 9, length: 5, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100144 \ ]
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100145endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100146
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100147func Test_prop_find()
148 new
149 call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix'])
Martin Tournoije2390c72021-07-28 13:30:16 +0200150
151 " Add two text props on lines 1 and 5, and one spanning lines 2 to 4.
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100152 call prop_type_add('prop_name', {'highlight': 'Directory'})
153 call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3})
154 call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9})
155 call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1})
156
157 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200158 \ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1},
159 \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0},
160 \ #{type_bufnr: 0, lnum: 5, col: 4, length: 1, id: 12, type: 'prop_name', start: 1, end: 1}
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100161 \ ]
162
163 " Starting at line 5 col 1 this should find the prop at line 5 col 4.
Ben Jacksona7704222022-08-20 20:54:51 +0100164 call cursor(5, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100165 let result = prop_find({'type': 'prop_name'}, 'f')
166 call assert_equal(expected[2], result)
167
168 " With skipstart left at false (default), this should find the prop at line
169 " 5 col 4.
170 let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4}, 'b')
171 call assert_equal(expected[2], result)
172
173 " With skipstart set to true, this should skip the prop at line 5 col 4.
174 let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4, 'skipstart': 1}, 'b')
175 unlet result.length
176 call assert_equal(expected[1], result)
177
178 " Search backwards from line 1 col 10 to find the prop on the same line.
179 let result = prop_find({'type': 'prop_name', 'lnum': 1, 'col': 10}, 'b')
180 call assert_equal(expected[0], result)
181
182 " with skipstart set to false, if the start position is anywhere between the
183 " start and end lines of a text prop (searching forward or backward), the
184 " result should be the prop on the first line (the line with 'start' set to 1).
Ben Jacksona7704222022-08-20 20:54:51 +0100185 call cursor(3, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100186 let result = prop_find({'type': 'prop_name'}, 'f')
187 unlet result.length
188 call assert_equal(expected[1], result)
189 let result = prop_find({'type': 'prop_name'}, 'b')
190 unlet result.length
191 call assert_equal(expected[1], result)
192
193 " with skipstart set to true, if the start position is anywhere between the
194 " start and end lines of a text prop (searching forward or backward), all lines
195 " of the prop will be skipped.
196 let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'b')
197 call assert_equal(expected[0], result)
198 let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'f')
199 call assert_equal(expected[2], result)
200
201 " Use skipstart to search through all props with type name 'prop_name'.
202 " First forward...
203 let lnum = 1
204 let col = 1
205 let i = 0
206 for exp in expected
207 let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'f')
208 if !has_key(exp, "length")
209 unlet result.length
210 endif
211 call assert_equal(exp, result)
212 let lnum = result.lnum
213 let col = result.col
214 let i = i + 1
215 endfor
216
217 " ...then backwards.
218 let lnum = 6
219 let col = 4
220 let i = 2
221 while i >= 0
222 let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'b')
223 if !has_key(expected[i], "length")
224 unlet result.length
225 endif
226 call assert_equal(expected[i], result)
227 let lnum = result.lnum
228 let col = result.col
229 let i = i - 1
Martin Tournoije2390c72021-07-28 13:30:16 +0200230 endwhile
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100231
232 " Starting from line 6 col 1 search backwards for prop with id 10.
Ben Jacksona7704222022-08-20 20:54:51 +0100233 call cursor(6, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100234 let result = prop_find({'id': 10, 'skipstart': 1}, 'b')
235 call assert_equal(expected[0], result)
236
237 " Starting from line 1 col 1 search forwards for prop with id 12.
Ben Jacksona7704222022-08-20 20:54:51 +0100238 call cursor(1, 1)
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100239 let result = prop_find({'id': 12}, 'f')
240 call assert_equal(expected[2], result)
241
242 " Search for a prop with an unknown id.
243 let result = prop_find({'id': 999}, 'f')
244 call assert_equal({}, result)
245
246 " Search backwards from the proceeding position of the prop with id 11
247 " (at line num 2 col 4). This should return an empty dict.
248 let result = prop_find({'id': 11, 'lnum': 2, 'col': 3}, 'b')
249 call assert_equal({}, result)
250
251 " When lnum is given and col is omitted, use column 1.
252 let result = prop_find({'type': 'prop_name', 'lnum': 1}, 'f')
253 call assert_equal(expected[0], result)
254
Bram Moolenaare041dde2021-08-01 21:30:12 +0200255 " Negative ID is possible, just like prop is not found.
Bram Moolenaar8e3fc132021-07-31 18:33:57 +0200256 call assert_equal({}, prop_find({'id': -1}))
Bram Moolenaare041dde2021-08-01 21:30:12 +0200257 call assert_equal({}, prop_find({'id': -2}))
Bram Moolenaar8e3fc132021-07-31 18:33:57 +0200258
Bram Moolenaare041dde2021-08-01 21:30:12 +0200259 call prop_clear(1, 6)
260
261 " Default ID is zero
262 call prop_add(5, 4, {'type': 'prop_name', 'length': 1})
263 call assert_equal(#{lnum: 5, id: 0, col: 4, type_bufnr: 0, end: 1, type: 'prop_name', length: 1, start: 1}, prop_find({'id': 0}))
264
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100265 call prop_type_delete('prop_name')
Bram Moolenaare041dde2021-08-01 21:30:12 +0200266 call prop_clear(1, 6)
Bram Moolenaar4da7a252020-09-02 19:59:00 +0200267 bwipe!
Bram Moolenaare05a89a2020-01-10 19:56:46 +0100268endfunc
269
Bram Moolenaareb245562020-09-03 22:33:44 +0200270def Test_prop_find2()
271 # Multiple props per line, start on the first, should find the second.
272 new
273 ['the quikc bronw fox jumsp over the layz dog']->repeat(2)->setline(1)
Bram Moolenaare0de1712020-12-02 17:36:54 +0100274 prop_type_add('misspell', {highlight: 'ErrorMsg'})
Bram Moolenaareb245562020-09-03 22:33:44 +0200275 for lnum in [1, 2]
276 for col in [8, 14, 24, 38]
Bram Moolenaare0de1712020-12-02 17:36:54 +0100277 prop_add(lnum, col, {type: 'misspell', length: 2})
Bram Moolenaareb245562020-09-03 22:33:44 +0200278 endfor
279 endfor
280 cursor(1, 8)
Martin Tournoije2390c72021-07-28 13:30:16 +0200281 var expected = {type_bufnr: 0, lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1}
Bram Moolenaare0de1712020-12-02 17:36:54 +0100282 var result = prop_find({type: 'misspell', skipstart: true}, 'f')
Bram Moolenaareb245562020-09-03 22:33:44 +0200283 assert_equal(expected, result)
284
285 prop_type_delete('misspell')
286 bwipe!
287enddef
288
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100289func Test_prop_find_smaller_len_than_match_col()
290 new
291 call prop_type_add('test', {'highlight': 'ErrorMsg'})
292 call setline(1, ['xxxx', 'x'])
293 call prop_add(1, 4, {'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200294 call assert_equal(
295 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 4, type: 'test', length: 0, start: 1, end: 1},
Bram Moolenaar346f18e2020-03-13 21:36:40 +0100296 \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b'))
297 bwipe!
298 call prop_type_delete('test')
299endfunc
300
Bram Moolenaar24f21fd2021-03-27 22:07:29 +0100301func Test_prop_find_with_both_option_enabled()
302 " Initialize
303 new
304 call AddPropTypes()
305 call SetupPropsInFirstLine()
306 let props = Get_expected_props()->map({_, v -> extend(v, {'lnum': 1})})
307 " Test
308 call assert_fails("call prop_find({'both': 1})", 'E968:')
309 call assert_fails("call prop_find({'id': 11, 'both': 1})", 'E860:')
310 call assert_fails("call prop_find({'type': 'three', 'both': 1})", 'E860:')
311 call assert_equal({}, prop_find({'id': 11, 'type': 'three', 'both': 1}))
312 call assert_equal({}, prop_find({'id': 130000, 'type': 'one', 'both': 1}))
313 call assert_equal(props[2], prop_find({'id': 12, 'type': 'two', 'both': 1}))
314 call assert_equal(props[0], prop_find({'id': 14, 'type': 'whole', 'both': 1}))
315 " Clean up
316 call DeletePropTypes()
317 bwipe!
318endfunc
319
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100320func Test_prop_add()
321 new
322 call AddPropTypes()
323 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100324 let expected_props = Get_expected_props()
325 call assert_equal(expected_props, prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100326 call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:')
327 call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:')
Martin Tournoije2390c72021-07-28 13:30:16 +0200328
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100329 " Insert a line above, text props must still be there.
330 call append(0, 'empty')
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100331 call assert_equal(expected_props, prop_list(2))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100332 " Delete a line above, text props must still be there.
333 1del
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100334 call assert_equal(expected_props, prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100335
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100336 " Prop without length or end column is zero length
337 call prop_clear(1)
Bram Moolenaar12f20032020-02-26 22:06:00 +0100338 call prop_type_add('included', {'start_incl': 1, 'end_incl': 1})
339 call prop_add(1, 5, #{type: 'included'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200340 let expected = [#{type_bufnr: 0, col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}]
Bram Moolenaar12f20032020-02-26 22:06:00 +0100341 call assert_equal(expected, prop_list(1))
342
343 " Inserting text makes the prop bigger.
344 exe "normal 5|ixx\<Esc>"
Martin Tournoije2390c72021-07-28 13:30:16 +0200345 let expected = [#{type_bufnr: 0, col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}]
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100346 call assert_equal(expected, prop_list(1))
347
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200348 call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
349
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100350 call DeletePropTypes()
Bram Moolenaar12f20032020-02-26 22:06:00 +0100351 call prop_type_delete('included')
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100352 bwipe!
353endfunc
354
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200355" Test for the prop_add_list() function
356func Test_prop_add_list()
357 new
358 call AddPropTypes()
359 call setline(1, ['one one one', 'two two two', 'six six six', 'ten ten ten'])
360 call prop_add_list(#{type: 'one', id: 2},
361 \ [[1, 1, 1, 3], [2, 5, 2, 7], [3, 6, 4, 6]])
362 call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
363 \ length: 2, start: 1}], prop_list(1))
364 call assert_equal([#{id: 2, col: 5, type_bufnr: 0, end: 1, type: 'one',
365 \ length: 2, start: 1}], prop_list(2))
366 call assert_equal([#{id: 2, col: 6, type_bufnr: 0, end: 0, type: 'one',
367 \ length: 7, start: 1}], prop_list(3))
368 call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
369 \ length: 5, start: 0}], prop_list(4))
Bram Moolenaard93009e2022-10-13 14:35:24 +0100370 call prop_remove(#{id: 2})
371 call assert_equal([], prop_list(1))
372
373 call prop_add_list(#{type: 'one', id: 3},
374 \ [[1, 1, 1, 3], [2, 5, 2, 7, 9]])
375 call assert_equal([#{id: 3, col: 1, type_bufnr: 0, end: 1, type: 'one',
376 \ length: 2, start: 1}], prop_list(1))
377 call assert_equal([#{id: 9, col: 5, type_bufnr: 0, end: 1, type: 'one',
378 \ length: 2, start: 1}], prop_list(2))
379
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200380 call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:')
381 call assert_fails('call prop_add_list({}, {})', 'E1211:')
382 call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:')
383 call assert_fails('call prop_add_list(#{type: "abc"}, [[1, 1, 1, 3]])', 'E971:')
384 call assert_fails('call prop_add_list(#{type: "one"}, [[]])', 'E474:')
385 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 1], {}])', 'E714:')
386 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, "a"]])', 'E474:')
387 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2]])', 'E474:')
388 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 2], [2, 2]])', 'E474:')
389 call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 2], [4, 1, 5, 2]])', 'E966:')
390 call assert_fails('call prop_add_list(#{type: "one"}, [[3, 1, 1, 2]])', 'E966:')
391 call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
392 call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
393 call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:')
Bram Moolenaard83392a2022-09-01 12:22:46 +0100394 call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E1298:')
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200395 call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:')
Christian Brabandt701c8632024-09-08 20:05:23 +0200396 call assert_fails('call prop_add_list(#{type: "one", id: 2147483648}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E1510:')
397 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 +0100398
399 " only one error for multiple wrong values
400 call assert_fails('call prop_add_list(#{type: "one"}, [[{}, [], 0z00, 0.3]])', ['E728:', 'E728:'])
Yegappan Lakshmananccfb7c62021-08-16 21:39:09 +0200401 call DeletePropTypes()
402 bw!
403endfunc
404
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100405func Test_prop_remove()
406 new
407 call AddPropTypes()
408 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100409 let props = Get_expected_props()
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100410 call assert_equal(props, prop_list(1))
411
412 " remove by id
Bram Moolenaara5a78822019-09-04 21:57:18 +0200413 call assert_equal(1, {'id': 12}->prop_remove(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100414 unlet props[2]
415 call assert_equal(props, prop_list(1))
416
417 " remove by type
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200418 call assert_equal(1, prop_remove({'type': 'one'}, 1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100419 unlet props[1]
420 call assert_equal(props, prop_list(1))
421
Bram Moolenaarf0884c52019-05-24 21:22:29 +0200422 " remove from unknown buffer
423 call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:')
424
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100425 call DeletePropTypes()
426 bwipe!
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100427
428 new
429 call AddPropTypes()
430 call SetupPropsInFirstLine()
431 call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
432 let props = Get_expected_props()
Martin Tournoije2390c72021-07-28 13:30:16 +0200433 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 +0100434 call assert_equal(props, prop_list(1))
435 call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
436 unlet props[3]
437 call assert_equal(props, prop_list(1))
438
Bram Moolenaare2e40752020-09-04 21:18:46 +0200439 call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:')
440 call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:')
Bram Moolenaar49b79bd2020-03-05 21:52:55 +0100441
442 call DeletePropTypes()
443 bwipe!
Ben Jacksona7704222022-08-20 20:54:51 +0100444
445 new
446 call AddPropTypes()
447 call SetupPropsInFirstLine()
448 let props = Get_expected_props() " [whole, one, two, three]
449 call assert_equal(props, prop_list(1))
450
451 " remove one by types
452 call assert_equal(1, prop_remove({'types': ['one', 'two', 'three']}, 1))
453 unlet props[1] " [whole, two, three]
454 call assert_equal(props, prop_list(1))
455
456 " remove 'all' by types
457 call assert_equal(2, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
458 unlet props[0] " [two, three]
459 unlet props[1] " [three]
460 call assert_equal(props, prop_list(1))
461
462 " remove none by types
463 call assert_equal(0, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
464 call assert_equal(props, prop_list(1))
465
466 " no types
467 call assert_fails("call prop_remove({'types': []}, 1)", 'E968:')
468 call assert_fails("call prop_remove({'types': ['not_a_real_type']}, 1)", 'E971:')
469
470 " only one of types and type can be supplied
471 call assert_fails("call prop_remove({'type': 'one', 'types': ['three'], 'all': 1}, 1)", 'E1295:')
472
473 call DeletePropTypes()
474 bwipe!
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100475endfunc
476
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200477def Test_prop_add_vim9()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100478 prop_type_add('comment', {
Bram Moolenaarfa2e38d2020-09-05 21:00:00 +0200479 highlight: 'Directory',
480 priority: 123,
481 start_incl: true,
482 end_incl: true,
483 combine: false,
484 })
485 prop_type_delete('comment')
486enddef
487
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200488def Test_prop_remove_vim9()
489 new
Bram Moolenaar62aec932022-01-29 21:45:34 +0000490 g:AddPropTypes()
491 g:SetupPropsInFirstLine()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100492 assert_equal(1, prop_remove({type: 'three', id: 13, both: true, all: true}))
Bram Moolenaar62aec932022-01-29 21:45:34 +0000493 g:DeletePropTypes()
Bram Moolenaara5a40c52020-09-05 20:50:49 +0200494 bwipe!
495enddef
496
Bram Moolenaar196d1572019-01-02 23:47:18 +0100497func SetupOneLine()
498 call setline(1, 'xonex xtwoxx')
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200499 normal gg0
Bram Moolenaar196d1572019-01-02 23:47:18 +0100500 call AddPropTypes()
501 call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'})
502 call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'})
503 let expected = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200504 \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1},
505 \ #{type_bufnr: 0, col: 8, length: 3, id: 12, type: 'two', start: 1, end: 1},
Bram Moolenaar196d1572019-01-02 23:47:18 +0100506 \]
507 call assert_equal(expected, prop_list(1))
508 return expected
509endfunc
510
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100511func Test_prop_add_remove_buf()
512 new
513 let bufnr = bufnr('')
514 call AddPropTypes()
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100515 for lnum in range(1, 4)
516 call setline(lnum, 'one two three')
517 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100518 wincmd w
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100519 for lnum in range(1, 4)
520 call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr})
521 call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr})
522 call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr})
523 endfor
524
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100525 let props = [
Martin Tournoije2390c72021-07-28 13:30:16 +0200526 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
527 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
528 \ #{type_bufnr: 0, col: 11, length: 3, id: 13, type: 'three', start: 1, end: 1},
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100529 \]
530 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100531
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100532 " remove by id
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100533 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100534 unlet props[1]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100535
536 call prop_remove({'id': 12, 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100537 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100538 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
539 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
540 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
541
542 call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4)
543 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
544 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
545 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
546 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
547
548 call prop_remove({'id': 12, 'bufnr': bufnr})
549 for lnum in range(1, 4)
550 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
551 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100552
553 " remove by type
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100554 let before_props = deepcopy(props)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100555 unlet props[0]
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100556
557 call prop_remove({'type': 'one', 'bufnr': bufnr}, 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100558 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar0a2f5782019-03-22 13:20:43 +0100559 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
560 call assert_equal(before_props, prop_list(3, {'bufnr': bufnr}))
561 call assert_equal(before_props, prop_list(4, {'bufnr': bufnr}))
562
563 call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4)
564 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
565 call assert_equal(before_props, prop_list(2, {'bufnr': bufnr}))
566 call assert_equal(props, prop_list(3, {'bufnr': bufnr}))
567 call assert_equal(props, prop_list(4, {'bufnr': bufnr}))
568
569 call prop_remove({'type': 'one', 'bufnr': bufnr})
570 for lnum in range(1, 4)
571 call assert_equal(props, prop_list(lnum, {'bufnr': bufnr}))
572 endfor
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100573
574 call DeletePropTypes()
575 wincmd w
576 bwipe!
577endfunc
578
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100579func Test_prop_backspace()
580 new
581 set bs=2
Bram Moolenaar196d1572019-01-02 23:47:18 +0100582 let expected = SetupOneLine() " 'xonex xtwoxx'
Bram Moolenaar33c8ca92019-01-02 18:00:27 +0100583
584 exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>"
585 call assert_equal('one xtwoxx', getline(1))
586 let expected[0].col = 1
587 let expected[1].col = 6
588 call assert_equal(expected, prop_list(1))
589
590 call DeletePropTypes()
591 bwipe!
592 set bs&
593endfunc
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100594
LemonBoyd0b1a092022-05-12 18:45:18 +0100595func Test_prop_change()
596 new
597 let expected = SetupOneLine() " 'xonex xtwoxx'
598
599 " Characterwise.
600 exe "normal 7|c$\<Esc>"
601 call assert_equal('xonex ', getline(1))
602 call assert_equal(expected[:0], prop_list(1))
603 " Linewise.
604 exe "normal cc\<Esc>"
605 call assert_equal('', getline(1))
606 call assert_equal([], prop_list(1))
607
608 call DeletePropTypes()
609 bwipe!
610 set bs&
611endfunc
612
Bram Moolenaar196d1572019-01-02 23:47:18 +0100613func Test_prop_replace()
614 new
615 set bs=2
616 let expected = SetupOneLine() " 'xonex xtwoxx'
617
618 exe "normal 0Ryyy\<Esc>"
619 call assert_equal('yyyex xtwoxx', getline(1))
620 call assert_equal(expected, prop_list(1))
621
622 exe "normal ftRyy\<BS>"
623 call assert_equal('yyyex xywoxx', getline(1))
624 call assert_equal(expected, prop_list(1))
625
626 exe "normal 0fwRyy\<BS>"
627 call assert_equal('yyyex xyyoxx', getline(1))
628 call assert_equal(expected, prop_list(1))
629
630 exe "normal 0foRyy\<BS>\<BS>"
631 call assert_equal('yyyex xyyoxx', getline(1))
632 call assert_equal(expected, prop_list(1))
633
LemonBoy0d534d92022-05-21 11:20:42 +0100634 " Replace three 1-byte chars with three 2-byte ones.
635 exe "normal 0l3rΓΈ"
636 call assert_equal('yΓΈΓΈΓΈx xyyoxx', getline(1))
637 let expected[0].length += 3
638 let expected[1].col += 3
639 call assert_equal(expected, prop_list(1))
640
Bram Moolenaar196d1572019-01-02 23:47:18 +0100641 call DeletePropTypes()
642 bwipe!
643 set bs&
644endfunc
645
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200646func Test_prop_open_line()
647 new
648
649 " open new line, props stay in top line
650 let expected = SetupOneLine() " 'xonex xtwoxx'
651 exe "normal o\<Esc>"
652 call assert_equal('xonex xtwoxx', getline(1))
653 call assert_equal('', getline(2))
654 call assert_equal(expected, prop_list(1))
655 call DeletePropTypes()
656
657 " move all props to next line
658 let expected = SetupOneLine() " 'xonex xtwoxx'
659 exe "normal 0i\<CR>\<Esc>"
660 call assert_equal('', getline(1))
661 call assert_equal('xonex xtwoxx', getline(2))
662 call assert_equal(expected, prop_list(2))
663 call DeletePropTypes()
664
665 " split just before prop, move all props to next line
666 let expected = SetupOneLine() " 'xonex xtwoxx'
667 exe "normal 0li\<CR>\<Esc>"
668 call assert_equal('x', getline(1))
669 call assert_equal('onex xtwoxx', getline(2))
670 let expected[0].col -= 1
671 let expected[1].col -= 1
672 call assert_equal(expected, prop_list(2))
673 call DeletePropTypes()
674
675 " split inside prop, split first prop
676 let expected = SetupOneLine() " 'xonex xtwoxx'
677 exe "normal 0lli\<CR>\<Esc>"
678 call assert_equal('xo', getline(1))
679 call assert_equal('nex xtwoxx', getline(2))
680 let exp_first = [deepcopy(expected[0])]
681 let exp_first[0].length = 1
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200682 let exp_first[0].end = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200683 call assert_equal(exp_first, prop_list(1))
684 let expected[0].col = 1
685 let expected[0].length = 2
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200686 let expected[0].start = 0
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200687 let expected[1].col -= 2
688 call assert_equal(expected, prop_list(2))
689 call DeletePropTypes()
690
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200691 " split just after first prop, second prop move to next line
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200692 let expected = SetupOneLine() " 'xonex xtwoxx'
693 exe "normal 0fea\<CR>\<Esc>"
694 call assert_equal('xone', getline(1))
695 call assert_equal('x xtwoxx', getline(2))
696 let exp_first = expected[0:0]
697 call assert_equal(exp_first, prop_list(1))
Bram Moolenaar5c65e6a2019-05-17 11:08:56 +0200698 let expected = expected[1:1]
699 let expected[0].col -= 4
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200700 call assert_equal(expected, prop_list(2))
701 call DeletePropTypes()
702
LemonBoy788c06a2022-05-14 18:48:05 +0100703 " split at the space character with 'ai' active, the leading space is removed
704 " in the second line and the prop is shifted accordingly.
705 let expected = SetupOneLine() " 'xonex xtwoxx'
706 set ai
707 exe "normal 6|i\<CR>\<Esc>"
708 call assert_equal('xonex', getline(1))
709 call assert_equal('xtwoxx', getline(2))
710 let expected[1].col -= 6
711 call assert_equal(expected, prop_list(1) + prop_list(2))
712 set ai&
713 call DeletePropTypes()
714
Bram Moolenaar45dd07f2019-05-15 22:45:37 +0200715 bwipe!
716 set bs&
717endfunc
718
Bram Moolenaarecb00c72022-08-07 14:55:14 +0100719func Test_prop_put()
720 new
721 let expected = SetupOneLine() " 'xonex xtwoxx'
722
723 let @a = 'new'
724 " insert just after the prop
725 normal 03l"ap
726 " insert inside the prop
727 normal 02l"ap
728 " insert just before the prop
729 normal 0"ap
730
731 call assert_equal('xnewonnewenewx xtwoxx', getline(1))
732 let expected[0].col += 3
733 let expected[0].length += 3
734 let expected[1].col += 9
735 call assert_equal(expected, prop_list(1))
736
737 " Visually select 4 chars in the prop and put "AB" to replace them
738 let @a = 'AB'
739 normal 05lv3l"ap
740 call assert_equal('xnewoABenewx xtwoxx', getline(1))
741 let expected[0].length -= 2
742 let expected[1].col -= 2
743 call assert_equal(expected, prop_list(1))
744
745 call DeletePropTypes()
746 bwipe!
747endfunc
748
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100749func Test_prop_clear()
750 new
751 call AddPropTypes()
752 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100753 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100754
Bram Moolenaara5a78822019-09-04 21:57:18 +0200755 eval 1->prop_clear()
756 call assert_equal([], 1->prop_list())
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100757
758 call DeletePropTypes()
759 bwipe!
760endfunc
761
762func Test_prop_clear_buf()
763 new
764 call AddPropTypes()
765 call SetupPropsInFirstLine()
766 let bufnr = bufnr('')
767 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100768 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100769
770 call prop_clear(1, 1, {'bufnr': bufnr})
771 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
772
773 wincmd w
774 call DeletePropTypes()
775 bwipe!
776endfunc
777
Bram Moolenaar21b50382019-01-04 18:07:24 +0100778func Test_prop_setline()
779 new
780 call AddPropTypes()
781 call SetupPropsInFirstLine()
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100782 call assert_equal(Get_expected_props(), prop_list(1))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100783
784 call setline(1, 'foobar')
785 call assert_equal([], prop_list(1))
786
787 call DeletePropTypes()
788 bwipe!
789endfunc
790
791func Test_prop_setbufline()
792 new
793 call AddPropTypes()
794 call SetupPropsInFirstLine()
795 let bufnr = bufnr('')
796 wincmd w
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100797 call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr}))
Bram Moolenaar21b50382019-01-04 18:07:24 +0100798
799 call setbufline(bufnr, 1, 'foobar')
800 call assert_equal([], prop_list(1, {'bufnr': bufnr}))
801
802 wincmd w
803 call DeletePropTypes()
804 bwipe!
805endfunc
806
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100807func Test_prop_substitute()
808 new
809 " Set first line to 'one two three'
810 call AddPropTypes()
811 call SetupPropsInFirstLine()
812 let expected_props = Get_expected_props()
813 call assert_equal(expected_props, prop_list(1))
814
815 " Change "n" in "one" to XX: 'oXXe two three'
816 s/n/XX/
817 let expected_props[0].length += 1
818 let expected_props[1].length += 1
819 let expected_props[2].col += 1
820 let expected_props[3].col += 1
821 call assert_equal(expected_props, prop_list(1))
822
823 " Delete "t" in "two" and "three" to XX: 'oXXe wo hree'
824 s/t//g
825 let expected_props[0].length -= 2
826 let expected_props[2].length -= 1
827 let expected_props[3].length -= 1
828 let expected_props[3].col -= 1
829 call assert_equal(expected_props, prop_list(1))
830
831 " Split the line by changing w to line break: 'oXXe ', 'o hree'
832 " The long prop is split and spans both lines.
833 " The props on "two" and "three" move to the next line.
834 s/w/\r/
835 let new_props = [
836 \ copy(expected_props[0]),
837 \ copy(expected_props[2]),
838 \ copy(expected_props[3]),
839 \ ]
840 let expected_props[0].length = 5
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200841 let expected_props[0].end = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100842 unlet expected_props[3]
843 unlet expected_props[2]
844 call assert_equal(expected_props, prop_list(1))
845
846 let new_props[0].length = 6
Bram Moolenaar87be9be2020-05-30 15:32:02 +0200847 let new_props[0].start = 0
Bram Moolenaar4164bb22019-01-04 23:09:49 +0100848 let new_props[1].col = 1
849 let new_props[1].length = 1
850 let new_props[2].col = 3
851 call assert_equal(new_props, prop_list(2))
852
853 call DeletePropTypes()
854 bwipe!
855endfunc
856
Bram Moolenaar663bc892019-01-08 23:07:24 +0100857func Test_prop_change_indent()
858 call prop_type_add('comment', {'highlight': 'Directory'})
859 new
860 call setline(1, [' xxx', 'yyyyy'])
861 call prop_add(2, 2, {'length': 2, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200862 let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0}
Bram Moolenaar663bc892019-01-08 23:07:24 +0100863 call assert_equal([expect], prop_list(2))
864
865 set shiftwidth=3
866 normal 2G>>
867 call assert_equal(' yyyyy', getline(2))
868 let expect.col += 3
869 call assert_equal([expect], prop_list(2))
870
871 normal 2G==
872 call assert_equal(' yyyyy', getline(2))
873 let expect.col = 6
874 call assert_equal([expect], prop_list(2))
875
876 call prop_clear(2)
877 call prop_add(2, 2, {'length': 5, 'type': 'comment'})
878 let expect.col = 2
879 let expect.length = 5
880 call assert_equal([expect], prop_list(2))
881
882 normal 2G<<
883 call assert_equal(' yyyyy', getline(2))
884 let expect.length = 2
885 call assert_equal([expect], prop_list(2))
886
887 set shiftwidth&
888 call prop_type_delete('comment')
889endfunc
890
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100891" Setup a three line prop in lines 2 - 4.
892" Add short props in line 1 and 5.
893func Setup_three_line_prop()
894 new
895 call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five'])
896 call prop_add(1, 2, {'length': 1, 'type': 'comment'})
897 call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'})
898 call prop_add(5, 2, {'length': 1, 'type': 'comment'})
899endfunc
900
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100901func Test_prop_multiline()
Bram Moolenaara5a78822019-09-04 21:57:18 +0200902 eval 'comment'->prop_type_add({'highlight': 'Directory'})
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100903 new
904 call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz'])
905
906 " start halfway line 1, end halfway line 3
907 call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +0200908 let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100909 call assert_equal([expect1], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200910 let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100911 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200912 let expect3 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100913 call assert_equal([expect3], prop_list(3))
914 call prop_clear(1, 3)
915
916 " include all three lines
917 call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'})
918 let expect1.col = 1
919 let expect1.length = 8
920 call assert_equal([expect1], prop_list(1))
921 call assert_equal([expect2], prop_list(2))
922 let expect3.length = 9
923 call assert_equal([expect3], prop_list(3))
924 call prop_clear(1, 3)
925
926 bwipe!
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100927
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100928 " Test deleting the first line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100929 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200930 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 +0100931 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200932 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100933 call assert_equal([expect2], prop_list(2))
934 2del
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100935 call assert_equal([expect_short], prop_list(1))
Martin Tournoije2390c72021-07-28 13:30:16 +0200936 let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100937 call assert_equal([expect2], prop_list(2))
938 bwipe!
939
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100940 " Test deleting the last line of a multi-line prop.
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100941 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200942 let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100943 call assert_equal([expect3], prop_list(3))
Martin Tournoije2390c72021-07-28 13:30:16 +0200944 let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100945 call assert_equal([expect4], prop_list(4))
946 4del
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100947 let expect3.end = 1
Bram Moolenaarc1a9bc12018-12-28 21:59:29 +0100948 call assert_equal([expect3], prop_list(3))
949 call assert_equal([expect_short], prop_list(4))
950 bwipe!
951
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100952 " Test appending a line below the multi-line text prop start.
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100953 call Setup_three_line_prop()
Martin Tournoije2390c72021-07-28 13:30:16 +0200954 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100955 call assert_equal([expect2], prop_list(2))
956 call append(2, "new line")
957 call assert_equal([expect2], prop_list(2))
Martin Tournoije2390c72021-07-28 13:30:16 +0200958 let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0}
Bram Moolenaarb56ac042018-12-28 23:22:40 +0100959 call assert_equal([expect3], prop_list(3))
960 bwipe!
961
Bram Moolenaare3d31b02018-12-24 23:07:04 +0100962 call prop_type_delete('comment')
963endfunc
964
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100965func Run_test_with_line2byte(add_props)
966 new
967 setlocal ff=unix
968 if a:add_props
969 call prop_type_add('textprop', #{highlight: 'Search'})
970 endif
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100971 " Add a text prop to every fourth line and then change every fifth line so
972 " that it causes a data block split a few times.
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100973 for nr in range(1, 1000)
974 call setline(nr, 'some longer text here')
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100975 if a:add_props && nr % 4 == 0
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100976 call prop_add(nr, 13, #{type: 'textprop', length: 4})
977 endif
978 endfor
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100979 let expected = 22 * 997 + 1
980 call assert_equal(expected, line2byte(998))
981
982 for nr in range(1, 1000, 5)
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100983 exe nr .. "s/longer/much more/"
Bram Moolenaare5a0e8c2022-08-09 21:37:55 +0100984 let expected += 3
985 call assert_equal(expected, line2byte(998), 'line ' .. nr)
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100986 endfor
Bram Moolenaarcf85d972022-08-08 14:59:47 +0100987
988 if a:add_props
989 call prop_type_delete('textprop')
990 endif
991 bwipe!
992endfunc
993
Bram Moolenaar9df53b62020-01-13 20:40:51 +0100994func Test_prop_line2byte()
Bram Moolenaarb413d2e2018-12-25 23:15:46 +0100995 call prop_type_add('comment', {'highlight': 'Directory'})
996 new
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100997 call setline(1, ['line1', 'second line', ''])
Bram Moolenaar8cf734e2018-12-26 01:09:00 +0100998 set ff=unix
Bram Moolenaar00b1e042018-12-26 23:42:10 +0100999 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01001000 call prop_add(1, 1, {'end_col': 3, 'type': 'comment'})
Bram Moolenaar00b1e042018-12-26 23:42:10 +01001001 call assert_equal(19, line2byte(3))
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01001002 bwipe!
Bram Moolenaar14c75302021-08-15 14:28:40 +02001003
1004 new
Bram Moolenaara401bba2021-08-15 15:04:41 +02001005 setlocal ff=unix
Bram Moolenaar14c75302021-08-15 14:28:40 +02001006 call setline(1, range(500))
1007 call assert_equal(1491, line2byte(401))
1008 call prop_add(2, 1, {'type': 'comment'})
1009 call prop_add(222, 1, {'type': 'comment'})
1010 call assert_equal(1491, line2byte(401))
1011 call prop_remove({'type': 'comment'})
1012 call assert_equal(1491, line2byte(401))
1013 bwipe!
1014
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +02001015 new
Bram Moolenaar49b93042021-08-25 17:02:00 +02001016 setlocal ff=unix
Bram Moolenaarcdd8a5e2021-08-25 16:40:03 +02001017 call setline(1, range(520))
1018 call assert_equal(1491, line2byte(401))
1019 call prop_add(2, 1, {'type': 'comment'})
1020 call assert_equal(1491, line2byte(401))
1021 2delete
1022 call assert_equal(1489, line2byte(400))
1023 bwipe!
1024
Bram Moolenaarcf85d972022-08-08 14:59:47 +01001025 " Add many lines so that the data block is split.
1026 " With and without props should give the same result.
1027 call Run_test_with_line2byte(0)
1028 call Run_test_with_line2byte(1)
1029
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01001030 call prop_type_delete('comment')
1031endfunc
1032
Bram Moolenaar9df53b62020-01-13 20:40:51 +01001033func Test_prop_byte2line()
1034 new
1035 set ff=unix
1036 call setline(1, ['one one', 'two two', 'three three', 'four four', 'five'])
1037 call assert_equal(4, byte2line(line2byte(4)))
1038 call assert_equal(5, byte2line(line2byte(5)))
1039
1040 call prop_type_add('prop', {'highlight': 'Directory'})
1041 call prop_add(3, 1, {'length': 5, 'type': 'prop'})
1042 call assert_equal(4, byte2line(line2byte(4)))
1043 call assert_equal(5, byte2line(line2byte(5)))
1044
1045 bwipe!
1046 call prop_type_delete('prop')
1047endfunc
1048
Bram Moolenaar59ff6402021-01-30 17:16:28 +01001049func Test_prop_goto_byte()
1050 new
1051 call setline(1, '')
1052 call setline(2, 'two three')
1053 call setline(3, '')
1054 call setline(4, 'four five')
1055
1056 call prop_type_add('testprop', {'highlight': 'Directory'})
1057 call search('^two')
1058 call prop_add(line('.'), col('.'), {
1059 \ 'length': len('two'),
1060 \ 'type': 'testprop'
1061 \ })
1062
1063 call search('two \zsthree')
1064 let expected_pos = line2byte(line('.')) + col('.') - 1
1065 exe expected_pos .. 'goto'
1066 let actual_pos = line2byte(line('.')) + col('.') - 1
1067 eval actual_pos->assert_equal(expected_pos)
1068
1069 call search('four \zsfive')
1070 let expected_pos = line2byte(line('.')) + col('.') - 1
1071 exe expected_pos .. 'goto'
1072 let actual_pos = line2byte(line('.')) + col('.') - 1
1073 eval actual_pos->assert_equal(expected_pos)
1074
1075 call prop_type_delete('testprop')
1076 bwipe!
1077endfunc
1078
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001079func Test_prop_undo()
1080 new
1081 call prop_type_add('comment', {'highlight': 'Directory'})
1082 call setline(1, ['oneone', 'twotwo', 'three'])
1083 " Set 'undolevels' to break changes into undo-able pieces.
1084 set ul&
1085
1086 call prop_add(1, 3, {'end_col': 5, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001087 let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}]
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001088 call assert_equal(expected, prop_list(1))
1089
1090 " Insert a character, then undo.
1091 exe "normal 0lllix\<Esc>"
1092 set ul&
1093 let expected[0].length = 3
1094 call assert_equal(expected, prop_list(1))
1095 undo
1096 let expected[0].length = 2
1097 call assert_equal(expected, prop_list(1))
1098
1099 " Delete a character, then undo
1100 exe "normal 0lllx"
1101 set ul&
1102 let expected[0].length = 1
1103 call assert_equal(expected, prop_list(1))
1104 undo
1105 let expected[0].length = 2
1106 call assert_equal(expected, prop_list(1))
1107
1108 " Delete the line, then undo
1109 1d
1110 set ul&
1111 call assert_equal([], prop_list(1))
1112 undo
1113 call assert_equal(expected, prop_list(1))
1114
1115 " Insert a character, delete two characters, then undo with "U"
1116 exe "normal 0lllix\<Esc>"
1117 set ul&
1118 let expected[0].length = 3
1119 call assert_equal(expected, prop_list(1))
1120 exe "normal 0lllxx"
1121 set ul&
1122 let expected[0].length = 1
1123 call assert_equal(expected, prop_list(1))
1124 normal U
1125 let expected[0].length = 2
1126 call assert_equal(expected, prop_list(1))
1127
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001128 " substitute a word, then undo
1129 call setline(1, 'the number 123 is highlighted.')
1130 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001131 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001132 call assert_equal(expected, prop_list(1))
1133 set ul&
1134 1s/number/foo
1135 let expected[0].col = 9
1136 call assert_equal(expected, prop_list(1))
1137 undo
1138 let expected[0].col = 12
1139 call assert_equal(expected, prop_list(1))
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001140 call prop_clear(1)
1141
1142 " substitute with backslash
1143 call setline(1, 'the number 123 is highlighted.')
1144 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001145 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarf3333b02019-05-19 22:53:40 +02001146 call assert_equal(expected, prop_list(1))
1147 1s/the/\The
1148 call assert_equal(expected, prop_list(1))
1149 1s/^/\\
1150 let expected[0].col += 1
1151 call assert_equal(expected, prop_list(1))
1152 1s/^/\~
1153 let expected[0].col += 1
1154 call assert_equal(expected, prop_list(1))
1155 1s/123/12\\3
1156 let expected[0].length += 1
1157 call assert_equal(expected, prop_list(1))
1158 call prop_clear(1)
Bram Moolenaar338dfda2019-05-19 15:19:57 +02001159
Bram Moolenaar7f1664e2019-01-04 17:21:24 +01001160 bwipe!
1161 call prop_type_delete('comment')
1162endfunc
1163
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001164func Test_prop_delete_text()
1165 new
1166 call prop_type_add('comment', {'highlight': 'Directory'})
1167 call setline(1, ['oneone', 'twotwo', 'three'])
1168
1169 " zero length property
1170 call prop_add(1, 3, {'type': 'comment'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001171 let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001172 call assert_equal(expected, prop_list(1))
1173
1174 " delete one char moves the property
1175 normal! x
Martin Tournoije2390c72021-07-28 13:30:16 +02001176 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001177 call assert_equal(expected, prop_list(1))
1178
1179 " delete char of the property has no effect
1180 normal! lx
Martin Tournoije2390c72021-07-28 13:30:16 +02001181 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001182 call assert_equal(expected, prop_list(1))
1183
1184 " delete more chars moves property to first column, is not deleted
1185 normal! 0xxxx
Martin Tournoije2390c72021-07-28 13:30:16 +02001186 let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
Bram Moolenaarecafcc12019-11-16 20:41:51 +01001187 call assert_equal(expected, prop_list(1))
1188
1189 bwipe!
1190 call prop_type_delete('comment')
1191endfunc
1192
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001193" screenshot test with textprop highlighting
Bram Moolenaar8055d172019-05-17 22:57:26 +02001194func Test_textprop_screenshot_various()
Bram Moolenaar34390282019-10-16 14:38:26 +02001195 CheckScreendump
Bram Moolenaared79d1e2019-02-22 14:38:58 +01001196 " The Vim running in the terminal needs to use utf-8.
Bram Moolenaar34390282019-10-16 14:38:26 +02001197 if g:orig_encoding != 'utf-8'
1198 throw 'Skipped: not using utf-8'
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001199 endif
1200 call writefile([
Bram Moolenaarde24a872019-05-05 15:48:00 +02001201 \ "call setline(1, ["
1202 \ .. "'One two',"
1203 \ .. "'NumbΓ©r 123 Γ€nd thΕ“n 4ΒΎ7.',"
1204 \ .. "'--aa--bb--cc--dd--',"
1205 \ .. "'// comment with error in it',"
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001206 \ .. "'first line',"
1207 \ .. "' second line ',"
1208 \ .. "'third line',"
1209 \ .. "' fourth line',"
Bram Moolenaarde24a872019-05-05 15:48:00 +02001210 \ .. "])",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001211 \ "hi NumberProp ctermfg=blue",
1212 \ "hi LongProp ctermbg=yellow",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001213 \ "hi BackgroundProp ctermbg=lightgrey",
1214 \ "hi UnderlineProp cterm=underline",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001215 \ "call prop_type_add('number', {'highlight': 'NumberProp'})",
Bram Moolenaara5a78822019-09-04 21:57:18 +02001216 \ "call prop_type_add('long', {'highlight': 'NumberProp'})",
1217 \ "call prop_type_change('long', {'highlight': 'LongProp'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001218 \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})",
1219 \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})",
1220 \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001221 \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})",
1222 \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})",
1223 \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})",
Bram Moolenaar58e32ab2019-11-12 22:44:22 +01001224 \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001225 \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001226 \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
1227 \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001228 \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})",
1229 \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})",
1230 \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})",
1231 \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})",
Bram Moolenaardbd43162019-11-09 21:28:14 +01001232 \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})",
1233 \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001234 \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001235 \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})",
1236 \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})",
1237 \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})",
1238 \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})",
Bram Moolenaarbfd45122019-05-17 13:05:07 +02001239 \ "set number cursorline",
Bram Moolenaarb9c67a52019-01-01 19:49:20 +01001240 \ "hi clear SpellBad",
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001241 \ "set spell",
Bram Moolenaarde24a872019-05-05 15:48:00 +02001242 \ "syn match Comment '//.*'",
1243 \ "hi Comment ctermfg=green",
Bram Moolenaar44746aa2019-01-02 00:02:11 +01001244 \ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>",
Bram Moolenaar33c8ca92019-01-02 18:00:27 +01001245 \ "normal 3G0lli\<BS>\<Esc>",
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001246 \ "normal 6G0i\<BS>\<Esc>",
1247 \ "normal 3J",
1248 \ "normal 3G",
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001249 \], 'XtestProp', 'D')
Bram Moolenaar80e737c2019-05-17 19:56:34 +02001250 let buf = RunVimInTerminal('-S XtestProp', {'rows': 8})
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001251 call VerifyScreenDump(buf, 'Test_textprop_01', {})
Bram Moolenaare3d31b02018-12-24 23:07:04 +01001252
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001253 " clean up
1254 call StopVimInTerminal(buf)
Bram Moolenaarc6d86dc2018-12-31 13:57:36 +01001255endfunc
Bram Moolenaar8055d172019-05-17 22:57:26 +02001256
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +01001257func Test_textprop_hl_override()
1258 CheckScreendump
1259
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)
1289 call writefile([
1290 \ "call setline(1, ["
1291 \ .. "'xxxxxxxxx 123 x',"
1292 \ .. "'xxxxxxxx 123 x',"
1293 \ .. "'xxxxxxx 123 x',"
1294 \ .. "'xxxxxx 123 x',"
1295 \ .. "'xxxxx 123 x',"
1296 \ .. "'xxxx 123 xx',"
1297 \ .. "'xxx 123 xxx',"
1298 \ .. "'xx 123 xxxx',"
1299 \ .. "'x 123 xxxxx',"
1300 \ .. "' 123 xxxxxx',"
1301 \ .. "])",
1302 \ "hi SearchProp ctermbg=yellow",
1303 \ "call prop_type_add('search', {'highlight': 'SearchProp'})",
1304 \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})",
1305 \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})",
1306 \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})",
1307 \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})",
1308 \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})",
1309 \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})",
1310 \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})",
1311 \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})",
1312 \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})",
1313 \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})",
1314 \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx",
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001315 \], 'XtestPropVis', 'D')
Bram Moolenaar8055d172019-05-17 22:57:26 +02001316 let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12})
1317 call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {})
1318
1319 " clean up
1320 call StopVimInTerminal(buf)
Bram Moolenaar8055d172019-05-17 22:57:26 +02001321endfunc
1322
1323" screenshot test with Visual block mode operations
1324func Test_textprop_screenshot_visual()
Bram Moolenaar34390282019-10-16 14:38:26 +02001325 CheckScreendump
Bram Moolenaar8055d172019-05-17 22:57:26 +02001326
1327 " Delete two columns while text props are three chars wide.
1328 call RunTestVisualBlock(2, '01')
1329
1330 " Same, but delete four columns
1331 call RunTestVisualBlock(4, '02')
1332endfunc
Bram Moolenaard79eef22019-05-24 20:41:55 +02001333
Bram Moolenaara956bf62019-06-19 17:34:24 +02001334func Test_textprop_after_tab()
Bram Moolenaar34390282019-10-16 14:38:26 +02001335 CheckScreendump
Bram Moolenaar37e66cf2019-06-19 18:16:10 +02001336
Bram Moolenaara956bf62019-06-19 17:34:24 +02001337 let lines =<< trim END
1338 call setline(1, [
1339 \ "\txxx",
1340 \ "x\txxx",
1341 \ ])
1342 hi SearchProp ctermbg=yellow
1343 call prop_type_add('search', {'highlight': 'SearchProp'})
1344 call prop_add(1, 2, {'length': 3, 'type': 'search'})
1345 call prop_add(2, 3, {'length': 3, 'type': 'search'})
1346 END
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00001347 call writefile(lines, 'XtextPropTab', 'D')
1348 let buf = RunVimInTerminal('-S XtextPropTab', {'rows': 6})
Bram Moolenaara956bf62019-06-19 17:34:24 +02001349 call VerifyScreenDump(buf, 'Test_textprop_tab', {})
1350
1351 " clean up
1352 call StopVimInTerminal(buf)
Bram Moolenaara956bf62019-06-19 17:34:24 +02001353endfunc
1354
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00001355func Test_textprop_nesting()
1356 CheckScreendump
1357
1358 let lines =<< trim END
1359 vim9script
1360 var lines =<< trim LINESEND
1361
1362 const func: func.IFunction = ({
1363 setLoading
1364 }) => {
1365 LINESEND
1366 setline(1, lines)
1367 prop_type_add('prop_add_test', {highlight: "ErrorMsg"})
1368 prop_add(2, 31, {type: 'prop_add_test', end_lnum: 4, end_col: 2})
1369 var text = 'text long enough to wrap line, text long enough to wrap line, text long enough to wrap line...'
1370 prop_add(2, 0, {type: 'prop_add_test', text_wrap: 'truncate', text_align: 'after', text: text})
1371 END
1372 call writefile(lines, 'XtextpropNesting', 'D')
1373 let buf = RunVimInTerminal('-S XtextpropNesting', {'rows': 8})
1374 call VerifyScreenDump(buf, 'Test_textprop_nesting', {})
1375
1376 " clean up
1377 call StopVimInTerminal(buf)
1378endfunc
1379
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001380func Test_textprop_nowrap_scrolled()
1381 CheckScreendump
1382
1383 let lines =<< trim END
1384 vim9script
1385 set nowrap
1386 setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns))
1387 prop_type_add('number', {'highlight': 'ErrorMsg'})
1388 prop_add(1, 12, {'length': 3, 'type': 'number'})
1389 prop_add(1, 32, {'length': 4, 'type': 'number'})
1390 feedkeys('gg20zl', 'nxt')
1391 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001392 call writefile(lines, 'XtestNowrap', 'D')
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001393 let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6})
1394 call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {})
1395
1396 call term_sendkeys(buf, "$")
1397 call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {})
1398
1399 " clean up
1400 call StopVimInTerminal(buf)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001401endfunc
1402
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001403func Test_textprop_text_priority()
1404 CheckScreendump
1405
1406 let lines =<< trim END
1407 call setline(1, "function( call, argument, here )")
1408
1409 call prop_type_add('one', #{highlight: 'Error'})
1410 call prop_type_add('two', #{highlight: 'Function'})
1411 call prop_type_add('three', #{highlight: 'DiffChange'})
1412 call prop_type_add('arg', #{highlight: 'Search'})
1413
1414 call prop_add(1, 27, #{type: 'arg', length: len('here')})
1415 call prop_add(1, 27, #{type: 'three', text: 'three: '})
1416 call prop_add(1, 11, #{type: 'one', text: 'one: '})
1417 call prop_add(1, 11, #{type: 'arg', length: len('call')})
1418 call prop_add(1, 17, #{type: 'two', text: 'two: '})
1419 call prop_add(1, 17, #{type: 'arg', length: len('argument')})
1420 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001421 call writefile(lines, 'XtestPropPrio', 'D')
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001422 let buf = RunVimInTerminal('-S XtestPropPrio', {'rows': 5})
1423 call VerifyScreenDump(buf, 'Test_prop_at_same_pos', {})
1424
1425 " clean up
1426 call StopVimInTerminal(buf)
Bram Moolenaar952c9b02022-08-10 16:00:33 +01001427endfunc
1428
zeertzjq4e26a9a2023-12-03 17:50:47 +01001429func Test_textprop_in_empty_popup()
1430 CheckScreendump
1431
1432 let lines =<< trim END
1433 vim9script
1434
1435 hi def link FilterMenuMatch Constant
1436 prop_type_add('FilterMenuMatch', {
1437 highlight: "FilterMenuMatch",
1438 override: true,
1439 priority: 1000,
1440 combine: true,
1441 })
1442
1443 var winid = popup_create([{text: "hello", props: [
1444 {col: 1, length: 1, type: 'FilterMenuMatch'},
1445 {col: 2, length: 1, type: 'FilterMenuMatch'},
1446 ]}], {
1447 minwidth: 20,
1448 minheight: 10,
1449 cursorline: false,
1450 highlight: "None",
1451 border: [],
1452 })
1453
1454 win_execute(winid, "setl nu cursorline cursorlineopt=both")
1455 popup_settext(winid, [])
1456 redraw
1457 END
1458 call writefile(lines, 'XtestPropEmptyPopup', 'D')
1459 let buf = RunVimInTerminal('-S XtestPropEmptyPopup', #{rows: 20, cols: 40})
1460 call VerifyScreenDump(buf, 'Test_prop_in_empty_popup', {})
1461
1462 " clean up
1463 call StopVimInTerminal(buf)
1464endfunc
1465
Bram Moolenaar34390282019-10-16 14:38:26 +02001466func Test_textprop_with_syntax()
1467 CheckScreendump
1468
1469 let lines =<< trim END
1470 call setline(1, [
1471 \ "(abc)",
1472 \ ])
1473 syn match csParens "[()]" display
1474 hi! link csParens MatchParen
1475
1476 call prop_type_add('TPTitle', #{ highlight: 'Title' })
1477 call prop_add(1, 2, #{type: 'TPTitle', end_col: 5})
1478 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01001479 call writefile(lines, 'XtestPropSyn', 'D')
Bram Moolenaar34390282019-10-16 14:38:26 +02001480 let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6})
1481 call VerifyScreenDump(buf, 'Test_textprop_syn_1', {})
1482
1483 " clean up
1484 call StopVimInTerminal(buf)
Bram Moolenaar34390282019-10-16 14:38:26 +02001485endfunc
1486
Bram Moolenaard79eef22019-05-24 20:41:55 +02001487" Adding a text property to a new buffer should not fail
1488func Test_textprop_empty_buffer()
1489 call prop_type_add('comment', {'highlight': 'Search'})
1490 new
1491 call prop_add(1, 1, {'type': 'comment'})
1492 close
Bram Moolenaaradfde112019-05-25 22:11:45 +02001493 call prop_type_delete('comment')
1494endfunc
1495
Bram Moolenaard74af422019-06-28 21:38:00 +02001496" Adding a text property with invalid highlight should be ignored.
1497func Test_textprop_invalid_highlight()
1498 call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:')
1499 new
Ben Jacksona7704222022-08-20 20:54:51 +01001500 call setline(1, ['asdf', 'asdf'])
Bram Moolenaard74af422019-06-28 21:38:00 +02001501 call prop_add(1, 1, {'length': 4, 'type': 'dni'})
1502 redraw
1503 bwipe!
1504 call prop_type_delete('dni')
1505endfunc
1506
Bram Moolenaaradfde112019-05-25 22:11:45 +02001507" Adding a text property to an empty buffer and then editing another
1508func Test_textprop_empty_buffer_next()
1509 call prop_type_add("xxx", {})
1510 call prop_add(1, 1, {"type": "xxx"})
1511 next X
1512 call prop_type_delete('xxx')
Bram Moolenaard79eef22019-05-24 20:41:55 +02001513endfunc
Bram Moolenaarf0884c52019-05-24 21:22:29 +02001514
1515func Test_textprop_remove_from_buf()
1516 new
1517 let buf = bufnr('')
1518 call prop_type_add('one', {'bufnr': buf})
1519 call prop_add(1, 1, {'type': 'one', 'id': 234})
1520 file x
1521 edit y
1522 call prop_remove({'id': 234, 'bufnr': buf}, 1)
1523 call prop_type_delete('one', {'bufnr': buf})
1524 bwipe! x
1525 close
1526endfunc
Bram Moolenaar45311b52019-08-13 22:27:32 +02001527
1528func Test_textprop_in_unloaded_buf()
1529 edit Xaaa
1530 call setline(1, 'aaa')
1531 write
1532 edit Xbbb
1533 call setline(1, 'bbb')
1534 write
1535 let bnr = bufnr('')
1536 edit Xaaa
1537
1538 call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'})
1539 call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:')
1540 exe 'buf ' .. bnr
1541 call assert_equal('bbb', getline(1))
1542 call assert_equal(0, prop_list(1)->len())
1543
1544 bwipe! Xaaa
1545 bwipe! Xbbb
1546 cal delete('Xaaa')
1547 cal delete('Xbbb')
1548endfunc
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001549
1550func Test_proptype_substitute2()
1551 new
1552 " text_prop.vim
1553 call setline(1, [
1554 \ 'The num 123 is smaller than 4567.',
1555 \ '123 The number 123 is smaller than 4567.',
1556 \ '123 The number 123 is smaller than 4567.'])
1557
1558 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1559
1560 call prop_add(1, 12, {'length': 3, 'type': 'number'})
1561 call prop_add(2, 1, {'length': 3, 'type': 'number'})
1562 call prop_add(3, 36, {'length': 4, 'type': 'number'})
1563 set ul&
Martin Tournoije2390c72021-07-28 13:30:16 +02001564 let expected = [
1565 \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1},
1566 \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1},
1567 \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}]
1568
1569 " TODO
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001570 if 0
1571 " Add some text in between
1572 %s/\s\+/ /g
1573 call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001574
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001575 " remove some text
1576 :1s/[a-z]\{3\}//g
1577 let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
1578 call assert_equal(expected, prop_list(1))
1579 endif
1580
1581 call prop_type_delete('number')
Bram Moolenaar1fd30d72019-10-25 22:13:29 +02001582 bwipe!
1583endfunc
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001584
Bram Moolenaar8902b312020-09-20 21:04:35 +02001585" This was causing property corruption.
1586func Test_proptype_substitute3()
1587 new
1588 call setline(1, ['abcxxx', 'def'])
1589 call prop_type_add("test", {"highlight": "Search"})
1590 call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"})
1591 %s/x\+$//
1592 redraw
1593
1594 call prop_type_delete('test')
1595 bwipe!
1596endfunc
1597
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001598func Test_proptype_substitute_join()
1599 new
1600 call setline(1, [
1601 \ 'This is some end',
1602 \ 'start is highlighted end',
1603 \ 'some is highlighted',
1604 \ 'start is also highlighted'])
1605
1606 call prop_type_add('number', {'highlight': 'ErrorMsg'})
1607
1608 call prop_add(1, 6, {'length': 2, 'type': 'number'})
1609 call prop_add(2, 7, {'length': 2, 'type': 'number'})
1610 call prop_add(3, 6, {'length': 2, 'type': 'number'})
1611 call prop_add(4, 7, {'length': 2, 'type': 'number'})
Dominique Pelleb49dfd02023-04-14 21:54:25 +01001612 " The highlighted "is" in line 1, 2 and 4 is kept and adjusted.
Bram Moolenaar213bbaf2022-08-05 19:46:48 +01001613 " The highlighted "is" in line 3 is deleted.
1614 let expected = [
1615 \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1},
1616 \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1},
1617 \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}]
1618
1619 s/end\nstart/joined/
1620 s/end\n.*\nstart/joined/
1621 call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1))
1622 call assert_equal(expected, prop_list(1))
1623
1624 call prop_type_delete('number')
1625 bwipe!
1626endfunc
1627
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001628func SaveOptions()
1629 let d = #{tabstop: &tabstop,
1630 \ softtabstop: &softtabstop,
1631 \ shiftwidth: &shiftwidth,
1632 \ expandtab: &expandtab,
1633 \ foldmethod: '"' .. &foldmethod .. '"',
1634 \ }
1635 return d
1636endfunc
1637
1638func RestoreOptions(dict)
1639 for name in keys(a:dict)
1640 exe 'let &' .. name .. ' = ' .. a:dict[name]
1641 endfor
1642endfunc
1643
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001644func Test_textprop_noexpandtab()
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001645 new
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001646 let save_dict = SaveOptions()
1647
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001648 set tabstop=8
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001649 set softtabstop=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001650 set shiftwidth=4
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001651 set noexpandtab
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001652 set foldmethod=marker
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001653
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001654 call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx")
1655 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1656 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1657 call feedkeys("0i\<tab>", "tx")
1658 call prop_remove({'type': 'test'})
1659 call prop_add(1, 2, {'end_col': 3, 'type': 'test'})
1660 call feedkeys("A\<left>\<tab>", "tx")
1661 call prop_remove({'type': 'test'})
1662 try
1663 " It is correct that this does not pass
1664 call prop_add(1, 6, {'end_col': 7, 'type': 'test'})
1665 " Has already collapsed here, start_col:6 does not result in an error
1666 call feedkeys("A\<left>\<tab>", "tx")
1667 catch /^Vim\%((\a\+)\)\=:E964/
1668 endtry
1669 call prop_remove({'type': 'test'})
Bram Moolenaarac15fd82020-01-09 21:35:48 +01001670 call prop_type_delete('test')
1671
1672 call RestoreOptions(save_dict)
1673 bwipe!
1674endfunc
1675
1676func Test_textprop_noexpandtab_redraw()
1677 new
1678 let save_dict = SaveOptions()
1679
1680 set tabstop=8
1681 set softtabstop=4
1682 set shiftwidth=4
1683 set noexpandtab
1684 set foldmethod=marker
1685
1686 call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx")
1687 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1688 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1689 call feedkeys("0i\<tab>", "tx")
1690 " Internally broken at the next line
1691 call feedkeys("A\<left>\<tab>", "tx")
1692 redraw
1693 " Index calculation failed internally on next line
1694 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1695 call prop_remove({'type': 'test', 'all': v:true})
1696 call prop_type_delete('test')
1697 call prop_type_delete('test')
1698
1699 call RestoreOptions(save_dict)
1700 bwipe!
1701endfunc
1702
1703func Test_textprop_ins_str()
1704 new
1705 call setline(1, 'just some text')
1706 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1707 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
Martin Tournoije2390c72021-07-28 13:30:16 +02001708 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 +01001709
1710 call feedkeys("foi\<F8>\<Esc>", "tx")
1711 call assert_equal('just s<F8>ome text', getline(1))
Martin Tournoije2390c72021-07-28 13:30:16 +02001712 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 +01001713
1714 bwipe!
1715 call prop_remove({'type': 'test'})
1716 call prop_type_delete('test')
Bram Moolenaar5cb0b932020-01-03 21:25:59 +01001717endfunc
Bram Moolenaar66b98852020-03-11 19:15:52 +01001718
1719func Test_find_prop_later_in_line()
1720 new
1721 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1722 call setline(1, 'just some text')
1723 call prop_add(1, 1, {'length': 4, 'type': 'test'})
1724 call prop_add(1, 10, {'length': 3, 'type': 'test'})
1725
Martin Tournoije2390c72021-07-28 13:30:16 +02001726 call assert_equal(
1727 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1},
1728 \ prop_find(#{type: 'test', lnum: 1, col: 6}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001729
1730 bwipe!
1731 call prop_type_delete('test')
1732endfunc
1733
1734func Test_find_zerowidth_prop_sol()
1735 new
1736 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1737 call setline(1, 'just some text')
1738 call prop_add(1, 1, {'length': 0, 'type': 'test'})
1739
Martin Tournoije2390c72021-07-28 13:30:16 +02001740 call assert_equal(
1741 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1},
1742 \ prop_find(#{type: 'test', lnum: 1}))
Bram Moolenaar66b98852020-03-11 19:15:52 +01001743
1744 bwipe!
1745 call prop_type_delete('test')
1746endfunc
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001747
1748" Test for passing invalid arguments to prop_xxx() functions
1749func Test_prop_func_invalid_args()
1750 call assert_fails('call prop_clear(1, 2, [])', 'E715:')
1751 call assert_fails('call prop_clear(-1, 2)', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001752 call assert_fails('call prop_find(test_null_dict())', 'E1297:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001753 call assert_fails('call prop_find({"bufnr" : []})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001754 call assert_fails('call prop_find({})', 'E968:')
1755 call assert_fails('call prop_find({}, "x")', 'E474:')
1756 call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001757 call assert_fails('call prop_list(1, [])', 'E1206:')
Bram Moolenaar9d489562020-07-30 20:08:50 +02001758 call assert_fails('call prop_list(-1, {})', 'E16:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001759 call assert_fails('call prop_remove([])', 'E1206:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001760 call assert_fails('call prop_remove({}, -2)', 'E16:')
1761 call assert_fails('call prop_remove({})', 'E968:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001762 call assert_fails('call prop_type_add([], {})', 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001763 call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001764 call assert_fails("call prop_type_delete([])", 'E730:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001765 call assert_fails("call prop_type_delete('xyz', [])", 'E715:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001766 call assert_fails("call prop_type_get([])", 'E730:')
Bram Moolenaar89469d12022-12-02 20:46:26 +00001767 call assert_fails("call prop_type_get('', [])", 'E475:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001768 call assert_fails("call prop_type_list([])", 'E715:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001769 call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:')
1770 call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:')
1771 call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:')
Yegappan Lakshmanan04c4c572022-08-30 19:48:24 +01001772 call assert_fails('call prop_add(1, 1, 0)', 'E1206:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001773
1774 new
1775 call setline(1, ['first', 'second'])
1776 call prop_type_add('xxx', {})
1777
1778 call assert_fails("call prop_type_add('xxx', {})", 'E969:')
1779 call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:')
1780 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:')
1781 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:')
1782 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:')
1783 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:')
1784 call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:')
Christian Brabandt701c8632024-09-08 20:05:23 +02001785 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'id': 2147483648})", 'E1510:')
1786 call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'id': -2147483648})", 'E1510:')
Bram Moolenaar3dc34742021-03-02 13:36:47 +01001787
1788 call prop_type_delete('xxx')
1789 bwipe!
Bram Moolenaar99fa7212020-04-26 15:59:55 +02001790endfunc
1791
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001792func Test_prop_split_join()
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001793 new
1794 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1795 call setline(1, 'just some text')
1796 call prop_add(1, 6, {'length': 4, 'type': 'test'})
1797
1798 " Split in middle of "some"
1799 execute "normal! 8|i\<CR>"
Martin Tournoije2390c72021-07-28 13:30:16 +02001800 call assert_equal(
1801 \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}],
1802 \ prop_list(1))
1803 call assert_equal(
1804 \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}],
1805 \ prop_list(2))
Bram Moolenaar87be9be2020-05-30 15:32:02 +02001806
1807 " Join the two lines back together
1808 normal! 1GJ
Martin Tournoije2390c72021-07-28 13:30:16 +02001809 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 +02001810
1811 bwipe!
1812 call prop_type_delete('test')
1813endfunc
1814
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001815func Test_prop_increment_decrement()
1816 new
1817 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1818 call setline(1, 'its 998 times')
1819 call prop_add(1, 5, {'length': 3, 'type': 'test'})
1820
1821 exe "normal! 0f9\<C-A>"
1822 eval getline(1)->assert_equal('its 999 times')
1823 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001824 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001825
1826 exe "normal! 0f9\<C-A>"
1827 eval getline(1)->assert_equal('its 1000 times')
1828 eval prop_list(1)->assert_equal([
Martin Tournoije2390c72021-07-28 13:30:16 +02001829 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
Bram Moolenaarc8f12c92020-09-15 20:34:10 +02001830
1831 bwipe!
1832 call prop_type_delete('test')
1833endfunc
1834
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001835func Test_prop_block_insert()
1836 new
1837 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1838 call setline(1, ['one ', 'two '])
1839 call prop_add(1, 1, {'length': 3, 'type': 'test'})
1840 call prop_add(2, 1, {'length': 3, 'type': 'test'})
1841
1842 " insert "xx" in the first column of both lines
1843 exe "normal! gg0\<C-V>jIxx\<Esc>"
1844 eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
Martin Tournoije2390c72021-07-28 13:30:16 +02001845 let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
Bram Moolenaar8b51b7f2020-09-15 21:34:18 +02001846 eval prop_list(1)->assert_equal(expected)
1847 eval prop_list(2)->assert_equal(expected)
1848
1849 " insert "yy" inside the text props to make them longer
1850 exe "normal! gg03l\<C-V>jIyy\<Esc>"
1851 eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo '])
1852 let expected[0].length = 5
1853 eval prop_list(1)->assert_equal(expected)
1854 eval prop_list(2)->assert_equal(expected)
1855
1856 " insert "zz" after the text props, text props don't change
1857 exe "normal! gg07l\<C-V>jIzz\<Esc>"
1858 eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz '])
1859 eval prop_list(1)->assert_equal(expected)
1860 eval prop_list(2)->assert_equal(expected)
1861
1862 bwipe!
1863 call prop_type_delete('test')
1864endfunc
1865
Bram Moolenaar23999d72020-12-23 14:36:00 +01001866" this was causing an ml_get error because w_botline was wrong
1867func Test_prop_one_line_window()
1868 enew
1869 call range(2)->setline(1)
1870 call prop_type_add('testprop', {})
1871 call prop_add(1, 1, {'type': 'testprop'})
1872 call popup_create('popup', {'textprop': 'testprop'})
1873 $
1874 new
1875 wincmd _
1876 call feedkeys("\r", 'xt')
1877 redraw
1878
1879 call popup_clear()
1880 call prop_type_delete('testprop')
1881 close
1882 bwipe!
1883endfunc
1884
Bram Moolenaarf05a1e52022-08-02 11:48:53 +01001885def Test_prop_column_zero_error()
1886 prop_type_add('proptype', {highlight: 'Search'})
1887 var caught = false
1888 try
1889 popup_create([{
1890 text: 'a',
1891 props: [{col: 0, length: 1, type: 'type'}],
1892 }], {})
1893 catch /E964:/
1894 caught = true
1895 endtry
1896 assert_true(caught)
1897
1898 popup_clear()
1899 prop_type_delete('proptype')
1900enddef
1901
Bram Moolenaar840f91f2021-05-26 22:32:10 +02001902" This was calling ml_append_int() and copy a text property from a previous
1903" line at the wrong moment. Exact text length matters.
1904def Test_prop_splits_data_block()
1905 new
1906 var lines: list<string> = [repeat('x', 35)]->repeat(41)
1907 + [repeat('!', 35)]
1908 + [repeat('x', 35)]->repeat(56)
1909 lines->setline(1)
1910 prop_type_add('someprop', {highlight: 'ErrorMsg'})
1911 prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'})
1912 prop_remove({type: 'someprop'}, 1)
1913 prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'})
1914 prop_remove({type: 'someprop'}, 35, 43)
1915 assert_equal([], prop_list(42))
1916
1917 bwipe!
1918 prop_type_delete('someprop')
1919enddef
1920
Bram Moolenaar4cd5c522021-06-27 13:04:00 +02001921" This was calling ml_delete_int() and try to change text properties.
1922def Test_prop_add_delete_line()
1923 new
1924 var a = 10
1925 var b = 20
1926 repeat([''], a)->append('$')
1927 prop_type_add('Test', {highlight: 'ErrorMsg'})
1928 for lnum in range(1, a)
1929 for col in range(1, b)
1930 prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'})
1931 endfor
1932 endfor
1933
1934 # check deleting lines is OK
1935 :5del
1936 :1del
1937 :$del
1938
1939 prop_type_delete('Test')
1940 bwipe!
1941enddef
1942
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001943" This test is to detect a regression related to #10430. It is not an attempt
1944" fully cover deleting lines in the presence of multi-line properties.
1945def Test_delete_line_within_multiline_prop()
1946 new
1947 setline(1, '# Top.')
1948 append(1, ['some_text = """', 'A string.', '"""', '# Bottom.'])
1949 prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1950 prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0})
1951 prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9})
1952 prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4})
1953
1954 # The property for line 3 should extend into the previous and next lines.
1955 var props = prop_list(3)
1956 var prop = props[0]
1957 assert_equal(1, len(props))
1958 assert_equal(0, prop['start'])
1959 assert_equal(0, prop['end'])
1960
1961 # This deletion should run without raising an exception.
1962 try
1963 :2 del
1964 catch
dundargocc57b5bc2022-11-02 13:30:51 +00001965 assert_report('Line delete should have worked, but it raised an error.')
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001966 endtry
1967
1968 # The property for line 2 (was 3) should no longer extend into the previous
1969 # line.
1970 props = prop_list(2)
1971 prop = props[0]
1972 assert_equal(1, len(props))
1973 assert_equal(1, prop['start'], 'Property was not changed to start within the line.')
1974
1975 # This deletion should run without raising an exception.
1976 try
1977 :3 del
1978 catch
dundargocc57b5bc2022-11-02 13:30:51 +00001979 assert_report('Line delete should have worked, but it raised an error.')
Paul Ollis1bdc60e2022-05-15 22:24:55 +01001980 endtry
1981
1982 # The property for line 2 (originally 3) should no longer extend into the next
1983 # line.
1984 props = prop_list(2)
1985 prop = props[0]
1986 assert_equal(1, len(props))
1987 assert_equal(1, prop['end'], 'Property was not changed to end within the line.')
1988
1989 prop_type_delete('Identifier')
1990 prop_type_delete('String')
1991 bwip!
1992enddef
1993
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001994func Test_prop_in_linebreak()
1995 CheckRunVimInTerminal
1996
1997 let lines =<< trim END
1998 set breakindent linebreak breakat+=]
1999 call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1)
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002000 call prop_type_add('test', #{highlight: 'MatchParen'})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002001 call prop_add(1, 51, #{length: 1, type: 'test'})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002002 func AddMatch()
2003 syntax on
2004 syntax match xTest /.*/
2005 hi link xTest Comment
2006 set signcolumn=yes
2007 endfunc
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002008 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002009 call writefile(lines, 'XscriptPropLinebreak', 'D')
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002010 let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10})
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002011 call VerifyScreenDump(buf, 'Test_prop_linebreak_1', {})
2012
2013 call term_sendkeys(buf, ":call AddMatch()\<CR>")
2014 call VerifyScreenDump(buf, 'Test_prop_linebreak_2', {})
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002015
2016 call StopVimInTerminal(buf)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002017endfunc
2018
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002019func Test_prop_with_linebreak()
2020 CheckRunVimInTerminal
2021
2022 let lines =<< trim END
2023 vim9script
2024 set linebreak
2025 setline(1, 'one twoword')
2026 prop_type_add('test', {highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002027 prop_add(1, 4, {text: ': virtual text', type: 'test'})
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002028 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002029 call writefile(lines, 'XscriptPropWithLinebreak', 'D')
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002030 let buf = RunVimInTerminal('-S XscriptPropWithLinebreak', #{rows: 6, cols: 50})
2031 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_1', {})
2032 call term_sendkeys(buf, "iasdf asdf asdf asdf asdf as\<Esc>")
2033 call VerifyScreenDump(buf, 'Test_prop_with_linebreak_2', {})
2034
2035 call StopVimInTerminal(buf)
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002036endfunc
2037
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002038func Test_prop_with_wrap()
2039 CheckRunVimInTerminal
2040
2041 let lines =<< trim END
2042 vim9script
2043 set linebreak
2044 setline(1, 'asdf '->repeat(15))
2045 prop_type_add('test', {highlight: 'Special'})
2046 prop_add(1, 43, {text: 'some virtual text', type: 'test'})
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +00002047 normal G$
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002048 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002049 call writefile(lines, 'XscriptPropWithWrap', 'D')
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002050 let buf = RunVimInTerminal('-S XscriptPropWithWrap', #{rows: 6, cols: 50})
2051 call VerifyScreenDump(buf, 'Test_prop_with_wrap_1', {})
2052
2053 call StopVimInTerminal(buf)
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01002054endfunc
2055
Bram Moolenaar42eba042021-11-30 20:22:49 +00002056func Test_prop_after_tab()
2057 CheckRunVimInTerminal
2058
2059 let lines =<< trim END
2060 set breakindent linebreak breakat+=]
2061 call setline(1, "\t[xxx]")
2062 call prop_type_add('test', #{highlight: 'ErrorMsg'})
2063 call prop_add(1, 2, #{length: 1, type: 'test'})
2064 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002065 call writefile(lines, 'XscriptPropAfterTab', 'D')
Bram Moolenaar42eba042021-11-30 20:22:49 +00002066 let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10})
Bram Moolenaar42eba042021-11-30 20:22:49 +00002067 call VerifyScreenDump(buf, 'Test_prop_after_tab', {})
2068
2069 call StopVimInTerminal(buf)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002070endfunc
2071
Bram Moolenaare428fa02022-08-09 16:55:41 +01002072func Test_prop_before_tab()
2073 CheckRunVimInTerminal
2074
2075 let lines =<< trim END
2076 call setline(1, ["\tx"]->repeat(6))
2077 call prop_type_add('test', #{highlight: 'Search'})
2078 call prop_add(1, 1, #{type: 'test', text: '123'})
2079 call prop_add(2, 1, #{type: 'test', text: '1234567'})
2080 call prop_add(3, 1, #{type: 'test', text: '12345678'})
2081 call prop_add(4, 1, #{type: 'test', text: '123456789'})
2082 call prop_add(5, 2, #{type: 'test', text: 'ABC'})
2083 call prop_add(6, 3, #{type: 'test', text: 'ABC'})
2084 normal gg0
2085 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002086 call writefile(lines, 'XscriptPropBeforeTab', 'D')
Bram Moolenaare428fa02022-08-09 16:55:41 +01002087 let buf = RunVimInTerminal('-S XscriptPropBeforeTab', #{rows: 8})
2088 call VerifyScreenDump(buf, 'Test_prop_before_tab_01', {})
2089 call term_sendkeys(buf, "$")
2090 call VerifyScreenDump(buf, 'Test_prop_before_tab_02', {})
2091 call term_sendkeys(buf, "j0")
2092 call VerifyScreenDump(buf, 'Test_prop_before_tab_03', {})
2093 call term_sendkeys(buf, "$")
2094 call VerifyScreenDump(buf, 'Test_prop_before_tab_04', {})
2095 call term_sendkeys(buf, "j0")
2096 call VerifyScreenDump(buf, 'Test_prop_before_tab_05', {})
2097 call term_sendkeys(buf, "$")
2098 call VerifyScreenDump(buf, 'Test_prop_before_tab_06', {})
2099 call term_sendkeys(buf, "j0")
2100 call VerifyScreenDump(buf, 'Test_prop_before_tab_07', {})
2101 call term_sendkeys(buf, "$")
2102 call VerifyScreenDump(buf, 'Test_prop_before_tab_08', {})
2103 call term_sendkeys(buf, "j")
2104 call VerifyScreenDump(buf, 'Test_prop_before_tab_09', {})
2105 call term_sendkeys(buf, "j")
2106 call VerifyScreenDump(buf, 'Test_prop_before_tab_10', {})
2107
2108 call StopVimInTerminal(buf)
Bram Moolenaare428fa02022-08-09 16:55:41 +01002109endfunc
2110
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002111func Test_prop_after_linebreak()
2112 CheckRunVimInTerminal
2113
2114 let lines =<< trim END
2115 set linebreak wrap
2116 call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1)
2117 call prop_type_add('test', #{highlight: 'ErrorMsg'})
2118 call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'})
2119 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002120 call writefile(lines, 'XscriptPropAfterLinebreak', 'D')
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002121 let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10})
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002122 call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {})
2123
2124 call StopVimInTerminal(buf)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002125endfunc
2126
Martin Tournoije2390c72021-07-28 13:30:16 +02002127" Buffer number of 0 should be ignored, as if the parameter wasn't passed.
2128def Test_prop_bufnr_zero()
2129 new
2130 try
2131 var bufnr = bufnr('')
2132 setline(1, 'hello')
2133 prop_type_add('bufnr-global', {highlight: 'ErrorMsg'})
2134 prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr})
2135
2136 prop_add(1, 1, {type: 'bufnr-global', length: 1})
2137 prop_add(1, 2, {type: 'bufnr-buffer', length: 1})
2138
2139 var list = prop_list(1)
2140 assert_equal([
2141 {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1},
2142 {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1},
2143 ], list)
2144
2145 assert_equal(
2146 {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1},
2147 prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr}))
2148
2149 assert_equal(
2150 {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1},
2151 prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr}))
2152 finally
2153 bwipe!
2154 prop_type_delete('bufnr-global')
2155 endtry
2156enddef
2157
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002158" Tests for the prop_list() function
2159func Test_prop_list()
2160 let lines =<< trim END
2161 new
Bram Moolenaar62aec932022-01-29 21:45:34 +00002162 call g:AddPropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002163 call setline(1, repeat([repeat('a', 60)], 10))
2164 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2165 call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7})
2166 call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14})
2167 call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15})
2168 call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22})
2169 call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23})
2170 call assert_equal([
2171 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2172 \ 'type': 'one', 'length': 2, 'start': 1},
2173 \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2174 \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1))
2175 #" text properties between a few lines
2176 call assert_equal([
2177 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2178 \ 'type': 'one', 'length': 2, 'start': 1},
2179 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2180 \ 'type': 'two', 'length': 2, 'start': 1},
2181 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
2182 \ 'type': 'one', 'length': 2, 'start': 1},
2183 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
2184 \ 'type': 'two', 'length': 2, 'start': 1}],
2185 \ prop_list(2, {'end_lnum': 5}))
2186 #" text properties across all the lines
2187 call assert_equal([
2188 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2189 \ 'type': 'one', 'length': 2, 'start': 1},
2190 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2191 \ 'type': 'one', 'length': 2, 'start': 1},
2192 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
2193 \ 'type': 'one', 'length': 2, 'start': 1}],
2194 \ prop_list(1, {'types': ['one'], 'end_lnum': -1}))
2195 #" text properties with the specified identifier
2196 call assert_equal([
2197 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2198 \ 'type': 'one', 'length': 2, 'start': 1},
2199 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
2200 \ 'type': 'two', 'length': 2, 'start': 1}],
2201 \ prop_list(1, {'ids': [20], 'end_lnum': 10}))
2202 #" text properties of the specified type and id
2203 call assert_equal([
2204 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2205 \ 'type': 'two', 'length': 2, 'start': 1},
2206 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2207 \ 'type': 'two', 'length': 2, 'start': 1}],
2208 \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20}))
2209 call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10}))
2210 call assert_equal([], prop_list(6, {'end_lnum': 10}))
2211 call assert_equal([], prop_list(2, {'end_lnum': 2}))
2212 #" error cases
2213 call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:')
2214 call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:')
2215 call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:')
2216 call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})",
2217 \ 'E971:')
2218 call assert_fails("echo prop_list(1, {'types': ['one', 'blue'],
2219 \ 'end_lnum': 10})", 'E971:')
2220 call assert_fails("echo prop_list(1, {'types': ['one', 10],
2221 \ 'end_lnum': 10})", 'E928:')
2222 call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:')
2223 call assert_equal([], prop_list(2, {'types': []}))
2224 call assert_equal([], prop_list(2, {'types': test_null_list()}))
2225 call assert_fails("call prop_list(1, {'types': {}})", 'E714:')
2226 call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:')
2227 call assert_equal([], prop_list(2, {'types': ['one'],
2228 \ 'ids': test_null_list()}))
2229 call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []}))
2230 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})",
2231 \ 'E714:')
2232 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})",
2233 \ 'E714:')
2234 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})",
2235 \ 'E745:')
2236 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})",
2237 \ 'E745:')
Martin Tournoije2390c72021-07-28 13:30:16 +02002238
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002239 #" get text properties from a non-current buffer
2240 wincmd w
2241 call assert_equal([
2242 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2243 \ 'type': 'one', 'length': 2, 'start': 1},
2244 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
2245 \ 'type': 'two', 'length': 2, 'start': 1},
2246 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
2247 \ 'type': 'one', 'length': 2, 'start': 1},
2248 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
2249 \ 'type': 'two', 'length': 2, 'start': 1}],
2250 \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4}))
2251 wincmd w
2252
2253 #" get text properties after clearing all the properties
2254 call prop_clear(1, line('$'))
2255 call assert_equal([], prop_list(1, {'end_lnum': 10}))
2256
2257 call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2258 call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6})
2259 call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6})
2260 #" get text properties with a list of types
2261 call assert_equal([
2262 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2263 \ 'type': 'two', 'length': 2, 'start': 1},
2264 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2265 \ 'type': 'one', 'length': 2, 'start': 1}],
2266 \ prop_list(2, {'types': ['one', 'two']}))
2267 call assert_equal([
2268 \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1,
2269 \ 'type': 'three', 'length': 2, 'start': 1},
2270 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2271 \ 'type': 'one', 'length': 2, 'start': 1}],
2272 \ prop_list(2, {'types': ['one', 'three']}))
2273 #" get text properties with a list of identifiers
2274 call assert_equal([
2275 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
2276 \ 'type': 'two', '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, {'ids': [5, 10, 20]}))
2280 call prop_clear(1, line('$'))
2281 call assert_equal([], prop_list(2, {'types': ['one', 'two']}))
2282 call assert_equal([], prop_list(2, {'ids': [5, 10, 20]}))
2283
2284 #" get text properties from a hidden buffer
2285 edit! Xaaa
2286 call setline(1, repeat([repeat('b', 60)], 10))
2287 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
2288 call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10})
2289 VAR bnr = bufnr()
2290 hide edit Xbbb
2291 call assert_equal([
2292 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
2293 \ 'type': 'one', 'length': 2, 'start': 1},
2294 \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1,
2295 \ 'type': 'two', 'length': 2, 'start': 1}],
2296 \ prop_list(1, {'bufnr': bnr,
2297 \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1}))
2298 #" get text properties from an unloaded buffer
2299 bunload! Xaaa
2300 call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1}))
2301
Bram Moolenaar62aec932022-01-29 21:45:34 +00002302 call g:DeletePropTypes()
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002303 :%bw!
2304 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00002305 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanane0216622021-11-23 11:46:32 +00002306endfunc
Bram Moolenaar23999d72020-12-23 14:36:00 +01002307
LemonBoy9bd3ce22022-04-18 21:54:02 +01002308func Test_prop_find_prev_on_same_line()
2309 new
2310
2311 call setline(1, 'the quikc bronw fox jumsp over the layz dog')
2312 call prop_type_add('misspell', #{highlight: 'ErrorMsg'})
2313 for col in [8, 14, 24, 38]
2314 call prop_add(1, col, #{type: 'misspell', length: 2})
2315 endfor
2316
Ben Jacksona7704222022-08-20 20:54:51 +01002317 call cursor(1, 18)
LemonBoy9bd3ce22022-04-18 21:54:02 +01002318 let expected = [
2319 \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1},
2320 \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}
2321 \ ]
2322
2323 let result = prop_find(#{type: 'misspell'}, 'b')
2324 call assert_equal(expected[0], result)
2325 let result = prop_find(#{type: 'misspell'}, 'f')
2326 call assert_equal(expected[1], result)
2327
2328 call prop_type_delete('misspell')
2329 bwipe!
2330endfunc
2331
LemonBoyb7a70122022-05-13 12:41:50 +01002332func Test_prop_spell()
2333 new
2334 set spell
2335 call AddPropTypes()
2336
2337 call setline(1, ["helo world", "helo helo helo"])
2338 call prop_add(1, 1, #{type: 'one', length: 4})
2339 call prop_add(1, 6, #{type: 'two', length: 5})
2340 call prop_add(2, 1, #{type: 'three', length: 4})
2341 call prop_add(2, 6, #{type: 'three', length: 4})
2342 call prop_add(2, 11, #{type: 'three', length: 4})
2343
2344 " The first prop over 'helo' increases its length after the word is corrected
2345 " to 'Hello', the second one is shifted to the right.
2346 let expected = [
2347 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2348 \ 'length': 5, 'start': 1},
2349 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2350 \ 'length': 5, 'start': 1}
2351 \ ]
2352 call feedkeys("z=1\<CR>", 'xt')
2353
2354 call assert_equal('Hello world', getline(1))
2355 call assert_equal(expected, prop_list(1))
2356
2357 " Repeat the replacement done by z=
2358 spellrepall
2359
2360 let expected = [
2361 \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2362 \ 'length': 5, 'start': 1},
2363 \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2364 \ 'length': 5, 'start': 1},
2365 \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three',
2366 \ 'length': 5, 'start': 1}
2367 \ ]
2368 call assert_equal('Hello Hello Hello', getline(2))
2369 call assert_equal(expected, prop_list(2))
2370
2371 call DeletePropTypes()
2372 set spell&
2373 bwipe!
2374endfunc
2375
LemonBoy4b936742022-05-13 21:56:28 +01002376func Test_prop_shift_block()
2377 new
2378 call AddPropTypes()
2379
2380 call setline(1, ['some highlighted text']->repeat(2))
2381 call prop_add(1, 10, #{type: 'one', length: 11})
2382 call prop_add(2, 10, #{type: 'two', length: 11})
2383
2384 call cursor(1, 1)
2385 call feedkeys("5l\<c-v>>", 'nxt')
2386 call cursor(2, 1)
2387 call feedkeys("5l\<c-v><", 'nxt')
2388
2389 let expected = [
2390 \ {'lnum': 1, 'id': 0, 'col': 8, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2391 \ 'length': 11, 'start' : 1},
2392 \ {'lnum': 2, 'id': 0, 'col': 6, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2393 \ 'length': 11, 'start' : 1}
2394 \ ]
2395 call assert_equal(expected, prop_list(1, #{end_lnum: 2}))
2396
2397 call DeletePropTypes()
2398 bwipe!
2399endfunc
LemonBoyb7a70122022-05-13 12:41:50 +01002400
LemonBoy698cb4c2022-05-14 18:10:15 +01002401func Test_prop_insert_multiline()
2402 new
2403 call AddPropTypes()
2404
2405 call setline(1, ['foobar', 'barbaz'])
2406 call prop_add(1, 4, #{end_lnum: 2, end_col: 4, type: 'one'})
2407
2408 call feedkeys("1Goquxqux\<Esc>", 'nxt')
2409 call feedkeys("2GOquxqux\<Esc>", 'nxt')
2410
2411 let lines =<< trim END
2412 foobar
2413 quxqux
2414 quxqux
2415 barbaz
2416 END
2417 call assert_equal(lines, getline(1, '$'))
2418 let expected = [
2419 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one',
Ben Jacksona7704222022-08-20 20:54:51 +01002420 \ 'length': 4 , 'start': 1},
LemonBoy698cb4c2022-05-14 18:10:15 +01002421 \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2422 \ 'length': 7, 'start': 0},
2423 \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2424 \ 'length': 7, 'start': 0},
2425 \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2426 \ 'length': 3, 'start': 0}
2427 \ ]
2428 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2429
2430 call DeletePropTypes()
2431 bwipe!
2432endfunc
2433
LemonBoyb559b302022-05-15 13:08:02 +01002434func Test_prop_blockwise_change()
2435 new
2436 call AddPropTypes()
2437
2438 call setline(1, ['foooooo', 'bar', 'baaaaz'])
2439 call prop_add(1, 1, #{end_col: 3, type: 'one'})
2440 call prop_add(2, 1, #{end_col: 3, type: 'two'})
2441 call prop_add(3, 1, #{end_col: 3, type: 'three'})
2442
2443 " Replace the first two columns with '123', since 'start_incl' is false the
2444 " prop is not extended.
2445 call feedkeys("gg\<c-v>2jc123\<Esc>", 'nxt')
2446
2447 let lines =<< trim END
2448 123oooooo
2449 123ar
2450 123aaaaz
2451 END
2452 call assert_equal(lines, getline(1, '$'))
2453 let expected = [
2454 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'one',
2455 \ 'length': 1, 'start': 1},
2456 \ {'lnum': 2, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'two',
2457 \ 'length': 1, 'start': 1},
2458 \ {'lnum': 3, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1 ,
2459 \ 'type': 'three', 'length': 1, 'start': 1}
2460 \ ]
2461 call assert_equal(expected, prop_list(1, #{end_lnum: 10}))
2462
2463 call DeletePropTypes()
2464 bwipe!
2465endfunc
2466
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002467func Do_test_props_do_not_affect_byte_offsets(ff, increment)
2468 new
2469 let lcount = 410
2470
2471 " File format affects byte-offset calculations, so make sure it is known.
2472 exec 'setlocal fileformat=' . a:ff
2473
2474 " Fill the buffer with varying length lines. We need a suitably large number
dundargocc57b5bc2022-11-02 13:30:51 +00002475 " to force Vim code through paths where previous error have occurred. This
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002476 " is more 'art' than 'science'.
2477 let text = 'a'
2478 call setline(1, text)
2479 let offsets = [1]
2480 for idx in range(lcount)
2481 call add(offsets, offsets[idx] + len(text) + a:increment)
2482 if (idx % 6) == 0
2483 let text = text . 'a'
2484 endif
2485 call append(line('$'), text)
2486 endfor
2487
2488 " Set a property that spans a few lines to cause Vim's internal buffer code
2489 " to perform a reasonable amount of rearrangement.
2490 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2491 call prop_add(1, 1, {'type': 'one', 'end_lnum': 6, 'end_col': 2})
2492
2493 for idx in range(lcount)
2494 let boff = line2byte(idx + 1)
2495 call assert_equal(offsets[idx], boff, 'Bad byte offset at line ' . (idx + 1))
2496 endfor
2497
2498 call prop_type_delete('one')
2499 bwipe!
2500endfunc
2501
2502func Test_props_do_not_affect_byte_offsets()
2503 call Do_test_props_do_not_affect_byte_offsets('unix', 1)
2504endfunc
2505
2506func Test_props_do_not_affect_byte_offsets_dos()
2507 call Do_test_props_do_not_affect_byte_offsets('dos', 2)
2508endfunc
2509
2510func Test_props_do_not_affect_byte_offsets_editline()
2511 new
2512 let lcount = 410
2513
2514 " File format affects byte-offset calculations, so make sure it is known.
2515 setlocal fileformat=unix
2516
2517 " Fill the buffer with varying length lines. We need a suitably large number
dundargocc57b5bc2022-11-02 13:30:51 +00002518 " to force Vim code through paths where previous error have occurred. This
Paul Ollis4c3d21a2022-05-24 21:26:37 +01002519 " is more 'art' than 'science'.
2520 let text = 'aa'
2521 call setline(1, text)
2522 let offsets = [1]
2523 for idx in range(lcount)
2524 call add(offsets, offsets[idx] + len(text) + 1)
2525 if (idx % 6) == 0
2526 let text = text . 'a'
2527 endif
2528 call append(line('$'), text)
2529 endfor
2530
2531 " Set a property that just covers the first line. When this test was
2532 " developed, this did not trigger a byte-offset error.
2533 call prop_type_add('one', {'highlight': 'ErrorMsg'})
2534 call prop_add(1, 1, {'type': 'one', 'end_lnum': 1, 'end_col': 3})
2535
2536 for idx in range(lcount)
2537 let boff = line2byte(idx + 1)
2538 call assert_equal(offsets[idx], boff,
2539 \ 'Confounding bad byte offset at line ' . (idx + 1))
2540 endfor
2541
2542 " Insert text in the middle of the first line, keeping the property
2543 " unchanged.
2544 :1
2545 normal aHello
2546 for idx in range(1, lcount)
2547 let offsets[idx] = offsets[idx] + 5
2548 endfor
2549
2550 for idx in range(lcount)
2551 let boff = line2byte(idx + 1)
2552 call assert_equal(offsets[idx], boff,
2553 \ 'Bad byte offset at line ' . (idx + 1))
2554 endfor
2555
2556 call prop_type_delete('one')
2557 bwipe!
2558endfunc
2559
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002560func Test_prop_inserts_text()
2561 CheckRunVimInTerminal
2562
2563 " Just a basic check for now
2564 let lines =<< trim END
2565 call setline(1, 'insert some text here and other text there and some more text after wrapping')
2566 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2567 call prop_type_add('otherprop', #{highlight: 'Search'})
2568 call prop_type_add('moreprop', #{highlight: 'DiffAdd'})
2569 call prop_add(1, 18, #{type: 'someprop', text: 'SOME '})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002570 call prop_add(1, 38, #{type: 'otherprop', text: "OTHER\t"})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002571 call prop_add(1, 69, #{type: 'moreprop', text: 'MORE '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002572 normal $
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002573
2574 call setline(2, 'prepost')
2575 call prop_type_add('multibyte', #{highlight: 'Visual'})
2576 call prop_add(2, 4, #{type: 'multibyte', text: 'sΓΆmeε’ŒεΉ³tΓ©xt'})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002577
Bram Moolenaar25463612022-08-08 11:07:47 +01002578 call setline(3, 'Foo foo = { 1, 2 };')
Bram Moolenaar3331dd02022-08-10 16:49:02 +01002579 call prop_type_add('testprop', #{highlight: 'Comment'})
Bram Moolenaar25463612022-08-08 11:07:47 +01002580 call prop_add(3, 13, #{type: 'testprop', text: '.x='})
2581 call prop_add(3, 16, #{type: 'testprop', text: '.y='})
2582
2583 call setline(4, '')
2584 call prop_add(4, 1, #{type: 'someprop', text: 'empty line'})
Bram Moolenaar3331dd02022-08-10 16:49:02 +01002585
2586 call setline(5, 'look highlight')
2587 call prop_type_add('nohi', #{})
2588 call prop_add(5, 6, #{type: 'nohi', text: 'no '})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002589 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002590 call writefile(lines, 'XscriptPropsWithText', 'D')
Bram Moolenaar25463612022-08-08 11:07:47 +01002591 let buf = RunVimInTerminal('-S XscriptPropsWithText', #{rows: 8, cols: 60})
Bram Moolenaar711483c2022-07-30 21:33:46 +01002592 call VerifyScreenDump(buf, 'Test_prop_inserts_text_1', {})
2593
2594 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2595 call VerifyScreenDump(buf, 'Test_prop_inserts_text_2', {})
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002596
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002597 call term_sendkeys(buf, "2G$")
2598 call VerifyScreenDump(buf, 'Test_prop_inserts_text_3', {})
2599
Bram Moolenaar25463612022-08-08 11:07:47 +01002600 call term_sendkeys(buf, "3Gf1")
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002601 call VerifyScreenDump(buf, 'Test_prop_inserts_text_4', {})
Bram Moolenaar25463612022-08-08 11:07:47 +01002602 call term_sendkeys(buf, "f2")
2603 call VerifyScreenDump(buf, 'Test_prop_inserts_text_5', {})
2604
2605 call term_sendkeys(buf, "4G")
2606 call VerifyScreenDump(buf, 'Test_prop_inserts_text_6', {})
Bram Moolenaarafd2aa72022-08-05 13:07:23 +01002607
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002608 call StopVimInTerminal(buf)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002609endfunc
2610
Bram Moolenaare38fc862022-08-11 17:24:50 +01002611func Test_prop_inserts_text_highlight()
2612 CheckRunVimInTerminal
2613
2614 " Just a basic check for now
2615 let lines =<< trim END
2616 call setline(1, 'insert some text (here) and there')
2617 call prop_type_add('someprop', #{highlight: 'ErrorMsg'})
2618 let bef_prop = prop_add(1, 18, #{type: 'someprop', text: 'BEFORE'})
2619 set hlsearch
2620 let thematch = matchaddpos("DiffAdd", [[1, 18]])
2621 func DoAfter()
2622 call prop_remove(#{id: g:bef_prop})
2623 call prop_add(1, 19, #{type: 'someprop', text: 'AFTER'})
2624 let g:thematch = matchaddpos("DiffAdd", [[1, 18]])
2625 let @/ = ''
2626 endfunc
2627 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002628 call writefile(lines, 'XscriptPropsWithHighlight', 'D')
Bram Moolenaare38fc862022-08-11 17:24:50 +01002629 let buf = RunVimInTerminal('-S XscriptPropsWithHighlight', #{rows: 6, cols: 60})
2630 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_1', {})
2631 call term_sendkeys(buf, "/text (he\<CR>")
2632 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_2', {})
2633 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2634 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_3', {})
2635
2636 call term_sendkeys(buf, ":call DoAfter()\<CR>")
2637 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_4', {})
2638 call term_sendkeys(buf, "/text (he\<CR>")
2639 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_5', {})
2640 call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>")
2641 call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_6', {})
2642
2643 call StopVimInTerminal(buf)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002644endfunc
2645
zeertzjqd809c0a2023-08-27 11:17:39 +02002646func Test_prop_inserts_text_normal_gM()
2647 CheckRunVimInTerminal
2648
2649 let lines =<< trim END
2650 call setline(1, '123456789')
2651 call prop_type_add('theprop', #{highlight: 'Special'})
2652 call prop_add(1, 3, {'type': 'theprop', 'text': 'bbb'})
2653 call prop_add(1, 8, {'type': 'theprop', 'text': 'bbb'})
2654 END
2655 call writefile(lines, 'XscriptPropsNormal_gM', 'D')
2656 let buf = RunVimInTerminal('-S XscriptPropsNormal_gM', #{rows: 3, cols: 60})
2657 call term_sendkeys(buf, "gM")
2658 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gM', {})
2659
2660 call StopVimInTerminal(buf)
2661endfunc
2662
2663func Run_test_prop_inserts_text_normal_gj_gk(cmd)
2664 CheckRunVimInTerminal
2665
2666 let lines =<< trim END
2667 call setline(1, repeat([repeat('a', 55)], 2))
2668 call prop_type_add('theprop', {})
2669 call prop_add(1, 41, {'type': 'theprop', 'text': repeat('b', 10)})
2670 call prop_add(2, 41, {'type': 'theprop', 'text': repeat('b', 10)})
2671 END
2672 let lines = insert(lines, a:cmd)
2673 call writefile(lines, 'XscriptPropsNormal_gj_gk', 'D')
2674 let buf = RunVimInTerminal('-S XscriptPropsNormal_gj_gk', #{rows: 6, cols: 60})
2675 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_1', {})
2676 call term_sendkeys(buf, "gj")
2677 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_2', {})
2678 call term_sendkeys(buf, "gj")
2679 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_3', {})
2680 call term_sendkeys(buf, "gj")
2681 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_4', {})
2682 call term_sendkeys(buf, "gk")
2683 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_5', {})
2684 call term_sendkeys(buf, "gk")
2685 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_6', {})
2686 call term_sendkeys(buf, "gk")
2687 call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_7', {})
2688
2689 call StopVimInTerminal(buf)
2690endfunc
2691
2692func Test_prop_inserts_text_normal_gj_gk()
2693 call Run_test_prop_inserts_text_normal_gj_gk('')
2694 call Run_test_prop_inserts_text_normal_gj_gk('set virtualedit=all')
2695endfunc
2696
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002697func Test_prop_normal_gj_gk_gM_with_outer_virtual_text()
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002698 CheckRunVimInTerminal
2699
2700 let lines =<< trim END
2701 vim9script
2702 setlocal number
2703 setline(1, ['First line fits on screen line.', '', 'Third line fits on screen line.'])
2704
2705 var vt = 'test'
2706 prop_type_add(vt, {highlight: 'ToDo'})
2707 for ln in range(1, line('$'))
2708 prop_add(ln, 0, {type: vt, text: 'Above', text_align: 'above'})
2709 prop_add(ln, 0, {type: vt, text: 'After text wraps to next line.', text_align: 'after', text_wrap: 'wrap'})
2710 prop_add(ln, 0, {type: vt, text: 'Right text wraps to next line.', text_align: 'right', text_wrap: 'wrap'})
2711 prop_add(ln, 0, {type: vt, text: 'Below', text_align: 'below'})
2712 endfor
2713 normal 3l
2714 END
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002715 call writefile(lines, 'XscriptPropsNormal_gj_gk_gM_with_outer_text', 'D')
2716 let buf = RunVimInTerminal('-S XscriptPropsNormal_gj_gk_gM_with_outer_text', #{rows: 16, cols: 40})
2717 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002718
2719 call term_sendkeys(buf, "gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002720 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_2', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002721 call term_sendkeys(buf, "gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002722 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_3', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002723 call term_sendkeys(buf, "gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002724 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_2', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002725 call term_sendkeys(buf, "gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002726 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002727
2728 call term_sendkeys(buf, "2gj")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002729 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_3', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002730 call term_sendkeys(buf, "2gk")
Dylan Thacker-Smith366c81a2024-03-24 09:46:56 +01002731 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {})
2732
2733 call term_sendkeys(buf, "gM")
2734 call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_4', {})
Dylan Thacker-Smithb2d124c2024-03-24 09:43:25 +01002735
2736 call StopVimInTerminal(buf)
2737endfunc
2738
zeertzjq6e940d92023-08-17 23:21:40 +02002739func Test_prop_inserts_text_visual_block()
2740 CheckRunVimInTerminal
2741
2742 let lines =<< trim END
zeertzjqfc305842023-08-19 13:27:03 +02002743 call setline(1, repeat(['123456789'], 4))
zeertzjq6e940d92023-08-17 23:21:40 +02002744 call prop_type_add('theprop', #{highlight: 'Special'})
2745 call prop_add(2, 2, {'type': 'theprop', 'text': '-口-'})
zeertzjqfc305842023-08-19 13:27:03 +02002746 call prop_add(3, 3, {'type': 'theprop', 'text': '口'})
zeertzjq6e940d92023-08-17 23:21:40 +02002747 END
2748 call writefile(lines, 'XscriptPropsVisualBlock', 'D')
2749 let buf = RunVimInTerminal('-S XscriptPropsVisualBlock', #{rows: 6, cols: 60})
2750 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_1', {})
zeertzjqfc305842023-08-19 13:27:03 +02002751 call term_sendkeys(buf, "\<C-V>3jl")
zeertzjq6e940d92023-08-17 23:21:40 +02002752 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_2', {})
2753 call term_sendkeys(buf, "l")
2754 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_3', {})
2755 call term_sendkeys(buf, "4l")
2756 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_4', {})
2757 call term_sendkeys(buf, "Ol")
2758 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_5', {})
2759 call term_sendkeys(buf, "l")
2760 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_6', {})
2761 call term_sendkeys(buf, "l")
2762 call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_7', {})
2763
2764 call StopVimInTerminal(buf)
2765endfunc
2766
zeertzjqb557f482023-08-22 22:07:34 +02002767func Run_test_prop_inserts_text_showbreak(cmd)
2768 CheckRunVimInTerminal
2769
2770 let lines =<< trim END
2771 highlight! link LineNr Normal
zeertzjq6a389722023-08-27 19:04:14 +02002772 setlocal number showbreak=+ breakindent breakindentopt=shift:2
2773 setlocal scrolloff=0 smoothscroll
zeertzjqb557f482023-08-22 22:07:34 +02002774 call setline(1, repeat('a', 28))
2775 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002776 call prop_add(1, 28, #{type: 'theprop', text: repeat('123', 23)})
zeertzjqb557f482023-08-22 22:07:34 +02002777 normal! $
2778 END
2779 let lines = insert(lines, a:cmd)
2780 call writefile(lines, 'XscriptPropsShowbreak', 'D')
2781 let buf = RunVimInTerminal('-S XscriptPropsShowbreak', #{rows: 6, cols: 30})
2782 call term_sendkeys(buf, ":set noruler\<CR>")
2783 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_1', {})
2784 call term_sendkeys(buf, "\<C-E>")
2785 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_2', {})
2786 call term_sendkeys(buf, "\<C-E>")
2787 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_3', {})
2788 call term_sendkeys(buf, "\<C-E>")
2789 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_4', {})
2790 call term_sendkeys(buf, "\<C-E>")
2791 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_5', {})
2792 call term_sendkeys(buf, "zbi")
2793 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_6', {})
2794 call term_sendkeys(buf, "\<BS>")
2795 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_7', {})
2796 call term_sendkeys(buf, "\<Esc>l")
2797 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_8', {})
2798 call term_sendkeys(buf, "\<C-E>")
2799 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_9', {})
2800 call term_sendkeys(buf, "\<C-E>")
2801 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_10', {})
2802 call term_sendkeys(buf, "\<C-E>")
2803 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_11', {})
2804 call term_sendkeys(buf, "\<C-E>")
2805 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_12', {})
2806 call term_sendkeys(buf, "023x$")
2807 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_13', {})
2808 call term_sendkeys(buf, "\<C-E>")
2809 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_14', {})
2810 call term_sendkeys(buf, "\<C-E>")
2811 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_15', {})
2812 call term_sendkeys(buf, "\<C-E>")
2813 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_16', {})
2814 call term_sendkeys(buf, "zbi")
2815 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_17', {})
2816 call term_sendkeys(buf, "\<C-U>")
2817 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_18', {})
2818 call term_sendkeys(buf, "\<Esc>")
2819 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_19', {})
2820 call term_sendkeys(buf, "\<C-E>")
2821 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_20', {})
2822 call term_sendkeys(buf, "\<C-E>")
2823 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_21', {})
zeertzjq11939512023-08-23 20:58:01 +02002824 call term_sendkeys(buf, "zbx")
2825 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_22', {})
zeertzjq6a389722023-08-27 19:04:14 +02002826 call term_sendkeys(buf, "26ia\<Esc>a")
2827 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_23', {})
2828 call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal breakindentopt=\<CR>")
2829 call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_24', {})
zeertzjqb557f482023-08-22 22:07:34 +02002830
2831 call StopVimInTerminal(buf)
2832endfunc
2833
2834func Test_prop_inserts_text_showbreak()
2835 call Run_test_prop_inserts_text_showbreak('')
2836 " because of 'breakindent' the screendumps are the same
2837 call Run_test_prop_inserts_text_showbreak('set cpoptions+=n')
2838endfunc
2839
2840func Test_prop_before_tab_skipcol()
2841 CheckRunVimInTerminal
2842
2843 let lines =<< trim END
zeertzjq6a389722023-08-27 19:04:14 +02002844 setlocal list listchars=tab:<-> scrolloff=0 smoothscroll
zeertzjqb557f482023-08-22 22:07:34 +02002845 call setline(1, repeat("\t", 4) .. 'a')
2846 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002847 call prop_add(1, 4, #{type: 'theprop', text: repeat('12', 32)})
zeertzjqb557f482023-08-22 22:07:34 +02002848 normal! $
2849 END
2850 call writefile(lines, 'XscriptPropsBeforeTabSkipcol', 'D')
2851 let buf = RunVimInTerminal('-S XscriptPropsBeforeTabSkipcol', #{rows: 6, cols: 30})
2852 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_1', {})
2853 call term_sendkeys(buf, "\<C-E>")
2854 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_2', {})
2855 call term_sendkeys(buf, "\<C-E>")
2856 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_3', {})
2857 call term_sendkeys(buf, "\<C-E>")
2858 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_4', {})
2859 call term_sendkeys(buf, "zbh")
2860 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_5', {})
2861 call term_sendkeys(buf, "i")
2862 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_6', {})
2863 call term_sendkeys(buf, "\<C-O>:setlocal nolist\<CR>")
2864 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_7', {})
2865 call term_sendkeys(buf, "\<Esc>l")
2866 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_8', {})
2867 call term_sendkeys(buf, "\<C-E>")
2868 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_9', {})
2869 call term_sendkeys(buf, "\<C-E>")
2870 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_10', {})
2871 call term_sendkeys(buf, "\<C-E>")
2872 call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_11', {})
2873
2874 call StopVimInTerminal(buf)
2875endfunc
2876
zeertzjq6e55e852023-08-30 16:55:09 +02002877func Test_prop_inserts_text_before_linebreak()
2878 CheckRunVimInTerminal
2879
2880 let lines =<< trim END
2881 setlocal linebreak showbreak=+ breakindent breakindentopt=shift:2
2882 call setline(1, repeat('a', 50) .. ' ' .. repeat('c', 45))
2883 call prop_type_add('theprop', #{highlight: 'Special'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002884 call prop_add(1, 51, #{type: 'theprop', text: repeat('b', 10)})
zeertzjq6e55e852023-08-30 16:55:09 +02002885 normal! $
2886 END
2887 call writefile(lines, 'XscriptPropsBeforeLinebreak', 'D')
2888 let buf = RunVimInTerminal('-S XscriptPropsBeforeLinebreak', #{rows: 6, cols: 50})
2889 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_linebreak_1', {})
2890 call term_sendkeys(buf, '05x$')
2891 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_linebreak_2', {})
2892
2893 call StopVimInTerminal(buf)
2894endfunc
2895
zeertzjqac2d8812023-08-31 18:07:30 +02002896func Test_prop_inserts_text_before_double_width_wrap()
2897 CheckRunVimInTerminal
2898
2899 let lines =<< trim END
2900 call setline(1, repeat('a', 40) .. '口' .. '12345')
2901 call prop_type_add('theprop', #{highlight: 'Special'})
2902 call prop_add(1, 41, #{type: 'theprop', text: repeat('b', 9)})
2903 normal! $
2904 END
2905 call writefile(lines, 'XscriptPropsBeforeDoubleWidthWrap', 'D')
2906 let buf = RunVimInTerminal('-S XscriptPropsBeforeDoubleWidthWrap', #{rows: 3, cols: 50})
2907 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_1', {})
zeertzjqb5d6b5c2024-07-18 21:13:31 +02002908 call term_sendkeys(buf, 'g0')
2909 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_2', {})
2910 call term_sendkeys(buf, ":set showbreak=+++\<CR>")
2911 call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_3', {})
zeertzjqac2d8812023-08-31 18:07:30 +02002912
2913 call StopVimInTerminal(buf)
2914endfunc
2915
zeertzjq6a389722023-08-27 19:04:14 +02002916func Test_prop_inserts_text_lcs_extends()
2917 CheckRunVimInTerminal
2918
2919 let lines =<< trim END
2920 setlocal nowrap list listchars=extends:!
2921 call setline(1, repeat('a', &columns + 1))
2922 call prop_type_add('theprop', #{highlight: 'Special'})
2923 call prop_add(1, &columns + 2, #{type: 'theprop', text: 'bbb'})
2924 END
2925 call writefile(lines, 'XscriptPropsListExtends', 'D')
2926 let buf = RunVimInTerminal('-S XscriptPropsListExtends', #{rows: 3, cols: 50})
2927 call term_sendkeys(buf, '20l')
2928 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_1', {})
2929 call term_sendkeys(buf, 'zl')
2930 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_2', {})
2931 call term_sendkeys(buf, 'zl')
2932 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_3', {})
2933 call term_sendkeys(buf, 'zl')
2934 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_4', {})
2935 call term_sendkeys(buf, 'zl')
2936 call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_5', {})
2937
2938 call StopVimInTerminal(buf)
2939endfunc
2940
Bram Moolenaarfb593c52022-09-17 18:57:36 +01002941func Test_prop_add_with_text_fails()
2942 call prop_type_add('failing', #{highlight: 'ErrorMsg'})
2943 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_lnum: 1})", 'E1305:')
2944 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_col: 1})", 'E1305:')
2945 call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', length: 1})", 'E1305:')
2946
2947 call prop_type_delete('failing')
2948endfunc
2949
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002950func Test_props_with_text_right_align_twice()
2951 CheckRunVimInTerminal
2952
2953 let lines =<< trim END
2954 call setline(1, ["some text some text some text some text", 'line two'])
Bram Moolenaarfb593c52022-09-17 18:57:36 +01002955 call prop_type_add('MyErrorText', #{highlight: 'ErrorMsg'})
2956 call prop_type_add('MyPadding', #{highlight: 'DiffChange'})
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002957 call prop_add(1, 0, #{type: 'MyPadding', text: ' nothing here', text_wrap: 'wrap'})
2958 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Some error', text_wrap: 'wrap', text_align: 'right'})
2959 call prop_add(1, 0, #{type: 'MyErrorText', text: 'Another error', text_wrap: 'wrap', text_align: 'right'})
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002960 normal G$
2961 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002962 call writefile(lines, 'XscriptPropsRightAlign', 'D')
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002963 let buf = RunVimInTerminal('-S XscriptPropsRightAlign', #{rows: 8})
2964 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_1', {})
2965
2966 call term_sendkeys(buf, "ggisome more text\<Esc>G$")
2967 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {})
2968
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +01002969 call term_sendkeys(buf, ":set signcolumn=yes\<CR>")
2970 call VerifyScreenDump(buf, 'Test_prop_right_align_twice_3', {})
2971
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002972 call StopVimInTerminal(buf)
Bram Moolenaarf0ccfa42022-08-13 16:41:19 +01002973endfunc
2974
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002975func Test_props_with_text_after()
2976 CheckRunVimInTerminal
2977
2978 let lines =<< trim END
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002979 set showbreak=+++
Bram Moolenaar73c38422022-08-07 11:53:40 +01002980 set breakindent
2981 call setline(1, ' some text here and other text there')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002982 call prop_type_add('rightprop', #{highlight: 'ErrorMsg'})
2983 call prop_type_add('afterprop', #{highlight: 'Search'})
2984 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
2985 call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'})
Bram Moolenaar783ef722022-08-01 16:11:06 +01002986 call prop_add(1, 0, #{type: 'afterprop', text: "\tAFTER\t", text_align: 'after'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002987 call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'})
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002988 call prop_add(1, 0, #{type: 'belowprop', text: ' ALSO BELOW ', text_align: 'below'})
Bram Moolenaar84b247f2022-08-01 11:17:40 +01002989
2990 call setline(2, 'Last line.')
2991 call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'})
2992 normal G$
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002993
2994 call setline(3, 'right here')
2995 call prop_add(3, 0, #{type: 'rightprop', text: 'sΓΆmeε’ŒεΉ³tΓ©xt', text_align: 'right'})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002996 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01002997 call writefile(lines, 'XscriptPropsWithTextAfter', 'D')
Bram Moolenaar50e75fe2022-08-05 20:25:50 +01002998 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60})
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002999 call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {})
3000
3001 call StopVimInTerminal(buf)
Bram Moolenaar82b14c12022-08-10 19:50:47 +01003002
3003 call assert_fails('call prop_add(1, 2, #{text: "yes", text_align: "right", type: "some"})', 'E1294:')
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003004endfunc
3005
Bram Moolenaar877151b2022-10-11 15:29:50 +01003006func Test_props_with_text_after_and_list()
3007 CheckRunVimInTerminal
3008
3009 let lines =<< trim END
3010 vim9script
3011 setline(1, ['one', 'two'])
3012 prop_type_add('test', {highlight: 'Special'})
3013 prop_add(1, 0, {
3014 type: 'test',
3015 text: range(50)->join(' '),
3016 text_align: 'after',
3017 text_padding_left: 3
3018 })
3019 prop_add(1, 0, {
3020 type: 'test',
3021 text: range(50)->join('-'),
3022 text_align: 'after',
3023 text_padding_left: 5
3024 })
3025 prop_add(1, 0, {
3026 type: 'test',
3027 text: range(50)->join('.'),
3028 text_align: 'after',
3029 text_padding_left: 1
3030 })
3031 normal G$
3032 END
3033 call writefile(lines, 'XscriptPropsAfter', 'D')
3034 let buf = RunVimInTerminal('-S XscriptPropsAfter', #{rows: 8, cols: 60})
3035 call VerifyScreenDump(buf, 'Test_props_after_1', {})
3036
3037 call term_sendkeys(buf, ":set list\<CR>")
3038 call VerifyScreenDump(buf, 'Test_props_after_2', {})
3039
3040 call StopVimInTerminal(buf)
3041endfunc
3042
Bram Moolenaarcba69522022-08-06 21:03:53 +01003043func Test_props_with_text_after_below_trunc()
3044 CheckRunVimInTerminal
3045
3046 let lines =<< trim END
3047 vim9script
3048 edit foobar
3049 set showbreak=+++
3050 setline(1, ['onasdf asdf asdf asdf asd fas df', 'two'])
3051 prop_type_add('test', {highlight: 'Special'})
3052 prop_add(1, 0, {
3053 type: 'test',
3054 text: 'the quick brown fox jumps over the lazy dog',
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003055 text_align: 'after',
Bram Moolenaarcba69522022-08-06 21:03:53 +01003056 })
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003057 prop_type_add('another', {highlight: 'DiffChange'})
Bram Moolenaarcba69522022-08-06 21:03:53 +01003058 prop_add(1, 0, {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003059 type: 'another',
Bram Moolenaarcba69522022-08-06 21:03:53 +01003060 text: 'the quick brown fox jumps over the lazy dog',
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003061 text_align: 'below',
3062 text_padding_left: 4,
Bram Moolenaarcba69522022-08-06 21:03:53 +01003063 })
3064 normal G$
3065 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003066 call writefile(lines, 'XscriptPropsAfterTrunc', 'D')
Bram Moolenaarcba69522022-08-06 21:03:53 +01003067 let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60})
3068 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {})
3069
Bram Moolenaarccf28372022-10-10 21:10:03 +01003070 call term_sendkeys(buf, ":set number\<CR>")
3071 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_2', {})
3072
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003073 call term_sendkeys(buf, ":set cursorline\<CR>gg")
3074 call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_3', {})
3075
Bram Moolenaarcba69522022-08-06 21:03:53 +01003076 call StopVimInTerminal(buf)
Bram Moolenaarcba69522022-08-06 21:03:53 +01003077endfunc
3078
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003079func Test_props_with_text_truncated_just_before_after()
3080 CheckRunVimInTerminal
3081
3082 let lines =<< trim END
3083 vim9script
3084 set showbreak=+++
3085 set list listchars=extends:>
3086 set nowrap
3087
3088 setline(1, [
3089 'here is text long enough to fill the row',
3090 'second line',
3091 ])
3092
3093 prop_type_add("test", {"highlight": "Error"})
Dylan Thacker-Smith515f7342024-03-28 12:01:14 +01003094 prop_add(1, 0, {type: "test", text_align: "right", text: "right text"})
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003095 def g:AddPropBelow()
3096 prop_add(1, 0, {type: "test", text_align: "below", text: "below text"})
3097 enddef
Dylan Thacker-Smith515f7342024-03-28 12:01:14 +01003098 def g:AddPropAfter()
3099 prop_add(1, 0, {type: "test", text: "after text", text_padding_left: 1})
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003100 enddef
3101 normal G$
3102 END
3103 call writefile(lines, 'XscriptPropsWithTextTruncatedJustBeforeAfter', 'D')
3104 let buf = RunVimInTerminal('-S XscriptPropsWithTextTruncatedJustBeforeAfter', #{rows: 8, cols: 40})
3105 call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_1', {})
3106
3107 call term_sendkeys(buf, ":call AddPropBelow()\<CR>")
3108 call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_2', {})
3109
Dylan Thacker-Smith515f7342024-03-28 12:01:14 +01003110 call term_sendkeys(buf, ":call AddPropAfter()\<CR>:\<Esc>")
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01003111 call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_2', {})
3112
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01003113 call StopVimInTerminal(buf)
3114endfunc
3115
porygonisaduck38854b52022-11-27 20:55:05 +00003116func Test_prop_with_text_below_after_empty()
3117 CheckRunVimInTerminal
3118
3119 let lines =<< trim END
3120 vim9script
Bram Moolenaar94722c52023-01-28 19:19:03 +00003121
porygonisaduck38854b52022-11-27 20:55:05 +00003122 setline(1, ['vim9script', '', 'three', ''])
3123
3124 # Add text prop below empty line 2 with padding.
3125 prop_type_add('test', {highlight: 'ErrorMsg'})
3126 prop_add(2, 0, {
3127 type: 'test',
3128 text: 'The quick brown fox jumps over the lazy dog',
3129 text_align: 'below',
3130 text_padding_left: 1,
3131 })
3132
3133 # Add text prop below empty line 4 without padding.
3134 prop_type_add('other', {highlight: 'DiffChange'})
3135 prop_add(4, 0, {
3136 type: 'other',
3137 text: 'The slow fox bumps into the lazy dog',
3138 text_align: 'below',
3139 text_padding_left: 0,
3140 })
3141 END
3142 call writefile(lines, 'XscriptPropBelowAfterEmpty', 'D')
3143 let buf = RunVimInTerminal('-S XscriptPropBelowAfterEmpty', #{rows: 8, cols: 60})
Bram Moolenaar94722c52023-01-28 19:19:03 +00003144 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_1', {})
porygonisaduck38854b52022-11-27 20:55:05 +00003145
Bram Moolenaar7c02ad92022-11-29 21:37:13 +00003146 call term_sendkeys(buf, ":set number\<CR>")
Bram Moolenaar94722c52023-01-28 19:19:03 +00003147 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_2', {})
Bram Moolenaar7c02ad92022-11-29 21:37:13 +00003148
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003149 call term_sendkeys(buf, ":set nowrap\<CR>")
Bram Moolenaar94722c52023-01-28 19:19:03 +00003150 call VerifyScreenDump(buf, 'Test_prop_below_after_empty_3', {})
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003151
porygonisaduck38854b52022-11-27 20:55:05 +00003152 call StopVimInTerminal(buf)
3153endfunc
3154
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003155func Test_prop_with_text_above_below_empty()
3156 CheckRunVimInTerminal
3157
3158 let lines =<< trim END
3159 setlocal number
3160 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3161
3162 let vt = 'test'
3163 call prop_type_add(vt, {'highlight': 'ToDo'})
3164 for ln in range(1, line('$'))
Dylan Thacker-Smithda0c9132024-02-27 20:25:10 +01003165 " use 1 character text to test for off-by-one regressions
3166 call prop_add(ln, 0, {'type': vt, 'text': '-', 'text_align': 'above'})
3167 call prop_add(ln, 0, {'type': vt, 'text': '+', 'text_align': 'below'})
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003168 endfor
3169 normal G
zeertzjq918b92b2024-03-20 19:49:20 +01003170
3171 func AddMore()
3172 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3173 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3174 call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
3175 endfunc
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003176 END
3177 call writefile(lines, 'XscriptPropAboveBelowEmpty', 'D')
3178 let buf = RunVimInTerminal('-S XscriptPropAboveBelowEmpty', #{rows: 16, cols: 60})
3179 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_1', {})
3180
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003181 call term_sendkeys(buf, ":set list\<CR>")
3182 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_2', {})
3183
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003184 call term_sendkeys(buf, ":set nolist\<CR>")
3185 call term_sendkeys(buf, ":set colorcolumn=10\<CR>")
3186 call term_sendkeys(buf, ":\<CR>")
3187 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_3', {})
3188
Bram Moolenaara572b932023-02-19 14:34:37 +00003189 call term_sendkeys(buf, ":set colorcolumn=\<CR>")
3190 call term_sendkeys(buf, ":set relativenumber\<CR>")
3191 call term_sendkeys(buf, ":\<CR>")
3192 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_4', {})
3193
3194 call term_sendkeys(buf, "kk")
3195 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_5', {})
3196
zeertzjq918b92b2024-03-20 19:49:20 +01003197 " This was drawing line number over cmdline and leaking memory.
3198 call term_sendkeys(buf, ":call AddMore()\<CR>")
3199 call term_sendkeys(buf, "gg")
3200 call term_sendkeys(buf, "j")
3201 call VerifyScreenDump(buf, 'Test_prop_above_below_empty_6', {})
3202
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003203 call StopVimInTerminal(buf)
3204endfunc
3205
Matthias2c9f49b2025-03-16 19:27:51 +01003206func Test_prop_multiple_lines_above()
3207 CheckRunVimInTerminal
3208
3209 let lines =<< trim END
3210 setlocal number colorcolumn=10
3211 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3212
3213 let vt = 'test'
3214 call prop_type_add(vt, {'highlight': 'ToDo'})
3215 for ln in range(1, line('$'))
3216 call prop_add(ln, 0, {'type': vt, 'text': 'above1', 'text_align': 'above'})
3217 call prop_add(ln, 0, {'type': vt, 'text': 'above2', 'text_align': 'above'})
3218 endfor
3219 normal G
3220 END
3221 call writefile(lines, 'XscriptPropMultipleLinesAbove', 'D')
3222 let buf = RunVimInTerminal('-S XscriptPropMultipleLinesAbove', #{rows: 16, cols: 60})
3223 call VerifyScreenDump(buf, 'Test_prop_multiple_lines_above_1', {})
3224
3225 call StopVimInTerminal(buf)
3226endfunc
3227
zeertzjq91d26aa2024-10-27 19:23:34 +01003228func Test_prop_with_multibyte_above()
3229 CheckRunVimInTerminal
3230
3231 let lines =<< trim END
3232 setlocal number colorcolumn=10
3233 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3234
3235 let vt = 'test'
3236 call prop_type_add(vt, {'highlight': 'ToDo'})
3237 for ln in range(1, line('$'))
3238 call prop_add(ln, 0, {'type': vt, 'text': '…', 'text_align': 'above'})
3239 endfor
3240 normal G
3241 END
3242 call writefile(lines, 'XscriptPropMultibyteAbove', 'D')
3243 let buf = RunVimInTerminal('-S XscriptPropMultibyteAbove', #{rows: 16, cols: 60})
3244 call VerifyScreenDump(buf, 'Test_prop_multibyte_above_1', {})
3245
3246 call StopVimInTerminal(buf)
3247endfunc
3248
Bram Moolenaarea62cee2023-02-19 18:36:41 +00003249func Test_prop_with_multibyte_below()
3250 CheckRunVimInTerminal
3251
3252 let lines =<< trim END
3253 setlocal number
3254 call setline(1, ['Β©', 'Β©', 'Β©'])
3255
3256 let vt = 'test'
3257 call prop_type_add(vt, {'highlight': 'ToDo'})
3258 for ln in range(1, line('$'))
3259 call prop_add(ln, 0, {'type': vt, 'text': '+++', 'text_align': 'below'})
3260 endfor
3261 normal G
3262 END
3263 call writefile(lines, 'XscriptPropMultibyteBelow', 'D')
3264 let buf = RunVimInTerminal('-S XscriptPropMultibyteBelow', #{rows: 10, cols: 60})
3265 call VerifyScreenDump(buf, 'Test_prop_multibyte_below_1', {})
3266
3267 call StopVimInTerminal(buf)
3268endfunc
3269
zeertzjq6b9c2022023-09-11 20:01:17 +02003270func Test_prop_with_text_below_rightleft()
3271 CheckRunVimInTerminal
3272 CheckFeature rightleft
3273
3274 let lines =<< trim END
3275 setlocal number rightleft
3276 call setline(1, 'abcde')
3277 call prop_type_add('theprop', #{highlight: 'Special'})
3278 call prop_add(1, 0, #{type: 'theprop', text: '12345', text_align: 'below'})
3279 END
3280 call writefile(lines, 'XscriptPropBelowRightleft', 'D')
3281 let buf = RunVimInTerminal('-S XscriptPropBelowRightleft', #{rows: 6, cols: 60})
3282 call VerifyScreenDump(buf, 'Test_prop_below_rightleft_1', {})
3283
3284 call StopVimInTerminal(buf)
3285endfunc
3286
Bram Moolenaar5ceb8152023-02-12 18:11:21 +00003287func Test_prop_with_text_above_empty()
3288 CheckRunVimInTerminal
3289
3290 " check the cursor is in the correct line
3291 let lines =<< trim END
3292 setlocal number
3293 call setline(1, ['11111111', '', '333333333', '', '55555555555'])
3294
3295 let vt = 'test'
3296 call prop_type_add(vt, {'highlight': 'ToDo'})
3297 for ln in range(1, line('$'))
3298 call prop_add(ln, 0, {'type': vt, 'text': '---', 'text_align': 'above'})
3299 endfor
3300 normal G
3301 END
3302 call writefile(lines, 'XscriptPropAboveEmpty', 'D')
3303 let buf = RunVimInTerminal('-S XscriptPropAboveEmpty', #{rows: 16, cols: 60})
3304 call VerifyScreenDump(buf, 'Test_prop_above_empty_1', {})
3305
3306 call term_sendkeys(buf, ":set list\<CR>")
3307 call VerifyScreenDump(buf, 'Test_prop_above_empty_2', {})
3308
3309 call StopVimInTerminal(buf)
3310endfunc
3311
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003312func Test_prop_with_text_below_after_match()
3313 CheckRunVimInTerminal
3314
3315 let lines =<< trim END
3316 vim9script
3317
3318 setline(1, ['vim9script', 'some text'])
3319 set signcolumn=yes
3320 matchaddpos('Search', [[1, 10]])
3321 prop_type_add('test', {highlight: 'Error'})
3322 prop_add(1, 0, {
3323 type: 'test',
3324 text: 'The quick brown fox',
3325 text_align: 'below'
3326 })
3327 END
3328 call writefile(lines, 'XscriptPropsBelow', 'D')
3329 let buf = RunVimInTerminal('-S XscriptPropsBelow', #{rows: 8, cols: 60})
3330 call VerifyScreenDump(buf, 'Test_prop_with_text_below_after_match_1', {})
3331
3332 call StopVimInTerminal(buf)
3333endfunc
3334
Bram Moolenaare175dc62022-08-01 22:18:50 +01003335func Test_props_with_text_after_joined()
3336 CheckRunVimInTerminal
3337
3338 let lines =<< trim END
3339 call setline(1, ['one', 'two', 'three', 'four'])
3340 call prop_type_add('afterprop', #{highlight: 'Search'})
3341 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'})
3342 call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'})
3343 normal ggJ
3344 normal GkJ
3345
3346 call setline(3, ['a', 'b', 'c', 'd', 'e', 'f'])
3347 call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'})
3348 call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'})
3349 call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'})
3350 call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'})
3351 normal 3G6J
3352 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003353 call writefile(lines, 'XscriptPropsWithTextAfterJoined', 'D')
Bram Moolenaare175dc62022-08-01 22:18:50 +01003354 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60})
3355 call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {})
3356
3357 call StopVimInTerminal(buf)
Bram Moolenaare175dc62022-08-01 22:18:50 +01003358endfunc
3359
Bram Moolenaar398649e2022-08-04 15:03:48 +01003360func Test_props_with_text_after_truncated()
3361 CheckRunVimInTerminal
3362
3363 let lines =<< trim END
3364 call setline(1, ['one two three four five six seven'])
3365 call prop_type_add('afterprop', #{highlight: 'Search'})
3366 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3367
3368 call setline(2, ['one two three four five six seven'])
3369 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3370
3371 call setline(3, ['one two three four five six seven'])
3372 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'})
3373
3374 call setline(4, ['cursor here'])
3375 normal 4Gfh
3376 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003377 call writefile(lines, 'XscriptPropsWithTextAfterTrunc', 'D')
Bram Moolenaar398649e2022-08-04 15:03:48 +01003378 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60})
3379 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {})
3380
3381 call term_sendkeys(buf, ":37vsp\<CR>gg")
3382 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {})
3383
3384 call term_sendkeys(buf, ":36wincmd |\<CR>")
3385 call term_sendkeys(buf, "2G$")
3386 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {})
3387
3388 call term_sendkeys(buf, ":33wincmd |\<CR>")
3389 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {})
3390
3391 call term_sendkeys(buf, ":18wincmd |\<CR>")
3392 call term_sendkeys(buf, "0fx")
3393 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {})
3394
3395 call StopVimInTerminal(buf)
Bram Moolenaar398649e2022-08-04 15:03:48 +01003396endfunc
3397
h-east4c42c7e2023-04-17 21:44:57 +01003398func Test_props_with_text_after_truncated_and_ambiwidth_is_double()
3399 CheckRunVimInTerminal
3400
3401 let lines =<< trim END
3402 set ambiwidth=double
3403 call setline(1, ['one two three four five six seven'])
3404 call prop_type_add('afterprop', #{highlight: 'Search'})
3405 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3406
3407 call setline(2, ['one two three four five six seven'])
3408 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3409
3410 call setline(3, ['one two three four five six seven'])
3411 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'})
3412
3413 call setline(4, ['cursor here'])
3414 normal 4Gfh
3415 END
3416 call writefile(lines, 'XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', 'D')
3417 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', #{rows: 9, cols: 60})
3418 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_ambiw_d_1', {})
3419
3420 call StopVimInTerminal(buf)
3421endfunc
3422
3423
3424func Test_props_with_text_after_truncated_not_utf8()
3425 CheckRunVimInTerminal
3426
3427 let lines =<< trim END
3428 set enc=cp932 tenc=utf-8
3429 call setline(1, ['one two three four five six seven'])
3430 call prop_type_add('afterprop', #{highlight: 'Search'})
3431 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
3432
3433 call setline(2, ['one two three four five six seven'])
3434 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
3435
3436 call setline(3, ['one two three four five six seven'])
3437 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'})
3438
3439 call setline(4, ['cursor here'])
3440 normal 4Gfh
3441 END
3442 call writefile(lines, 'XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', 'D')
3443 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', #{rows: 9, cols: 60})
3444 call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_not_utf8', {})
3445
3446 call StopVimInTerminal(buf)
3447endfunc
3448
Bram Moolenaar49a90792022-08-09 18:25:23 +01003449func Test_props_with_text_empty_line()
3450 CheckRunVimInTerminal
3451
3452 let lines =<< trim END
3453 call setline(1, ['', 'aaa', '', 'bbbbbb'])
3454 call prop_type_add('prop1', #{highlight: 'Search'})
zeertzjq3c3cf1d2023-09-02 21:55:00 +02003455 call prop_add(1, 1, #{type: 'prop1', text: repeat('X', &columns)})
3456 call prop_add(3, 1, #{type: 'prop1', text: repeat('X', &columns + 1)})
Bram Moolenaar49a90792022-08-09 18:25:23 +01003457 normal gg0
3458 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003459 call writefile(lines, 'XscriptPropsWithTextEmptyLine', 'D')
Bram Moolenaar49a90792022-08-09 18:25:23 +01003460 let buf = RunVimInTerminal('-S XscriptPropsWithTextEmptyLine', #{rows: 8, cols: 60})
3461 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_1', {})
3462 call term_sendkeys(buf, "$")
3463 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_2', {})
3464 call term_sendkeys(buf, "j")
3465 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_3', {})
3466 call term_sendkeys(buf, "j")
3467 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_4', {})
3468 call term_sendkeys(buf, "j")
3469 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_5', {})
zeertzjqe3daa062023-08-27 19:11:46 +02003470 call term_sendkeys(buf, "0\<C-V>2l2k")
3471 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_6', {})
3472 call term_sendkeys(buf, "\<Esc>/aaa\\n\\%V\<CR>")
3473 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_7', {})
3474 call term_sendkeys(buf, "3ggic")
3475 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_8', {})
3476 call term_sendkeys(buf, "\<Esc>/aaa\\nc\\%V\<CR>")
3477 call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_9', {})
Bram Moolenaar49a90792022-08-09 18:25:23 +01003478
3479 call StopVimInTerminal(buf)
Bram Moolenaar49a90792022-08-09 18:25:23 +01003480endfunc
3481
Bram Moolenaar398649e2022-08-04 15:03:48 +01003482func Test_props_with_text_after_wraps()
3483 CheckRunVimInTerminal
3484
3485 let lines =<< trim END
3486 call setline(1, ['one two three four five six seven'])
3487 call prop_type_add('afterprop', #{highlight: 'Search'})
3488 call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'})
3489
3490 call setline(2, ['one two three four five six seven'])
3491 call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'})
3492
3493 call setline(3, ['one two three four five six seven'])
3494 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'})
3495
3496 call setline(4, ['cursor here'])
3497 normal 4Gfh
3498 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003499 call writefile(lines, 'XscriptPropsWithTextAfterWraps', 'D')
Bram Moolenaar398649e2022-08-04 15:03:48 +01003500 let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60})
3501 call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {})
3502
3503 call StopVimInTerminal(buf)
Bram Moolenaar398649e2022-08-04 15:03:48 +01003504endfunc
3505
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003506func Test_props_with_text_after_nowrap()
3507 CheckRunVimInTerminal
3508
3509 let lines =<< trim END
3510 set nowrap
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003511 call setline(1, ['one', 'two', 'three', 'four'])
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
3513 call prop_type_add('anotherprop', #{highlight: 'Search'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01003514 call prop_type_add('someprop', #{highlight: 'DiffChange'})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003515 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
3516 call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'})
3517 call prop_add(2, 0, #{type: 'belowprop', text: 'One More Here', text_align: 'below'})
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01003518 call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'})
3519 call prop_add(1, 0, #{type: 'someprop', text: ' After the text', text_align: 'after'})
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003520 normal 3G$
3521
3522 call prop_add(3, 0, #{type: 'anotherprop', text: 'right aligned', text_align: 'right'})
3523 call prop_add(3, 0, #{type: 'anotherprop', text: 'also right aligned', text_align: 'right'})
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003524 hi CursorLine ctermbg=lightgrey
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003526 call writefile(lines, 'XscriptPropsAfterNowrap', 'D')
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003527 let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 12, cols: 60})
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003528 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {})
3529
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003530 call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\<CR>")
Bram Moolenaar1306b362022-08-06 15:59:06 +01003531 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {})
3532
Bram Moolenaar8f369fb2022-08-13 19:35:05 +01003533 call term_sendkeys(buf, "j")
3534 call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_3', {})
3535
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003536 call StopVimInTerminal(buf)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537endfunc
3538
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003539func Test_prop_with_text_below_cul()
3540 CheckRunVimInTerminal
3541
3542 let lines =<< trim END
3543 vim9script
3544
3545 setline(1, ['some text', 'last line'])
3546 set cursorline nowrap
3547 prop_type_add('test', {highlight: 'DiffChange'})
3548 prop_add(1, 0, {
3549 type: 'test',
3550 text: 'The quick brown fox jumps over the lazy dog',
3551 text_align: 'below',
3552 text_padding_left: 4,
3553 })
3554 END
3555 call writefile(lines, 'XscriptPropsBelowCurline', 'D')
3556 let buf = RunVimInTerminal('-S XscriptPropsBelowCurline', #{rows: 6, cols: 60})
3557 call VerifyScreenDump(buf, 'Test_prop_with_text_below_cul_1', {})
3558
3559 call StopVimInTerminal(buf)
3560endfunc
3561
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003562func Test_props_with_text_below_nowrap()
3563 CheckRunVimInTerminal
3564
3565 let lines =<< trim END
3566 vim9script
3567 edit foobar
3568 set nowrap
3569 set showbreak=+++\
3570 setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two'])
3571 prop_type_add('test', {highlight: 'Special'})
3572 prop_add(1, 0, {
3573 type: 'test',
3574 text: 'the quick brown fox jumps over the lazy dog',
3575 text_align: 'after'
3576 })
3577 prop_add(1, 0, {
3578 type: 'test',
3579 text: 'the quick brown fox jumps over the lazy dog',
3580 text_align: 'below'
3581 })
3582 normal G$
3583 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003584 call writefile(lines, 'XscriptPropsBelowNowrap', 'D')
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003585 let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60})
3586 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {})
3587
3588 call term_sendkeys(buf, "gg$")
3589 call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {})
3590
3591 call StopVimInTerminal(buf)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003592endfunc
3593
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003594func Test_props_with_text_above()
3595 CheckRunVimInTerminal
3596
3597 let lines =<< trim END
3598 call setline(1, ['one two', 'three four', 'five six'])
3599 call prop_type_add('above1', #{highlight: 'Search'})
3600 call prop_type_add('above2', #{highlight: 'DiffChange'})
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003601 call prop_type_add('below', #{highlight: 'DiffAdd'})
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003602 call prop_add(1, 0, #{type: 'above1', text: 'first thing above', text_align: 'above'})
3603 call prop_add(1, 0, #{type: 'above2', text: 'second thing above', text_align: 'above'})
Bram Moolenaar79f8b842022-09-11 13:31:01 +01003604 call prop_add(3, 0, #{type: 'above1', text: 'another thing', text_align: 'above', text_padding_left: 3})
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003605
3606 normal gglllj
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003607 func AddPropBelow()
3608 call prop_add(1, 0, #{type: 'below', text: 'below', text_align: 'below'})
3609 endfunc
Bram Moolenaar9466fb82022-10-11 14:54:42 +01003610 func AddLongPropAbove()
3611 3,4delete
3612 set wrap
3613 call prop_add(1, 0, #{type: 'above1', text: range(50)->join(' '), text_align: 'above', text_padding_left: 2})
3614 endfunc
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003615 END
3616 call writefile(lines, 'XscriptPropsWithTextAbove', 'D')
3617 let buf = RunVimInTerminal('-S XscriptPropsWithTextAbove', #{rows: 9, cols: 60})
3618 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1', {})
3619
Bram Moolenaare24b4ab2022-09-16 20:51:14 +01003620 call term_sendkeys(buf, "ggg$")
3621 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1a', {})
3622 call term_sendkeys(buf, "g0")
3623 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1b', {})
3624
Bram Moolenaar4c7fd4d2022-09-17 17:15:33 +01003625 call term_sendkeys(buf, ":set showbreak=>>\<CR>")
3626 call term_sendkeys(buf, "ggll")
3627 call VerifyScreenDump(buf, 'Test_prop_with_text_above_1c', {})
3628 call term_sendkeys(buf, ":set showbreak=\<CR>")
3629
Bram Moolenaar88b79cb2022-09-10 22:32:14 +01003630 call term_sendkeys(buf, "ggI")
3631 call VerifyScreenDump(buf, 'Test_prop_with_text_above_2', {})
3632 call term_sendkeys(buf, "inserted \<Esc>")
3633 call VerifyScreenDump(buf, 'Test_prop_with_text_above_3', {})
3634
Bram Moolenaar79f8b842022-09-11 13:31:01 +01003635 call term_sendkeys(buf, ":set number signcolumn=yes\<CR>")
3636 call VerifyScreenDump(buf, 'Test_prop_with_text_above_4', {})
3637
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003638 call term_sendkeys(buf, ":set nowrap\<CR>gg$j")
3639 call VerifyScreenDump(buf, 'Test_prop_with_text_above_5', {})
3640
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01003641 call term_sendkeys(buf, ":call AddPropBelow()\<CR>")
3642 call term_sendkeys(buf, "ggve")
3643 call VerifyScreenDump(buf, 'Test_prop_with_text_above_6', {})
3644 call term_sendkeys(buf, "V")
3645 call VerifyScreenDump(buf, 'Test_prop_with_text_above_7', {})
3646
Bram Moolenaar3b93cf22022-09-13 18:34:18 +01003647 call term_sendkeys(buf, "\<Esc>ls\<CR>\<Esc>")
3648 call VerifyScreenDump(buf, 'Test_prop_with_text_above_8', {})
3649
Bram Moolenaar9466fb82022-10-11 14:54:42 +01003650 call term_sendkeys(buf, ":call AddLongPropAbove()\<CR>")
3651 call VerifyScreenDump(buf, 'Test_prop_with_text_above_9', {})
3652
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01003653 call StopVimInTerminal(buf)
3654endfunc
3655
Bram Moolenaar2354b662023-04-23 21:42:25 +01003656func Test_prop_with_text_above_padding()
3657 CheckRunVimInTerminal
3658
3659 let lines =<< trim END
3660 vim9script
3661
3662 setlocal tabstop=8 noexpandtab
3663 setline(1, ['', 'sky is blue', 'ocean is blue'])
3664 prop_type_add('DiagVirtualText', {highlight: 'Search', override: true})
3665 prop_add(3, 0, {text: "β”Œβ”€ start", text_align: "above",
3666 type: 'DiagVirtualText',
3667 text_padding_left: 200})
3668 END
3669 call writefile(lines, 'XscriptAbovePadding', 'D')
3670 let buf = RunVimInTerminal('-S XscriptAbovePadding', #{rows: 8})
3671 call VerifyScreenDump(buf, 'Test_prop_above_padding_1', {})
3672
3673 call StopVimInTerminal(buf)
3674endfunc
3675
Bram Moolenaar702bd6c2022-09-14 16:09:57 +01003676func Test_prop_above_with_indent()
3677 new
3678 call setline(1, ['first line', ' second line', ' line below'])
3679 setlocal cindent
3680 call prop_type_add('indented', #{highlight: 'Search'})
3681 call prop_add(3, 0, #{type: 'indented', text: 'here', text_align: 'above', text_padding_left: 4})
3682 call assert_equal(' line below', getline(3))
3683
3684 exe "normal 3G2|a\<CR>"
3685 call assert_equal(' ', getline(3))
3686 call assert_equal(' line below', getline(4))
3687
3688 bwipe!
3689 call prop_type_delete('indented')
3690endfunc
3691
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01003692func Test_prop_above_with_number()
3693 CheckRunVimInTerminal
3694
3695 let lines =<< trim END
3696 vim9script
3697 setline(1, ['one one one', 'two two two', 'three three three'])
3698 set number cpo+=n
3699 prop_type_add('test', {highlight: 'DiffChange'})
3700 prop_add(2, 0, {
3701 text: 'above the text',
3702 type: 'test',
3703 text_align: 'above',
3704 })
3705 def g:OneMore()
3706 prop_add(2, 0, {
3707 text: 'also above the text',
3708 type: 'test',
3709 text_align: 'above',
3710 })
3711 enddef
3712 END
3713 call writefile(lines, 'XscriptPropAboveNr', 'D')
3714 let buf = RunVimInTerminal('-S XscriptPropAboveNr', #{rows: 8})
3715 call VerifyScreenDump(buf, 'Test_prop_above_number_1', {})
3716
3717 call term_sendkeys(buf, ":call OneMore()\<CR>")
3718 call VerifyScreenDump(buf, 'Test_prop_above_number_2', {})
3719
zeertzjq62f19542025-03-08 16:27:37 +01003720 call term_sendkeys(buf, ":setlocal cursorline cursorlineopt=number\<CR>")
3721 call term_sendkeys(buf, 'j')
3722 call VerifyScreenDump(buf, 'Test_prop_above_number_3', {})
3723
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01003724 call StopVimInTerminal(buf)
3725endfunc
3726
zeertzjqce53e3e2023-09-01 18:49:30 +02003727func Test_prop_above_with_linebreak()
3728 CheckRunVimInTerminal
3729
3730 let lines =<< trim END
3731 setlocal linebreak breakindent breakindentopt=shift:4
3732 call setline(1, ["a b", "c d"])
3733 call prop_type_add('theprop' , #{highlight: 'Special'})
3734 call prop_add(1, 0, #{type: 'theprop', text: '123', text_align: 'above'})
3735 normal! 2gg$
3736 END
3737 call writefile(lines, 'XscriptPropAboveLinebreak', 'D')
3738 let buf = RunVimInTerminal('-S XscriptPropAboveLinebreak', #{rows: 6})
3739 call VerifyScreenDump(buf, 'Test_prop_above_linebreak_1', {})
3740 call term_sendkeys(buf, 'k')
3741 call VerifyScreenDump(buf, 'Test_prop_above_linebreak_2', {})
3742
3743 call StopVimInTerminal(buf)
3744endfunc
3745
3746func Test_prop_above_and_before()
3747 CheckRunVimInTerminal
3748
3749 let lines =<< trim END
3750 setlocal linebreak breakindent breakindentopt=shift:2
3751 call setline(1, ["a", " b c"])
3752 call prop_type_add('theprop' , #{highlight: 'Special'})
3753 call prop_add(2, 0, #{type: 'theprop', text: ' 123', text_align: 'above'})
3754 call prop_add(2, 4, #{type: 'theprop', text: ': 456'} )
3755 normal! 2gg$
3756 END
3757 call writefile(lines, 'XscriptPropAboveAndBefore', 'D')
3758 let buf = RunVimInTerminal('-S XscriptPropAboveAndBefore', #{rows: 6})
3759 call VerifyScreenDump(buf, 'Test_prop_above_and_before_1', {})
3760 call term_sendkeys(buf, 'h')
3761 call VerifyScreenDump(buf, 'Test_prop_above_and_before_2', {})
3762 call term_sendkeys(buf, 'h')
3763 call VerifyScreenDump(buf, 'Test_prop_above_and_before_3', {})
3764 call term_sendkeys(buf, 'h')
3765 call VerifyScreenDump(buf, 'Test_prop_above_and_before_4', {})
3766 call term_sendkeys(buf, 'h')
3767 call VerifyScreenDump(buf, 'Test_prop_above_and_before_5', {})
3768
3769 call StopVimInTerminal(buf)
3770endfunc
3771
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003772func Test_prop_below_split_line()
3773 CheckRunVimInTerminal
3774
3775 let lines =<< trim END
3776 vim9script
3777 setline(1, ['one one one', 'two two two', 'three three three'])
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003778 prop_type_add('test', {highlight: 'Search'})
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003779 prop_add(2, 0, {
3780 text: '└─ Virtual text below the 2nd line',
3781 type: 'test',
3782 text_align: 'below',
3783 text_padding_left: 3
3784 })
3785 END
3786 call writefile(lines, 'XscriptPropBelowSpitLine', 'D')
3787 let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8})
3788 call term_sendkeys(buf, "2GA\<CR>xx")
3789 call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {})
3790
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003791 call term_sendkeys(buf, "\<Esc>:set number\<CR>")
3792 call VerifyScreenDump(buf, 'Test_prop_below_split_line_2', {})
3793
Bram Moolenaarb84d5652022-09-20 17:57:53 +01003794 call term_sendkeys(buf, ":set nowrap\<CR>")
3795 call VerifyScreenDump(buf, 'Test_prop_below_split_line_3', {})
3796
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003797 call StopVimInTerminal(buf)
3798endfunc
3799
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00003800func Test_prop_above_below_smoothscroll()
3801 CheckRunVimInTerminal
3802
3803 let lines =<< trim END
3804 vim9script
3805 setline(1, range(1, 10)->mapnew((_, v) => '" line ' .. v))
3806
3807 set smoothscroll wrap
3808 call prop_type_add('mytype', {highlight: 'DiffChange'})
3809 call prop_add(3, 0, {text: "insert above", type: "mytype", text_align: 'above'})
3810 call prop_add(5, 0, {text: "insert above 1", type: "mytype", text_align: 'above'})
3811 call prop_add(5, 0, {text: "insert above 2", type: "mytype", text_align: 'above'})
3812 call prop_add(7, 0, {text: "insert below", type: "mytype", text_align: 'below'})
3813 call prop_add(9, 0, {text: "insert below 1", type: "mytype", text_align: 'below'})
3814 call prop_add(9, 0, {text: "insert below 2", type: "mytype", text_align: 'below'})
3815 END
3816 call writefile(lines, 'XscriptPropsSmoothscroll', 'D')
3817 let buf = RunVimInTerminal('-S XscriptPropsSmoothscroll', #{rows: 8, cols: 60})
3818 call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_1', {})
3819
3820 for nr in range(2, 16)
3821 call term_sendkeys(buf, "\<C-E>")
3822 call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_' .. nr, {})
3823 endfor
3824
3825 call StopVimInTerminal(buf)
3826endfunc
3827
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003828func Test_props_with_text_override()
3829 CheckRunVimInTerminal
3830
3831 let lines =<< trim END
3832 vim9script
3833 setline(1, 'some text here')
3834 hi Likethis ctermfg=blue ctermbg=cyan
3835 prop_type_add('prop', {highlight: 'Likethis', override: true})
3836 prop_add(1, 6, {type: 'prop', text: ' inserted '})
3837 hi CursorLine cterm=underline ctermbg=lightgrey
3838 set cursorline
3839 END
Bram Moolenaarebd0e8b2022-09-14 22:13:59 +01003840 call writefile(lines, 'XscriptPropsOverride', 'D')
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003841 let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60})
3842 call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {})
3843
3844 call term_sendkeys(buf, ":set nocursorline\<CR>")
3845 call term_sendkeys(buf, "0llvfr")
3846 call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {})
3847
3848 call StopVimInTerminal(buf)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003849endfunc
3850
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003851func Test_props_with_text_CursorMoved()
3852 CheckRunVimInTerminal
3853
3854 let lines =<< trim END
3855 call setline(1, ['this is line one', 'this is line two', 'three', 'four', 'five'])
3856
3857 call prop_type_add('prop', #{highlight: 'Error'})
3858 let g:long_text = repeat('x', &columns * 2)
3859
3860 let g:prop_id = v:null
3861 func! Update()
3862 if line('.') == 1
3863 if g:prop_id == v:null
3864 let g:prop_id = prop_add(1, 0, #{type: 'prop', text_wrap: 'wrap', text: g:long_text})
3865 endif
3866 elseif g:prop_id != v:null
3867 call prop_remove(#{id: g:prop_id})
3868 let g:prop_id = v:null
3869 endif
3870 endfunc
3871
3872 autocmd CursorMoved * call Update()
3873 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003874 call writefile(lines, 'XscriptPropsCursorMovec', 'D')
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003875 let buf = RunVimInTerminal('-S XscriptPropsCursorMovec', #{rows: 8, cols: 60})
3876 call term_sendkeys(buf, "gg0w")
3877 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
3878
3879 call term_sendkeys(buf, "j")
3880 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_2', {})
3881
3882 " back to the first state
3883 call term_sendkeys(buf, "k")
3884 call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {})
3885
3886 call StopVimInTerminal(buf)
Bram Moolenaar326c5d32022-08-12 13:05:49 +01003887endfunc
3888
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003889func Test_props_with_text_after_split_join()
3890 CheckRunVimInTerminal
3891
3892 let lines =<< trim END
3893 call setline(1, ['1122'])
3894 call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
3895 call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
3896 exe "normal f2i\<CR>\<Esc>"
3897
3898 func AddMore()
3899 call prop_type_add('another', #{highlight: 'Search'})
3900 call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'})
3901 call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'})
3902 endfunc
3903 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003904 call writefile(lines, 'XscriptPropsAfterSplitJoin', 'D')
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003905 let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60})
3906 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {})
3907
3908 call term_sendkeys(buf, "ggJ")
3909 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {})
3910
3911 call term_sendkeys(buf, ":call AddMore()\<CR>")
3912 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {})
3913
3914 call term_sendkeys(buf, "ggf s\<CR>\<Esc>")
3915 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {})
3916
3917 call term_sendkeys(buf, "ggJ")
3918 call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {})
3919
3920 call StopVimInTerminal(buf)
Bram Moolenaar7d0f7e92022-08-06 17:10:57 +01003921endfunc
3922
Bram Moolenaar3a4cd392022-07-30 22:17:18 +01003923func Test_removed_prop_with_text_cleans_up_array()
3924 new
3925 call setline(1, 'some text here')
3926 call prop_type_add('some', #{highlight: 'ErrorMsg'})
3927 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
3928 call assert_equal(-1, id1)
3929 let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"})
3930 call assert_equal(-2, id2)
3931
3932 " removing the props resets the index
3933 call prop_remove(#{id: id1})
3934 call prop_remove(#{id: id2})
3935 let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"})
3936 call assert_equal(-1, id1)
3937
3938 call prop_type_delete('some')
3939 bwipe!
3940endfunc
3941
Bram Moolenaar1f4ee192022-08-01 15:52:55 +01003942def Test_insert_text_before_virtual_text()
3943 new foobar
3944 setline(1, '12345678')
3945 prop_type_add('test', {highlight: 'Search'})
3946 prop_add(1, 5, {
3947 type: 'test',
3948 text: ' virtual text '
3949 })
3950 normal! f4axyz
3951 normal! f5iXYZ
3952 assert_equal('1234xyzXYZ5678', getline(1))
3953
3954 prop_type_delete('test')
3955 bwipe!
3956enddef
3957
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003958func Test_insert_text_start_incl()
3959 CheckRunVimInTerminal
3960
3961 let lines =<< trim END
3962 vim9script
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003963 setline(1, ['text one text two', '', 'function(arg)'])
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003964
3965 prop_type_add('propincl', {highlight: 'NonText', start_incl: true})
3966 prop_add(1, 6, {type: 'propincl', text: 'after '})
3967 cursor(1, 6)
3968 prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false})
3969 prop_add(1, 15, {type: 'propnotincl', text: 'before '})
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003970
Bram Moolenaar94722c52023-01-28 19:19:03 +00003971 set cindent sw=4
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003972 prop_type_add('argname', {highlight: 'DiffChange', start_incl: true})
3973 prop_add(3, 10, {type: 'argname', text: 'arg: '})
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003974 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01003975 call writefile(lines, 'XscriptPropsStartIncl', 'D')
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003976 let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60})
3977 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {})
3978
3979 call term_sendkeys(buf, "i")
3980 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {})
3981 call term_sendkeys(buf, "xx\<Esc>")
3982 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {})
3983
3984 call term_sendkeys(buf, "2wi")
3985 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {})
3986 call term_sendkeys(buf, "yy\<Esc>")
3987 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {})
3988
Bram Moolenaard8d4cfc2022-08-15 15:55:10 +01003989 call term_sendkeys(buf, "3Gfai\<CR>\<Esc>")
3990 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_6', {})
3991 call term_sendkeys(buf, ">>")
3992 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_7', {})
3993 call term_sendkeys(buf, "<<<<")
3994 call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_8', {})
3995
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003996 call StopVimInTerminal(buf)
Bram Moolenaar28c9f892022-08-14 13:28:55 +01003997endfunc
3998
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003999func Test_insert_text_list_mode()
4000 CheckRunVimInTerminal
4001
4002 let lines =<< trim END
4003 vim9script
4004 setline(1, ['This is a line with quite a bit of text here.',
4005 'second line', 'third line'])
4006 set list listchars+=extends:Β»
4007 prop_type_add('Prop1', {highlight: 'Error'})
4008 prop_add(1, 0, {
4009 type: 'Prop1',
4010 text: 'The quick brown fox jumps over the lazy dog',
4011 text_align: 'right'
4012 })
4013 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004014 call writefile(lines, 'XscriptPropsListMode', 'D')
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01004015 let buf = RunVimInTerminal('-S XscriptPropsListMode', #{rows: 8, cols: 60})
4016 call term_sendkeys(buf, "ggj")
4017 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_1', {})
4018
4019 call term_sendkeys(buf, ":set nowrap\<CR>")
4020 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_2', {})
4021
4022 call term_sendkeys(buf, "ggd32l")
4023 call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_3', {})
4024
4025 call StopVimInTerminal(buf)
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01004026endfunc
4027
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004028func Test_insert_text_with_padding()
4029 CheckRunVimInTerminal
4030
4031 let lines =<< trim END
4032 vim9script
4033 setline(1, ['Some text to add virtual text to.',
4034 'second line',
4035 'Another line with some text to make the wrap.'])
4036 prop_type_add('theprop', {highlight: 'DiffChange'})
4037 prop_add(1, 0, {
4038 type: 'theprop',
4039 text: 'after',
4040 text_align: 'after',
4041 text_padding_left: 3,
4042 })
4043 prop_add(1, 0, {
4044 type: 'theprop',
4045 text: 'right aligned',
4046 text_align: 'right',
4047 text_padding_left: 5,
4048 })
4049 prop_add(1, 0, {
4050 type: 'theprop',
4051 text: 'below the line',
4052 text_align: 'below',
4053 text_padding_left: 4,
4054 })
4055 prop_add(3, 0, {
4056 type: 'theprop',
4057 text: 'rightmost',
4058 text_align: 'right',
4059 text_padding_left: 6,
4060 text_wrap: 'wrap',
4061 })
4062 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004063 call writefile(lines, 'XscriptPropsPadded', 'D')
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004064 let buf = RunVimInTerminal('-S XscriptPropsPadded', #{rows: 8, cols: 60})
4065 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_1', {})
4066
4067 call term_sendkeys(buf, "ggixxxxxxxxxx\<Esc>")
4068 call term_sendkeys(buf, "3Gix\<Esc>")
4069 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_2', {})
4070
4071 call term_sendkeys(buf, "ggix\<Esc>")
4072 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_3', {})
4073
Bram Moolenaara4abe512022-09-15 19:44:09 +01004074 call term_sendkeys(buf, ":set list\<CR>")
4075 call VerifyScreenDump(buf, 'Test_prop_text_with_padding_4', {})
4076
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004077 call StopVimInTerminal(buf)
Bram Moolenaarf396ce82022-08-23 18:39:37 +01004078endfunc
4079
Bram Moolenaar13845c42022-10-09 15:26:03 +01004080func Test_long_text_below_with_padding()
4081 CheckRunVimInTerminal
4082
4083 let lines =<< trim END
4084 vim9script
4085 setline(1, ['first line', 'second line'])
4086 prop_type_add('theprop', {highlight: 'DiffChange'})
4087 prop_add(1, 0, {
4088 type: 'theprop',
4089 text: 'after '->repeat(20),
4090 text_align: 'below',
4091 text_padding_left: 3,
4092 })
4093 prop_add(1, 0, {
4094 type: 'theprop',
4095 text: 'more '->repeat(20),
4096 text_align: 'below',
4097 text_padding_left: 30,
4098 })
4099 normal 2Gw
4100 END
4101 call writefile(lines, 'XlongTextBelowWithPadding', 'D')
4102 let buf = RunVimInTerminal('-S XlongTextBelowWithPadding', #{rows: 8, cols: 60})
4103 call VerifyScreenDump(buf, 'Test_long_text_with_padding_1', {})
4104
Bram Moolenaara9a36482022-10-11 16:47:22 +01004105 call term_sendkeys(buf, ":set list\<CR>")
4106 call VerifyScreenDump(buf, 'Test_long_text_with_padding_2', {})
4107
Bram Moolenaar13845c42022-10-09 15:26:03 +01004108 call StopVimInTerminal(buf)
4109endfunc
4110
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004111func Test_text_after_nowrap()
4112 CheckRunVimInTerminal
4113
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004114 let lines =<< trim END
4115 vim9script
Bram Moolenaarcd105412022-10-10 19:50:42 +01004116 setline(1, ['first line', range(80)->join(' '), 'third', 'fourth'])
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004117 set nowrap
4118 prop_type_add('theprop', {highlight: 'DiffChange'})
4119 prop_add(1, 0, {
4120 type: 'theprop',
Bram Moolenaarcd105412022-10-10 19:50:42 +01004121 text: 'right after the text '->repeat(3),
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004122 text_align: 'after',
4123 text_padding_left: 2,
4124 })
Bram Moolenaarcd105412022-10-10 19:50:42 +01004125 prop_add(1, 0, {
4126 type: 'theprop',
4127 text: 'in the middle '->repeat(4),
4128 text_align: 'after',
4129 text_padding_left: 3,
4130 })
4131 prop_add(1, 0, {
4132 type: 'theprop',
4133 text: 'the last one '->repeat(3),
4134 text_align: 'after',
4135 text_padding_left: 1,
4136 })
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004137 normal 2Gw
Bram Moolenaar7e017462022-10-11 21:02:09 +01004138 def g:ChangeText()
4139 prop_clear(1)
4140 set list
4141 prop_add(1, 0, {
4142 type: 'theprop',
4143 text: 'just after txt '->repeat(3),
4144 text_align: 'after',
4145 text_padding_left: 2,
4146 })
4147 prop_add(1, 0, {
4148 type: 'theprop',
4149 text: 'in the middle '->repeat(4),
4150 text_align: 'after',
4151 text_padding_left: 1,
4152 })
4153 enddef
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004154 END
4155 call writefile(lines, 'XTextAfterNowrap', 'D')
4156 let buf = RunVimInTerminal('-S XTextAfterNowrap', #{rows: 8, cols: 60})
4157 call VerifyScreenDump(buf, 'Test_text_after_nowrap_1', {})
4158
Bram Moolenaarcd105412022-10-10 19:50:42 +01004159 call term_sendkeys(buf, "30w")
4160 call VerifyScreenDump(buf, 'Test_text_after_nowrap_2', {})
4161
4162 call term_sendkeys(buf, "22w")
4163 call VerifyScreenDump(buf, 'Test_text_after_nowrap_3', {})
4164
4165 call term_sendkeys(buf, "$")
4166 call VerifyScreenDump(buf, 'Test_text_after_nowrap_4', {})
4167
Bram Moolenaar7e017462022-10-11 21:02:09 +01004168 call term_sendkeys(buf, "0")
4169 call term_sendkeys(buf, ":call ChangeText()\<CR>")
4170 call VerifyScreenDump(buf, 'Test_text_after_nowrap_5', {})
4171
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01004172 call StopVimInTerminal(buf)
4173endfunc
4174
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00004175func Test_text_after_nowrap_list()
4176 CheckRunVimInTerminal
4177
4178 let lines =<< trim END
4179 vim9script
4180
4181 set nowrap
4182 set listchars+=extends:>
4183 set list
4184 setline(1, ['some text here', '', 'last line'])
4185
4186 prop_type_add('test', {highlight: 'DiffChange'})
4187 prop_add(1, 0, {
4188 type: 'test',
4189 text: 'The quick brown fox jumps.',
4190 text_padding_left: 2,
4191 })
4192 prop_add(1, 0, {
4193 type: 'test',
4194 text: 'β–  The fox jumps over the lazy dog.',
4195 text_padding_left: 2,
4196 })
4197 prop_add(1, 0, {
4198 type: 'test',
4199 text: 'β–  The lazy dog.',
4200 text_padding_left: 2,
4201 })
4202 normal 3G$
4203 END
4204 call writefile(lines, 'XTextAfterNowrapList', 'D')
4205 let buf = RunVimInTerminal('-S XTextAfterNowrapList', #{rows: 6, cols: 60})
4206 call VerifyScreenDump(buf, 'Test_text_after_nowrap_list_1', {})
4207
4208 call StopVimInTerminal(buf)
4209endfunc
4210
Bram Moolenaar1206c162022-10-10 15:40:04 +01004211func Test_text_below_nowrap()
4212 CheckRunVimInTerminal
4213
4214 let lines =<< trim END
4215 vim9script
4216 setline(1, ['first line', 'second line '->repeat(50), 'third', 'fourth'])
4217 set nowrap number
4218 prop_type_add('theprop', {highlight: 'DiffChange'})
4219 prop_add(1, 0, {
4220 type: 'theprop',
4221 text: 'one below the text '->repeat(5),
4222 text_align: 'below',
4223 text_padding_left: 2,
4224 })
4225 prop_add(1, 0, {
4226 type: 'theprop',
4227 text: 'two below the text '->repeat(5),
4228 text_align: 'below',
4229 text_padding_left: 2,
4230 })
4231 normal 2Gw
4232 END
4233 call writefile(lines, 'XTextBelowNowrap', 'D')
4234 let buf = RunVimInTerminal('-S XTextBelowNowrap', #{rows: 8, cols: 60})
4235 call VerifyScreenDump(buf, 'Test_text_below_nowrap_1', {})
4236
4237 call StopVimInTerminal(buf)
4238endfunc
4239
Dylan Thacker-Smith80557212024-02-21 21:00:59 +01004240func Test_virtual_text_overlap_with_highlight()
4241 CheckRunVimInTerminal
4242
4243 let lines =<< trim END
4244 vim9script
4245 setline(1, ['one', 'two', 'three', 'four', 'five'])
4246 set number
4247
4248 prop_type_add('demo_highlight_warning', {highlight: 'WarningMsg'})
4249 prop_type_add('demo_virtual_text_error', {highlight: 'Error'})
4250
4251 prop_add(2, 4, {
4252 type: 'demo_highlight_warning',
4253 end_col: 4,
4254 })
4255 prop_add(2, 0, {
4256 type: 'demo_virtual_text_error',
4257 text: 'syntax error',
4258 text_align: 'below',
4259 })
4260 normal 2j
4261
4262 prop_add(4, 4, {
4263 type: 'demo_highlight_warning',
4264 end_lnum: 5,
4265 end_col: 1,
4266 })
4267 prop_add(4, 0, {
4268 type: 'demo_virtual_text_error',
4269 text: 'other error',
4270 text_align: 'right',
4271 })
4272 END
4273 call writefile(lines, 'XVirtualTextOverlapWithHighlight', 'D')
4274 let buf = RunVimInTerminal('-S XVirtualTextOverlapWithHighlight', #{rows: 8, cols: 60})
4275 call VerifyScreenDump(buf, 'Test_virtual_text_overlap_with_highlight_1', {})
4276
4277 call StopVimInTerminal(buf)
4278endfunc
4279
Bram Moolenaaree28c702022-11-17 14:56:00 +00004280func Test_virtual_text_in_popup_highlight()
4281 CheckRunVimInTerminal
4282
4283 let lines =<< trim END
4284 vim9script
4285
4286 # foreground highlight only, popup background is used
4287 prop_type_add('Prop1', {'highlight': 'SpecialKey'})
4288 # foreground and background highlight, popup background is not used
4289 prop_type_add('Prop2', {'highlight': 'DiffDelete'})
4290
4291 var popupText = [{
4292 text: 'Some text',
4293 props: [
4294 {
4295 col: 1,
4296 type: 'Prop1',
4297 text: ' + '
4298 },
4299 {
4300 col: 6,
4301 type: 'Prop2',
4302 text: ' x '
4303 },
4304 ]
4305 }]
4306 var popupArgs = {
4307 line: 3,
4308 col: 20,
4309 maxwidth: 80,
4310 highlight: 'PMenu',
4311 border: [],
4312 borderchars: [' '],
4313 }
4314
4315 popup_create(popupText, popupArgs)
4316 END
4317 call writefile(lines, 'XscriptVirtualHighlight', 'D')
4318 let buf = RunVimInTerminal('-S XscriptVirtualHighlight', #{rows: 8})
4319 call VerifyScreenDump(buf, 'Test_virtual_text_in_popup_highlight_1', {})
4320
4321 call StopVimInTerminal(buf)
4322endfunc
4323
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004324func Test_insert_text_change_arg()
4325 CheckRunVimInTerminal
4326
4327 let lines =<< trim END
4328 vim9script
4329 setline(1, ['SetErrorCode( 10, 20 )', 'second line'])
4330 prop_type_add('param', {highlight: 'DiffChange', start_incl: 1})
4331 prop_type_add('padd', {highlight: 'NonText', start_incl: 1})
4332 prop_add(1, 15, {
4333 type: 'param',
4334 text: 'id:',
4335 })
4336 prop_add(1, 15, {
4337 type: 'padd',
4338 text: '-',
4339 })
4340 prop_add(1, 19, {
4341 type: 'param',
4342 text: 'id:',
4343 })
4344 prop_add(1, 19, {
4345 type: 'padd',
4346 text: '-',
4347 })
4348 END
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +01004349 call writefile(lines, 'XscriptPropsChange', 'D')
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004350 let buf = RunVimInTerminal('-S XscriptPropsChange', #{rows: 5, cols: 60})
4351 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_1', {})
4352
4353 call term_sendkeys(buf, "ggf1cw1234\<Esc>")
4354 call VerifyScreenDump(buf, 'Test_prop_text_change_arg_2', {})
4355
4356 call StopVimInTerminal(buf)
Bram Moolenaarf5240b92022-08-24 12:24:37 +01004357endfunc
4358
Bram Moolenaar2f7bfe62022-11-13 12:54:50 +00004359def Test_textprop_in_quickfix_window()
4360 enew!
4361 var prop_type = 'my_prop'
4362 prop_type_add(prop_type, {})
4363
4364 for lnum in range(1, 10)
4365 setline(lnum, 'hello world')
4366 endfor
4367
4368 cgetbuffer
4369 copen
4370
4371 var bufnr = bufnr()
4372 for lnum in range(1, line('$', bufnr->bufwinid()))
4373 prop_add(lnum, 1, {
4374 id: 1000 + lnum,
4375 type: prop_type,
4376 bufnr: bufnr,
4377 })
4378 endfor
4379
4380 prop_type_delete(prop_type)
4381 cclose
4382 bwipe!
4383enddef
4384
Bram Moolenaar89469d12022-12-02 20:46:26 +00004385func Test_text_prop_delete_updates()
4386 CheckRunVimInTerminal
4387
4388 let lines =<< trim END
4389 vim9script
4390
4391 setline(1, ['some text', 'more text', 'the end'])
4392 prop_type_add('test', {highlight: 'DiffChange'})
4393 prop_add(1, 0, {
4394 type: 'test',
4395 text: 'The quick brown fox jumps over the lazy dog',
4396 text_align: 'below',
4397 text_padding_left: 3,
4398 })
4399 prop_add(1, 0, {
4400 type: 'test',
4401 text: 'The quick brown fox jumps over the lazy dog',
4402 text_align: 'below',
4403 text_padding_left: 5,
4404 })
4405
4406 normal! G
4407 END
4408 call writefile(lines, 'XtextPropDelete', 'D')
4409 let buf = RunVimInTerminal('-S XtextPropDelete', #{rows: 10, cols: 60})
4410 call VerifyScreenDump(buf, 'Test_prop_delete_updates_1', {})
4411
4412 " Check that after deleting the text prop type the text properties using
4413 " this type no longer show and are not counted for cursor positioning.
4414 call term_sendkeys(buf, ":call prop_type_delete('test')\<CR>")
4415 call VerifyScreenDump(buf, 'Test_prop_delete_updates_2', {})
4416
4417 call term_sendkeys(buf, "ggj")
4418 call VerifyScreenDump(buf, 'Test_prop_delete_updates_3', {})
4419
4420 call StopVimInTerminal(buf)
4421endfunc
4422
Bram Moolenaard097af72022-12-17 11:33:00 +00004423func Test_text_prop_diff_mode()
4424 CheckRunVimInTerminal
4425
4426 let lines =<< trim END
4427 call setline(1, ['9000', '0009', '0009', '9000', '0009'])
4428
4429 let type = 'test'
4430 call prop_type_add(type, {})
4431 let text = '<text>'
4432 call prop_add(1, 1, {'type': type, 'text': text})
4433 call prop_add(2, 0, {'type': type, 'text': text, 'text_align': 'after'})
4434 call prop_add(3, 0, {'type': type, 'text': text, 'text_align': 'right'})
4435 call prop_add(4, 0, {'type': type, 'text': text, 'text_align': 'above'})
4436 call prop_add(5, 0, {'type': type, 'text': text, 'text_align': 'below'})
4437 set diff
4438
4439 vnew
4440 call setline(1, ['000', '000', '000', '000', '000'])
4441 set diff
4442 END
4443 call writefile(lines, 'XtextPropDiff', 'D')
4444 let buf = RunVimInTerminal('-S XtextPropDiff', #{rows: 10, cols: 60})
4445 call VerifyScreenDump(buf, 'Test_prop_diff_mode_1', {})
4446
4447 call term_sendkeys(buf, ":windo set number\<CR>")
4448 call VerifyScreenDump(buf, 'Test_prop_diff_mode_2', {})
4449
4450 call StopVimInTerminal(buf)
4451endfunc
Bram Moolenaar94722c52023-01-28 19:19:03 +00004452
Bram Moolenaar4ce1f992022-12-19 13:31:06 +00004453func Test_error_when_using_negative_id()
4454 call prop_type_add('test1', #{highlight: 'ErrorMsg'})
4455 call prop_add(1, 1, #{type: 'test1', text: 'virtual'})
4456 call assert_fails("call prop_add(1, 1, #{type: 'test1', length: 1, id: -1})", 'E1293:')
4457
4458 call prop_type_delete('test1')
4459endfunc
4460
4461func Test_error_after_using_negative_id()
4462 " This needs to run a separate Vim instance because the
4463 " "did_use_negative_pop_id" will be set.
4464 CheckRunVimInTerminal
4465
4466 let lines =<< trim END
4467 vim9script
4468
4469 setline(1, ['one', 'two', 'three'])
4470 prop_type_add('test_1', {highlight: 'Error'})
4471 prop_type_add('test_2', {highlight: 'WildMenu'})
4472
4473 prop_add(3, 1, {
4474 type: 'test_1',
4475 length: 5,
4476 id: -1
4477 })
4478
4479 def g:AddTextprop()
4480 prop_add(1, 0, {
4481 type: 'test_2',
4482 text: 'The quick fox',
4483 text_padding_left: 2
4484 })
4485 enddef
4486 END
4487 call writefile(lines, 'XtextPropError', 'D')
4488 let buf = RunVimInTerminal('-S XtextPropError', #{rows: 8, cols: 60})
4489 call VerifyScreenDump(buf, 'Test_prop_negative_error_1', {})
4490
4491 call term_sendkeys(buf, ":call AddTextprop()\<CR>")
4492 call VerifyScreenDump(buf, 'Test_prop_negative_error_2', {})
4493
4494 call StopVimInTerminal(buf)
4495endfunc
Bram Moolenaard097af72022-12-17 11:33:00 +00004496
Ibbya6ab5e62023-08-20 20:24:18 +02004497func Test_modify_text_before_prop()
4498 CheckRunVimInTerminal
4499
4500 let lines =<< trim END
4501 vim9script
4502 setline(1, ['test_words', 'second line', 'third line', 'fourth line'])
4503 set number
4504 prop_type_add('text', {highlight: 'DiffChange'})
4505 prop_type_add('below', {highlight: 'NonText'})
4506 prop_add(1, 11, {type: 'text', text: repeat('a', 65)})
4507 prop_add(1, 0, {type: 'below', text: repeat('a', 65), text_align: 'below'})
4508 END
4509 call writefile(lines, 'XtextPropModifyBefore', 'D')
4510 let buf = RunVimInTerminal('-S XtextPropModifyBefore', #{rows: 5, cols: 60})
4511 call VerifyScreenDump(buf, 'Test_modify_text_before_prop_1', {})
4512
4513 call term_sendkeys(buf, "xxia\<Esc>")
4514 call VerifyScreenDump(buf, 'Test_modify_text_before_prop_2', {})
4515
4516 call StopVimInTerminal(buf)
4517endfunc
4518
Christian Brabandtf1cc4d52023-08-12 00:14:14 +02004519func Test_overlong_textprop_above_crash()
4520 CheckRunVimInTerminal
Bram Moolenaar2f7bfe62022-11-13 12:54:50 +00004521
Christian Brabandtf1cc4d52023-08-12 00:14:14 +02004522 let lines =<< trim END
4523 vim9script
4524 prop_type_add('PropType', {highlight: 'Error'})
4525 setline(1, ['xxx ', 'yyy'])
4526 prop_add(1, 0, {
4527 type: 'PropType',
4528 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.',
4529 text_align: 'above',
4530 text_wrap: 'wrap',
4531 })
4532 END
4533 call writefile(lines, 'XtextPropLongAbove', 'D')
4534 let buf = RunVimInTerminal('-S XtextPropLongAbove', #{rows: 8, cols: 60})
4535 call VerifyScreenDump(buf, 'Test_prop_long_above_1', {})
4536
4537 call StopVimInTerminal(buf)
4538endfunc
Christian Brabandtdbeadf02023-08-19 15:35:04 +02004539
4540func Test_text_prop_list_hl_and_sign_highlight()
4541 CheckRunVimInTerminal
4542
4543 let lines =<< trim END
4544 func Test()
4545 split Xbuffer
4546 call setline(1, ['one', "\ttab", ' space', 'three', 'four', 'five'])
4547 call prop_type_add('Prop1', #{highlight: 'Search', override: v:true})
4548 sign define sign1 text=>> linehl=DiffAdd
4549 sign place 10 line=2 name=sign1
4550 sign place 20 line=3 name=sign1
4551 call prop_add(1, 1, #{end_lnum: 4, end_col: 5, type: 'Prop1'})
4552 sign place 30 line=5 name=sign1
4553 endfunc
4554 call Test()
4555 END
4556 call writefile(lines, 'XtextPropSignTab', 'D')
4557 let buf = RunVimInTerminal('-S XtextPropSignTab', #{rows: 8, cols: 60})
4558 call VerifyScreenDump(buf, 'Test_prop_sign_tab_1', {})
4559
4560 call term_sendkeys(buf, ":setl list listchars=eol:ΒΆ,tab:>-\<CR>")
4561 call VerifyScreenDump(buf, 'Test_prop_sign_tab_2', {})
4562
4563 call StopVimInTerminal(buf)
4564endfunc
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004565
4566" Test for getting the virtual text properties
4567func Test_virtual_text_get()
4568 new foobar
4569 call setline(1, '12345678')
4570 call prop_type_add('test', #{highlight: 'Search'})
4571 call prop_add(1, 2, #{type: 'test', text: ' virtual text1 '})
4572 call prop_add(1, 3, #{type: 'test'})
4573 call prop_add(1, 0, #{type: 'test', text: ' virtual text2 ',
4574 \ text_align: 'right'})
4575 call prop_add(1, 5, #{type: 'test'})
4576 call prop_add(1, 6, #{type: 'test', text: ' virtual text3 ',
4577 \ text_wrap: 'wrap'})
4578
4579 let p = prop_list(1, #{end_lnum: -1})
4580 call assert_equal(
Yegappan Lakshmanan171c5b92023-08-22 21:48:50 +02004581 \ #{lnum: 1, col: 2, type_bufnr: 0, end: 1,
4582 \ type: 'test', start: 1,
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004583 \ text: ' virtual text1 '}, p[0])
4584 call assert_equal(
4585 \ #{lnum: 1, id: 0, col: 3, type_bufnr: 0, end: 1,
4586 \ type: 'test', length: 0, start: 1}, p[1])
4587 call assert_equal(
4588 \ #{lnum: 1, id: 0, col: 5, type_bufnr: 0, end: 1,
4589 \ type: 'test', length: 0, start: 1}, p[2])
4590 call assert_equal(
Yegappan Lakshmanan171c5b92023-08-22 21:48:50 +02004591 \ #{lnum: 1, col: 6, type_bufnr: 0, end: 1, type: 'test',
4592 \ text_wrap: 'wrap', start: 1, text: ' virtual text3 '},
Yegappan Lakshmananf9037f12023-08-20 18:27:45 +02004593 \ p[3])
4594 call assert_equal('right', p[4].text_align)
4595
4596 call prop_type_delete('test')
4597 bwipe!
4598endfunc
4599
Christian Brabandt0d0b3b12023-12-03 17:56:43 +01004600" This used to throw: E967
4601func Test_textprop_notype_join()
4602 new Xtextprop_no_type_join
4603 call setline(1, range(1, 3))
4604 call cursor(1, 1)
4605 let name = 'a'
4606 call prop_type_add(name, {})
4607 call prop_add(line('.'), col('.'), { 'type': name })
4608 call prop_type_delete(name, {})
4609 join
4610 call assert_equal(["1 2", "3"], getline(1, '$'))
4611
4612 bwipe!
4613endfunc
4614
zeertzjq7ac11452024-03-06 20:54:22 +01004615" This was causing text property corruption.
4616func Test_textprop_backspace_fo_aw()
4617 new
4618 call setline(1, 'foobar')
4619 call prop_type_add('test', {'highlight': 'ErrorMsg'})
4620 call prop_add(1, 1, {'type': 'test', 'length': 3})
4621 set backspace=indent,eol,start
4622 setlocal formatoptions+=aw
4623 call feedkeys("A \<CR>\<BS>\<Esc>", 'tx')
4624 call assert_equal('foobar', getline(1))
4625 call assert_equal([
4626 \ #{id: 0, col: 1, start: 1, end: 1, type_bufnr: 0,
4627 \ type: 'test', length: 3}], prop_list(1))
4628
4629 bwipe!
4630 set backspace&
4631 call prop_type_delete('test')
4632endfunc
4633
zeertzjq9352c282024-03-14 18:16:56 +01004634func Test_textprop_with_wincolor()
4635 CheckRunVimInTerminal
4636
4637 let lines =<< trim END
4638 call setline(1, 'some text here')
4639 call setline(2, 'some much longer text here')
4640 call setline(3, 'more text here')
4641 call prop_type_add('afterprop', #{highlight: 'Search'})
4642 call prop_type_add('belowprop', #{highlight: 'DiffAdd'})
4643 call prop_add(3, 0, #{type: 'afterprop', text: 'AFTER',
4644 \ text_align: 'after', text_padding_left: 3})
4645 call prop_add(1, 0, #{type: 'belowprop', text: 'BELOW',
4646 \ text_align: 'below', text_padding_left: 3})
4647 set wincolor=DiffChange wrap
4648 END
4649 call writefile(lines, 'XtextPropWincolor', 'D')
4650 let buf = RunVimInTerminal('-S XtextPropWincolor', #{rows: 8, cols: 60})
4651
4652 call term_sendkeys(buf, ":\<CR>")
4653 call VerifyScreenDump(buf, 'Test_prop_wincolor_1', {})
4654
4655 call term_sendkeys(buf, ":set cursorline\<CR>:\<CR>")
4656 call VerifyScreenDump(buf, 'Test_prop_wincolor_2', {})
4657
4658 call term_sendkeys(buf, ":set nowrap\<CR>:\<CR>")
4659 call VerifyScreenDump(buf, 'Test_prop_wincolor_2', {})
4660
4661 call term_sendkeys(buf, ":set nocursorline\<CR>:\<CR>")
4662 call VerifyScreenDump(buf, 'Test_prop_wincolor_1', {})
4663
4664 call term_sendkeys(buf, ":set cursorline colorcolumn=30\<CR>:\<CR>")
4665 call VerifyScreenDump(buf, 'Test_prop_wincolor_3', {})
4666
4667 call term_sendkeys(buf, ":hi CursorLine ctermbg=Brown\<CR>:\<CR>")
4668 call VerifyScreenDump(buf, 'Test_prop_wincolor_4', {})
4669
4670 call term_sendkeys(buf, ":set cursorcolumn\<CR>:\<CR>")
4671 call term_sendkeys(buf, '$')
4672 call VerifyScreenDump(buf, 'Test_prop_wincolor_5', {})
4673
4674 call term_sendkeys(buf, 'j')
4675 call VerifyScreenDump(buf, 'Test_prop_wincolor_6', {})
4676
4677 call term_sendkeys(buf, ":set virtualedit=all\<CR>:\<CR>")
4678 call term_sendkeys(buf, 'l')
4679 call VerifyScreenDump(buf, 'Test_prop_wincolor_7', {})
4680
4681 call term_sendkeys(buf, 'k')
4682 call VerifyScreenDump(buf, 'Test_prop_wincolor_8', {})
4683
zeertzjqf6272552024-03-17 10:01:47 +01004684 if has('rightleft')
4685 call term_sendkeys(buf, ":set rightleft\<CR>:\<CR>")
4686 call VerifyScreenDump(buf, 'Test_prop_wincolor_9', {})
4687 endif
4688
zeertzjq9352c282024-03-14 18:16:56 +01004689 call StopVimInTerminal(buf)
4690endfunc
4691
Bram Moolenaar99fa7212020-04-26 15:59:55 +02004692" vim: shiftwidth=2 sts=2 expandtab