Mercurial > vim
comparison src/list.c @ 25597:0fdacd8f0cf3 v8.2.3335
patch 8.2.3335: Vim9: not enough tests run with Vim9
Commit: https://github.com/vim/vim/commit/ef98257593a0abf1300d0f70358dc45a70a62580
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 12 19:27:57 2021 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 12 Aug 2021 19:30:03 +0200 |
parents | ea69398b40d1 |
children | b85e44974a08 |
comparison
equal
deleted
inserted
replaced
25596:15ce187b41b8 | 25597:0fdacd8f0cf3 |
---|---|
1434 if (argvars[0].v_type != VAR_LIST) | 1434 if (argvars[0].v_type != VAR_LIST) |
1435 { | 1435 { |
1436 emsg(_(e_listreq)); | 1436 emsg(_(e_listreq)); |
1437 return; | 1437 return; |
1438 } | 1438 } |
1439 rettv->v_type = VAR_STRING; | |
1439 if (argvars[0].vval.v_list == NULL) | 1440 if (argvars[0].vval.v_list == NULL) |
1440 return; | 1441 return; |
1442 | |
1441 if (argvars[1].v_type == VAR_UNKNOWN) | 1443 if (argvars[1].v_type == VAR_UNKNOWN) |
1442 sep = (char_u *)" "; | 1444 sep = (char_u *)" "; |
1443 else | 1445 else |
1444 sep = tv_get_string_chk(&argvars[1]); | 1446 sep = tv_get_string_chk(&argvars[1]); |
1445 | |
1446 rettv->v_type = VAR_STRING; | |
1447 | 1447 |
1448 if (sep != NULL) | 1448 if (sep != NULL) |
1449 { | 1449 { |
1450 ga_init2(&ga, (int)sizeof(char), 80); | 1450 ga_init2(&ga, (int)sizeof(char), 80); |
1451 list_join(&ga, argvars[0].vval.v_list, sep, TRUE, FALSE, 0); | 1451 list_join(&ga, argvars[0].vval.v_list, sep, TRUE, FALSE, 0); |
1966 if (argvars[0].v_type != VAR_LIST) | 1966 if (argvars[0].v_type != VAR_LIST) |
1967 semsg(_(e_listarg), sort ? "sort()" : "uniq()"); | 1967 semsg(_(e_listarg), sort ? "sort()" : "uniq()"); |
1968 else | 1968 else |
1969 { | 1969 { |
1970 l = argvars[0].vval.v_list; | 1970 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, |
1972 (char_u *)(sort ? N_("sort() argument") : N_("uniq() argument")), | 1972 (char_u *)(sort ? N_("sort() argument") : N_("uniq() argument")), |
1973 TRUE)) | 1973 TRUE)) |
1974 goto theend; | 1974 goto theend; |
1975 rettv_list_set(rettv, l); | 1975 rettv_list_set(rettv, l); |
1976 if (l == NULL) | |
1977 goto theend; | |
1976 CHECK_LIST_MATERIALIZE(l); | 1978 CHECK_LIST_MATERIALIZE(l); |
1977 | 1979 |
1978 len = list_len(l); | 1980 len = list_len(l); |
1979 if (len <= 1) | 1981 if (len <= 1) |
1980 goto theend; // short list sorts pretty quickly | 1982 goto theend; // short list sorts pretty quickly |
3108 return; | 3110 return; |
3109 } | 3111 } |
3110 | 3112 |
3111 if (argvars[0].v_type != VAR_LIST) | 3113 if (argvars[0].v_type != VAR_LIST) |
3112 semsg(_(e_listblobarg), "reverse()"); | 3114 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 | |
3114 && !value_check_lock(l->lv_lock, | 3120 && !value_check_lock(l->lv_lock, |
3115 (char_u *)N_("reverse() argument"), TRUE)) | 3121 (char_u *)N_("reverse() argument"), TRUE)) |
3116 { | 3122 { |
3117 if (l->lv_first == &range_list_item) | 3123 if (l->lv_first == &range_list_item) |
3118 { | 3124 { |
3119 varnumber_T new_start = l->lv_u.nonmat.lv_start | 3125 varnumber_T new_start = l->lv_u.nonmat.lv_start |
3120 + (l->lv_len - 1) * l->lv_u.nonmat.lv_stride; | 3126 + (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 |
3122 - (l->lv_u.nonmat.lv_end - l->lv_u.nonmat.lv_start); | 3128 - (l->lv_u.nonmat.lv_end - l->lv_u.nonmat.lv_start); |
3123 l->lv_u.nonmat.lv_start = new_start; | 3129 l->lv_u.nonmat.lv_start = new_start; |
3124 l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride; | 3130 l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride; |
3125 rettv_list_set(rettv, l); | 3131 return; |
3126 return; | 3132 } |
3127 } | 3133 li = l->lv_u.mat.lv_last; |
3128 li = l->lv_u.mat.lv_last; | 3134 l->lv_first = l->lv_u.mat.lv_last = NULL; |
3129 l->lv_first = l->lv_u.mat.lv_last = NULL; | 3135 l->lv_len = 0; |
3130 l->lv_len = 0; | 3136 while (li != NULL) |
3131 while (li != NULL) | 3137 { |
3132 { | 3138 ni = li->li_prev; |
3133 ni = li->li_prev; | 3139 list_append(l, li); |
3134 list_append(l, li); | 3140 li = ni; |
3135 li = ni; | 3141 } |
3136 } | 3142 l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1; |
3137 rettv_list_set(rettv, l); | 3143 } |
3138 l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1; | |
3139 } | 3144 } |
3140 } | 3145 } |
3141 | 3146 |
3142 /* | 3147 /* |
3143 * "reduce(list, { accumulator, element -> value } [, initial])" function | 3148 * "reduce(list, { accumulator, element -> value } [, initial])" function |