support cpying self-referenced table (#2076)

This commit is contained in:
hrsh7th
2024-11-02 13:54:35 +09:00
committed by GitHub
parent 7d4051064c
commit f17d9b4394
2 changed files with 53 additions and 15 deletions

View File

@@ -5,6 +5,33 @@ local misc = require('cmp.utils.misc')
describe('misc', function()
before_each(spec.before)
it('copy', function()
-- basic.
local tbl, copy
tbl = {
a = {
b = 1,
},
}
copy = misc.copy(tbl)
assert.are_not.equal(tbl, copy)
assert.are_not.equal(tbl.a, copy.a)
assert.are.same(tbl, copy)
-- self reference.
tbl = {
a = {
b = 1,
},
}
tbl.a.c = tbl.a
copy = misc.copy(tbl)
assert.are_not.equal(tbl, copy)
assert.are_not.equal(tbl.a, copy.a)
assert.are_not.equal(tbl.a.c, copy.a.c)
assert.are.same(tbl, copy)
end)
it('merge', function()
local merged
merged = misc.merge({