File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -44,4 +44,39 @@ extension AlgorithmTests {
44
44
XCTAssertEqual ( " x " , " axb " . _trimming ( r) )
45
45
XCTAssertEqual ( " x " , " axbb " . _trimming ( r) )
46
46
}
47
+
48
+ func testMatchesCollection( ) {
49
+ let r = try ! Regex ( " a|b+|c* " , as: Substring . self)
50
+
51
+ let str = " zaabbbbbbcde "
52
+ let matches = str. _matches ( of: r)
53
+ let expected : [ Substring ] = [
54
+ " " , // before 'z'
55
+ " a " ,
56
+ " a " ,
57
+ " bbbbbb " ,
58
+ " c " ,
59
+ " " , // after 'c'
60
+ " " , // after 'd'
61
+ " " , // after 'e'
62
+ ]
63
+
64
+ // Make sure we're getting the right collection type
65
+ let _: RegexMatchesCollection < Substring > = matches
66
+
67
+ XCTAssertEqual ( matches. map ( \. output) , expected)
68
+
69
+ let i = matches. index ( matches. startIndex, offsetBy: 3 )
70
+ XCTAssertEqual ( matches [ i] . output, expected [ 3 ] )
71
+ let j = matches. index ( i, offsetBy: 5 )
72
+ XCTAssertEqual ( j, matches. endIndex)
73
+
74
+ var index = matches. startIndex
75
+ while index < matches. endIndex {
76
+ XCTAssertEqual (
77
+ matches [ index] . output,
78
+ expected [ matches. distance ( from: matches. startIndex, to: index) ] )
79
+ matches. formIndex ( after: & index)
80
+ }
81
+ }
47
82
}
You can’t perform that action at this time.
0 commit comments