Skip to content

Commit e5c8092

Browse files
authored
Merge pull request #4134 from apple/simplify-tests
Simplify Foundation tests that compare types
2 parents 1df1bce + 1425a92 commit e5c8092

19 files changed

+141
-117
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ public func expectOptionalEqual${Generic}(
256256

257257
%end
258258

259+
public func expectEqual(
260+
_ expected: Any.Type, _ actual: Any.Type, ${TRACE}
261+
) {
262+
expectEqualTest(expected, actual, ${trace}, showFrame: false) { $0 == $1 }
263+
}
264+
259265
public func expectLT<T : Comparable>(_ lhs: T, _ rhs: T, ${TRACE}) {
260266
if !(lhs < rhs) {
261267
expectationFailure("\(lhs) < \(rhs)", trace: ${trace})

test/1_stdlib/TestAffineTransform.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ class TestAffineTransform : TestAffineTransformSuper {
337337
AffineTransform(m11: -55.66, m12: 22.7, m21: 1.5, m22: 0.0, tX: -22, tY: -33)
338338
]
339339
let anyHashables = values.map(AnyHashable.init)
340-
expectEqual("AffineTransform", String(describing: type(of: anyHashables[0].base)))
341-
expectEqual("AffineTransform", String(describing: type(of: anyHashables[1].base)))
342-
expectEqual("AffineTransform", String(describing: type(of: anyHashables[2].base)))
340+
expectEqual(AffineTransform.self, type(of: anyHashables[0].base))
341+
expectEqual(AffineTransform.self, type(of: anyHashables[1].base))
342+
expectEqual(AffineTransform.self, type(of: anyHashables[2].base))
343343
expectNotEqual(anyHashables[0], anyHashables[1])
344344
expectEqual(anyHashables[1], anyHashables[2])
345345
}
@@ -356,9 +356,9 @@ class TestAffineTransform : TestAffineTransformSuper {
356356
makeNSAffineTransform(rotatedByDegrees: 10),
357357
]
358358
let anyHashables = values.map(AnyHashable.init)
359-
expectEqual("AffineTransform", String(describing: type(of: anyHashables[0].base)))
360-
expectEqual("AffineTransform", String(describing: type(of: anyHashables[1].base)))
361-
expectEqual("AffineTransform", String(describing: type(of: anyHashables[2].base)))
359+
expectEqual(AffineTransform.self, type(of: anyHashables[0].base))
360+
expectEqual(AffineTransform.self, type(of: anyHashables[1].base))
361+
expectEqual(AffineTransform.self, type(of: anyHashables[2].base))
362362
expectNotEqual(anyHashables[0], anyHashables[1])
363363
expectEqual(anyHashables[1], anyHashables[2])
364364
}

test/1_stdlib/TestCalendar.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ class TestCalendar : TestCalendarSuper {
263263
Calendar(identifier: .japanese)
264264
]
265265
let anyHashables = values.map(AnyHashable.init)
266-
expectEqual("Calendar", String(describing: type(of: anyHashables[0].base)))
267-
expectEqual("Calendar", String(describing: type(of: anyHashables[1].base)))
268-
expectEqual("Calendar", String(describing: type(of: anyHashables[2].base)))
266+
expectEqual(Calendar.self, type(of: anyHashables[0].base))
267+
expectEqual(Calendar.self, type(of: anyHashables[1].base))
268+
expectEqual(Calendar.self, type(of: anyHashables[2].base))
269269
expectNotEqual(anyHashables[0], anyHashables[1])
270270
expectEqual(anyHashables[1], anyHashables[2])
271271
}
@@ -278,9 +278,9 @@ class TestCalendar : TestCalendarSuper {
278278
NSCalendar(identifier: .japanese)!,
279279
]
280280
let anyHashables = values.map(AnyHashable.init)
281-
expectEqual("Calendar", String(describing: type(of: anyHashables[0].base)))
282-
expectEqual("Calendar", String(describing: type(of: anyHashables[1].base)))
283-
expectEqual("Calendar", String(describing: type(of: anyHashables[2].base)))
281+
expectEqual(Calendar.self, type(of: anyHashables[0].base))
282+
expectEqual(Calendar.self, type(of: anyHashables[1].base))
283+
expectEqual(Calendar.self, type(of: anyHashables[2].base))
284284
expectNotEqual(anyHashables[0], anyHashables[1])
285285
expectEqual(anyHashables[1], anyHashables[2])
286286
}

