@@ -89,30 +89,34 @@ func SetupPropsInFirstLine()
8989 call setline (1 , ' one two three' )
9090 call prop_add (1 , 1 , {' length' : 3 , ' id' : 11 , ' type' : ' one' })
9191 call prop_add (1 , 5 , {' length' : 3 , ' id' : 12 , ' type' : ' two' })
92- call prop_add (1 , 8 , {' length' : 5 , ' id' : 13 , ' type' : ' three' })
92+ call prop_add (1 , 9 , {' length' : 5 , ' id' : 13 , ' type' : ' three' })
9393 call prop_add (1 , 1 , {' length' : 13 , ' id' : 14 , ' type' : ' whole' })
9494endfunc
9595
96- let s: expected_props = [{' col' : 1 , ' length' : 13 , ' id' : 14 , ' type' : ' whole' , ' start' : 1 , ' end' : 1 },
96+ func Get_expected_props ()
97+ return [
98+ \ {' col' : 1 , ' length' : 13 , ' id' : 14 , ' type' : ' whole' , ' start' : 1 , ' end' : 1 },
9799 \ {' col' : 1 , ' length' : 3 , ' id' : 11 , ' type' : ' one' , ' start' : 1 , ' end' : 1 },
98100 \ {' col' : 5 , ' length' : 3 , ' id' : 12 , ' type' : ' two' , ' start' : 1 , ' end' : 1 },
99- \ {' col' : 8 , ' length' : 5 , ' id' : 13 , ' type' : ' three' , ' start' : 1 , ' end' : 1 },
101+ \ {' col' : 9 , ' length' : 5 , ' id' : 13 , ' type' : ' three' , ' start' : 1 , ' end' : 1 },
100102 \ ]
103+ endfunc
101104
102105func Test_prop_add ()
103106 new
104107 call AddPropTypes ()
105108 call SetupPropsInFirstLine ()
106- call assert_equal (s: expected_props , prop_list (1 ))
109+ let expected_props = Get_expected_props ()
110+ call assert_equal (expected_props, prop_list (1 ))
107111 call assert_fails (" call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})" , ' E966:' )
108112 call assert_fails (" call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})" , ' E964:' )
109113
110114 " Insert a line above, text props must still be there.
111115 call append (0 , ' empty' )
112- call assert_equal (s: expected_props , prop_list (2 ))
116+ call assert_equal (expected_props, prop_list (2 ))
113117 " Delete a line above, text props must still be there.
114118 1 del
115- call assert_equal (s: expected_props , prop_list (1 ))
119+ call assert_equal (expected_props, prop_list (1 ))
116120
117121 " Prop without length or end column is zero length
118122 call prop_clear (1 )
@@ -128,7 +132,7 @@ func Test_prop_remove()
128132 new
129133 call AddPropTypes ()
130134 call SetupPropsInFirstLine ()
131- let props = deepcopy ( s: expected_props )
135+ let props = Get_expected_props ( )
132136 call assert_equal (props, prop_list (1 ))
133137
134138 " remove by id
@@ -236,7 +240,7 @@ func Test_prop_clear()
236240 new
237241 call AddPropTypes ()
238242 call SetupPropsInFirstLine ()
239- call assert_equal (s: expected_props , prop_list (1 ))
243+ call assert_equal (Get_expected_props () , prop_list (1 ))
240244
241245 call prop_clear (1 )
242246 call assert_equal ([], prop_list (1 ))
@@ -251,7 +255,7 @@ func Test_prop_clear_buf()
251255 call SetupPropsInFirstLine ()
252256 let bufnr = bufnr (' ' )
253257 wincmd w
254- call assert_equal (s: expected_props , prop_list (1 , {' bufnr' : bufnr }))
258+ call assert_equal (Get_expected_props () , prop_list (1 , {' bufnr' : bufnr }))
255259
256260 call prop_clear (1 , 1 , {' bufnr' : bufnr })
257261 call assert_equal ([], prop_list (1 , {' bufnr' : bufnr }))
@@ -265,7 +269,7 @@ func Test_prop_setline()
265269 new
266270 call AddPropTypes ()
267271 call SetupPropsInFirstLine ()
268- call assert_equal (s: expected_props , prop_list (1 ))
272+ call assert_equal (Get_expected_props () , prop_list (1 ))
269273
270274 call setline (1 , ' foobar' )
271275 call assert_equal ([], prop_list (1 ))
@@ -280,7 +284,7 @@ func Test_prop_setbufline()
280284 call SetupPropsInFirstLine ()
281285 let bufnr = bufnr (' ' )
282286 wincmd w
283- call assert_equal (s: expected_props , prop_list (1 , {' bufnr' : bufnr }))
287+ call assert_equal (Get_expected_props () , prop_list (1 , {' bufnr' : bufnr }))
284288
285289 call setbufline (bufnr , 1 , ' foobar' )
286290 call assert_equal ([], prop_list (1 , {' bufnr' : bufnr }))
@@ -290,6 +294,54 @@ func Test_prop_setbufline()
290294 bwipe!
291295endfunc
292296
297+ func Test_prop_substitute ()
298+ new
299+ " Set first line to 'one two three'
300+ call AddPropTypes ()
301+ call SetupPropsInFirstLine ()
302+ let expected_props = Get_expected_props ()
303+ call assert_equal (expected_props, prop_list (1 ))
304+
305+ " Change "n" in "one" to XX: 'oXXe two three'
306+ s /n/ XX/
307+ let expected_props[0 ].length += 1
308+ let expected_props[1 ].length += 1
309+ let expected_props[2 ].col += 1
310+ let expected_props[3 ].col += 1
311+ call assert_equal (expected_props, prop_list (1 ))
312+
313+ " Delete "t" in "two" and "three" to XX: 'oXXe wo hree'
314+ s /t/ /g
315+ let expected_props[0 ].length -= 2
316+ let expected_props[2 ].length -= 1
317+ let expected_props[3 ].length -= 1
318+ let expected_props[3 ].col -= 1
319+ call assert_equal (expected_props, prop_list (1 ))
320+
321+ " Split the line by changing w to line break: 'oXXe ', 'o hree'
322+ " The long prop is split and spans both lines.
323+ " The props on "two" and "three" move to the next line.
324+ s /w/ \r /
325+ let new_props = [
326+ \ copy (expected_props[0 ]),
327+ \ copy (expected_props[2 ]),
328+ \ copy (expected_props[3 ]),
329+ \ ]
330+ let expected_props[0 ].length = 5
331+ unlet expected_props[3 ]
332+ unlet expected_props[2 ]
333+ call assert_equal (expected_props, prop_list (1 ))
334+
335+ let new_props[0 ].length = 6
336+ let new_props[1 ].col = 1
337+ let new_props[1 ].length = 1
338+ let new_props[2 ].col = 3
339+ call assert_equal (new_props, prop_list (2 ))
340+
341+ call DeletePropTypes ()
342+ bwipe!
343+ endfunc
344+
293345" Setup a three line prop in lines 2 - 4.
294346" Add short props in line 1 and 5.
295347func Setup_three_line_prop ()
0 commit comments