diff options
author | ZyX <kp-pav@yandex.ru> | 2016-10-02 04:34:30 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-29 10:08:06 +0300 |
commit | b3672ae2fced4715963442d2e19048f8fadbe0b8 (patch) | |
tree | 87a674a959a32382349157d37471e414e158d274 | |
parent | 4f9e7844272335943c075b9444934f77d3cba234 (diff) | |
download | rneovim-b3672ae2fced4715963442d2e19048f8fadbe0b8.tar.gz rneovim-b3672ae2fced4715963442d2e19048f8fadbe0b8.tar.bz2 rneovim-b3672ae2fced4715963442d2e19048f8fadbe0b8.zip |
eval/typval: Add tv_list_equal() tests, compare NULL lists equal
-rw-r--r-- | src/nvim/eval/typval.c | 7 | ||||
-rw-r--r-- | test/functional/eval/null_spec.lua | 9 | ||||
-rw-r--r-- | test/unit/eval/typval_spec.lua | 133 |
3 files changed, 107 insertions, 42 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 746cbbfe1c..b0b95e955f 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -623,13 +623,12 @@ bool tv_list_equal(list_T *const l1, list_T *const l2, const bool ic, const bool recursive) FUNC_ATTR_WARN_UNUSED_RESULT { - if (l1 == NULL || l2 == NULL) { - // FIXME? compare empty list with NULL list equal - return false; - } if (l1 == l2) { return true; } + if (l1 == NULL || l2 == NULL) { + return false; + } if (tv_list_len(l1) != tv_list_len(l2)) { return false; } diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index ccdd1ce34c..e587ede319 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -57,12 +57,6 @@ describe('NULL', function() null_list_expr_test('does not crash extend()', 'extend(L, [1])', 0, 0) -- FIXME extend() should not return 0 at all 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() 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}) @@ -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 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('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) diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 382ec79429..8740e9eb1f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1031,39 +1031,108 @@ describe('typval.c', function() eq(empty_list, typvalt2lua(rettv4)) end) end) - end) - describe('join()', function() - local function list_join(l, sep, ret) - local ga = ga_alloc() - eq(ret or OK, lib.tv_list_join(ga, l, sep)) - if ga.ga_data == nil then return '' - else return ffi.string(ga.ga_data) + describe('join()', function() + local function list_join(l, sep, ret) + local ga = ga_alloc() + eq(ret or OK, lib.tv_list_join(ga, l, sep)) + if ga.ga_data == nil then return '' + else return ffi.string(ga.ga_data) + end end - end - it('works', function() - local l - l = list('boo', 'far') - eq('boo far', list_join(l, ' ')) - eq('boofar', list_join(l, '')) - - l = list('boo') - eq('boo', list_join(l, ' ')) - - l = list() - eq('', list_join(l, ' ')) - - l = list({}, 'far') - eq('{} far', list_join(l, ' ')) - - local recursive_list = {} - recursive_list[1] = recursive_list - l = ffi.gc(list(recursive_list, 'far'), nil) - eq('[[...@0]] far', list_join(l, ' ')) - - local recursive_l = l.lv_first.li_tv.vval.v_list - local recursive_li = recursive_l.lv_first - lib.tv_list_item_remove(recursive_l, recursive_li) - lib.tv_list_free(l, true) + itp('works', function() + local l + l = list('boo', 'far') + eq('boo far', list_join(l, ' ')) + eq('boofar', list_join(l, '')) + + l = list('boo') + eq('boo', list_join(l, ' ')) + + l = list() + eq('', list_join(l, ' ')) + + l = list({}, 'far') + eq('{} far', list_join(l, ' ')) + + local recursive_list = {} + recursive_list[1] = recursive_list + l = ffi.gc(list(recursive_list, 'far'), nil) + eq('[[...@0]] far', list_join(l, ' ')) + + local recursive_l = l.lv_first.li_tv.vval.v_list + local recursive_li = recursive_l.lv_first + lib.tv_list_item_remove(recursive_l, recursive_li) + lib.tv_list_free(l, true) + 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) |