comparison src/testdir/test_textprop.vim @ 29788:d08aa1bfe319 v9.0.0233

patch 9.0.0233: removing multiple text properties takes many calls Commit: https://github.com/vim/vim/commit/a7704226a26b95b15bf87d3a3a5128e23e4aaa06 Author: Ben Jackson <puremourning@gmail.com> Date: Sat Aug 20 20:54:51 2022 +0100 patch 9.0.0233: removing multiple text properties takes many calls Problem: Removing multiple text properties takes many calls. Solution: Pass a list to prop_remove(). (Ben Jackson, closes https://github.com/vim/vim/issues/10945)
author Bram Moolenaar <Bram@vim.org>
date Sat, 20 Aug 2022 22:00:03 +0200
parents 7e2321707fea
children bbe62ea78aac
comparison
equal deleted inserted replaced
29787:f3901ba52a12 29788:d08aa1bfe319
159 \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0}, 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} 160 \ #{type_bufnr: 0, lnum: 5, col: 4, length: 1, id: 12, type: 'prop_name', start: 1, end: 1}
161 \ ] 161 \ ]
162 162
163 " Starting at line 5 col 1 this should find the prop at line 5 col 4. 163 " Starting at line 5 col 1 this should find the prop at line 5 col 4.
164 call cursor(5,1) 164 call cursor(5, 1)
165 let result = prop_find({'type': 'prop_name'}, 'f') 165 let result = prop_find({'type': 'prop_name'}, 'f')
166 call assert_equal(expected[2], result) 166 call assert_equal(expected[2], result)
167 167
168 " With skipstart left at false (default), this should find the prop at line 168 " With skipstart left at false (default), this should find the prop at line
169 " 5 col 4. 169 " 5 col 4.
180 call assert_equal(expected[0], result) 180 call assert_equal(expected[0], result)
181 181
182 " with skipstart set to false, if the start position is anywhere between the 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 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). 184 " result should be the prop on the first line (the line with 'start' set to 1).
185 call cursor(3,1) 185 call cursor(3, 1)
186 let result = prop_find({'type': 'prop_name'}, 'f') 186 let result = prop_find({'type': 'prop_name'}, 'f')
187 unlet result.length 187 unlet result.length
188 call assert_equal(expected[1], result) 188 call assert_equal(expected[1], result)
189 let result = prop_find({'type': 'prop_name'}, 'b') 189 let result = prop_find({'type': 'prop_name'}, 'b')
190 unlet result.length 190 unlet result.length
228 let col = result.col 228 let col = result.col
229 let i = i - 1 229 let i = i - 1
230 endwhile 230 endwhile
231 231
232 " Starting from line 6 col 1 search backwards for prop with id 10. 232 " Starting from line 6 col 1 search backwards for prop with id 10.
233 call cursor(6,1) 233 call cursor(6, 1)
234 let result = prop_find({'id': 10, 'skipstart': 1}, 'b') 234 let result = prop_find({'id': 10, 'skipstart': 1}, 'b')
235 call assert_equal(expected[0], result) 235 call assert_equal(expected[0], result)
236 236
237 " Starting from line 1 col 1 search forwards for prop with id 12. 237 " Starting from line 1 col 1 search forwards for prop with id 12.
238 call cursor(1,1) 238 call cursor(1, 1)
239 let result = prop_find({'id': 12}, 'f') 239 let result = prop_find({'id': 12}, 'f')
240 call assert_equal(expected[2], result) 240 call assert_equal(expected[2], result)
241 241
242 " Search for a prop with an unknown id. 242 " Search for a prop with an unknown id.
243 let result = prop_find({'id': 999}, 'f') 243 let result = prop_find({'id': 999}, 'f')
421 unlet props[3] 421 unlet props[3]
422 call assert_equal(props, prop_list(1)) 422 call assert_equal(props, prop_list(1))
423 423
424 call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:') 424 call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:')
425 call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:') 425 call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:')
426
427 call DeletePropTypes()
428 bwipe!
429
430 new
431 call AddPropTypes()
432 call SetupPropsInFirstLine()
433 let props = Get_expected_props() " [whole, one, two, three]
434 call assert_equal(props, prop_list(1))
435
436 " remove one by types
437 call assert_equal(1, prop_remove({'types': ['one', 'two', 'three']}, 1))
438 unlet props[1] " [whole, two, three]
439 call assert_equal(props, prop_list(1))
440
441 " remove 'all' by types
442 call assert_equal(2, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
443 unlet props[0] " [two, three]
444 unlet props[1] " [three]
445 call assert_equal(props, prop_list(1))
446
447 " remove none by types
448 call assert_equal(0, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1))
449 call assert_equal(props, prop_list(1))
450
451 " no types
452 call assert_fails("call prop_remove({'types': []}, 1)", 'E968:')
453 call assert_fails("call prop_remove({'types': ['not_a_real_type']}, 1)", 'E971:')
454
455 " only one of types and type can be supplied
456 call assert_fails("call prop_remove({'type': 'one', 'types': ['three'], 'all': 1}, 1)", 'E1295:')
426 457
427 call DeletePropTypes() 458 call DeletePropTypes()
428 bwipe! 459 bwipe!
429 endfunc 460 endfunc
430 461
1394 1425
1395 " Adding a text property with invalid highlight should be ignored. 1426 " Adding a text property with invalid highlight should be ignored.
1396 func Test_textprop_invalid_highlight() 1427 func Test_textprop_invalid_highlight()
1397 call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:') 1428 call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:')
1398 new 1429 new
1399 call setline(1, ['asdf','asdf']) 1430 call setline(1, ['asdf', 'asdf'])
1400 call prop_add(1, 1, {'length': 4, 'type': 'dni'}) 1431 call prop_add(1, 1, {'length': 4, 'type': 'dni'})
1401 redraw 1432 redraw
1402 bwipe! 1433 bwipe!
1403 call prop_type_delete('dni') 1434 call prop_type_delete('dni')
1404 endfunc 1435 endfunc
2205 call prop_type_add('misspell', #{highlight: 'ErrorMsg'}) 2236 call prop_type_add('misspell', #{highlight: 'ErrorMsg'})
2206 for col in [8, 14, 24, 38] 2237 for col in [8, 14, 24, 38]
2207 call prop_add(1, col, #{type: 'misspell', length: 2}) 2238 call prop_add(1, col, #{type: 'misspell', length: 2})
2208 endfor 2239 endfor
2209 2240
2210 call cursor(1,18) 2241 call cursor(1, 18)
2211 let expected = [ 2242 let expected = [
2212 \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}, 2243 \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1},
2213 \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1} 2244 \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}
2214 \ ] 2245 \ ]
2215 2246
2308 barbaz 2339 barbaz
2309 END 2340 END
2310 call assert_equal(lines, getline(1, '$')) 2341 call assert_equal(lines, getline(1, '$'))
2311 let expected = [ 2342 let expected = [
2312 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one', 2343 \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2313 \ 'length': 4 ,'start': 1}, 2344 \ 'length': 4 , 'start': 1},
2314 \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one', 2345 \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2315 \ 'length': 7, 'start': 0}, 2346 \ 'length': 7, 'start': 0},
2316 \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one', 2347 \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one',
2317 \ 'length': 7, 'start': 0}, 2348 \ 'length': 7, 'start': 0},
2318 \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one', 2349 \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',