"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchesObject = matchesObject;
exports.anyOf = anyOf;
exports.arrayContaining = arrayContaining;
exports.stringContaining = stringContaining;
exports.objectContaining = objectContaining;
exports.anything = anything;
exports.assertCalledWith = assertCalledWith;
const tslib_1 = require("tslib");
const __ΩRecord = ['K', 'T', 'Record', 'l\'e#"Rb!b"Pde"!N#!w#y'];
function __assignType(fn, args) {
    fn.__type = args;
    return fn;
}
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const strict_1 = tslib_1.__importDefault(require("node:assert/strict"));
const ASYMMETRIC_MATCHER = Symbol.for('asymmetricMatcher');
const __ΩAsymmetricMatcher = [true, () => ASYMMETRIC_MATCHER, 'value', 'check', 'toString', 'AsymmetricMatcher', 'P.!4"P#2#)1$P&1%Mw&y'];
function isAsymmetricMatcher(value) {
    return typeof value === 'object' && value !== null && ASYMMETRIC_MATCHER in value;
}
isAsymmetricMatcher.__type = ['value', 'isAsymmetricMatcher', 'P#2!!/"'];
function deepMatch(actual, expected) {
    if (isAsymmetricMatcher(expected)) {
        return expected.check(actual);
    }
    if (expected === null || expected === undefined) {
        return actual === expected;
    }
    if (typeof expected !== 'object') {
        return lodash_1.default.isEqual(actual, expected);
    }
    if (Array.isArray(expected)) {
        if (!Array.isArray(actual))
            return false;
        if (actual.length !== expected.length)
            return false;
        return expected.every(__assignType((exp, i) => deepMatch(actual[i], exp), ['exp', 'i', '', 'P"2!"2""/#']));
    }
    if (typeof actual !== 'object' || actual === null)
        return false;
    for (const key of Object.keys(expected)) {
        if (!deepMatch(actual[key], expected[key])) {
            return false;
        }
    }
    return true;
}
deepMatch.__type = ['actual', 'expected', 'deepMatch', 'P#2!#2")/#'];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const PRIMITIVE_TYPE_MAP = (Map.Ω = [['"'], ['&']], new Map([
    [Number, 'number'],
    [String, 'string'],
    [Boolean, 'boolean'],
    [BigInt, 'bigint'],
    [Symbol, 'symbol']
]));
function matchesObject(actual, expected) {
    if (!deepMatch(actual, expected)) {
        strict_1.default.fail(`Expected object to match:\n` + `  Expected: ${JSON.stringify(expected, null, 2)}\n` + `  Actual:   ${JSON.stringify(actual, null, 2)}`);
    }
}
matchesObject.__type = ['actual', 'expected', 'matchesObject', 'P#2!#2"$/#'];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function anyOf(Type) {
    const primitiveType = PRIMITIVE_TYPE_MAP.get(Type);
    return {
        [ASYMMETRIC_MATCHER]: true,
        check: __assignType(function check(value) {
            if (primitiveType)
                return typeof value === primitiveType;
            return value instanceof Type;
        }, ['value', 'check', 'P#2!"/"']),
        toString: __assignType(function toString() {
            return `any(${Type.name})`;
        }, ['toString', 'P"/!'])
    };
}
anyOf.__type = ['args', 'new', 'Type', () => __ΩAsymmetricMatcher, 'anyOf', 'PP"@2!"/"2#n$/%'];
function arrayContaining(expected) {
    return {
        [ASYMMETRIC_MATCHER]: true,
        check(value) {
            if (!Array.isArray(value))
                return false;
            return expected.every(__assignType(exp => value.some(__assignType(v => deepMatch(v, exp), ['v', '', 'P"2!"/"'])), ['exp', '', 'P"2!"/"']));
        },
        toString: __assignType(function toString() {
            return `arrayContaining(${JSON.stringify(expected)})`;
        }, ['toString', 'P"/!'])
    };
}
arrayContaining.__type = ['expected', () => __ΩAsymmetricMatcher, 'arrayContaining', 'P#F2!n"/#'];
function stringContaining(expected) {
    return {
        [ASYMMETRIC_MATCHER]: true,
        check: __assignType(function check(value) {
            return typeof value === 'string' && value.includes(expected);
        }, ['value', 'check', 'P#2!"/"']),
        toString: __assignType(function toString() {
            return `stringContaining(${JSON.stringify(expected)})`;
        }, ['toString', 'P"/!'])
    };
}
stringContaining.__type = ['expected', () => __ΩAsymmetricMatcher, 'stringContaining', 'P&2!n"/#'];
function objectContaining(expected) {
    return {
        [ASYMMETRIC_MATCHER]: true,
        check: __assignType(function check(value) {
            if (typeof value !== 'object' || value === null)
                return false;
            return deepMatch(value, expected);
        }, ['value', 'check', 'P#2!"/"']),
        toString: __assignType(function toString() {
            return `objectContaining(${JSON.stringify(expected)})`;
        }, ['toString', 'P"/!'])
    };
}
objectContaining.__type = [() => __ΩRecord, 'expected', () => __ΩAsymmetricMatcher, 'objectContaining', 'P&#o!#2"n#/$'];
function anything() {
    return {
        [ASYMMETRIC_MATCHER]: true,
        check: __assignType(function check() {
            return true;
        }, ['check', 'P"/!']),
        toString: __assignType(function toString() {
            return 'anything()';
        }, ['toString', 'P"/!'])
    };
}
anything.__type = [() => __ΩAsymmetricMatcher, 'anything', 'Pn!/"'];
/**
 * Assert that a mock was called with the given arguments at least once.
 * Works with node:test mock.fn() and mock.method() return values.
 */
function assertCalledWith(mockFn, ...expectedArgs) {
    const calls = mockFn.mock.calls;
    const match = calls.some(__assignType(call => {
        if (call.arguments.length !== expectedArgs.length)
            return false;
        return expectedArgs.every(__assignType((exp, i) => deepMatch(call.arguments[i], exp), ['exp', 'i', '', 'P"2!"2""/#']));
    }, ['call', '', 'P"2!"/"']));
    if (!match) {
        strict_1.default.fail(`Expected mock to have been called with:\n` +
            `  Expected: ${JSON.stringify(expectedArgs, null, 2)}\n` +
            `  Actual calls: ${JSON.stringify(calls.map(__assignType(c => c.arguments, ['c', '', 'P"2!"/"'])), null, 2)}`);
    }
}
assertCalledWith.__type = ['arguments', 'calls', 'mock', 'mockFn', 'expectedArgs', 'assertCalledWith', 'PPPP#F4!MF4"M4#M2$#@2%$/&'];
//# sourceMappingURL=expect.js.map