Skip to content

Commit 72f4e65

Browse files
committed
[test] assumingMemoryBound on raw memory buffers
1 parent 9f2c4b5 commit 72f4e65

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

validation-test/stdlib/UnsafeBufferPointer.swift.gyb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,4 +1099,20 @@ Unsafe${'Mutable' if mutable else ''}RawBufferPointerTestSuite.test("withMemoryR
10991099

11001100
% end # mutable
11011101

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+
11021118
runAllTests()

0 commit comments

Comments
 (0)