From 2fc9df9c332a0a8e17e4140c03d41bc64aede126 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 7 Mar 2023 16:38:53 -0800 Subject: [PATCH 1/3] Fix regression in `typeName` output The regular expression that strips excessive info from type names was refactored in #73 to fix some bugs that were discovered, but this change caused a regression in some nested types. --- Sources/CustomDump/Internal/AnyType.swift | 2 +- Tests/CustomDumpTests/DumpTests.swift | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/CustomDump/Internal/AnyType.swift b/Sources/CustomDump/Internal/AnyType.swift index 0ef3481..af2e255 100644 --- a/Sources/CustomDump/Internal/AnyType.swift +++ b/Sources/CustomDump/Internal/AnyType.swift @@ -5,7 +5,7 @@ func typeName( ) -> String { var name = _typeName(type, qualified: qualified) .replacingOccurrences( - of: #"\w+\.(\w+)"#, + of: #"^\w+\.(\w+)"#, with: "$1", options: .regularExpression ) diff --git a/Tests/CustomDumpTests/DumpTests.swift b/Tests/CustomDumpTests/DumpTests.swift index acc102b..d2fe2f2 100644 --- a/Tests/CustomDumpTests/DumpTests.swift +++ b/Tests/CustomDumpTests/DumpTests.swift @@ -24,6 +24,18 @@ final class DumpTests: XCTestCase { Foo.Bar.self """ ) + + struct Feature { + struct State {} + } + dump = "" + customDump(Feature.State.self, to: &dump) + XCTAssertNoDifference( + dump, + """ + DumpTests.Feature.State.self + """ + ) } func testClass() { From a724f7a9d6b996adc95f4b5ea48f51019e0e85eb Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 7 Mar 2023 16:54:16 -0800 Subject: [PATCH 2/3] fix --- Sources/CustomDump/Conformances/KeyPath.swift | 6 +++++- Sources/CustomDump/Internal/AnyType.swift | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/CustomDump/Conformances/KeyPath.swift b/Sources/CustomDump/Conformances/KeyPath.swift index a66ebec..3f8eea4 100644 --- a/Sources/CustomDump/Conformances/KeyPath.swift +++ b/Sources/CustomDump/Conformances/KeyPath.swift @@ -35,7 +35,11 @@ extension AnyKeyPath: CustomDumpStringConvertible { } return name #else - return typeName(Self.self, genericsAbbreviated: false) + return """ + \(typeName(Self.self))<\ + \(typeName(Self.rootType)), \ + \(typeName(Self.valueType,genericsAbbreviated: false))> + """ #endif } } diff --git a/Sources/CustomDump/Internal/AnyType.swift b/Sources/CustomDump/Internal/AnyType.swift index af2e255..d934bf5 100644 --- a/Sources/CustomDump/Internal/AnyType.swift +++ b/Sources/CustomDump/Internal/AnyType.swift @@ -5,13 +5,13 @@ func typeName( ) -> String { var name = _typeName(type, qualified: qualified) .replacingOccurrences( - of: #"^\w+\.(\w+)"#, - with: "$1", + of: #"\(unknown context at \$[[:xdigit:]]+\)\."#, + with: "", options: .regularExpression ) .replacingOccurrences( - of: #"\(unknown context at \$[[:xdigit:]]+\)\."#, - with: "", + of: #"\w+\.([\w.]+)"#, + with: "$1", options: .regularExpression ) if genericsAbbreviated { From 7f2fb85d957adbaae46729041e9e69b6b42b344f Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 7 Mar 2023 16:55:21 -0800 Subject: [PATCH 3/3] wip --- Tests/CustomDumpTests/DumpTests.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tests/CustomDumpTests/DumpTests.swift b/Tests/CustomDumpTests/DumpTests.swift index d2fe2f2..46df8bf 100644 --- a/Tests/CustomDumpTests/DumpTests.swift +++ b/Tests/CustomDumpTests/DumpTests.swift @@ -36,6 +36,15 @@ final class DumpTests: XCTestCase { DumpTests.Feature.State.self """ ) + + dump = "" + customDump((x: Double, y: Double).self, to: &dump) + XCTAssertNoDifference( + dump, + """ + (x: Double, y: Double).self + """ + ) } func testClass() {