From a799dad405c31f1e1d76f579f24ac43faeb058d9 Mon Sep 17 00:00:00 2001 From: Mahmood Tahir Date: Thu, 22 Sep 2022 12:37:46 -0400 Subject: [PATCH] Dump superclass by default --- .../CustomDump/Conformances/Foundation.swift | 20 +++++++++++++++++++ Sources/CustomDump/CustomDumpChildren.swift | 4 ++-- Sources/CustomDump/Dump.swift | 3 ++- Tests/CustomDumpTests/DumpTests.swift | 4 ++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Sources/CustomDump/Conformances/Foundation.swift b/Sources/CustomDump/Conformances/Foundation.swift index 3158488..5a4f28b 100644 --- a/Sources/CustomDump/Conformances/Foundation.swift +++ b/Sources/CustomDump/Conformances/Foundation.swift @@ -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 diff --git a/Sources/CustomDump/CustomDumpChildren.swift b/Sources/CustomDump/CustomDumpChildren.swift index cdee3bb..2f3878b 100644 --- a/Sources/CustomDump/CustomDumpChildren.swift +++ b/Sources/CustomDump/CustomDumpChildren.swift @@ -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 /// diff --git a/Sources/CustomDump/Dump.swift b/Sources/CustomDump/Dump.swift index d3ede71..5c7d7a6 100644 --- a/Sources/CustomDump/Dump.swift +++ b/Sources/CustomDump/Dump.swift @@ -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 @@ -262,7 +263,7 @@ public func customDump( } } - 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) } diff --git a/Tests/CustomDumpTests/DumpTests.swift b/Tests/CustomDumpTests/DumpTests.swift index 36065de..cf680e2 100644 --- a/Tests/CustomDumpTests/DumpTests.swift +++ b/Tests/CustomDumpTests/DumpTests.swift @@ -723,7 +723,7 @@ final class DumpTests: XCTestCase { let age = 97 } - class Doctor: Human, CustomDumpIncludeSuperclass { + class Doctor: Human { let field = "Podiatry" } @@ -750,7 +750,7 @@ final class DumpTests: XCTestCase { let age = 97 } - class Doctor: Human, CustomDumpIncludeSuperclass { + class Doctor: Human { let field = "Podiatry" }