0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.1.0419: eval.c not sufficiently tested

Problem:  eval.c not sufficiently tested
Solution: Add a few more additional tests for eval.c,
          (Yegappan Lakshmanan)

closes: #14799

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2024-05-19 09:06:50 +02:00
committed by Christian Brabandt
parent 5f75714730
commit 4776e64e72
10 changed files with 76 additions and 15 deletions

View File

@@ -4509,18 +4509,21 @@ handle_predefined(char_u *s, int len, typval_T *rettv)
case 9:
if (STRNCMP(s, "null_", 5) != 0)
break;
// null_list
if (STRNCMP(s + 5, "list", 4) == 0)
{
rettv->v_type = VAR_LIST;
rettv->vval.v_list = NULL;
return OK;
}
// null_dict
if (STRNCMP(s + 5, "dict", 4) == 0)
{
rettv->v_type = VAR_DICT;
rettv->vval.v_dict = NULL;
return OK;
}
// null_blob
if (STRNCMP(s + 5, "blob", 4) == 0)
{
rettv->v_type = VAR_BLOB;

View File

@@ -26,5 +26,4 @@ func Test_autoload_vim9script()
call assert_equal(49, auto9#Add42(7))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -1629,6 +1629,35 @@ func Test_foldtext_in_modeline()
delfunc ModelineFoldText
endfunc
" Test for setting 'foldexpr' from the modeline and executing the expression
" in a sandbox
func Test_foldexpr_in_modeline()
func ModelineFoldExpr()
call feedkeys('aFoo', 'xt')
return strlen(matchstr(getline(v:lnum),'^\s*'))
endfunc
let lines =<< trim END
aaa
bbb
ccc
ccc
bbb
aaa
" vim: foldenable foldmethod=expr foldexpr=ModelineFoldExpr()
END
call writefile(lines, 'Xmodelinefoldexpr', 'D')
set modeline modelineexpr
split Xmodelinefoldexpr
call assert_equal(2, foldlevel(3))
call assert_equal(lines, getbufline('', 1, '$'))
bw!
set modeline& modelineexpr&
delfunc ModelineFoldExpr
endfunc
" Make sure a fold containing a nested fold is split correctly when using
" foldmethod=indent
func Test_fold_split()

View File

@@ -1498,4 +1498,18 @@ func Test_substitute_expr_recursive()
exe bufnr .. "bw!"
endfunc
" Test for changing 'cpo' in a substitute expression
func Test_substitute_expr_cpo()
func XSubExpr()
set cpo=
return 'x'
endfunc
let save_cpo = &cpo
call assert_equal('xxx', substitute('abc', '.', '\=XSubExpr()', 'g'))
call assert_equal(save_cpo, &cpo)
delfunc XSubExpr
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -960,6 +960,8 @@ def Test_execute()
assert_equal("\nhello", res)
res = execute(["echo 'here'", "echo 'there'"])
assert_equal("\nhere\nthere", res)
res = execute("echo 'hi'\n# foo")
assert_equal("\nhi", res)
v9.CheckSourceDefAndScriptFailure(['execute(123)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1222: String or List required for argument 1'])
v9.CheckSourceDefFailure(['execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')

View File

@@ -2118,6 +2118,12 @@ def Test_expr9_number()
Test()
END
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
vim9script
eval("10\n")
END
v9.CheckSourceScriptFailure(lines, "E488: Trailing characters: \n")
enddef
def Test_expr9_float()

View File

@@ -2510,6 +2510,11 @@ def Test_for_loop()
reslist->add('x')
endfor
assert_equal(['x', 'x', 'x'], reslist)
# Test for trying to use the loop variable "_" inside the loop
for _ in "a"
assert_fails('echo _', 'E1181: Cannot use an underscore here')
endfor
END
v9.CheckDefAndScriptSuccess(lines)

View File

@@ -7510,12 +7510,13 @@ func Test_for_over_string()
endfor
call assert_equal('', res)
" Test for ignoring loop var assignment
let c = 0
for _ in 'abc'
let c += 1
" Test for using "_" as the loop variable
let i = 0
let s = 'abc'
for _ in s
call assert_equal(s[i], _)
let i += 1
endfor
call assert_equal(3, c)
endfunc
" Test for deeply nested :source command {{{1

View File

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