@@ -460,9 +460,25 @@ extension RegexTests {
460
460
461
461
parseTest ( " [-] " , charClass ( " - " ) )
462
462
463
- // Empty character classes are forbidden, therefore this is a character
464
- // class of literal ']'.
463
+ // Empty character classes are forbidden, therefore these are character
464
+ // classes containing literal ']'.
465
465
parseTest ( " []] " , charClass ( " ] " ) )
466
+ parseTest ( " []a] " , charClass ( " ] " , " a " ) )
467
+ parseTest (
468
+ " (?x)[ ]] " , changeMatchingOptions (
469
+ matchingOptions ( adding: . extended) , isIsolated: true ,
470
+ charClass ( " ] " ) )
471
+ )
472
+ parseTest (
473
+ " (?x)[ ] ] " , changeMatchingOptions (
474
+ matchingOptions ( adding: . extended) , isIsolated: true ,
475
+ charClass ( " ] " ) )
476
+ )
477
+ parseTest (
478
+ " (?x)[ ] a ] " , changeMatchingOptions (
479
+ matchingOptions ( adding: . extended) , isIsolated: true ,
480
+ charClass ( " ] " , " a " ) )
481
+ )
466
482
467
483
// These are metacharacters in certain contexts, but normal characters
468
484
// otherwise.
@@ -613,6 +629,16 @@ extension RegexTests {
613
629
parseTest (
614
630
" ~~* " , concat ( " ~ " , zeroOrMore ( of: " ~ " ) ) )
615
631
632
+ parseTest (
633
+ " [ && ] " , charClass (
634
+ . setOperation( [ " " ] , . init( faking: . intersection) , [ " " , " " ] ) )
635
+ )
636
+ parseTest (
637
+ " (?x)[ a && b ] " , changeMatchingOptions (
638
+ matchingOptions ( adding: . extended) , isIsolated: true , charClass (
639
+ . setOperation( [ " a " ] , . init( faking: . intersection) , [ " b " ] ) )
640
+ ) )
641
+
616
642
// MARK: Quotes
617
643
618
644
parseTest (
@@ -2205,6 +2231,9 @@ extension RegexTests {
2205
2231
diagnosticTest ( " ))) " , . unbalancedEndOfGroup)
2206
2232
diagnosticTest ( " ())() " , . unbalancedEndOfGroup)
2207
2233
2234
+ diagnosticTest ( " [ " , . expectedCustomCharacterClassMembers)
2235
+ diagnosticTest ( " [^ " , . expectedCustomCharacterClassMembers)
2236
+
2208
2237
diagnosticTest ( #"\u{5"# , . expected( " } " ) )
2209
2238
diagnosticTest ( #"\x{5"# , . expected( " } " ) )
2210
2239
diagnosticTest ( #"\N{A"# , . expected( " } " ) )
@@ -2245,9 +2274,21 @@ extension RegexTests {
2245
2274
diagnosticTest ( " (?<a-b " , . expected( " > " ) )
2246
2275
diagnosticTest ( " (?<a-b> " , . expected( " ) " ) )
2247
2276
2248
- // The first ']' of a custom character class is literal, so this is missing
2249
- // the closing bracket.
2277
+ // MARK: Character classes
2278
+
2279
+ diagnosticTest ( " [a " , . expected( " ] " ) )
2280
+
2281
+ // The first ']' of a custom character class is literal, so these are
2282
+ // missing the closing bracket.
2250
2283
diagnosticTest ( " [] " , . expected( " ] " ) )
2284
+ diagnosticTest ( " (?x)[ ] " , . expected( " ] " ) )
2285
+
2286
+ diagnosticTest ( " [&&] " , . expectedCustomCharacterClassMembers)
2287
+ diagnosticTest ( " [a&&] " , . expectedCustomCharacterClassMembers)
2288
+ diagnosticTest ( " [&&a] " , . expectedCustomCharacterClassMembers)
2289
+ diagnosticTest ( " (?x)[ && ] " , . expectedCustomCharacterClassMembers)
2290
+ diagnosticTest ( " (?x)[ &&a] " , . expectedCustomCharacterClassMembers)
2291
+ diagnosticTest ( " (?x)[a&& ] " , . expectedCustomCharacterClassMembers)
2251
2292
2252
2293
diagnosticTest ( " [:a " , . expected( " ] " ) )
2253
2294
diagnosticTest ( " [:a: " , . expected( " ] " ) )
0 commit comments