comparison src/testdir/test_textprop.vim @ 25392:b427a26b0210 v8.2.3233

patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer Commit: https://github.com/vim/vim/commit/e2390c7f32879ab7942adf0d38b1db34933695fa Author: Martin Tournoij <martin@arp242.net> Date: Wed Jul 28 13:30:16 2021 +0200 patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer Problem: prop_list() and prop_find() do not indicate the buffer for the used type. Solution: Add "type_bufnr" to the results. (closes #8647)
author Bram Moolenaar <Bram@vim.org>
date Wed, 28 Jul 2021 13:45:03 +0200
parents eafc0e07b188
children e06540cc3371
comparison
equal deleted inserted replaced
25391:df2096e6825e 25392:b427a26b0210
37 call assert_equal(0, len(prop_type_list())) 37 call assert_equal(0, len(prop_type_list()))
38 endfunc 38 endfunc
39 39
40 func Test_proptype_buf() 40 func Test_proptype_buf()
41 let bufnr = bufnr('') 41 let bufnr = bufnr('')
42 call prop_type_add('comment', {'bufnr': bufnr, 'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) 42 call prop_type_add('comment', #{bufnr: bufnr, highlight: 'Directory', priority: 123, start_incl: 1, end_incl: 1})
43 let proptypes = prop_type_list({'bufnr': bufnr}) 43 let proptypes = prop_type_list({'bufnr': bufnr})
44 call assert_equal(1, len(proptypes)) 44 call assert_equal(1, len(proptypes))
45 call assert_equal('comment', proptypes[0]) 45 call assert_equal('comment', proptypes[0])
46 46
47 let proptype = prop_type_get('comment', {'bufnr': bufnr}) 47 let proptype = prop_type_get('comment', {'bufnr': bufnr})
68 call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) 68 call assert_equal(0, len(prop_type_list({'bufnr': bufnr})))
69 69
70 call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:") 70 call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
71 endfunc 71 endfunc
72 72
73 def Test_proptype_buf_list()
74 new
75 var bufnr = bufnr('')
76 try
77 prop_type_add('global', {})
78 prop_type_add('local', {bufnr: bufnr})
79
80 prop_add(1, 1, {type: 'global'})
81 prop_add(1, 1, {type: 'local'})
82
83 assert_equal([
84 {type: 'local', type_bufnr: bufnr, id: 0, col: 1, end: 1, length: 0, start: 1},
85 {type: 'global', type_bufnr: 0, id: 0, col: 1, end: 1, length: 0, start: 1},
86 ], prop_list(1))
87 assert_equal(
88 {lnum: 1, id: 0, col: 1, type_bufnr: bufnr, end: 1, type: 'local', length: 0, start: 1},
89 prop_find({lnum: 1, type: 'local'}))
90 assert_equal(
91 {lnum: 1, id: 0, col: 1, type_bufnr: 0, end: 1, type: 'global', length: 0, start: 1},
92 prop_find({lnum: 1, type: 'global'}))
93
94 prop_remove({type: 'global'}, 1)
95 prop_remove({type: 'local'}, 1)
96 finally
97 prop_type_delete('global')
98 prop_type_delete('local', {bufnr: bufnr})
99 bwipe!
100 endtry
101 enddef
102
73 func AddPropTypes() 103 func AddPropTypes()
74 call prop_type_add('one', {}) 104 call prop_type_add('one', {})
75 call prop_type_add('two', {}) 105 call prop_type_add('two', {})
76 call prop_type_add('three', {}) 106 call prop_type_add('three', {})
77 call prop_type_add('whole', {}) 107 call prop_type_add('whole', {})
92 call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) 122 call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'})
93 endfunc 123 endfunc
94 124
95 func Get_expected_props() 125 func Get_expected_props()
96 return [ 126 return [
97 \ {'col': 1, 'length': 13, 'id': 14, 'type': 'whole', 'start': 1, 'end': 1}, 127 \ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1},
98 \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, 128 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
99 \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, 129 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
100 \ {'col': 9, 'length': 5, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, 130 \ #{type_bufnr: 0, col: 9, length: 5, id: 13, type: 'three', start: 1, end: 1},
101 \ ] 131 \ ]
102 endfunc 132 endfunc
103 133
104 func Test_prop_find() 134 func Test_prop_find()
105 new 135 new
106 call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix']) 136 call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix'])
107 137
108 " Add two text props on lines 1 and 5, and one spanning lines 2 to 4. 138 " Add two text props on lines 1 and 5, and one spanning lines 2 to 4.
109 call prop_type_add('prop_name', {'highlight': 'Directory'}) 139 call prop_type_add('prop_name', {'highlight': 'Directory'})
110 call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3}) 140 call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3})
111 call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9}) 141 call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9})
112 call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1}) 142 call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1})
113 143
114 let expected = [ 144 let expected = [
115 \ {'lnum': 1, 'col': 5, 'length': 3, 'id': 10, 'type': 'prop_name', 'start': 1, 'end': 1}, 145 \ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1},
116 \ {'lnum': 2, 'col': 4, 'id': 11, 'type': 'prop_name', 'start': 1, 'end': 0}, 146 \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0},
117 \ {'lnum': 5, 'col': 4, 'length': 1, 'id': 12, 'type': 'prop_name', 'start': 1, 'end': 1} 147 \ #{type_bufnr: 0, lnum: 5, col: 4, length: 1, id: 12, type: 'prop_name', start: 1, end: 1}
118 \ ] 148 \ ]
119 149
120 " Starting at line 5 col 1 this should find the prop at line 5 col 4. 150 " Starting at line 5 col 1 this should find the prop at line 5 col 4.
121 call cursor(5,1) 151 call cursor(5,1)
122 let result = prop_find({'type': 'prop_name'}, 'f') 152 let result = prop_find({'type': 'prop_name'}, 'f')
182 endif 212 endif
183 call assert_equal(expected[i], result) 213 call assert_equal(expected[i], result)
184 let lnum = result.lnum 214 let lnum = result.lnum
185 let col = result.col 215 let col = result.col
186 let i = i - 1 216 let i = i - 1
187 endwhile 217 endwhile
188 218
189 " Starting from line 6 col 1 search backwards for prop with id 10. 219 " Starting from line 6 col 1 search backwards for prop with id 10.
190 call cursor(6,1) 220 call cursor(6,1)
191 let result = prop_find({'id': 10, 'skipstart': 1}, 'b') 221 let result = prop_find({'id': 10, 'skipstart': 1}, 'b')
192 call assert_equal(expected[0], result) 222 call assert_equal(expected[0], result)
224 for col in [8, 14, 24, 38] 254 for col in [8, 14, 24, 38]
225 prop_add(lnum, col, {type: 'misspell', length: 2}) 255 prop_add(lnum, col, {type: 'misspell', length: 2})
226 endfor 256 endfor
227 endfor 257 endfor
228 cursor(1, 8) 258 cursor(1, 8)
229 var expected = {lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1} 259 var expected = {type_bufnr: 0, lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1}
230 var result = prop_find({type: 'misspell', skipstart: true}, 'f') 260 var result = prop_find({type: 'misspell', skipstart: true}, 'f')
231 assert_equal(expected, result) 261 assert_equal(expected, result)
232 262
233 prop_type_delete('misspell') 263 prop_type_delete('misspell')
234 bwipe! 264 bwipe!
237 func Test_prop_find_smaller_len_than_match_col() 267 func Test_prop_find_smaller_len_than_match_col()
238 new 268 new
239 call prop_type_add('test', {'highlight': 'ErrorMsg'}) 269 call prop_type_add('test', {'highlight': 'ErrorMsg'})
240 call setline(1, ['xxxx', 'x']) 270 call setline(1, ['xxxx', 'x'])
241 call prop_add(1, 4, {'type': 'test'}) 271 call prop_add(1, 4, {'type': 'test'})
242 call assert_equal({'id': 0, 'lnum': 1, 'col': 4, 'type': 'test', 'length': 0, 'start': 1, 'end': 1}, 272 call assert_equal(
273 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 4, type: 'test', length: 0, start: 1, end: 1},
243 \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b')) 274 \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b'))
244 bwipe! 275 bwipe!
245 call prop_type_delete('test') 276 call prop_type_delete('test')
246 endfunc 277 endfunc
247 278
270 call SetupPropsInFirstLine() 301 call SetupPropsInFirstLine()
271 let expected_props = Get_expected_props() 302 let expected_props = Get_expected_props()
272 call assert_equal(expected_props, prop_list(1)) 303 call assert_equal(expected_props, prop_list(1))
273 call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') 304 call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:')
274 call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') 305 call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:')
275 306
276 " Insert a line above, text props must still be there. 307 " Insert a line above, text props must still be there.
277 call append(0, 'empty') 308 call append(0, 'empty')
278 call assert_equal(expected_props, prop_list(2)) 309 call assert_equal(expected_props, prop_list(2))
279 " Delete a line above, text props must still be there. 310 " Delete a line above, text props must still be there.
280 1del 311 1del
282 313
283 " Prop without length or end column is zero length 314 " Prop without length or end column is zero length
284 call prop_clear(1) 315 call prop_clear(1)
285 call prop_type_add('included', {'start_incl': 1, 'end_incl': 1}) 316 call prop_type_add('included', {'start_incl': 1, 'end_incl': 1})
286 call prop_add(1, 5, #{type: 'included'}) 317 call prop_add(1, 5, #{type: 'included'})
287 let expected = [#{col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}] 318 let expected = [#{type_bufnr: 0, col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}]
288 call assert_equal(expected, prop_list(1)) 319 call assert_equal(expected, prop_list(1))
289 320
290 " Inserting text makes the prop bigger. 321 " Inserting text makes the prop bigger.
291 exe "normal 5|ixx\<Esc>" 322 exe "normal 5|ixx\<Esc>"
292 let expected = [#{col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}] 323 let expected = [#{type_bufnr: 0, col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}]
293 call assert_equal(expected, prop_list(1)) 324 call assert_equal(expected, prop_list(1))
294 325
295 call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:') 326 call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
296 327
297 call DeletePropTypes() 328 call DeletePropTypes()
325 new 356 new
326 call AddPropTypes() 357 call AddPropTypes()
327 call SetupPropsInFirstLine() 358 call SetupPropsInFirstLine()
328 call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'}) 359 call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
329 let props = Get_expected_props() 360 let props = Get_expected_props()
330 call insert(props, {'col': 6, 'length': 2, 'id': 11, 'type': 'three', 'start': 1, 'end': 1}, 3) 361 call insert(props, #{type_bufnr: 0, col: 6, length: 2, id: 11, type: 'three', start: 1, end: 1}, 3)
331 call assert_equal(props, prop_list(1)) 362 call assert_equal(props, prop_list(1))
332 call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1)) 363 call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
333 unlet props[3] 364 unlet props[3]
334 call assert_equal(props, prop_list(1)) 365 call assert_equal(props, prop_list(1))
335 366
365 normal gg0 396 normal gg0
366 call AddPropTypes() 397 call AddPropTypes()
367 call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) 398 call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'})
368 call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) 399 call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'})
369 let expected = [ 400 let expected = [
370 \ {'col': 2, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, 401 \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1},
371 \ {'col': 8, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, 402 \ #{type_bufnr: 0, col: 8, length: 3, id: 12, type: 'two', start: 1, end: 1},
372 \] 403 \]
373 call assert_equal(expected, prop_list(1)) 404 call assert_equal(expected, prop_list(1))
374 return expected 405 return expected
375 endfunc 406 endfunc
376 407
387 call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr}) 418 call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr})
388 call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr}) 419 call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr})
389 endfor 420 endfor
390 421
391 let props = [ 422 let props = [
392 \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, 423 \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
393 \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, 424 \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
394 \ {'col': 11, 'length': 3, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, 425 \ #{type_bufnr: 0, col: 11, length: 3, id: 13, type: 'three', start: 1, end: 1},
395 \] 426 \]
396 call assert_equal(props, prop_list(1, {'bufnr': bufnr})) 427 call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
397 428
398 " remove by id 429 " remove by id
399 let before_props = deepcopy(props) 430 let before_props = deepcopy(props)
656 func Test_prop_change_indent() 687 func Test_prop_change_indent()
657 call prop_type_add('comment', {'highlight': 'Directory'}) 688 call prop_type_add('comment', {'highlight': 'Directory'})
658 new 689 new
659 call setline(1, [' xxx', 'yyyyy']) 690 call setline(1, [' xxx', 'yyyyy'])
660 call prop_add(2, 2, {'length': 2, 'type': 'comment'}) 691 call prop_add(2, 2, {'length': 2, 'type': 'comment'})
661 let expect = {'col': 2, 'length': 2, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} 692 let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0}
662 call assert_equal([expect], prop_list(2)) 693 call assert_equal([expect], prop_list(2))
663 694
664 set shiftwidth=3 695 set shiftwidth=3
665 normal 2G>> 696 normal 2G>>
666 call assert_equal(' yyyyy', getline(2)) 697 call assert_equal(' yyyyy', getline(2))
702 new 733 new
703 call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) 734 call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz'])
704 735
705 " start halfway line 1, end halfway line 3 736 " start halfway line 1, end halfway line 3
706 call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'}) 737 call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'})
707 let expect1 = {'col': 3, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} 738 let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0}
708 call assert_equal([expect1], prop_list(1)) 739 call assert_equal([expect1], prop_list(1))
709 let expect2 = {'col': 1, 'length': 10, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} 740 let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0}
710 call assert_equal([expect2], prop_list(2)) 741 call assert_equal([expect2], prop_list(2))
711 let expect3 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0} 742 let expect3 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
712 call assert_equal([expect3], prop_list(3)) 743 call assert_equal([expect3], prop_list(3))
713 call prop_clear(1, 3) 744 call prop_clear(1, 3)
714 745
715 " include all three lines 746 " include all three lines
716 call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'}) 747 call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'})
724 755
725 bwipe! 756 bwipe!
726 757
727 " Test deleting the first line of a multi-line prop. 758 " Test deleting the first line of a multi-line prop.
728 call Setup_three_line_prop() 759 call Setup_three_line_prop()
729 let expect_short = {'col': 2, 'length': 1, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} 760 let expect_short = #{type_bufnr: 0, col: 2, length: 1, type: 'comment', start: 1, end: 1, id: 0}
730 call assert_equal([expect_short], prop_list(1)) 761 call assert_equal([expect_short], prop_list(1))
731 let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} 762 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
732 call assert_equal([expect2], prop_list(2)) 763 call assert_equal([expect2], prop_list(2))
733 2del 764 2del
734 call assert_equal([expect_short], prop_list(1)) 765 call assert_equal([expect_short], prop_list(1))
735 let expect2 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} 766 let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0}
736 call assert_equal([expect2], prop_list(2)) 767 call assert_equal([expect2], prop_list(2))
737 bwipe! 768 bwipe!
738 769
739 " Test deleting the last line of a multi-line prop. 770 " Test deleting the last line of a multi-line prop.
740 call Setup_three_line_prop() 771 call Setup_three_line_prop()
741 let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} 772 let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0}
742 call assert_equal([expect3], prop_list(3)) 773 call assert_equal([expect3], prop_list(3))
743 let expect4 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0} 774 let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
744 call assert_equal([expect4], prop_list(4)) 775 call assert_equal([expect4], prop_list(4))
745 4del 776 4del
746 let expect3.end = 1 777 let expect3.end = 1
747 call assert_equal([expect3], prop_list(3)) 778 call assert_equal([expect3], prop_list(3))
748 call assert_equal([expect_short], prop_list(4)) 779 call assert_equal([expect_short], prop_list(4))
749 bwipe! 780 bwipe!
750 781
751 " Test appending a line below the multi-line text prop start. 782 " Test appending a line below the multi-line text prop start.
752 call Setup_three_line_prop() 783 call Setup_three_line_prop()
753 let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} 784 let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
754 call assert_equal([expect2], prop_list(2)) 785 call assert_equal([expect2], prop_list(2))
755 call append(2, "new line") 786 call append(2, "new line")
756 call assert_equal([expect2], prop_list(2)) 787 call assert_equal([expect2], prop_list(2))
757 let expect3 = {'col': 1, 'length': 9, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} 788 let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0}
758 call assert_equal([expect3], prop_list(3)) 789 call assert_equal([expect3], prop_list(3))
759 bwipe! 790 bwipe!
760 791
761 call prop_type_delete('comment') 792 call prop_type_delete('comment')
762 endfunc 793 endfunc
826 call setline(1, ['oneone', 'twotwo', 'three']) 857 call setline(1, ['oneone', 'twotwo', 'three'])
827 " Set 'undolevels' to break changes into undo-able pieces. 858 " Set 'undolevels' to break changes into undo-able pieces.
828 set ul& 859 set ul&
829 860
830 call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) 861 call prop_add(1, 3, {'end_col': 5, 'type': 'comment'})
831 let expected = [{'col': 3, 'length': 2, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] 862 let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}]
832 call assert_equal(expected, prop_list(1)) 863 call assert_equal(expected, prop_list(1))
833 864
834 " Insert a character, then undo. 865 " Insert a character, then undo.
835 exe "normal 0lllix\<Esc>" 866 exe "normal 0lllix\<Esc>"
836 set ul& 867 set ul&
870 call assert_equal(expected, prop_list(1)) 901 call assert_equal(expected, prop_list(1))
871 902
872 " substitute a word, then undo 903 " substitute a word, then undo
873 call setline(1, 'the number 123 is highlighted.') 904 call setline(1, 'the number 123 is highlighted.')
874 call prop_add(1, 12, {'length': 3, 'type': 'comment'}) 905 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
875 let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] 906 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
876 call assert_equal(expected, prop_list(1)) 907 call assert_equal(expected, prop_list(1))
877 set ul& 908 set ul&
878 1s/number/foo 909 1s/number/foo
879 let expected[0].col = 9 910 let expected[0].col = 9
880 call assert_equal(expected, prop_list(1)) 911 call assert_equal(expected, prop_list(1))
884 call prop_clear(1) 915 call prop_clear(1)
885 916
886 " substitute with backslash 917 " substitute with backslash
887 call setline(1, 'the number 123 is highlighted.') 918 call setline(1, 'the number 123 is highlighted.')
888 call prop_add(1, 12, {'length': 3, 'type': 'comment'}) 919 call prop_add(1, 12, {'length': 3, 'type': 'comment'})
889 let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] 920 let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
890 call assert_equal(expected, prop_list(1)) 921 call assert_equal(expected, prop_list(1))
891 1s/the/\The 922 1s/the/\The
892 call assert_equal(expected, prop_list(1)) 923 call assert_equal(expected, prop_list(1))
893 1s/^/\\ 924 1s/^/\\
894 let expected[0].col += 1 925 let expected[0].col += 1
910 call prop_type_add('comment', {'highlight': 'Directory'}) 941 call prop_type_add('comment', {'highlight': 'Directory'})
911 call setline(1, ['oneone', 'twotwo', 'three']) 942 call setline(1, ['oneone', 'twotwo', 'three'])
912 943
913 " zero length property 944 " zero length property
914 call prop_add(1, 3, {'type': 'comment'}) 945 call prop_add(1, 3, {'type': 'comment'})
915 let expected = [{'col': 3, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] 946 let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
916 call assert_equal(expected, prop_list(1)) 947 call assert_equal(expected, prop_list(1))
917 948
918 " delete one char moves the property 949 " delete one char moves the property
919 normal! x 950 normal! x
920 let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] 951 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
921 call assert_equal(expected, prop_list(1)) 952 call assert_equal(expected, prop_list(1))
922 953
923 " delete char of the property has no effect 954 " delete char of the property has no effect
924 normal! lx 955 normal! lx
925 let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] 956 let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
926 call assert_equal(expected, prop_list(1)) 957 call assert_equal(expected, prop_list(1))
927 958
928 " delete more chars moves property to first column, is not deleted 959 " delete more chars moves property to first column, is not deleted
929 normal! 0xxxx 960 normal! 0xxxx
930 let expected = [{'col': 1, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] 961 let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
931 call assert_equal(expected, prop_list(1)) 962 call assert_equal(expected, prop_list(1))
932 963
933 bwipe! 964 bwipe!
934 call prop_type_delete('comment') 965 call prop_type_delete('comment')
935 endfunc 966 endfunc
1189 1220
1190 call prop_add(1, 12, {'length': 3, 'type': 'number'}) 1221 call prop_add(1, 12, {'length': 3, 'type': 'number'})
1191 call prop_add(2, 1, {'length': 3, 'type': 'number'}) 1222 call prop_add(2, 1, {'length': 3, 'type': 'number'})
1192 call prop_add(3, 36, {'length': 4, 'type': 'number'}) 1223 call prop_add(3, 36, {'length': 4, 'type': 'number'})
1193 set ul& 1224 set ul&
1194 let expected = [{'id': 0, 'col': 13, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}, 1225 let expected = [
1195 \ {'id': 0, 'col': 1, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}, 1226 \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1},
1196 \ {'id': 0, 'col': 50, 'end': 1, 'type': 'number', 'length': 4, 'start': 1}] 1227 \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1},
1228 \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}]
1229
1230 " TODO
1231 return
1197 " Add some text in between 1232 " Add some text in between
1198 %s/\s\+/ /g 1233 %s/\s\+/ /g
1199 call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3)) 1234 call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
1200 1235
1201 " remove some text 1236 " remove some text
1202 :1s/[a-z]\{3\}//g 1237 :1s/[a-z]\{3\}//g
1203 let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}] 1238 let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
1204 call assert_equal(expected, prop_list(1)) 1239 call assert_equal(expected, prop_list(1))
1296 func Test_textprop_ins_str() 1331 func Test_textprop_ins_str()
1297 new 1332 new
1298 call setline(1, 'just some text') 1333 call setline(1, 'just some text')
1299 call prop_type_add('test', {'highlight': 'ErrorMsg'}) 1334 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1300 call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) 1335 call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1301 call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1)) 1336 call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1))
1302 1337
1303 call feedkeys("foi\<F8>\<Esc>", "tx") 1338 call feedkeys("foi\<F8>\<Esc>", "tx")
1304 call assert_equal('just s<F8>ome text', getline(1)) 1339 call assert_equal('just s<F8>ome text', getline(1))
1305 call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1)) 1340 call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1))
1306 1341
1307 bwipe! 1342 bwipe!
1308 call prop_remove({'type': 'test'}) 1343 call prop_remove({'type': 'test'})
1309 call prop_type_delete('test') 1344 call prop_type_delete('test')
1310 endfunc 1345 endfunc
1314 call prop_type_add('test', {'highlight': 'ErrorMsg'}) 1349 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1315 call setline(1, 'just some text') 1350 call setline(1, 'just some text')
1316 call prop_add(1, 1, {'length': 4, 'type': 'test'}) 1351 call prop_add(1, 1, {'length': 4, 'type': 'test'})
1317 call prop_add(1, 10, {'length': 3, 'type': 'test'}) 1352 call prop_add(1, 10, {'length': 3, 'type': 'test'})
1318 1353
1319 call assert_equal({'id': 0, 'lnum': 1, 'col': 10, 'end': 1, 'type': 'test', 'length': 3, 'start': 1}, 1354 call assert_equal(
1320 \ prop_find(#{type: 'test', lnum: 1, col: 6})) 1355 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1},
1356 \ prop_find(#{type: 'test', lnum: 1, col: 6}))
1321 1357
1322 bwipe! 1358 bwipe!
1323 call prop_type_delete('test') 1359 call prop_type_delete('test')
1324 endfunc 1360 endfunc
1325 1361
1327 new 1363 new
1328 call prop_type_add('test', {'highlight': 'ErrorMsg'}) 1364 call prop_type_add('test', {'highlight': 'ErrorMsg'})
1329 call setline(1, 'just some text') 1365 call setline(1, 'just some text')
1330 call prop_add(1, 1, {'length': 0, 'type': 'test'}) 1366 call prop_add(1, 1, {'length': 0, 'type': 'test'})
1331 1367
1332 call assert_equal({'id': 0, 'lnum': 1, 'col': 1, 'end': 1, 'type': 'test', 'length': 0, 'start': 1}, 1368 call assert_equal(
1333 \ prop_find(#{type: 'test', lnum: 1})) 1369 \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1},
1370 \ prop_find(#{type: 'test', lnum: 1}))
1334 1371
1335 bwipe! 1372 bwipe!
1336 call prop_type_delete('test') 1373 call prop_type_delete('test')
1337 endfunc 1374 endfunc
1338 1375
1384 call setline(1, 'just some text') 1421 call setline(1, 'just some text')
1385 call prop_add(1, 6, {'length': 4, 'type': 'test'}) 1422 call prop_add(1, 6, {'length': 4, 'type': 'test'})
1386 1423
1387 " Split in middle of "some" 1424 " Split in middle of "some"
1388 execute "normal! 8|i\<CR>" 1425 execute "normal! 8|i\<CR>"
1389 call assert_equal([{'id': 0, 'col': 6, 'end': 0, 'type': 'test', 'length': 2, 'start': 1}], 1426 call assert_equal(
1390 \ prop_list(1)) 1427 \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}],
1391 call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 2, 'start': 0}], 1428 \ prop_list(1))
1392 \ prop_list(2)) 1429 call assert_equal(
1430 \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}],
1431 \ prop_list(2))
1393 1432
1394 " Join the two lines back together 1433 " Join the two lines back together
1395 normal! 1GJ 1434 normal! 1GJ
1396 call assert_equal([{'id': 0, 'col': 6, 'end': 1, 'type': 'test', 'length': 5, 'start': 1}], prop_list(1)) 1435 call assert_equal([#{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'test', length: 5, start: 1}], prop_list(1))
1397 1436
1398 bwipe! 1437 bwipe!
1399 call prop_type_delete('test') 1438 call prop_type_delete('test')
1400 endfunc 1439 endfunc
1401 1440
1406 call prop_add(1, 5, {'length': 3, 'type': 'test'}) 1445 call prop_add(1, 5, {'length': 3, 'type': 'test'})
1407 1446
1408 exe "normal! 0f9\<C-A>" 1447 exe "normal! 0f9\<C-A>"
1409 eval getline(1)->assert_equal('its 999 times') 1448 eval getline(1)->assert_equal('its 999 times')
1410 eval prop_list(1)->assert_equal([ 1449 eval prop_list(1)->assert_equal([
1411 \ #{id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}]) 1450 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}])
1412 1451
1413 exe "normal! 0f9\<C-A>" 1452 exe "normal! 0f9\<C-A>"
1414 eval getline(1)->assert_equal('its 1000 times') 1453 eval getline(1)->assert_equal('its 1000 times')
1415 eval prop_list(1)->assert_equal([ 1454 eval prop_list(1)->assert_equal([
1416 \ #{id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}]) 1455 \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
1417 1456
1418 bwipe! 1457 bwipe!
1419 call prop_type_delete('test') 1458 call prop_type_delete('test')
1420 endfunc 1459 endfunc
1421 1460
1427 call prop_add(2, 1, {'length': 3, 'type': 'test'}) 1466 call prop_add(2, 1, {'length': 3, 'type': 'test'})
1428 1467
1429 " insert "xx" in the first column of both lines 1468 " insert "xx" in the first column of both lines
1430 exe "normal! gg0\<C-V>jIxx\<Esc>" 1469 exe "normal! gg0\<C-V>jIxx\<Esc>"
1431 eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo ']) 1470 eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
1432 let expected = [#{id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}] 1471 let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
1433 eval prop_list(1)->assert_equal(expected) 1472 eval prop_list(1)->assert_equal(expected)
1434 eval prop_list(2)->assert_equal(expected) 1473 eval prop_list(2)->assert_equal(expected)
1435 1474
1436 " insert "yy" inside the text props to make them longer 1475 " insert "yy" inside the text props to make them longer
1437 exe "normal! gg03l\<C-V>jIyy\<Esc>" 1476 exe "normal! gg03l\<C-V>jIyy\<Esc>"
1508 1547
1509 prop_type_delete('Test') 1548 prop_type_delete('Test')
1510 bwipe! 1549 bwipe!
1511 enddef 1550 enddef
1512 1551
1552 " Buffer number of 0 should be ignored, as if the parameter wasn't passed.
1553 def Test_prop_bufnr_zero()
1554 new
1555 try
1556 var bufnr = bufnr('')
1557 setline(1, 'hello')
1558 prop_type_add('bufnr-global', {highlight: 'ErrorMsg'})
1559 prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr})
1560
1561 prop_add(1, 1, {type: 'bufnr-global', length: 1})
1562 prop_add(1, 2, {type: 'bufnr-buffer', length: 1})
1563
1564 var list = prop_list(1)
1565 assert_equal([
1566 {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1},
1567 {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1},
1568 ], list)
1569
1570 assert_equal(
1571 {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1},
1572 prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr}))
1573
1574 assert_equal(
1575 {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1},
1576 prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr}))
1577 finally
1578 bwipe!
1579 prop_type_delete('bufnr-global')
1580 endtry
1581 enddef
1582
1583
1513 1584
1514 " vim: shiftwidth=2 sts=2 expandtab 1585 " vim: shiftwidth=2 sts=2 expandtab