Problem: Vim9: not enough test coverage for executing :def function.
Solution: Add a few more tests. Fix inconsistencies.
&& value_check_lock(lp->ll_dict->dv_lock, lp->ll_name, FALSE)))
return FAIL;
else if (lp->ll_range)
- {
- if (list_unlet_range(lp->ll_list, lp->ll_li, lp->ll_name, lp->ll_n1,
- !lp->ll_empty2, lp->ll_n2) == FAIL)
- return FAIL;
- }
+ list_unlet_range(lp->ll_list, lp->ll_li, lp->ll_n1,
+ !lp->ll_empty2, lp->ll_n2);
+ else if (lp->ll_list != NULL)
+ // unlet a List item.
+ listitem_remove(lp->ll_list, lp->ll_li);
else
- {
- if (lp->ll_list != NULL)
- // unlet a List item.
- listitem_remove(lp->ll_list, lp->ll_li);
- else
- // unlet a Dictionary item.
- dictitem_remove(lp->ll_dict, lp->ll_di);
- }
+ // unlet a Dictionary item.
+ dictitem_remove(lp->ll_dict, lp->ll_di);
return ret;
}
* Unlet one item or a range of items from a list.
* Return OK or FAIL.
*/
- int
+ void
list_unlet_range(
list_T *l,
listitem_T *li_first,
- char_u *name,
long n1_arg,
int has_n2,
long n2)
listitem_T *li = li_first;
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.
li = li_first;
n1 = n1_arg;
li = next;
++n1;
}
- return OK;
}
/*
* "unlet" a variable. Return OK if it existed, FAIL if not.
void ex_unlet(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);
-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);
void item_lock(typval_T *tv, int deep, int lock, int check_refcount);
void del_menutrans_vars(void);
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]
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
endfunc
unlet dd[4]
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
var ll = [1, 2, 3, 4]
unlet ll[1]
END
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
var theList = [1, 2, 3]
lockvar theList
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 4600,
/**/
4599,
/**/
semsg(_(e_list_index_out_of_range_nr), n);
status = FAIL;
}
- else if (value_check_lock(li->li_tv.v_lock,
- NULL, FALSE))
- status = FAIL;
else
listitem_remove(l, li);
}
semsg(_(e_list_index_out_of_range_nr), n2);
status = FAIL;
}
- if (status != FAIL
- && list_unlet_range(l, li, NULL, n1,
- tv_idx2->v_type != VAR_SPECIAL, n2)
- == FAIL)
- status = FAIL;
+ if (status != FAIL)
+ list_unlet_range(l, li, n1,
+ tv_idx2->v_type != VAR_SPECIAL, n2);
}
}
}