@@ -2,54 +2,54 @@ import test from 'ava';
22import cryptoRandomString from '.' ;
33
44test ( 'main' , t => {
5- t . is ( cryptoRandomString ( 0 ) . length , 0 ) ;
6- t . is ( cryptoRandomString ( 10 ) . length , 10 ) ;
7- t . is ( cryptoRandomString ( 100 ) . length , 100 ) ;
8- t . regex ( cryptoRandomString ( 100 ) , / ^ [ a - f \d ] * $ / ) ; // Sanity check, probabilistic
5+ t . is ( cryptoRandomString ( { length : 0 } ) . length , 0 ) ;
6+ t . is ( cryptoRandomString ( { length : 10 } ) . length , 10 ) ;
7+ t . is ( cryptoRandomString ( { length : 100 } ) . length , 100 ) ;
8+ t . regex ( cryptoRandomString ( { length : 100 } ) , / ^ [ a - f \d ] * $ / ) ; // Sanity check, probabilistic
99} ) ;
1010
1111test ( 'hex' , t => {
12- t . is ( cryptoRandomString ( 0 , { type : 'hex' } ) . length , 0 ) ;
13- t . is ( cryptoRandomString ( 10 , { type : 'hex' } ) . length , 10 ) ;
14- t . is ( cryptoRandomString ( 100 , { type : 'hex' } ) . length , 100 ) ;
15- t . regex ( cryptoRandomString ( 100 , { type : 'hex' } ) , / ^ [ a - f \d ] * $ / ) ; // Sanity check, probabilistic
12+ t . is ( cryptoRandomString ( { length : 0 , type : 'hex' } ) . length , 0 ) ;
13+ t . is ( cryptoRandomString ( { length : 10 , type : 'hex' } ) . length , 10 ) ;
14+ t . is ( cryptoRandomString ( { length : 100 , type : 'hex' } ) . length , 100 ) ;
15+ t . regex ( cryptoRandomString ( { length : 100 , type : 'hex' } ) , / ^ [ a - f \d ] * $ / ) ; // Sanity check, probabilistic
1616} ) ;
1717
1818test ( 'base64' , t => {
19- t . is ( cryptoRandomString ( 0 , { type : 'base64' } ) . length , 0 ) ;
20- t . is ( cryptoRandomString ( 10 , { type : 'base64' } ) . length , 10 ) ;
21- t . is ( cryptoRandomString ( 100 , { type : 'base64' } ) . length , 100 ) ;
22- t . regex ( cryptoRandomString ( 100 , { type : 'base64' } ) , / ^ [ a - z A - Z \d / + ] * $ / ) ; // Sanity check, probabilistic
19+ t . is ( cryptoRandomString ( { length : 0 , type : 'base64' } ) . length , 0 ) ;
20+ t . is ( cryptoRandomString ( { length : 10 , type : 'base64' } ) . length , 10 ) ;
21+ t . is ( cryptoRandomString ( { length : 100 , type : 'base64' } ) . length , 100 ) ;
22+ t . regex ( cryptoRandomString ( { length : 100 , type : 'base64' } ) , / ^ [ a - z A - Z \d / + ] * $ / ) ; // Sanity check, probabilistic
2323} ) ;
2424
2525test ( 'url-safe' , t => {
26- t . is ( cryptoRandomString ( 0 , { type : 'url-safe' } ) . length , 0 ) ;
27- t . is ( cryptoRandomString ( 10 , { type : 'url-safe' } ) . length , 10 ) ;
28- t . is ( cryptoRandomString ( 100 , { type : 'url-safe' } ) . length , 100 ) ;
29- t . regex ( cryptoRandomString ( 100 , { type : 'url-safe' } ) , / ^ [ a - z A - Z \d . _ ~ - ] * $ / ) ; // Sanity check, probabilistic
26+ t . is ( cryptoRandomString ( { length : 0 , type : 'url-safe' } ) . length , 0 ) ;
27+ t . is ( cryptoRandomString ( { length : 10 , type : 'url-safe' } ) . length , 10 ) ;
28+ t . is ( cryptoRandomString ( { length : 100 , type : 'url-safe' } ) . length , 100 ) ;
29+ t . regex ( cryptoRandomString ( { length : 100 , type : 'url-safe' } ) , / ^ [ a - z A - Z \d . _ ~ - ] * $ / ) ; // Sanity check, probabilistic
3030} ) ;
3131
3232test ( 'characters' , t => {
33- t . is ( cryptoRandomString ( 0 , { characters : '1234' } ) . length , 0 ) ;
34- t . is ( cryptoRandomString ( 10 , { characters : '1234' } ) . length , 10 ) ;
35- t . is ( cryptoRandomString ( 100 , { characters : '1234' } ) . length , 100 ) ;
36- t . regex ( cryptoRandomString ( 100 , { characters : '1234' } ) , / ^ [ 1 - 4 ] * $ / ) ; // Sanity check, probabilistic
33+ t . is ( cryptoRandomString ( { length : 0 , characters : '1234' } ) . length , 0 ) ;
34+ t . is ( cryptoRandomString ( { length : 10 , characters : '1234' } ) . length , 10 ) ;
35+ t . is ( cryptoRandomString ( { length : 100 , characters : '1234' } ) . length , 100 ) ;
36+ t . regex ( cryptoRandomString ( { length : 100 , characters : '1234' } ) , / ^ [ 1 - 4 ] * $ / ) ; // Sanity check, probabilistic
3737} ) ;
3838
3939test ( 'argument errors' , t => {
4040 t . throws ( ( ) => {
41- cryptoRandomString ( Infinity ) ;
41+ cryptoRandomString ( { length : Infinity } ) ;
4242 } ) ;
4343
4444 t . throws ( ( ) => {
45- cryptoRandomString ( 0 , { type : 'hex' , characters : '1234' } ) ;
45+ cryptoRandomString ( { length : 0 , type : 'hex' , characters : '1234' } ) ;
4646 } ) ;
4747
4848 t . throws ( ( ) => {
49- cryptoRandomString ( 0 , { characters : 42 } ) ;
49+ cryptoRandomString ( { length : 0 , characters : 42 } ) ;
5050 } ) ;
5151
5252 t . throws ( ( ) => {
53- cryptoRandomString ( 0 , { type : 'unknown' } ) ;
53+ cryptoRandomString ( { length : 0 , type : 'unknown' } ) ;
5454 } ) ;
5555} ) ;
0 commit comments