local A=require(script.Parent.Parent.lib.t)local b=A.tuple(A.optional(A.table),A.optional(A.table))local function O(A,O)assert(b(A,O))local w=A and A.ClassName local X=Instance.new(w or"\070\111\108\100\101\114")if A then for A,b in pairs(A)do if A~="\067\108\097\115\115\078\097\109\101"then X[A]=b end end end if O then for A,b in pairs(O)do b.Name=A b.Parent=X end end return X end return O
--[[
	Allows you to easily construct complex hierarchies of instances.

	This has been particularly useful in unit tests, as we can easily fake the
	DataModel.

	Usage:

		local mockDataModel = new({
			Name = "game"
		}, {
			ServerScriptService = new(nil, {
				Script = Instance.new("Script")
			}),
			ReplicatedStorage = new(nil, {
				Module = Instance.new("ModuleScript")
			})
		})
]]

local t = require(script.Parent.Parent.lib.t)

local newCheck = t.tuple(t.optional(t.table), t.optional(t.table))
local function new(props, children)
	assert(newCheck(props, children))

	local className = props and props.ClassName
	local instance = Instance.new(className or "Folder")

	if props then
		for prop, value in pairs(props) do
			if prop ~= "ClassName" then
				instance[prop] = value
			end
		end
	end

	if children then
		for name, child in pairs(children) do
			child.Name = name
			child.Parent = instance
		end
	end

	return instance
end

return new
