1
1
'use strict' ;
2
2
3
- require ( '../common' ) ;
3
+ const common = require ( '../common' ) ;
4
4
const assert = require ( 'assert' ) ;
5
5
6
6
const b = Buffer . allocUnsafe ( 1024 ) ;
7
7
const c = Buffer . allocUnsafe ( 512 ) ;
8
+
9
+ const errorProperty = {
10
+ code : 'ERR_INDEX_OUT_OF_RANGE' ,
11
+ type : RangeError ,
12
+ message : 'Index out of range'
13
+ } ;
14
+
8
15
let cntr = 0 ;
9
16
10
17
{
@@ -107,9 +114,9 @@ bb.fill('hello crazy world');
107
114
b . copy ( c , 0 , 100 , 10 ) ;
108
115
109
116
// copy throws at negative sourceStart
110
- assert . throws ( function ( ) {
111
- Buffer . allocUnsafe ( 5 ) . copy ( Buffer . allocUnsafe ( 5 ) , 0 , - 1 ) ;
112
- } , RangeError ) ;
117
+ common . expectsError (
118
+ ( ) => Buffer . allocUnsafe ( 5 ) . copy ( Buffer . allocUnsafe ( 5 ) , 0 , - 1 ) ,
119
+ errorProperty ) ;
113
120
114
121
{
115
122
// check sourceEnd resets to targetEnd if former is greater than the latter
@@ -122,7 +129,8 @@ assert.throws(function() {
122
129
}
123
130
124
131
// throw with negative sourceEnd
125
- assert . throws ( ( ) => b . copy ( c , 0 , 0 , - 1 ) , RangeError ) ;
132
+ common . expectsError (
133
+ ( ) => b . copy ( c , 0 , - 1 ) , errorProperty ) ;
126
134
127
135
// when sourceStart is greater than sourceEnd, zero copied
128
136
assert . strictEqual ( b . copy ( c , 0 , 100 , 10 ) , 0 ) ;
0 commit comments