Skip to content

Commit ef98257

Browse files
committed
patch 8.2.3335: Vim9: not enough tests run with Vim9
Problem: Vim9: not enough tests run with Vim9. Solution: Run a few more tests in Vim9 script and :def function. Fix that items(), keys() and values9) return zero for a NULL dict. Make join() return an empty string for a NULL list. Make sort() return an empty list for a NULL list.
1 parent bd77aa9 commit ef98257

File tree

5 files changed

+248
-191
lines changed

5 files changed

+248
-191
lines changed

src/dict.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,11 +1209,12 @@ dict_list(typval_T *argvars, typval_T *rettv, int what)
12091209
emsg(_(e_dictreq));
12101210
return;
12111211
}
1212-
if ((d = argvars[0].vval.v_dict) == NULL)
1213-
return;
12141212

12151213
if (rettv_list_alloc(rettv) == FAIL)
12161214
return;
1215+
if ((d = argvars[0].vval.v_dict) == NULL)
1216+
// empty dict behaves like an empty dict
1217+
return;
12171218

12181219
todo = (int)d->dv_hashtab.ht_used;
12191220
for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)

src/list.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,15 +1436,15 @@ f_join(typval_T *argvars, typval_T *rettv)
14361436
emsg(_(e_listreq));
14371437
return;
14381438
}
1439+
rettv->v_type = VAR_STRING;
14391440
if (argvars[0].vval.v_list == NULL)
14401441
return;
1442+
14411443
if (argvars[1].v_type == VAR_UNKNOWN)
14421444
sep = (char_u *)" ";
14431445
else
14441446
sep = tv_get_string_chk(&argvars[1]);
14451447

1446-
rettv->v_type = VAR_STRING;
1447-
14481448
if (sep != NULL)
14491449
{
14501450
ga_init2(&ga, (int)sizeof(char), 80);
@@ -1968,11 +1968,13 @@ do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort)
19681968
else
19691969
{
19701970
l = argvars[0].vval.v_list;
1971-
if (l == NULL || value_check_lock(l->lv_lock,
1971+
if (l != NULL && value_check_lock(l->lv_lock,
19721972
(char_u *)(sort ? N_("sort() argument") : N_("uniq() argument")),
19731973
TRUE))
19741974
goto theend;
19751975
rettv_list_set(rettv, l);
1976+
if (l == NULL)
1977+
goto theend;
19761978
CHECK_LIST_MATERIALIZE(l);
19771979

19781980
len = list_len(l);
@@ -3110,32 +3112,35 @@ f_reverse(typval_T *argvars, typval_T *rettv)
31103112

31113113
if (argvars[0].v_type != VAR_LIST)
31123114
semsg(_(e_listblobarg), "reverse()");
3113-
else if ((l = argvars[0].vval.v_list) != NULL
3115+
else
3116+
{
3117+
l = argvars[0].vval.v_list;
3118+
rettv_list_set(rettv, l);
3119+
if (l != NULL
31143120
&& !value_check_lock(l->lv_lock,
31153121
(char_u *)N_("reverse() argument"), TRUE))
3116-
{
3117-
if (l->lv_first == &range_list_item)
31183122
{
3119-
varnumber_T new_start = l->lv_u.nonmat.lv_start
3123+
if (l->lv_first == &range_list_item)
3124+
{
3125+
varnumber_T new_start = l->lv_u.nonmat.lv_start
31203126
+ (l->lv_len - 1) * l->lv_u.nonmat.lv_stride;
3121-
l->lv_u.nonmat.lv_end = new_start
3127+
l->lv_u.nonmat.lv_end = new_start
31223128
- (l->lv_u.nonmat.lv_end - l->lv_u.nonmat.lv_start);
3123-
l->lv_u.nonmat.lv_start = new_start;
3124-
l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride;
3125-
rettv_list_set(rettv, l);
3126-
return;
3127-
}
3128-
li = l->lv_u.mat.lv_last;
3129-
l->lv_first = l->lv_u.mat.lv_last = NULL;
3130-
l->lv_len = 0;
3131-
while (li != NULL)
3132-
{
3133-
ni = li->li_prev;
3134-
list_append(l, li);
3135-
li = ni;
3129+
l->lv_u.nonmat.lv_start = new_start;
3130+
l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride;
3131+
return;
3132+
}
3133+
li = l->lv_u.mat.lv_last;
3134+
l->lv_first = l->lv_u.mat.lv_last = NULL;
3135+
l->lv_len = 0;
3136+
while (li != NULL)
3137+
{
3138+
ni = li->li_prev;
3139+
list_append(l, li);
3140+
li = ni;
3141+
}
3142+
l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1;
31363143
}
3137-
rettv_list_set(rettv, l);
3138-
l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1;
31393144
}
31403145
}
31413146

0 commit comments

Comments
 (0)