Skip to content

Commit

Permalink
test: add property for RangeError in test-buffer-copy
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
mritunjayz authored and rvagg committed Nov 28, 2018
1 parent 22b4149 commit 6ae07a9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions test/parallel/test-buffer-copy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
'use strict';

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

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

const errorProperty = {
type: RangeError,
message: 'out of range index'
};

let cntr = 0;

{
Expand Down Expand Up @@ -96,9 +102,9 @@ bb.fill('hello crazy world');
assert.doesNotThrow(() => { 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 +117,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

0 comments on commit 6ae07a9

Please sign in to comment.