import Testing import XCTest public func expectEqual(_ actual: T, _ expected: T) { #expect( actual == expected, "Objects are not equal:\n\(diffBetweenDumps(actual, expected))" ) } public func assertEqual(_ actual: T, _ expected: T) { if actual != expected { XCTFail("Objects are not equal:\n\(diffBetweenDumps(actual, expected))") } } private struct ElementWithAttachment: Hashable { let element: Element let attachment: Attachment func hash(into hasher: inout Hasher) { hasher.combine(element) } } private func == ( lhs: ElementWithAttachment, rhs: ElementWithAttachment ) -> Bool { lhs.element == rhs.element } private func diffBetween( _ a: T, _ b: T ) -> String where T.Iterator.Element: Hashable { var aIndex = a.startIndex var bIndex = b.startIndex var diff = "" while aIndex != a.endIndex, bIndex != b.endIndex { let hexAddressRegex = "0x[\\dA-Za-z]{8}" let mirrorElementNumberRegex = "#[\\d]+$" let aStr = "\(a[aIndex])".filteringRegexes(hexAddressRegex, mirrorElementNumberRegex) let bStr = "\(b[bIndex])".filteringRegexes(hexAddressRegex, mirrorElementNumberRegex) if aStr == bStr { aIndex = a.index(after: aIndex) bIndex = b.index(after: bIndex) continue } let aSlice = a[aIndex..(_ a: T, _ b: T) -> String { var aDump = "" dump(a, to: &aDump) var bDump = "" dump(b, to: &bDump) let aRows = aDump.components(separatedBy: "\n") let bRows = bDump.components(separatedBy: "\n") return diffBetween(aRows, bRows) } extension String { fileprivate func trimmedToLength(_ length: Int) -> String { let result = self[0.. String { var result = self for regex in regexes { result = result.replacingOccurrences(of: regex, with: "", options: [.regularExpression]) } return result } }