0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

add test for Buffer edge case

This commit is contained in:
Bartek Iwańczuk 2018-11-27 21:46:24 +01:00 committed by Ryan Dahl
parent 9ca92bd51b
commit b183b01c8e
2 changed files with 11 additions and 2 deletions

View file

@ -132,8 +132,7 @@ export class Buffer implements Reader, Writer {
// Buffer is empty, reset to recover space.
this.reset();
if (p.byteLength === 0) {
// TODO This edge case should be tested by porting TestReadEmptyAtEOF
// from the Go tests.
// this edge case is tested in 'bufferReadEmptyAtEOF' test
return { nread: 0, eof: false };
}
return { nread: 0, eof: true };

View file

@ -109,6 +109,16 @@ test(async function bufferBasicOperations() {
}
});
test(async function bufferReadEmptyAtEOF() {
// check that EOF of 'buf' is not reached (even though it's empty) if
// results are written to buffer that has 0 length (ie. it can't store any data)
let buf = new Buffer();
const zeroLengthTmp = new Uint8Array(0);
let result = await buf.read(zeroLengthTmp);
assertEqual(result.nread, 0);
assertEqual(result.eof, false);
});
test(async function bufferLargeByteWrites() {
init();
const buf = new Buffer();