0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.4600: Vim9: not enough test coverage for executing :def function

Problem:    Vim9: not enough test coverage for executing :def function.
Solution:   Add a few more tests.  Fix inconsistencies.
This commit is contained in:
Bram Moolenaar
2022-03-20 17:46:06 +00:00
parent a4df834a92
commit 6b8c7ba062
7 changed files with 54 additions and 35 deletions

View File

@@ -1804,20 +1804,14 @@ do_unlet_var(
&& value_check_lock(lp->ll_dict->dv_lock, lp->ll_name, FALSE))) && value_check_lock(lp->ll_dict->dv_lock, lp->ll_name, FALSE)))
return FAIL; return FAIL;
else if (lp->ll_range) else if (lp->ll_range)
{ list_unlet_range(lp->ll_list, lp->ll_li, lp->ll_n1,
if (list_unlet_range(lp->ll_list, lp->ll_li, lp->ll_name, lp->ll_n1, !lp->ll_empty2, lp->ll_n2);
!lp->ll_empty2, lp->ll_n2) == FAIL) else if (lp->ll_list != NULL)
return FAIL;
}
else
{
if (lp->ll_list != NULL)
// unlet a List item. // unlet a List item.
listitem_remove(lp->ll_list, lp->ll_li); listitem_remove(lp->ll_list, lp->ll_li);
else else
// unlet a Dictionary item. // unlet a Dictionary item.
dictitem_remove(lp->ll_dict, lp->ll_di); dictitem_remove(lp->ll_dict, lp->ll_di);
}
return ret; return ret;
} }
@@ -1826,11 +1820,10 @@ do_unlet_var(
* Unlet one item or a range of items from a list. * Unlet one item or a range of items from a list.
* Return OK or FAIL. * Return OK or FAIL.
*/ */
int void
list_unlet_range( list_unlet_range(
list_T *l, list_T *l,
listitem_T *li_first, listitem_T *li_first,
char_u *name,
long n1_arg, long n1_arg,
int has_n2, int has_n2,
long n2) long n2)
@@ -1838,14 +1831,6 @@ list_unlet_range(
listitem_T *li = li_first; listitem_T *li = li_first;
int n1 = n1_arg; int n1 = n1_arg;
while (li != NULL && (!has_n2 || n2 >= n1))
{
if (value_check_lock(li->li_tv.v_lock, name, FALSE))
return FAIL;
li = li->li_next;
++n1;
}
// Delete a range of List items. // Delete a range of List items.
li = li_first; li = li_first;
n1 = n1_arg; n1 = n1_arg;
@@ -1857,7 +1842,6 @@ list_unlet_range(
li = next; li = next;
++n1; ++n1;
} }
return OK;
} }
/* /*
* "unlet" a variable. Return OK if it existed, FAIL if not. * "unlet" a variable. Return OK if it existed, FAIL if not.

View File

@@ -23,7 +23,7 @@ void list_hashtable_vars(hashtab_T *ht, char *prefix, int empty, int *first);
void ex_unlet(exarg_T *eap); void ex_unlet(exarg_T *eap);
void ex_lockvar(exarg_T *eap); void ex_lockvar(exarg_T *eap);
void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, int glv_flags, int (*callback)(lval_T *, char_u *, exarg_T *, int, void *), void *cookie); void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, int glv_flags, int (*callback)(lval_T *, char_u *, exarg_T *, int, void *), void *cookie);
int list_unlet_range(list_T *l, listitem_T *li_first, char_u *name, long n1_arg, int has_n2, long n2); void list_unlet_range(list_T *l, listitem_T *li_first, long n1_arg, int has_n2, long n2);
int do_unlet(char_u *name, int forceit); int do_unlet(char_u *name, int forceit);
void item_lock(typval_T *tv, int deep, int lock, int check_refcount); void item_lock(typval_T *tv, int deep, int lock, int check_refcount);
void del_menutrans_vars(void); void del_menutrans_vars(void);

View File

@@ -721,10 +721,13 @@ func Test_list_locked_var_unlet()
endfor endfor
endfor endfor
" Deleting a list range should fail if the range is locked " Deleting a list range with locked items works, but changing the items
" fails.
let l = [1, 2, 3, 4] let l = [1, 2, 3, 4]
lockvar l[1:2] lockvar l[1:2]
call assert_fails('unlet l[1:2]', 'E741:') call assert_fails('let l[1:2] = [8, 9]', 'E741:')
unlet l[1:2]
call assert_equal([1, 4], l)
unlet l unlet l
endfunc endfunc

View File

@@ -2209,6 +2209,11 @@ def Test_unlet()
unlet dd[4] unlet dd[4]
assert_equal({b: 2}, dd) assert_equal({b: 2}, dd)
# null key works like empty string
dd = {'': 1, x: 9}
unlet dd[null_string]
assert_equal({x: 9}, dd)
# list unlet # list unlet
var ll = [1, 2, 3, 4] var ll = [1, 2, 3, 4]
unlet ll[1] unlet ll[1]

View File

@@ -1573,6 +1573,36 @@ def Test_lockvar()
END END
v9.CheckScriptFailure(lines, 'E741', 2) v9.CheckScriptFailure(lines, 'E741', 2)
# can unlet a locked list item but not change it
lines =<< trim END
var ll = [1, 2, 3]
lockvar ll[1]
unlet ll[1]
assert_equal([1, 3], ll)
END
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
var ll = [1, 2, 3]
lockvar ll[1]
ll[1] = 9
END
v9.CheckDefExecAndScriptFailure(lines, ['E1119:', 'E741'], 3)
# can unlet a locked dict item but not change it
lines =<< trim END
var dd = {a: 1, b: 2}
lockvar dd.a
unlet dd.a
assert_equal({b: 2}, dd)
END
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
var dd = {a: 1, b: 2}
lockvar dd.a
dd.a = 3
END
v9.CheckDefExecAndScriptFailure(lines, ['E1121:', 'E741'], 3)
lines =<< trim END lines =<< trim END
var theList = [1, 2, 3] var theList = [1, 2, 3]
lockvar theList lockvar theList

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4600,
/**/ /**/
4599, 4599,
/**/ /**/

View File

@@ -2048,9 +2048,6 @@ execute_unletindex(isn_T *iptr, ectx_T *ectx)
semsg(_(e_list_index_out_of_range_nr), n); semsg(_(e_list_index_out_of_range_nr), n);
status = FAIL; status = FAIL;
} }
else if (value_check_lock(li->li_tv.v_lock,
NULL, FALSE))
status = FAIL;
else else
listitem_remove(l, li); listitem_remove(l, li);
} }
@@ -2133,11 +2130,9 @@ execute_unletrange(isn_T *iptr, ectx_T *ectx)
semsg(_(e_list_index_out_of_range_nr), n2); semsg(_(e_list_index_out_of_range_nr), n2);
status = FAIL; status = FAIL;
} }
if (status != FAIL if (status != FAIL)
&& list_unlet_range(l, li, NULL, n1, list_unlet_range(l, li, n1,
tv_idx2->v_type != VAR_SPECIAL, n2) tv_idx2->v_type != VAR_SPECIAL, n2);
== FAIL)
status = FAIL;
} }
} }
} }