11var test = require ( 'tape' )
22var randomBytes = require ( './' )
3+ var MAX_BYTES = 65536
4+ var MAX_UINT32 = 4294967295
35
46test ( 'sync' , function ( t ) {
5- t . plan ( 4 )
7+ t . plan ( 9 )
68 t . equals ( randomBytes ( 0 ) . length , 0 , 'len: ' + 0 )
79 t . equals ( randomBytes ( 3 ) . length , 3 , 'len: ' + 3 )
810 t . equals ( randomBytes ( 30 ) . length , 30 , 'len: ' + 30 )
911 t . equals ( randomBytes ( 300 ) . length , 300 , 'len: ' + 300 )
12+ t . equals ( randomBytes ( 17 + MAX_BYTES ) . length , 17 + MAX_BYTES , 'len: ' + 17 + MAX_BYTES )
13+ t . equals ( randomBytes ( MAX_BYTES * 100 ) . length , MAX_BYTES * 100 , 'len: ' + MAX_BYTES * 100 )
14+ t . throws ( function ( ) {
15+ randomBytes ( MAX_UINT32 + 1 )
16+ } )
17+ t . throws ( function ( ) {
18+ t . equals ( randomBytes ( - 1 ) )
19+ } )
20+ t . throws ( function ( ) {
21+ t . equals ( randomBytes ( 'hello' ) )
22+ } )
1023} )
1124
1225test ( 'async' , function ( t ) {
13- t . plan ( 4 )
26+ t . plan ( 9 )
1427
1528 randomBytes ( 0 , function ( err , resp ) {
1629 if ( err ) throw err
@@ -35,22 +48,34 @@ test('async', function (t) {
3548
3649 t . equals ( resp . length , 300 , 'len: ' + 300 )
3750 } )
38- } )
3951
40- if ( process . browser ) {
41- test ( 'requesting to much throws' , function ( t ) {
42- t . plan ( 1 )
43- t . throws ( function ( ) {
44- randomBytes ( 65537 )
52+ randomBytes ( 17 + MAX_BYTES , function ( err , resp ) {
53+ if ( err ) throw err
54+
55+ t . equals ( resp . length , 17 + MAX_BYTES , 'len: ' + 17 + MAX_BYTES )
56+ } )
57+
58+ randomBytes ( MAX_BYTES * 100 , function ( err , resp ) {
59+ if ( err ) throw err
60+
61+ t . equals ( resp . length , MAX_BYTES * 100 , 'len: ' + MAX_BYTES * 100 )
62+ } )
63+
64+ t . throws ( function ( ) {
65+ randomBytes ( MAX_UINT32 + 1 , function ( ) {
66+ t . ok ( false , 'should not get here' )
4567 } )
4668 } )
4769
48- test ( 'requesting to much throws async' , function ( t ) {
49- t . plan ( 1 )
50- t . throws ( function ( ) {
51- randomBytes ( 65537 , function ( ) {
52- t . ok ( false , 'should not get here' )
53- } )
70+ t . throws ( function ( ) {
71+ randomBytes ( - 1 , function ( ) {
72+ t . ok ( false , 'should not get here' )
5473 } )
5574 } )
56- }
75+
76+ t . throws ( function ( ) {
77+ randomBytes ( 'hello' , function ( ) {
78+ t . ok ( false , 'should not get here' )
79+ } )
80+ } )
81+ } )
0 commit comments