Patch 8.2.3191
Problem:    Vim9: not enough code is tested.
Solution:   Use CheckLegacyAndVim9Success() in more places.  Fix uncovered
            problems.
Files:      src/vim9compile.c, src/vim9execute.c,
            src/testdir/test_listdict.vim


*** ../vim-8.2.3190/src/vim9compile.c   2021-07-19 22:19:25.690972401 +0200
--- src/vim9compile.c   2021-07-20 21:25:49.041990978 +0200
***************
*** 6599,6605 ****
                return FAIL;
            }
            type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
!           if ((dest_type != VAR_BLOB || type != &t_special)
                    && need_type(type, &t_number,
                                            -1, 0, cctx, FALSE, FALSE) == FAIL)
                return FAIL;
--- 6599,6605 ----
                return FAIL;
            }
            type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
!           if ((dest_type != VAR_BLOB && type != &t_special)
                    && need_type(type, &t_number,
                                            -1, 0, cctx, FALSE, FALSE) == FAIL)
                return FAIL;
*** ../vim-8.2.3190/src/vim9execute.c   2021-07-20 21:07:32.972058844 +0200
--- src/vim9execute.c   2021-07-20 22:20:00.626145973 +0200
***************
*** 2679,2685 ****
                        // indexes must be a number
                        SOURCING_LNUM = iptr->isn_lnum;
                        if (check_for_number(tv_idx1) == FAIL
!                               || check_for_number(tv_idx2) == FAIL)
                        {
                            status = FAIL;
                        }
--- 2679,2686 ----
                        // indexes must be a number
                        SOURCING_LNUM = iptr->isn_lnum;
                        if (check_for_number(tv_idx1) == FAIL
!                               || (tv_idx2->v_type != VAR_SPECIAL
!                                        && check_for_number(tv_idx2) == FAIL))
                        {
                            status = FAIL;
                        }
***************
*** 2687,2700 ****
                        {
                            list_T      *l = tv_dest->vval.v_list;
                            long        n1 = (long)tv_idx1->vval.v_number;
!                           long        n2 = (long)tv_idx2->vval.v_number;
                            listitem_T  *li;
  
                            li = list_find_index(l, &n1);
!                           if (li == NULL
!                                    || list_unlet_range(l, li, NULL, n1,
!                                                           TRUE, n2) == FAIL)
                                status = FAIL;
                        }
                    }
                    else
--- 2688,2719 ----
                        {
                            list_T      *l = tv_dest->vval.v_list;
                            long        n1 = (long)tv_idx1->vval.v_number;
!                           long        n2 = tv_idx2->v_type == VAR_SPECIAL
!                                           ? 0 : (long)tv_idx2->vval.v_number;
                            listitem_T  *li;
  
                            li = list_find_index(l, &n1);
!                           if (li == NULL)
                                status = FAIL;
+                           else
+                           {
+                               if (n1 < 0)
+                                   n1 = list_idx_of_item(l, li);
+                               if (n2 < 0)
+                               {
+                                   listitem_T *li2 = list_find(l, n2);
+ 
+                                   if (li2 == NULL)
+                                       status = FAIL;
+                                   else
+                                       n2 = list_idx_of_item(l, li2);
+                               }
+                               if (status != FAIL
+                                       && list_unlet_range(l, li, NULL, n1,
+                                           tv_idx2->v_type != VAR_SPECIAL, n2)
+                                                                      == FAIL)
+                                   status = FAIL;
+                           }
                        }
                    }
                    else
*** ../vim-8.2.3190/src/testdir/test_listdict.vim       2021-06-26 
15:00:55.881276189 +0200
--- src/testdir/test_listdict.vim       2021-07-20 22:11:37.894837698 +0200
***************
*** 1,5 ****
--- 1,7 ----
  " Tests for the List and Dict types
  
+ source vim9.vim
+ 
  func TearDown()
    " Run garbage collection after every test
    call test_garbagecollect_now()
***************
*** 44,109 ****
  
  " List identity
  func Test_list_identity()
!   let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
!   let ll = l
!   let lx = copy(l)
!   call assert_true(l == ll)
!   call assert_false(l isnot ll)
!   call assert_true(l is ll)
!   call assert_true(l == lx)
!   call assert_false(l is lx)
!   call assert_true(l isnot lx)
  endfunc
  
  " removing items with :unlet
  func Test_list_unlet()
!   let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
!   unlet l[2]
!   call assert_equal([1, 'as''d', {'a': 1}], l)
!   let l = range(8)
!   unlet l[:3]
!   unlet l[1:]
!   call assert_equal([4], l)
  
-   " removing items out of range: silently skip items that don't exist
-   let l = [0, 1, 2, 3]
-   call assert_fails('unlet l[2:1]', 'E684:')
    let l = [0, 1, 2, 3]
    unlet l[2:2]
    call assert_equal([0, 1, 3], l)
    let l = [0, 1, 2, 3]
    unlet l[2:3]
    call assert_equal([0, 1], l)
    let l = [0, 1, 2, 3]
