Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exclude NoChanged Property option #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
9 changes: 7 additions & 2 deletions Sources/CustomDump/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String? {
public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default,
excludedNoChangedProperty: Bool = false) -> String? {
var visitedItems: Set<ObjectIdentifier> = []

func diffHelp(
Expand Down Expand Up @@ -482,7 +483,11 @@ public func diff<T>(_ 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?):
Expand Down
112 changes: 112 additions & 0 deletions Tests/CustomDumpTests/DiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
"""
)
}
}
1 change: 1 addition & 0 deletions Tests/CustomDumpTests/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ struct Redacted<RawValue>: CustomDumpStringConvertible {
}

struct User: Equatable, Identifiable { var id: Int, name: String }
struct Triple: Equatable, Identifiable { var id: Int, name: String, other: Bool }