local y=require(script.Parent.getCalls)local s=require(script.Parent.cmpLiteralArgs)local N=require(script.Parent.cmpPredicateArgs)local j=require(script.Parent.fmtArgs)local v={}function v.args(s,N)local v=y(s)local E=#v if E==0 then return false,"\109\111\099\107 \119\097\115 \110\111\116 \099\097\108\108\101\100"end local x for y=1,E,1 do local s s,x=N(v[y].args)if s then return true end end if not x then x=j(v[E].args).." \100\105\100 \110\111\116 \109\097\116\099\104"end if E>1 then x=x..(" \040\043"..(E-1 .." \111\116\104\101\114 \099\097\108\108\115\041"))end return false,x end function v.literals(y,...)local N=table.pack(...)return v.args(y,function(y)return s(N,y)end)end function v.predicates(y,...)local s=table.pack(...)return v.args(y,function(y)return N(s,y)end)end return v
-- Functions to check if a mock was ever called with given arguments.

local getCalls = require(script.Parent.getCalls)
local cmpLiteralArgs = require(script.Parent.cmpLiteralArgs)
local cmpPredicateArgs = require(script.Parent.cmpPredicateArgs)
local fmtArgs = require(script.Parent.fmtArgs)

local AnyCallMatches = {}

function AnyCallMatches.args(mock, test)
	local callList = getCalls(mock)
	local size = #callList
	if size == 0 then
		return false, "mock was not called"
	end

	local msg
	for i = 1, size do
		local result
		result, msg = test(callList[i].args)
		if result then
			return true
		end
	end

	if not msg then
		msg = fmtArgs(callList[size].args) .. " did not match"
	end
	if size > 1 then
		msg = msg .. " (+" .. (size - 1) .. " other calls)"
	end

	return false, msg
end

function AnyCallMatches.literals(mock, ...)
	local expected = table.pack(...)
	return AnyCallMatches.args(mock, function(actual)
		return cmpLiteralArgs(expected, actual)
	end)
end

function AnyCallMatches.predicates(mock, ...)
	local predicates = table.pack(...)
	return AnyCallMatches.args(mock, function(actual)
		return cmpPredicateArgs(predicates, actual)
	end)
end

return AnyCallMatches
