Skip to content

Commit 6ae07a9

Browse files
mritunjayzrvagg
authored andcommittedNov 28, 2018
test: add property for RangeError in test-buffer-copy
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>
1 parent 22b4149 commit 6ae07a9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed
 

‎test/parallel/test-buffer-copy.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55

66
const b = Buffer.allocUnsafe(1024);
77
const c = Buffer.allocUnsafe(512);
8+
9+
const errorProperty = {
10+
type: RangeError,
11+
message: 'out of range index'
12+
};
13+
814
let cntr = 0;
915

1016
{
@@ -96,9 +102,9 @@ bb.fill('hello crazy world');
96102
assert.doesNotThrow(() => { b.copy(c, 0, 100, 10); });
97103

98104
// copy throws at negative sourceStart
99-
assert.throws(function() {
100-
Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1);
101-
}, RangeError);
105+
common.expectsError(
106+
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1),
107+
errorProperty);
102108

103109
{
104110
// check sourceEnd resets to targetEnd if former is greater than the latter
@@ -111,7 +117,8 @@ assert.throws(function() {
111117
}
112118

113119
// throw with negative sourceEnd
114-
assert.throws(() => b.copy(c, 0, 0, -1), RangeError);
120+
common.expectsError(
121+
() => b.copy(c, 0, -1), errorProperty);
115122

116123
// when sourceStart is greater than sourceEnd, zero copied
117124
assert.strictEqual(b.copy(c, 0, 100, 10), 0);

0 commit comments

Comments
 (0)