0
0
mirror of https://github.com/vim/vim.git synced 2025-10-17 07:44:28 -04:00

patch 8.1.1921: more functions can be used as methods

Problem:    More functions can be used as methods.
Solution:   Make various functions usable as a method.
This commit is contained in:
Bram Moolenaar
2019-08-24 20:50:19 +02:00
parent f63962378d
commit a4208966fb
13 changed files with 109 additions and 44 deletions

View File

@@ -1,4 +1,4 @@
*eval.txt* For Vim version 8.1. Last change: 2019 Aug 21 *eval.txt* For Vim version 8.1. Last change: 2019 Aug 24
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -3925,6 +3925,7 @@ empty({expr}) *empty()*
For a long |List| this is much faster than comparing the For a long |List| this is much faster than comparing the
length with zero. length with zero.
Can also be used as a |method|: > Can also be used as a |method|: >
mylist->empty() mylist->empty()
@@ -3936,6 +3937,9 @@ escape({string}, {chars}) *escape()*
c:\\program\ files\\vim c:\\program\ files\\vim
< Also see |shellescape()| and |fnameescape()|. < Also see |shellescape()| and |fnameescape()|.
Can also be used as a |method|: >
GetText()->escape(' \')
<
*eval()* *eval()*
eval({string}) Evaluate {string} and return the result. Especially useful to eval({string}) Evaluate {string} and return the result. Especially useful to
turn the result of |string()| back into the original value. turn the result of |string()| back into the original value.
@@ -3977,6 +3981,9 @@ executable({expr}) *executable()*
-1 not implemented on this system -1 not implemented on this system
|exepath()| can be used to get the full path of an executable. |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} [, {silent}]) *execute()*
Execute an Ex command or commands and return the output as a Execute an Ex command or commands and return the output as a
string. string.
@@ -4006,6 +4013,9 @@ execute({command} [, {silent}]) *execute()*
When used recursively the output of the recursive call is not When used recursively the output of the recursive call is not
included in the output of the higher level call. included in the output of the higher level call.
Can also be used as a |method|: >
GetCommand()->execute()
exepath({expr}) *exepath()* exepath({expr}) *exepath()*
If {expr} is an executable and is either an absolute path, a If {expr} is an executable and is either an absolute path, a
relative path or found in $PATH, return the full path. relative path or found in $PATH, return the full path.
@@ -4015,6 +4025,9 @@ exepath({expr}) *exepath()*
< If {expr} cannot be found in $PATH or is not executable then < If {expr} cannot be found in $PATH or is not executable then
an empty string is returned. an empty string is returned.
Can also be used as a |method|: >
GetCommand()->exepath()
*exists()* *exists()*
exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined, exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
zero otherwise. zero otherwise.
@@ -4100,6 +4113,9 @@ exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
< This doesn't check for existence of the "bufcount" variable, < This doesn't check for existence of the "bufcount" variable,
but gets the value of "bufcount", and checks if that exists. but gets the value of "bufcount", and checks if that exists.
Can also be used as a |method|: >
Varname()->exists()
exp({expr}) *exp()* exp({expr}) *exp()*
Return the exponential of {expr} as a |Float| in the range Return the exponential of {expr} as a |Float| in the range
[0, inf]. [0, inf].
@@ -4200,6 +4216,9 @@ expand({expr} [, {nosuf} [, {list}]]) *expand()*
See |glob()| for finding existing files. See |system()| for See |glob()| for finding existing files. See |system()| for
getting the raw output of an external command. getting the raw output of an external command.
Can also be used as a |method|: >
Getpattern()->expand()
expandcmd({expr}) *expandcmd()* expandcmd({expr}) *expandcmd()*
Expand special items in {expr} like what is done for an Ex Expand special items in {expr} like what is done for an Ex
command such as `:edit`. This expands special keywords, like command such as `:edit`. This expands special keywords, like
@@ -4207,6 +4226,9 @@ expandcmd({expr}) *expandcmd()*
{expr}. Returns the expanded string. {expr}. Returns the expanded string.
Example: > Example: >
:echo expandcmd('make %<.o') :echo expandcmd('make %<.o')
< Can also be used as a |method|: >
GetCommand()->expandcmd()
< <
extend({expr1}, {expr2} [, {expr3}]) *extend()* extend({expr1}, {expr2} [, {expr3}]) *extend()*
{expr1} and {expr2} must be both |Lists| or both {expr1} and {expr2} must be both |Lists| or both
@@ -4296,6 +4318,9 @@ feedkeys({string} [, {mode}]) *feedkeys()*
Return value is always 0. Return value is always 0.
Can also be used as a |method|: >
GetInput()->feedkeys()
filereadable({file}) *filereadable()* filereadable({file}) *filereadable()*
The result is a Number, which is |TRUE| when a file with the 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, name {file} exists, and can be read. If {file} doesn't exist,
@@ -4308,6 +4333,9 @@ filereadable({file}) *filereadable()*
0 0
echo filereadable(expand('~/.vimrc')) echo filereadable(expand('~/.vimrc'))
1 1
< Can also be used as a |method|: >
GetName()->filereadable()
< *file_readable()* < *file_readable()*
Obsolete name: file_readable(). Obsolete name: file_readable().
@@ -4318,6 +4346,9 @@ filewritable({file}) *filewritable()*
exist, or is not writable, the result is 0. If {file} is a exist, or is not writable, the result is 0. If {file} is a
directory, and we can write to it, the result is 2. directory, and we can write to it, the result is 2.
Can also be used as a |method|: >
GetName()->filewriteable()
filter({expr1}, {expr2}) *filter()* filter({expr1}, {expr2}) *filter()*
{expr1} must be a |List| or a |Dictionary|. {expr1} must be a |List| or a |Dictionary|.
@@ -4383,6 +4414,9 @@ finddir({name} [, {path} [, {count}]]) *finddir()*
{only available when compiled with the |+file_in_path| {only available when compiled with the |+file_in_path|
feature} feature}
Can also be used as a |method|: >
GetName()->finddir()
findfile({name} [, {path} [, {count}]]) *findfile()* findfile({name} [, {path} [, {count}]]) *findfile()*
Just like |finddir()|, but find a file instead of a directory. Just like |finddir()|, but find a file instead of a directory.
Uses 'suffixesadd'. Uses 'suffixesadd'.
@@ -4391,6 +4425,9 @@ findfile({name} [, {path} [, {count}]]) *findfile()*
< Searches from the directory of the current file upwards until < Searches from the directory of the current file upwards until
it finds the file "tags.vim". it finds the file "tags.vim".
Can also be used as a |method|: >
GetName()->findfile()
float2nr({expr}) *float2nr()* float2nr({expr}) *float2nr()*
Convert {expr} to a Number by omitting the part after the Convert {expr} to a Number by omitting the part after the
decimal point. decimal point.
@@ -4470,6 +4507,9 @@ fnameescape({string}) *fnameescape()*
:exe "edit " . fnameescape(fname) :exe "edit " . fnameescape(fname)
< results in executing: > < results in executing: >
edit \+some\ str\%nge\|name edit \+some\ str\%nge\|name
<
Can also be used as a |method|: >
GetName()->fnameescape()
fnamemodify({fname}, {mods}) *fnamemodify()* fnamemodify({fname}, {mods}) *fnamemodify()*
Modify file name {fname} according to {mods}. {mods} is a Modify file name {fname} according to {mods}. {mods} is a
@@ -4482,16 +4522,25 @@ fnamemodify({fname}, {mods}) *fnamemodify()*
< Note: Environment variables don't work in {fname}, use < Note: Environment variables don't work in {fname}, use
|expand()| first then. |expand()| first then.
Can also be used as a |method|: >
GetName()->fnamemodify(':p:h')
foldclosed({lnum}) *foldclosed()* foldclosed({lnum}) *foldclosed()*
The result is a Number. If the line {lnum} is in a closed 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. fold, the result is the number of the first line in that fold.
If the line {lnum} is not in a closed fold, -1 is returned. If the line {lnum} is not in a closed fold, -1 is returned.
Can also be used as a |method|: >
GetLnum()->foldclosed()
foldclosedend({lnum}) *foldclosedend()* foldclosedend({lnum}) *foldclosedend()*
The result is a Number. If the line {lnum} is in a closed 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. fold, the result is the number of the last line in that fold.
If the line {lnum} is not in a closed fold, -1 is returned. If the line {lnum} is not in a closed fold, -1 is returned.
Can also be used as a |method|: >
GetLnum()->foldclosedend()
foldlevel({lnum}) *foldlevel()* foldlevel({lnum}) *foldlevel()*
The result is a Number, which is the foldlevel of line {lnum} The result is a Number, which is the foldlevel of line {lnum}
in the current buffer. For nested folds the deepest level is in the current buffer. For nested folds the deepest level is
@@ -4502,6 +4551,9 @@ foldlevel({lnum}) *foldlevel()*
foldlevel is unknown. As a special case the level of the foldlevel is unknown. As a special case the level of the
previous line is usually available. previous line is usually available.
Can also be used as a |method|: >
GetLnum()->foldlevel()
*foldtext()* *foldtext()*
foldtext() Returns a String, to be displayed for a closed fold. This is foldtext() Returns a String, to be displayed for a closed fold. This is
the default function used for the 'foldtext' option and should the default function used for the 'foldtext' option and should
@@ -4529,6 +4581,10 @@ foldtextresult({lnum}) *foldtextresult()*
Useful when exporting folded text, e.g., to HTML. Useful when exporting folded text, e.g., to HTML.
{not available when compiled without the |+folding| feature} {not available when compiled without the |+folding| feature}
Can also be used as a |method|: >
GetLnum()->foldtextresult()
<
*foreground()* *foreground()*
foreground() Move the Vim window to the foreground. Useful when sent from foreground() Move the Vim window to the foreground. Useful when sent from
a client to a Vim server. |remote_send()| a client to a Vim server. |remote_send()|
@@ -4548,6 +4604,9 @@ funcref({name} [, {arglist}] [, {dict}])
Also for autoloaded functions. {name} cannot be a builtin Also for autoloaded functions. {name} cannot be a builtin
function. function.
Can also be used as a |method|: >
GetFuncname()->funcref([arg])
<
*function()* *E700* *E922* *E923* *function()* *E700* *E922* *E923*
function({name} [, {arglist}] [, {dict}]) function({name} [, {arglist}] [, {dict}])
Return a |Funcref| variable that refers to function {name}. Return a |Funcref| variable that refers to function {name}.
@@ -4623,6 +4682,9 @@ function({name} [, {arglist}] [, {dict}])
call Func(500) call Func(500)
< Invokes the function as with: > < Invokes the function as with: >
call context.Callback('one', 500) call context.Callback('one', 500)
<
Can also be used as a |method|: >
GetFuncname()->function([arg])
garbagecollect([{atexit}]) *garbagecollect()* garbagecollect([{atexit}]) *garbagecollect()*

