Working on diff xmission

This commit is contained in:
2021-08-23 23:34:30 -04:00
parent 7581ac7278
commit 2be6c2c58e
10 changed files with 702 additions and 149 deletions

View File

@@ -6,5 +6,6 @@
inspect.lua
ut-table.lua
ut-globaldb.lua
ut-tablecmp.lua
player.lua
login.lua

View File

@@ -0,0 +1,71 @@
local tdc = table.diffcompare
function unittests.tablecmp()
-- No differences in these simple-valued tables.
assert(tdc(nil, {a=true}, nil, {a=true}) == "")
assert(tdc(nil, {a=5}, nil, {a=5}) == "");
assert(tdc(nil, {a="foo"}, nil, {a="foo"}) == "")
-- Test transmission of missing simple values.
assert(tdc(nil, {a=true}, nil, {}) == "a=true;")
assert(tdc(nil, {a=5}, nil, {}) == "a=5;");
assert(tdc(nil, {a="foo"}, nil, {}) == "a=foo;")
-- Test the replacement of simple values.
assert(tdc(nil, {a=true}, nil, {a=false}) == "a=true;")
assert(tdc(nil, {a=5}, nil, {a=4}) == "a=5;");
assert(tdc(nil, {a="foo"}, nil, {a="bar"}) == "a=foo;")
-- Test the clearing of values.
assert(tdc(nil, {}, nil, {a=true}) == "a=nil;")
assert(tdc(nil, {}, nil, {a=5}) == "a=nil;");
assert(tdc(nil, {}, nil, {a="foo"}) == "a=nil;")
-- Try boolean keys.
assert(tdc(nil, {[true]=3}, nil, {}) == "true=3;")
assert(tdc(nil, {}, nil, {[true]=3}) == "true=nil;")
-- Try number keys.
assert(tdc(nil, {[7]=3}, nil, {}) == "7=3;")
assert(tdc(nil, {}, nil, {[7]=3}) == "7=nil;")
-- Try a table with multiple keys.
assert(tdc(nil, {a=4, b=5, c=6}, nil, {b=5, c=7, d=8}) == "a=4;c=6;d=nil;")
-- Nonsortable keys should be ignored (no diffs).
assert(tdc(nil, {[{}]=3}, nil, {}) == "")
-- Try a table containing a class.
assert(tdc(nil, {a=deque}, nil, {}) == "a=class deque;")
-- Try a table containing a pointer to the global environment.
assert(tdc(nil, {a=_G}, nil, {}) == "a=globals;")
-- GlobalDB tables should be forced to NIL.
assert(tdc(nil, {a=global("foo")}, nil, {a=global("foo")}) == "a=nil;");
assert(tdc(nil, {}, nil, {a=global("foo")}) == "a=nil;");
assert(tdc(nil, {a=global("foo")}, nil, {}) == "");
-- Set up some numbered tables for tests involving such.
local mtab10 = {}
local stab10 = {}
local mtab11 = {}
local stab11 = {}
local mtnmap = {}
local stnmap = {}
mtnmap[mtab10] = 10
stnmap[stab10] = 10
mtnmap[mtab11] = 11
stnmap[stab11] = 11
-- confirm that numbered tables are being transmitted.
assert(tdc(mtnmap, {a=mtab10}, stnmap, {}) == "a=table 10;")
assert(tdc(mtnmap, {a=mtab10}, stnmap, {a=stab10}) == "")
assert(tdc(mtnmap, {a=3}, stnmap, {a=stab10}) == "a=3;")
assert(tdc(mtnmap, {}, stnmap, {a=stab10}) == "a=nil;")
-- we're not going to test tangibles
-- creating tangibles here is too difficult.
end