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 1 commit
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
52 changes: 42 additions & 10 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,20 +804,52 @@ 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),
{
aeisenberg marked this conversation as resolved.
Show resolved Hide resolved
code: 'ERR_OUT_OF_RANGE',
type: RangeError
}
);
common.expectsError(
() => Buffer.alloc(16).writeDoubleLE(0, 9),
{
code: 'ERR_OUT_OF_RANGE',
type: RangeError
}
);

// 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),
{
code: 'ERR_OUT_OF_RANGE',
type: RangeError
}
);
common.expectsError(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, 0xffffffff),
{
code: 'ERR_OUT_OF_RANGE',
type: RangeError
}
);

// 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),
{
code: 'ERR_OUT_OF_RANGE',
type: RangeError
}
);
common.expectsError(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, -1),
{
code: 'ERR_OUT_OF_RANGE',
type: RangeError
}
);

// test for common write(U)IntLE/BE
{
Expand Down