regexp-examples 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97f98bdeee2363a4103134a035ccac28f1e6a295
4
- data.tar.gz: 2287c4ba5ab2503b11d365a8c63d37bef36fedb6
3
+ metadata.gz: 9df53956931ca38a9bdcd9f7da1318a80922bfee
4
+ data.tar.gz: f884ae6fe38349486eb86f15ffb63eca6febb5ef
5
5
  SHA512:
6
- metadata.gz: 461ae18a43b65a36cb04c6f5036c2a63ae8ea159820eb9bb02b7267b9b7718b474e6eae480afae8f9f89fb9c0231399c8388ac12179f603288810aa6c112a2a5
7
- data.tar.gz: 883b05b33bfec6f6a30ca6534fe86fed248f9f24b9a6c1c87f2e797f8a98dbda02fb66db673bc9c889f7938003ae03a2e0ec58d5e92a34af83f82f4ae4b4c9c6
6
+ metadata.gz: 5ec27e327cc331647dcfabe9f9d9028b96fd43051e3e56dae9d9b200683cbd704c62af78faff19740e7cecd008d47946e7dfc4871c480a24985eae857831dbe9
7
+ data.tar.gz: 8e999b7e0d41191d6cc0b3bfbf7069294a1faedb053468c8cf714f0310e2b06f2d7f65b678387d3020c64525a41d98d3e5444628bc3e0cf44ddab779b2763f64
data/README.md CHANGED
@@ -9,6 +9,7 @@ This method generates a list of (some\*) strings that will match the given regul
9
9
 
10
10
  \* If the regex has an infinite number of possible srings that match it, such as `/a*b+c{2,}/`,
11
11
  or a huge number of possible matches, such as `/.\w/`, then only a subset of these will be listed.
