Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/fallbacks/data-drift.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* `src/data.ts` is generated from `records.json` by `scripts/generate-data.ts`; records.json is the only
* file a reviewer hand-edits. This guards the two against drift: a hand-edit to data.ts, or an edit to
* records.json without re-running `bun run gen:data`, fails here. The generator is pure, so the test
* re-renders the module in memory and byte-compares it to the checked-in file.
*/
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import {
DATA_PATH,
loadRecords,
renderDataModule,
} from "./scripts/generate-data";
import { SUBSTITUTION_EVIDENCE } from "./src/index";

describe("data.ts is generated from records.json", () => {
test("checked-in src/data.ts matches the generator output (run `bun run gen:data` if this fails)", () => {
const onDisk = readFileSync(DATA_PATH, "utf8");
expect(onDisk).toBe(renderDataModule(loadRecords()));
});

test("the exported rows deep-equal records.json", () => {
expect(SUBSTITUTION_EVIDENCE).toEqual(loadRecords());
});
});
55 changes: 55 additions & 0 deletions packages/fallbacks/fallbacks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,58 @@ describe("glyphExceptions projection", () => {
).toHaveLength(1);
});
});

describe("Cooper Black -> Caprasimo (Regular-only, metric_safe)", () => {
const renderAll = { canRenderFamily: () => true };
const onlyCaprasimo = { canRenderFamily: (f: string) => f === "Caprasimo" };

test("the family resolves to Caprasimo as an exact, line-break-safe Regular substitute", () => {
// Unlike Baskerville -> Bacasime (visual_only, NBSP reflows), Cooper measures 0% across the Latin
// core, so the row is metric_safe with no glyph exceptions.
expect(getRenderableFallback("Cooper Black", renderAll)).toEqual({
substituteFamily: "Caprasimo",
policyAction: "substitute",
verdict: "metric_safe",
lineBreakSafe: true,
faces: { regular: true, bold: false, italic: false, boldItalic: false },
evidenceId: "cooper-black",
});
});

test("Regular maps; bold/italic/boldItalic are face_missing (never faux-styled onto Caprasimo)", () => {
expect(
getRenderableFallbackForFace("Cooper Black", "regular", renderAll)
?.substituteFamily,
).toBe("Caprasimo");
for (const face of ["bold", "italic", "boldItalic"] as const) {
expect(
getRenderableFallbackForFace("Cooper Black", face, renderAll),
`Cooper Black ${face}`,
).toBeNull();
expect(
getFallbackDecisionForFace("Cooper Black", face, renderAll),
`Cooper Black ${face} decision`,
).toEqual({
kind: "face_missing",
substituteFamily: "Caprasimo",
evidenceId: "cooper-black",
});
}
});

test("stays asset-aware: a consumer that does not bundle Caprasimo gets asset_missing, not a render", () => {
// Asset gate: Cooper stays inert until a consumer actually bundles Caprasimo.
expect(
getFallbackDecision("Cooper Black", { canRenderFamily: () => false }),
).toEqual({
kind: "asset_missing",
substituteFamily: "Caprasimo",
verdict: "metric_safe",
evidenceId: "cooper-black",
});
expect(
getRenderableFallbackForFace("Cooper Black", "regular", onlyCaprasimo)
?.substituteFamily,
).toBe("Caprasimo");
});
});
1 change: 1 addition & 0 deletions packages/fallbacks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"directory": "packages/fallbacks"
},
"scripts": {
"gen:data": "bun run scripts/generate-data.ts",
"build": "tsc -p tsconfig.build.json",
"prepack": "bun run build"
},
Expand Down
Loading
Loading