!   unlet l[2:4]
!   call assert_equal([0, 1], l)
!   let l = [0, 1, 2, 3]
!   unlet l[2:5]
!   call assert_equal([0, 1], l)
    let l = [0, 1, 2, 3]
    call assert_fails('unlet l[-1:2]', 'E684:')
-   let l = [0, 1, 2, 3]
-   unlet l[-2:2]
-   call assert_equal([0, 1, 3], l)
-   let l = [0, 1, 2, 3]
-   unlet l[-3:2]
-   call assert_equal([0, 3], l)
-   let l = [0, 1, 2, 3]
-   unlet l[-4:2]
-   call assert_equal([3], l)
-   let l = [0, 1, 2, 3]
-   unlet l[-5:2]
-   call assert_equal([3], l)
-   let l = [0, 1, 2, 3]
-   unlet l[-6:2]
-   call assert_equal([3], l)
  endfunc
  
  " assignment to a list
  func Test_list_assign()
    let l = [0, 1, 2, 3]
-   let [va, vb] = l[2:3]
-   call assert_equal([2, 3], [va, vb])
    call assert_fails('let [va, vb] = l', 'E687:')
    call assert_fails('let [va, vb] = l[1:1]', 'E688:')
  endfunc
--- 46,132 ----
  
  " List identity
  func Test_list_identity()
!   let lines =<< trim END
!       VAR l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
!       VAR ll = l
!       VAR lx = copy(l)
!       call assert_true(l == ll)
!       call assert_false(l isnot ll)
!       call assert_true(l is ll)
!       call assert_true(l == lx)
!       call assert_false(l is lx)
!       call assert_true(l isnot lx)
!   END
!   call CheckLegacyAndVim9Success(lines)
  endfunc
  
  " removing items with :unlet
  func Test_list_unlet()
!   let lines =<< trim END
!       VAR l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
!       unlet l[2]
!       call assert_equal([1, 'as''d', {'a': 1}], l)
!       LET l = range(8)
!       unlet l[: 3]
!       unlet l[1 :]
!       call assert_equal([4], l)
! 
!       #" removing items out of range: silently skip items that don't exist
!       LET l = [0, 1, 2, 3]
!       unlet l[2 : 2]
!       call assert_equal([0, 1, 3], l)
!       LET l = [0, 1, 2, 3]
!       unlet l[2 : 3]
!       call assert_equal([0, 1], l)
!       LET l = [0, 1, 2, 3]
!       unlet l[2 : 4]
!       call assert_equal([0, 1], l)
!       LET l = [0, 1, 2, 3]
!       unlet l[2 : 5]
!       call assert_equal([0, 1], l)
!       LET l = [0, 1, 2, 3]
!       unlet l[-2 : 2]
!       call assert_equal([0, 1, 3], l)
!       LET l = [0, 1, 2, 3]
!       unlet l[-3 : 2]
!       call assert_equal([0, 3], l)
!       LET l = [0, 1, 2, 3]
!       unlet l[-4 : 2]
!       call assert_equal([3], l)
!       LET l = [0, 1, 2, 3]
!       unlet l[-5 : 2]
!       call assert_equal([3], l)
!       LET l = [0, 1, 2, 3]
!       unlet l[-6 : 2]
!       call assert_equal([3], l)
!   END
!   call CheckLegacyAndVim9Success(lines)
  
    let l = [0, 1, 2, 3]
    unlet l[2:2]
    call assert_equal([0, 1, 3], l)
    let l = [0, 1, 2, 3]
    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:')
  endfunc
  
  " assignment to a list
  func Test_list_assign()
+   let lines =<< trim END
+       VAR l = [0, 1, 2, 3]
+       VAR va = 0
+       VAR vb = 0
+       LET [va, vb] = l[2 : 3]
+       call assert_equal([2, 3], [va, vb])
+   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:')
  endfunc
***************
*** 119,149 ****
  
  " Test removing items in list
  func Test_list_func_remove()
!   " Test removing 1 element
!   let l = [1, 2, 3, 4]
!   call assert_equal(1, remove(l, 0))
!   call assert_equal([2, 3, 4], l)
! 
!   let l = [1, 2, 3, 4]
!   call assert_equal(2, remove(l, 1))
!   call assert_equal([1, 3, 4], l)
! 
!   let l = [1, 2, 3, 4]
!   call assert_equal(4, remove(l, -1))
!   call assert_equal([1, 2, 3], l)
! 
!   " Test removing range of element(s)
!   let l = [1, 2, 3, 4]
!   call assert_equal([3], remove(l, 2, 2))
!   call assert_equal([1, 2, 4], l)
! 
!   let l = [1, 2, 3, 4]
!   call assert_equal([2, 3], remove(l, 1, 2))
!   call assert_equal([1, 4], l)
! 
!   let l = [1, 2, 3, 4]
!   call assert_equal([2, 3], remove(l, -3, -2))
!   call assert_equal([1, 4], l)
  
    " Test invalid cases
    let l = [1, 2, 3, 4]
--- 142,175 ----
  
  " Test removing items in list
  func Test_list_func_remove()
