@@ -17,6 +17,38 @@ private import Foundation
17
17
// protocol for types that already support Codable.
18
18
@_spi ( Experimental)
19
19
extension Encodable where Self: Test . Attachable {
20
+ /// Encode this value into a buffer using either [`PropertyListEncoder`](https://developer.apple.com/documentation/foundation/propertylistencoder)
21
+ /// or [`JSONEncoder`](https://developer.apple.com/documentation/foundation/jsonencoder),
22
+ /// then call a function and pass that buffer to it.
23
+ ///
24
+ /// - Parameters:
25
+ /// - attachment: The attachment that is requesting a buffer (that is, the
26
+ /// attachment containing this instance.)
27
+ /// - body: A function to call. A temporary buffer containing a data
28
+ /// representation of this instance is passed to it.
29
+ ///
30
+ /// - Returns: Whatever is returned by `body`.
31
+ ///
32
+ /// - Throws: Whatever is thrown by `body`, or any error that prevented the
33
+ /// creation of the buffer.
34
+ ///
35
+ /// The testing library uses this function when writing an attachment to a
36
+ /// test report or to a file on disk. The encoding used depends on the path
37
+ /// extension specified by the value of `attachment`'s ``Testing/Test/Attachment/preferredName``
38
+ /// property:
39
+ ///
40
+ /// | Extension | Encoding Used | Encoder Used |
41
+ /// |-|-|-|
42
+ /// | `".xml"` | XML property list | [`PropertyListEncoder`](https://developer.apple.com/documentation/foundation/propertylistencoder) |
43
+ /// | `".plist"` | Binary property list | [`PropertyListEncoder`](https://developer.apple.com/documentation/foundation/propertylistencoder) |
44
+ /// | None, `".json"` | JSON | [`JSONEncoder`](https://developer.apple.com/documentation/foundation/jsonencoder) |
45
+ ///
46
+ /// OpenStep-style property lists are not supported.
47
+ ///
48
+ /// - Note: On Apple platforms, if the attachment's preferred name includes
49
+ /// some other path extension, that path extension must represent a type
50
+ /// that conforms to [`UTType.propertyList`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/propertylist)
51
+ /// or to [`UTType.json`](https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/json).
20
52
public func withUnsafeBufferPointer< R> ( for attachment: borrowing Test . Attachment , _ body: ( UnsafeRawBufferPointer ) throws -> R ) throws -> R {
21
53
let format = try EncodingFormat ( for: attachment)
22
54
0 commit comments