mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 16:28:17 +00:00
vim-patch:8.1.1911: more functions can be used as methods
Problem: More functions can be used as methods.
Solution: Make a few more functions usable as a method.
64b4d73524
Note that the old-style version of Test_byteidx() was already translated
to a Lua test in 069_multibyte_formatting_spec.lua. Keep both versions,
using Test_byteidx() to mainly test the method call syntax for byteidx()
and byteidxcomp().
This commit is contained in:
@@ -2954,6 +2954,9 @@ byte2line({byte}) *byte2line()*
|
|||||||
one.
|
one.
|
||||||
Also see |line2byte()|, |go| and |:goto|.
|
Also see |line2byte()|, |go| and |:goto|.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetOffset()->byte2line()
|
||||||
|
|
||||||
byteidx({expr}, {nr}) *byteidx()*
|
byteidx({expr}, {nr}) *byteidx()*
|
||||||
Return byte index of the {nr}'th character in the string
|
Return byte index of the {nr}'th character in the string
|
||||||
{expr}. Use zero for the first character, it then returns
|
{expr}. Use zero for the first character, it then returns
|
||||||
@@ -2976,6 +2979,9 @@ byteidx({expr}, {nr}) *byteidx()*
|
|||||||
If there are exactly {nr} characters the length of the string
|
If there are exactly {nr} characters the length of the string
|
||||||
in bytes is returned.
|
in bytes is returned.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetName()->byteidx(idx)
|
||||||
|
|
||||||
byteidxcomp({expr}, {nr}) *byteidxcomp()*
|
byteidxcomp({expr}, {nr}) *byteidxcomp()*
|
||||||
Like byteidx(), except that a composing character is counted
|
Like byteidx(), except that a composing character is counted
|
||||||
as a separate character. Example: >
|
as a separate character. Example: >
|
||||||
@@ -2989,6 +2995,9 @@ byteidxcomp({expr}, {nr}) *byteidxcomp()*
|
|||||||
Only works differently from byteidx() when 'encoding' is set to
|
Only works differently from byteidx() when 'encoding' is set to
|
||||||
a Unicode encoding.
|
a Unicode encoding.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetName()->byteidxcomp(idx)
|
||||||
|
|
||||||
call({func}, {arglist} [, {dict}]) *call()* *E699*
|
call({func}, {arglist} [, {dict}]) *call()* *E699*
|
||||||
Call function {func} with the items in |List| {arglist} as
|
Call function {func} with the items in |List| {arglist} as
|
||||||
arguments.
|
arguments.
|
||||||
@@ -2998,6 +3007,9 @@ call({func}, {arglist} [, {dict}]) *call()* *E699*
|
|||||||
{dict} is for functions with the "dict" attribute. It will be
|
{dict} is for functions with the "dict" attribute. It will be
|
||||||
used to set the local variable "self". |Dictionary-function|
|
used to set the local variable "self". |Dictionary-function|
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetFunc()->call([arg, arg], dict)
|
||||||
|
|
||||||
ceil({expr}) *ceil()*
|
ceil({expr}) *ceil()*
|
||||||
Return the smallest integral value greater than or equal to
|
Return the smallest integral value greater than or equal to
|
||||||
{expr} as a |Float| (round up).
|
{expr} as a |Float| (round up).
|
||||||
|
@@ -62,10 +62,10 @@ return {
|
|||||||
bufnr={args={0, 2}, base=1},
|
bufnr={args={0, 2}, base=1},
|
||||||
bufwinid={args=1, base=1},
|
bufwinid={args=1, base=1},
|
||||||
bufwinnr={args=1, base=1},
|
bufwinnr={args=1, base=1},
|
||||||
byte2line={args=1},
|
byte2line={args=1, base=1},
|
||||||
byteidx={args=2},
|
byteidx={args=2, base=1},
|
||||||
byteidxcomp={args=2},
|
byteidxcomp={args=2, base=1},
|
||||||
call={args={2, 3}},
|
call={args={2, 3}, base=1},
|
||||||
ceil={args=1, base=1, func="float_op_wrapper", data="&ceil"},
|
ceil={args=1, base=1, func="float_op_wrapper", data="&ceil"},
|
||||||
changenr={},
|
changenr={},
|
||||||
chanclose={args={1, 2}},
|
chanclose={args={1, 2}},
|
||||||
|
@@ -852,7 +852,7 @@ func Test_byte2line_line2byte()
|
|||||||
|
|
||||||
set fileformat=mac
|
set fileformat=mac
|
||||||
call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
|
call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
|
||||||
\ map(range(-1, 8), 'byte2line(v:val)'))
|
\ map(range(-1, 8), 'v:val->byte2line()'))
|
||||||
call assert_equal([-1, -1, 1, 3, 6, 8, -1],
|
call assert_equal([-1, -1, 1, 3, 6, 8, -1],
|
||||||
\ map(range(-1, 5), 'line2byte(v:val)'))
|
\ map(range(-1, 5), 'line2byte(v:val)'))
|
||||||
|
|
||||||
@@ -875,6 +875,34 @@ func Test_byte2line_line2byte()
|
|||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_byteidx()
|
||||||
|
let a = '.é.' " one char of two bytes
|
||||||
|
call assert_equal(0, byteidx(a, 0))
|
||||||
|
call assert_equal(0, byteidxcomp(a, 0))
|
||||||
|
call assert_equal(1, byteidx(a, 1))
|
||||||
|
call assert_equal(1, byteidxcomp(a, 1))
|
||||||
|
call assert_equal(3, byteidx(a, 2))
|
||||||
|
call assert_equal(3, byteidxcomp(a, 2))
|
||||||
|
call assert_equal(4, byteidx(a, 3))
|
||||||
|
call assert_equal(4, byteidxcomp(a, 3))
|
||||||
|
call assert_equal(-1, byteidx(a, 4))
|
||||||
|
call assert_equal(-1, byteidxcomp(a, 4))
|
||||||
|
|
||||||
|
let b = '.é.' " normal e with composing char
|
||||||
|
call assert_equal(0, b->byteidx(0))
|
||||||
|
call assert_equal(1, b->byteidx(1))
|
||||||
|
call assert_equal(4, b->byteidx(2))
|
||||||
|
call assert_equal(5, b->byteidx(3))
|
||||||
|
call assert_equal(-1, b->byteidx(4))
|
||||||
|
|
||||||
|
call assert_equal(0, b->byteidxcomp(0))
|
||||||
|
call assert_equal(1, b->byteidxcomp(1))
|
||||||
|
call assert_equal(2, b->byteidxcomp(2))
|
||||||
|
call assert_equal(4, b->byteidxcomp(3))
|
||||||
|
call assert_equal(5, b->byteidxcomp(4))
|
||||||
|
call assert_equal(-1, b->byteidxcomp(5))
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for charidx()
|
" Test for charidx()
|
||||||
func Test_charidx()
|
func Test_charidx()
|
||||||
let a = 'xáb́y'
|
let a = 'xáb́y'
|
||||||
@@ -1476,6 +1504,7 @@ endfunc
|
|||||||
|
|
||||||
func Test_call()
|
func Test_call()
|
||||||
call assert_equal(3, call('len', [123]))
|
call assert_equal(3, call('len', [123]))
|
||||||
|
call assert_equal(3, 'len'->call([123]))
|
||||||
call assert_fails("call call('len', 123)", 'E714:')
|
call assert_fails("call call('len', 123)", 'E714:')
|
||||||
call assert_equal(0, call('', []))
|
call assert_equal(0, call('', []))
|
||||||
|
|
||||||
@@ -1483,6 +1512,7 @@ func Test_call()
|
|||||||
return len(self.data)
|
return len(self.data)
|
||||||
endfunction
|
endfunction
|
||||||
let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
|
let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
|
||||||
|
eval mydict.len->call([], mydict)->assert_equal(4)
|
||||||
call assert_fails("call call('Mylen', [], 0)", 'E715:')
|
call assert_fails("call call('Mylen', [], 0)", 'E715:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user