Files
swift-mirror/test/refactoring/AddCodableImplementation/Outputs/enum/encodable.swift.expected
Allan Shortlidge 8079d9cf45 AST: Fix whitespace for switch statements under -print-ast.
No test changes because the tests for `-print-ast` don't match whitespace.
2023-07-31 21:27:46 -07:00

44 lines
1.1 KiB
Plaintext

enum Payload: Codable {
case plain(String)
case pair(key: String, value: String)
}
enum Payload_D: Decodable {
case plain(String)
case pair(key: String, value: String)
}
enum Payload_E: Encodable {
case plain(String)
case pair(key: String, value: String)
enum CodingKeys: CodingKey {
case plain
case pair
}
enum PlainCodingKeys: CodingKey {
case _0
}
enum PairCodingKeys: CodingKey {
case key
case value
}
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: Payload_E.CodingKeys.self)
switch self {
case .plain(let a0):
var nestedContainer = container.nestedContainer(keyedBy: Payload_E.PlainCodingKeys.self, forKey: Payload_E.CodingKeys.plain)
try nestedContainer.encode(a0, forKey: Payload_E.PlainCodingKeys._0)
case .pair(let key, let value):
var nestedContainer = container.nestedContainer(keyedBy: Payload_E.PairCodingKeys.self, forKey: Payload_E.CodingKeys.pair)
try nestedContainer.encode(key, forKey: Payload_E.PairCodingKeys.key)
try nestedContainer.encode(value, forKey: Payload_E.PairCodingKeys.value)
}
}
}