@@ -74,9 +74,7 @@ describe('exactly', () => {
74
74
expect ( oneOrMore ( exactly ( 'foo' ) ) . toString ( ) ) . toBe ( '(?:foo)+' ) ;
75
75
} ) ;
76
76
it ( 'cannot be negated' , ( ) => {
77
- // @ts -expect-error - repeat is not negatable
78
77
expect ( ( ) => not . exactly `foo` . toString ( ) ) . toThrow ( ) ;
79
- // @ts -expect-error - repeat is not negatable
80
78
expect ( ( ) => not ( exactly ( 'foo' ) ) . toString ( ) ) . toThrow ( ) ;
81
79
} ) ;
82
80
it ( 'throws for invalid argument' , ( ) => {
@@ -200,17 +198,14 @@ describe('not', () => {
200
198
expect ( not . whitespace . not ( whitespace ) . not . whitespace . toString ( ) ) . toBe ( '\\S\\S\\S' ) ;
201
199
} ) ;
202
200
it ( 'does not allow non-negatable tokens' , ( ) => {
203
- // @ts -expect-error - not(char) is not negatable
204
201
expect ( ( ) => not ( char ) ) . toThrow ( ) ;
205
202
} ) ;
206
203
it ( 'can be quantified' , ( ) => {
207
204
expect ( oneOrMore . not . word . toString ( ) ) . toBe ( '\\W+' ) ;
208
205
expect ( oneOrMore ( not ( word ) ) . toString ( ) ) . toBe ( '\\W+' ) ;
209
206
} ) ;
210
207
it ( 'cannot be negated' , ( ) => {
211
- // @ts -expect-error - repeat is not negatable
212
208
expect ( ( ) => not . not . word . toString ( ) ) . toThrow ( ) ;
213
- // @ts -expect-error - repeat is not negatable
214
209
expect ( ( ) => not ( not ( word ) ) . toString ( ) ) . toThrow ( ) ;
215
210
} ) ;
216
211
it ( 'throws for invalid argument' , ( ) => {
@@ -249,14 +244,11 @@ describe('repeat', () => {
249
244
expect ( repeat ( 3 , 3 ) `foo` . toString ( ) ) . toBe ( '(?:foo){3}' ) ;
250
245
} ) ;
251
246
it ( 'cannot be quantified in dot syntax' , ( ) => {
252
- // @ts -expect-error - stacking quantifiers only cause error in dot syntax
253
247
expect ( oneOrMore . repeat ( 3 , 5 ) `foo` . toString ( ) ) . toBe ( '(?:(?:foo){3,5})+' ) ;
254
248
expect ( oneOrMore ( repeat ( 3 , 5 ) `foo` ) . toString ( ) ) . toBe ( '(?:(?:foo){3,5})+' ) ;
255
249
} ) ;
256
250
it ( 'cannot be negated' , ( ) => {
257
- // @ts -expect-error - repeat is not negatable
258
251
expect ( ( ) => not . repeat ( 3 , 5 ) `foo` . toString ( ) ) . toThrow ( ) ;
259
- // @ts -expect-error - repeat is not negatable
260
252
expect ( ( ) => not ( repeat ( 3 , 5 ) `foo` ) . toString ( ) ) . toThrow ( ) ;
261
253
} ) ;
262
254
it ( 'supports lazily' , ( ) => {
@@ -302,14 +294,11 @@ describe('atLeast', () => {
302
294
expect ( atLeast ( 3 ) . exactly `foo` . toString ( ) ) . toBe ( '(?:foo){3,}' ) ;
303
295
} ) ;
304
296
it ( 'cannot be quantified in dot syntax' , ( ) => {
305
- // @ts -expect-error - stacking quantifiers only cause error in dot syntax
306
297
expect ( oneOrMore . atLeast ( 3 ) `foo` . toString ( ) ) . toBe ( '(?:(?:foo){3,})+' ) ;
307
298
expect ( oneOrMore ( atLeast ( 3 ) `foo` ) . toString ( ) ) . toBe ( '(?:(?:foo){3,})+' ) ;
308
299
} ) ;
309
300
it ( 'cannot be negated' , ( ) => {
310
- // @ts -expect-error - atLeast is not negatable
311
301
expect ( ( ) => not . atLeast ( 3 ) `foo` . toString ( ) ) . toThrow ( ) ;
312
- // @ts -expect-error - atLeast is not negatable
313
302
expect ( ( ) => not ( atLeast ( 3 ) `foo` ) . toString ( ) ) . toThrow ( ) ;
314
303
} ) ;
315
304
it ( 'supports lazily' , ( ) => {
@@ -351,14 +340,11 @@ describe('atMost', () => {
351
340
expect ( atMost ( 3 ) . exactly `foo` . toString ( ) ) . toBe ( '(?:foo){,3}' ) ;
352
341
} ) ;
353
342
it ( 'cannot be quantified in dot syntax' , ( ) => {
354
- // @ts -expect-error - stacking quantifiers only cause error in dot syntax
355
343
expect ( oneOrMore . atMost ( 3 ) `foo` . toString ( ) ) . toBe ( '(?:(?:foo){,3})+' ) ;
356
344
expect ( oneOrMore ( atMost ( 3 ) `foo` ) . toString ( ) ) . toBe ( '(?:(?:foo){,3})+' ) ;
357
345
} ) ;
358
346
it ( 'cannot be negated' , ( ) => {
359
- // @ts -expect-error - atMost is not negatable
360
347
expect ( ( ) => not . atMost ( 3 ) `foo` . toString ( ) ) . toThrow ( ) ;
361
- // @ts -expect-error - atMost is not negatable
362
348
expect ( ( ) => not ( atMost ( 3 ) `foo` ) . toString ( ) ) . toThrow ( ) ;
363
349
} ) ;
364
350
it ( 'supports lazily' , ( ) => {
@@ -404,14 +390,11 @@ describe('maybe', () => {
404
390
expect ( exactly ( 'foo' ) . maybe ( exactly ( 'foo' ) ) . toString ( ) ) . toBe ( 'foo(?:foo)?' ) ;
405
391
} ) ;
406
392
it ( 'cannot be quantified in dot syntax' , ( ) => {
407
- // @ts -expect-error - stacking quantifiers only cause error in dot syntax
408
393
expect ( oneOrMore . maybe `foo` . toString ( ) ) . toBe ( '(?:(?:foo)?)+' ) ;
409
394
expect ( oneOrMore ( maybe `foo` ) . toString ( ) ) . toBe ( '(?:(?:foo)?)+' ) ;
410
395
} ) ;
411
396
it ( 'cannot be negated' , ( ) => {
412
- // @ts -expect-error - maybe is not negatable
413
397
expect ( ( ) => not . maybe `foo` . toString ( ) ) . toThrow ( ) ;
414
- // @ts -expect-error - maybe is not negatable
415
398
expect ( ( ) => not ( maybe `foo` ) . toString ( ) ) . toThrow ( ) ;
416
399
} ) ;
417
400
it ( 'supports lazily' , ( ) => {
@@ -447,14 +430,11 @@ describe('zeroOrMore', () => {
447
430
expect ( exactly ( 'foo' ) . zeroOrMore ( exactly ( 'foo' ) ) . toString ( ) ) . toBe ( 'foo(?:foo)*' ) ;
448
431
} ) ;
449
432
it ( 'cannot be quantified in dot syntax' , ( ) => {
450
- // @ts -expect-error - stacking quantifiers only cause error in dot syntax
451
433
expect ( oneOrMore . zeroOrMore `foo` . toString ( ) ) . toBe ( '(?:(?:foo)*)+' ) ;
452
434
expect ( oneOrMore ( zeroOrMore `foo` ) . toString ( ) ) . toBe ( '(?:(?:foo)*)+' ) ;
453
435
} ) ;
454
436
it ( 'cannot be negated' , ( ) => {
455
- // @ts -expect-error - zeroOrMore is not negatable
456
437
expect ( ( ) => not . zeroOrMore `foo` . toString ( ) ) . toThrow ( ) ;
457
- // @ts -expect-error - zeroOrMore is not negatable
458
438
expect ( ( ) => not ( zeroOrMore `foo` ) . toString ( ) ) . toThrow ( ) ;
459
439
} ) ;
460
440
it ( 'supports lazily' , ( ) => {
@@ -490,14 +470,11 @@ describe('oneOrMore', () => {
490
470
expect ( exactly ( 'foo' ) . oneOrMore ( exactly ( 'foo' ) ) . toString ( ) ) . toBe ( 'foo(?:foo)+' ) ;
491
471
} ) ;
492
472
it ( 'cannot be quantified in dot syntax' , ( ) => {
493
- // @ts -expect-error - stacking quantifiers only cause error in dot syntax
494
473
expect ( oneOrMore . oneOrMore `foo` . toString ( ) ) . toBe ( '(?:(?:foo)+)+' ) ;
495
474
expect ( oneOrMore ( oneOrMore `foo` ) . toString ( ) ) . toBe ( '(?:(?:foo)+)+' ) ;
496
475
} ) ;
497
476
it ( 'cannot be negated' , ( ) => {
498
- // @ts -expect-error - oneOrMore is not negatable
499
477
expect ( ( ) => not . oneOrMore `foo` . toString ( ) ) . toThrow ( ) ;
500
- // @ts -expect-error - oneOrMore is not negatable
501
478
expect ( ( ) => not ( oneOrMore `foo` ) . toString ( ) ) . toThrow ( ) ;
502
479
} ) ;
503
480
it ( 'supports lazily' , ( ) => {
@@ -518,13 +495,10 @@ describe('oneOrMore', () => {
518
495
describe ( 'lazily' , ( ) => {
519
496
it ( 'cannot be used alone' , ( ) => {
520
497
expect ( maybe . lazily `bar` . toString ( ) ) . toBe ( '(?:bar)??' ) ;
521
- // @ts -expect-error - lazily can only be used with a quantifier
522
498
expect ( ( ) => exactly `foo` . lazily `bar` ) . toThrow ( ) ;
523
499
} ) ;
524
500
it ( 'cannot be repeated' , ( ) => {
525
- // @ts -expect-error - lazily should only be used once
526
501
expect ( repeatLazily ( 3 , 5 ) . lazily `foo` . toString ( ) ) . toBe ( '(?:foo){3,5}?' ) ;
527
- // @ts -expect-error - lazily should only be used once
528
502
expect ( repeat ( 3 , 5 ) . lazily . lazily `foo` . toString ( ) ) . toBe ( '(?:foo){3,5}?' ) ;
529
503
} ) ;
530
504
it ( 'throws for invalid argument' , ( ) => {
@@ -559,9 +533,7 @@ describe('capture', () => {
559
533
expect ( oneOrMore ( capture `foo` ) . toString ( ) ) . toBe ( '(foo)+' ) ;
560
534
} ) ;
561
535
it ( 'cannot be negated' , ( ) => {
562
- // @ts -expect-error - capture is not negatable
563
536
expect ( ( ) => not . capture `foo` . toString ( ) ) . toThrow ( ) ;
564
- // @ts -expect-error - capture is not negatable
565
537
expect ( ( ) => not ( capture `foo` ) . toString ( ) ) . toThrow ( ) ;
566
538
} ) ;
567
539
it ( 'throws for invalid argument' , ( ) => {
@@ -610,9 +582,7 @@ describe('captureAs', () => {
610
582
expect ( oneOrMore ( captureAs `bar` `foo` ) . toString ( ) ) . toBe ( '(?<bar>foo)+' ) ;
611
583
} ) ;
612
584
it ( 'cannot be negated' , ( ) => {
613
- // @ts -expect-error - captureAs is not negatable
614
585
expect ( ( ) => not . captureAs `bar` `foo` . toString ( ) ) . toThrow ( ) ;
615
- // @ts -expect-error - captureAs is not negatable
616
586
expect ( ( ) => not ( captureAs `bar` `foo` ) . toString ( ) ) . toThrow ( ) ;
617
587
} ) ;
618
588
it ( 'throws for invalid argument' , ( ) => {
@@ -702,9 +672,7 @@ describe('ref', () => {
702
672
expect ( oneOrMore ( ref ( 12 ) ) ) . toHaveProperty ( 'regExp' , '\\12+' ) ;
703
673
} ) ;
704
674
it ( 'cannot be negated' , ( ) => {
705
- // @ts -expect-error - ref is not negatable
706
675
expect ( ( ) => not . ref `foo` ) . toThrow ( ) ;
707
- // @ts -expect-error - ref is not negatable
708
676
expect ( ( ) => not ( ref `foo` ) ) . toThrow ( ) ;
709
677
} ) ;
710
678
it ( 'throws for invalid argument' , ( ) => {
@@ -737,9 +705,7 @@ describe('group', () => {
737
705
expect ( oneOrMore ( group `foo` ) . toString ( ) ) . toBe ( '(?:foo)+' ) ;
738
706
} ) ;
739
707
it ( 'cannot be negated' , ( ) => {
740
- // @ts -expect-error - group is not negatable
741
708
expect ( ( ) => not . group `foo` . toString ( ) ) . toThrow ( ) ;
742
- // @ts -expect-error - group is not negatable
743
709
expect ( ( ) => not ( group `foo` ) . toString ( ) ) . toThrow ( ) ;
744
710
} ) ;
745
711
it ( 'throws for invalid argument' , ( ) => {
@@ -769,7 +735,6 @@ describe('ahead', () => {
769
735
expect ( exactly ( 'foo' ) . ahead ( exactly ( 'foo' ) ) . toString ( ) ) . toBe ( 'foo(?=foo)' ) ;
770
736
} ) ;
771
737
it ( 'can be quantified' , ( ) => {
772
- // @ts -expect-error - lookarounds are not quantifiable by themselves
773
738
expect ( oneOrMore . ahead `foo` . toString ( ) ) . toBe ( '(?:(?=foo))+' ) ;
774
739
expect ( oneOrMore ( ahead `foo` ) . toString ( ) ) . toBe ( '(?:(?=foo))+' ) ;
775
740
} ) ;
@@ -804,7 +769,6 @@ describe('behind', () => {
804
769
expect ( exactly ( 'foo' ) . behind ( exactly ( 'foo' ) ) . toString ( ) ) . toBe ( 'foo(?<=foo)' ) ;
805
770
} ) ;
806
771
it ( 'can be quantified' , ( ) => {
807
- // @ts -expect-error - lookarounds are not quantifiable by themselves
808
772
expect ( oneOrMore . behind `foo` . toString ( ) ) . toBe ( '(?:(?<=foo))+' ) ;
809
773
expect ( oneOrMore ( behind `foo` ) . toString ( ) ) . toBe ( '(?:(?<=foo))+' ) ;
810
774
} ) ;
@@ -839,14 +803,11 @@ describe('notAhead', () => {
839
803
expect ( exactly ( 'foo' ) . notAhead ( exactly ( 'foo' ) ) . toString ( ) ) . toBe ( 'foo(?!foo)' ) ;
840
804
} ) ;
841
805
it ( 'can be quantified' , ( ) => {
842
- // @ts -expect-error - lookarounds are not quantifiable by themselves
843
806
expect ( oneOrMore . notAhead `foo` . toString ( ) ) . toBe ( '(?:(?!foo))+' ) ;
844
807
expect ( oneOrMore ( notAhead `foo` ) . toString ( ) ) . toBe ( '(?:(?!foo))+' ) ;
845
808
} ) ;
846
809
it ( 'cannot be negated' , ( ) => {
847
- // @ts -expect-error - notAhead is not negatable
848
810
expect ( ( ) => not . notAhead `foo` . toString ( ) ) . toThrow ( ) ;
849
- // @ts -expect-error - notAhead is not negatable
850
811
expect ( ( ) => not ( notAhead `foo` ) . toString ( ) ) . toThrow ( ) ;
851
812
} ) ;
852
813
it ( 'throws for invalid argument' , ( ) => {
@@ -876,14 +837,11 @@ describe('notBehind', () => {
876
837
expect ( exactly ( 'foo' ) . notBehind ( exactly ( 'foo' ) ) . toString ( ) ) . toBe ( 'foo(?<!foo)' ) ;
877
838
} ) ;
878
839
it ( 'can be quantified' , ( ) => {
879
- // @ts -expect-error - lookarounds are not quantifiable by themselves
880
840
expect ( oneOrMore . notBehind `foo` . toString ( ) ) . toBe ( '(?:(?<!foo))+' ) ;
881
841
expect ( oneOrMore ( notBehind `foo` ) . toString ( ) ) . toBe ( '(?:(?<!foo))+' ) ;
882
842
} ) ;
883
843
it ( 'cannot be negated' , ( ) => {
884
- // @ts -expect-error - notBehind is not negatable
885
844
expect ( ( ) => not . notBehind `foo` . toString ( ) ) . toThrow ( ) ;
886
- // @ts -expect-error - notBehind is not negatable
887
845
expect ( ( ) => not ( notBehind `foo` ) . toString ( ) ) . toThrow ( ) ;
888
846
} ) ;
889
847
it ( 'throws for invalid argument' , ( ) => {
@@ -914,9 +872,7 @@ describe('oneOf', () => {
914
872
expect ( oneOrMore ( oneOf `foo` `bar` `baz` ) . toString ( ) ) . toBe ( '(?:foo|bar|baz)+' ) ;
915
873
} ) ;
916
874
it ( 'cannot be negated' , ( ) => {
917
- // @ts -expect-error - oneOf is not negatable
918
875
expect ( ( ) => not . oneOf `foo` `bar` `baz` . toString ( ) ) . toThrow ( ) ;
919
- // @ts -expect-error - oneOf is not negatable
920
876
expect ( ( ) => not ( oneOf `foo` `bar` `baz` ) . toString ( ) ) . toThrow ( ) ;
921
877
} ) ;
922
878
it ( 'throws for invalid argument' , ( ) => {
@@ -938,15 +894,11 @@ describe('match', () => {
938
894
expect ( oneOrMore . match ( exactly `baz` . char ) . toString ( ) ) . toBe ( '(?:baz.)+' ) ;
939
895
} ) ;
940
896
it ( 'verifies quantifiers' , ( ) => {
941
- // @ts -expect-error - match content is not quantifiable
942
897
expect ( ( ) => oneOrMore . match ( lineStart ) . toString ( ) ) . toThrow ( ) ;
943
- // @ts -expect-error - match content is not quantifiable
944
898
expect ( ( ) => oneOrMore ( match ( lineStart ) ) . toString ( ) ) . toThrow ( ) ;
945
899
} ) ;
946
900
it ( 'cannot be negated' , ( ) => {
947
- // @ts -expect-error - match is not negatable
948
901
expect ( ( ) => not . match ( exactly `foo` ) . toString ( ) ) . toThrow ( ) ;
949
- // @ts -expect-error - match is not negatable
950
902
expect ( ( ) => not ( match ( exactly `foo` ) ) . toString ( ) ) . toThrow ( ) ;
951
903
} ) ;
952
904
it ( 'throws for invalid argument' , ( ) => {
@@ -1023,9 +975,7 @@ describe('notCharIn', () => {
1023
975
expect ( oneOrMore . notCharIn `abc${ unicode `0123` } ${ unicode `fe3d` } ` . toString ( ) ) . toBe ( '[^abc\\u0123\\ufe3d]+' ) ;
1024
976
} ) ;
1025
977
it ( 'cannot be negated' , ( ) => {
1026
- // @ts -expect-error - notCharIn is not negatable
1027
978
expect ( ( ) => not . notCharIn `abc` `A-Z` `0-9` . toString ( ) ) . toThrow ( ) ;
1028
- // @ts -expect-error - notCharIn is not negatable
1029
979
expect ( ( ) => not ( notCharIn `abc` `A-Z` `0-9` ) . toString ( ) ) . toThrow ( ) ;
1030
980
} ) ;
1031
981
it ( 'throws for invalid argument' , ( ) => {
@@ -1040,8 +990,6 @@ describe('notCharIn', () => {
1040
990
1041
991
describe ( 'quantifiers' , ( ) => {
1042
992
it ( 'stacks properly' , ( ) => {
1043
- // @ts -expect-error - stacking quantifiers only cause error in dot syntax
1044
- // because the two quantifiers always have the same scope, and is thus redundant
1045
993
expect ( zeroOrMore . oneOrMore . exactly `foo` . toString ( ) ) . toBe ( '(?:(?:foo)+)*' ) ;
1046
994
expect ( zeroOrMore ( oneOrMore ( exactly `foo` ) ) . toString ( ) ) . toBe ( '(?:(?:foo)+)*' ) ;
1047
995
expect ( zeroOrMore ( digit . oneOrMore ( exactly `foo` ) ) . toString ( ) ) . toBe ( '(?:\\d(?:foo)+)*' ) ;
0 commit comments