File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -1099,4 +1099,20 @@ Unsafe${'Mutable' if mutable else ''}RawBufferPointerTestSuite.test("withMemoryR
1099
1099
1100
1100
% end # mutable
1101
1101
1102
+ UnsafeRawBufferPointerTestSuite.test("assumingMemoryBound") {
1103
+ let array = (0..<4).map({ $0 })
1104
+ array.withUnsafeBytes({
1105
+ let b: UnsafeBufferPointer = $0.assumingMemoryBound(to: Int.self)
1106
+ expectEqual(b.count, array.count)
1107
+ expectEqual(b[3], array[3])
1108
+ })
1109
+ var mutableArray = array
1110
+ mutableArray.withUnsafeMutableBytes({
1111
+ let b: UnsafeMutableBufferPointer = $0.assumingMemoryBound(to: Int.self)
1112
+ expectEqual(b.count, array.count)
1113
+ for i in b.indices { b[i] += 1 }
1114
+ })
1115
+ expectEqual(mutableArray[3], array[3]+1)
1116
+ }
1117
+
1102
1118
runAllTests()
You can’t perform that action at this time.
0 commit comments