Add cross-service refs case to serializePlace tests

This commit is contained in:
Kenneth Loeffler 2023-09-19 16:17:54 -07:00
parent 74d7f3d66f
commit 3e1314a0f3

View file

@ -2,30 +2,55 @@ local fs = require("@lune/fs")
local roblox = require("@lune/roblox")
local Instance = roblox.Instance
local game = Instance.new("DataModel")
-- Smoke tests
do
local game = Instance.new("DataModel")
local workspace = game:GetService("Workspace")
local workspace = game:GetService("Workspace")
local model = Instance.new("Model")
local part = Instance.new("Part")
local model = Instance.new("Model")
local part = Instance.new("Part")
part.Parent = model
model.Parent = workspace
part.Parent = model
model.Parent = workspace
local placeAsBinary = roblox.serializePlace(game)
local placeAsXml = roblox.serializePlace(game, true)
local placeAsBinary = roblox.serializePlace(game)
local placeAsXml = roblox.serializePlace(game, true)
fs.writeFile("bin/temp-place.rbxl", placeAsBinary)
fs.writeFile("bin/temp-place.rbxlx", placeAsXml)
fs.writeFile("bin/temp-place.rbxl", placeAsBinary)
fs.writeFile("bin/temp-place.rbxlx", placeAsXml)
local savedFileBinary = fs.readFile("bin/temp-place.rbxl")
local savedFileXml = fs.readFile("bin/temp-place.rbxlx")
local savedFileBinary = fs.readFile("bin/temp-place.rbxl")
local savedFileXml = fs.readFile("bin/temp-place.rbxlx")
local savedBinary = roblox.deserializePlace(savedFileBinary)
local savedXml = roblox.deserializePlace(savedFileXml)
local savedBinary = roblox.deserializePlace(savedFileBinary)
local savedXml = roblox.deserializePlace(savedFileXml)
assert(savedBinary.Name ~= "ROOT")
assert(savedXml.Name ~= "ROOT")
assert(savedBinary.Name ~= "ROOT")
assert(savedXml.Name ~= "ROOT")
assert(savedBinary.ClassName == "DataModel")
assert(savedXml.ClassName == "DataModel")
assert(savedBinary.ClassName == "DataModel")
assert(savedXml.ClassName == "DataModel")
end
-- Ensure Ref properties are preserved across services
do
local game = Instance.new("DataModel")
local ReplicatedStorage = Instance.new("ReplicatedStorage")
local Workspace = Instance.new("Workspace")
Workspace.Parent = game
ReplicatedStorage.Parent = game
local part = Instance.new("Part")
part.Parent = ReplicatedStorage
local objectValue = Instance.new("ObjectValue")
objectValue.Value = part
objectValue.Parent = Workspace
local serialized = roblox.serializePlace(game)
local deserialized = roblox.deserializePlace(serialized)
assert(deserialized.Workspace.ObjectValue.Value == deserialized.ReplicatedStorage.Part)
end