patch 8.2.3356: adding many text properties requires a lot of function calls
Problem: Adding many text properties requires a lot of function calls.
Solution: Add the prop_add_list() function. (Yegappan Lakshmanan,
closes #8751)
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 6af47e3..373df6e 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -339,6 +339,41 @@
bwipe!
endfunc
+" Test for the prop_add_list() function
+func Test_prop_add_list()
+ new
+ call AddPropTypes()
+ call setline(1, ['one one one', 'two two two', 'six six six', 'ten ten ten'])
+ call prop_add_list(#{type: 'one', id: 2},
+ \ [[1, 1, 1, 3], [2, 5, 2, 7], [3, 6, 4, 6]])
+ call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
+ \ length: 2, start: 1}], prop_list(1))
+ call assert_equal([#{id: 2, col: 5, type_bufnr: 0, end: 1, type: 'one',
+ \ length: 2, start: 1}], prop_list(2))
+ call assert_equal([#{id: 2, col: 6, type_bufnr: 0, end: 0, type: 'one',
+ \ length: 7, start: 1}], prop_list(3))
+ call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
+ \ length: 5, start: 0}], prop_list(4))
+ call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:')
+ call assert_fails('call prop_add_list({}, {})', 'E1211:')
+ call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:')
+ call assert_fails('call prop_add_list(#{type: "abc"}, [[1, 1, 1, 3]])', 'E971:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [[]])', 'E474:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 1], {}])', 'E714:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, "a"]])', 'E474:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2]])', 'E474:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 2], [2, 2]])', 'E474:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 2], [4, 1, 5, 2]])', 'E966:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [[3, 1, 1, 2]])', 'E966:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
+ call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:')
+ call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:')
+ call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E714:')
+ call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:')
+ call DeletePropTypes()
+ bw!
+endfunc
+
func Test_prop_remove()
new
call AddPropTypes()
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 5e45edb..00d021f 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -2364,6 +2364,11 @@
CheckDefAndScriptFailure2(['prop_add(1, 2, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
enddef
+def Test_prop_add_list()
+ CheckDefAndScriptFailure2(['prop_add_list([], [])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 1')
+ CheckDefAndScriptFailure2(['prop_add_list({}, {})'], 'E1013: Argument 2: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 2')
+enddef
+
def Test_prop_clear()
CheckDefAndScriptFailure2(['prop_clear("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['prop_clear(1, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')