diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/swift-custom-dump.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/swift-custom-dump.xcscheme index 7bdac93..380f574 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/swift-custom-dump.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/swift-custom-dump.xcscheme @@ -40,7 +40,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/Sources/CustomDump/Diff.swift b/Sources/CustomDump/Diff.swift index 138d8dd..c52173b 100644 --- a/Sources/CustomDump/Diff.swift +++ b/Sources/CustomDump/Diff.swift @@ -25,7 +25,8 @@ /// unchanged lines. /// - Returns: A string describing any difference detected between values, or `nil` if no difference /// is detected. -public func diff(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String? { +public func diff(_ lhs: T, _ rhs: T, format: DiffFormat = .default, + excludedNoChangedProperty: Bool = false) -> String? { var visitedItems: Set = [] func diffHelp( @@ -482,7 +483,11 @@ public func diff(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String suffix: ")", elementIndent: 2, elementSeparator: ",", - collapseUnchanged: false + collapseUnchanged: excludedNoChangedProperty, + areInIncreasingOrder: + excludedNoChangedProperty + ? { ($0.label ?? "") > ($1.label ?? "") } + : nil ) case (_, .tuple?, _, .tuple?): diff --git a/Tests/CustomDumpTests/DiffTests.swift b/Tests/CustomDumpTests/DiffTests.swift index 7ba6e6f..cbcd318 100644 --- a/Tests/CustomDumpTests/DiffTests.swift +++ b/Tests/CustomDumpTests/DiffTests.swift @@ -914,4 +914,116 @@ final class DiffTests: XCTestCase { """ ) } + + func testExcludedNoChangedProperty() throws { + XCTAssertNoDifference( + diff( + User( + id: 42, + name: "Blob" + ), + User( + id: 42, + name: "Blob, Jr." + ), + excludedNoChangedProperty: true + ), + """ + User( + - name: "Blob", + + name: "Blob, Jr.", + … (1 unchanged) + ) + """ + ) + + XCTAssertNoDifference( + diff( + User( + id: 41, + name: "Blob" + ), + User( + id: 42, + name: "Blob" + ), + excludedNoChangedProperty: true + ), + """ + User( + - id: 41 + + id: 42 + … (1 unchanged) + ) + """ + ) + XCTAssertNoDifference( + diff( + Triple( + id: 42, + name: "Blob", + other: true + ), + Triple( + id: 42, + name: "Blob", + other: false + ), + excludedNoChangedProperty: true + ), + """ + Triple( + - other: true, + + other: false, + … (2 unchanged) + ) + """ + ) + + XCTAssertNoDifference( + diff( + Triple( + id: 41, + name: "Blob", + other: true + ), + Triple( + id: 42, + name: "Blob", + other: true + ), + excludedNoChangedProperty: true + ), + """ + Triple( + - id: 41 + + id: 42 + … (2 unchanged) + ) + """ + ) + + XCTAssertNoDifference( + diff( + Triple( + id: 42, + name: "Blob", + other: true + ), + Triple( + id: 42, + name: "Blob, Jr", + other: true + ), + excludedNoChangedProperty: true + ), + """ + Triple( + - name: "Blob", + + name: "Blob, Jr", + … (2 unchanged) + ) + """ + ) + } } diff --git a/Tests/CustomDumpTests/Mocks.swift b/Tests/CustomDumpTests/Mocks.swift index 1c73be2..c3d7fb4 100644 --- a/Tests/CustomDumpTests/Mocks.swift +++ b/Tests/CustomDumpTests/Mocks.swift @@ -122,3 +122,4 @@ struct Redacted: CustomDumpStringConvertible { } struct User: Equatable, Identifiable { var id: Int, name: String } +struct Triple: Equatable, Identifiable { var id: Int, name: String, other: Bool }