test/1_stdlib/TestCharacterSet.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ class TestCharacterSet : TestCharacterSetSuper {
160160
CharacterSet(charactersIn: "XYZ")
161161
]
162162
let anyHashables = values.map(AnyHashable.init)
163-
expectEqual("CharacterSet", String(describing: type(of: anyHashables[0].base)))
164-
expectEqual("CharacterSet", String(describing: type(of: anyHashables[1].base)))
165-
expectEqual("CharacterSet", String(describing: type(of: anyHashables[2].base)))
163+
expectEqual(CharacterSet.self, type(of: anyHashables[0].base))
164+
expectEqual(CharacterSet.self, type(of: anyHashables[1].base))
165+
expectEqual(CharacterSet.self, type(of: anyHashables[2].base))
166166
expectNotEqual(anyHashables[0], anyHashables[1])
167167
expectEqual(anyHashables[1], anyHashables[2])
168168
}
@@ -174,9 +174,9 @@ class TestCharacterSet : TestCharacterSetSuper {
174174
NSCharacterSet(charactersIn: "XYZ"),
175175
]
176176
let anyHashables = values.map(AnyHashable.init)
177-
expectEqual("CharacterSet", String(describing: type(of: anyHashables[0].base)))
178-
expectEqual("CharacterSet", String(describing: type(of: anyHashables[1].base)))
179-
expectEqual("CharacterSet", String(describing: type(of: anyHashables[2].base)))
177+
expectEqual(CharacterSet.self, type(of: anyHashables[0].base))
178+
expectEqual(CharacterSet.self, type(of: anyHashables[1].base))
179+
expectEqual(CharacterSet.self, type(of: anyHashables[2].base))
180180
expectNotEqual(anyHashables[0], anyHashables[1])
181181
expectEqual(anyHashables[1], anyHashables[2])
182182
}

test/1_stdlib/TestData.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,9 @@ class TestData : TestDataSuper {
875875
Data(base64Encoded: "AAAB")!,
876876
]
877877
let anyHashables = values.map(AnyHashable.init)
878-
expectEqual("Data", String(describing: type(of: anyHashables[0].base)))
879-
expectEqual("Data", String(describing: type(of: anyHashables[1].base)))
880-
expectEqual("Data", String(describing: type(of: anyHashables[2].base)))
878+
expectEqual(Data.self, type(of: anyHashables[0].base))
879+
expectEqual(Data.self, type(of: anyHashables[1].base))
880+
expectEqual(Data.self, type(of: anyHashables[2].base))
881881
expectNotEqual(anyHashables[0], anyHashables[1])
882882
expectEqual(anyHashables[1], anyHashables[2])
883883
}
@@ -889,9 +889,9 @@ class TestData : TestDataSuper {
889889
NSData(base64Encoded: "AAAB")!,
890890
]
891891
let anyHashables = values.map(AnyHashable.init)
892-
expectEqual("Data", String(describing: type(of: anyHashables[0].base)))
893-
expectEqual("Data", String(describing: type(of: anyHashables[1].base)))
894-
expectEqual("Data", String(describing: type(of: anyHashables[2].base)))
892+
expectEqual(Data.self, type(of: anyHashables[0].base))
893+
expectEqual(Data.self, type(of: anyHashables[1].base))
894+
expectEqual(Data.self, type(of: anyHashables[2].base))
895895
expectNotEqual(anyHashables[0], anyHashables[1])
896896
expectEqual(anyHashables[1], anyHashables[2])
897897
}

