Skip to content

Commit 253e3d9

Browse files
authored
Differentiate equal dumps of different types (#49)
Fixes #48.
1 parent c4f78db commit 253e3d9

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

Sources/CustomDump/Diff.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,23 @@ public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String
4848
var out = ""
4949

5050
func diffEverything() {
51+
var lhs = _customDump(lhs, name: lhsName, indent: indent, maxDepth: .max)
52+
var rhs = _customDump(rhs, name: rhsName, indent: indent, maxDepth: .max)
53+
if lhs == rhs {
54+
if lhsMirror.subjectType != rhsMirror.subjectType {
55+
lhs.append(" as \(typeName(lhsMirror.subjectType))")
56+
rhs.append(" as \(typeName(rhsMirror.subjectType))")
57+
}
58+
}
59+
lhs.append(separator)
60+
rhs.append(separator)
61+
5162
print(
52-
_customDump(lhs, name: lhsName, indent: indent, maxDepth: .max)
53-
.appending(separator)
54-
.indenting(with: format.first + " "),
63+
lhs.indenting(with: format.first + " "),
5564
to: &out
5665
)
5766
print(
58-
_customDump(rhs, name: rhsName, indent: indent, maxDepth: .max)
59-
.appending(separator)
60-
.indenting(with: format.second + " "),
67+
rhs.indenting(with: format.second + " "),
6168
terminator: "",
6269
to: &out
6370
)

Tests/CustomDumpTests/DiffTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,35 @@ final class DiffTests: XCTestCase {
883883
)
884884
"""
885885
)
886+
}
887+
888+
func testDifferentTypes() {
889+
XCTAssertNoDifference(
890+
diff(
891+
29.99 as Float as Any,
892+
29.99 as Double as Any
893+
),
894+
"""
895+
- 29.99 as Float
896+
+ 29.99 as Double
897+
"""
898+
)
886899

900+
XCTAssertNoDifference(
901+
diff(
902+
[
903+
"value": 29.99 as Float,
904+
],
905+
[
906+
"value": 29.99 as Double,
907+
]
908+
),
909+
"""
910+
[
911+
- "value": 29.99 as Float
912+
+ "value": 29.99 as Double
913+
]
914+
"""
915+
)
887916
}
888917
}

0 commit comments

Comments
 (0)