@@ -325,6 +325,7 @@ func firstMatchTests(
325325 enableTracing: Bool = false ,
326326 dumpAST: Bool = false ,
327327 xfail: Bool = false ,
328+ validateOptimizations: Bool = true ,
328329 semanticLevel: RegexSemanticLevel = . graphemeCluster,
329330 file: StaticString = #filePath,
330331 line: UInt = #line
@@ -338,6 +339,7 @@ func firstMatchTests(
338339 enableTracing: enableTracing,
339340 dumpAST: dumpAST,
340341 xfail: xfail,
342+ validateOptimizations: validateOptimizations,
341343 semanticLevel: semanticLevel,
342344 file: file,
343345 line: line)
@@ -1602,27 +1604,57 @@ extension RegexTests {
16021604 ( input: " hezllo " , match: nil ) ,
16031605 ( input: " helloz " , match: nil ) )
16041606
1607+ // MARK: Lookbehinds
16051608 firstMatchTest (
1606- #"(?<=USD)\d+"# , input: " Price: USD100 " , match: " 100 " , xfail : true )
1609+ #"(?<=USD)\d+"# , input: " Price: USD100 " , match: " 100 " )
16071610 firstMatchTest (
1608- #"(*plb:USD)\d+"# , input: " Price: USD100 " , match: " 100 " , xfail : true )
1611+ #"(*plb:USD)\d+"# , input: " Price: USD100 " , match: " 100 " )
16091612 firstMatchTest (
16101613 #"(*positive_lookbehind:USD)\d+"# ,
1611- input: " Price: USD100 " , match: " 100 " , xfail: true )
1612- // engines generally enforce that lookbehinds are fixed width
1614+ input: " Price: USD100 " , match: " 100 " )
1615+
1616+ // TODO: Why is a match not found when unoptimized?
16131617 firstMatchTest (
1614- #"\d{3}(?<=USD\d{3})"# , input: " Price: USD100 " , match: " 100 " , xfail : true )
1618+ #"\d{3}(?<=USD\d{3})"# , input: " Price: USD100 " , match: " 100 " , validateOptimizations : false )
16151619
16161620 firstMatchTest (
1617- #"(?<!USD)\d+"# , input: " Price: JYP100 " , match: " 100 " , xfail : true )
1621+ #"(?<!USD)\d+"# , input: " Price: JYP100 " , match: " 100 " )
16181622 firstMatchTest (
1619- #"(*nlb:USD)\d+"# , input: " Price: JYP100 " , match: " 100 " , xfail : true )
1623+ #"(*nlb:USD)\d+"# , input: " Price: JYP100 " , match: " 100 " )
16201624 firstMatchTest (
16211625 #"(*negative_lookbehind:USD)\d+"# ,
1622- input: " Price: JYP100 " , match: " 100 " , xfail: true )
1623- // engines generally enforce that lookbehinds are fixed width
1626+ input: " Price: JYP100 " , match: " 100 " )
1627+
1628+ firstMatchTest (
1629+ #"\d{3}(?<!USD\d{3})"# , input: " Price: JYP100 " , match: " 100 " )
1630+
1631+ firstMatchTest ( #"(?<=abc)def"# , input: " abcdefg " , match: " def " , validateOptimizations: false )
1632+ firstMatchTests (
1633+ #"(?<=az|b|c)def"# ,
1634+ ( " azdefg " , " def " ) ,
1635+ ( " bdefg " , " def " ) ,
1636+ ( " cdefg " , " def " ) ,
1637+ ( " 123defg " , nil ) ,
1638+ validateOptimizations: false
1639+ )
1640+
1641+ // FIXME: quickMatch and thoroughMatch have different results
16241642 firstMatchTest (
1625- #"\d{3}(?<!USD\d{3})"# , input: " Price: JYP100 " , match: " 100 " , xfail: true )
1643+ #"(?<=\d{1,3}-.{1,3}-\d{1,3})suffix"# ,
1644+ input: " 123-_+/-789suffix " ,
1645+ match: " suffix " ,
1646+ validateOptimizations: false
1647+ )
1648+
1649+ firstMatchTests (
1650+ #"(?<=^\d{1,3})abc"# ,
1651+ ( " 123abc " , " abc " ) ,
1652+ ( " 12abc " , " abc " ) ,
1653+ ( " 1abc " , " abc " ) ,
1654+ ( " 1234abc " , nil ) , // FIXME: Shouldn't match but does because `^` assertions are broken
1655+ ( " z123abc " , nil ) , // FIXME: Same as above
1656+ validateOptimizations: false
1657+ )
16261658 }
16271659
16281660 func testMatchAnchors( ) throws {
0 commit comments