Fix diff xmit of metatables

This commit is contained in:
2021-09-01 18:13:30 -04:00
parent 3e9403d015
commit 5cefa4f1e2
2 changed files with 31 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ local tdc = table.diffcompare
local tda = table.diffapply
function unittests.diffcompare()
local mtab = nil
local rtab = nil
-- No differences in these simple-valued tables.
@@ -73,6 +74,15 @@ function unittests.diffcompare()
assert(tdc(mtnmap, {a={}}, stnmap, {}) == "")
assert(tdc(mtnmap, {a={}}, stnmap, {a=3}) == "a=nil;")
-- transmit a correction to the metatable.
mtab={}
stab={}
setmetatable(mtab, mtab10)
setmetatable(stab, stab10)
assert(tdc(mtnmap, mtab, stnmap, {}) == "nil=table 10;")
assert(tdc(mtnmap, mtab, stnmap, stab) == "")
assert(tdc(mtnmap, {}, stnmap, stab) == "nil=nil;")
-- we're not going to test tangibles
-- creating tangibles here is too difficult.
end
@@ -83,6 +93,8 @@ function unittests.diffapply()
local tnmap={}
tnmap[tab10] = 10
tnmap[tab11] = 11
local mtab=nil
local stab=nil
-- verify some simple values.
assert(tda(tnmap, {a=1}, {}))
@@ -114,6 +126,20 @@ function unittests.diffapply()
assert(not tda({}, {a={}}, rtab))
assert(rtab.a == nil)
-- transmit a correction to the metatable
mtab={}
rtab={}
setmetatable(mtab, tab10)
assert(tda(tnmap, mtab, rtab))
assert(getmetatable(rtab) == tab10)
-- transmit a clearing of the metatable
mtab={}
rtab={}
setmetatable(rtab, tab10)
assert(tda(tnmap, mtab, rtab))
assert(getmetatable(rtab) == nil)
-- don't test tangibles.
end