mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(eval/method): partially port v8.1.1921
Adds method call support for all functions in the patch, but it cannot be fully ported due to missing tests for: - filereadable(): requires v8.1.1378 for Test_delete_rf(), but there appears to have been some trouble porting it. (#12784) - confirm(): requires v8.1.0832 for Test_confirm() and v8.1.0815 for feedkeys()'s "L" flag. (I did attempt to port the test using nvim_input() instead, but seems that input handling for confirm() doesn't work in --headless mode?) Note that confirm() was actually added as a method in v8.1.1915. Uncomment use of method call syntax in Test_Executable() previously included instead from v8.2.2259.
This commit is contained in:
parent
0193b3a391
commit
6110480c29
@ -3831,6 +3831,9 @@ escape({string}, {chars}) *escape()*
|
||||
c:\\program\ files\\vim
|
||||
< Also see |shellescape()| and |fnameescape()|.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetText()->escape(' \')
|
||||
<
|
||||
*eval()*
|
||||
eval({string}) Evaluate {string} and return the result. Especially useful to
|
||||
turn the result of |string()| back into the original value.
|
||||
@ -3870,6 +3873,9 @@ executable({expr}) *executable()*
|
||||
-1 not implemented on this system
|
||||
|exepath()| can be used to get the full path of an executable.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetCommand()->executable()
|
||||
|
||||
execute({command} [, {silent}]) *execute()*
|
||||
Execute {command} and capture its output.
|
||||
If {command} is a |String|, returns {command} output.
|
||||
@ -3897,12 +3903,18 @@ execute({command} [, {silent}]) *execute()*
|
||||
To execute a command in another window than the current one
|
||||
use `win_execute()`.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetCommand()->execute()
|
||||
|
||||
exepath({expr}) *exepath()*
|
||||
Returns the full path of {expr} if it is an executable and
|
||||
given as a (partial or full) path or is found in $PATH.
|
||||
Returns empty string otherwise.
|
||||
If {expr} starts with "./" the |current-directory| is used.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetCommand()->exepath()
|
||||
|
||||
*exists()*
|
||||
exists({expr}) The result is a Number, which is |TRUE| if {expr} is
|
||||
defined, zero otherwise.
|
||||
@ -3988,6 +4000,9 @@ exists({expr}) The result is a Number, which is |TRUE| if {expr} is
|
||||
< This doesn't check for existence of the "bufcount" variable,
|
||||
but gets the value of "bufcount", and checks if that exists.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
Varname()->exists()
|
||||
|
||||
exp({expr}) *exp()*
|
||||
Return the exponential of {expr} as a |Float| in the range
|
||||
[0, inf].
|
||||
@ -4094,6 +4109,9 @@ expand({string} [, {nosuf} [, {list}]]) *expand()*
|
||||
See |glob()| for finding existing files. See |system()| for
|
||||
getting the raw output of an external command.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
Getpattern()->expand()
|
||||
|
||||
expandcmd({expr}) *expandcmd()*
|
||||
Expand special items in {expr} like what is done for an Ex
|
||||
command such as `:edit`. This expands special keywords, like
|
||||
@ -4101,6 +4119,9 @@ expandcmd({expr}) *expandcmd()*
|
||||
{expr}. "~user" and "~/path" are only expanded at the start.
|
||||
Returns the expanded string. Example: >
|
||||
:echo expandcmd('make %<.o')
|
||||
|
||||
< Can also be used as a |method|: >
|
||||
GetCommand()->expandcmd()
|
||||
<
|
||||
extend({expr1}, {expr2} [, {expr3}]) *extend()*
|
||||
{expr1} and {expr2} must be both |Lists| or both
|
||||
@ -4186,6 +4207,9 @@ feedkeys({string} [, {mode}]) *feedkeys()*
|
||||
|
||||
Return value is always 0.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetInput()->feedkeys()
|
||||
|
||||
filereadable({file}) *filereadable()*
|
||||
The result is a Number, which is |TRUE| when a file with the
|
||||
name {file} exists, and can be read. If {file} doesn't exist,
|
||||
@ -4199,12 +4223,17 @@ filereadable({file}) *filereadable()*
|
||||
echo filereadable(expand('~/.vimrc'))
|
||||
1
|
||||
|
||||
< Can also be used as a |method|: >
|
||||
GetName()->filereadable()
|
||||
|
||||
filewritable({file}) *filewritable()*
|
||||
The result is a Number, which is 1 when a file with the
|
||||
name {file} exists, and can be written. If {file} doesn't
|
||||
exist, or is not writable, the result is 0. If {file} is a
|
||||
directory, and we can write to it, the result is 2.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetName()->filewriteable()
|
||||
|
||||
filter({expr1}, {expr2}) *filter()*
|
||||
{expr1} must be a |List|, |Blob|, or a |Dictionary|.
|
||||
@ -4275,6 +4304,9 @@ finddir({name} [, {path} [, {count}]]) *finddir()*
|
||||
|
||||
This is quite similar to the ex-command `:find`.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetName()->finddir()
|
||||
|
||||
findfile({name} [, {path} [, {count}]]) *findfile()*
|
||||
Just like |finddir()|, but find a file instead of a directory.
|
||||
Uses 'suffixesadd'.
|
||||
@ -4283,6 +4315,9 @@ findfile({name} [, {path} [, {count}]]) *findfile()*
|
||||
< Searches from the directory of the current file upwards until
|
||||
it finds the file "tags.vim".
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetName()->findfile()
|
||||
|
||||
flatten({list} [, {maxdepth}]) *flatten()*
|
||||
Flatten {list} up to {maxdepth} levels. Without {maxdepth}
|
||||
the result is a |List| without nesting, as if {maxdepth} is
|
||||
@ -4372,6 +4407,9 @@ fnameescape({string}) *fnameescape()*
|
||||
:exe "edit " . fnameescape(fname)
|
||||
< results in executing: >
|
||||
edit \+some\ str\%nge\|name
|
||||
<
|
||||
Can also be used as a |method|: >
|
||||
GetName()->fnameescape()
|
||||
|
||||
fnamemodify({fname}, {mods}) *fnamemodify()*
|
||||
Modify file name {fname} according to {mods}. {mods} is a
|
||||
@ -4385,6 +4423,9 @@ fnamemodify({fname}, {mods}) *fnamemodify()*
|
||||
Note: Environment variables don't work in {fname}, use
|
||||
|expand()| first then.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetName()->fnamemodify(':p:h')
|
||||
|
||||
foldclosed({lnum}) *foldclosed()*
|
||||
The result is a Number. If the line {lnum} is in a closed
|
||||
fold, the result is the number of the first line in that fold.
|
||||
@ -4392,6 +4433,9 @@ foldclosed({lnum}) *foldclosed()*
|
||||
{lnum} is used like with |getline()|. Thus "." is the current
|
||||
line, "'m" mark m, etc.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetLnum()->foldclosed()
|
||||
|
||||
foldclosedend({lnum}) *foldclosedend()*
|
||||
The result is a Number. If the line {lnum} is in a closed
|
||||
fold, the result is the number of the last line in that fold.
|
||||
@ -4399,6 +4443,9 @@ foldclosedend({lnum}) *foldclosedend()*
|
||||
{lnum} is used like with |getline()|. Thus "." is the current
|
||||
line, "'m" mark m, etc.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetLnum()->foldclosedend()
|
||||
|
||||
foldlevel({lnum}) *foldlevel()*
|
||||
The result is a Number, which is the foldlevel of line {lnum}
|
||||
in the current buffer. For nested folds the deepest level is
|
||||
@ -4411,6 +4458,9 @@ foldlevel({lnum}) *foldlevel()*
|
||||
{lnum} is used like with |getline()|. Thus "." is the current
|
||||
line, "'m" mark m, etc.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetLnum()->foldlevel()
|
||||
|
||||
*foldtext()*
|
||||
foldtext() Returns a String, to be displayed for a closed fold. This is
|
||||
the default function used for the 'foldtext' option and should
|
||||
@ -4436,6 +4486,9 @@ foldtextresult({lnum}) *foldtextresult()*
|
||||
line, "'m" mark m, etc.
|
||||
Useful when exporting folded text, e.g., to HTML.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetLnum()->foldtextresult()
|
||||
<
|
||||
*foreground()*
|
||||
foreground() Move the Vim window to the foreground. Useful when sent from
|
||||
a client to a Vim server. |remote_send()|
|
||||
@ -4454,6 +4507,9 @@ funcref({name} [, {arglist}] [, {dict}])
|
||||
Also for autoloaded functions. {name} cannot be a builtin
|
||||
function.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetFuncname()->funcref([arg])
|
||||
<
|
||||
*function()* *E700* *E922* *E923*
|
||||
function({name} [, {arglist}] [, {dict}])
|
||||
Return a |Funcref| variable that refers to function {name}.
|
||||
@ -4503,7 +4559,9 @@ function({name} [, {arglist}] [, {dict}])
|
||||
call Func(500)
|
||||
< Invokes the function as with: >
|
||||
call context.Callback('one', 500)
|
||||
|
||||
<
|
||||
Can also be used as a |method|: >
|
||||
GetFuncname()->function([arg])
|
||||
|
||||
garbagecollect([{atexit}]) *garbagecollect()*
|
||||
Cleanup unused |Lists| and |Dictionaries| that have circular
|
||||
|
@ -102,38 +102,38 @@ return {
|
||||
diff_hlID={args=2, base=1},
|
||||
empty={args=1, base=1},
|
||||
environ={},
|
||||
escape={args=2},
|
||||
escape={args=2, base=1},
|
||||
eval={args=1, base=1},
|
||||
eventhandler={},
|
||||
executable={args=1},
|
||||
execute={args={1, 2}},
|
||||
exepath={args=1},
|
||||
exists={args=1},
|
||||
executable={args=1, base=1},
|
||||
execute={args={1, 2}, base=1},
|
||||
exepath={args=1, base=1},
|
||||
exists={args=1, base=1},
|
||||
exp={args=1, base=1, func="float_op_wrapper", data="&exp"},
|
||||
expand={args={1, 3}},
|
||||
expandcmd={args=1},
|
||||
expand={args={1, 3}, base=1},
|
||||
expandcmd={args=1, base=1},
|
||||
extend={args={2, 3}, base=1},
|
||||
feedkeys={args={1, 2}},
|
||||
file_readable={args=1, func='f_filereadable'}, -- obsolete
|
||||
filereadable={args=1},
|
||||
filewritable={args=1},
|
||||
feedkeys={args={1, 2}, base=1},
|
||||
file_readable={args=1, base=1, func='f_filereadable'}, -- obsolete
|
||||
filereadable={args=1, base=1},
|
||||
filewritable={args=1, base=1},
|
||||
filter={args=2, base=1},
|
||||
finddir={args={1, 3}},
|
||||
findfile={args={1, 3}},
|
||||
finddir={args={1, 3}, base=1},
|
||||
findfile={args={1, 3}, base=1},
|
||||
flatten={args={1, 2}},
|
||||
float2nr={args=1, base=1},
|
||||
floor={args=1, base=1, func="float_op_wrapper", data="&floor"},
|
||||
fmod={args=2, base=1},
|
||||
fnameescape={args=1},
|
||||
fnamemodify={args=2},
|
||||
foldclosed={args=1},
|
||||
foldclosedend={args=1},
|
||||
foldlevel={args=1},
|
||||
fnameescape={args=1, base=1},
|
||||
fnamemodify={args=2, base=1},
|
||||
foldclosed={args=1, base=1},
|
||||
foldclosedend={args=1, base=1},
|
||||
foldlevel={args=1, base=1},
|
||||
foldtext={},
|
||||
foldtextresult={args=1},
|
||||
foldtextresult={args=1, base=1},
|
||||
foreground={},
|
||||
funcref={args={1, 3}},
|
||||
['function']={args={1, 3}},
|
||||
funcref={args={1, 3}, base=1},
|
||||
['function']={args={1, 3}, base=1},
|
||||
garbagecollect={args={0, 1}},
|
||||
get={args={2, 3}, base=1},
|
||||
getbufinfo={args={0, 1}},
|
||||
|
@ -40,7 +40,7 @@ endfunc
|
||||
func Test_expand()
|
||||
new
|
||||
call assert_equal("", expand('%:S'))
|
||||
call assert_equal('3', expand('<slnum>'))
|
||||
call assert_equal('3', '<slnum>'->expand())
|
||||
call assert_equal(['4'], expand('<slnum>', v:false, v:true))
|
||||
" Don't add any line above this, otherwise <slnum> will change.
|
||||
quit
|
||||
|
@ -147,7 +147,7 @@ function Test_printf_spec_s()
|
||||
call assert_equal(string(value), printf('%s', value))
|
||||
|
||||
" funcref
|
||||
call assert_equal('printf', printf('%s', function('printf')))
|
||||
call assert_equal('printf', printf('%s', 'printf'->function()))
|
||||
|
||||
" partial
|
||||
call assert_equal(string(function('printf', ['%s'])), printf('%s', function('printf', ['%s'])))
|
||||
@ -477,7 +477,7 @@ func Test_funcref()
|
||||
endfunc
|
||||
call assert_equal(2, OneByName())
|
||||
call assert_equal(1, OneByRef())
|
||||
let OneByRef = funcref('One')
|
||||
let OneByRef = 'One'->funcref()
|
||||
call assert_equal(2, OneByRef())
|
||||
call assert_fails('echo funcref("{")', 'E475:')
|
||||
let OneByRef = funcref("One", repeat(["foo"], 20))
|
||||
|
@ -50,7 +50,7 @@ func Test_findfile()
|
||||
set path=.
|
||||
call assert_equal('Xdir2/foo', findfile('foo'))
|
||||
call assert_equal('', findfile('bar'))
|
||||
call assert_equal('Xdir2/foobar', findfile('foobar'))
|
||||
call assert_equal('Xdir2/foobar', 'foobar'->findfile())
|
||||
|
||||
" Empty {path} 2nd argument is the same as no 2nd argument.
|
||||
call assert_equal('Xdir2/foo', findfile('foo', ''))
|
||||
@ -138,7 +138,7 @@ func Test_finddir()
|
||||
cd Xdir1
|
||||
|
||||
call assert_equal('Xdir2', finddir('Xdir2'))
|
||||
call assert_equal('', finddir('Xdir3'))
|
||||
call assert_equal('', 'Xdir3'->finddir())
|
||||
|
||||
" Files should not be found (findfile() finds them).
|
||||
call assert_equal('', finddir('foo'))
|
||||
|
@ -13,7 +13,7 @@ func Test_fnameescape()
|
||||
let fname = 'Xemark!'
|
||||
let status = v:false
|
||||
try
|
||||
exe "w! " . fnameescape(fname)
|
||||
exe "w! " . fname->fnameescape()
|
||||
let status = v:true
|
||||
endtry
|
||||
call assert_true(status, "ExclamationMark")
|
||||
|
@ -13,7 +13,7 @@ func Test_fnamemodify()
|
||||
call assert_equal('a', fnamemodify('../testdir/a', ':.'))
|
||||
call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~'))
|
||||
call assert_equal('~/testdir/a', fnamemodify('../testdir/a', ':~'))
|
||||
call assert_equal('a', fnamemodify('../testdir/a', ':t'))
|
||||
call assert_equal('a', '../testdir/a'->fnamemodify(':t'))
|
||||
call assert_equal('', fnamemodify('.', ':p:t'))
|
||||
call assert_equal('test.out', fnamemodify('test.out', ':p:t'))
|
||||
call assert_equal('out', fnamemodify('test.out', ':p:e'))
|
||||
|
@ -88,7 +88,7 @@ func Test_indent_fold2()
|
||||
setl fen fdm=marker
|
||||
2
|
||||
norm! >>
|
||||
let a=map(range(1,5), 'foldclosed(v:val)')
|
||||
let a=map(range(1,5), 'v:val->foldclosed()')
|
||||
call assert_equal([-1,-1,-1,4,4], a)
|
||||
bw!
|
||||
endfunc
|
||||
@ -132,7 +132,7 @@ func Test_indent_fold_with_read()
|
||||
call assert_equal(0, foldlevel(3))
|
||||
call assert_equal(0, foldlevel(4))
|
||||
call assert_equal(1, foldlevel(5))
|
||||
call assert_equal(7, foldclosedend(5))
|
||||
call assert_equal(7, 5->foldclosedend())
|
||||
|
||||
bwipe!
|
||||
set foldmethod&
|
||||
@ -207,7 +207,7 @@ func Test_update_folds_expr_read()
|
||||
%foldclose
|
||||
call assert_equal(2, foldclosedend(1))
|
||||
call assert_equal(0, foldlevel(3))
|
||||
call assert_equal(0, foldlevel(4))
|
||||
call assert_equal(0, 4->foldlevel())
|
||||
call assert_equal(6, foldclosedend(5))
|
||||
call assert_equal(10, foldclosedend(7))
|
||||
call assert_equal(14, foldclosedend(11))
|
||||
@ -663,7 +663,7 @@ func Test_fold_move()
|
||||
call assert_equal(10, foldclosed(10))
|
||||
call assert_equal(11, foldclosedend(10))
|
||||
call assert_equal('+-- 2 lines: Line2', foldtextresult(2))
|
||||
call assert_equal('+-- 2 lines: Line8', foldtextresult(10))
|
||||
call assert_equal('+-- 2 lines: Line8', 10->foldtextresult())
|
||||
|
||||
set fdm& sw& fdl&
|
||||
enew!
|
||||
|
@ -1057,7 +1057,7 @@ func Test_filewritable()
|
||||
call assert_equal(0, filewritable('Xfilewritable'))
|
||||
|
||||
call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----'))
|
||||
call assert_equal(1, filewritable('Xfilewritable'))
|
||||
call assert_equal(1, 'Xfilewritable'->filewritable())
|
||||
|
||||
call assert_equal(0, filewritable('doesnotexist'))
|
||||
|
||||
@ -1068,12 +1068,12 @@ endfunc
|
||||
func Test_Executable()
|
||||
if has('win32')
|
||||
call assert_equal(1, executable('notepad'))
|
||||
call assert_equal(1, executable('notepad.exe'))
|
||||
call assert_equal(1, 'notepad.exe'->executable())
|
||||
call assert_equal(0, executable('notepad.exe.exe'))
|
||||
call assert_equal(0, executable('shell32.dll'))
|
||||
call assert_equal(0, executable('win.ini'))
|
||||
elseif has('unix')
|
||||
call assert_equal(1, executable('cat'))
|
||||
call assert_equal(1, 'cat'->executable())
|
||||
call assert_equal(0, executable('nodogshere'))
|
||||
|
||||
" get "cat" path and remove the leading /
|
||||
@ -1082,8 +1082,7 @@ func Test_Executable()
|
||||
" check that the relative path works in /
|
||||
lcd /
|
||||
call assert_equal(1, executable(catcmd))
|
||||
" let result = catcmd->exepath()
|
||||
let result = exepath(catcmd)
|
||||
let result = catcmd->exepath()
|
||||
" when using chroot looking for sbin/cat can return bin/cat, that is OK
|
||||
if catcmd =~ '\<sbin\>' && result =~ '\<bin\>'
|
||||
call assert_equal('/' .. substitute(catcmd, '\<sbin\>', 'bin', ''), result)
|
||||
@ -1320,7 +1319,7 @@ func Test_func_exists_on_reload()
|
||||
call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists')
|
||||
call assert_equal(0, exists('*ExistingFunction'))
|
||||
source Xfuncexists
|
||||
call assert_equal(1, exists('*ExistingFunction'))
|
||||
call assert_equal(1, '*ExistingFunction'->exists())
|
||||
" Redefining a function when reloading a script is OK.
|
||||
source Xfuncexists
|
||||
call assert_equal(1, exists('*ExistingFunction'))
|
||||
@ -1351,7 +1350,7 @@ func Test_func_sandbox()
|
||||
sandbox let F = {-> 'hello'}
|
||||
call assert_equal('hello', F())
|
||||
|
||||
sandbox let F = {-> execute("normal ix\<Esc>")}
|
||||
sandbox let F = {-> "normal ix\<Esc>"->execute()}
|
||||
call assert_fails('call F()', 'E48:')
|
||||
unlet F
|
||||
|
||||
|
@ -1338,7 +1338,7 @@ func Test_search_display_pattern()
|
||||
|
||||
call cursor(1, 1)
|
||||
let @/ = 'foo'
|
||||
let pat = escape(@/, '()*?'. '\s\+')
|
||||
let pat = @/->escape('()*?'. '\s\+')
|
||||
let g:a = execute(':unsilent :norm! n')
|
||||
call assert_match(pat, g:a)
|
||||
|
||||
|
@ -635,7 +635,7 @@ function! MSG(enr, emsg)
|
||||
if v:errmsg == ""
|
||||
Xout "Message missing."
|
||||
else
|
||||
let v:errmsg = escape(v:errmsg, '"')
|
||||
let v:errmsg = v:errmsg->escape('"')
|
||||
Xout "Unexpected message:" v:errmsg
|
||||
endif
|
||||
endif
|
||||
|
@ -81,7 +81,7 @@ describe('expand file name', function()
|
||||
call assert_equal('e Xfile1', expandcmd('e %'))
|
||||
edit Xfile2
|
||||
edit Xfile1
|
||||
call assert_equal('e Xfile2', expandcmd('e #'))
|
||||
call assert_equal('e Xfile2', 'e #'->expandcmd())
|
||||
edit Xfile2
|
||||
edit Xfile3
|
||||
edit Xfile4
|
||||
|
Loading…
Reference in New Issue
Block a user