File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,10 @@ module.exports = class RandExp {
236
236
*/
237
237
static randexp ( regexp , m ) {
238
238
var randexp ;
239
+ if ( typeof regexp === 'string' ) {
240
+ regexp = new RegExp ( regexp , m ) ;
241
+ }
242
+
239
243
if ( regexp . _randexp === undefined ) {
240
244
randexp = new RandExp ( regexp , m ) ;
241
245
regexp . _randexp = randexp ;
Original file line number Diff line number Diff line change @@ -53,6 +53,13 @@ describe('Call with a string', () => {
53
53
} ) ;
54
54
} ) ;
55
55
56
+ describe ( 'Call shorthand randexp method with a string' , ( ) => {
57
+ it ( 'Returns a correctly generated string' , ( ) => {
58
+ var r = randexp ( '\\d{4}' ) ;
59
+ assert . equal ( r . length , 4 ) ;
60
+ } ) ;
61
+ } ) ;
62
+
56
63
describe ( 'Call without a string or regular expression' , ( ) => {
57
64
it ( 'Throws an error' , ( ) => {
58
65
assert . throws ( ( ) => {
You can’t perform that action at this time.
0 commit comments