]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4946: Vim9: some code not covered by tests v8.2.4946
authorBram Moolenaar <Bram@vim.org>
Thu, 12 May 2022 21:03:01 +0000 (22:03 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 12 May 2022 21:03:01 +0000 (22:03 +0100)
Problem:    Vim9: some code not covered by tests.
Solution:   Add a few more test cases.  Remove dead code.

src/testdir/test_vim9_builtin.vim
src/testdir/test_vim9_expr.vim
src/version.c
src/vim9expr.c

index 6fc7d0619c381b7077d7094472bcfd0d3441ab33..318968b9c683b5f4e29659aaabfa30539dbf0cde 100644 (file)
@@ -78,6 +78,7 @@ enddef
 
 def Test_add()
   v9.CheckDefAndScriptFailure(['add({}, 1)'], ['E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1226: List or Blob required for argument 1'])
+  v9.CheckDefAndScriptFailure(['add([])'], 'E119:')
   v9.CheckDefExecFailure([
         'var ln: list<number> = [1]',
         'add(ln, "a")'],
index 9807b6c364c4afb79280e5cfe92cdd3628cdb535..93c6bcd1ffd6913f355fbcb5415c43453b59d83f 100644 (file)
@@ -2151,6 +2151,9 @@ def Test_expr8_string()
   vv = $'other {val}'
   assert_equal('other val', vv)
 
+  v9.CheckDefAndScriptFailure(['var x = $"foo'], 'E114:', 1)
+  v9.CheckDefAndScriptFailure(['var x = $"foo{xxx}"'], ['E1001: Variable not found: xxx', 'E121: Undefined variable: xxx'], 1)
+
   var x = 'x'
   var vl = 'foo xxx bar xxx baz'
               ->split($'x{x}x')
@@ -2818,6 +2821,7 @@ def Test_expr8_dict()
   g:key = 'x'
   v9.CheckDefExecAndScriptFailure(["var x = {[g:key]: 'text', [g:key]: 'text'}"], 'E721:', 1)
   unlet g:key
+  v9.CheckDefExecAndScriptFailure(["var x = {[notexists]: 'text'}"], ['E1001:', 'E121: Undefined variable: notexists'], 1)
   v9.CheckDefExecAndScriptFailure(["var x = g:anint.member"], ['E715:', 'E488:'], 1)
   v9.CheckDefExecAndScriptFailure(["var x = g:dict_empty.member"], 'E716:', 1)
 
@@ -3370,6 +3374,9 @@ def Test_expr8_parens()
       assert_equal('onetwo', s)
   END
   v9.CheckDefAndScriptSuccess(lines)
+
+  v9.CheckDefAndScriptFailure(['echo ('], ['E1097: Line incomplete', 'E15: Invalid expression: "("'])
+  v9.CheckDefAndScriptFailure(['echo (123]'], "E110: Missing ')'", 1)
 enddef
 
 def Test_expr8_negate_add()
@@ -3480,6 +3487,7 @@ def Test_expr8_call()
        "var x = substitute ('x', 'x', 'x', 'x')"
        ], ['E1001:', 'E121:'], 1)
   v9.CheckDefAndScriptFailure(["var Ref = function('len' [1, 2])"], ['E1123:', 'E116:'], 1)
+  v9.CheckDefAndScriptFailure(["echo match(['foo'] , 'foo')"], 'E1068:', 1)
 enddef
 
 def g:ExistingGlobal(): string
@@ -4000,6 +4008,16 @@ def Test_expr8_blob_subscript()
   v9.CheckDefAndScriptSuccess(lines)
 enddef
 
+def Test_expr8_funcref_subscript()
+  var lines =<< trim END
+      var l = function('len')("abc")
+      assert_equal(3, l)
+  END
+  v9.CheckDefAndScriptSuccess(lines)
+
+  v9.CheckDefAndScriptFailure(["var l = function('len')(xxx)"], ['E1001: Variable not found: xxx', 'E121: Undefined variable: xxx'], 1)
+enddef
+
 def Test_expr8_subscript_linebreak()
   var lines =<< trim END
       var range = range(
index 45f0f28601ba2e10d956debec0f022e8e2d81f6b..e63e6b13942d7b480a726e2b7cf887c7edbc26c3 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4946,
 /**/
     4945,
 /**/
index a200a87951a6e86726d59691b967a343d1b5065c..6fb6fc4d2d1f16e754398b3455c6e3ee29fdd03f 100644 (file)
@@ -1122,7 +1122,7 @@ get_lambda_tv_and_compile(
     r = get_lambda_tv(arg, rettv, types_optional, evalarg);
     current_sctx.sc_version = save_sc_version;
     if (r != OK)
-       return r;
+       return r;  // currently unreachable
 
     // "rettv" will now be a partial referencing the function.
     ufunc = rettv->vval.v_partial->pt_func;
@@ -1682,12 +1682,6 @@ compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end)
                                            -1, 0, cctx, FALSE, FALSE) == FAIL)
                return FAIL;
 
-           while (p > start && (p[-1] == '-' || p[-1] == '+'))
-           {
-               --p;
-               if (*p == '-')
-                   negate = !negate;
-           }
            // only '-' has an effect, for '+' we only check the type
            if (negate)
            {