Skip to content

Commit de8ba65

Browse files
authored
Fix regression in typeName output (#77)
* 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. * fix * wip
1 parent e266399 commit de8ba65

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

Sources/CustomDump/Conformances/KeyPath.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ extension AnyKeyPath: CustomDumpStringConvertible {
3535
}
3636
return name
3737
#else
38-
return typeName(Self.self, genericsAbbreviated: false)
38+
return """
39+
\(typeName(Self.self))<\
40+
\(typeName(Self.rootType)), \
41+
\(typeName(Self.valueType,genericsAbbreviated: false))>
42+
"""
3943
#endif
4044
}
4145
}

Sources/CustomDump/Internal/AnyType.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ func typeName(
55
) -> String {
66
var name = _typeName(type, qualified: qualified)
77
.replacingOccurrences(
8-
of: #"\w+\.(\w+)"#,
9-
with: "$1",
8+
of: #"\(unknown context at \$[[:xdigit:]]+\)\."#,
9+
with: "",
1010
options: .regularExpression
1111
)
1212
.replacingOccurrences(
13-
of: #"\(unknown context at \$[[:xdigit:]]+\)\."#,
14-
with: "",
13+
of: #"\w+\.([\w.]+)"#,
14+
with: "$1",
1515
options: .regularExpression
1616
)
1717
if genericsAbbreviated {

Tests/CustomDumpTests/DumpTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ final class DumpTests: XCTestCase {
2424
Foo.Bar.self
2525
"""
2626
)
27+
28+
struct Feature {
29+
struct State {}
30+
}
31+
dump = ""
32+
customDump(Feature.State.self, to: &dump)
33+
XCTAssertNoDifference(
34+
dump,
35+
"""
36+
DumpTests.Feature.State.self
37+
"""
38+
)
39+
40+
dump = ""
41+
customDump((x: Double, y: Double).self, to: &dump)
42+
XCTAssertNoDifference(
43+
dump,
44+
"""
45+
(x: Double, y: Double).self
46+
"""
47+
)
2748
}
2849

2950
func testClass() {

0 commit comments

Comments
 (0)