Skip to content

Commit

Permalink
Add zero byte reading unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Aug 7, 2024
1 parent 952ab84 commit cfbad82
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,14 @@ describe('Matrix tests', () => {
}
});

it('should handle zero byte read', async () => {

const rst = await getTokenizerWithData('\x00\x00\x00', tokenizerType);
const uint8Array = await rst.readToken(new Token.Uint8ArrayType(0));
assert.strictEqual(uint8Array.length, 0);
await rst.close();
});

it('should not throw an Error if we read exactly until the end of the file', async () => {

const rst = await getTokenizerWithData('\x89\x54\x40', tokenizerType);
Expand All @@ -804,7 +812,7 @@ describe('Matrix tests', () => {
const buffer = new Uint8Array(4);

return getTokenizerWithData('\x89\x54\x40', tokenizerType).then(rst => {
return rst.readBuffer(buffer).then(len => {
return rst.readBuffer(buffer).then(() => {
assert.fail('It should throw EndOfFile Error');
}).catch(err => {
assert.instanceOf(err, EndOfStreamError);
Expand Down

0 comments on commit cfbad82

Please sign in to comment.