Skip to content

Commit ed14512

Browse files
committed
Add mutable buffer conformances
1 parent 427ff78 commit ed14512

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Sources/Testing/Attachments/Test.Attachable.swift

+14
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,27 @@ extension UnsafeBufferPointer<UInt8>: Test.Attachable {
104104
}
105105
}
106106

107+
@_spi(Experimental)
108+
extension UnsafeMutableBufferPointer<UInt8>: Test.Attachable {
109+
public func withUnsafeBufferPointer<R>(for attachment: borrowing Test.Attachment, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
110+
try body(.init(self))
111+
}
112+
}
113+
107114
@_spi(Experimental)
108115
extension UnsafeRawBufferPointer: Test.Attachable {
109116
public func withUnsafeBufferPointer<R>(for attachment: borrowing Test.Attachment, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
110117
try body(self)
111118
}
112119
}
113120

121+
@_spi(Experimental)
122+
extension UnsafeMutableRawBufferPointer: Test.Attachable {
123+
public func withUnsafeBufferPointer<R>(for attachment: borrowing Test.Attachment, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
124+
try body(.init(self))
125+
}
126+
}
127+
114128
@_spi(Experimental)
115129
extension String: Test.Attachable {
116130
public func withUnsafeBufferPointer<R>(for attachment: borrowing Test.Attachment, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {

Tests/TestingTests/AttachmentTests.swift

+14
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,27 @@ extension AttachmentTests {
201201
}
202202
}
203203

204+
@Test func uint8UnsafeMutableBufferPointer() throws {
205+
var value: [UInt8] = Array("abc123".utf8)
206+
try value.withUnsafeMutableBufferPointer { value in
207+
try test(value)
208+
}
209+
}
210+
204211
@Test func unsafeRawBufferPointer() throws {
205212
let value: [UInt8] = Array("abc123".utf8)
206213
try value.withUnsafeBytes { value in
207214
try test(value)
208215
}
209216
}
210217

218+
@Test func unsafeMutableRawBufferPointer() throws {
219+
var value: [UInt8] = Array("abc123".utf8)
220+
try value.withUnsafeMutableBytes { value in
221+
try test(value)
222+
}
223+
}
224+
211225
@Test func string() throws {
212226
let value = "abc123"
213227
try test(value)

0 commit comments

Comments
 (0)