test/1_stdlib/TestDate.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class TestDate : TestDateSuper {
143143
dateWithString("2010-05-17 14:49:47 -0700"),
144144
]
145145
let anyHashables = values.map(AnyHashable.init)
146-
expectEqual("Date", String(describing: type(of: anyHashables[0].base)))
147-
expectEqual("Date", String(describing: type(of: anyHashables[1].base)))
148-
expectEqual("Date", String(describing: type(of: anyHashables[2].base)))
146+
expectEqual(Date.self, type(of: anyHashables[0].base))
147+
expectEqual(Date.self, type(of: anyHashables[1].base))
148+
expectEqual(Date.self, type(of: anyHashables[2].base))
149149
expectNotEqual(anyHashables[0], anyHashables[1])
150150
expectEqual(anyHashables[1], anyHashables[2])
151151
}
@@ -157,9 +157,9 @@ class TestDate : TestDateSuper {
157157
NSDate(timeIntervalSince1970: 1000000001),
158158
]
159159
let anyHashables = values.map(AnyHashable.init)
160-
expectEqual("Date", String(describing: type(of: anyHashables[0].base)))
161-
expectEqual("Date", String(describing: type(of: anyHashables[1].base)))
162-
expectEqual("Date", String(describing: type(of: anyHashables[2].base)))
160+
expectEqual(Date.self, type(of: anyHashables[0].base))
161+
expectEqual(Date.self, type(of: anyHashables[1].base))
162+
expectEqual(Date.self, type(of: anyHashables[2].base))
163163
expectNotEqual(anyHashables[0], anyHashables[1])
164164
expectEqual(anyHashables[1], anyHashables[2])
165165
}
@@ -171,9 +171,9 @@ class TestDate : TestDateSuper {
171171
DateComponents(year: 1995),
172172
]
173173
let anyHashables = values.map(AnyHashable.init)
174-
expectEqual("DateComponents", String(describing: type(of: anyHashables[0].base)))
175-
expectEqual("DateComponents", String(describing: type(of: anyHashables[1].base)))
176-
expectEqual("DateComponents", String(describing: type(of: anyHashables[2].base)))
174+
expectEqual(DateComponents.self, type(of: anyHashables[0].base))
175+
expectEqual(DateComponents.self, type(of: anyHashables[1].base))
176+
expectEqual(DateComponents.self, type(of: anyHashables[2].base))
177177
expectNotEqual(anyHashables[0], anyHashables[1])
178178
expectEqual(anyHashables[1], anyHashables[2])
179179
}
@@ -190,9 +190,9 @@ class TestDate : TestDateSuper {
190190
makeNSDateComponents(year: 1995),
191191
]
192192
let anyHashables = values.map(AnyHashable.init)
193-
expectEqual("DateComponents", String(describing: type(of: anyHashables[0].base)))
194-
expectEqual("DateComponents", String(describing: type(of: anyHashables[1].base)))
195-
expectEqual("DateComponents", String(describing: type(of: anyHashables[2].base)))
193+
expectEqual(DateComponents.self, type(of: anyHashables[0].base))
194+
expectEqual(DateComponents.self, type(of: anyHashables[1].base))
195+
expectEqual(DateComponents.self, type(of: anyHashables[2].base))
196196
expectNotEqual(anyHashables[0], anyHashables[1])
197197
expectEqual(anyHashables[1], anyHashables[2])
198198
}

test/1_stdlib/TestDateInterval.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ class TestDateInterval : TestDateIntervalSuper {
140140
DateInterval(start: start, duration: duration / 2),
141141
]
142142
let anyHashables = values.map(AnyHashable.init)
143-
expectEqual("DateInterval", String(describing: type(of: anyHashables[0].base)))
144-
expectEqual("DateInterval", String(describing: type(of: anyHashables[1].base)))
145-
expectEqual("DateInterval", String(describing: type(of: anyHashables[2].base)))
143+
expectEqual(DateInterval.self, type(of: anyHashables[0].base))
144+
expectEqual(DateInterval.self, type(of: anyHashables[1].base))
145+
expectEqual(DateInterval.self, type(of: anyHashables[2].base))
146146
expectNotEqual(anyHashables[0], anyHashables[1])
147147
expectEqual(anyHashables[1], anyHashables[2])
148148
}
@@ -158,9 +158,9 @@ class TestDateInterval : TestDateIntervalSuper {
158158
NSDateInterval(start: start, duration: duration / 2),
159159
]
160160
let anyHashables = values.map(AnyHashable.init)
161-
expectEqual("DateInterval", String(describing: type(of: anyHashables[0].base)))
162-
expectEqual("DateInterval", String(describing: type(of: anyHashables[1].base)))
163-
expectEqual("DateInterval", String(describing: type(of: anyHashables[2].base)))
161+
expectEqual(DateInterval.self, type(of: anyHashables[0].base))
162+
expectEqual(DateInterval.self, type(of: anyHashables[1].base))
163+
expectEqual(DateInterval.self, type(of: anyHashables[2].base))
164164
expectNotEqual(anyHashables[0], anyHashables[1])
165165
expectEqual(anyHashables[1], anyHashables[2])
166166
}

