Skip to content

Commit

Permalink
Dump superclass by default
Browse files Browse the repository at this point in the history
  • Loading branch information
tahirmt committed Sep 22, 2022
1 parent b7b33cd commit cfa341e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
20 changes: 20 additions & 0 deletions Sources/CustomDump/Conformances/Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,23 @@ extension UUID: CustomDumpStringConvertible {
"UUID(\(self.uuidString))"
}
}

extension KeyPath: CustomDumpExcludeSuperclass {}
extension CFNumber: CustomDumpExcludeSuperclass {}
extension NSNumber: CustomDumpExcludeSuperclass {}
extension NSMutableAttributedString: CustomDumpExcludeSuperclass {}
extension NSCalendar: CustomDumpExcludeSuperclass {}
extension NSCountedSet: CustomDumpExcludeSuperclass {}
#if !os(WASI)
extension NSData: CustomDumpExcludeSuperclass {}
extension NSDate: CustomDumpExcludeSuperclass {}
extension NSNotification: CustomDumpExcludeSuperclass {}
extension NSTimeZone: CustomDumpExcludeSuperclass {}
extension NSURLRequest: CustomDumpExcludeSuperclass {}
#endif
extension NSDictionary: CustomDumpExcludeSuperclass {}
extension NSString: CustomDumpExcludeSuperclass {}
extension NSLocale: CustomDumpExcludeSuperclass {}
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
extension NSExpression: CustomDumpExcludeSuperclass {}
#endif
4 changes: 2 additions & 2 deletions Sources/CustomDump/CustomDumpChildren.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Implement this protocol to include superclass nodes
public protocol CustomDumpIncludeSuperclass {}
/// Implement this protocol to exclude superclass nodes
public protocol CustomDumpExcludeSuperclass {}

/// Implement this protocol to ignore dumping child nodes
///
Expand Down
3 changes: 2 additions & 1 deletion Sources/CustomDump/Dump.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
/// Dumps the given value's contents using its mirror to standard output.
///
/// This function aims to dump the contents of a value into a nicely formatted, tree-like
Expand Down Expand Up @@ -262,7 +263,7 @@ public func customDump<T, TargetStream>(
}
}

if let superclassMirror = mirror.superclassMirror, value is CustomDumpIncludeSuperclass {
if let superclassMirror = mirror.superclassMirror, superclassMirror.subjectType != NSObject.self, !(value is CustomDumpExcludeSuperclass) {
out.write("\n")
dumpMirror(mirror: superclassMirror)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/CustomDumpTests/DumpTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ final class DumpTests: XCTestCase {
let age = 97
}

class Doctor: Human, CustomDumpIncludeSuperclass {
class Doctor: Human {
let field = "Podiatry"
}

Expand All @@ -750,7 +750,7 @@ final class DumpTests: XCTestCase {
let age = 97
}

class Doctor: Human, CustomDumpIncludeSuperclass {
class Doctor: Human {
let field = "Podiatry"
}

Expand Down

0 comments on commit cfa341e

Please sign in to comment.