Commit: patch 9.1.0419: eval.c not sufficiently tested

4 views
Skip to first unread message

Christian Brabandt

unread,
May 19, 2024, 3:15:15 AM5/19/24
to vim...@googlegroups.com
patch 9.1.0419: eval.c not sufficiently tested

Commit: https://github.com/vim/vim/commit/4776e64e72de2976ff90b17d236e50e2b02c5540
Author: Yegappan Lakshmanan <yega...@yahoo.com>
Date: Sun May 19 09:06:50 2024 +0200

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 <yega...@yahoo.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/eval.c b/src/eval.c
index 322b45aae..8cc6ed1ed 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2979,7 +2979,7 @@ newline_skip_comments(char_u *arg)
char_u *nl = vim_strchr(p, NL);

if (nl == NULL)
- break;
+ break;
p = nl;
}
if (*p != NL)
@@ -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;
diff --git a/src/testdir/test_autoload.vim b/src/testdir/test_autoload.vim
index 835b81e27..d0f913660 100644
--- a/src/testdir/test_autoload.vim
+++ b/src/testdir/test_autoload.vim
@@ -26,5 +26,4 @@ func Test_autoload_vim9script()
call assert_equal(49, auto9#Add42(7))
endfunc

-
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim
index 7184142a4..871d427bf 100644
--- a/src/testdir/test_fold.vim
+++ b/src/testdir/test_fold.vim
@@ -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()
diff --git a/src/testdir/test_spellrare.vim b/src/testdir/test_spellrare.vim
index bbb13c27c..ceb35cbd1 100644
--- a/src/testdir/test_spellrare.vim
+++ b/src/testdir/test_spellrare.vim
@@ -11,15 +11,15 @@ func Test_spellrareword()
" Create a small word list to test that spellbadword('...')
" can return ['...', 'rare'].
let lines =<< trim END
- foo
- foobar/?
- foobara/?
-END
- call writefile(lines, 'Xwords', 'D')
-
- mkspell! Xwords.spl Xwords
- set spelllang=Xwords.spl
- call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))
+ foo
+ foobar/?
+ foobara/?
+ END
+ call writefile(lines, 'Xwords', 'D')
+
+ mkspell! Xwords.spl Xwords
+ set spelllang=Xwords.spl
+ call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))

new
call setline(1, ['foo', '', 'foo bar foo bar foobara foo foo foo foobar', '', 'End'])
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
index 7c2bbb476..cf2c73fb9 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -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
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index ba3b76a18..3200b7335 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -960,6 +960,8 @@ def Test_execute()
assert_equal("
hello", res)
res = execute(["echo 'here'", "echo 'there'"])
assert_equal("
here
there", res)
+ res = execute("echo 'hi'
# foo")
+ assert_equal("
hi", 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>')
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 523728ccc..57347318e 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -2118,6 +2118,12 @@ def Test_expr9_number()
Test()
END
v9.CheckDefAndScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ eval("10
")
+ END
+ v9.CheckSourceScriptFailure(lines, "E488: Trailing characters:
")
enddef

def Test_expr9_float()
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index f07c4c99a..a640fce9b 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -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)

diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim
index c13530439..897677957 100644
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index ad3b585cd..34f474da4 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 419,
/**/
418,
/**/
Reply all
Reply to author
Forward
0 new messages