From 6ae07a9248344cdd08be848a357ca192b53108c5 Mon Sep 17 00:00:00 2001 From: mritunjaygoutam12 Date: Tue, 30 Oct 2018 12:59:02 +0530 Subject: [PATCH] test: add property for RangeError in test-buffer-copy PR-URL: https://github.com/nodejs/node/pull/23968 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat Reviewed-By: Colin Ihrig --- test/parallel/test-buffer-copy.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-buffer-copy.js b/test/parallel/test-buffer-copy.js index 1b10dadb5b709b..f2c6f466d21515 100644 --- a/test/parallel/test-buffer-copy.js +++ b/test/parallel/test-buffer-copy.js @@ -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; { @@ -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 @@ -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);