mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
test(plist): reuse the number projection plan fixture (#16779)
This commit is contained in:
1 parent
2fc54591f8
commit
86a77f2c0f
1 file changed
+21
-41
@@ -15,6 +15,9 @@ import {
|
||||
isPlistDecodeBudgetFailure,
|
||||
} from "./propertyListDecodeBudget.js";
|
||||
|
||||
const numberProjectionPlan = (bytes: Buffer, budget = 1024 * 1024) =>
|
||||
estimateBinaryPlistExpansion(bytes, budget, { numberProjection: true });
|
||||
|
||||
const dataObjectWithUnusedOverlappingInteger = (): Buffer => {
|
||||
const bytes = Buffer.alloc(66);
|
||||
bytes[8] = 0xa1; // One-element array referencing data object 1.
|
||||
@@ -120,9 +123,7 @@ describe("binary plist date precision", () => {
|
||||
bytes[8] = 0x33;
|
||||
bytes.writeDoubleBE(seconds, 9);
|
||||
binaryPlistObjectTable(bytes, [8], 17);
|
||||
const plan = estimateBinaryPlistExpansion(bytes, 1024 * 1024, {
|
||||
numberProjection: true,
|
||||
});
|
||||
const plan = numberProjectionPlan(bytes);
|
||||
const metadata = scanBinaryPlistScalars(bytes, plan);
|
||||
expect(binaryDateRequiresExactSeconds(seconds)).toBe(false);
|
||||
const decoded = parseBinary(
|
||||
@@ -343,9 +344,7 @@ describe("binary plist number rewriting", () => {
|
||||
it("does not rewrite a wide integer when a date aliases its payload", () => {
|
||||
const bytes = integerPayloadContainingDate();
|
||||
const original = Buffer.from(bytes);
|
||||
const plan = estimateBinaryPlistExpansion(bytes, 1024 * 1024, {
|
||||
numberProjection: true,
|
||||
});
|
||||
const plan = numberProjectionPlan(bytes);
|
||||
const metadata = scanBinaryPlistScalars(bytes, plan);
|
||||
|
||||
expect(metadata.literals.incomplete).toBe(false);
|
||||
@@ -358,11 +357,9 @@ describe("binary plist number rewriting", () => {
|
||||
expect(plan.reachableWideIntegerOffsets).toEqual([11]);
|
||||
expect(plan.overlappingWideIntegerOffsets).toEqual([11]);
|
||||
expect(plan.overlappingDateOffsets).toEqual([18]);
|
||||
expect(() =>
|
||||
estimateBinaryPlistExpansion(bytes, plan.estimatedBytes - 1, {
|
||||
numberProjection: true,
|
||||
}),
|
||||
).toThrow(/budget/u);
|
||||
expect(() => numberProjectionPlan(bytes, plan.estimatedBytes - 1)).toThrow(
|
||||
/budget/u,
|
||||
);
|
||||
const decoded = decodeBinaryPlistScalars(bytes, metadata, plan);
|
||||
expect(decoded).not.toBe(bytes);
|
||||
const layout = readBinaryPlistLayout(decoded);
|
||||
@@ -416,15 +413,10 @@ const int64 = (value: bigint): Buffer => {
|
||||
};
|
||||
|
||||
describe("binary plist shared object-table entries", () => {
|
||||
const plan = (bytes: Buffer) =>
|
||||
estimateBinaryPlistExpansion(bytes, 1024 * 1024, {
|
||||
numberProjection: true,
|
||||
});
|
||||
|
||||
it("keeps every exact integer when two entries share one Int64 record", () => {
|
||||
const bytes = sharedScalarEntries(int64(9007199254740993n));
|
||||
const original = Buffer.from(bytes);
|
||||
const scalarPlan = plan(bytes);
|
||||
const scalarPlan = numberProjectionPlan(bytes);
|
||||
const metadata = scanBinaryPlistScalars(bytes, scalarPlan);
|
||||
|
||||
expect(metadata.literals.incomplete).toBe(false);
|
||||
@@ -451,7 +443,7 @@ describe("binary plist shared object-table entries", () => {
|
||||
wide.writeBigUInt64BE(2n, 9);
|
||||
const bytes = sharedScalarEntries(wide);
|
||||
const original = Buffer.from(bytes);
|
||||
const scalarPlan = plan(bytes);
|
||||
const scalarPlan = numberProjectionPlan(bytes);
|
||||
const metadata = scanBinaryPlistScalars(bytes, scalarPlan);
|
||||
|
||||
expect(metadata.literals.incomplete).toBe(false);
|
||||
@@ -475,7 +467,7 @@ describe("binary plist shared object-table entries", () => {
|
||||
date[0] = 0x33;
|
||||
date.writeDoubleBE(0.1005, 1);
|
||||
const bytes = sharedScalarEntries(date);
|
||||
const scalarPlan = plan(bytes);
|
||||
const scalarPlan = numberProjectionPlan(bytes);
|
||||
const metadata = scanBinaryPlistScalars(bytes, scalarPlan);
|
||||
|
||||
expect(metadata.literals.incomplete).toBe(false);
|
||||
@@ -517,9 +509,7 @@ describe("binary plist shared object-table entries", () => {
|
||||
describe("binary plist numeric association", () => {
|
||||
it("keeps an overlapping int64 exact without rewriting either object", () => {
|
||||
const bytes = integerPayloadContainingReal();
|
||||
const plan = estimateBinaryPlistExpansion(bytes, 1024 * 1024, {
|
||||
numberProjection: true,
|
||||
});
|
||||
const plan = numberProjectionPlan(bytes);
|
||||
const metadata = scanBinaryPlistScalars(bytes, plan);
|
||||
|
||||
expect(metadata.literals.incomplete).toBe(false);
|
||||
@@ -556,9 +546,7 @@ describe("binary plist numeric association", () => {
|
||||
|
||||
it("does not associate unreachable overlapping integers with a reachable real", () => {
|
||||
const bytes = unreachableOverlappingIntegerAndReal();
|
||||
const plan = estimateBinaryPlistExpansion(bytes, 1024 * 1024, {
|
||||
numberProjection: true,
|
||||
});
|
||||
const plan = numberProjectionPlan(bytes);
|
||||
const sourceMetadata = scanBinaryPlistScalars(bytes);
|
||||
const metadata = scanBinaryPlistScalars(bytes, plan);
|
||||
|
||||
@@ -585,20 +573,14 @@ describe("binary plist numeric association", () => {
|
||||
describe("binary plist scalar clone budgeting", () => {
|
||||
it("widens offset entries and budgets isolated date clones before allocation", () => {
|
||||
const bytes = dateInsideDataWithLargeOffsetTable();
|
||||
const plan = estimateBinaryPlistExpansion(bytes, 1024 * 1024, {
|
||||
numberProjection: true,
|
||||
});
|
||||
const plan = numberProjectionPlan(bytes);
|
||||
expect(plan.overlappingDateOffsets).toEqual([13]);
|
||||
expect(plan.datePrecisionOverlapCount).toBe(1);
|
||||
expect(() =>
|
||||
estimateBinaryPlistExpansion(bytes, plan.estimatedBytes - 1, {
|
||||
numberProjection: true,
|
||||
}),
|
||||
).toThrow(/budget/u);
|
||||
expect(() => numberProjectionPlan(bytes, plan.estimatedBytes - 1)).toThrow(
|
||||
/budget/u,
|
||||
);
|
||||
expect(
|
||||
estimateBinaryPlistExpansion(bytes, plan.estimatedBytes, {
|
||||
numberProjection: true,
|
||||
}).estimatedBytes,
|
||||
numberProjectionPlan(bytes, plan.estimatedBytes).estimatedBytes,
|
||||
).toBe(plan.estimatedBytes);
|
||||
|
||||
const metadata = scanBinaryPlistScalars(bytes);
|
||||
@@ -622,11 +604,9 @@ it.each([4n, 0xffffffffffffffffn])(
|
||||
expect(scanBinaryPlistScalars(bytes)).toEqual(expected);
|
||||
expect(expected.literals.incomplete).toBe(false);
|
||||
expect(expected.literals.unsafeIntegerLiterals).toBe(2);
|
||||
expect(() =>
|
||||
estimateBinaryPlistExpansion(bytes, 1024 * 1024, {
|
||||
numberProjection: true,
|
||||
}),
|
||||
).toThrow("binary plist trailer or object table is invalid");
|
||||
expect(() => numberProjectionPlan(bytes)).toThrow(
|
||||
"binary plist trailer or object table is invalid",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user