test: add property for RangeError in test-buffer-copy
PR-URL: https://github.com/nodejs/node/pull/23968 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
0d9d32ad15
commit
a6e836a657
@ -1,10 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const b = Buffer.allocUnsafe(1024);
|
const b = Buffer.allocUnsafe(1024);
|
||||||
const c = Buffer.allocUnsafe(512);
|
const c = Buffer.allocUnsafe(512);
|
||||||
|
|
||||||
|
const errorProperty = {
|
||||||
|
code: 'ERR_OUT_OF_RANGE',
|
||||||
|
type: RangeError,
|
||||||
|
message: 'Index out of range'
|
||||||
|
};
|
||||||
|
|
||||||
let cntr = 0;
|
let cntr = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -96,9 +103,9 @@ bb.fill('hello crazy world');
|
|||||||
b.copy(c, 0, 100, 10);
|
b.copy(c, 0, 100, 10);
|
||||||
|
|
||||||
// copy throws at negative sourceStart
|
// copy throws at negative sourceStart
|
||||||
assert.throws(function() {
|
common.expectsError(
|
||||||
Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1);
|
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1),
|
||||||
}, RangeError);
|
errorProperty);
|
||||||
|
|
||||||
{
|
{
|
||||||
// check sourceEnd resets to targetEnd if former is greater than the latter
|
// check sourceEnd resets to targetEnd if former is greater than the latter
|
||||||
@ -111,7 +118,8 @@ assert.throws(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// throw with negative sourceEnd
|
// throw with negative sourceEnd
|
||||||
assert.throws(() => b.copy(c, 0, 0, -1), RangeError);
|
common.expectsError(
|
||||||
|
() => b.copy(c, 0, -1), errorProperty);
|
||||||
|
|
||||||
// when sourceStart is greater than sourceEnd, zero copied
|
// when sourceStart is greater than sourceEnd, zero copied
|
||||||
assert.strictEqual(b.copy(c, 0, 100, 10), 0);
|
assert.strictEqual(b.copy(c, 0, 100, 10), 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user