1
1
// With verbose set to false, this test is successful if there is no output. Set verbose to true to see expected matches.
2
2
let verbose = false ;
3
3
4
+ let errors = 0 ;
5
+
4
6
function arrayToString ( arr )
5
7
{
6
8
let str = '' ;
@@ -30,7 +32,7 @@ function objectToString(obj)
30
32
31
33
firstEntry = false ;
32
34
}
33
-
35
+
34
36
return "{ " + str + " }" ;
35
37
}
36
38
@@ -139,17 +141,21 @@ function testRegExp(re, str, exp, groups)
139
141
if ( result ) {
140
142
if ( verbose )
141
143
print ( re . toString ( ) + ".exec(" + dumpValue ( str ) + "), passed " , dumpValue ( exp ) ) ;
142
- } else
144
+ } else {
143
145
print ( re . toString ( ) + ".exec(" + dumpValue ( str ) + "), FAILED test #" + testNumber + ", Expected " , dumpValue ( exp ) , " got " , dumpValue ( actual ) ) ;
146
+ errors ++ ;
147
+ }
144
148
}
145
149
146
150
function testRegExpSyntaxError ( reString , flags , expError )
147
151
{
148
152
testNumber ++ ;
149
153
154
+
150
155
try {
151
156
let re = new RegExp ( reString , flags ) ;
152
- print ( "FAILED test #" + testNumber + ", Expected /" + reString + "/" + flags + " to throw \"" + expError ) ;
157
+ print ( "FAILED test #" + testNumber + ", Expected /" + reString + "/" + flags + " to throw \"" + expError + "\", but it didn't" ) ;
158
+ errors ++ ;
153
159
} catch ( e ) {
154
160
if ( e != expError )
155
161
print ( "FAILED test #" + testNumber + ", Expected /" + reString + "/" + flags + " to throw \"" + expError + "\" got \"" + e + "\"" ) ;
@@ -158,6 +164,12 @@ function testRegExpSyntaxError(reString, flags, expError)
158
164
}
159
165
}
160
166
167
+ function printErrors ( )
168
+ {
169
+ if ( errors )
170
+ throw "Test had " + errors + " errors" ;
171
+ }
172
+
161
173
// Test 1
162
174
testRegExpSyntaxError ( "[\\p{RGI_Emoji_Tag_Sequence}a]" , "u" , "SyntaxError: Invalid regular expression: invalid property expression" ) ;
163
175
testRegExpSyntaxError ( "\\P{Emoji_Keycap_Sequence}" , "v" , "SyntaxError: Invalid regular expression: negated class set may contain strings" ) ;
@@ -520,58 +532,105 @@ testRegExpSyntaxError("\\%", "u", "SyntaxError: Invalid regular expression: inva
520
532
testRegExpSyntaxError ( "\\," , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
521
533
testRegExpSyntaxError ( "\\:" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
522
534
523
- // Test 256
535
+ // Test 261
524
536
testRegExpSyntaxError ( "\\;" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
525
537
testRegExpSyntaxError ( "\\<" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
526
538
testRegExpSyntaxError ( "\\=" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
527
539
testRegExpSyntaxError ( "\\>" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
528
540
testRegExpSyntaxError ( "\\@" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
529
541
530
- // Test 261
542
+ // Test 266
531
543
testRegExpSyntaxError ( "\\`" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
532
544
testRegExpSyntaxError ( "\\~" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
533
545
testRegExpSyntaxError ( "[\\&]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
534
546
testRegExpSyntaxError ( "[\\!]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
535
547
testRegExpSyntaxError ( "[\\#]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
536
548
537
- // Test 255
549
+ // Test 260
538
550
testRegExpSyntaxError ( "[\\%]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
539
551
testRegExpSyntaxError ( "[\\,]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
540
552
testRegExpSyntaxError ( "[\\:]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
541
553
testRegExpSyntaxError ( "[\\;]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
542
554
testRegExpSyntaxError ( "[\\<]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
543
555
544
- // Test 271
556
+ // Test 276
545
557
testRegExpSyntaxError ( "[\\=]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
546
558
testRegExpSyntaxError ( "[\\>]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
547
559
testRegExpSyntaxError ( "[\\@]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
548
560
testRegExpSyntaxError ( "[\\`]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
549
561
testRegExpSyntaxError ( "[\\~]" , "u" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
550
562
551
- // Test 276
563
+ // Test 281
552
564
testRegExpSyntaxError ( "\\&" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
553
565
testRegExpSyntaxError ( "\\-" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
554
566
testRegExpSyntaxError ( "\\!" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
555
567
testRegExpSyntaxError ( "\\#" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
556
568
testRegExpSyntaxError ( "\\%" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
557
569
558
- // Test 281
570
+ // Test 286
559
571
testRegExpSyntaxError ( "\\," , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
560
572
testRegExpSyntaxError ( "\\:" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
561
573
testRegExpSyntaxError ( "\\;" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
562
574
testRegExpSyntaxError ( "\\<" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
563
575
testRegExpSyntaxError ( "\\=" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
564
576
565
- // Test 286
577
+ // Test 291
566
578
testRegExpSyntaxError ( "\\>" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
567
579
testRegExpSyntaxError ( "\\@" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
568
580
testRegExpSyntaxError ( "\\`" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
569
581
testRegExpSyntaxError ( "\\~" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
570
582
testRegExpSyntaxError ( "\\q{a}" , "v" , "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern" ) ;
571
583
572
- // Test 291
584
+ // Test 296
573
585
testRegExp ( / [ \& \- \! \# \% \, \: \; \< \= \> \@ \` \~ ] * / v, "&-!#%,:;<=>@`~" , [ "&-!#%,:;<=>@`~" ] ) ;
574
586
testRegExp ( / [ \q { \& \- \! \# \% \, \: \; \< \= \> \@ \` \~ } X ] * / v, "X&-!#%,:;<=>@`~X" , [ "X&-!#%,:;<=>@`~X" ] ) ;
575
587
testRegExp ( / [ \q { } ] / v, "" , [ "" ] ) ;
576
588
testRegExp ( / [ \q { \u{0095} | k } ] / vi, "k" , [ "k" ] ) ;
577
589
testRegExp ( / [ \q { \u{0095} | s } ] / vi, "s" , [ "s" ] ) ;
590
+
591
+ // Test 301
592
+ testRegExp ( / [ f [ ^ a - z ] ] / v, "f" , [ "f" ] ) ;
593
+ testRegExp ( / [ f [ ^ a - z ] ] / v, "a" , null ) ;
594
+ testRegExp ( / [ f [ ^ a - z ] ] / v, "2" , [ "2" ] ) ;
595
+
596
+ // Test 304
597
+ testRegExp ( / [ ^ f [ ^ a - z ] ] / v, "f" , null ) ;
598
+ testRegExp ( / [ ^ f [ ^ a - z ] ] / v, "a" , [ "a" ] ) ;
599
+ testRegExp ( / [ ^ f [ ^ a - z ] ] / v, "2" , null ) ;
600
+
601
+ // Test 307
602
+ testRegExp ( / [ ^ f [ a - z ] ] / v, "f" , null ) ;
603
+ testRegExp ( / [ ^ f [ a - z ] ] / v, "a" , null ) ;
604
+ testRegExp ( / [ ^ f [ a - z ] ] / v, "2" , [ "2" ] ) ;
605
+
606
+ // Test 310
607
+ testRegExp ( / [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ a b c ] ] ] ] ] ] ] ] ] ] ] ] / v, "a" , [ "a" ] ) ;
608
+ testRegExp ( / [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ a b c ] ] ] ] ] ] ] ] ] ] ] ] / v, "d" , null ) ;
609
+
610
+ testRegExp ( / [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ a b c ] ] ] ] ] ] ] ] ] ] ] / v, "a" , null ) ;
611
+ testRegExp ( / [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ [ ^ a b c ] ] ] ] ] ] ] ] ] ] ] / v, "d" , [ "d" ] ) ;
612
+
613
+ // Test 314
614
+ testRegExp ( / [ a \u{1813} [ ^ \u{0250} - \u{3373} a ] ] / v, "\u{0250}" , null ) ;
615
+ testRegExp ( / [ a \u{1813} [ ^ \u{0250} - \u{3373} a ] ] / v, "\u{1813}" , [ "\u{1813}" ] ) ;
616
+ testRegExp ( / [ a \u{1813} [ ^ \u{0250} - \u{3373} a ] ] / v, "a" , [ "a" ] ) ;
617
+
618
+ // Test 317
619
+ testRegExpSyntaxError ( "[a-[^a-z]]" , "v" , "SyntaxError: Invalid regular expression: invalid class set character" ) ;
620
+
621
+ // Test 318
622
+ testRegExp ( / [ f [ ^ [ a - m ] [ n - z ] ] ] / v, "f" , "f" ) ;
623
+ testRegExp ( / [ f [ ^ [ a - m ] [ n - z ] ] ] / v, "a" , null ) ;
624
+ testRegExp ( / [ f [ ^ [ a - m ] [ n - z ] ] ] / v, "2" , "2" ) ;
625
+
626
+ // Test 321
627
+ testRegExp ( / [ f [ ^ [ a - z ] & & [ a - f ] ] ] / v, "f" , "f" ) ;
628
+ testRegExp ( / [ f [ ^ [ a - z ] & & [ a - f ] ] ] / v, "a" , null ) ;
629
+ testRegExp ( / [ f [ ^ [ a - z ] & & [ a - f ] ] ] / v, "g" , "g" ) ;
630
+ testRegExp ( / [ f [ ^ [ a - z ] & & [ a - f ] ] ] / v, "2" , "2" ) ;
631
+
632
+ testRegExp ( / [ f [ ^ [ a - z ] - - [ a - f ] ] ] / v, "f" , "f" ) ;
633
+ testRegExp ( / [ f [ ^ [ a - z ] - - [ a - f ] ] ] / v, "a" , "a" ) ;
634
+ testRegExp ( / [ f [ ^ [ a - z ] - - [ a - f ] ] ] / v, "g" , null ) ;
635
+ testRegExp ( / [ f [ ^ [ a - z ] - - [ a - f ] ] ] / v, "2" , "2" ) ;
636
+
0 commit comments