test/1_stdlib/TestIndexPath.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class TestIndexPath : TestIndexPathSuper {
8989
IndexPath(indexes: [1, 2, 3]),
9090
]
9191
let anyHashables = values.map(AnyHashable.init)
92-
expectEqual("IndexPath", String(describing: type(of: anyHashables[0].base)))
93-
expectEqual("IndexPath", String(describing: type(of: anyHashables[1].base)))
94-
expectEqual("IndexPath", String(describing: type(of: anyHashables[2].base)))
92+
expectEqual(IndexPath.self, type(of: anyHashables[0].base))
93+
expectEqual(IndexPath.self, type(of: anyHashables[1].base))
94+
expectEqual(IndexPath.self, type(of: anyHashables[2].base))
9595
expectNotEqual(anyHashables[0], anyHashables[1])
9696
expectEqual(anyHashables[1], anyHashables[2])
9797
}
@@ -103,9 +103,9 @@ class TestIndexPath : TestIndexPathSuper {
103103
NSIndexPath(index: 2),
104104
]
105105
let anyHashables = values.map(AnyHashable.init)
106-
expectEqual("IndexPath", String(describing: type(of: anyHashables[0].base)))
107-
expectEqual("IndexPath", String(describing: type(of: anyHashables[1].base)))
108-
expectEqual("IndexPath", String(describing: type(of: anyHashables[2].base)))
106+
expectEqual(IndexPath.self, type(of: anyHashables[0].base))
107+
expectEqual(IndexPath.self, type(of: anyHashables[1].base))
108+
expectEqual(IndexPath.self, type(of: anyHashables[2].base))
109109
expectNotEqual(anyHashables[0], anyHashables[1])
110110
expectEqual(anyHashables[1], anyHashables[2])
111111
}

test/1_stdlib/TestIndexSet.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,9 @@ class TestIndexSet : TestIndexSetSuper {
799799
IndexSet([0, 1, 2]),
800800
]
801801
let anyHashables = values.map(AnyHashable.init)
802-
expectEqual("IndexSet", String(describing: type(of: anyHashables[0].base)))
803-
expectEqual("IndexSet", String(describing: type(of: anyHashables[1].base)))
804-
expectEqual("IndexSet", String(describing: type(of: anyHashables[2].base)))
802+
expectEqual(IndexSet.self, type(of: anyHashables[0].base))
803+
expectEqual(IndexSet.self, type(of: anyHashables[1].base))
804+
expectEqual(IndexSet.self, type(of: anyHashables[2].base))
805805
expectNotEqual(anyHashables[0], anyHashables[1])
806806
expectEqual(anyHashables[1], anyHashables[2])
807807
}
@@ -813,9 +813,9 @@ class TestIndexSet : TestIndexSetSuper {
813813
NSIndexSet(index: 1),
814814
]
815815
let anyHashables = values.map(AnyHashable.init)
816-
expectEqual("IndexSet", String(describing: type(of: anyHashables[0].base)))
817-
expectEqual("IndexSet", String(describing: type(of: anyHashables[1].base)))
818-
expectEqual("IndexSet", String(describing: type(of: anyHashables[2].base)))
816+
expectEqual(IndexSet.self, type(of: anyHashables[0].base))
817+
expectEqual(IndexSet.self, type(of: anyHashables[1].base))
818+
expectEqual(IndexSet.self, type(of: anyHashables[2].base))
819819
expectNotEqual(anyHashables[0], anyHashables[1])
820820
expectEqual(anyHashables[1], anyHashables[2])
821821
}

