@@ -460,9 +460,25 @@ extension RegexTests {
460460
461461 parseTest ( " [-] " , charClass ( " - " ) )
462462
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 ']'.
465465 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+ )
466482
467483 // These are metacharacters in certain contexts, but normal characters
468484 // otherwise.
@@ -613,6 +629,16 @@ extension RegexTests {
613629 parseTest (
614630 " ~~* " , concat ( " ~ " , zeroOrMore ( of: " ~ " ) ) )
615631
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+
616642 // MARK: Quotes
617643
618644 parseTest (
@@ -2205,6 +2231,9 @@ extension RegexTests {
22052231 diagnosticTest ( " ))) " , . unbalancedEndOfGroup)
22062232 diagnosticTest ( " ())() " , . unbalancedEndOfGroup)
22072233
2234+ diagnosticTest ( " [ " , . expectedCustomCharacterClassMembers)
2235+ diagnosticTest ( " [^ " , . expectedCustomCharacterClassMembers)
2236+
22082237 diagnosticTest ( #"\u{5"# , . expected( " } " ) )
22092238 diagnosticTest ( #"\x{5"# , . expected( " } " ) )
22102239 diagnosticTest ( #"\N{A"# , . expected( " } " ) )
@@ -2245,9 +2274,21 @@ extension RegexTests {
22452274 diagnosticTest ( " (?<a-b " , . expected( " > " ) )
22462275 diagnosticTest ( " (?<a-b> " , . expected( " ) " ) )
22472276
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.
22502283 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)
22512292
22522293 diagnosticTest ( " [:a " , . expected( " ] " ) )
22532294 diagnosticTest ( " [:a: " , . expected( " ] " ) )
0 commit comments