Skip to content

Commit 20ef18c

Browse files
committed
clean up tests
1 parent 988678f commit 20ef18c

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

Tests/TestDebugDescriptionDriver.swift

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,16 @@ final class TestDebugDescriptionDriver: XCTestCase {
2323
private static let contentSizePattern = #"\{\d+, \d+\}"# // {0, 0}
2424
private static let adjustedContentInsetPattern = #"\{\d+, \d+, \d+, \d+\}"# // {0, 0, 0, 0}
2525

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+
"""
4136

4237
@MainActor
4338
func test_empty() throws {
@@ -52,7 +47,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
5247
viewModel: viewModel
5348
)
5449

55-
let pattern =
50+
let expected =
5651
"""
5752
CollectionViewDriver \\{
5853
options:
@@ -76,7 +71,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
7671
7772
"""
7873

79-
try self.assertEqualRegex(string: driver.debugDescription, pattern: pattern)
74+
XCTAssertTrue(driver.debugDescription.regexMatches(pattern: expected))
8075
}
8176

8277
@MainActor
@@ -95,7 +90,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
9590
viewModel: viewModel
9691
)
9792

98-
let pattern =
93+
let expected =
9994
"""
10095
CollectionViewDriver \\{
10196
options:
@@ -132,7 +127,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
132127
133128
"""
134129

135-
try self.assertEqualRegex(string: driver.debugDescription, pattern: pattern)
130+
XCTAssertTrue(driver.debugDescription.regexMatches(pattern: expected))
136131
}
137132

138133
@MainActor
@@ -157,7 +152,7 @@ final class TestDebugDescriptionDriver: XCTestCase {
157152
driver.scrollViewDelegate = flowLayoutDelegate
158153
driver.flowLayoutDelegate = flowLayoutDelegate
159154

160-
let pattern =
155+
let expected =
161156
"""
162157
CollectionViewDriver \\{
163158
options:
@@ -181,6 +176,14 @@ final class TestDebugDescriptionDriver: XCTestCase {
181176
182177
"""
183178

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
185188
}
186189
}

0 commit comments

Comments
 (0)