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

code property added for rangeError #23968

Closed
wants to merge 1 commit into from
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
18 changes: 13 additions & 5 deletions test/parallel/test-buffer-copy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');

const b = Buffer.allocUnsafe(1024);
const c = Buffer.allocUnsafe(512);

const errorProperty = {
code: 'ERR_OUT_OF_RANGE',
type: RangeError,
message: 'Index out of range'
};

let cntr = 0;

{
Expand Down Expand Up @@ -96,9 +103,9 @@ bb.fill('hello crazy world');
b.copy(c, 0, 100, 10);

// copy throws at negative sourceStart
assert.throws(function() {
Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1);
}, RangeError);
common.expectsError(
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1),
errorProperty);

{
// check sourceEnd resets to targetEnd if former is greater than the latter
Expand All @@ -111,7 +118,8 @@ assert.throws(function() {
}

// 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
assert.strictEqual(b.copy(c, 0, 100, 10), 0);
Expand Down