mirror of
https://github.com/neovim/neovim.git
synced 2026-02-20 09:19:43 +10:00
vim-patch:8.1.0112: no error when using bad arguments with searchpair()
Problem: No error when using bad arguments with searchpair().
Solution: Add error messages.
3dddb09c98
This commit is contained in:
@@ -14527,7 +14527,8 @@ static int searchpair_cmn(typval_T *argvars, pos_T *match_pos)
|
||||
long lnum_stop = 0;
|
||||
long time_limit = 0;
|
||||
|
||||
// Get the three pattern arguments: start, middle, end.
|
||||
// Get the three pattern arguments: start, middle, end. Will result in an
|
||||
// error if not a valid argument.
|
||||
char nbuf1[NUMBUFLEN];
|
||||
char nbuf2[NUMBUFLEN];
|
||||
const char *spat = tv_get_string_chk(&argvars[0]);
|
||||
@@ -14566,16 +14567,19 @@ static int searchpair_cmn(typval_T *argvars, pos_T *match_pos)
|
||||
if (skip->v_type != VAR_FUNC
|
||||
&& skip->v_type != VAR_PARTIAL
|
||||
&& skip->v_type != VAR_STRING) {
|
||||
emsgf(_(e_invarg2), tv_get_string(&argvars[4]));
|
||||
goto theend; // Type error.
|
||||
}
|
||||
if (argvars[5].v_type != VAR_UNKNOWN) {
|
||||
lnum_stop = tv_get_number_chk(&argvars[5], NULL);
|
||||
if (lnum_stop < 0) {
|
||||
emsgf(_(e_invarg2), tv_get_string(&argvars[5]));
|
||||
goto theend;
|
||||
}
|
||||
if (argvars[6].v_type != VAR_UNKNOWN) {
|
||||
time_limit = tv_get_number_chk(&argvars[6], NULL);
|
||||
if (time_limit < 0) {
|
||||
emsgf(_(e_invarg2), tv_get_string(&argvars[6]));
|
||||
goto theend;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,16 +288,26 @@ func Test_searchpair()
|
||||
new
|
||||
call setline(1, ['other code here', '', '[', '" cursor here', ']'])
|
||||
4
|
||||
let a=searchpair('\[','',']','bW')
|
||||
let a = searchpair('\[','',']','bW')
|
||||
call assert_equal(3, a)
|
||||
set nomagic
|
||||
4
|
||||
let a=searchpair('\[','',']','bW')
|
||||
let a = searchpair('\[','',']','bW')
|
||||
call assert_equal(3, a)
|
||||
set magic
|
||||
q!
|
||||
endfunc
|
||||
|
||||
func Test_searchpair_errors()
|
||||
call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String')
|
||||
call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String')
|
||||
call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String')
|
||||
call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags')
|
||||
call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 0, 99, 100)", 'E475: Invalid argument: 0')
|
||||
call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99')
|
||||
call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100')
|
||||
endfunc
|
||||
|
||||
func Test_searchpair_skip()
|
||||
func Zero()
|
||||
return 0
|
||||
@@ -312,8 +322,6 @@ func Test_searchpair_skip()
|
||||
3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0}))
|
||||
3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero')))
|
||||
3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0])))
|
||||
" invalid argument
|
||||
3 | call assert_equal(0, searchpair('{', '', '}', 'bWn', 0))
|
||||
bw!
|
||||
endfunc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user