@@ -56,25 +56,6 @@ LazyTestSuite.test("Repeated") {
56
56
57
57
// FIXME: trap tests.
58
58
59
- //===----------------------------------------------------------------------===//
60
- // CollectionOfOne
61
- //===----------------------------------------------------------------------===//
62
-
63
- // Check that the generic parameter is called 'Element'.
64
- extension CollectionOfOne where Element : TestProtocol1 {
65
- var _elementIsTestProtocol1: Bool {
66
- fatalError("not implemented")
67
- }
68
- }
69
-
70
- LazyTestSuite.test("CollectionOfOne") {
71
- checkRandomAccessCollection(
72
- [ OpaqueValue(42) ],
73
- CollectionOfOne(OpaqueValue(42))) { $0.value == $1.value }
74
- }
75
-
76
- // FIXME: trap tests.
77
-
78
59
//===----------------------------------------------------------------------===//
79
60
// IteratorOverOne
80
61
//===----------------------------------------------------------------------===//
@@ -98,6 +79,111 @@ LazyTestSuite.test("IteratorOverOne") {
98
79
{ $0.value == $1.value }
99
80
}
100
81
82
+ //===----------------------------------------------------------------------===//
83
+ // ColectionOfOne
84
+ //===----------------------------------------------------------------------===//
85
+
86
+ // Check that the generic parameter is called 'Element'.
87
+ extension CollectionOfOne where Element : TestProtocol1 {
88
+ var _elementIsTestProtocol1: Bool {
89
+ fatalError("not implemented")
90
+ }
91
+ }
92
+
93
+ LazyTestSuite.test("CollectionOfOne") {
94
+ let c = CollectionOfOne(OpaqueValue(42))
95
+ expectEqual(0, c.startIndex)
96
+ expectEqual(1, c.endIndex)
97
+ expectEqual(0..<1, c.indices)
98
+
99
+ checkRandomAccessCollection(
100
+ [ OpaqueValue(42) ], c) { $0.value == $1.value }
101
+ }
102
+
103
+ LazyTestSuite.test("CollectionOfOne/AssociatedTypes") {
104
+ typealias Subject = CollectionOfOne<OpaqueValue<Int>>
105
+ expectRandomAccessCollectionAssociatedTypes(
106
+ collectionType: Subject.self,
107
+ iteratorType: IteratorOverOne<OpaqueValue<Int>>.self,
108
+ subSequenceType: MutableRandomAccessSlice<Subject>.self,
109
+ indexType: Int.self,
110
+ indexDistanceType: Int.self,
111
+ indicesType: CountableRange<Int>.self)
112
+ }
113
+
114
+ % for (name, operation, indices) in [
115
+ % ('index(after:)', '_ = c.index(after: i)', '-2, -1, 1, 2'),
116
+ % ('index(before:)', '_ = c.index(before: i)', '-1, 0, 2'),
117
+ % ('subscript(Index)/Get', '_ = c[i]', '-2, -1, 1, 2'),
118
+ % ('subscript(Index)/Set', 'c[i] = OpaqueValue(42)', '-2, -1, 1, 2'),
119
+ % ]:
120
+ LazyTestSuite.test("CollectionOfOne/${name}")
121
+ .forEach(in: [${indices}]) {
122
+ i in
123
+
124
+ var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
125
+ expectCrashLater()
126
+ ${operation}
127
+ }
128
+ % end
129
+
130
+ LazyTestSuite.test("CollectionOfOne/subscript(Index)/Get/Set/Empty/NoTrap") {
131
+ var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
132
+ c[0] = OpaqueValue(4242)
133
+ expectEqual(4242, c[0].value)
134
+ expectEqualSequence([OpaqueValue(4242)], c) { $0.value == $1.value }
135
+ }
136
+
137
+ % for (name, operation) in [
138
+ % ('subscript(Range<Index>)/Get', '_ = c[r]'),
139
+ % ('subscript(Range<Index>)/Set', 'c[r] = slice'),
140
+ % ]:
141
+ LazyTestSuite.test("CollectionOfOne/${name}/Trap")
142
+ .forEach(in: [
143
+ -1 ..< -1, -1..<0, -1..<1, 1..<2, 2..<2,
144
+ ] as [Range<Int>]) {
145
+ r in
146
+ var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
147
+ let slice = r.count == 0 ? c[0..<0] : c[0..<1]
148
+ expectCrashLater()
149
+ ${operation}
150
+ }
151
+ % end
152
+
153
+ LazyTestSuite.test("CollectionOfOne/subscript(Range<Index>)/Set/DifferentLength/Trap")
154
+ .forEach(in: [ 0..<0, 0..<1, 1..<1 ] as [Range<Int>]) {
155
+ r in
156
+ var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
157
+ let slice = r.count == 0 ? c[0..<1] : c[0..<0]
158
+ expectCrashLater()
159
+ c[r] = slice
160
+ }
161
+
162
+ LazyTestSuite.test("CollectionOfOne/subscript(Range<Index>)/Get/Set/Empty/NoTrap") {
163
+ var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
164
+ let slice0 = c[0..<0]
165
+ let slice1 = c[1..<1]
166
+ checkRandomAccessCollection([], slice0) { $0.value == $1.value }
167
+ checkRandomAccessCollection([], slice1) { $0.value == $1.value }
168
+ c[0..<0] = slice0
169
+ c[0..<0] = slice1
170
+ c[1..<1] = slice0
171
+ c[1..<1] = slice1
172
+ expectEqualSequence([OpaqueValue(42)], c) { $0.value == $1.value }
173
+ }
174
+
175
+ LazyTestSuite.test("CollectionOfOne/{CustomDebugStringConvertible,CustomReflectable}") {
176
+ let c = CollectionOfOne(CustomPrintableValue(42))
177
+ expectPrinted("CollectionOfOne((value: 42).debugDescription)", c)
178
+ expectDebugPrinted("CollectionOfOne((value: 42).debugDescription)", c)
179
+ expectDumped(
180
+ "▿ CollectionOfOne((value: 42).debugDescription)\n" +
181
+ " ▿ element: (value: 42).debugDescription\n" +
182
+ " - value: 42\n" +
183
+ " - identity: 0\n",
184
+ c)
185
+ }
186
+
101
187
//===----------------------------------------------------------------------===//
102
188
// EmptyCollection
103
189
//===----------------------------------------------------------------------===//
@@ -118,6 +204,15 @@ LazyTestSuite.test("EmptyCollection") {
118
204
checkRandomAccessCollection([], c) { $0.value == $1.value }
119
205
}
120
206
207
+ LazyTestSuite.test("EmptyCollection/CustomReflectable") {
208
+ let c = EmptyCollection<OpaqueValue<Int>>()
209
+ expectPrinted("EmptyCollection<OpaqueValue<Int>>()", c)
210
+ expectDebugPrinted("Swift.EmptyCollection<StdlibUnittest.OpaqueValue<Swift.Int>>()", c)
211
+ expectDumped(
212
+ "- Swift.EmptyCollection<StdlibUnittest.OpaqueValue<Swift.Int>>\n",
213
+ c)
214
+ }
215
+
121
216
LazyTestSuite.test("EmptyCollection/Equatable") {
122
217
let instances = [ EmptyCollection<OpaqueValue<Int>>() ]
123
218
checkEquatable(instances, oracle: { $0 == $1 })
0 commit comments