mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 09:48:19 +00:00
eval/typval: Add tv_list_equal() tests, compare NULL lists equal
This commit is contained in:
@@ -623,13 +623,12 @@ bool tv_list_equal(list_T *const l1, list_T *const l2, const bool ic,
|
|||||||
const bool recursive)
|
const bool recursive)
|
||||||
FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
if (l1 == NULL || l2 == NULL) {
|
|
||||||
// FIXME? compare empty list with NULL list equal
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (l1 == l2) {
|
if (l1 == l2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (l1 == NULL || l2 == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (tv_list_len(l1) != tv_list_len(l2)) {
|
if (tv_list_len(l1) != tv_list_len(l2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -57,12 +57,6 @@ describe('NULL', function()
|
|||||||
null_list_expr_test('does not crash extend()', 'extend(L, [1])', 0, 0)
|
null_list_expr_test('does not crash extend()', 'extend(L, [1])', 0, 0)
|
||||||
-- FIXME extend() should not return 0 at all
|
-- FIXME extend() should not return 0 at all
|
||||||
null_list_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, 0)
|
null_list_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, 0)
|
||||||
-- FIXME Should return 1
|
|
||||||
null_list_expr_test('is equal to itself', 'L == L', 0, 0)
|
|
||||||
-- FIXME Should return 0
|
|
||||||
null_list_expr_test('is not not equal to itself', 'L != L', 0, 1)
|
|
||||||
-- FIXME Should return 1
|
|
||||||
null_list_expr_test('counts correctly', 'count([L], L)', 0, 0)
|
|
||||||
-- FIXME should be accepted by inputlist()
|
-- FIXME should be accepted by inputlist()
|
||||||
null_list_expr_test('is accepted as an empty list by inputlist()',
|
null_list_expr_test('is accepted as an empty list by inputlist()',
|
||||||
'[feedkeys("\\n"), inputlist(L)]', 'E686: Argument of inputlist() must be a List', {0, 0})
|
'[feedkeys("\\n"), inputlist(L)]', 'E686: Argument of inputlist() must be a List', {0, 0})
|
||||||
@@ -133,5 +127,8 @@ describe('NULL', function()
|
|||||||
null_list_expr_test('can be added to itself', '(L + L) is L', 0, 1)
|
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', '([1] + L)', 0, {1})
|
||||||
null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])', 0, {1})
|
null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])', 0, {1})
|
||||||
|
null_list_expr_test('is equal to itself', 'L == L', 0, 1)
|
||||||
|
null_list_expr_test('is not not equal to itself', 'L != L', 0, 0)
|
||||||
|
null_list_expr_test('counts correctly', 'count([L], L)', 0, 1)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@@ -1031,7 +1031,6 @@ describe('typval.c', function()
|
|||||||
eq(empty_list, typvalt2lua(rettv4))
|
eq(empty_list, typvalt2lua(rettv4))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
|
||||||
describe('join()', function()
|
describe('join()', function()
|
||||||
local function list_join(l, sep, ret)
|
local function list_join(l, sep, ret)
|
||||||
local ga = ga_alloc()
|
local ga = ga_alloc()
|
||||||
@@ -1040,7 +1039,7 @@ describe('typval.c', function()
|
|||||||
else return ffi.string(ga.ga_data)
|
else return ffi.string(ga.ga_data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it('works', function()
|
itp('works', function()
|
||||||
local l
|
local l
|
||||||
l = list('boo', 'far')
|
l = list('boo', 'far')
|
||||||
eq('boo far', list_join(l, ' '))
|
eq('boo far', list_join(l, ' '))
|
||||||
@@ -1066,4 +1065,74 @@ describe('typval.c', function()
|
|||||||
lib.tv_list_free(l, true)
|
lib.tv_list_free(l, true)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
describe('equal()', function()
|
||||||
|
itp('compares empty and NULL lists correctly', function()
|
||||||
|
local l = list()
|
||||||
|
local l2 = list()
|
||||||
|
|
||||||
|
-- NULL lists are not equal to empty lists
|
||||||
|
eq(false, lib.tv_list_equal(l, nil, true, false))
|
||||||
|
eq(false, lib.tv_list_equal(nil, l, false, false))
|
||||||
|
eq(false, lib.tv_list_equal(nil, l, false, true))
|
||||||
|
eq(false, lib.tv_list_equal(l, nil, true, true))
|
||||||
|
|
||||||
|
-- Yet NULL lists are equal themselves
|
||||||
|
eq(true, lib.tv_list_equal(nil, nil, true, false))
|
||||||
|
eq(true, lib.tv_list_equal(nil, nil, false, false))
|
||||||
|
eq(true, lib.tv_list_equal(nil, nil, false, true))
|
||||||
|
eq(true, lib.tv_list_equal(nil, nil, true, true))
|
||||||
|
|
||||||
|
-- As well as empty lists
|
||||||
|
eq(true, lib.tv_list_equal(l, l, true, false))
|
||||||
|
eq(true, lib.tv_list_equal(l, l2, false, false))
|
||||||
|
eq(true, lib.tv_list_equal(l2, l, false, true))
|
||||||
|
eq(true, lib.tv_list_equal(l2, l2, true, true))
|
||||||
|
end)
|
||||||
|
-- Must not use recursive=true argument in the following tests because it
|
||||||
|
-- indicates that tv_equal_recurse_limit and recursive_cnt were set which
|
||||||
|
-- is essential. This argument will be set when comparing inner lists.
|
||||||
|
itp('compares lists correctly when case is not ignored', function()
|
||||||
|
local l1 = list('abc', {1, 2, 'Abc'}, 'def')
|
||||||
|
local l2 = list('abc', {1, 2, 'Abc'})
|
||||||
|
local l3 = list('abc', {1, 2, 'Abc'}, 'Def')
|
||||||
|
local l4 = list('abc', {1, 2, 'Abc', 4}, 'def')
|
||||||
|
local l5 = list('Abc', {1, 2, 'Abc'}, 'def')
|
||||||
|
local l6 = list('abc', {1, 2, 'Abc'}, 'def')
|
||||||
|
local l7 = list('abc', {1, 2, 'abc'}, 'def')
|
||||||
|
local l8 = list('abc', nil, 'def')
|
||||||
|
local l9 = list('abc', {1, 2, nil}, 'def')
|
||||||
|
|
||||||
|
eq(true, lib.tv_list_equal(l1, l1, false, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l2, false, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l3, false, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l4, false, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l5, false, false))
|
||||||
|
eq(true, lib.tv_list_equal(l1, l6, false, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l7, false, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l8, false, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l9, false, false))
|
||||||
|
end)
|
||||||
|
itp('compares lists correctly when case is ignored', function()
|
||||||
|
local l1 = list('abc', {1, 2, 'Abc'}, 'def')
|
||||||
|
local l2 = list('abc', {1, 2, 'Abc'})
|
||||||
|
local l3 = list('abc', {1, 2, 'Abc'}, 'Def')
|
||||||
|
local l4 = list('abc', {1, 2, 'Abc', 4}, 'def')
|
||||||
|
local l5 = list('Abc', {1, 2, 'Abc'}, 'def')
|
||||||
|
local l6 = list('abc', {1, 2, 'Abc'}, 'def')
|
||||||
|
local l7 = list('abc', {1, 2, 'abc'}, 'def')
|
||||||
|
local l8 = list('abc', nil, 'def')
|
||||||
|
local l9 = list('abc', {1, 2, nil}, 'def')
|
||||||
|
|
||||||
|
eq(true, lib.tv_list_equal(l1, l1, true, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l2, true, false))
|
||||||
|
eq(true, lib.tv_list_equal(l1, l3, true, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l4, true, false))
|
||||||
|
eq(true, lib.tv_list_equal(l1, l5, true, false))
|
||||||
|
eq(true, lib.tv_list_equal(l1, l6, true, false))
|
||||||
|
eq(true, lib.tv_list_equal(l1, l7, true, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l8, true, false))
|
||||||
|
eq(false, lib.tv_list_equal(l1, l9, true, false))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user