Skip to content

Commit

Permalink
add various coverage things
Browse files Browse the repository at this point in the history
  • Loading branch information
thetayloredman committed Feb 21, 2023
1 parent da5f3fe commit 747743e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/stream/DirectStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ export default class DirectStream extends SafeEventEmitter<DirectStreamEventArgu
if (controlCharacter === ControlCharacters.ReadByte) {
results.push([controlCharacter, input.subarray(size - remaining, size - remaining + 1)]);
remaining -= 1;
} else if ([ControlCharacters.ReadBytes, ControlCharacters.ReadKB, ControlCharacters.ReadMB].includes(controlCharacter)) {
continue;
}

/* istanbul ignore else */
if ([ControlCharacters.ReadBytes, ControlCharacters.ReadKB, ControlCharacters.ReadMB].includes(controlCharacter)) {
let byteSize;
switch (controlCharacter) {
case ControlCharacters.ReadBytes:
Expand All @@ -295,7 +299,11 @@ export default class DirectStream extends SafeEventEmitter<DirectStreamEventArgu

results.push([controlCharacter, number, input.subarray(size - remaining, size - remaining + byteSize)]);
remaining -= byteSize;
} else throw new Error(`Unrecognized control character returned by _bestControlCharacter for size ${remainder}`);
continue;
}

/* istanbul ignore next */
throw new Error(`Unrecognized control character returned by _bestControlCharacter for size ${remainder}`);
}
return Buffer.from(results.flat().flatMap((x) => (x instanceof Buffer ? Array.from(x.values()) : x)));
}
Expand Down
8 changes: 8 additions & 0 deletions src/tests/stream/DirectStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,12 @@ describe("Stream", () => {
);
// TODO: more?
});

it("fails for unsupported read sizes", () => {
const stream = new DirectStream();

expect(() => stream.feed(Buffer.from([ControlCharacters.ReadGB]))).toThrow(
"Internal error: ReadGB, ReadTB, and ReadPB are not yet implemented."
);
});
});

0 comments on commit 747743e

Please sign in to comment.