View File

@@ -523,41 +523,41 @@ static funcentry_T global_functions[] =
{"diff_hlID", 2, 2, FEARG_1, f_diff_hlID}, {"diff_hlID", 2, 2, FEARG_1, f_diff_hlID},
{"empty", 1, 1, FEARG_1, f_empty}, {"empty", 1, 1, FEARG_1, f_empty},
{"environ", 0, 0, 0, f_environ}, {"environ", 0, 0, 0, f_environ},
{"escape", 2, 2, 0, f_escape}, {"escape", 2, 2, FEARG_1, f_escape},
{"eval", 1, 1, FEARG_1, f_eval}, {"eval", 1, 1, FEARG_1, f_eval},
{"eventhandler", 0, 0, 0, f_eventhandler}, {"eventhandler", 0, 0, 0, f_eventhandler},
{"executable", 1, 1, 0, f_executable}, {"executable", 1, 1, FEARG_1, f_executable},
{"execute", 1, 2, 0, f_execute}, {"execute", 1, 2, FEARG_1, f_execute},
{"exepath", 1, 1, 0, f_exepath}, {"exepath", 1, 1, FEARG_1, f_exepath},
{"exists", 1, 1, 0, f_exists}, {"exists", 1, 1, FEARG_1, f_exists},
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
{"exp", 1, 1, FEARG_1, f_exp}, {"exp", 1, 1, FEARG_1, f_exp},
#endif #endif
{"expand", 1, 3, 0, f_expand}, {"expand", 1, 3, FEARG_1, f_expand},
{"expandcmd", 1, 1, 0, f_expandcmd}, {"expandcmd", 1, 1, FEARG_1, f_expandcmd},
{"extend", 2, 3, FEARG_1, f_extend}, {"extend", 2, 3, FEARG_1, f_extend},
{"feedkeys", 1, 2, 0, f_feedkeys}, {"feedkeys", 1, 2, FEARG_1, f_feedkeys},
{"file_readable", 1, 1, 0, f_filereadable}, // obsolete {"file_readable", 1, 1, FEARG_1, f_filereadable}, // obsolete
{"filereadable", 1, 1, 0, f_filereadable}, {"filereadable", 1, 1, FEARG_1, f_filereadable},
{"filewritable", 1, 1, 0, f_filewritable}, {"filewritable", 1, 1, FEARG_1, f_filewritable},
{"filter", 2, 2, FEARG_1, f_filter}, {"filter", 2, 2, FEARG_1, f_filter},
{"finddir", 1, 3, 0, f_finddir}, {"finddir", 1, 3, FEARG_1, f_finddir},
{"findfile", 1, 3, 0, f_findfile}, {"findfile", 1, 3, FEARG_1, f_findfile},
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
{"float2nr", 1, 1, FEARG_1, f_float2nr}, {"float2nr", 1, 1, FEARG_1, f_float2nr},
{"floor", 1, 1, FEARG_1, f_floor}, {"floor", 1, 1, FEARG_1, f_floor},
{"fmod", 2, 2, FEARG_1, f_fmod}, {"fmod", 2, 2, FEARG_1, f_fmod},
#endif #endif
{"fnameescape", 1, 1, 0, f_fnameescape}, {"fnameescape", 1, 1, FEARG_1, f_fnameescape},
{"fnamemodify", 2, 2, 0, f_fnamemodify}, {"fnamemodify", 2, 2, FEARG_1, f_fnamemodify},
{"foldclosed", 1, 1, 0, f_foldclosed}, {"foldclosed", 1, 1, FEARG_1, f_foldclosed},
{"foldclosedend", 1, 1, 0, f_foldclosedend}, {"foldclosedend", 1, 1, FEARG_1, f_foldclosedend},
{"foldlevel", 1, 1, 0, f_foldlevel}, {"foldlevel", 1, 1, FEARG_1, f_foldlevel},
{"foldtext", 0, 0, 0, f_foldtext}, {"foldtext", 0, 0, 0, f_foldtext},
{"foldtextresult", 1, 1, 0, f_foldtextresult}, {"foldtextresult", 1, 1, FEARG_1, f_foldtextresult},
{"foreground", 0, 0, 0, f_foreground}, {"foreground", 0, 0, 0, f_foreground},
{"funcref", 1, 3, 0, f_funcref}, {"funcref", 1, 3, FEARG_1, f_funcref},
{"function", 1, 3, 0, f_function}, {"function", 1, 3, FEARG_1, f_function},
{"garbagecollect", 0, 1, 0, f_garbagecollect}, {"garbagecollect", 0, 1, 0, f_garbagecollect},
{"get", 2, 3, FEARG_1, f_get}, {"get", 2, 3, FEARG_1, f_get},
{"getbufinfo", 0, 1, 0, f_getbufinfo}, {"getbufinfo", 0, 1, 0, f_getbufinfo},

