Skip to content

Commit f873a51

Browse files
committed
[test] MinimalTypes: Move ==, < definitions into the corresponding type (NFC)
1 parent 08e6624 commit f873a51

File tree

1 file changed

+86
-73
lines changed

1 file changed

+86
-73
lines changed

stdlib/private/StdlibUnittest/MinimalTypes.swift

Lines changed: 86 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ public struct MinimalEquatableValue : Equatable {
5151
self.value = value
5252
self.identity = identity
5353
}
54-
}
55-
public func == (
56-
lhs: MinimalEquatableValue,
57-
rhs: MinimalEquatableValue
58-
) -> Bool {
59-
MinimalEquatableValue.timesEqualEqualWasCalled += 1
60-
return MinimalEquatableValue.equalImpl.value(lhs.value, rhs.value)
54+
55+
public static func == (
56+
lhs: MinimalEquatableValue,
57+
rhs: MinimalEquatableValue
58+
) -> Bool {
59+
MinimalEquatableValue.timesEqualEqualWasCalled += 1
60+
return MinimalEquatableValue.equalImpl.value(lhs.value, rhs.value)
61+
}
6162
}
6263

6364
/// A type that conforms only to `Equatable` and `Comparable`.
@@ -85,22 +86,22 @@ public struct MinimalComparableValue : Equatable, Comparable {
8586
self.value = value
8687
self.identity = identity
8788
}
88-
}
8989

90-
public func == (
91-
lhs: MinimalComparableValue,
92-
rhs: MinimalComparableValue
93-
) -> Bool {
94-
MinimalComparableValue.timesEqualEqualWasCalled.value += 1
95-
return MinimalComparableValue.equalImpl.value(lhs.value, rhs.value)
96-
}
90+
public static func == (
91+
lhs: MinimalComparableValue,
92+
rhs: MinimalComparableValue
93+
) -> Bool {
94+
MinimalComparableValue.timesEqualEqualWasCalled.value += 1
95+
return MinimalComparableValue.equalImpl.value(lhs.value, rhs.value)
96+
}
9797

98-
public func < (
99-
lhs: MinimalComparableValue,
100-
rhs: MinimalComparableValue
101-
) -> Bool {
102-
MinimalComparableValue.timesLessWasCalled.value += 1
103-
return MinimalComparableValue.lessImpl.value(lhs.value, rhs.value)
98+
public static func < (
99+
lhs: MinimalComparableValue,
100+
rhs: MinimalComparableValue
101+
) -> Bool {
102+
MinimalComparableValue.timesLessWasCalled.value += 1
103+
return MinimalComparableValue.lessImpl.value(lhs.value, rhs.value)
104+
}
104105
}
105106

106107

@@ -130,19 +131,20 @@ public struct MinimalHashableValue : Equatable, Hashable {
130131
self.identity = identity
131132
}
132133

134+
public static func ==(
135+
lhs: MinimalHashableValue,
136+
rhs: MinimalHashableValue
137+
) -> Bool {
138+
MinimalHashableValue.timesEqualEqualWasCalled += 1
139+
return MinimalHashableValue.equalImpl.value(lhs.value, rhs.value)
140+
}
141+
133142
public var hashValue: Int {
134143
MinimalHashableValue.timesHashValueWasCalled += 1
135144
return MinimalHashableValue.hashValueImpl.value(value)
136145
}
137146
}
138147

139-
public func == (
140-
lhs: MinimalHashableValue,
141-
rhs: MinimalHashableValue
142-
) -> Bool {
143-
MinimalHashableValue.timesEqualEqualWasCalled += 1
144-
return MinimalHashableValue.equalImpl.value(lhs.value, rhs.value)
145-
}
146148

147149

148150
/// A type that conforms only to `Equatable` and `Hashable`.
@@ -171,29 +173,34 @@ public class MinimalHashableClass : Equatable, Hashable {
171173
self.identity = identity
172174
}
173175

