local ____lualib = require("lualib_bundle")
local Map = ____lualib.Map
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local oldTableHasUpdatedValue, newTableHasSameValue, oldTableHasUpdatedValueFromNull, oldTableHasSerializedIsaacAPIClass, oldTableHasFilledChildTable, oldTableHasFilledMap, oldTableHasFilledDefaultMap, oldTableHasVector, oldTableHasVectorSerialized, oldTableHasRNG, oldTableHasRNGSerialized
local ____DefaultMap = require("classes.DefaultMap")
local DefaultMap = ____DefaultMap.DefaultMap
local ____SerializationType = require("enums.SerializationType")
local SerializationType = ____SerializationType.SerializationType
local ____deepCopy = require("functions.deepCopy")
local deepCopy = ____deepCopy.deepCopy
local ____log = require("functions.log")
local logAndPrint = ____log.logAndPrint
local ____merge = require("functions.merge")
local merge = ____merge.merge
local ____rng = require("functions.rng")
local isRNG = ____rng.isRNG
local newRNG = ____rng.newRNG
local ____serialization = require("functions.serialization")
local isSerializedIsaacAPIClass = ____serialization.isSerializedIsaacAPIClass
local ____vector = require("functions.vector")
local isVector = ____vector.isVector
local serializeVector = ____vector.serializeVector
function oldTableHasUpdatedValue(self)
    local key = "foo"
    local oldValue = "bar"
    local newValue = "baz"
    local oldTable = {foo = oldValue}
    local newTable = {foo = newValue}
    merge(nil, oldTable, newTable, "oldTableHasUpdatedValue")
    local oldTableValue = oldTable[key]
    if oldTableValue ~= newValue then
        error("The old table does not have a value of: " .. newValue)
    end
end
function newTableHasSameValue(self)
    local key = "foo"
    local oldValue = "bar"
    local newValue = "baz"
    local oldTable = {foo = oldValue}
    local newTable = {foo = newValue}
    merge(nil, oldTable, newTable, "newTableHasSameValue")
    local newTableValue = newTable[key]
    if newTableValue ~= newValue then
        error("The new table does not have a value of: " .. newValue)
    end
end
function oldTableHasUpdatedValueFromNull(self)
    local key = "foo"
    local newValue = "baz"
    local oldTable = {foo = nil}
    local newTable = {foo = newValue}
    merge(nil, oldTable, newTable, "oldTableHasUpdatedValueFromNull")
    local oldTableValue = oldTable[key]
    if oldTableValue ~= newValue then
        error("The old table does not have a value of: " .. newValue)
    end
end
function oldTableHasSerializedIsaacAPIClass(self)
    local x = 50
    local y = 60
    local vector = Vector(x, y)
    local vectorSerialized = serializeVector(nil, vector)
    if not isSerializedIsaacAPIClass(nil, vectorSerialized) then
        error("The \"isSerializedIsaacAPIClass\" function says that a serialized vector is not serialized.")
    end
end
function oldTableHasFilledChildTable(self)
    local key = "foo"
    local newValue = "baz"
    local oldTable = {foo = nil}
    local foo = {bar = newValue}
    local newTable = {foo = foo}
    merge(nil, oldTable, newTable, "oldTableHasFilledChildTable")
    local oldTableValue = oldTable[key]
    if oldTableValue == nil then
        error(("The old table's key of \"" .. key) .. "\" was not filled.")
    end
    if oldTableValue.bar ~= newValue then
        error("The old table's key of \"bar\" was not filled.")
    end
end
function oldTableHasFilledMap(self)
    local fakeV = {run = {myMap = __TS__New(Map)}}
    local saveData = {run = {myMap = __TS__New(Map, {{"foo1", "bar1"}, {"foo2", "bar2"}, {"foo3", "bar3"}})}}
    local serializedSaveData = deepCopy(nil, saveData, SerializationType.SERIALIZE)
    merge(nil, fakeV, serializedSaveData, "oldTableHasFilledMap")
    local expectedSize = 3
    if fakeV.run.myMap.size ~= expectedSize then
        error((("The size of the merged map was equal to " .. tostring(fakeV.run.myMap.size)) .. ", but it should be equal to: ") .. tostring(expectedSize))
    end
    do
        local key = "foo1"
        local expectedValue = "bar1"
        local value = fakeV.run.myMap:get(key)
        if value ~= expectedValue then
            error((((("The old table's map key of \"" .. key) .. "\" was not equal to \"") .. expectedValue) .. "\" and was instead equal to: ") .. tostring(value))
        end
    end
    do
        local key = "foo2"
        local expectedValue = "bar2"
        local value = fakeV.run.myMap:get(key)
        if value ~= expectedValue then
            error((((("The old table's map key of \"" .. key) .. "\" was not equal to \"") .. expectedValue) .. "\" and was instead equal to: ") .. tostring(value))
        end
    end
    do
        local key = "foo3"
        local expectedValue = "bar3"
        local value = fakeV.run.myMap:get(key)
        if value ~= expectedValue then
            error((((("The old table's map key of \"" .. key) .. "\" was not equal to \"") .. expectedValue) .. "\" and was instead equal to: ") .. tostring(value))
        end
    end
