import { describe, expect, it } from "vitest"; import { categorizeSwiftTypes } from "./symbolAnalysis.js"; describe("modern Swift category evidence", () => { it.each([ ["$s4main7ServiceCMa", "classes"], ["$s4main5StateOMa", "enums"], ["$s4main7ScoringPMp", "protocols"], ["$s4main5OuterV5InnerCMa", "classes"], ["$s4main4PairV5otherE7doubledSiyF", "extensions"], ["$S4main4PairVMa", "structs"], ["_T04main4PairVMa", "structs"], ["$s4_TtX4PairVMa", "structs"], ] as const)("decodes nominal contexts for %s", (name, category) => { expect( categorizeSwiftTypes([{ address: "0x1", name }], { category }), ).toMatchObject({ total: 1, categories: { [category]: { count: 1 } }, unclassified: [], }); }); it("retains unresolved Swift observations under category filters", () => { const names = [ "$s4main13swiftIndirectySiAA7Scoring_p_SitF", "$sSi4mainE7doubledSiyF", "$s9999999999999999999999BadVMa", "$s4main04PairVMa", ]; const result = categorizeSwiftTypes( names.map((name, index) => ({ address: String(index), name })), { category: "structs" }, ); expect(result).toMatchObject({ total: 0, unclassified: names.map((name) => ({ name, mangled_names: [name], reason: "category_not_decoded", })), limitations: expect.arrayContaining([ expect.stringContaining("could not be established"), ]), }); expect( categorizeSwiftTypes([{ address: "0x1", name: names[0] ?? "" }], { category: "structs", pattern: "missing", }), ).toMatchObject({ total: 0, unclassified: [] }); }); it("deduplicates display names after selecting a category", () => { expect( categorizeSwiftTypes( [ { address: "0x1", name: "shared" }, { address: "0x2", name: "shared" }, ], { category: "structs" }, [ { address: "0x1", name: "$s4main7ServiceCMa" }, { address: "0x2", name: "$s4main4PairVMa" }, ], ), ).toMatchObject({ total: 1, categories: { structs: { items: [{ address: "0x2", name: "shared" }] } }, }); }); }); describe("Swift alias ambiguity", () => { it("reports conflicting aliases rather than choosing a category", () => { expect( categorizeSwiftTypes( [{ address: "0x1", name: "shared" }], { category: "structs" }, [ { address: "0x1", name: "$s4main4PairVMa" }, { address: "0x1", name: "$s4main7ServiceCMa" }, ], ), ).toMatchObject({ total: 0, unclassified: [ { name: "shared", reason: "conflicting_categories", mangled_names: ["$s4main4PairVMa", "$s4main7ServiceCMa"], }, ], }); }); });