Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,40 @@ new Buffer('', 'binary');
Buffer(0);

// try to write a 0-length string beyond the end of b
assert.throws(() => b.write('', 2048), RangeError);
common.expectsError(
() => b.write('', 2048),
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since this error object is used multiple times in the test, it can be stored in a const.

code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);

// throw when writing to negative offset
assert.throws(() => b.write('a', -1), RangeError);
common.expectsError(
() => b.write('a', -1),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);

// throw when writing past bounds from the pool
assert.throws(() => b.write('a', 2048), RangeError);
common.expectsError(
() => b.write('a', 2048),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);

// throw when writing to negative offset
assert.throws(() => b.write('a', -1), RangeError);
common.expectsError(
() => b.write('a', -1),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);

// try to copy 0 bytes worth of data into an empty buffer
b.copy(Buffer.alloc(0), 0, 0, 0);
Expand Down