end
function oldTableHasFilledDefaultMap(self)
    local fakeV = {run = {myDefaultMap = __TS__New(DefaultMap, "default")}}
    local saveData = {run = {myDefaultMap = __TS__New(DefaultMap, "default", {{"foo1", "bar1"}, {"foo2", "bar2"}, {"foo3", "bar3"}})}}
    local serializedSaveData = deepCopy(nil, saveData, SerializationType.SERIALIZE)
    merge(nil, fakeV, serializedSaveData, "oldTableHasFilledDefaultMap")
    local expectedSize = 3
    if fakeV.run.myDefaultMap.size ~= expectedSize then
        error((("The size of the merged default map was equal to " .. tostring(fakeV.run.myDefaultMap.size)) .. ", but it should be equal to: ") .. tostring(expectedSize))
    end
    do
        local key = "foo1"
        local expectedValue = "bar1"
        local value = fakeV.run.myDefaultMap:get(key)
        if value ~= expectedValue then
            error((((("The old table's default map key of \"" .. key) .. "\" was not equal to \"") .. expectedValue) .. "\" and was instead equal to: ") .. tostring(value))
        end
    end
    do
        local key = "foo2"
        local expectedValue = "bar2"
        local value = fakeV.run.myDefaultMap:get(key)
        if value ~= expectedValue then
            error((((("The old table's default map key of \"" .. key) .. "\" was not equal to \"") .. expectedValue) .. "\" and was instead equal to: ") .. tostring(value))
        end
    end
    do
        local key = "foo3"
        local expectedValue = "bar3"
        local value = fakeV.run.myDefaultMap:get(key)
        if value ~= expectedValue then
            error((((("The old table's default map key of \"" .. key) .. "\" was not equal to \"") .. expectedValue) .. "\" and was instead equal to: ") .. tostring(value))
        end
    end
end
function oldTableHasVector(self)
    local key = "foo"
    local x = 50
    local y = 60
    local newValue = Vector(x, y)
    local oldTable = {foo = nil}
    local foo = {bar = newValue}
    local newTable = {foo = foo}
    merge(nil, oldTable, newTable, "oldTableHasVector")
    local oldTableValue = oldTable[key]
    if oldTableValue == nil then
        error(("The old table's key of \"" .. key) .. "\" was not filled.")
    end
    if oldTableValue.bar.X ~= x then
        error("The old table's value for \"x\" does not match: " .. tostring(x))
    end
    if oldTableValue.bar.Y ~= y then
        error("The old table's value for \"y\" does not match: " .. tostring(y))
    end
    if not isVector(nil, oldTableValue.bar) then
        error("The old table's value is not a Vector object.")
    end
end
function oldTableHasVectorSerialized(self)
    local key = "foo"
    local x = 50
    local y = 60
    local newValue = Vector(x, y)
    local oldTable = {foo = nil}
    local foo = {bar = newValue}
    local newTable = {foo = foo}
    local newTableSerialized = deepCopy(nil, newTable, SerializationType.SERIALIZE, "oldTableHasVectorSerialized")
    merge(nil, oldTable, newTableSerialized, "oldTableHasVectorSerialized")
    local oldTableValue = oldTable[key]
    if oldTableValue == nil then
        error(("The old table's key of \"" .. key) .. "\" was not filled.")
    end
    if oldTableValue.bar.X ~= x then
        error("The old table's value for \"x\" does not match: " .. tostring(x))
    end
    if oldTableValue.bar.Y ~= y then
        error("The old table's value for \"y\" does not match: " .. tostring(y))
    end
    if not isVector(nil, oldTableValue.bar) then
        error("The old table's value is not a Vector object (during the serialized test).")
    end
end
function oldTableHasRNG(self)
    local key = "foo"
    local seed = 50
    local newValue = newRNG(nil, seed)
    local oldTable = {foo = nil}
    local foo = {bar = newValue}
    local newTable = {foo = foo}
    merge(nil, oldTable, newTable, "oldTableHasRNG")
    local oldTableValue = oldTable[key]
    if oldTableValue == nil then
        error(("The old table's key of \"" .. key) .. "\" was not filled.")
    end
    if not isRNG(nil, oldTableValue.bar) then
        error("The old table's value is not an RNG object.")
    end
    local newSeed = oldTableValue.bar:GetSeed()
    if newSeed ~= seed then
        error("The old table's seed not match: " .. tostring(seed))
    end
end
function oldTableHasRNGSerialized(self)
    local key = "foo"
    local seed = 50
    local newValue = newRNG(nil, seed)
    local oldTable = {foo = nil}
    local foo = {bar = newValue}
    local newTable = {foo = foo}
    local newTableSerialized = deepCopy(nil, newTable, SerializationType.SERIALIZE, "oldTableHasRNGSerialized")
    merge(nil, oldTable, newTableSerialized, "oldTableHasRNGSerialized")
    local oldTableValue = oldTable[key]
    if oldTableValue == nil then
        error(("The old table's key of \"" .. key) .. "\" was not filled.")
    end
    if not isRNG(nil, oldTableValue.bar) then
        error("The old table's value is not an RNG object (during the serialized test).")
    end
    local newSeed = oldTableValue.bar:GetSeed()
    if newSeed ~= seed then
        error("The old table's seed not match: " .. tostring(seed))
    end
end
--- Run the suite of tests that prove that the "merge" function works properly.
-- 
-- This function is only useful if you are troubleshooting the save data manager.
function ____exports.runMergeTests(self)
    oldTableHasUpdatedValue(nil)
    newTableHasSameValue(nil)
    oldTableHasUpdatedValueFromNull(nil)
    oldTableHasSerializedIsaacAPIClass(nil)
    oldTableHasFilledChildTable(nil)
    oldTableHasFilledMap(nil)
    oldTableHasFilledDefaultMap(nil)
    oldTableHasVector(nil)
    oldTableHasVectorSerialized(nil)
    oldTableHasRNG(nil)
    oldTableHasRNGSerialized(nil)
    local successText = "All merge tests passed!"
    logAndPrint(nil, successText)
end
return ____exports
