@@ -63,7 +63,7 @@ ${SelfName}TestSuite.test("AssociatedTypes") {
63
63
% if IsRaw:
64
64
iteratorType: ${SelfType}.Iterator.self,
65
65
% else:
66
- iteratorType: UnsafeBufferPointerIterator <Float>.self,
66
+ iteratorType: UnsafeBufferPointer <Float>.Iterator .self,
67
67
% end
68
68
subSequenceType: Slice<${SelfType}>.self,
69
69
indexType: Int.self,
@@ -361,6 +361,31 @@ UnsafeMutableBufferPointerTestSuite.test("withContiguous(Mutable)StorageIfAvaila
361
361
expectEqual(result1, result2)
362
362
}
363
363
364
+ UnsafeMutableBufferPointerTestSuite.test("Slice.withContiguousStorageIfAvailable") {
365
+ guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else {
366
+ return
367
+ }
368
+
369
+ for test in subscriptRangeTests {
370
+ let c = test.collection.map { MinimalEquatableValue($0.value) }
371
+ let buffer = UnsafeMutableBufferPointer<MinimalEquatableValue>.allocate(
372
+ capacity: test.collection.count)
373
+ var (it, idx) = buffer.initialize(from: c)
374
+ expectEqual(buffer.endIndex, idx)
375
+ expectNil(it.next())
376
+
377
+ let expected = test.expected.map { MinimalEquatableValue($0.value) }
378
+ let r1: Void? = buffer[test.bounds].withContiguousStorageIfAvailable { b in
379
+ expectTrue(expected.elementsEqual(b))
380
+ }
381
+ expectNotNil(r1)
382
+ let r2: Void? = buffer[test.bounds].withContiguousMutableStorageIfAvailable { b in
383
+ expectTrue(expected.elementsEqual(b))
384
+ }
385
+ expectNotNil(r2)
386
+ }
387
+ }
388
+
364
389
UnsafeMutableBufferPointerTestSuite.test("sort") {
365
390
var values = (0..<1000).map({ _ in Int.random(in: 0..<100) })
366
391
let sortedValues = values.sorted()
@@ -389,7 +414,7 @@ for testIndex in (0..<bufCount) {
389
414
% Type = 'Unsafe' + ('Mutable' if mutable else '') + ('Raw' if raw else '') + 'BufferPointer'
390
415
${Type}TestSuite.test("${action}Element\(testIndex)ViaSlice") {
391
416
% if raw:
392
- let allocated = UnsafeMutableRawPointer.allocate(bytes : bufCount, alignedTo : 8)
417
+ let allocated = UnsafeMutableRawPointer.allocate(byteCount : bufCount, alignment : 8)
393
418
for i in 0..<bufCount {
394
419
allocated.storeBytes(of: UInt8(i), toByteOffset: i, as: UInt8.self)
395
420
}
@@ -400,7 +425,7 @@ for testIndex in (0..<bufCount) {
400
425
defer { allocated.deallocate() }
401
426
402
427
let buffer = ${Type}(start: allocated, count: bufCount)
403
- ${'var' if mutable else 'let'} slice = buffer[sliceRange]
428
+ ${'var' if mutable and action <> 'read' else 'let'} slice = buffer[sliceRange]
404
429
405
430
if _isDebugAssertConfiguration(),
406
431
testIndex < sliceRange.lowerBound ||
@@ -430,7 +455,7 @@ for testRange in testRanges {
430
455
% Type = 'Unsafe' + ('Mutable' if mutable else '') + ('Raw' if raw else '') + 'BufferPointer'
431
456
${Type}TestSuite.test("${action}Slice\(testRange)ViaSlice") {
432
457
% if raw:
433
- let allocated = UnsafeMutableRawPointer.allocate(bytes : bufCount+2, alignedTo : 8)
458
+ let allocated = UnsafeMutableRawPointer.allocate(byteCount : bufCount+2, alignment : 8)
434
459
for i in 0..<bufCount+2 {
435
460
allocated.storeBytes(of: UInt8(i), toByteOffset: i, as: UInt8.self)
436
461
}
@@ -441,7 +466,7 @@ for testRange in testRanges {
441
466
defer { allocated.deallocate() }
442
467
443
468
let buffer = ${Type}(start: allocated, count: bufCount+2)
444
- ${'var' if mutable else 'let'} slice = buffer[sliceRange]
469
+ ${'var' if mutable and action <> 'read' else 'let'} slice = buffer[sliceRange]
445
470
446
471
if _isDebugAssertConfiguration(),
447
472
testRange.lowerBound < sliceRange.lowerBound ||
@@ -937,7 +962,7 @@ UnsafeMutable${'Raw' if IsRaw else ''}BufferPointerTestSuite.test("subscript/${R
937
962
938
963
UnsafeMutable${'Raw' if IsRaw else ''}BufferPointerTestSuite.test("subscript/set/overlaps") {
939
964
% if IsRaw:
940
- let buffer = UnsafeMutableRawBufferPointer.allocate(count : 4)
965
+ let buffer = UnsafeMutableRawBufferPointer.allocate(byteCount : 4, alignment: 1 )
941
966
% else:
942
967
let buffer = UnsafeMutableBufferPointer<Int>.allocate(capacity: 4)
943
968
% end
@@ -970,7 +995,7 @@ UnsafeMutable${'Raw' if IsRaw else ''}BufferPointerTestSuite.test("subscript/set
970
995
971
996
UnsafeMutable${'Raw' if IsRaw else ''}BufferPointerTestSuite.test("nonmutating-swapAt") {
972
997
% if IsRaw:
973
- let allocated = UnsafeMutableRawPointer.allocate(bytes : 4, alignedTo : 8)
998
+ let allocated = UnsafeMutableRawPointer.allocate(byteCount : 4, alignment : 8)
974
999
let buffer = UnsafeMutableRawBufferPointer(start: allocated, count: 3)
975
1000
allocated.storeBytes(of: UInt8.max, toByteOffset: 3, as: UInt8.self)
976
1001
% else:
0 commit comments