176+
public static func == (
177+
lhs: MinimalHashableClass,
178+
rhs: MinimalHashableClass
179+
) -> Bool {
180+
MinimalHashableClass.timesEqualEqualWasCalled += 1
181+
return MinimalHashableClass.equalImpl.value(lhs.value, rhs.value)
182+
}
183+
174184
public var hashValue: Int {
175185
MinimalHashableClass.timesHashValueWasCalled += 1
176186
return MinimalHashableClass.hashValueImpl.value(value)
177187
}
178188
}
179189

180-
public func == (
181-
lhs: MinimalHashableClass,
182-
rhs: MinimalHashableClass
183-
) -> Bool {
184-
MinimalHashableClass.timesEqualEqualWasCalled += 1
185-
return MinimalHashableClass.equalImpl.value(lhs.value, rhs.value)
186-
}
187190

188191

189192

190193
public var GenericMinimalHashableValue_timesEqualEqualWasCalled: Int = 0
191194
public var GenericMinimalHashableValue_timesHashValueWasCalled: Int = 0
192195

193-
public var GenericMinimalHashableValue_equalImpl = ResettableValue<(Any, Any) -> Bool>(
194-
{ _, _ in fatalError("GenericMinimalHashableValue_equalImpl is not set yet"); () })
195-
public var GenericMinimalHashableValue_hashValueImpl = ResettableValue<(Any) -> Int>(
196-
{ _ in fatalError("GenericMinimalHashableValue_hashValueImpl is not set yet"); () })
196+
public var GenericMinimalHashableValue_equalImpl =
197+
ResettableValue<(Any, Any) -> Bool>({ _, _ in
198+
fatalError("GenericMinimalHashableValue_equalImpl is not set yet")
199+
})
200+
public var GenericMinimalHashableValue_hashValueImpl =
201+
ResettableValue<(Any) -> Int>({ _ in
202+
fatalError("GenericMinimalHashableValue_hashValueImpl is not set yet")
203+
})
197204

198205
/// A type that conforms only to `Equatable` and `Hashable`.
199206
///
@@ -213,28 +220,32 @@ public struct GenericMinimalHashableValue<Wrapped> : Equatable, Hashable {
213220
self.identity = identity
214221
}
215222

223+
public static func == <Wrapped>(
224+
lhs: GenericMinimalHashableValue<Wrapped>,
225+
rhs: GenericMinimalHashableValue<Wrapped>
226+
) -> Bool {
227+
GenericMinimalHashableValue_timesEqualEqualWasCalled += 1
228+
return GenericMinimalHashableValue_equalImpl.value(lhs.value, rhs.value)
229+
}
230+
216231
public var hashValue: Int {
217232
GenericMinimalHashableValue_timesHashValueWasCalled += 1
218233
return GenericMinimalHashableValue_hashValueImpl.value(value)
219234
}
220235
}
221236

222-
public func == <Wrapped>(
223-
lhs: GenericMinimalHashableValue<Wrapped>,
224-
rhs: GenericMinimalHashableValue<Wrapped>
225-
) -> Bool {
226-
GenericMinimalHashableValue_timesEqualEqualWasCalled += 1
227-
return GenericMinimalHashableValue_equalImpl.value(lhs.value, rhs.value)
228-
}
229-
230237

231238
public var GenericMinimalHashableClass_timesEqualEqualWasCalled: Int = 0
232239
public var GenericMinimalHashableClass_timesHashValueWasCalled: Int = 0
233240

