Skip to content

Commit

Permalink
Show label for visited items (pointfreeco#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentleyjones authored Mar 2, 2022
1 parent 1c38456 commit e7c6d64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/CustomDump/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String
let subjectType = typeName(lhsMirror.subjectType)
if visitedItems.contains(lhsItem) || visitedItems.contains(rhsItem) {
print(
"\(subjectType)(↩︎)"
"\(lhsName.map { "\($0): " } ?? "")\(subjectType)(↩︎)"
.indenting(by: indent)
.indenting(with: format.first + " "),
to: &out
)
print(
"\(subjectType)(↩︎)"
"\(rhsName.map { "\($0): " } ?? "")\(subjectType)(↩︎)"
.indenting(by: indent)
.indenting(with: format.second + " "),
terminator: "",
Expand Down
17 changes: 17 additions & 0 deletions Tests/CustomDumpTests/DiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ final class DiffTests: XCTestCase {
+ NSObject()
"""
)

XCTAssertNoDifference(
diff(
RepeatedObject(id: "a"),
RepeatedObject(id: "b")
),
"""
RepeatedObject(
child: RepeatedObject.Child(
- grandchild: RepeatedObject.Grandchild(id: "a")
+ grandchild: RepeatedObject.Grandchild(id: "b")
),
- grandchild: RepeatedObject.Grandchild(↩︎)
+ grandchild: RepeatedObject.Grandchild(↩︎)
)
"""
)
}

func testClassObjectIdentity() {
Expand Down
22 changes: 22 additions & 0 deletions Tests/CustomDumpTests/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ import Foundation

class RecursiveFoo { var foo: RecursiveFoo? }

class RepeatedObject {
class Child {
let grandchild: Grandchild
init(id: String) {
grandchild = Grandchild(id: id)
}
}
class Grandchild {
let id: String
init(id: String) {
self.id = id
}
}

let child: Child
let grandchild: Grandchild
init(id: String) {
child = Child(id: id)
grandchild = child.grandchild
}
}

class UserClass {
let id: Int, name: String
init(id: Int, name: String) {
Expand Down

0 comments on commit e7c6d64

Please sign in to comment.