Skip to content

Commit 65fc9e2

Browse files
committed
wip
1 parent b803caa commit 65fc9e2

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

Sources/CustomDump/Diff.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String
360360
elementIndent: 2,
361361
elementSeparator: ",",
362362
collapseUnchanged: false,
363-
filter: { $0.label.map { !$0.hasPrefix("_$") } ?? true }
363+
filter: macroPropertyFilter(for: lhs)
364364
)
365365
}
366366

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

511511
case (_, .tuple?, _, .tuple?):

Sources/CustomDump/Dump.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func _customDump<T, TargetStream>(
198198
of: Mirror(value, children: children),
199199
prefix: "\(typeName(mirror.subjectType))\(id)(",
200200
suffix: ")",
201-
filter: { $0.label.map { !$0.hasPrefix("_$") } ?? true }
201+
filter: macroPropertyFilter(for: value)
202202
)
203203
}
204204

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

285285
case (_, .tuple?):
@@ -331,3 +331,9 @@ func _customDump(_ value: Any, name: String?, indent: Int, isRoot: Bool, maxDept
331331
_customDump(value, to: &out, name: name, indent: indent, isRoot: isRoot, maxDepth: maxDepth)
332332
return out
333333
}
334+
335+
func macroPropertyFilter(for value: Any) -> (Mirror.Child) -> Bool {
336+
value is CustomDumpReflectable
337+
? { _ in true }
338+
: { $0.label.map { !$0.hasPrefix("_$") } ?? true }
339+
}

Tests/CustomDumpTests/DumpTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,4 +1329,29 @@ final class DumpTests: XCTestCase {
13291329
"""
13301330
)
13311331
}
1332+
1333+
func testExplicitFilteredPropertyPreserved() {
1334+
struct ObservationRegistrar {}
1335+
class Object: CustomDumpReflectable {
1336+
let name = "Blob Sr."
1337+
let _$observationRegistrar = ObservationRegistrar()
1338+
1339+
var customDumpMirror: Mirror {
1340+
Mirror(
1341+
self,
1342+
children: ["name": self.name, "_$observationRegistrar": self._$observationRegistrar],
1343+
displayStyle: .class
1344+
)
1345+
}
1346+
}
1347+
XCTAssertNoDifference(
1348+
String(customDumping: Object()),
1349+
"""
1350+
DumpTests.Object(
1351+
name: "Blob Sr.",
1352+
_$observationRegistrar: DumpTests.ObservationRegistrar()
1353+
)
1354+
"""
1355+
)
1356+
}
13321357
}

Tests/CustomDumpTests/Mocks.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ struct Wrapper<RawValue>: CustomDumpRepresentable {
9494
struct LoginState: CustomDumpReflectable {
9595
var email = "", password = "", token: String
9696

97+
init(email: String = "", password: String = "", token: String) {
98+
self.email = email
99+
self.password = password
100+
self.token = token
101+
}
102+
97103
var customDumpMirror: Mirror {
98104
.init(
99105
self,

0 commit comments

Comments
 (0)