mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
eval/typval: Make tv_list_concat handle NULL lists correctly
Fixes some FIXMEs in eval/null_spec.lua.
This commit is contained in:
parent
82e6cac5f9
commit
f80a00469f
@ -498,20 +498,25 @@ void tv_list_extend(list_T *const l1, list_T *const l2,
|
|||||||
int tv_list_concat(list_T *const l1, list_T *const l2, typval_T *const tv)
|
int tv_list_concat(list_T *const l1, list_T *const l2, typval_T *const tv)
|
||||||
FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
if (l1 == NULL || l2 == NULL) {
|
list_T *l;
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make a copy of the first list.
|
|
||||||
list_T *const l = tv_list_copy(NULL, l1, false, 0);
|
|
||||||
if (l == NULL) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
tv->v_type = VAR_LIST;
|
tv->v_type = VAR_LIST;
|
||||||
tv->vval.v_list = l;
|
|
||||||
|
|
||||||
// append all items from the second list
|
if (l1 == NULL && l2 == NULL) {
|
||||||
tv_list_extend(l, l2, NULL);
|
l = NULL;
|
||||||
|
} else if (l1 == NULL) {
|
||||||
|
l = tv_list_copy(NULL, l2, false, 0);
|
||||||
|
} else {
|
||||||
|
l = tv_list_copy(NULL, l1, false, 0);
|
||||||
|
if (l != NULL && l2 != NULL) {
|
||||||
|
tv_list_extend(l, l2, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (l == NULL && !(l1 == NULL && l2 == NULL)) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
tv->vval.v_list = l;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,14 +61,6 @@ describe('NULL', function()
|
|||||||
null_list_expr_test('is equal to itself', 'L == L', 0, 0)
|
null_list_expr_test('is equal to itself', 'L == L', 0, 0)
|
||||||
-- FIXME Should return 0
|
-- FIXME Should return 0
|
||||||
null_list_expr_test('is not not equal to itself', 'L != L', 0, 1)
|
null_list_expr_test('is not not equal to itself', 'L != L', 0, 1)
|
||||||
-- FIXME Should return empty list
|
|
||||||
null_list_expr_test('can be added to itself', '(L + L)', 'E15: Invalid expression: (L + L)', nil)
|
|
||||||
-- FIXME Should return [1]
|
|
||||||
null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])',
|
|
||||||
'E15: Invalid expression: (L + [1])', nil)
|
|
||||||
-- FIXME Should return [1]
|
|
||||||
null_list_expr_test('can be added to non-empty list', '([1] + L)',
|
|
||||||
'E15: Invalid expression: ([1] + L)', nil)
|
|
||||||
-- FIXME Should return 1
|
-- FIXME Should return 1
|
||||||
null_list_expr_test('counts correctly', 'count([L], L)', 0, 0)
|
null_list_expr_test('counts correctly', 'count([L], L)', 0, 0)
|
||||||
-- FIXME should be accepted by inputlist()
|
-- FIXME should be accepted by inputlist()
|
||||||
@ -137,5 +129,9 @@ describe('NULL', function()
|
|||||||
null_list_expr_test('is stringified correctly', 'string(L)', 0, '[]')
|
null_list_expr_test('is stringified correctly', 'string(L)', 0, '[]')
|
||||||
null_list_expr_test('is JSON encoded correctly', 'json_encode(L)', 0, '[]')
|
null_list_expr_test('is JSON encoded correctly', 'json_encode(L)', 0, '[]')
|
||||||
null_list_test('does not crash lockvar', 'lockvar! L', 0)
|
null_list_test('does not crash lockvar', 'lockvar! L', 0)
|
||||||
|
null_list_expr_test('can be added to itself', '(L + L)', 0, {})
|
||||||
|
null_list_expr_test('can be added to itself', '(L + L) is L', 0, 1)
|
||||||
|
null_list_expr_test('can be added to non-empty list', '([1] + L)', 0, {1})
|
||||||
|
null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])', 0, {1})
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user