@@ -528,23 +528,7 @@ extension RegexTests {
528528 ) )
529529
530530 parseTest ( " [-] " , charClass ( " - " ) )
531-
532- // Empty character classes are forbidden, therefore these are character
533- // classes containing literal ']'.
534- parseTest ( " []] " , charClass ( " ] " ) )
535- parseTest ( " []a] " , charClass ( " ] " , " a " ) )
536- parseTest ( " (?x)[ ]] " , concat (
537- changeMatchingOptions ( matchingOptions ( adding: . extended) ) ,
538- charClass ( " ] " )
539- ) )
540- parseTest ( " (?x)[ ] ] " , concat (
541- changeMatchingOptions ( matchingOptions ( adding: . extended) ) ,
542- charClass ( " ] " )
543- ) )
544- parseTest ( " (?x)[ ] a ] " , concat (
545- changeMatchingOptions ( matchingOptions ( adding: . extended) ) ,
546- charClass ( " ] " , " a " )
547- ) )
531+ parseTest ( #"[\]]"# , charClass ( " ] " ) )
548532
549533 // These are metacharacters in certain contexts, but normal characters
550534 // otherwise.
@@ -2497,10 +2481,15 @@ extension RegexTests {
24972481
24982482 diagnosticTest ( " [a " , . expected( " ] " ) )
24992483
2500- // The first ']' of a custom character class is literal, so these are
2501- // missing the closing bracket.
2502- diagnosticTest ( " [] " , . expected( " ] " ) )
2503- diagnosticTest ( " (?x)[ ] " , . expected( " ] " ) )
2484+ // Character classes may not be empty.
2485+ diagnosticTest ( " [] " , . expectedCustomCharacterClassMembers)
2486+ diagnosticTest ( " []] " , . expectedCustomCharacterClassMembers)
2487+ diagnosticTest ( " []a] " , . expectedCustomCharacterClassMembers)
2488+ diagnosticTest ( " (?x)[ ] " , . expectedCustomCharacterClassMembers)
2489+ diagnosticTest ( " (?x)[ ] ] " , . expectedCustomCharacterClassMembers)
2490+ diagnosticTest ( " (?x)[ ] a ] " , . expectedCustomCharacterClassMembers)
2491+ diagnosticTest ( " (?xx)[ ] a ]+ " , . expectedCustomCharacterClassMembers)
2492+ diagnosticTest ( " (?x)[ ]] " , . expectedCustomCharacterClassMembers)
25042493
25052494 diagnosticTest ( " [&&] " , . expectedCustomCharacterClassMembers)
25062495 diagnosticTest ( " [a&&] " , . expectedCustomCharacterClassMembers)
0 commit comments