View File

@@ -58,7 +58,7 @@ func Test_expandcmd()
call assert_equal('e Xfile1', expandcmd('e %')) call assert_equal('e Xfile1', expandcmd('e %'))
edit Xfile2 edit Xfile2
edit Xfile1 edit Xfile1
call assert_equal('e Xfile2', expandcmd('e #')) call assert_equal('e Xfile2', 'e #'->expandcmd())
edit Xfile2 edit Xfile2
edit Xfile3 edit Xfile3
edit Xfile4 edit Xfile4

View File

@@ -68,7 +68,7 @@ endfunc
func Test_expand() func Test_expand()
new new
call assert_equal("", expand('%:S')) 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)) call assert_equal(['4'], expand('<slnum>', v:false, v:true))
" Don't add any line above this, otherwise <slnum> will change. " Don't add any line above this, otherwise <slnum> will change.
quit quit

View File

@@ -403,7 +403,7 @@ function Test_printf_spec_s()
call assert_equal(string(value), printf('%s', value)) call assert_equal(string(value), printf('%s', value))
" funcref " funcref
call assert_equal('printf', printf('%s', function('printf'))) call assert_equal('printf', printf('%s', 'printf'->function()))
" partial " partial
call assert_equal(string(function('printf', ['%s'])), printf('%s', function('printf', ['%s']))) call assert_equal(string(function('printf', ['%s'])), printf('%s', function('printf', ['%s'])))
@@ -490,7 +490,7 @@ func Test_funcref()
endfunc endfunc
call assert_equal(2, OneByName()) call assert_equal(2, OneByName())
call assert_equal(1, OneByRef()) call assert_equal(1, OneByRef())
let OneByRef = funcref('One') let OneByRef = 'One'->funcref()
call assert_equal(2, OneByRef()) call assert_equal(2, OneByRef())
call assert_fails('echo funcref("{")', 'E475:') call assert_fails('echo funcref("{")', 'E475:')
endfunc endfunc

