test(iso9660): reuse root directory parsing fixtures (#16056)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-02 19:21:11 +00:00
1 parent a71a4b55e9
commit d8b5fb2b58
1 file changed
+17 -34
+17 -34
View File
@@ -34,6 +34,20 @@ const rootLinks = (layout: {
return { self: root, parent: root };
};
const rootDirectorySteps = (
bytes: Buffer,
layout: Parameters<typeof rootLinks>[0],
) => {
const root = layout.directoryBlocks.get("")! * ISO9660_SECTOR_BYTES;
return parseIso9660DirectoryExtent(
bytes.subarray(root, root + ISO9660_SECTOR_BYTES),
root,
() => {},
ONE_VOLUME,
rootLinks(layout),
);
};
/** The records among a directory extent's steps. */
const recordsOf = (steps: Iterable<Iso9660DirectoryStep>) =>
Array.from(steps).flatMap((step) =>
@@ -379,16 +393,7 @@ it("groups multi-extent records and strips version suffixes", () => {
bytes.writeUInt32BE(attributeBlock, second + 6);
bytes[second + 1] = 1;
bytes[second + 25] = 0x10;
const root = layout.directoryBlocks.get("")! * ISO9660_SECTOR_BYTES;
const steps = Array.from(
parseIso9660DirectoryExtent(
bytes.subarray(root, root + ISO9660_SECTOR_BYTES),
root,
() => {},
ONE_VOLUME,
rootLinks(layout),
),
);
const steps = Array.from(rootDirectorySteps(bytes, layout));
const grouped = Array.from(groupIso9660Members(steps, false));
// One value per step, so a long chain never completes inside one next().
expect(grouped).toHaveLength(steps.length);
@@ -628,20 +633,8 @@ it("rejects a reserved . or .. identifier after the opening pair", () => {
},
],
});
const root = layout.directoryBlocks.get("")! * ISO9660_SECTOR_BYTES;
const records = () =>
Array.from(
groupIso9660Members(
parseIso9660DirectoryExtent(
bytes.subarray(root, root + ISO9660_SECTOR_BYTES),
root,
() => {},
ONE_VOLUME,
rootLinks(layout),
),
false,
),
);
Array.from(groupIso9660Members(rootDirectorySteps(bytes, layout), false));
expect(records).toThrow(
expect.objectContaining({
failure: expect.objectContaining({
@@ -661,18 +654,8 @@ it("strips a version suffix only when digits follow the semicolon", () => {
{ path: "NOTES2", bytes: Buffer.from("m"), primaryIdentifier: "NOTES;" },
],
});
const root = layout.directoryBlocks.get("")! * ISO9660_SECTOR_BYTES;
const members = Array.from(
groupIso9660Members(
parseIso9660DirectoryExtent(
bytes.subarray(root, root + ISO9660_SECTOR_BYTES),
root,
() => {},
ONE_VOLUME,
rootLinks(layout),
),
false,
),
groupIso9660Members(rootDirectorySteps(bytes, layout), false),
).filter((member) => member !== undefined);
expect(members.map(({ identifier, name }) => ({ identifier, name }))).toEqual(
[