summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-06 14:14:39 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-06 14:14:39 +0200
commit3cfa5b16b06bcc034f6de77070fa779d698ab5e9 (patch)
tree1791529efb117bb1e68814a35dbe9f6d5a8bca0f
parent7a2217bedd223df4c8bbebe731bf0b5fe8532533 (diff)
downloadvim-git-3cfa5b16b06bcc034f6de77070fa779d698ab5e9.tar.gz
patch 8.2.2949: tests failing because no error for float to string conversionv8.2.2949
Problem: Tests failing because there is no error for float to string conversion. Solution: Change the check for failure to check for correct result. Make some conversions strict in Vim9 script.
-rw-r--r--src/evalfunc.c5
-rw-r--r--src/filepath.c4
-rw-r--r--src/findfile.c2
-rw-r--r--src/float.c2
-rw-r--r--src/json.c11
-rw-r--r--src/testdir/test_eval_stuff.vim2
-rw-r--r--src/testdir/test_execute_func.vim6
-rw-r--r--src/testdir/test_float_func.vim5
-rw-r--r--src/testdir/test_functions.vim15
-rw-r--r--src/testdir/test_glob2regpat.vim5
-rw-r--r--src/testdir/test_listdict.vim6
-rw-r--r--src/version.c2
12 files changed, 46 insertions, 19 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 1962ccd15..07f158d6d 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -3000,7 +3000,8 @@ execute_common(typval_T *argvars, typval_T *rettv, int arg_off)
if (argvars[arg_off + 1].v_type != VAR_UNKNOWN)
{
char_u buf[NUMBUFLEN];
- char_u *s = tv_get_string_buf_chk(&argvars[arg_off + 1], buf);
+ char_u *s = tv_get_string_buf_chk_strict(&argvars[arg_off + 1], buf,
+ in_vim9script());
if (s == NULL)
return;
@@ -8897,7 +8898,7 @@ f_strdisplaywidth(typval_T *argvars, typval_T *rettv)
static void
f_strwidth(typval_T *argvars, typval_T *rettv)
{
- char_u *s = tv_get_string(&argvars[0]);
+ char_u *s = tv_get_string_strict(&argvars[0]);
rettv->vval.v_number = (varnumber_T)(mb_string2cells(s, -1));
}
diff --git a/src/filepath.c b/src/filepath.c
index e81eeb120..69bc8b5f4 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -1301,7 +1301,9 @@ f_glob(typval_T *argvars, typval_T *rettv)
void
f_glob2regpat(typval_T *argvars, typval_T *rettv)
{
- char_u *pat = tv_get_string_chk(&argvars[0]);
+ char_u buf[NUMBUFLEN];
+ char_u *pat = tv_get_string_buf_chk_strict(&argvars[0], buf,
+ in_vim9script());
rettv->v_type = VAR_STRING;
rettv->vval.v_string = (pat == NULL)
diff --git a/src/findfile.c b/src/findfile.c
index 4f69c47ca..a72fe45ad 100644
--- a/src/findfile.c
+++ b/src/findfile.c
@@ -2848,7 +2848,7 @@ f_simplify(typval_T *argvars, typval_T *rettv)
{
char_u *p;
- p = tv_get_string(&argvars[0]);
+ p = tv_get_string_strict(&argvars[0]);
rettv->vval.v_string = vim_strsave(p);
simplify_filename(rettv->vval.v_string); // simplify in place
rettv->v_type = VAR_STRING;
diff --git a/src/float.c b/src/float.c
index 1361a36d5..7c020448a 100644
--- a/src/float.c
+++ b/src/float.c
@@ -417,7 +417,7 @@ f_sqrt(typval_T *argvars, typval_T *rettv)
void
f_str2float(typval_T *argvars, typval_T *rettv)
{
- char_u *p = skipwhite(tv_get_string(&argvars[0]));
+ char_u *p = skipwhite(tv_get_string_strict(&argvars[0]));
int isneg = (*p == '-');
if (*p == '+' || *p == '-')
diff --git a/src/json.c b/src/json.c
index db25b70cc..d0a087a92 100644
--- a/src/json.c
+++ b/src/json.c
@@ -607,7 +607,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
cur_item = res;
init_tv(&item);
if (res != NULL)
- init_tv(res);
+ init_tv(res);
fill_numbuflen(reader);
p = reader->js_buf + reader->js_used;
@@ -920,6 +920,15 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
if (top_item != NULL && top_item->jd_type == JSON_OBJECT_KEY
&& cur_item != NULL)
{
+#ifdef FEAT_FLOAT
+ if (cur_item->v_type == VAR_FLOAT)
+ {
+ // cannot use a float as a key
+ emsg(_(e_float_as_string));
+ retval = FAIL;
+ goto theend;
+ }
+#endif
top_item->jd_key = tv_get_string_buf_chk(cur_item, key_buf);
if (top_item->jd_key == NULL)
{
diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim
index 4549f4860..0c1e75df5 100644
--- a/src/testdir/test_eval_stuff.vim
+++ b/src/testdir/test_eval_stuff.vim
@@ -144,7 +144,7 @@ func Test_string_concatenation()
if has('float')
let a = 'A'
let b = 1.234
- call assert_fails('echo a .. b', 'E806:')
+ call assert_equal('A1.234', a .. b)
endif
endfunc
diff --git a/src/testdir/test_execute_func.vim b/src/testdir/test_execute_func.vim
index 036371715..c08b2390f 100644
--- a/src/testdir/test_execute_func.vim
+++ b/src/testdir/test_execute_func.vim
@@ -2,6 +2,7 @@
source view_util.vim
source check.vim
+source vim9.vim
func NestedEval()
let nested = execute('echo "nested\nlines"')
@@ -37,8 +38,9 @@ func Test_execute_string()
call assert_equal("\nsomething", execute('echo "something"', 'silent!'))
call assert_equal("", execute('burp', 'silent!'))
if has('float')
- call assert_fails('call execute(3.4)', 'E806:')
- call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:')
+ call assert_fails('call execute(3.4)', 'E492:')
+ call assert_equal("\nx", execute("echo \"x\"", 3.4))
+ call CheckDefExecAndScriptFailure(['execute("echo \"x\"", 3.4)'], 'E806:')
endif
endfunc
diff --git a/src/testdir/test_float_func.vim b/src/testdir/test_float_func.vim
index 17b5cdac9..b10bffd72 100644
--- a/src/testdir/test_float_func.vim
+++ b/src/testdir/test_float_func.vim
@@ -2,6 +2,7 @@
source check.vim
CheckFeature float
+source vim9.vim
func Test_abs()
call assert_equal('1.23', string(abs(1.23)))
@@ -238,7 +239,9 @@ func Test_str2float()
call assert_equal('nan', string(str2float('NaN')))
call assert_equal('nan', string(str2float(' nan ')))
- call assert_fails("call str2float(1.2)", 'E806:')
+ call assert_equal(1.2, str2float(1.2))
+ call CheckDefExecFailure(['str2float(1.2)'], 'E1013:')
+ call CheckScriptFailure(['vim9script', 'str2float(1.2)'], 'E806:')
call assert_fails("call str2float([])", 'E730:')
call assert_fails("call str2float({})", 'E731:')
call assert_fails("call str2float(function('string'))", 'E729:')
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index bc9649172..023da66ba 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -165,11 +165,13 @@ func Test_strwidth()
call assert_fails('call strwidth({->0})', 'E729:')
call assert_fails('call strwidth([])', 'E730:')
call assert_fails('call strwidth({})', 'E731:')
- if has('float')
- call assert_fails('call strwidth(1.2)', 'E806:')
- endif
endfor
+ if has('float')
+ call assert_equal(3, strwidth(1.2))
+ call CheckDefExecAndScriptFailure(['echo strwidth(1.2)'], 'E806:')
+ endif
+
set ambiwidth&
endfunc
@@ -233,7 +235,9 @@ func Test_str2nr()
call assert_fails('call str2nr([])', 'E730:')
call assert_fails('call str2nr({->2})', 'E729:')
if has('float')
- call assert_fails('call str2nr(1.2)', 'E806:')
+ call assert_equal(1, str2nr(1.2))
+ call CheckDefExecFailure(['echo str2nr(1.2)'], 'E1013:')
+ call CheckScriptFailure(['vim9script', 'echo str2nr(1.2)'], 'E806:')
endif
call assert_fails('call str2nr(10, [])', 'E745:')
endfunc
@@ -494,7 +498,8 @@ func Test_simplify()
call assert_fails('call simplify([])', 'E730:')
call assert_fails('call simplify({})', 'E731:')
if has('float')
- call assert_fails('call simplify(1.2)', 'E806:')
+ call assert_equal('1.2', simplify(1.2))
+ call CheckDefExecAndScriptFailure(['echo simplify(1.2)'], 'E806:')
endif
endfunc
diff --git a/src/testdir/test_glob2regpat.vim b/src/testdir/test_glob2regpat.vim
index 2907b286d..ab459bba3 100644
--- a/src/testdir/test_glob2regpat.vim
+++ b/src/testdir/test_glob2regpat.vim
@@ -1,8 +1,11 @@
" Test glob2regpat()
+source vim9.vim
+
func Test_glob2regpat_invalid()
if has('float')
- call assert_fails('call glob2regpat(1.33)', 'E806:')
+ call assert_equal('^1\.33$', glob2regpat(1.33))
+ call CheckDefExecAndScriptFailure(['echo glob2regpat(1.33)'], 'E806:')
endif
call assert_fails('call glob2regpat("}")', 'E219:')
call assert_fails('call glob2regpat("{")', 'E220:')
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim
index 46b030b86..8351acb41 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -859,7 +859,7 @@ func Test_listdict_extend()
call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'error')", 'E737:')
call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'xxx')", 'E475:')
if has('float')
- call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 1.2)", 'E806:')
+ call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 1.2)", 'E475:')
endif
call assert_equal({'a': 'A', 'b': 'B'}, d)
@@ -1022,9 +1022,9 @@ func Test_listdict_index()
call assert_fails("let l = insert([1,2,3], 4, [])", 'E745:')
let l = [1, 2, 3]
call assert_fails("let l[i] = 3", 'E121:')
- call assert_fails("let l[1.1] = 4", 'E806:')
+ call assert_fails("let l[1.1] = 4", 'E805:')
call assert_fails("let l[:i] = [4, 5]", 'E121:')
- call assert_fails("let l[:3.2] = [4, 5]", 'E806:')
+ call assert_fails("let l[:3.2] = [4, 5]", 'E805:')
let t = test_unknown()
call assert_fails("echo t[0]", 'E685:')
endfunc
diff --git a/src/version.c b/src/version.c
index b9df68801..94a4cfb23 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2949,
+/**/
2948,
/**/
2947,