12
+ For more detail on this, see [configuration options](#configuration_options).
12
13
 
13
14
  ## Usage
14
15
 
@@ -63,15 +64,50 @@ Using any of the following will raise a RegexpExamples::IllegalSyntax exception:
63
64
 
64
65
  (Note: Backreferences are not really "regular" either, but I got these to work with a bit of hackery!)
65
66
 
67
+ <a name="configuration_options"/>
68
+ ##Configuration Options
69
+
70
+ When generating examples, the gem uses 2 configurable values to limit how many examples are listed:
71
+
72
+ * `max_repeater_variance` (default = `2`) restricts how many examples to return for each repeater. For example:
73
+ * `.*` is equivalent to `.{0,2}`
74
+ * `.+` is equivalent to `.{1,3}`
75
+ * `.{2,}` is equivalent to `.{2,4}`
76
+ * `.{,3}` is equivalent to `.{0,2}`
77
+ * `.{3,8}` is equivalent to `.{3,5}`
78
+
79
+ * `max_group_results` (default = `5`) restricts how many characters to return for each "set". For example:
80
+ * `\d` is equivalent to `[01234]`
81
+ * `\w` is equivalent to `[abcde]`
82
+ * `[h-s]` is equivalent to `[hijkl]`
83
+ * `(1|2|3|4|5|6|7|8)` is equivalent to `[12345]`
84
+
85
+ To use an alternative value, simply pass the configuration option as follows:
86
+
87
+ ```ruby
88
+ /a*/.examples(max_repeater_variance: 5) #=> [''. 'a', 'aa', 'aaa', 'aaaa' 'aaaaa']
89
+ /[F-X]/.examples(max_group_results: 10) #=> ['F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O']
90
+ ```
91
+
92
+ **_WARNING_**: Choosing huge numbers, along with a "complex" regex, could easily cause your system to freeze!
93
+
94
+ For example, if you try to generate a list of _all_ 5-letter words: `/\w{5}/.examples(max_group_results: 999)`, then since there are actually `63` "word" characters (upper/lower case letters, numbers and "\_"), this will try to generate `63**5 #=> 992436543` (almost 1 _trillion_) examples!
95
+
96
+ In other words, think twice before playing around with this config!
97
+
98
+ A more sensible use case might be, for example, to generate one random 1-4 digit string:
99
+
100
+ `/\d{1,4}/.examples(max_repeater_variance: 3, max_group_results: 10).sample(1)`
101
+
102
+ (Note: I may develop a much more efficient way to "generate one example" in a later release of this gem.)
103
+
66
104
  ## Known Bugs
67
105
 
68
106
  There are a few obscure bugs that have yet to be resolved:
69
107
 
70
108
  * Various (weird!) legal patterns do not get parsed correctly, such as `/[[wtf]]/.examples` - To solve this, I'll probably have to dig deep into the Ruby source code and imitate the actual Regex parser more closely.
71
109
 
72
- * Not all examples are shown for repeated groups, e.g. `/[ab]{2}/.examples` does not contain `"ab"` or `"ba"`. This is due to a flaw in the current parser design, and will be fixed in the next major release.
73
-
74
- * Similarly, examples like `/(a){2} \1/.examples #=> ["aa aa"]` do not quite work properly, as the backreference is saved as `"aa"`, rather than just `"a"`. This bug is closely related to the one above.
110
+ * Backreferences are replaced by the _first_ occurance of the group, not the _last_ (as it should be). This is quite a rare occurance, but for example: `/(a|b){2} \1/.examples` incorrectly includes: `"ba b"` rather than the correct: `"ba a"`
75
111
 
76
112
  ## Installation
77
113
 
@@ -16,26 +16,26 @@
16
16
  null,
17
17
  null,
18
18
  1,
19
- 353,
20
- 353,
21
- 205,
22
- 295,
19
+ 813,
20
+ 813,
21
+ 256,
22
+ 350,
23
23
  null,
24
24
  null,
25
25
  null,
26
26
  1,
27
- 295,
28
- 295,
27
+ 350,
28
+ 350,
29
29
  null,
30
30
  null,
31
- 295,
31
+ 350,
32
32
  null,
33
33
  null,
34
34
  1,
35
35
  null,
36
- 208,
37
- 107,
38
- 107,
36
+ 220,
37
+ 117,
38
+ 117,
39
39
  null,
40
40
  null,
41
41
  null,
@@ -46,82 +46,86 @@
46
46
  1,
47
47
  1,
48
48
  1,
49
- 394,
49
+ 410,
50
50
  null,
51
51
  null,
52
52
  1,
53
- 353,
54
- 353,
55
- 353,
56
- 391,
57
- 499,
53
+ 369,
54
+ 369,
55
+ 369,
56
+ 414,
57
+ 19,
58
+ null,
59
+ null,
60
+ null,
61
+ 395,
58
62
  null,
59
63
  null,
60
- 353,
64
+ 369,
61
65
  null,
62
66
  null,
63
67
  null,
64
68
  1,
65
69
  1,
66
- 366,
70
+ 376,
67
71
  null,
68
72
  null,
69
73
  1,
70
- 325,
74
+ 335,
71
75
  null,
72
76
  null,
73
77
  null,
74
78
  1,
75
79
  1,
76
- 6,
80
+ 5,
77
81
  null,
78
82
  null,
79
83
  1,
80
- 6,
84
+ 5,
81
85
  null,
82
86
  null,
83
87
  null,
84
88
  1,
85
89
  1,
86
- 5,
90
+ 7,
87
91
  null,
88
92
  null,
89
93
  1,
90
- 5,
94
+ 7,
91
95
  null,
92
96
  null,
93
97
  null,
94
98
  1,
95
99
  1,
96
- 11,
100
+ 13,
97
101
  null,
98
102
  null,
99
103
  1,
100
- 11,
104
+ 13,
101
105
  null,
102
106
  null,
103
107
  null,
104
108
  1,
105
109
  1,
106
- 6,
107
- 6,
108
- 6,
110
+ 9,
111
+ 9,
112
+ 9,
109
113
  null,
110
- 2,
111
- 4,
114
+ 3,
115
+ 6,
112
116
  1,
113
117
  null,
114
- 3,
118
+ 5,
115
119
  null,
116
120
  null,
117
121
  null,
118
122
  1,
119
- 6,
123
+ 9,
120
124
  null,
121
125
  null,
122
126
  1,
123
127
  1,
124
- 2,
128
+ 3,
125
129
  null,
126
130
  null,
127
131
  null,
@@ -131,19 +135,25 @@
131
135
  1,
132
136
  1,
133
137
  1,
134
- 89,
135
- 183,
136
- 28,
137
138
  null,
138
- 183,
139
+ 215,
140
+ 215,
141
+ 32,
142
+ null,
143
+ 213,
144
+ null,
145
+ null,
139
146
  null,
147
+ 2,
148
+ null,
149
+ 95,
140
150
  null,
141
151
  null,
142
152
  1,
143
153
  1,
144
- 28,
145
- 76,
146
154
  null,
155
+ 80,
156
+ 32,
147
157
  null,
148
158
  null,
149
159
  null,
@@ -155,24 +165,42 @@
155
165
  1,
156
166
  1,
157
167
  1,
168
+ 1,
158
169
  null
159
170
  ],
