vim-patch:8.2.2949: tests failing because no error for float to string conversion

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.

3cfa5b16b0

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2023-06-12 12:48:14 +08:00
parent 1ffd20a26e
commit 7abfb1f86e
10 changed files with 34 additions and 29 deletions

View File

@ -1,16 +1,10 @@
-- Tests for signs
local helpers = require('test.functional.helpers')(after_each)
local clear, exc_exec = helpers.clear, helpers.exc_exec
local clear = helpers.clear
local eq, eval = helpers.eq, helpers.eval
describe('glob2regpat()', function()
before_each(clear)
it('handles invalid input', function()
eq('Vim(call):E806: Using a Float as a String',
exc_exec('call glob2regpat(1.33)'))
end)
it('returns ^$ for empty input', function()
eq('^$', eval("glob2regpat('')"))
end)

View File

@ -93,14 +93,10 @@ describe('execute()', function()
it('captures errors', function()
local ret
ret = exc_exec('call execute(0.0)')
eq('Vim(call):E806: Using a Float as a String', ret)
ret = exc_exec('call execute(v:_null_dict)')
eq('Vim(call):E731: Using a Dictionary as a String', ret)
ret = exc_exec('call execute(function("tr"))')
eq('Vim(call):E729: Using a Funcref as a String', ret)
ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])')
eq('Vim:E806: Using a Float as a String', ret)
ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])')
eq('Vim:E731: Using a Dictionary as a String', ret)
ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])')
@ -330,9 +326,6 @@ describe('execute()', function()
it('propagates errors for "" and "silent"', function()
local ret
ret = exc_exec('call execute(0.0, "")')
eq('Vim(call):E806: Using a Float as a String', ret)
ret = exc_exec('call execute(v:_null_dict, "silent")')
eq('Vim(call):E731: Using a Dictionary as a String', ret)

View File

@ -145,8 +145,6 @@ describe('writefile()', function()
pcall_err(command, ('call writefile(%s, "%s", "b")'):format(arg, fname)))
end
for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do
eq('Vim(call):E806: Using a Float as a String',
pcall_err(command, ('call writefile(%s)'):format(args:format('0.0'))))
eq('Vim(call):E730: Using a List as a String',
pcall_err(command, ('call writefile(%s)'):format(args:format('[]'))))
eq('Vim(call):E731: Using a Dictionary as a String',

View File

@ -234,7 +234,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

View File

@ -1,6 +1,8 @@
" test execute()
source view_util.vim
source check.vim
source vim9.vim
func NestedEval()
let nested = execute('echo "nested\nlines"')
@ -31,7 +33,6 @@ func Test_execute_string()
call assert_equal("\nthat", evaled)
call assert_fails('call execute("doesnotexist")', 'E492:')
call assert_fails('call execute(3.4)', 'E806:')
" Nvim supports execute('... :redir ...'), so this test is intentionally
" disabled.
" call assert_fails('call execute("call NestedRedir()")', 'E930:')
@ -40,7 +41,11 @@ func Test_execute_string()
call assert_equal("\nsomething", execute('echo "something"', 'silent'))
call assert_equal("\nsomething", execute('echo "something"', 'silent!'))
call assert_equal("", execute('burp', 'silent!'))
call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:')
if has('float')
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
func Test_execute_list()

View File

@ -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("str2float('nan')", string(str2float('NaN')))
call assert_equal("str2float('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:')

View File

@ -153,11 +153,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
@ -221,7 +223,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
@ -372,7 +376,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

View File

@ -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:')

View File

@ -882,7 +882,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)
@ -1051,9 +1051,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:')
" Nvim doesn't have test_unknown()
" let t = test_unknown()
" call assert_fails("echo t[0]", 'E685:')

View File

@ -2,6 +2,10 @@
" Use a different file name for each run.
let s:sequence = 1
func CheckDefExecFailure(lines, error, lnum = -3)
return
endfunc
func CheckScriptFailure(lines, error, lnum = -3)
if get(a:lines, 0, '') ==# 'vim9script'
return