Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: replace assert.throws w/ common.expectsError #23454

Closed
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
76 changes: 34 additions & 42 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,22 @@ new Buffer('', 'latin1');
new Buffer('', 'binary');
Buffer(0);

const outOfBoundsError = {
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
};

// try to write a 0-length string beyond the end of b
common.expectsError(
() => b.write('', 2048),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);
common.expectsError(() => b.write('', 2048), outOfBoundsError);

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

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

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

// try to copy 0 bytes worth of data into an empty buffer
b.copy(Buffer.alloc(0), 0, 0, 0);
Expand Down Expand Up @@ -804,20 +785,34 @@ assert.strictEqual(Buffer.from('13.37').length, 5);
Buffer.from(Buffer.allocUnsafe(0), 0, 0);

// issue GH-5587
assert.throws(() => Buffer.alloc(8).writeFloatLE(0, 5), RangeError);
assert.throws(() => Buffer.alloc(16).writeDoubleLE(0, 9), RangeError);
common.expectsError(
() => Buffer.alloc(8).writeFloatLE(0, 5),
outOfBoundsError
);
common.expectsError(
() => Buffer.alloc(16).writeDoubleLE(0, 9),
outOfBoundsError
);

// attempt to overflow buffers, similar to previous bug in array buffers
assert.throws(() => Buffer.allocUnsafe(8).writeFloatLE(0.0, 0xffffffff),
RangeError);
assert.throws(() => Buffer.allocUnsafe(8).writeFloatLE(0.0, 0xffffffff),
RangeError);

common.expectsError(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, 0xffffffff),
outOfBoundsError
);
common.expectsError(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, 0xffffffff),
outOfBoundsError
);

// ensure negative values can't get past offset
assert.throws(() => Buffer.allocUnsafe(8).writeFloatLE(0.0, -1), RangeError);
assert.throws(() => Buffer.allocUnsafe(8).writeFloatLE(0.0, -1), RangeError);

common.expectsError(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, -1),
outOfBoundsError
);
common.expectsError(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, -1),
outOfBoundsError
);

// test for common write(U)IntLE/BE
{
Expand Down Expand Up @@ -1010,10 +1005,7 @@ common.expectsError(() => {
const a = Buffer.alloc(1);
const b = Buffer.alloc(1);
a.copy(b, 0, 0x100000000, 0x100000001);
}, {
code: 'ERR_OUT_OF_RANGE',
type: RangeError
});
}, outOfBoundsError);

// Unpooled buffer (replaces SlowBuffer)
{
Expand Down