@@ -13,8 +13,7 @@ import Testing
1313@testable @_spi ( RegexBuilder) import _StringProcessing
1414@testable import _RegexParser
1515
16- @Suite
17- struct OptimizationTests {
16+ @Suite struct OptimizationTests {
1817 @available ( macOS 9999 , * )
1918 @Test ( arguments: [ #/a/#, #/a+/#, #/(?:a+)/#, #/(?:a)+/#, #/(?m)a+/#, #/ab?c/#, #/(?:a+)+$/# ] )
2019 func requiredFirstAtom( pattern: Regex < Substring > ) throws {
@@ -60,19 +59,34 @@ struct OptimizationTests {
6059 }
6160
6261 @available ( macOS 9999 , * )
63- @Test ( arguments: [ #/(?: a+b|b+a)/#]) //[#/a+b/# , #/a*b/#, #/\d+a/#, #/\ w+\s/#, #/(?:a+b|b+a)/# ] )
62+ @Test ( arguments: [ #/a+b/# , #/a*b/#, #/\w+\s/#, #/(?:a+b|b+a)/#]) // , #/\d+a/#
6463 func autoPossessify( pattern: Regex < Substring > ) throws {
6564 var list = DSLList ( tree: pattern. program. tree)
66- var index = 0
67- _ = list. autoPossessifyNextQuantification ( & index)
68- print ( pattern. _literalPattern!)
69- dump ( list)
65+ list. autoPossessify ( )
66+ for node in list. nodes {
67+ switch node {
68+ case . quantification( _, let kind, _) :
69+ #expect(
70+ kind. isExplicit && kind. quantificationKind? . ast == . possessive,
71+ " Expected possessification in ' \( pattern. _literalPattern!) ' " )
72+ default : break
73+ }
74+ }
7075 }
7176
7277 @available ( macOS 9999 , * )
73- @Test ( arguments: [ #/a?/#, #/(?:a|b)/#, #/(?:a+|b+)/#, #/[a]/#, #/a?a/# ] )
78+ @Test ( arguments: [ #/a?/#, #/a+a/#, #/ (?:a|b)/#, #/(?:a+|b+)/#, #/[a]/#, #/a?a/# ] )
7479 func noAutoPossessify( pattern: Regex < Substring > ) throws {
7580 var list = DSLList ( tree: pattern. program. tree)
7681 list. autoPossessify ( )
82+ for node in list. nodes {
83+ switch node {
84+ case . quantification( _, let kind, _) :
85+ #expect(
86+ kind. quantificationKind? . ast != . possessive,
87+ " Unexpected possessification in ' \( pattern. _literalPattern!) ' " )
88+ default : break
89+ }
90+ }
7791 }
7892}
0 commit comments