@@ -33,6 +33,15 @@ crypto.DEFAULT_ENCODING = 'buffer';
33
33
// bump, we register a lot of exit listeners
34
34
process . setMaxListeners ( 256 ) ;
35
35
36
+ const errMessages = {
37
+ offsetNotNumber : / ^ T y p e E r r o r : o f f s e t m u s t b e a n u m b e r $ / ,
38
+ offsetOutOfRange : / ^ R a n g e E r r o r : o f f s e t o u t o f r a n g e $ / ,
39
+ offsetNotUInt32 : / ^ T y p e E r r o r : o f f s e t m u s t b e a u i n t 3 2 $ / ,
40
+ sizeNotNumber : / ^ T y p e E r r o r : s i z e m u s t b e a n u m b e r $ / ,
41
+ sizeNotUInt32 : / ^ T y p e E r r o r : s i z e m u s t b e a u i n t 3 2 $ / ,
42
+ bufferTooSmall : / ^ R a n g e E r r o r : b u f f e r t o o s m a l l $ / ,
43
+ } ;
44
+
36
45
const expectedErrorRegexp = / ^ T y p e E r r o r : s i z e m u s t b e a n u m b e r > = 0 $ / ;
37
46
[ crypto . randomBytes , crypto . pseudoRandomBytes ] . forEach ( function ( f ) {
38
47
[ - 1 , undefined , null , false , true , { } , [ ] ] . forEach ( function ( value ) {
@@ -41,10 +50,10 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
41
50
expectedErrorRegexp ) ;
42
51
} ) ;
43
52
44
- [ 0 , 1 , 2 , 4 , 16 , 256 , 1024 ] . forEach ( function ( len ) {
53
+ [ 0 , 1 , 2 , 4 , 16 , 256 , 1024 , 101.2 ] . forEach ( function ( len ) {
45
54
f ( len , common . mustCall ( function ( ex , buf ) {
46
55
assert . strictEqual ( ex , null ) ;
47
- assert . strictEqual ( buf . length , len ) ;
56
+ assert . strictEqual ( buf . length , Math . floor ( len ) ) ;
48
57
assert . ok ( Buffer . isBuffer ( buf ) ) ;
49
58
} ) ) ;
50
59
} ) ;
@@ -139,14 +148,6 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
139
148
Buffer . alloc ( 10 ) ,
140
149
new Uint8Array ( new Array ( 10 ) . fill ( 0 ) )
141
150
] ;
142
- const errMessages = {
143
- offsetNotNumber : / ^ T y p e E r r o r : o f f s e t m u s t b e a n u m b e r $ / ,
144
- offsetOutOfRange : / ^ R a n g e E r r o r : o f f s e t o u t o f r a n g e $ / ,
145
- offsetNotUInt32 : / ^ T y p e E r r o r : o f f s e t m u s t b e a u i n t 3 2 $ / ,
146
- sizeNotNumber : / ^ T y p e E r r o r : s i z e m u s t b e a n u m b e r $ / ,
147
- sizeNotUInt32 : / ^ T y p e E r r o r : s i z e m u s t b e a u i n t 3 2 $ / ,
148
- bufferTooSmall : / ^ R a n g e E r r o r : b u f f e r t o o s m a l l $ / ,
149
- } ;
150
151
151
152
const max = require ( 'buffer' ) . kMaxLength + 1 ;
152
153
@@ -264,4 +265,4 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
264
265
// length exceeds max acceptable value"
265
266
assert . throws ( function ( ) {
266
267
crypto . randomBytes ( ( - 1 >>> 0 ) + 1 ) ;
267
- } , / ^ T y p e E r r o r : s i z e m u s t b e a n u m b e r > = 0 $ / ) ;
268
+ } , errMessages . sizeNotUInt32 ) ;
0 commit comments