]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0419: eval.c not sufficiently tested v9.1.0419
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 19 May 2024 07:06:50 +0000 (09:06 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 19 May 2024 07:06:50 +0000 (09:06 +0200)
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>
src/eval.c
src/testdir/test_autoload.vim
src/testdir/test_fold.vim
src/testdir/test_spellrare.vim
src/testdir/test_substitute.vim
src/testdir/test_vim9_builtin.vim
src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_script.vim
src/testdir/test_vimscript.vim
src/version.c

index 322b45aaefdcd0bceb4ac3d43679d81f9eb245a6..8cc6ed1ed51225791200c772da08f3d732d683b8 100644 (file)
@@ -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;
index 835b81e27ef52d219b15055b0f3b5c11434107de..d0f913660efaf6faca61edfa94c57b68fad227b1 100644 (file)
@@ -26,5 +26,4 @@ func Test_autoload_vim9script()
   call assert_equal(49, auto9#Add42(7))
 endfunc
 
-
 " vim: shiftwidth=2 sts=2 expandtab
index 7184142a44679c3e1e37db86874a6851c40f0a3e..871d427bf2905b0e41ef328838138da4a39fc251 100644 (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()
index bbb13c27c2d8a762c55f90820a3178f2a2e16244..ceb35cbd17dd7962a7880078d1aaaf54e55363a6 100644 (file)
@@ -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'])
index 7c2bbb4767705d74ea0059d85b9c936dd400c879..cf2c73fb954aff0156a4fa0a4a5dc7dc8943ba5e 100644 (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
index ba3b76a18f4ea26c0f8e1e3d750ba12a53a4c519..3200b73358bfe5f19fc7f89ec534f6933b24ce6a 100644 (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>')
index 523728ccc26e7c5cea5d0e8ee1a9b6fc1c1d6a0e..57347318e0ec2b8955e1b6cf163e7d9ebb0af257 100644 (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()
index f07c4c99a482459e452dda59d210aa6de9caf0f8..a640fce9bd4de53ed2a88eb6319f51b0dca6e17f 100644 (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)
 
index c13530439efb3867537e04767a710a6ba03a94ac..897677957a5aa328565e677944d15ae4a2df515c 100644 (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
index ad3b585cdc0e16fb9580f334413b9225fe30c603..34f474da4d644f8d908a06630c9654cf7a4c2624 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    419,
 /**/
     418,
 /**/