]> granicus.if.org Git - vim/commitdiff
patch 9.0.0169: insufficient testing for line2byte() with text properties v9.0.0169
authorBram Moolenaar <Bram@vim.org>
Mon, 8 Aug 2022 13:59:47 +0000 (14:59 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 8 Aug 2022 13:59:47 +0000 (14:59 +0100)
Problem:    Insufficient testing for line2byte() with text properties.
Solution:   Add tests with a lot of text.

src/testdir/test_textprop.vim
src/textprop.c
src/version.c

index 5ff87b4f10762e91950516f0944c1eeb4fd63cc7..9fae8070abea019c4e1350ed79256e08c69142d7 100644 (file)
@@ -904,6 +904,30 @@ func Test_prop_multiline()
   call prop_type_delete('comment')
 endfunc
 
+func Run_test_with_line2byte(add_props)
+  new
+  setlocal ff=unix
+  if a:add_props
+    call prop_type_add('textprop', #{highlight: 'Search'})
+  endif
+  for nr in range(1, 1000)
+    call setline(nr, 'some longer text here')
+    if a:add_props && nr % 17 == 0
+      call prop_add(nr, 13, #{type: 'textprop', length: 4})
+    endif
+  endfor
+  call assert_equal(21935, line2byte(998))
+  for nr in range(1, 1000, 7)
+    exe nr .. "s/longer/much more/"
+  endfor
+  call assert_equal(22364, line2byte(998))
+
+  if a:add_props
+    call prop_type_delete('textprop')
+  endif
+  bwipe!
+endfunc
+
 func Test_prop_line2byte()
   call prop_type_add('comment', {'highlight': 'Directory'})
   new
@@ -935,6 +959,11 @@ func Test_prop_line2byte()
   call assert_equal(1489, line2byte(400))
   bwipe!
 
+  " Add many lines so that the data block is split.
+  " With and without props should give the same result.
+  call Run_test_with_line2byte(0)
+  call Run_test_with_line2byte(1)
+
   call prop_type_delete('comment')
 endfunc
 
index d67ec4c7e8b6ecc196616fda7c019cdc56d33107..d5a53d6cbe7cfdd17520e2eab451ddbcf4b80c63 100644 (file)
@@ -9,10 +9,6 @@
 
 /*
  * Text properties implementation.  See ":help text-properties".
- *
- * TODO:
- * - Also test line2byte() with many lines, so that ml_updatechunk() is taken
- *   into account.
  */
 
 #include "vim.h"
index 2f34ffe2c2f7669097abd8a5583b2539601dce65..3660eb7c4a7365d9877269d7dbe68d4d1c294b59 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    169,
 /**/
     168,
 /**/