234-
public var GenericMinimalHashableClass_equalImpl = ResettableValue<(Any, Any) -> Bool>(
235-
{ _, _ in fatalError("GenericMinimalHashableClass_equalImpl is not set yet"); () })
236-
public var GenericMinimalHashableClass_hashValueImpl = ResettableValue<(Any) -> Int>(
237-
{ _ in fatalError("GenericMinimalHashableClass_hashValueImpl is not set yet"); () })
241+
public var GenericMinimalHashableClass_equalImpl =
242+
ResettableValue<(Any, Any) -> Bool>({ _, _ in
243+
fatalError("GenericMinimalHashableClass_equalImpl is not set yet")
244+
})
245+
public var GenericMinimalHashableClass_hashValueImpl =
246+
ResettableValue<(Any) -> Int>({ _ in
247+
fatalError("GenericMinimalHashableClass_hashValueImpl is not set yet")
248+
})
238249

239250
/// A type that conforms only to `Equatable` and `Hashable`.
240251
///
@@ -254,19 +265,20 @@ public class GenericMinimalHashableClass<Wrapped> : Equatable, Hashable {
254265
self.identity = identity
255266
}
256267

268+
public static func == <Wrapped>(
269+
lhs: GenericMinimalHashableClass<Wrapped>,
270+
rhs: GenericMinimalHashableClass<Wrapped>
271+
) -> Bool {
272+
GenericMinimalHashableClass_timesEqualEqualWasCalled += 1
273+
return GenericMinimalHashableClass_equalImpl.value(lhs.value, rhs.value)
274+
}
275+
257276
public var hashValue: Int {
258277
GenericMinimalHashableClass_timesHashValueWasCalled += 1
259278
return GenericMinimalHashableClass_hashValueImpl.value(value)
260279
}
261280
}
262281

263-
public func == <Wrapped>(
264-
lhs: GenericMinimalHashableClass<Wrapped>,
265-
rhs: GenericMinimalHashableClass<Wrapped>
266-
) -> Bool {
267-
GenericMinimalHashableClass_timesEqualEqualWasCalled += 1
268-
return GenericMinimalHashableClass_equalImpl.value(lhs.value, rhs.value)
269-
}
270282

271283

272284
/// A type that conforms only to `Equatable`, `Comparable`, and `Strideable`.
@@ -299,6 +311,22 @@ public struct MinimalStrideableValue : Equatable, Comparable, Strideable {
299311

300312
public typealias Stride = Int
301313

314+
public static func == (
315+
lhs: MinimalStrideableValue,
316+
rhs: MinimalStrideableValue
317+
) -> Bool {
318+
MinimalStrideableValue.timesEqualEqualWasCalled.value += 1
319+
return MinimalStrideableValue.equalImpl.value(lhs.value, rhs.value)
320+
}
321+
322+
public static func < (
323+
lhs: MinimalStrideableValue,
324+
rhs: MinimalStrideableValue
325+
) -> Bool {
326+
MinimalStrideableValue.timesLessWasCalled.value += 1
327+
return MinimalStrideableValue.lessImpl.value(lhs.value, rhs.value)
328+
}
329+
302330
public func distance(to other: MinimalStrideableValue) -> Stride {
303331
MinimalStrideableValue.timesDistanceWasCalled.value += 1
304332
return other.value - self.value
@@ -310,21 +338,6 @@ public struct MinimalStrideableValue : Equatable, Comparable, Strideable {
310338
}
311339
}
312340

313-
public func == (
314-
lhs: MinimalStrideableValue,
315-
rhs: MinimalStrideableValue
316-
) -> Bool {
317-
MinimalStrideableValue.timesEqualEqualWasCalled.value += 1
318-
return MinimalStrideableValue.equalImpl.value(lhs.value, rhs.value)
319-
}
320-
321-
public func < (
322-
lhs: MinimalStrideableValue,
323-
rhs: MinimalStrideableValue
324-
) -> Bool {
325-
MinimalStrideableValue.timesLessWasCalled.value += 1
326-
return MinimalStrideableValue.lessImpl.value(lhs.value, rhs.value)
327-
}
328341

329342
// Local Variables:
330343
// eval: (read-only-mode 1)

0 commit comments

Comments
 (0)