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
+ type : RangeError ,
11
+ message : 'out of range index'
12
+ } ;
13
+
8
14
let cntr = 0 ;
9
15
10
16
{
@@ -96,9 +102,9 @@ bb.fill('hello crazy world');
96
102
assert . doesNotThrow ( ( ) => { b . copy ( c , 0 , 100 , 10 ) ; } ) ;
97
103
98
104
// 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 ) ;
102
108
103
109
{
104
110
// check sourceEnd resets to targetEnd if former is greater than the latter
@@ -111,7 +117,8 @@ assert.throws(function() {
111
117
}
112
118
113
119
// throw with negative sourceEnd
114
- assert . throws ( ( ) => b . copy ( c , 0 , 0 , - 1 ) , RangeError ) ;
120
+ common . expectsError (
121
+ ( ) => b . copy ( c , 0 , - 1 ) , errorProperty ) ;
115
122
116
123
// when sourceStart is greater than sourceEnd, zero copied
117
124
assert . strictEqual ( b . copy ( c , 0 , 100 , 10 ) , 0 ) ;
0 commit comments