!   let lines =<< trim END
!       #" Test removing 1 element
!       VAR l = [1, 2, 3, 4]
!       call assert_equal(1, remove(l, 0))
!       call assert_equal([2, 3, 4], l)
! 
!       LET l = [1, 2, 3, 4]
!       call assert_equal(2, remove(l, 1))
!       call assert_equal([1, 3, 4], l)
! 
!       LET l = [1, 2, 3, 4]
!       call assert_equal(4, remove(l, -1))
!       call assert_equal([1, 2, 3], l)
! 
!       #" Test removing range of element(s)
!       LET l = [1, 2, 3, 4]
!       call assert_equal([3], remove(l, 2, 2))
!       call assert_equal([1, 2, 4], l)
! 
!       LET l = [1, 2, 3, 4]
!       call assert_equal([2, 3], remove(l, 1, 2))
!       call assert_equal([1, 4], l)
! 
!       LET l = [1, 2, 3, 4]
!       call assert_equal([2, 3], remove(l, -3, -2))
!       call assert_equal([1, 4], l)
!   END
!   call CheckLegacyAndVim9Success(lines)
  
    " Test invalid cases
    let l = [1, 2, 3, 4]
***************
*** 156,170 ****
  
  " List add() function
  func Test_list_add()
!   let l = []
!   call add(l, 1)
!   call add(l, [2, 3])
!   call add(l, [])
!   call add(l, test_null_list())
!   call add(l, {'k' : 3})
!   call add(l, {})
!   call add(l, test_null_dict())
!   call assert_equal([1, [2, 3], [], [], {'k' : 3}, {}, {}], l)
    call assert_equal(1, add(test_null_list(), 4))
  endfunc
  
--- 182,201 ----
  
  " List add() function
  func Test_list_add()
!   let lines =<< trim END
!       VAR l = []
!       call add(l, 1)
!       call add(l, [2, 3])
!       call add(l, [])
!       call add(l, test_null_list())
!       call add(l, {'k': 3})
!       call add(l, {})
!       call add(l, test_null_dict())
!       call assert_equal([1, [2, 3], [], [], {'k': 3}, {}, {}], l)
!   END
!   call CheckLegacyAndVim9Success(lines)
! 
!   " weird legacy behavior
    call assert_equal(1, add(test_null_list(), 4))
  endfunc
  
***************
*** 172,182 ****
  
  func Test_dict()
    " Creating Dictionary directly with different types
    let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
    call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': 
{'a': 1}}", string(d))
!   call assert_equal('asd', d.1)
!   call assert_equal(['-1', '1', 'b'], sort(keys(d)))
!   call assert_equal(['asd', [1, 2, function('strlen')], {'a': 1}], values(d))
    let v = []
    for [key, val] in items(d)
      call extend(v, [key, val])
--- 203,223 ----
  
  func Test_dict()
    " Creating Dictionary directly with different types
+   let lines =<< trim END
+       VAR d = {'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}, }
+       call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': 
{'a': 1}}", string(d))
+       call assert_equal('asd', d.1)
+       call assert_equal(['-1', '1', 'b'], sort(keys(d)))
+       call assert_equal(['asd', [1, 2, function('strlen')], {'a': 1}], 
values(d))
+       call extend(d, {3: 33, 1: 99})
+       call extend(d, {'b': 'bbb', 'c': 'ccc'}, "keep")
+       call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, 
function('strlen')], '3': 33, '-1': {'a': 1}}, d)
+   END
+   call CheckLegacyAndVim9Success(lines)
+ 
    let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
    call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': 
{'a': 1}}", string(d))
! 
    let v = []
    for [key, val] in items(d)
      call extend(v, [key, val])
***************
*** 184,195 ****
    endfor
    call assert_equal(['1','asd','b',[1, 2, function('strlen')],'-1',{'a': 1}], 
v)
  
!   call extend(d, {3:33, 1:99})
!   call extend(d, {'b':'bbb', 'c':'ccc'}, "keep")
    call assert_fails("call extend(d, {3:333,4:444}, 'error')", 'E737:')
-   call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], 
'3': 33, '-1': {'a': 1}}, d)
-   call filter(d, 'v:key =~ ''[ac391]''')
-   call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d)
  
    " duplicate key
    call assert_fails("let d = {'k' : 10, 'k' : 20}", 'E721:')
--- 225,232 ----
    endfor
    call assert_equal(['1','asd','b',[1, 2, function('strlen')],'-1',{'a': 1}], 
v)
  
!   call extend(d, {3: 33, 1: 99})
    call assert_fails("call extend(d, {3:333,4:444}, 'error')", 'E737:')
  
    " duplicate key
    call assert_fails("let d = {'k' : 10, 'k' : 20}", 'E721:')
*** ../vim-8.2.3190/src/version.c       2021-07-20 21:07:32.972058844 +0200
--- src/version.c       2021-07-20 22:21:34.826014932 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3191,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
192. Your boss asks you to "go fer" coffee and you come up with 235 FTP sites.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202107202022.16KKMxCe3381958%40masaka.moolenaar.net.

Raspunde prin e-mail lui