refactor: remove abandoned test-only analysis scaffolding
This commit is contained in:
@@ -1,150 +1,8 @@
|
||||
import { fc } from "@fast-check/vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
countMethodsByType,
|
||||
isDbSaveComplete,
|
||||
isGetterSelector,
|
||||
isSetterSelector,
|
||||
inspectNativeDispatchMetadata,
|
||||
propertyNameFromSelector,
|
||||
swiftDeclsByKind,
|
||||
type ObjcMethod,
|
||||
type SwiftDecl,
|
||||
type DbSaveResult,
|
||||
} from "./objcSwiftMetadata.js";
|
||||
import { inspectNativeDispatchMetadata } from "./objcSwiftMetadata.js";
|
||||
|
||||
describe("ObjC/Swift metadata", () => {
|
||||
it("identifies getter selectors", () => {
|
||||
expect(isGetterSelector("name")).toBe(true);
|
||||
expect(isGetterSelector("setName:")).toBe(false);
|
||||
expect(isGetterSelector("set")).toBe(true);
|
||||
});
|
||||
|
||||
it("identifies setter selectors", () => {
|
||||
expect(isSetterSelector("setName:")).toBe(true);
|
||||
expect(isSetterSelector("name")).toBe(false);
|
||||
});
|
||||
|
||||
it("extracts property name from selector", () => {
|
||||
expect(propertyNameFromSelector("name")).toBe("name");
|
||||
expect(propertyNameFromSelector("setName:")).toBe("name");
|
||||
expect(propertyNameFromSelector("set")).toBe("set");
|
||||
});
|
||||
|
||||
it("counts methods by type", () => {
|
||||
const methods: ObjcMethod[] = [
|
||||
{
|
||||
selector: "init",
|
||||
method_type: "instance",
|
||||
address: 0x1000,
|
||||
is_required: false,
|
||||
is_optional: false,
|
||||
},
|
||||
{
|
||||
selector: "alloc",
|
||||
method_type: "class",
|
||||
address: 0x2000,
|
||||
is_required: false,
|
||||
is_optional: false,
|
||||
},
|
||||
];
|
||||
const counts = countMethodsByType(methods);
|
||||
expect(counts.instance).toBe(1);
|
||||
expect(counts.class).toBe(1);
|
||||
expect(counts.ivar_getter).toBe(0);
|
||||
expect(counts.ivar_setter).toBe(0);
|
||||
});
|
||||
|
||||
it("filters Swift declarations by kind", () => {
|
||||
const decls: SwiftDecl[] = [
|
||||
{
|
||||
kind: "class",
|
||||
name: "Foo",
|
||||
module: null,
|
||||
access_level: "public",
|
||||
super_class: null,
|
||||
protocols: [],
|
||||
is_final: false,
|
||||
is_required: false,
|
||||
is_convenience_init: false,
|
||||
is_override: false,
|
||||
},
|
||||
];
|
||||
const classes = swiftDeclsByKind(decls, "class");
|
||||
expect(classes).toHaveLength(1);
|
||||
expect(classes[0]!.name).toBe("Foo");
|
||||
});
|
||||
|
||||
it("checks database save completeness", () => {
|
||||
const result: DbSaveResult = {
|
||||
operation: "save",
|
||||
succeeded: true,
|
||||
preserved_names: 10,
|
||||
preserved_comments: 5,
|
||||
preserved_bookmarks: 3,
|
||||
database_path: "/tmp/db.hop",
|
||||
error: null,
|
||||
};
|
||||
expect(isDbSaveComplete(result, 10, 5, 3)).toBe(true);
|
||||
expect(isDbSaveComplete(result, 11, 5, 3)).toBe(false);
|
||||
});
|
||||
|
||||
it("is monotone in every expected count and total at the observed count", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.record({
|
||||
operation: fc.constantFrom(
|
||||
"save",
|
||||
"readback",
|
||||
"open_database",
|
||||
"close_database",
|
||||
"export",
|
||||
"import",
|
||||
),
|
||||
succeeded: fc.boolean(),
|
||||
preserved_names: fc.nat({ max: 50 }),
|
||||
preserved_comments: fc.nat({ max: 50 }),
|
||||
preserved_bookmarks: fc.nat({ max: 50 }),
|
||||
database_path: fc.option(fc.string(), { nil: null }),
|
||||
error: fc.option(fc.string(), { nil: null }),
|
||||
}),
|
||||
fc.nat({ max: 50 }),
|
||||
fc.nat({ max: 50 }),
|
||||
fc.nat({ max: 50 }),
|
||||
(result, names, comments, bookmarks) => {
|
||||
// Completeness is downward closed: if demanding more was met,
|
||||
// demanding less must also be met.
|
||||
if (isDbSaveComplete(result, names + 1, comments, bookmarks)) {
|
||||
expect(isDbSaveComplete(result, names, comments, bookmarks)).toBe(
|
||||
true,
|
||||
);
|
||||
}
|
||||
if (isDbSaveComplete(result, names, comments + 1, bookmarks)) {
|
||||
expect(isDbSaveComplete(result, names, comments, bookmarks)).toBe(
|
||||
true,
|
||||
);
|
||||
}
|
||||
if (isDbSaveComplete(result, names, comments, bookmarks + 1)) {
|
||||
expect(isDbSaveComplete(result, names, comments, bookmarks)).toBe(
|
||||
true,
|
||||
);
|
||||
}
|
||||
// Expecting exactly what was preserved is complete iff the save worked.
|
||||
expect(
|
||||
isDbSaveComplete(
|
||||
result,
|
||||
result.preserved_names,
|
||||
result.preserved_comments,
|
||||
result.preserved_bookmarks,
|
||||
),
|
||||
).toBe(result.succeeded);
|
||||
},
|
||||
),
|
||||
{ numRuns: 200 },
|
||||
);
|
||||
});
|
||||
|
||||
it("bounds symbol projections and labels symbol-only metadata as partial", () => {
|
||||
const result = inspectNativeDispatchMetadata(
|
||||
[
|
||||
|
||||
@@ -7,7 +7,6 @@ export const objcMethodTypeSchema = z.enum([
|
||||
"ivar_getter",
|
||||
"ivar_setter",
|
||||
]);
|
||||
export type ObjcMethodType = z.infer<typeof objcMethodTypeSchema>;
|
||||
|
||||
/** Objective-C property attribute. */
|
||||
export const objcPropertyAttributeSchema = z.strictObject({
|
||||
@@ -27,7 +26,7 @@ export const objcMethodSchema = z.strictObject({
|
||||
is_required: z.boolean().default(false),
|
||||
is_optional: z.boolean().default(false),
|
||||
});
|
||||
export type ObjcMethod = z.infer<typeof objcMethodSchema>;
|
||||
type ObjcMethod = z.infer<typeof objcMethodSchema>;
|
||||
|
||||
/** Objective-C property metadata. */
|
||||
export const objcPropertySchema = z.strictObject({
|
||||
@@ -87,7 +86,7 @@ export const objcClassSchema = z.strictObject({
|
||||
)
|
||||
.optional(),
|
||||
});
|
||||
export type ObjcClass = z.infer<typeof objcClassSchema>;
|
||||
type ObjcClass = z.infer<typeof objcClassSchema>;
|
||||
|
||||
/** Exact location of a decoded native metadata value when the provider knows it. */
|
||||
export const nativeMetadataLocationSchema = z.strictObject({
|
||||
@@ -162,7 +161,7 @@ export const objcDispatchImplementationSchema = z.strictObject({
|
||||
decode: nativeMetadataDecodeSchema,
|
||||
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
||||
});
|
||||
export type ObjcDispatchImplementation = z.infer<
|
||||
type ObjcDispatchImplementation = z.infer<
|
||||
typeof objcDispatchImplementationSchema
|
||||
>;
|
||||
|
||||
@@ -224,7 +223,7 @@ export const swiftSymbolSchema = z.strictObject({
|
||||
decode: nativeMetadataDecodeSchema,
|
||||
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
||||
});
|
||||
export type SwiftSymbol = z.infer<typeof swiftSymbolSchema>;
|
||||
type SwiftSymbol = z.infer<typeof swiftSymbolSchema>;
|
||||
|
||||
/** Per-facet coverage; empty arrays are meaningful only with this record. */
|
||||
export const nativeMetadataCoverageSchema = z.strictObject({
|
||||
@@ -246,7 +245,6 @@ export const swiftDeclKindSchema = z.enum([
|
||||
"global_var",
|
||||
"global_func",
|
||||
]);
|
||||
export type SwiftDeclKind = z.infer<typeof swiftDeclKindSchema>;
|
||||
|
||||
/** Swift access level. */
|
||||
export const swiftAccessLevelSchema = z.enum([
|
||||
@@ -269,7 +267,6 @@ export const swiftDeclSchema = z.strictObject({
|
||||
is_convenience_init: z.boolean().default(false),
|
||||
is_override: z.boolean().default(false),
|
||||
});
|
||||
export type SwiftDecl = z.infer<typeof swiftDeclSchema>;
|
||||
|
||||
/** Database save/read operation type. */
|
||||
export const dbOperationSchema = z.enum([
|
||||
@@ -290,7 +287,6 @@ export const dbSaveResultSchema = z.strictObject({
|
||||
database_path: z.string().nullable(),
|
||||
error: z.string().nullable(),
|
||||
});
|
||||
export type DbSaveResult = z.infer<typeof dbSaveResultSchema>;
|
||||
|
||||
/** Result of deeper ObjC/Swift metadata extraction. */
|
||||
export const objcSwiftMetadataSchema = z.strictObject({
|
||||
@@ -479,60 +475,3 @@ const parseMetadataAddress = (address: string | null): number | null => {
|
||||
const value = Number.parseInt(match[1], 16);
|
||||
return Number.isSafeInteger(value) ? value : null;
|
||||
};
|
||||
|
||||
/** Check if a selector name looks like a getter. */
|
||||
export function isGetterSelector(selector: string): boolean {
|
||||
return /^[a-z][a-zA-Z0-9_]*$/u.test(selector) && !selector.includes(":");
|
||||
}
|
||||
|
||||
/** Check if a selector name looks like a setter. */
|
||||
export function isSetterSelector(selector: string): boolean {
|
||||
return selector.startsWith("set") && selector.endsWith(":");
|
||||
}
|
||||
|
||||
/** Extract property name from a getter/setter selector. */
|
||||
export function propertyNameFromSelector(selector: string): string | null {
|
||||
if (isSetterSelector(selector)) {
|
||||
const inner = selector.slice(3, -1);
|
||||
return inner.charAt(0).toLowerCase() + inner.slice(1);
|
||||
}
|
||||
if (isGetterSelector(selector)) {
|
||||
return selector;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Count ObjC methods by type. */
|
||||
export function countMethodsByType(
|
||||
methods: readonly ObjcMethod[],
|
||||
): Record<ObjcMethodType, number> {
|
||||
return {
|
||||
instance: methods.filter((m) => m.method_type === "instance").length,
|
||||
class: methods.filter((m) => m.method_type === "class").length,
|
||||
ivar_getter: methods.filter((m) => m.method_type === "ivar_getter").length,
|
||||
ivar_setter: methods.filter((m) => m.method_type === "ivar_setter").length,
|
||||
};
|
||||
}
|
||||
|
||||
/** Get all Swift declarations of a specific kind. */
|
||||
export function swiftDeclsByKind(
|
||||
decls: readonly SwiftDecl[],
|
||||
kind: SwiftDeclKind,
|
||||
): SwiftDecl[] {
|
||||
return decls.filter((d) => d.kind === kind);
|
||||
}
|
||||
|
||||
/** Check if a database save preserved all expected items. */
|
||||
export function isDbSaveComplete(
|
||||
result: DbSaveResult,
|
||||
expectedNames: number,
|
||||
expectedComments: number,
|
||||
expectedBookmarks: number,
|
||||
): boolean {
|
||||
return (
|
||||
result.succeeded &&
|
||||
result.preserved_names >= expectedNames &&
|
||||
result.preserved_comments >= expectedComments &&
|
||||
result.preserved_bookmarks >= expectedBookmarks
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user