Skip to content

Commit e7c6d64

Browse files
Show label for visited items (#43)
1 parent 1c38456 commit e7c6d64

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

Sources/CustomDump/Diff.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,13 @@ public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String
304304
let subjectType = typeName(lhsMirror.subjectType)
305305
if visitedItems.contains(lhsItem) || visitedItems.contains(rhsItem) {
306306
print(
307-
"\(subjectType)(↩︎)"
307+
"\(lhsName.map { "\($0): " } ?? "")\(subjectType)(↩︎)"
308308
.indenting(by: indent)
309309
.indenting(with: format.first + " "),
310310
to: &out
311311
)
312312
print(
313-
"\(subjectType)(↩︎)"
313+
"\(rhsName.map { "\($0): " } ?? "")\(subjectType)(↩︎)"
314314
.indenting(by: indent)
315315
.indenting(with: format.second + " "),
316316
terminator: "",

Tests/CustomDumpTests/DiffTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ final class DiffTests: XCTestCase {
7474
+ NSObject()
7575
"""
7676
)
77+
78+
XCTAssertNoDifference(
79+
diff(
80+
RepeatedObject(id: "a"),
81+
RepeatedObject(id: "b")
82+
),
83+
"""
84+
RepeatedObject(
85+
child: RepeatedObject.Child(
86+
- grandchild: RepeatedObject.Grandchild(id: "a")
87+
+ grandchild: RepeatedObject.Grandchild(id: "b")
88+
),
89+
- grandchild: RepeatedObject.Grandchild(↩︎)
90+
+ grandchild: RepeatedObject.Grandchild(↩︎)
91+
)
92+
"""
93+
)
7794
}
7895

7996
func testClassObjectIdentity() {

Tests/CustomDumpTests/Mocks.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@ import Foundation
33

44
class RecursiveFoo { var foo: RecursiveFoo? }
55

6+
class RepeatedObject {
7+
class Child {
8+
let grandchild: Grandchild
9+
init(id: String) {
10+
grandchild = Grandchild(id: id)
11+
}
12+
}
13+
class Grandchild {
14+
let id: String
15+
init(id: String) {
16+
self.id = id
17+
}
18+
}
19+
20+
let child: Child
21+
let grandchild: Grandchild
22+
init(id: String) {
23+
child = Child(id: id)
24+
grandchild = child.grandchild
25+
}
26+
}
27+
628
class UserClass {
729
let id: Int, name: String
830
init(id: Int, name: String) {

0 commit comments

Comments
 (0)