mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 19:06:31 +00:00
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:
@@ -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))) {
|
lp->ll_name_len))) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
} else if (lp->ll_range) {
|
} else if (lp->ll_range) {
|
||||||
if (list_unlet_range(lp->ll_list, lp->ll_li, lp->ll_name, lp->ll_name_len,
|
tv_list_unlet_range(lp->ll_list, lp->ll_li, lp->ll_n1, !lp->ll_empty2, lp->ll_n2);
|
||||||
lp->ll_n1, !lp->ll_empty2, lp->ll_n2) == FAIL) {
|
} else if (lp->ll_list != NULL) {
|
||||||
return FAIL;
|
// unlet a List item.
|
||||||
}
|
tv_list_item_remove(lp->ll_list, lp->ll_li);
|
||||||
} else {
|
} else {
|
||||||
if (lp->ll_list != NULL) {
|
// unlet a Dictionary item.
|
||||||
// unlet a List item.
|
dict_T *d = lp->ll_dict;
|
||||||
tv_list_item_remove(lp->ll_list, lp->ll_li);
|
assert(d != NULL);
|
||||||
} else {
|
dictitem_T *di = lp->ll_di;
|
||||||
// unlet a Dictionary item.
|
bool watched = tv_dict_is_watched(d);
|
||||||
dict_T *d = lp->ll_dict;
|
char *key = NULL;
|
||||||
assert(d != NULL);
|
typval_T oldtv;
|
||||||
dictitem_T *di = lp->ll_di;
|
|
||||||
bool watched = tv_dict_is_watched(d);
|
|
||||||
char *key = NULL;
|
|
||||||
typval_T oldtv;
|
|
||||||
|
|
||||||
if (watched) {
|
if (watched) {
|
||||||
tv_copy(&di->di_tv, &oldtv);
|
tv_copy(&di->di_tv, &oldtv);
|
||||||
// need to save key because dictitem_remove will free it
|
// need to save key because dictitem_remove will free it
|
||||||
key = xstrdup(di->di_key);
|
key = xstrdup(di->di_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
tv_dict_item_remove(d, di);
|
tv_dict_item_remove(d, di);
|
||||||
|
|
||||||
if (watched) {
|
if (watched) {
|
||||||
tv_dict_watcher_notify(d, key, NULL, &oldtv);
|
tv_dict_watcher_notify(d, key, NULL, &oldtv);
|
||||||
tv_clear(&oldtv);
|
tv_clear(&oldtv);
|
||||||
xfree(key);
|
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.
|
/// Unlet one item or a range of items from a list.
|
||||||
/// Return OK or FAIL.
|
/// Return OK or FAIL.
|
||||||
static int list_unlet_range(list_T *const l, listitem_T *const li_first, const char *const name,
|
static void tv_list_unlet_range(list_T *const l, listitem_T *const li_first, const long n1_arg,
|
||||||
const size_t name_len, const long n1_arg, const bool has_n2,
|
const bool has_n2, const long n2)
|
||||||
const long n2)
|
|
||||||
{
|
{
|
||||||
assert(l != NULL);
|
assert(l != NULL);
|
||||||
// Delete a range of List items.
|
// Delete a range of List items.
|
||||||
listitem_T *li_last = li_first;
|
listitem_T *li_last = li_first;
|
||||||
long n1 = n1_arg;
|
long n1 = n1_arg;
|
||||||
while (true) {
|
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);
|
listitem_T *const li = TV_LIST_ITEM_NEXT(l, li_last);
|
||||||
n1++;
|
n1++;
|
||||||
if (li == NULL || (has_n2 && n2 < 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;
|
li_last = li;
|
||||||
}
|
}
|
||||||
tv_list_remove_items(l, li_first, li_last);
|
tv_list_remove_items(l, li_first, li_last);
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// unlet a variable
|
/// unlet a variable
|
||||||
|
@@ -666,10 +666,14 @@ func Test_list_locked_var_unlet()
|
|||||||
call assert_equal(expected[depth][u][1], ps)
|
call assert_equal(expected[depth][u][1], ps)
|
||||||
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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user