1
1
import { when } from 'jest-when' ;
2
+ import { Chars } from './constants' ;
2
3
import Expansion from './Expansion' ;
3
4
import { fill } from './helpers/utils' ;
4
5
import * as patternLib from './pattern' ;
@@ -363,7 +364,7 @@ describe('expand', () => {
363
364
}
364
365
365
366
const result = expandAll ( '[^abc]' ) ;
366
- expect ( result . length ) . toBeGreaterThan ( 1 ) ;
367
+ expect ( result ) . toHaveLength ( 95 ) ;
367
368
result . forEach ( testExpansion ) ;
368
369
} ) ;
369
370
@@ -374,7 +375,7 @@ describe('expand', () => {
374
375
}
375
376
376
377
const result = expandAll ( '[^246]' ) ;
377
- expect ( result . length ) . toBeGreaterThan ( 1 ) ;
378
+ expect ( result ) . toHaveLength ( 95 ) ;
378
379
result . forEach ( testExpansion ) ;
379
380
} ) ;
380
381
@@ -385,7 +386,7 @@ describe('expand', () => {
385
386
}
386
387
387
388
const result = expandAll ( '[^a-p]' ) ;
388
- expect ( result . length ) . toBeGreaterThan ( 1 ) ;
389
+ expect ( result ) . toHaveLength ( 82 ) ;
389
390
result . forEach ( testExpansion ) ;
390
391
} ) ;
391
392
@@ -396,7 +397,7 @@ describe('expand', () => {
396
397
}
397
398
398
399
const result = expandAll ( '[^0-8]' ) ;
399
- expect ( result . length ) . toBeGreaterThan ( 1 ) ;
400
+ expect ( result ) . toHaveLength ( 89 ) ;
400
401
result . forEach ( testExpansion ) ;
401
402
} ) ;
402
403
@@ -407,7 +408,7 @@ describe('expand', () => {
407
408
}
408
409
409
410
const result = expandAll ( '[^aeiou0-5A-T]' ) ;
410
- expect ( result . length ) . toBeGreaterThan ( 1 ) ;
411
+ expect ( result ) . toHaveLength ( 67 ) ;
411
412
result . forEach ( testExpansion ) ;
412
413
} ) ;
413
414
@@ -438,10 +439,14 @@ describe('expand', () => {
438
439
it . each ( [ / ./ , / \w / , / \W / , / \d / , / \D / , / \s / , / \S / ] ) (
439
440
'expands the single character class %p' ,
440
441
( charClass : RegExp ) => {
442
+ function testExpansion ( expansion : string ) {
443
+ expect ( expansion ) . toHaveLength ( 1 ) ;
444
+ expect ( expansion ) . toMatch ( charClass ) ;
445
+ }
446
+
441
447
const result = expandAll ( charClass ) ;
442
448
expect ( result . length ) . toBeGreaterThan ( 1 ) ;
443
- expect ( result [ 0 ] ) . toHaveLength ( 1 ) ;
444
- expect ( result [ 0 ] ) . toMatch ( charClass ) ;
449
+ result . forEach ( testExpansion ) ;
445
450
}
446
451
) ;
447
452
@@ -562,6 +567,17 @@ describe('expand', () => {
562
567
}
563
568
) ;
564
569
570
+ it . each ( [ / ( .| \r ) / s, / [ \s \S ] / ] ) (
571
+ 'includes all supported characters in %p' ,
572
+ regex => {
573
+ const result = expandAll ( regex ) ;
574
+
575
+ Chars . all . forEach ( char => {
576
+ expect ( result ) . toContain ( char ) ;
577
+ } ) ;
578
+ }
579
+ ) ;
580
+
565
581
it ( 'expands repeated character class' , ( ) => {
566
582
const allTwoDigitNumbers = fill ( 0 , 99 ) . map ( num =>
567
583
num . toString ( ) . padStart ( 2 , '0' )
0 commit comments