File tree Expand file tree Collapse file tree 2 files changed +106
-5
lines changed
Sources/CustomDump/Internal Expand file tree Collapse file tree 2 files changed +106
-5
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,31 @@ func typeName(
9
9
with: " " ,
10
10
options: . regularExpression
11
11
)
12
- . replacingOccurrences (
13
- of: #"\w+\.([\w.]+)"# ,
14
- with: " $1 " ,
15
- options: . regularExpression
16
- )
12
+ for _ in 1 ... 10 { // NB: Only handle so much nesting
13
+ let abbreviated = name
14
+ . replacingOccurrences (
15
+ of: #"\bSwift.Optional<([^><]+)>"# ,
16
+ with: " $1? " ,
17
+ options: . regularExpression
18
+ )
19
+ . replacingOccurrences (
20
+ of: #"\bSwift.Array<([^><]+)>"# ,
21
+ with: " [$1] " ,
22
+ options: . regularExpression
23
+ )
24
+ . replacingOccurrences (
25
+ of: #"\bSwift.Dictionary<([^,<]+), ([^><]+)>"# ,
26
+ with: " [$1: $2] " ,
27
+ options: . regularExpression
28
+ )
29
+ if abbreviated == name { break }
30
+ name = abbreviated
31
+ }
32
+ name = name. replacingOccurrences (
33
+ of: #"\w+\.([\w.]+)"# ,
34
+ with: " $1 " ,
35
+ options: . regularExpression
36
+ )
17
37
if genericsAbbreviated {
18
38
name = name. replacingOccurrences (
19
39
of: #"<.+>"# ,
Original file line number Diff line number Diff line change @@ -45,6 +45,87 @@ final class DumpTests: XCTestCase {
45
45
(x: Double, y: Double).self
46
46
"""
47
47
)
48
+
49
+ dump = " "
50
+ customDump ( Double ? . self, to: & dump)
51
+ XCTAssertNoDifference (
52
+ dump,
53
+ """
54
+ Double?.self
55
+ """
56
+ )
57
+
58
+ dump = " "
59
+ customDump ( [ Int ] . self, to: & dump)
60
+ XCTAssertNoDifference (
61
+ dump,
62
+ """
63
+ [Int].self
64
+ """
65
+ )
66
+
67
+ dump = " "
68
+ customDump ( [ String : Int ] . self, to: & dump)
69
+ XCTAssertNoDifference (
70
+ dump,
71
+ """
72
+ [String: Int].self
73
+ """
74
+ )
75
+
76
+ dump = " "
77
+ customDump ( [ [ Double : Double ? ] ] . self, to: & dump)
78
+ XCTAssertNoDifference (
79
+ dump,
80
+ """
81
+ [[Double: Double?]].self
82
+ """
83
+ )
84
+
85
+ dump = " "
86
+ customDump ( [ [ Double : Double ] ? ] . self, to: & dump)
87
+ XCTAssertNoDifference (
88
+ dump,
89
+ """
90
+ [[Double: Double]?].self
91
+ """
92
+ )
93
+
94
+ dump = " "
95
+ customDump ( [ [ Double: [ Double] ] ] ? . self, to: & dump)
96
+ XCTAssertNoDifference (
97
+ dump,
98
+ """
99
+ [[Double: [Double]]]?.self
100
+ """
101
+ )
102
+
103
+ dump = " "
104
+ customDump ( [ [ [ Double: Double] ] ] ? . self, to: & dump)
105
+ XCTAssertNoDifference (
106
+ dump,
107
+ """
108
+ [[[Double: Double]]]?.self
109
+ """
110
+ )
111
+
112
+ dump = " "
113
+ customDump ( [ Double : [ Double ? ] ] . self, to: & dump)
114
+ XCTAssertNoDifference (
115
+ dump,
116
+ """
117
+ [Double: [Double?]].self
118
+ """
119
+ )
120
+
121
+ dump = " "
122
+ customDump ( [ Double : [ Double ] ? ] . self, to: & dump)
123
+ XCTAssertNoDifference (
124
+ dump,
125
+ """
126
+ [Double: [Double]?].self
127
+ """
128
+ )
48
129
}
49
130
50
131
func testClass( ) {
You can’t perform that action at this time.
0 commit comments