--[[*
 * Test `input` with the given `regex`. This is used by the main
 * `picomatch()` function to test the input string.
 *
 * ```js
 * const picomatch = require('picomatch');
 * // picomatch.test(input, regex[, options]);
 *
 * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
 * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
 * ```
 * @param {String} `input` String to test.
 * @param {RegExp} `regex`
 * @return {Object} Returns an object with matching info.
 * @api public
 ]]


function picomatch.test(input: string, regex: RegExp, options: Object?, ref_: Object?)
	local ref: Object = ref_ or {}
	local glob, posix = ref.glob, ref.posix

	if typeof(input) ~= "string" then
		error(Error.new("TypeError: Expected input to be a string"))
	end

	if input == "" then
		return { isMatch = false, output = "" }
	end

	local opts: Object = options or {}
	local format = if Boolean.toJSBoolean(opts.format)
		then opts.format
		else if Boolean.toJSBoolean(posix) then utils.toPosixSlashes else nil
	local match = input == glob
	local output = if match and Boolean.toJSBoolean(format) then format(input) else input

	if match == false then
		output = if Boolean.toJSBoolean(format) then format(input) else input
		match = output == glob
	end

	if match == false or opts.capture == true then
		if opts.matchBase == true or opts.basename == true then
			match = picomatch.matchBase(input, regex, options, posix)
		else
			-- ROBLOX FIXME: Luau narrows the type to boolean and doesn't allow for result of RegExp:exec to be assigned
			match = regex:exec(output) :: any
		end
	end

	return { isMatch = Boolean.toJSBoolean(match), match = match, output = output }
end
