mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.0188: Check commands don't work well with Vim9 script
Problem: Check commands don't work well with Vim9 script. Solution: Improve constant expression handling.
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
source shared.vim
|
source shared.vim
|
||||||
|
|
||||||
|
command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing'
|
||||||
|
|
||||||
" Command to check for the presence of a feature.
|
" Command to check for the presence of a feature.
|
||||||
command -nargs=1 CheckFeature call CheckFeature(<f-args>)
|
command -nargs=1 CheckFeature call CheckFeature(<f-args>)
|
||||||
func CheckFeature(name)
|
func CheckFeature(name)
|
||||||
if !has(a:name)
|
if !has(a:name)
|
||||||
throw 'Skipped: ' .. a:name .. ' feature missing'
|
MissingFeature a:name
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -31,7 +31,9 @@ def Test_expr1()
|
|||||||
|
|
||||||
assert_equal('two', false ? 'one' : 'two')
|
assert_equal('two', false ? 'one' : 'two')
|
||||||
assert_equal('two', 0 ? 'one' : 'two')
|
assert_equal('two', 0 ? 'one' : 'two')
|
||||||
|
if has('float')
|
||||||
assert_equal('two', 0.0 ? 'one' : 'two')
|
assert_equal('two', 0.0 ? 'one' : 'two')
|
||||||
|
endif
|
||||||
assert_equal('two', '' ? 'one' : 'two')
|
assert_equal('two', '' ? 'one' : 'two')
|
||||||
" assert_equal('one', 0z ? 'one' : 'two')
|
" assert_equal('one', 0z ? 'one' : 'two')
|
||||||
assert_equal('two', [] ? 'one' : 'two')
|
assert_equal('two', [] ? 'one' : 'two')
|
||||||
@@ -420,7 +422,9 @@ def Test_expr5()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr5_float()
|
def Test_expr5_float()
|
||||||
CheckFeature float
|
if !has('float')
|
||||||
|
MissingFeature 'float'
|
||||||
|
else
|
||||||
assert_equal(66.0, 60.0 + 6.0)
|
assert_equal(66.0, 60.0 + 6.0)
|
||||||
assert_equal(66.0, 60.0 + 6)
|
assert_equal(66.0, 60.0 + 6)
|
||||||
assert_equal(66.0, 60 + 6.0)
|
assert_equal(66.0, 60 + 6.0)
|
||||||
@@ -436,6 +440,7 @@ def Test_expr5_float()
|
|||||||
assert_equal(7.9, 8 - g:afloat)
|
assert_equal(7.9, 8 - g:afloat)
|
||||||
assert_equal(9.9, g:anint - g:afloat)
|
assert_equal(9.9, g:anint - g:afloat)
|
||||||
assert_equal(-9.9, g:afloat - g:anint)
|
assert_equal(-9.9, g:afloat - g:anint)
|
||||||
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
func Test_expr5_fails()
|
func Test_expr5_fails()
|
||||||
@@ -476,8 +481,9 @@ def Test_expr6()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr6_float()
|
def Test_expr6_float()
|
||||||
CheckFeature float
|
if !has('float')
|
||||||
|
MissingFeature 'float'
|
||||||
|
else
|
||||||
assert_equal(36.0, 6.0 * 6)
|
assert_equal(36.0, 6.0 * 6)
|
||||||
assert_equal(36.0, 6 * 6.0)
|
assert_equal(36.0, 6 * 6.0)
|
||||||
assert_equal(36.0, 6.0 * 6.0)
|
assert_equal(36.0, 6.0 * 6.0)
|
||||||
@@ -497,6 +503,7 @@ def Test_expr6_float()
|
|||||||
assert_equal(4.0, 6.0 * 4.0 / 6.0)
|
assert_equal(4.0, 6.0 * 4.0 / 6.0)
|
||||||
|
|
||||||
assert_equal(4.0, 6.0 * 4.0 / 6.0)
|
assert_equal(4.0, 6.0 * 4.0 / 6.0)
|
||||||
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
func Test_expr6_fails()
|
func Test_expr6_fails()
|
||||||
@@ -581,7 +588,9 @@ enddef
|
|||||||
|
|
||||||
def Test_expr7_float()
|
def Test_expr7_float()
|
||||||
" float constant
|
" float constant
|
||||||
if has('float')
|
if !has('float')
|
||||||
|
MissingFeature 'float'
|
||||||
|
else
|
||||||
assert_equal(g:float_zero, .0)
|
assert_equal(g:float_zero, .0)
|
||||||
assert_equal(g:float_zero, 0.0)
|
assert_equal(g:float_zero, 0.0)
|
||||||
assert_equal(g:float_neg, -9.8)
|
assert_equal(g:float_neg, -9.8)
|
||||||
|
@@ -742,6 +742,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 */
|
||||||
|
/**/
|
||||||
|
188,
|
||||||
/**/
|
/**/
|
||||||
187,
|
187,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -3460,14 +3460,31 @@ new_scope(cctx_T *cctx, scopetype_T type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Evaluate an expression that is a constant: has(arg)
|
* Evaluate an expression that is a constant:
|
||||||
|
* has(arg)
|
||||||
|
*
|
||||||
|
* Also handle:
|
||||||
|
* ! in front logical NOT
|
||||||
|
*
|
||||||
* Return FAIL if the expression is not a constant.
|
* Return FAIL if the expression is not a constant.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
evaluate_const_expr4(char_u **arg, cctx_T *cctx UNUSED, typval_T *tv)
|
evaluate_const_expr7(char_u **arg, cctx_T *cctx UNUSED, typval_T *tv)
|
||||||
{
|
{
|
||||||
typval_T argvars[2];
|
typval_T argvars[2];
|
||||||
|
char_u *start_leader, *end_leader;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip '!' characters. They are handled later.
|
||||||
|
*/
|
||||||
|
start_leader = *arg;
|
||||||
|
while (**arg == '!')
|
||||||
|
*arg = skipwhite(*arg + 1);
|
||||||
|
end_leader = *arg;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Recognize only has() for now.
|
||||||
|
*/
|
||||||
if (STRNCMP("has(", *arg, 4) != 0)
|
if (STRNCMP("has(", *arg, 4) != 0)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
*arg = skipwhite(*arg + 4);
|
*arg = skipwhite(*arg + 4);
|
||||||
@@ -3497,6 +3514,13 @@ evaluate_const_expr4(char_u **arg, cctx_T *cctx UNUSED, typval_T *tv)
|
|||||||
f_has(argvars, tv);
|
f_has(argvars, tv);
|
||||||
clear_tv(&argvars[0]);
|
clear_tv(&argvars[0]);
|
||||||
|
|
||||||
|
while (start_leader < end_leader)
|
||||||
|
{
|
||||||
|
if (*start_leader == '!')
|
||||||
|
tv->vval.v_number = !tv->vval.v_number;
|
||||||
|
++start_leader;
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3529,7 +3553,7 @@ evaluate_const_and_or(char_u **arg, cctx_T *cctx, char *op, typval_T *tv)
|
|||||||
*arg = skipwhite(p + 2);
|
*arg = skipwhite(p + 2);
|
||||||
tv2.v_type = VAR_UNKNOWN;
|
tv2.v_type = VAR_UNKNOWN;
|
||||||
if ((opchar == '|' ? evaluate_const_expr3(arg, cctx, &tv2)
|
if ((opchar == '|' ? evaluate_const_expr3(arg, cctx, &tv2)
|
||||||
: evaluate_const_expr4(arg, cctx, &tv2)) == FAIL)
|
: evaluate_const_expr7(arg, cctx, &tv2)) == FAIL)
|
||||||
{
|
{
|
||||||
clear_tv(&tv2);
|
clear_tv(&tv2);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@@ -3558,7 +3582,7 @@ evaluate_const_and_or(char_u **arg, cctx_T *cctx, char *op, typval_T *tv)
|
|||||||
evaluate_const_expr3(char_u **arg, cctx_T *cctx, typval_T *tv)
|
evaluate_const_expr3(char_u **arg, cctx_T *cctx, typval_T *tv)
|
||||||
{
|
{
|
||||||
// evaluate the first expression
|
// evaluate the first expression
|
||||||
if (evaluate_const_expr4(arg, cctx, tv) == FAIL)
|
if (evaluate_const_expr7(arg, cctx, tv) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
// || and && work almost the same
|
// || and && work almost the same
|
||||||
|
Reference in New Issue
Block a user