local d=require(script.Parent.assertDeepEqual)local function o(o)local H={}H.callCount=0 H.values={}H.valuesLength=0 H.value=function(...)H.callCount=H.callCount+1 H.values={...}H.valuesLength=select("\035",...)if o~=nil then return o(...)end return nil end H.assertCalledWith=function(d,...)local o=select("\035",...)if H.valuesLength~=o then error(("\069\120\112\101\099\116\101\100 \037\100 \097\114\103\117\109\101\110\116\115\044 \098\117\116 \119\097\115 \099\097\108\108\101\100 \119\105\116\104 \037\100 \097\114\103\117\109\101\110\116\115"):format(H.valuesLength,o),2)end for d=1,o,1 do local o=select(d,...)assert(H.values[d]==o,"\118\097\108\117\101 \100\105\102\102\101\114\115")end end H.assertCalledWithDeepEqual=function(o,...)local E=select("\035",...)if H.valuesLength~=E then error(("\069\120\112\101\099\116\101\100 \037\100 \097\114\103\117\109\101\110\116\115\044 \098\117\116 \119\097\115 \099\097\108\108\101\100 \119\105\116\104 \037\100 \097\114\103\117\109\101\110\116\115"):format(H.valuesLength,E),2)end for o=1,E,1 do local E=select(o,...)d(H.values[o],E)end end H.captureValues=function(d,...)local o=select("\035",...)local E={}assert(H.valuesLength==o,"\108\101\110\103\116\104 \111\102 \101\120\112\101\099\116\101\100 \118\097\108\117\101\115 \100\105\102\102\101\114\115 \102\114\111\109 \115\116\111\114\101\100 \118\097\108\117\101\115")for d=1,o,1 do local o=select(d,...)E[o]=H.values[d]end return E end setmetatable(H,{__index=function(d,o)error(("\037\113 \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 \115\112\121"):format(o))end})return H end return o
--[[
	A utility used to create a function spy that can be used to robustly test
	that functions are invoked the correct number of times and with the correct
	number of arguments.

	This should only be used in tests.
]]

local assertDeepEqual = require(script.Parent.assertDeepEqual)

local function createSpy(inner)
	local self = {}
	self.callCount = 0
	self.values = {}
	self.valuesLength = 0
	self.value = function(...)
		self.callCount = self.callCount + 1
		self.values = { ... }
		self.valuesLength = select("#", ...)

		if inner ~= nil then
			return inner(...)
		end
		return nil
	end

	self.assertCalledWith = function(_, ...)
		local len = select("#", ...)

		if self.valuesLength ~= len then
			error(("Expected %d arguments, but was called with %d arguments"):format(self.valuesLength, len), 2)
		end

		for i = 1, len do
			local expected = select(i, ...)

			assert(self.values[i] == expected, "value differs")
		end
	end

	self.assertCalledWithDeepEqual = function(_, ...)
		local len = select("#", ...)

		if self.valuesLength ~= len then
			error(("Expected %d arguments, but was called with %d arguments"):format(self.valuesLength, len), 2)
		end

		for i = 1, len do
			local expected = select(i, ...)

			assertDeepEqual(self.values[i], expected)
		end
	end

	self.captureValues = function(_, ...)
		local len = select("#", ...)
		local result = {}

		assert(self.valuesLength == len, "length of expected values differs from stored values")

		for i = 1, len do
			local key = select(i, ...)
			result[key] = self.values[i]
		end

		return result
	end

	setmetatable(self, {
		__index = function(_, key)
			error(("%q is not a valid member of spy"):format(key))
		end,
	})

	return self
end

return createSpy
