Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Oct 31, 2023
1 parent b803caa commit 65fc9e2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Sources/CustomDump/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String
elementIndent: 2,
elementSeparator: ",",
collapseUnchanged: false,
filter: { $0.label.map { !$0.hasPrefix("_$") } ?? true }
filter: macroPropertyFilter(for: lhs)
)
}

Expand Down Expand Up @@ -505,7 +505,7 @@ public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String
elementIndent: 2,
elementSeparator: ",",
collapseUnchanged: false,
filter: { $0.label.map { !$0.hasPrefix("_$") } ?? true }
filter: macroPropertyFilter(for: lhs)
)

case (_, .tuple?, _, .tuple?):
Expand Down
10 changes: 8 additions & 2 deletions Sources/CustomDump/Dump.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func _customDump<T, TargetStream>(
of: Mirror(value, children: children),
prefix: "\(typeName(mirror.subjectType))\(id)(",
suffix: ")",
filter: { $0.label.map { !$0.hasPrefix("_$") } ?? true }
filter: macroPropertyFilter(for: value)
)
}

Expand Down Expand Up @@ -279,7 +279,7 @@ func _customDump<T, TargetStream>(
of: mirror,
prefix: "\(typeName(mirror.subjectType))(",
suffix: ")",
filter: { $0.label.map { !$0.hasPrefix("_$") } ?? true }
filter: macroPropertyFilter(for: value)
)

case (_, .tuple?):
Expand Down Expand Up @@ -331,3 +331,9 @@ func _customDump(_ value: Any, name: String?, indent: Int, isRoot: Bool, maxDept
_customDump(value, to: &out, name: name, indent: indent, isRoot: isRoot, maxDepth: maxDepth)
return out
}

func macroPropertyFilter(for value: Any) -> (Mirror.Child) -> Bool {
value is CustomDumpReflectable
? { _ in true }
: { $0.label.map { !$0.hasPrefix("_$") } ?? true }
}
25 changes: 25 additions & 0 deletions Tests/CustomDumpTests/DumpTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1329,4 +1329,29 @@ final class DumpTests: XCTestCase {
"""
)
}

func testExplicitFilteredPropertyPreserved() {
struct ObservationRegistrar {}
class Object: CustomDumpReflectable {
let name = "Blob Sr."
let _$observationRegistrar = ObservationRegistrar()

var customDumpMirror: Mirror {
Mirror(
self,
children: ["name": self.name, "_$observationRegistrar": self._$observationRegistrar],
displayStyle: .class
)
}
}
XCTAssertNoDifference(
String(customDumping: Object()),
"""
DumpTests.Object(
name: "Blob Sr.",
_$observationRegistrar: DumpTests.ObservationRegistrar()
)
"""
)
}
}
6 changes: 6 additions & 0 deletions Tests/CustomDumpTests/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ struct Wrapper<RawValue>: CustomDumpRepresentable {
struct LoginState: CustomDumpReflectable {
var email = "", password = "", token: String

init(email: String = "", password: String = "", token: String) {
self.email = email
self.password = password
self.token = token
}

var customDumpMirror: Mirror {
.init(
self,
Expand Down

0 comments on commit 65fc9e2

Please sign in to comment.