test/1_stdlib/TestLocale.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ class TestLocale : TestLocaleSuper {
116116
Locale(identifier: "uk"),
117117
]
118118
let anyHashables = values.map(AnyHashable.init)
119-
expectEqual("Locale", String(describing: type(of: anyHashables[0].base)))
120-
expectEqual("Locale", String(describing: type(of: anyHashables[1].base)))
121-
expectEqual("Locale", String(describing: type(of: anyHashables[2].base)))
119+
expectEqual(Locale.self, type(of: anyHashables[0].base))
120+
expectEqual(Locale.self, type(of: anyHashables[1].base))
121+
expectEqual(Locale.self, type(of: anyHashables[2].base))
122122
expectNotEqual(anyHashables[0], anyHashables[1])
123123
expectEqual(anyHashables[1], anyHashables[2])
124124
}
@@ -130,9 +130,9 @@ class TestLocale : TestLocaleSuper {
130130
NSLocale(localeIdentifier: "uk"),
131131
]
132132
let anyHashables = values.map(AnyHashable.init)
133-
expectEqual("Locale", String(describing: type(of: anyHashables[0].base)))
134-
expectEqual("Locale", String(describing: type(of: anyHashables[1].base)))
135-
expectEqual("Locale", String(describing: type(of: anyHashables[2].base)))
133+
expectEqual(Locale.self, type(of: anyHashables[0].base))
134+
expectEqual(Locale.self, type(of: anyHashables[1].base))
135+
expectEqual(Locale.self, type(of: anyHashables[2].base))
136136
expectNotEqual(anyHashables[0], anyHashables[1])
137137
expectEqual(anyHashables[1], anyHashables[2])
138138
}

test/1_stdlib/TestPersonNameComponents.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class TestPersonNameComponents : TestPersonNameComponentsSuper {
3737
makePersonNameComponents(givenName: "John", familyName: "Appleseed"),
3838
]
3939
let anyHashables = values.map(AnyHashable.init)
40-
expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[0].base)))
41-
expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[1].base)))
42-
expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[2].base)))
40+
expectEqual(PersonNameComponents.self, type(of: anyHashables[0].base))
41+
expectEqual(PersonNameComponents.self, type(of: anyHashables[1].base))
42+
expectEqual(PersonNameComponents.self, type(of: anyHashables[2].base))
4343
expectNotEqual(anyHashables[0], anyHashables[1])
4444
expectEqual(anyHashables[1], anyHashables[2])
4545
}
@@ -61,9 +61,9 @@ class TestPersonNameComponents : TestPersonNameComponentsSuper {
6161
makeNSPersonNameComponents(givenName: "John", familyName: "Appleseed"),
6262
]
6363
let anyHashables = values.map(AnyHashable.init)
64-
expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[0].base)))
65-
expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[1].base)))
66-
expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[2].base)))
64+
expectEqual(PersonNameComponents.self, type(of: anyHashables[0].base))
65+
expectEqual(PersonNameComponents.self, type(of: anyHashables[1].base))
66+
expectEqual(PersonNameComponents.self, type(of: anyHashables[2].base))
6767
expectNotEqual(anyHashables[0], anyHashables[1])
6868
expectEqual(anyHashables[1], anyHashables[2])
6969
}

test/1_stdlib/TestTimeZone.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class TestTimeZone : TestTimeZoneSuper {
7070
TimeZone(identifier: "Europe/Kiev")!,
7171
]
7272
let anyHashables = values.map(AnyHashable.init)
73-
expectEqual("TimeZone", String(describing: type(of: anyHashables[0].base)))
74-
expectEqual("TimeZone", String(describing: type(of: anyHashables[1].base)))
75-
expectEqual("TimeZone", String(describing: type(of: anyHashables[2].base)))
73+
expectEqual(TimeZone.self, type(of: anyHashables[0].base))
74+
expectEqual(TimeZone.self, type(of: anyHashables[1].base))
75+
expectEqual(TimeZone.self, type(of: anyHashables[2].base))
7676
expectNotEqual(anyHashables[0], anyHashables[1])
7777
expectEqual(anyHashables[1], anyHashables[2])
7878
}
@@ -84,9 +84,9 @@ class TestTimeZone : TestTimeZoneSuper {
8484
NSTimeZone(name: "Europe/Kiev")!,
8585
]
8686
let anyHashables = values.map(AnyHashable.init)
87-
expectEqual("TimeZone", String(describing: type(of: anyHashables[0].base)))
88-
expectEqual("TimeZone", String(describing: type(of: anyHashables[1].base)))
89-
expectEqual("TimeZone", String(describing: type(of: anyHashables[2].base)))
87+
expectEqual(TimeZone.self, type(of: anyHashables[0].base))
88+
expectEqual(TimeZone.self, type(of: anyHashables[1].base))
89+
expectEqual(TimeZone.self, type(of: anyHashables[2].base))
9090
expectNotEqual(anyHashables[0], anyHashables[1])
9191
expectEqual(anyHashables[1], anyHashables[2])
9292
}

0 commit comments

Comments
 (0)