160
171
  "/home/tom/git/regexp-examples/lib/regexp-examples/constants.rb": [
161
172
  1,
173
+ 1,
174
+ null,
175
+ null,
176
+ null,
177
+ null,
162
178
  null,
163
179
  null,
164
180
  null,
181
+ 1,
182
+ null,
183
+ null,
165
184
  null,
166
185
  null,
167
186
  null,
187
+ 1,
168
188
  null,
169
189
  1,
190
+ 1,
191
+ 1,
192
+ 112,
193
+ 112,
170
194
  null,
171
195
  null,
172
196
  null,
173
197
  null,
198
+ 1,
199
+ 16,
174
200
  null,
175
201
  1,
202
+ 369,
203
+ null,
176
204
  null,
177
205
  1,
178
206
  1,
@@ -211,42 +239,46 @@
211
239
  1,
212
240
  1,
213
241
  1,
214
- 106,
215
- 106,
216
- 106,
242
+ 112,
243
+ 112,
244
+ 112,
245
+ 112,
246
+ null,
247
+ null,
248
+ null,
217
249
  null,
218
250
  null,
219
251
  1,
220
- 157,
221
- 157,
222
- 453,
223
- 435,
224
- 394,
225
- 9,
252
+ 169,
253
+ 169,
254
+ 473,
255
+ 455,
256
+ 410,
257
+ 11,
226
258
  null,
227
- 385,
228
- 385,
259
+ 399,
260
+ 399,
229
261
  null,
230
- 130,
262
+ 140,
231
263
  null,
232
264
  null,
233
265
  1,
234
266
  null,
235
267
  1,
236
- 453,
237
- 453,
268
+ 473,
269
+ 473,
238
270
  null,
239
- 46,
271
+ 50,
240
272
  null,
241
- 41,
273
+ 45,
242
274
  null,
243
275
  27,
244
276
  null,
245
277
  4,
246
278
  null,
247
- 9,
279
+ 11,
248
280
  null,
249
- 63,
281
+ 66,
250
282
  null,
251
283
  2,
252
284
  1,
@@ -260,22 +292,22 @@
260
292
  1,
261
293
  null,
262
294
  null,
263
- 259,
295
+ 266,
264
296
  null,
265
- 435,
297
+ 455,
266
298
  null,
267
299
  null,
268
300
  1,
269
- 63,
301
+ 66,
270
302
  null,
271
303
  null,
272
- 19,
273
- 19,
304
+ 21,
305
+ 21,
274
306
  null,
275
307
  1,
276
308
  1,
277
309
  null,
278
- 14,
310
+ 15,
279
311
  null,
280
312
  null,
281
313
  null,
@@ -312,35 +344,35 @@
312
344
  null,
313
345
  null,
314
346
  2,
315
- 63,
316
- 53,
347
+ 66,
348
+ 56,
317
349
  null,
318
350
  null,
319
351
  1,
320
- 385,
321
- 385,
322
- null,
323
- 6,
352
+ 399,
353
+ 399,
324
354
  null,
325
355
  5,
326
356
  null,
327
- 11,
357
+ 7,
328
358
  null,
329
- 6,
359
+ 13,
360
+ null,
361
+ 9,
330
362
  null,
331
- 357,
363
+ 365,
332
364
  null,
333
- 385,
365
+ 399,
334
366
  null,
335
367
  null,
336
368
  1,
337
- 46,
338
- 46,
339
- 46,
340
- 46,
369
+ 50,
370
+ 50,
371
+ 50,
372
+ 50,
341
373
  null,
342
374
  null,
343
- 38,
375
+ 42,
344
376
  null,
345
377
  1,
346
378
  1,
@@ -351,14 +383,14 @@
351
383
  null,
352
384
  3,
353
385
  3,
354
- 46,
386
+ 50,
355
387
  null,
356
- 42,
357
- 41,
388
+ 46,
389
+ 45,
358
390
  null,
359
391
  null,
360
392
  1,
361
- 41,
393
+ 45,
362
394
  null,
363
395
  null,
364
396
  1,
@@ -379,8 +411,8 @@
379
411
  null,
380
412
  null,
381
413
  null,
382
- 105,
383
- 105,
414
+ 102,
415
+ 102,
384
416
  null,
385
417
  26,
386
418
  null,
@@ -390,18 +422,18 @@
390
422
  null,
391
423
  null,
392
424
  1,
393
- 9,
394
- 9,
395
- 9,
425
+ 11,
426
+ 11,
427
+ 11,
396
428
  null,
397
429
  null,
398
430
  null,
399
431
  1,
400
- 280,
432
+ 287,
401
433
  null,
402
434
  null,
403
435
  1,
404
- 20,
436
+ 22,
405
437
  null,
406
438
  null,
407
439
  1,
@@ -418,35 +450,35 @@
418
450
  null,
419
451
  null,
420
452
  1,
421
- 6,
422
- 6,
453
+ 5,
454
+ 5,
423
455
  null,
424
456
  null,
425
457
  1,
426
- 5,
427
- 5,
458
+ 7,
459
+ 7,
428
460
  null,
429
461
  null,
430
462
  1,
431
- 11,
432
- 11,
463
+ 13,
464
+ 13,
433
465
  null,
434
466
  null,
435
467
  1,
436
- 6,
437
- 6,
438
- 6,
439
- 6,
440
- 6,
441
- 6,
468
+ 9,
469
+ 9,
470
+ 9,
471
+ 9,
472
+ 9,
473
+ 9,
442
474
  null,
443
475
  null,
444
476
  1,
445
- 357,
477
+ 365,
446
478
  null,
447
479
  null,
448
480
  1,
449
- 306,
481
+ 317,
450
482
  null,
451
483
  null,
452
484
  null,
@@ -460,75 +492,69 @@
460
492
  1,
461
493
  1,
462
494
  1,
463
- 1882,
464
- 1882,
465
- 1882,
466
- 142,
495
+ 1491,
496
+ 1491,
497
+ 1491,
498
+ 155,
467
499
  null,
468
- 1882,
500
+ 1491,
469
501
  null,
470
502
  null,
471
503
  1,
472
- 1939,
473
- null,
474
- null,
475
- null,
476
- null,
477
- 1,
478
- 499,
504
+ 2213,
479
505
  null,
480
506
  null,
481
507
  null,
482
508
  1,
483
509
  1,
484
- 280,
510
+ 287,
485
511
  null,
486
512
  1,
487
- 242,
513
+ 249,
488
514
  null,
489
515
  null,
490
516
  null,
491
517
  1,
492
518
  1,
493
- 40,
494
- 40,
495
- 11,
496
- 11,
519
+ 41,
520
+ 41,
521
+ 10,
522
+ 10,
497
523
  null,
498
- 29,
524
+ 31,
499
525
  null,
500
526
  null,
501
- 40,
502
- 40,
527
+ 41,
528
+ 41,
503
529
  null,
504
530
  null,
505
531
  1,
506
532
  null,
507
- 40,
508
- 40,
509
- 40,
510
- 40,
533
+ 41,
534
+ 41,
535
+ 41,
536
+ 41,
511
537
  null,
512
- 40,
538
+ 41,
513
539
  null,
514
540
  null,
515
- 26,
516
- 15,
517
- 15,
541
+ 25,
542
+ 14,
543
+ 14,
518
544
  null,
519
545
  11,
520
546
  null,
521
547
  null,
522
548
  null,
523
- 40,
524
- 40,
549
+ 41,
550
+ 41,
525
551
  null,
526
552
  null,
527
553
  1,
528
- 40,
529
- 1430,
530
- 32,
531
- 22,
554
+ 41,
555
+ 1348,
556
+ 30,
557
+ 20,
532
558
  null,
533
559
  1,
534
560
  null,
@@ -541,17 +567,17 @@
541
567
  null,
542
568
  null,
543
569
  1,
544
- 40,
545
- 590,
570
+ 41,
571
+ 602,
546
572
  null,
547
573
  null,
548
574
  null,
549
575
  1,
550
576
  1,
551
- 547,
552
- 10,
577
+ 534,
578
+ 9,
553
579
  null,
554
- 22,
580
+ 20,
555
581
  null,
556
582
  null,
557
583
  null,
@@ -566,17 +592,17 @@
566
592
  1,
567
593
  1,
568
594
  1,
569
- 41,
570
- 41,
595
+ 45,
596
+ 45,
571
597
  null,
572
598
  null,
573
599
  null,
574
600
  null,
575
601
  null,
576
602
  1,
577
- 186,
578
- 41,
579
- 113,
603
+ 194,
604
+ 45,
605
+ 119,
580
606
  null,
581
607
  null,
582
608
  null,
@@ -586,17 +612,16 @@
586
612
  null,
587
613
  1,
588
614
  1,
589
- 9,
590
- 9,
615
+ 11,
616
+ 11,
591
617
  null,
592
618
  null,
593
619
  null,
594
620
  1,
595
- 9,
596
- 9,
597
- null,
598
- 9,
599
- 29,
621
+ 11,
622
+ 11,
623
+ 11,
624
+ 36,
600
625
  null,
601
626
  null,
602
627
  null,
@@ -604,11 +629,11 @@
604
629
  1,
605
630
  1,
606
631
  1,
607
- 20,
632
+ 22,
608
633
  null,
609
634
  null,
610
635
  1,
611
- 20,
636
+ 22,
612
637
  null,
613
638
  null,
614
639
  null,
@@ -618,16 +643,10 @@
618
643
  1,
619
644
  1,
620
645
  1,
646
+ 112,
621
647
  null,
622
648
  null,
623
- null,
624
- null,
625
- null,
626
- null,
627
- 106,
628
- null,
629
- null,
630
- 89,
649
+ 95,
631
650
  null,
632
651
  null,
633
652
  1,
@@ -637,11 +656,11 @@
637
656
  "/home/tom/git/regexp-examples/spec/regexp-examples_spec.rb": [
638
657
  1,
639
658
  1,
640
- 12,
641
- 79,
642
- 79,
643
- 79,
644
- 262,
659
+ 11,
660
+ 80,
661
+ 80,
662
+ 80,
663
+ 263,
645
664
  null,
646
665
  null,
647
666
  null,
@@ -668,8 +687,8 @@
668
687
  null,
669
688
  1,
670
689
  1,
671
- 10,
672
- 10,
690
+ 9,
691
+ 9,
673
692
  null,
674
693
  null,
675
694
  null,
@@ -756,6 +775,8 @@
756
775
  null,
757
776
  null,
758
777
  null,
778
+ null,
779
+ null,
759
780
  1,
760
781
  null,
761
782
  1,
@@ -851,9 +872,27 @@
851
872
  null,
852
873
  null,
853
874
  null,
875
+ 1,
876
+ null,
877
+ 1,
878
+ 2,
879
+ 2,
880
+ 2,
881
+ null,
882
+ 1,
883
+ 1,
884
+ 1,
885
+ null,
886
+ null,
887
+ 1,
888
+ 1,
889
+ null,
890
+ null,
854
891
  null,
855
892
  1,
856
893
  1,
894
+ 1,
895
+ null,
857
896
  null,
858
897
  null,
859
898
  null,
@@ -862,6 +901,6 @@
862
901
  null
863
902
  ]
864
903
  },
865
- "timestamp": 1422115371
904
+ "timestamp": 1422185398
866
905
  }
867
906
  }