local l=require(script.Parent.getCalls)local E=require(script.Parent.cmpLiteralArgs)local O=require(script.Parent.cmpPredicateArgs)local u=require(script.Parent.fmtArgs)local I={}function I.args(E,O)local I=l(E)local J=#I if J==0 then return false,"\109\111\099\107 \119\097\115 \110\111\116 \099\097\108\108\101\100"end local q for l=1,J,1 do local E E,q=O(I[l].args)if E then return true end end if not q then q=u(I[J].args).." \100\105\100 \110\111\116 \109\097\116\099\104"end if J>1 then q=q..(" \040\043"..(J-1 .." \111\116\104\101\114 \099\097\108\108\115\041"))end return false,q end function I.literals(l,...)local O=table.pack(...)return I.args(l,function(l)return E(O,l)end)end function I.predicates(l,...)local E=table.pack(...)return I.args(l,function(l)return O(E,l)end)end return I


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
