File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1653,5 +1653,35 @@ extension RegexTests {
1653
1653
let scalarExpected : [ Substring ] = [ " \u{FE0F} 💖🧠 " , " 🧠💖☕ " ]
1654
1654
XCTAssertEqual ( scalarMatches. map { $0. 0 } , scalarExpected)
1655
1655
}
1656
+
1657
+ func testConcurrentAccess( ) async throws {
1658
+ for _ in 0 ..< 1000 {
1659
+ let regex = try Regex ( #"abc+d*e?"# )
1660
+ let strings = [
1661
+ " abc " ,
1662
+ " abccccccccdddddddddde " ,
1663
+ " abcccce " ,
1664
+ " abddddde " ,
1665
+ ]
1666
+ let matches = await withTaskGroup ( of: Optional < Regex < AnyRegexOutput > . Match > . self) { group -> [ Regex < AnyRegexOutput > . Match ] in
1667
+ var result : [ Regex < AnyRegexOutput > . Match ] = [ ]
1668
+
1669
+ for str in strings {
1670
+ group. addTask {
1671
+ str. firstMatch ( of: regex)
1672
+ }
1673
+ }
1674
+
1675
+ for await match in group {
1676
+ guard let match = match else { continue }
1677
+ result. append ( match)
1678
+ }
1679
+
1680
+ return result
1681
+ }
1682
+
1683
+ XCTAssertEqual ( matches. count, 3 )
1684
+ }
1685
+ }
1656
1686
}
1657
1687
You can’t perform that action at this time.
0 commit comments