View File

@@ -50,7 +50,7 @@ func Test_findfile()
set path=. set path=.
call assert_equal('Xdir2/foo', findfile('foo')) call assert_equal('Xdir2/foo', findfile('foo'))
call assert_equal('', findfile('bar')) 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. " Empty {path} 2nd argument is the same as no 2nd argument.
call assert_equal('Xdir2/foo', findfile('foo', '')) call assert_equal('Xdir2/foo', findfile('foo', ''))
@@ -137,7 +137,7 @@ func Test_finddir()
cd Xdir1 cd Xdir1
call assert_equal('Xdir2', finddir('Xdir2')) call assert_equal('Xdir2', finddir('Xdir2'))
call assert_equal('', finddir('Xdir3')) call assert_equal('', 'Xdir3'->finddir())
" Files should not be found (findfile() finds them). " Files should not be found (findfile() finds them).
call assert_equal('', finddir('foo')) call assert_equal('', finddir('foo'))

View File

@@ -13,7 +13,7 @@ func Test_fnameescape()
let fname = 'Xemark!' let fname = 'Xemark!'
let status = v:false let status = v:false
try try
exe "w! " . fnameescape(fname) exe "w! " . fname->fnameescape()
let status = v:true let status = v:true
endtry endtry
call assert_true(status, "ExclamationMark") call assert_true(status, "ExclamationMark")

