return function()local Q=require(script.Parent.Draft)local n=require(script.Parent.makeDraftSafeReadOnly)local u=require(script.Parent.constants)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \097 \100\114\097\102\116-\115\097\102\101 \118\101\114\115\105\111\110 \111\102 \116\104\101 \103\105\118\101\110 \102\117\110\099\116\105\111\110",function()local function u(Q,n)return rawget(Q,n)end local y=n(u)local V={foo={}}local h=Q.new(V)local b={}h.bar=b;(expect(y(h,"\102\111\111"))).to.equal(V.foo);(expect(y(h,"\098\097\114"))).to.equal(b)end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \097 \102\117\110\099\116\105\111\110 \116\104\097\116 \100\111\101\115 \110\111\116 \099\114\101\097\116\101 \097 \099\108\111\110\101 \111\102 \116\104\101 \100\114\097\102\116",function()local function y(Q,n)return rawget(Q,n)end local V=n(y)local h={foo="\098\097\114"}local b=Q.new(h)V(b,"\102\111\111");(expect(rawget(b,u.CLONE))).to.never.be.ok()end)it("\115\104\111\117\108\100 \097\108\108\111\119 \110\111\110-\100\114\097\102\116\115 \105\110 \116\104\101 \114\101\116\117\114\110\101\100 \100\114\097\102\116-\115\097\102\101 \102\117\110\099\116\105\111\110",function()local Q={"\102\111\111";"\098\097\114"}local u=n(table.find);(expect(function()u(Q,"\098\097\114")end)).to.never.throw();(expect(u(Q,"\098\097\114"))).to.equal(2)end)end
return function()
	local Draft = require(script.Parent.Draft)
	local makeDraftSafeReadOnly = require(script.Parent.makeDraftSafeReadOnly)
	local constants = require(script.Parent.constants)

	it("should return a draft-safe version of the given function", function()
		local function unsafe(t, k)
			return rawget(t, k)
		end

		local safe = makeDraftSafeReadOnly(unsafe)

		local original = { foo = {} }
		local draft = Draft.new(original)
		
		local bar = {}
		draft.bar = bar

		expect(safe(draft, "foo")).to.equal(original.foo)
		expect(safe(draft, "bar")).to.equal(bar)
	end)

	it("should return a function that does not create a clone of the draft", function()
		-- so that finishDraft returns the original table if the draft was not modified

		local function unsafe(t, k)
			return rawget(t, k)
		end

		local safe = makeDraftSafeReadOnly(unsafe)

		local original = { foo = "bar" }
		local draft = Draft.new(original)

		safe(draft, "foo")

		expect(rawget(draft, constants.CLONE)).to.never.be.ok()
	end)

	it("should allow non-drafts in the returned draft-safe function", function()
		local nonDraft = { "foo", "bar" }

		local safe = makeDraftSafeReadOnly(table.find)

		expect(function()
			safe(nonDraft, "bar")
		end).to.never.throw()
		
		expect(safe(nonDraft, "bar")).to.equal(2)
	end)
end
