Skip to content

Commit 9beb1c1

Browse files
committed
Build fix
1 parent 42d60c3 commit 9beb1c1

File tree

1 file changed

+75
-65
lines changed

1 file changed

+75
-65
lines changed

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift

Lines changed: 75 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,40 @@
1313
import StdlibUnittest
1414

1515
// A minimal RRC conformance, to test default implementations with
16-
struct NaiveRRC : RangeReplaceableCollection, ExpressibleByArrayLiteral {
16+
public struct NaiveRRC : RangeReplaceableCollection, ExpressibleByArrayLiteral {
1717

1818
// we're trying to move away from calling reserveCapacity inside most mutating
1919
// methods, this will let us verify that we don't
2020
internal var allowReserveCapacity = true
21-
var storage:[UInt8] = []
21+
var storage:[Int] = []
2222

23-
init() {}
23+
public init() {}
2424

25-
init(arrayLiteral elements: Element...) {
25+
public init(arrayLiteral elements: Element...) {
2626
storage.append(contentsOf: elements)
2727
}
2828

29-
func index(after i: Int) -> Int {
29+
public func index(after i: Int) -> Int {
3030
i + 1
3131
}
3232

33-
func index(before i: Int) -> Int {
33+
public func index(before i: Int) -> Int {
3434
i - 1
3535
}
3636

37-
var startIndex: Int {
37+
public var startIndex: Int {
3838
0
3939
}
4040

41-
var endIndex: Int {
41+
public var endIndex: Int {
4242
count
4343
}
4444

45-
var count: Int {
45+
public var count: Int {
4646
storage.count
4747
}
4848

49-
subscript(position: Int) -> UInt8 {
49+
public subscript(position: Int) -> Int {
5050
get {
5151
storage[position]
5252
}
@@ -55,11 +55,11 @@ struct NaiveRRC : RangeReplaceableCollection, ExpressibleByArrayLiteral {
5555
}
5656
}
5757

58-
mutating func replaceSubrange(_ subrange: Range<Int>, with newElements: some Collection<UInt8>) {
58+
public mutating func replaceSubrange(_ subrange: Range<Int>, with newElements: some Collection<Int>) {
5959
storage.replaceSubrange(subrange, with: newElements)
6060
}
6161

62-
mutating func reserveCapacity(_ n: Int) {
62+
public mutating func reserveCapacity(_ n: Int) {
6363
precondition(allowReserveCapacity)
6464
storage.reserveCapacity(n)
6565
}
@@ -81,17 +81,18 @@ internal enum IndexSelection {
8181
}
8282
}
8383

84-
public struct ReplaceSubrangeTest {
84+
public struct ReplaceSubrangeTest<C: RangeReplaceableCollection> where C.Element == Int {
8585
public let collection: [OpaqueValue<Int>]
8686
public let newElements: [OpaqueValue<Int>]
8787
public let rangeSelection: RangeSelection
88-
public let expected: [Int]
89-
public let closedExpected: [Int]? // Expected array for closed ranges
88+
public let expected: C
89+
public let closedExpected: C? // Expected array for closed ranges
9090
public let loc: SourceLoc
9191

9292
internal init(
93-
collection: [Int], newElements: [Int],
94-
rangeSelection: RangeSelection, expected: [Int], closedExpected: [Int]? = nil,
93+
collection: some RangeReplaceableCollection<Int>,
94+
newElements: some Collection<Int>,
95+
rangeSelection: RangeSelection, expected: C, closedExpected: C? = nil,
9596
file: String = #file, line: UInt = #line
9697
) {
9798
self.collection = collection.map(OpaqueValue.init)
@@ -103,14 +104,15 @@ public struct ReplaceSubrangeTest {
103104
}
104105
}
105106

106-
internal struct AppendTest {
107+
internal struct AppendTest<C: RangeReplaceableCollection> where C.Element == Int {
107108
let collection: [OpaqueValue<Int>]
108109
let newElement: OpaqueValue<Int>
109-
let expected: [Int]
110+
let expected: C
110111
let loc: SourceLoc
111112

112113
internal init(
113-
collection: [Int], newElement: Int, expected: [Int],
114+
collection: some RangeReplaceableCollection<Int>,
115+
newElement: Int, expected: C,
114116
file: String = #file, line: UInt = #line
115117
) {
116118
self.collection = collection.map(OpaqueValue.init)
@@ -120,14 +122,15 @@ internal struct AppendTest {
120122
}
121123
}
122124

123-
internal struct AppendContentsOfTest {
125+
internal struct AppendContentsOfTest<C: RangeReplaceableCollection> where C.Element == Int {
124126
let collection: [OpaqueValue<Int>]
125127
let newElements: [OpaqueValue<Int>]
126-
let expected: [Int]
128+
let expected: C
127129
let loc: SourceLoc
128130

129131
internal init(
130-
collection: [Int], newElements: [Int], expected: [Int],
132+
collection: some RangeReplaceableCollection<Int>,
133+
newElements: some RangeReplaceableCollection<Int>, expected: C,
131134
file: String = #file, line: UInt = #line
132135
) {
133136
self.collection = collection.map(OpaqueValue.init)
@@ -137,16 +140,17 @@ internal struct AppendContentsOfTest {
137140
}
138141
}
139142

140-
internal struct InsertTest {
143+
internal struct InsertTest<C: RangeReplaceableCollection> where C.Element == Int {
141144
let collection: [OpaqueValue<Int>]
142145
let newElement: OpaqueValue<Int>
143146
let indexSelection: IndexSelection
144-
let expected: [Int]
147+
let expected: C
145148
let loc: SourceLoc
146149

147150
internal init(
148-
collection: [Int], newElement: Int, indexSelection: IndexSelection,
149-
expected: [Int], file: String = #file, line: UInt = #line
151+
collection: some RangeReplaceableCollection<Int>,
152+
newElement: Int, indexSelection: IndexSelection,
153+
expected: C, file: String = #file, line: UInt = #line
150154
) {
151155
self.collection = collection.map(OpaqueValue.init)
152156
self.newElement = OpaqueValue(newElement)
@@ -156,16 +160,18 @@ internal struct InsertTest {
156160
}
157161
}
158162

159-
internal struct InsertContentsOfTest {
163+
internal struct InsertContentsOfTest<C: RangeReplaceableCollection> where C.Element == Int {
160164
let collection: [OpaqueValue<Int>]
161165
let newElements: [OpaqueValue<Int>]
162166
let indexSelection: IndexSelection
163-
let expected: [Int]
167+
let expected: C
164168
let loc: SourceLoc
165169

166170
internal init(
167-
collection: [Int], newElements: [Int], indexSelection: IndexSelection,
168-
expected: [Int], file: String = #file, line: UInt = #line
171+
collection: some RangeReplaceableCollection<Int>,
172+
newElements: some RangeReplaceableCollection<Int>,
173+
indexSelection: IndexSelection,
174+
expected: C, file: String = #file, line: UInt = #line
169175
) {
170176
self.collection = collection.map(OpaqueValue.init)
171177
self.newElements = newElements.map(OpaqueValue.init)
@@ -175,17 +181,17 @@ internal struct InsertContentsOfTest {
175181
}
176182
}
177183

178-
internal struct RemoveAtIndexTest {
184+
internal struct RemoveAtIndexTest<C: RangeReplaceableCollection> where C.Element == Int {
179185
let collection: [OpaqueValue<Int>]
180186
let indexSelection: IndexSelection
181187
let expectedRemovedElement: Int
182-
let expectedCollection: [Int]
188+
let expectedCollection: C
183189
let loc: SourceLoc
184190

185191
internal init(
186-
collection: [Int], indexSelection: IndexSelection,
187-
expectedRemovedElement: Int, expectedCollection: [Int],
188-
file: String = #file, line: UInt = #line
192+
collection: some RangeReplaceableCollection<Int>,
193+
indexSelection: IndexSelection, expectedRemovedElement: Int,
194+
expectedCollection: C, file: String = #file, line: UInt = #line
189195
) {
190196
self.collection = collection.map(OpaqueValue.init)
191197
self.indexSelection = indexSelection
@@ -195,14 +201,15 @@ internal struct RemoveAtIndexTest {
195201
}
196202
}
197203

198-
internal struct RemoveLastNTest {
204+
internal struct RemoveLastNTest<C: RangeReplaceableCollection> where C.Element == Int {
199205
let collection: [OpaqueValue<Int>]
200206
let numberToRemove: Int
201-
let expectedCollection: [Int]
207+
let expectedCollection: C
202208
let loc: SourceLoc
203209

204210
internal init(
205-
collection: [Int], numberToRemove: Int, expectedCollection: [Int],
211+
collection: some RangeReplaceableCollection<Int>,
212+
numberToRemove: Int, expectedCollection: C,
206213
file: String = #file, line: UInt = #line
207214
) {
208215
self.collection = collection.map(OpaqueValue.init)
@@ -212,14 +219,15 @@ internal struct RemoveLastNTest {
212219
}
213220
}
214221

215-
public struct RemoveSubrangeTest {
222+
public struct RemoveSubrangeTest<C: RangeReplaceableCollection> where C.Element == Int {
216223
public let collection: [OpaqueValue<Int>]
217224
public let rangeSelection: RangeSelection
218-
public let expected: [Int]
225+
public let expected: C
219226
public let loc: SourceLoc
220227

221228
internal init(
222-
collection: [Int], rangeSelection: RangeSelection, expected: [Int],
229+
collection: some RangeReplaceableCollection<Int>,
230+
rangeSelection: RangeSelection, expected: C,
223231
file: String = #file, line: UInt = #line
224232
) {
225233
self.collection = collection.map(OpaqueValue.init)
@@ -229,13 +237,13 @@ public struct RemoveSubrangeTest {
229237
}
230238
}
231239

232-
internal struct RemoveAllTest {
240+
internal struct RemoveAllTest<C: RangeReplaceableCollection> where C.Element == Int {
233241
let collection: [OpaqueValue<Int>]
234-
let expected: [Int]
242+
let expected: C
235243
let loc: SourceLoc
236244

237245
internal init(
238-
collection: [Int], expected: [Int],
246+
collection: some RangeReplaceableCollection<Int>, expected: C,
239247
file: String = #file, line: UInt = #line
240248
) {
241249
self.collection = collection.map(OpaqueValue.init)
@@ -250,7 +258,7 @@ internal struct ReserveCapacityTest {
250258
let loc: SourceLoc
251259

252260
internal init(
253-
collection: [Int], requestedCapacity: Int,
261+
collection: some RangeReplaceableCollection<Int>, requestedCapacity: Int,
254262
file: String = #file, line: UInt = #line
255263
) {
256264
self.collection = collection.map(OpaqueValue.init)
@@ -259,14 +267,16 @@ internal struct ReserveCapacityTest {
259267
}
260268
}
261269

262-
internal struct OperatorPlusTest {
270+
internal struct OperatorPlusTest<C: RangeReplaceableCollection> where C.Element == Int {
263271
let lhs: [OpaqueValue<Int>]
264272
let rhs: [OpaqueValue<Int>]
265-
let expected: [Int]
273+
let expected: C
266274
let loc: SourceLoc
267275

268276
internal init(
269-
lhs: [Int], rhs: [Int], expected: [Int],
277+
lhs: some RangeReplaceableCollection<Int>,
278+
rhs: some RangeReplaceableCollection<Int>,
279+
expected: C,
270280
file: String = #file, line: UInt = #line
271281
) {
272282
self.lhs = lhs.map(OpaqueValue.init)
@@ -603,44 +613,44 @@ public let removeRangeTests: [RemoveSubrangeTest] = [
603613
expected: [1010, 6060]),
604614

605615
RemoveSubrangeTest(
606-
collection: [] as NaiveRRC),
616+
collection: [] as NaiveRRC,
607617
rangeSelection: .emptyRange,
608-
expected: []) as NaiveRRC),
618+
expected: [] as NaiveRRC),
609619

610620
RemoveSubrangeTest(
611-
collection: [1010] as NaiveRRC),
621+
collection: [1010] as NaiveRRC,
612622
rangeSelection: .middle,
613-
expected: [] as NaiveRRC)),
623+
expected: [] as NaiveRRC),
614624

615625
RemoveSubrangeTest(
616-
collection: [1010, 2020, 3030, 4040] as NaiveRRC),
626+
collection: [1010, 2020, 3030, 4040] as NaiveRRC,
617627
rangeSelection: .leftHalf,
618-
expected: [3030, 4040] as NaiveRRC)),
628+
expected: [3030, 4040] as NaiveRRC),
619629

620630
RemoveSubrangeTest(
621-
collection: [1010, 2020, 3030, 4040] as NaiveRRC),
631+
collection: [1010, 2020, 3030, 4040] as NaiveRRC,
622632
rangeSelection: .rightHalf,
623-
expected: [1010, 2020] as NaiveRRC)),
633+
expected: [1010, 2020] as NaiveRRC),
624634

625635
RemoveSubrangeTest(
626-
collection: [1010, 2020, 3030, 4040, 5050] as NaiveRRC),
636+
collection: [1010, 2020, 3030, 4040, 5050] as NaiveRRC,
627637
rangeSelection: .middle,
628-
expected: [1010, 5050] as NaiveRRC)),
638+
expected: [1010, 5050] as NaiveRRC),
629639

630640
RemoveSubrangeTest(
631-
collection: [1010, 2020, 3030, 4040, 5050, 6060] as NaiveRRC),
641+
collection: [1010, 2020, 3030, 4040, 5050, 6060] as NaiveRRC,
632642
rangeSelection: .leftHalf,
633-
expected: [4040, 5050, 6060] as NaiveRRC)),
643+
expected: [4040, 5050, 6060] as NaiveRRC),
634644

635645
RemoveSubrangeTest(
636-
collection: [1010, 2020, 3030, 4040, 5050, 6060] as NaiveRRC),
646+
collection: [1010, 2020, 3030, 4040, 5050, 6060] as NaiveRRC,
637647
rangeSelection: .rightHalf,
638-
expected: [1010, 2020, 3030] as NaiveRRC)),
648+
expected: [1010, 2020, 3030] as NaiveRRC),
639649

640650
RemoveSubrangeTest(
641-
collection: [1010, 2020, 3030, 4040, 5050, 6060] as NaiveRRC),
651+
collection: [1010, 2020, 3030, 4040, 5050, 6060] as NaiveRRC,
642652
rangeSelection: .middle,
643-
expected: [1010, 6060] as NaiveRRC)),
653+
expected: [1010, 6060] as NaiveRRC),
644654
]
645655

646656
extension TestSuite {

0 commit comments

Comments
 (0)