@@ -188,9 +188,9 @@ class Missile {
188
188
}
189
189
190
190
func checkPointerCorrectness(_ check: Check,
191
+ _ withMissiles: Bool = false,
191
192
_ f: (UnsafeMutablePointer<Missile>) ->
192
- (UnsafeMutablePointer<Missile>, count: Int) -> Void,
193
- _ withMissiles: Bool = false) {
193
+ (UnsafeMutablePointer<Missile>, count: Int) -> Void) {
194
194
let ptr = UnsafeMutablePointer<Missile>(allocatingCapacity: 4)
195
195
switch check {
196
196
case .RightOverlap:
@@ -235,9 +235,23 @@ func checkPointerCorrectness(_ check: Check,
235
235
}
236
236
}
237
237
238
- let checkPtr: (((UnsafeMutablePointer<Missile>) ->
239
- (UnsafeMutablePointer<Missile>, count: Int) -> Void), Bool) -> (Check) -> Void
240
- = { (f, m) in return { checkPointerCorrectness($0, f, m) } }
238
+ func checkPtr(
239
+ _ f: ((UnsafeMutablePointer<Missile>) -> (UnsafeMutablePointer<Missile>, count: Int) -> Void),
240
+ _ m: Bool
241
+ ) -> (Check) -> Void {
242
+ return { checkPointerCorrectness($0, m, f) }
243
+ }
244
+
245
+ func checkPtr(
246
+ _ f: ((UnsafeMutablePointer<Missile>) -> (UnsafePointer<Missile>, count: Int) -> Void),
247
+ _ m: Bool
248
+ ) -> (Check) -> Void {
249
+ return {
250
+ checkPointerCorrectness($0, m) { destPtr in
251
+ return { f(destPtr)(UnsafeMutablePointer($0), count: $1) }
252
+ }
253
+ }
254
+ }
241
255
242
256
UnsafeMutablePointerTestSuite.test("moveInitializeBackwardFrom") {
243
257
let check = checkPtr(UnsafeMutablePointer.moveInitializeBackwardFrom, false)
@@ -322,6 +336,41 @@ UnsafeMutablePointerTestSuite.test("initializeFrom.Right") {
322
336
}
323
337
}
324
338
339
+ UnsafeMutablePointerTestSuite.test("initializeFrom/immutable") {
340
+ var ptr = UnsafeMutablePointer<Missile>(allocatingCapacity: 3)
341
+ defer {
342
+ ptr.deinitialize(count: 3)
343
+ ptr.deallocateCapacity(3)
344
+ }
345
+ let source = (0..<3).map(Missile.init)
346
+ source.withUnsafeBufferPointer { bufferPtr in
347
+ ptr.initializeFrom(bufferPtr.baseAddress!, count: 3)
348
+ expectEqual(0, ptr[0].number)
349
+ expectEqual(1, ptr[1].number)
350
+ expectEqual(2, ptr[2].number)
351
+ }
352
+ }
353
+
354
+ % for assign in ['assignFrom', 'assignBackwardFrom']:
355
+
356
+ UnsafeMutablePointerTestSuite.test("${assign}/immutable") {
357
+ var ptr = UnsafeMutablePointer<Missile>(allocatingCapacity: 2)
358
+ defer {
359
+ ptr.deinitialize(count: 2)
360
+ ptr.deallocateCapacity(2)
361
+ }
362
+ ptr.initialize(with: Missile(1))
363
+ (ptr + 1).initialize(with: Missile(2))
364
+ let source = (3..<5).map(Missile.init)
365
+ source.withUnsafeBufferPointer { bufferPtr in
366
+ ptr.${assign}(bufferPtr.baseAddress!, count: 2)
367
+ expectEqual(3, ptr[0].number)
368
+ expectEqual(4, ptr[1].number)
369
+ }
370
+ }
371
+
372
+ % end
373
+
325
374
UnsafePointerTestSuite.test("customMirror") {
326
375
// Ensure that the custom mirror works properly, including when the raw value
327
376
// is greater than Int.max
0 commit comments