import { attest, bench } from "@ark/attest";
import { setup } from "@ark/attest";
import { expectTypeOf } from "expect-type";
setup({
    updateSnapshots: !process.env.CI,
});
function test(name, fn) {
    fn(name + ": ");
}
test("unmasks deeply nested fragments", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([5, "instantiations"]);
    bench(prefix + "functionality", () => {
        expectTypeOf().toEqualTypeOf();
    });
});
test("unmasks deeply nested fragments", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([5, "instantiations"]);
    bench(prefix + "functionality", () => {
        expectTypeOf().toEqualTypeOf();
    });
});
test("unmasks deeply nested nullable fragments", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([5, "instantiations"]);
    bench(prefix + "functionality", () => {
        expectTypeOf().toEqualTypeOf();
    });
});
test("unmasks DeepPartial types", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([5, "instantiations"]);
    bench(prefix + "functionality", () => {
        expectTypeOf().toEqualTypeOf();
    });
});
test("Unmasked handles odd types", (prefix) => {
    bench(prefix + "empty type instantiations", () => {
        attest();
    }).types([111, "instantiations"]);
    bench(prefix + "empty type functionality", () => {
        expectTypeOf().toEqualTypeOf();
    });
    bench(prefix + "generic record type instantiations", () => {
        attest();
    }).types([115, "instantiations"]);
    bench(prefix + "generic record type functionality", () => {
        expectTypeOf().toEqualTypeOf();
    });
    bench(prefix + "unknown instantiations", () => {
        attest();
    }).types([47, "instantiations"]);
    bench(prefix + "unknown functionality", () => {
        expectTypeOf().toBeUnknown();
    });
    bench(prefix + "any instantiations", () => {
        attest();
    }).types([48, "instantiations"]);
    bench(prefix + "any functionality", () => {
        expectTypeOf().toBeAny();
    });
});
test("MaybeMasked handles odd types", (prefix) => {
    bench(prefix + "empty type instantiations", () => {
        attest();
    }).types([41, "instantiations"]);
    bench(prefix + "empty type functionality", () => {
        expectTypeOf().toEqualTypeOf();
    });
    bench(prefix + "generic record type instantiations", () => {
        attest();
    }).types([46, "instantiations"]);
    bench(prefix + "generic record type functionality", () => {
        expectTypeOf().toEqualTypeOf();
    });
    bench(prefix + "unknown instantiations", () => {
        attest();
    }).types([41, "instantiations"]);
    bench(prefix + "unknown functionality", () => {
        expectTypeOf().toBeUnknown();
    });
    bench(prefix + "any instantiations", () => {
        attest();
    }).types([43, "instantiations"]);
    bench(prefix + "any functionality", () => {
        expectTypeOf().toBeAny();
    });
});
test("distributed members on MaybeMasked", (prefix) => {
    (function unresolvedGeneric() {
        bench(prefix + "one unresolved generic mixed with null|undefined", () => {
            attest();
        }).types([49, "instantiations"]);
    })();
    (function unresolvedGenerics() {
        bench(prefix + "two unresolved generics distribute", () => {
            attest();
        }).types([50, "instantiations"]);
    })();
});
test("deals with overlapping array from parent fragment", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([5, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        // some fields for hovering
        x.id;
        x.artists;
        x.artists?.[0]?.id;
        x.artists?.[0]?.birthdate;
        x.artists?.[0]?.lastname;
        expectTypeOf(x).branded.toEqualTypeOf();
    });
});
test("base type, multiple fragments on sub-types", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([5, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        expectTypeOf(x).branded.toEqualTypeOf();
    });
});
test("does not detect `$fragmentRefs` if type contains `any`", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([1, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        expectTypeOf(x).branded.toEqualTypeOf();
    });
});
test("leaves tuples alone", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([5, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        expectTypeOf(x).branded.toEqualTypeOf();
    });
});
test("does not detect `$fragmentRefs` if type is a record type", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([1, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        expectTypeOf(x).branded.toEqualTypeOf();
    });
});
test("does not detect `$fragmentRefs` on types with index signatures", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([1, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        expectTypeOf(x).branded.toEqualTypeOf();
    });
});
test("detects `$fragmentRefs` on types with index signatures", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([1, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        const y = {};
        expectTypeOf(x).branded.toEqualTypeOf();
        expectTypeOf(y).toEqualTypeOf();
    });
});
test("recursive types: no error 'Type instantiation is excessively deep and possibly infinite.'", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([1, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        expectTypeOf(x).branded.toEqualTypeOf();
    });
});
test("MaybeMasked can be called with a generic if `mode` is not set to `unmask`", (prefix) => {
    function withGenericResult(arg) {
        bench(prefix + "Result generic - instantiations", () => {
            const maybeMasked = arg;
            return maybeMasked;
        }).types([1, "instantiations"]);
        bench(prefix + "Result generic - functionality", () => {
            const maybeMasked = arg;
            expectTypeOf(maybeMasked).toEqualTypeOf(arg);
        });
    }
    function withGenericDocument(arg) {
        bench(prefix + "Result generic - instantiations", () => {
            const maybeMasked = arg;
            return maybeMasked;
        }).types([1, "instantiations"]);
        bench(prefix + "Result generic - functionality", () => {
            const maybeMasked = arg;
            // cannot use unresolved generic with `expectTypeOf` here so we just try an assignment the other way round
            const test = maybeMasked;
            return test;
        });
    }
    withGenericResult({});
    withGenericDocument({});
});
test("Unmasked handles branded primitive types", (prefix) => {
    bench(prefix + "instantiations", () => {
        return {};
    }).types([5, "instantiations"]);
    bench(prefix + "functionality", () => {
        const x = {};
        expectTypeOf(x).branded.toEqualTypeOf();
    });
});
//# sourceMappingURL=types.bench.js.map
