vim-patch:8.2.4600: Vim9: not enough test coverage for executing :def function (#24001)

Problem:    Vim9: not enough test coverage for executing :def function.
Solution:   Add a few more tests.  Fix inconsistencies.

6b8c7ba062

Cherry-pick a blank line in test_listdict.vim from patch 8.2.3842.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2023-06-12 21:58:40 +08:00
committed by GitHub
parent 564d2d20a3
commit a7e5d4238a
2 changed files with 29 additions and 35 deletions

View File

@@ -1056,36 +1056,31 @@ static int do_unlet_var(lval_T *lp, char *name_end, exarg_T *eap, int deep FUNC_
lp->ll_name_len))) {
return FAIL;
} else if (lp->ll_range) {
if (list_unlet_range(lp->ll_list, lp->ll_li, lp->ll_name, lp->ll_name_len,
lp->ll_n1, !lp->ll_empty2, lp->ll_n2) == FAIL) {
return FAIL;
}
tv_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.
tv_list_item_remove(lp->ll_list, lp->ll_li);
} else {
if (lp->ll_list != NULL) {
// unlet a List item.
tv_list_item_remove(lp->ll_list, lp->ll_li);
} else {
// unlet a Dictionary item.
dict_T *d = lp->ll_dict;
assert(d != NULL);
dictitem_T *di = lp->ll_di;
bool watched = tv_dict_is_watched(d);
char *key = NULL;
typval_T oldtv;
// unlet a Dictionary item.
dict_T *d = lp->ll_dict;
assert(d != NULL);
dictitem_T *di = lp->ll_di;
bool watched = tv_dict_is_watched(d);
char *key = NULL;
typval_T oldtv;
if (watched) {
tv_copy(&di->di_tv, &oldtv);
// need to save key because dictitem_remove will free it
key = xstrdup(di->di_key);
}
if (watched) {
tv_copy(&di->di_tv, &oldtv);
// need to save key because dictitem_remove will free it
key = xstrdup(di->di_key);
}
tv_dict_item_remove(d, di);
tv_dict_item_remove(d, di);
if (watched) {
tv_dict_watcher_notify(d, key, NULL, &oldtv);
tv_clear(&oldtv);
xfree(key);
}
if (watched) {
tv_dict_watcher_notify(d, key, NULL, &oldtv);
tv_clear(&oldtv);
xfree(key);
}
}
@@ -1094,18 +1089,14 @@ static int do_unlet_var(lval_T *lp, char *name_end, exarg_T *eap, int deep FUNC_
/// Unlet one item or a range of items from a list.
/// Return OK or FAIL.
static int list_unlet_range(list_T *const l, listitem_T *const li_first, const char *const name,
const size_t name_len, const long n1_arg, const bool has_n2,
const long n2)
static void tv_list_unlet_range(list_T *const l, listitem_T *const li_first, const long n1_arg,
const bool has_n2, const long n2)
{
assert(l != NULL);
// Delete a range of List items.
listitem_T *li_last = li_first;
long n1 = n1_arg;
while (true) {
if (value_check_lock(TV_LIST_ITEM_TV(li_last)->v_lock, name, name_len)) {
return FAIL;
}
listitem_T *const li = TV_LIST_ITEM_NEXT(l, li_last);
n1++;
if (li == NULL || (has_n2 && n2 < n1)) {
@@ -1114,7 +1105,6 @@ static int list_unlet_range(list_T *const l, listitem_T *const li_first, const c
li_last = li;
}
tv_list_remove_items(l, li_first, li_last);
return OK;
}
/// unlet a variable

View File

@@ -666,10 +666,14 @@ func Test_list_locked_var_unlet()
call assert_equal(expected[depth][u][1], ps)
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