1
0
forked from aniani/vim

patch 8.2.5034: there is no way to get the byte index from a virtual column

Problem:    There is no way to get the byte index from a virtual column.
Solution:   Add virtcol2col(). (Yegappan Lakshmanan, closes #10477,
            closes #10098)
This commit is contained in:
Bram Moolenaar
2022-05-27 21:58:00 +01:00
parent 968443efb5
commit 5a6ec10cc8
7 changed files with 89 additions and 0 deletions

View File

@@ -419,4 +419,26 @@ func Test_setcursorcharpos()
%bw!
endfunc
" Test for virtcol2col()
func Test_virtcol2col()
new
call setline(1, ["a\tb\tc"])
call assert_equal(1, virtcol2col(0, 1, 1))
call assert_equal(2, virtcol2col(0, 1, 2))
call assert_equal(2, virtcol2col(0, 1, 8))
call assert_equal(3, virtcol2col(0, 1, 9))
call assert_equal(4, virtcol2col(0, 1, 10))
call assert_equal(4, virtcol2col(0, 1, 16))
call assert_equal(5, virtcol2col(0, 1, 17))
call assert_equal(-1, virtcol2col(10, 1, 1))
call assert_equal(-1, virtcol2col(0, 10, 1))
call assert_equal(-1, virtcol2col(0, -1, 1))
call assert_equal(-1, virtcol2col(0, 1, -1))
call assert_equal(5, virtcol2col(0, 1, 20))
call assert_fails('echo virtcol2col("0", 1, 20)', 'E1210:')
call assert_fails('echo virtcol2col(0, "1", 20)', 'E1210:')
call assert_fails('echo virtcol2col(0, 1, "1")', 'E1210:')
bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab