]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.3202: Vim9: tests are only executed for legacy script v8.2.3202
authorBram Moolenaar <Bram@vim.org>
Thu, 22 Jul 2021 16:48:53 +0000 (18:48 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 22 Jul 2021 16:48:53 +0000 (18:48 +0200)
Problem:    Vim9: tests are only executed for legacy script.
Solution:   Run more tests also for Vim9 script.  Fix uncovered problems.

src/ex_docmd.c
src/testdir/test_listdict.vim
src/version.c
src/vim9execute.c

index c1d0295f4c1469ca0900815016ed8d639884eb34..2f1fdb6045ec53bc8a5585bddd30d1a2531ed9dd 100644 (file)
@@ -3451,7 +3451,8 @@ find_ex_command(
                            // "varname[]" is an expression.
                            *p == '['
                            // "varname.key" is an expression.
-                        || (*p == '.' && ASCII_ISALPHA(p[1]))))
+                        || (*p == '.' && (ASCII_ISALPHA(p[1])
+                                                            || p[1] == '_'))))
            {
                char_u  *after = eap->cmd;
 
index 32e376899b0b75451f410eddff6521fe42f788f3..370b5c7f294adf15eef0c045e3f462352c37dc1b 100644 (file)
@@ -109,10 +109,17 @@ func Test_list_unlet()
   unlet l[2:3]
   call assert_equal([0, 1], l)
 
-  let l = [0, 1, 2, 3]
-  call assert_fails('unlet l[2:1]', 'E684:')
-  let l = [0, 1, 2, 3]
-  call assert_fails('unlet l[-1:2]', 'E684:')
+  let lines =<< trim END
+      VAR l = [0, 1, 2, 3]
+      unlet l[2 : 1]
+  END
+  call CheckLegacyAndVim9Failure(lines, 'E684:')
+
+  let lines =<< trim END
+      VAR l = [0, 1, 2, 3]
+      unlet l[-1 : 2]
+  END
+  call CheckLegacyAndVim9Failure(lines, 'E684:')
 endfunc
 
 " assignment to a list
@@ -126,9 +133,33 @@ func Test_list_assign()
   END
   call CheckLegacyAndVim9Success(lines)
 
-  let l = [0, 1, 2, 3]
-  call assert_fails('let [va, vb] = l', 'E687:')
-  call assert_fails('let [va, vb] = l[1:1]', 'E688:')
+  let lines =<< trim END
+      let l = [0, 1, 2, 3]
+      let [va, vb] = l
+  END
+  call CheckScriptFailure(lines, 'E687:')
+  let lines =<< trim END
+      var l = [0, 1, 2, 3]
+      var va = 0
+      var vb = 0
+      [va, vb] = l
+  END
+  call CheckScriptFailure(['vim9script'] + lines, 'E687:')
+  call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 4')
+
+  let lines =<< trim END
+      let l = [0, 1, 2, 3]
+      let [va, vb] = l[1:1]
+  END
+  call CheckScriptFailure(lines, 'E688:')
+  let lines =<< trim END
+      var l = [0, 1, 2, 3]
+      var va = 0
+      var vb = 0
+      [va, vb] = l[1 : 1]
+  END
+  call CheckScriptFailure(['vim9script'] + lines, 'E688:')
+  call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
 endfunc
 
 " test for range assign
@@ -248,23 +279,29 @@ let s:dict_with_spaces_lit = #{one : 1 , two : 2 , three : 3}
 
 " Dictionary identity
 func Test_dict_identity()
-  let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
-  let dd = d
-  let dx = copy(d)
-  call assert_true(d == dd)
-  call assert_false(d isnot dd)
-  call assert_true(d is dd)
-  call assert_true(d == dx)
-  call assert_false(d is dx)
-  call assert_true(d isnot dx)
+  let lines =<< trim END
+      VAR d = {'1': 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1}, }
+      VAR dd = d
+      VAR dx = copy(d)
+      call assert_true(d == dd)
+      call assert_false(d isnot dd)
+      call assert_true(d is dd)
+      call assert_true(d == dx)
+      call assert_false(d is dx)
+      call assert_true(d isnot dx)
+  END
+  call CheckLegacyAndVim9Success(lines)
 endfunc
 
 " removing items with :unlet
 func Test_dict_unlet()
-  let d = {'b':'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
-  unlet d.b
-  unlet d[-1]
-  call assert_equal({'1': 99, '3': 33}, d)
+  let lines =<< trim END
+      VAR d = {'b': 'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
+      unlet d.b
+      unlet d[-1]
+      call assert_equal({'1': 99, '3': 33}, d)
+  END
+  call CheckLegacyAndVim9Success(lines)
 endfunc
 
 " manipulating a big Dictionary (hashtable.c has a border of 1000 entries)
@@ -332,8 +369,30 @@ func Test_dict_assign()
   let d._ = 2
   call assert_equal({'1': 1, '_': 2}, d)
 
-  let n = 0
-  call assert_fails('let n.key = 3', 'E1203: Dot can only be used on a dictionary: n.key = 3')
+  let lines =<< trim END
+      VAR d = {}
+      LET d.a = 1
+      LET d._ = 2
+      call assert_equal({'a': 1, '_': 2}, d)
+  END
+  call CheckLegacyAndVim9Success(lines)
+
+  let lines =<< trim END
+    let n = 0
+    let n.key = 3
+  END
+  call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
+  let lines =<< trim END
+    vim9script
+    var n = 0
+    n.key = 3
+  END
+  call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
+  let lines =<< trim END
+    var n = 0
+    n.key = 3
+  END
+  call CheckDefFailure(lines, 'E1141:')
 endfunc
 
 " Function in script-local List or Dict
@@ -350,13 +409,41 @@ endfunc
 
 " Test removing items in a dictionary
 func Test_dict_func_remove()
-  let d = {1:'a', 2:'b', 3:'c'}
-  call assert_equal('b', remove(d, 2))
-  call assert_equal({1:'a', 3:'c'}, d)
+  let lines =<< trim END
+      VAR d = {1: 'a', 2: 'b', 3: 'c'}
+      call assert_equal('b', remove(d, 2))
+      call assert_equal({1: 'a', 3: 'c'}, d)
+  END
+  call CheckLegacyAndVim9Success(lines)
+
+  let lines =<< trim END
+      VAR d = {1: 'a', 3: 'c'}
+      call remove(d, 1, 2)
+  END
+  call CheckLegacyAndVim9Failure(lines, 'E118:')
 
-  call assert_fails("call remove(d, 1, 2)", 'E118:')
-  call assert_fails("call remove(d, 'a')", 'E716:')
-  call assert_fails("call remove(d, [])", 'E730:')
+  let lines =<< trim END
+      VAR d = {1: 'a', 3: 'c'}
+      call remove(d, 'a')
+  END
+  call CheckLegacyAndVim9Failure(lines, 'E716:')
+
+  let lines =<< trim END
+      let d = {1: 'a', 3: 'c'}
+      call remove(d, [])
+  END
+  call CheckScriptFailure(lines, 'E730:')
+  let lines =<< trim END
+      vim9script
+      var d = {1: 'a', 3: 'c'}
+      call remove(d, [])
+  END
+  call CheckScriptFailure(lines, 'E1174: String required for argument 2')
+  let lines =<< trim END
+      var d = {1: 'a', 3: 'c'}
+      call remove(d, [])
+  END
+  call CheckDefExecFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
 endfunc
 
 " Nasty: remove func from Dict that's being called (works)
@@ -372,7 +459,7 @@ endfunc
 func Test_dict_literal_keys()
   call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, #{one: 1, two2: 2, 3three: 3, 44: 4},)
 
-  " why *{} cannot be used
+  " why *{} cannot be used for a literal dictionary
   let blue = 'blue'
   call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
 endfunc
@@ -564,7 +651,6 @@ endfunc
 
 " No :unlet after lock on dict:
 func Test_dict_lock_unlet()
-  unlet! d
   let d = {'a': 99, 'b': 100}
   lockvar 1 d
   call assert_fails('unlet d.a', 'E741:')
@@ -572,7 +658,6 @@ endfunc
 
 " unlet after lock on dict item
 func Test_dict_item_lock_unlet()
-  unlet! d
   let d = {'a': 99, 'b': 100}
   lockvar d.a
   unlet d.a
@@ -581,7 +666,6 @@ endfunc
 
 " filter() after lock on dict item
 func Test_dict_lock_filter()
-  unlet! d
   let d = {'a': 99, 'b': 100}
   lockvar d.a
   call filter(d, 'v:key != "a"')
@@ -590,7 +674,6 @@ endfunc
 
 " map() after lock on dict
 func Test_dict_lock_map()
-  unlet! d
   let d = {'a': 99, 'b': 100}
   lockvar 1 d
   call map(d, 'v:val + 200')
@@ -599,7 +682,6 @@ endfunc
 
 " No extend() after lock on dict item
 func Test_dict_lock_extend()
-  unlet! d
   let d = {'a': 99, 'b': 100}
   lockvar d.a
   call assert_fails("call extend(d, {'a' : 123})", 'E741:')
@@ -608,7 +690,6 @@ endfunc
 
 " Cannot use += with a locked dict
 func Test_dict_lock_operator()
-  unlet! d
   let d = {}
   lockvar d
   call assert_fails("let d += {'k' : 10}", 'E741:')
@@ -711,9 +792,6 @@ func Test_func_arg_list()
   call s:arg_list_test(1, 2, [3, 4], {5: 6})
 endfunc
 
-func Test_dict_item_locked()
-endfunc
-
 " Tests for reverse(), sort(), uniq()
 func Test_reverse_sort_uniq()
   let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5]
index 8d726e400bab11dfbc0166502c36289d77ca9ccf..8eb758c0ade9040b3481de72c75f9e5baadff89e 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3202,
 /**/
     3201,
 /**/
index 33ad788a22f30f65559a77f49dec705d90c41021..16b1bdf38db4fe9f113534b5f2b50b8680097b7a 100644 (file)
@@ -2711,6 +2711,13 @@ exec_instructions(ectx_T *ectx)
                                    else
                                        n2 = list_idx_of_item(l, li2);
                                }
+                               if (status != FAIL
+                                       && tv_idx2->v_type != VAR_SPECIAL
+                                       && n2 < n1)
+                               {
+                                   semsg(_(e_listidx), n2);
+                                   status = FAIL;
+                               }
                                if (status != FAIL
                                        && list_unlet_range(l, li, NULL, n1,
                                            tv_idx2->v_type != VAR_SPECIAL, n2)