Skip to content

Commit e395327

Browse files
committed
Even more info.
1 parent 0c69d1a commit e395327

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

TestFoundation/TestDateIntervalFormatter.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,33 @@
1515
#endif
1616
#endif
1717

18+
enum ContainsInOrderResult: Equatable {
19+
case success
20+
case missed(String)
21+
case doesNotEndWithLastElement
22+
}
23+
1824
extension String {
19-
func containsInOrder(requiresLastToBeAtEnd: Bool = false, _ substrings: [String]) -> Bool {
25+
func containsInOrder(requiresLastToBeAtEnd: Bool = false, _ substrings: [String]) -> ContainsInOrderResult {
2026
var foundRange: Range<String.Index> = startIndex ..< startIndex
2127
for substring in substrings {
2228
if let newRange = range(of: substring, options: [], range: foundRange.upperBound..<endIndex, locale: nil) {
2329
foundRange = newRange
2430
} else {
25-
return false
31+
return .missed(substring)
2632
}
2733
}
2834

2935
if requiresLastToBeAtEnd {
30-
return foundRange.upperBound == endIndex
36+
return foundRange.upperBound == endIndex ? .success : .doesNotEndWithLastElement
3137
} else {
32-
return true
38+
return .success
3339
}
3440
}
3541

3642
func assertContainsInOrder(requiresLastToBeAtEnd: Bool = false, _ substrings: String...) {
37-
XCTAssert(containsInOrder(requiresLastToBeAtEnd: requiresLastToBeAtEnd, substrings), "String '\(self)' (must end with: \(requiresLastToBeAtEnd)) does not contain in sequence: \(substrings)")
43+
let result = containsInOrder(requiresLastToBeAtEnd: requiresLastToBeAtEnd, substrings)
44+
XCTAssert(result == .success, "String '\(self)' (must end with: \(requiresLastToBeAtEnd)) does not contain in sequence: \(substrings) — reason: \(result)")
3845
}
3946
}
4047

0 commit comments

Comments
 (0)