@@ -23,21 +23,16 @@ final class TestDebugDescriptionDriver: XCTestCase {
23
23
private static let contentSizePattern = #"\{\d+, \d+\}"# // {0, 0}
24
24
private static let adjustedContentInsetPattern = #"\{\d+, \d+, \d+, \d+\}"# // {0, 0, 0, 0}
25
25
26
- // swiftlint:disable:next line_length
27
- private let viewPattern = " <ReactiveCollectionsKitTests \\ .FakeCollectionView: \( addressPattern) ; baseClass = UICollectionView; frame = \( framePattern) ; clipsToBounds = YES; gestureRecognizers = <NSArray: \( addressPattern) >; backgroundColor = <UIDynamicSystemColor: \( addressPattern) ; name = systemBackgroundColor>; layer = <CALayer: \( addressPattern) >; contentOffset: \( contentOffsetPattern) ; contentSize: \( contentSizePattern) ; adjustedContentInset: \( adjustedContentInsetPattern) ; layout: <ReactiveCollectionsKitTests \\ .FakeCollectionLayout: \( addressPattern) >; dataSource: <ReactiveCollectionsKit \\ .DiffableDataSource: \( addressPattern) >> "
28
-
29
- private func assertEqualRegex(
30
- string: String ,
31
- pattern: String ,
32
- numMatches: Int = 1 ,
33
- _ message: @autoclosure ( ) -> String = " " ,
34
- file: StaticString = #filePath,
35
- line: UInt = #line
36
- ) throws {
37
- let regex = try NSRegularExpression ( pattern: pattern)
38
- let count = regex. numberOfMatches ( in: string, range: NSRange ( string. startIndex... , in: string) )
39
- XCTAssertEqual ( count, numMatches, message ( ) , file: file, line: line)
40
- }
26
+ private let viewPattern = """
27
+ <ReactiveCollectionsKitTests \\ .FakeCollectionView: \( addressPattern) ; \
28
+ baseClass = UICollectionView; frame = \( framePattern) ; clipsToBounds = YES; \
29
+ gestureRecognizers = <NSArray: \( addressPattern) >; \
30
+ backgroundColor = <UIDynamicSystemColor: \( addressPattern) ; name = systemBackgroundColor>; \
31
+ layer = <CALayer: \( addressPattern) >; contentOffset: \( contentOffsetPattern) ; \
32
+ contentSize: \( contentSizePattern) ; adjustedContentInset: \( adjustedContentInsetPattern) ; \
33
+ layout: <ReactiveCollectionsKitTests \\ .FakeCollectionLayout: \( addressPattern) >; \
34
+ dataSource: <ReactiveCollectionsKit \\ .DiffableDataSource: \( addressPattern) >>
35
+ """
41
36
42
37
@MainActor
43
38
func test_empty( ) throws {
@@ -52,7 +47,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
52
47
viewModel: viewModel
53
48
)
54
49
55
- let pattern =
50
+ let expected =
56
51
"""
57
52
CollectionViewDriver \\ {
58
53
options:
@@ -76,7 +71,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
76
71
77
72
"""
78
73
79
- try self . assertEqualRegex ( string : driver. debugDescription, pattern: pattern )
74
+ XCTAssertTrue ( driver. debugDescription. regexMatches ( pattern: expected ) )
80
75
}
81
76
82
77
@MainActor
@@ -95,7 +90,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
95
90
viewModel: viewModel
96
91
)
97
92
98
- let pattern =
93
+ let expected =
99
94
"""
100
95
CollectionViewDriver \\ {
101
96
options:
@@ -132,7 +127,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
132
127
133
128
"""
134
129
135
- try self . assertEqualRegex ( string : driver. debugDescription, pattern: pattern )
130
+ XCTAssertTrue ( driver. debugDescription. regexMatches ( pattern: expected ) )
136
131
}
137
132
138
133
@MainActor
@@ -157,7 +152,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
157
152
driver. scrollViewDelegate = flowLayoutDelegate
158
153
driver. flowLayoutDelegate = flowLayoutDelegate
159
154
160
- let pattern =
155
+ let expected =
161
156
"""
162
157
CollectionViewDriver \\ {
163
158
options:
@@ -181,6 +176,14 @@ final class TestDebugDescriptionDriver: XCTestCase {
181
176
182
177
"""
183
178
184
- try self . assertEqualRegex ( string: driver. debugDescription, pattern: pattern)
179
+ XCTAssertTrue ( driver. debugDescription. regexMatches ( pattern: expected) )
180
+ }
181
+ }
182
+
183
+ extension String {
184
+ func regexMatches( pattern: String ) -> Bool {
185
+ let regex = try ? NSRegularExpression ( pattern: pattern)
186
+ let range = NSRange ( self . startIndex... , in: self )
187
+ return regex? . numberOfMatches ( in: self , range: range) == 1
185
188
}
186
189
}
0 commit comments