View File

@@ -13,7 +13,7 @@ func Test_fnamemodify()
call assert_equal('a', fnamemodify('../testdir/a', ':.')) call assert_equal('a', fnamemodify('../testdir/a', ':.'))
call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~')) call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~'))
call assert_equal('~/testdir/a', fnamemodify('../testdir/a', ':~')) 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('', fnamemodify('.', ':p:t'))
call assert_equal('test.out', fnamemodify('test.out', ':p:t')) call assert_equal('test.out', fnamemodify('test.out', ':p:t'))
call assert_equal('out', fnamemodify('test.out', ':p:e')) call assert_equal('out', fnamemodify('test.out', ':p:e'))

View File

@@ -89,7 +89,7 @@ func Test_indent_fold2()
setl fen fdm=marker setl fen fdm=marker
2 2
norm! >> 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) call assert_equal([-1,-1,-1,4,4], a)
bw! bw!
endfunc endfunc
@@ -133,7 +133,7 @@ func Test_indent_fold_with_read()
call assert_equal(0, foldlevel(3)) call assert_equal(0, foldlevel(3))
call assert_equal(0, foldlevel(4)) call assert_equal(0, foldlevel(4))
call assert_equal(1, foldlevel(5)) call assert_equal(1, foldlevel(5))
call assert_equal(7, foldclosedend(5)) call assert_equal(7, 5->foldclosedend())
bwipe! bwipe!
set foldmethod& set foldmethod&
@@ -208,7 +208,7 @@ func Test_update_folds_expr_read()
%foldclose %foldclose
call assert_equal(2, foldclosedend(1)) call assert_equal(2, foldclosedend(1))
call assert_equal(0, foldlevel(3)) 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(6, foldclosedend(5))
call assert_equal(10, foldclosedend(7)) call assert_equal(10, foldclosedend(7))
call assert_equal(14, foldclosedend(11)) call assert_equal(14, foldclosedend(11))
@@ -656,7 +656,7 @@ func Test_fold_move()
call assert_equal(10, foldclosed(10)) call assert_equal(10, foldclosed(10))
call assert_equal(11, foldclosedend(10)) call assert_equal(11, foldclosedend(10))
call assert_equal('+-- 2 lines: Line2', foldtextresult(2)) 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& set fdm& sw& fdl&
enew! enew!

View File

