Mercurial > vim
comparison src/testdir/test_textprop.vim @ 15367:273649cad196 v8.1.0691
patch 8.1.0691: text properties are not adjusted for :substitute
commit https://github.com/vim/vim/commit/4164bb204e97a2ff3d6c43cba779bdff9e853892
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 4 23:09:49 2019 +0100
patch 8.1.0691: text properties are not adjusted for :substitute
Problem: Text properties are not adjusted for :substitute.
Solution: Adjust text properties as well as possible.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 04 Jan 2019 23:15:04 +0100 |
parents | 01ee8dc12313 |
children | 3e02464faaac |
comparison
equal
deleted
inserted
replaced
15366:537ee1380f26 | 15367:273649cad196 |
---|---|
87 | 87 |
88 func SetupPropsInFirstLine() | 88 func SetupPropsInFirstLine() |
89 call setline(1, 'one two three') | 89 call setline(1, 'one two three') |
90 call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) | 90 call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) |
91 call prop_add(1, 5, {'length': 3, 'id': 12, 'type': 'two'}) | 91 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'}) |
93 call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) | 93 call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) |
94 endfunc | 94 endfunc |
95 | 95 |
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}, | |
97 \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, | 99 \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, |
98 \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, | 100 \ {'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}, |
100 \ ] | 102 \ ] |
103 endfunc | |
101 | 104 |
102 func Test_prop_add() | 105 func Test_prop_add() |
103 new | 106 new |
104 call AddPropTypes() | 107 call AddPropTypes() |
105 call SetupPropsInFirstLine() | 108 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)) | |
107 call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') | 111 call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') |
108 call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') | 112 call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') |
109 | 113 |
110 " Insert a line above, text props must still be there. | 114 " Insert a line above, text props must still be there. |
111 call append(0, 'empty') | 115 call append(0, 'empty') |
112 call assert_equal(s:expected_props, prop_list(2)) | 116 call assert_equal(expected_props, prop_list(2)) |
113 " Delete a line above, text props must still be there. | 117 " Delete a line above, text props must still be there. |
114 1del | 118 1del |
115 call assert_equal(s:expected_props, prop_list(1)) | 119 call assert_equal(expected_props, prop_list(1)) |
116 | 120 |
117 " Prop without length or end column is zero length | 121 " Prop without length or end column is zero length |
118 call prop_clear(1) | 122 call prop_clear(1) |
119 call prop_add(1, 5, {'type': 'two'}) | 123 call prop_add(1, 5, {'type': 'two'}) |
120 let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}] | 124 let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}] |
126 | 130 |
127 func Test_prop_remove() | 131 func Test_prop_remove() |
128 new | 132 new |
129 call AddPropTypes() | 133 call AddPropTypes() |
130 call SetupPropsInFirstLine() | 134 call SetupPropsInFirstLine() |
131 let props = deepcopy(s:expected_props) | 135 let props = Get_expected_props() |
132 call assert_equal(props, prop_list(1)) | 136 call assert_equal(props, prop_list(1)) |
133 | 137 |
134 " remove by id | 138 " remove by id |
135 call prop_remove({'id': 12}, 1) | 139 call prop_remove({'id': 12}, 1) |
136 unlet props[2] | 140 unlet props[2] |
234 | 238 |
235 func Test_prop_clear() | 239 func Test_prop_clear() |
236 new | 240 new |
237 call AddPropTypes() | 241 call AddPropTypes() |
238 call SetupPropsInFirstLine() | 242 call SetupPropsInFirstLine() |
239 call assert_equal(s:expected_props, prop_list(1)) | 243 call assert_equal(Get_expected_props(), prop_list(1)) |
240 | 244 |
241 call prop_clear(1) | 245 call prop_clear(1) |
242 call assert_equal([], prop_list(1)) | 246 call assert_equal([], prop_list(1)) |
243 | 247 |
244 call DeletePropTypes() | 248 call DeletePropTypes() |
249 new | 253 new |
250 call AddPropTypes() | 254 call AddPropTypes() |
251 call SetupPropsInFirstLine() | 255 call SetupPropsInFirstLine() |
252 let bufnr = bufnr('') | 256 let bufnr = bufnr('') |
253 wincmd w | 257 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})) |
255 | 259 |
256 call prop_clear(1, 1, {'bufnr': bufnr}) | 260 call prop_clear(1, 1, {'bufnr': bufnr}) |
257 call assert_equal([], prop_list(1, {'bufnr': bufnr})) | 261 call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
258 | 262 |
259 wincmd w | 263 wincmd w |
263 | 267 |
264 func Test_prop_setline() | 268 func Test_prop_setline() |
265 new | 269 new |
266 call AddPropTypes() | 270 call AddPropTypes() |
267 call SetupPropsInFirstLine() | 271 call SetupPropsInFirstLine() |
268 call assert_equal(s:expected_props, prop_list(1)) | 272 call assert_equal(Get_expected_props(), prop_list(1)) |
269 | 273 |
270 call setline(1, 'foobar') | 274 call setline(1, 'foobar') |
271 call assert_equal([], prop_list(1)) | 275 call assert_equal([], prop_list(1)) |
272 | 276 |
273 call DeletePropTypes() | 277 call DeletePropTypes() |
278 new | 282 new |
279 call AddPropTypes() | 283 call AddPropTypes() |
280 call SetupPropsInFirstLine() | 284 call SetupPropsInFirstLine() |
281 let bufnr = bufnr('') | 285 let bufnr = bufnr('') |
282 wincmd w | 286 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})) |
284 | 288 |
285 call setbufline(bufnr, 1, 'foobar') | 289 call setbufline(bufnr, 1, 'foobar') |
286 call assert_equal([], prop_list(1, {'bufnr': bufnr})) | 290 call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
287 | 291 |
288 wincmd w | 292 wincmd w |
293 call DeletePropTypes() | |
294 bwipe! | |
295 endfunc | |
296 | |
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 | |
289 call DeletePropTypes() | 341 call DeletePropTypes() |
290 bwipe! | 342 bwipe! |
291 endfunc | 343 endfunc |
292 | 344 |
293 " Setup a three line prop in lines 2 - 4. | 345 " Setup a three line prop in lines 2 - 4. |