@@ -1001,7 +1001,7 @@ func Test_filewritable()
call assert_equal(0, filewritable('Xfilewritable')) call assert_equal(0, filewritable('Xfilewritable'))
call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----')) 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')) call assert_equal(0, filewritable('doesnotexist'))
@@ -1012,20 +1012,21 @@ endfunc
func Test_Executable() func Test_Executable()
if has('win32') if has('win32')
call assert_equal(1, executable('notepad')) 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('notepad.exe.exe'))
call assert_equal(0, executable('shell32.dll')) call assert_equal(0, executable('shell32.dll'))
call assert_equal(0, executable('win.ini')) call assert_equal(0, executable('win.ini'))
elseif has('unix') elseif has('unix')
call assert_equal(1, executable('cat')) call assert_equal(1, 'cat'->executable())
call assert_equal(0, executable('nodogshere')) call assert_equal(0, executable('nodogshere'))
" get "cat" path and remove the leading / " get "cat" path and remove the leading /
let catcmd = exepath('cat')[1:] let catcmd = exepath('cat')[1:]
new new
" check that the relative path works in /
lcd / lcd /
call assert_equal(1, executable(catcmd)) call assert_equal(1, executable(catcmd))
call assert_equal('/' .. catcmd, exepath(catcmd)) call assert_equal('/' .. catcmd, catcmd->exepath())
bwipe bwipe
endif endif
endfunc endfunc
@@ -1349,7 +1350,7 @@ func Test_func_sandbox()
sandbox let F = {-> 'hello'} sandbox let F = {-> 'hello'}
call assert_equal('hello', F()) 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:') call assert_fails('call F()', 'E48:')
unlet F unlet F
@@ -1380,7 +1381,7 @@ func Test_func_exists_on_reload()
call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists') call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists')
call assert_equal(0, exists('*ExistingFunction')) call assert_equal(0, exists('*ExistingFunction'))
source Xfuncexists source Xfuncexists
call assert_equal(1, exists('*ExistingFunction')) call assert_equal(1, '*ExistingFunction'->exists())
" Redefining a function when reloading a script is OK. " Redefining a function when reloading a script is OK.
source Xfuncexists source Xfuncexists
call assert_equal(1, exists('*ExistingFunction')) call assert_equal(1, exists('*ExistingFunction'))
@@ -1427,7 +1428,7 @@ func Test_confirm()
" <Esc> requires another character to avoid it being seen as the start of an " <Esc> requires another character to avoid it being seen as the start of an
" escape sequence. Zero should be harmless. " escape sequence. Zero should be harmless.
call feedkeys("\<Esc>0", 'L') eval "\<Esc>0"->feedkeys('L')
let a = confirm('Are you sure?', "&Yes\n&No") let a = confirm('Are you sure?', "&Yes\n&No")
call assert_equal(0, a) call assert_equal(0, a)
@@ -1525,7 +1526,7 @@ func Test_delete_rf()
call writefile([], 'Xdir/[a-1]/foo.txt') call writefile([], 'Xdir/[a-1]/foo.txt')
call writefile([], 'Xdir/[a-1]/bar.txt') call writefile([], 'Xdir/[a-1]/bar.txt')
call assert_true(filereadable('Xdir/foo.txt')) call assert_true(filereadable('Xdir/foo.txt'))
call assert_true(filereadable('Xdir/[a-1]/foo.txt')) call assert_true('Xdir/[a-1]/foo.txt'->filereadable())
call assert_equal(0, delete('Xdir', 'rf')) call assert_equal(0, delete('Xdir', 'rf'))
call assert_false(filereadable('Xdir/foo.txt')) call assert_false(filereadable('Xdir/foo.txt'))

View File

@@ -1303,7 +1303,7 @@ func Test_search_display_pattern()
call cursor(1, 1) call cursor(1, 1)
let @/ = 'foo' let @/ = 'foo'
let pat = escape(@/, '()*?'. '\s\+') let pat = @/->escape('()*?'. '\s\+')
let g:a = execute(':unsilent :norm! n') let g:a = execute(':unsilent :norm! n')
call assert_match(pat, g:a) call assert_match(pat, g:a)

View File

@@ -638,7 +638,7 @@ function! MSG(enr, emsg)
if v:errmsg == "" if v:errmsg == ""
Xout "Message missing." Xout "Message missing."
else else
let v:errmsg = escape(v:errmsg, '"') let v:errmsg = v:errmsg->escape('"')
Xout "Unexpected message:" v:errmsg Xout "Unexpected message:" v:errmsg
endif endif
endif endif

View File

@@ -761,6 +761,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1921,
/**/ /**/
1920, 1920,
/**/ /**/