|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 |
| -public struct InstalledSwiftPMConfiguration: Codable { |
| 13 | +public struct InstalledSwiftPMConfiguration { |
14 | 14 | public struct Version: Codable, CustomStringConvertible {
|
15 | 15 | let major: Int
|
16 | 16 | let minor: Int
|
@@ -42,12 +42,55 @@ public struct InstalledSwiftPMConfiguration: Codable {
|
42 | 42 | patch: 0,
|
43 | 43 | prereleaseIdentifier: "latest"
|
44 | 44 | ),
|
45 |
| - swiftTestingVersionForTestTemplate: .init( |
46 |
| - major: 0, |
47 |
| - minor: 7, |
48 |
| - patch: 0, |
49 |
| - prereleaseIdentifier: nil |
50 |
| - ) |
| 45 | + swiftTestingVersionForTestTemplate: defaultSwiftTestingVersionForTestTemplate |
| 46 | + ) |
| 47 | + } |
| 48 | + |
| 49 | + private static var defaultSwiftTestingVersionForTestTemplate: Version { |
| 50 | + .init( |
| 51 | + major: 0, |
| 52 | + minor: 7, |
| 53 | + patch: 0, |
| 54 | + prereleaseIdentifier: nil |
| 55 | + ) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +extension InstalledSwiftPMConfiguration: Codable { |
| 60 | + enum CodingKeys: CodingKey { |
| 61 | + case version |
| 62 | + case swiftSyntaxVersionForMacroTemplate |
| 63 | + case swiftTestingVersionForTestTemplate |
| 64 | + } |
| 65 | + |
| 66 | + public init(from decoder: any Decoder) throws { |
| 67 | + let container = try decoder.container(keyedBy: CodingKeys.self) |
| 68 | + |
| 69 | + self.version = try container.decode( |
| 70 | + Int.self, |
| 71 | + forKey: CodingKeys.version |
| 72 | + ) |
| 73 | + self.swiftSyntaxVersionForMacroTemplate = try container.decode( |
| 74 | + Version.self, |
| 75 | + forKey: CodingKeys.swiftSyntaxVersionForMacroTemplate |
51 | 76 | )
|
| 77 | + self.swiftTestingVersionForTestTemplate = try container.decodeIfPresent( |
| 78 | + Version.self, |
| 79 | + forKey: CodingKeys.swiftTestingVersionForTestTemplate |
| 80 | + ) ?? InstalledSwiftPMConfiguration.defaultSwiftTestingVersionForTestTemplate |
52 | 81 | }
|
| 82 | + |
| 83 | + public func encode(to encoder: any Encoder) throws { |
| 84 | + var container = encoder.container(keyedBy: CodingKeys.self) |
| 85 | + |
| 86 | + try container.encode(self.version, forKey: CodingKeys.version) |
| 87 | + try container.encode( |
| 88 | + self.swiftSyntaxVersionForMacroTemplate, |
| 89 | + forKey: CodingKeys.swiftSyntaxVersionForMacroTemplate |
| 90 | + ) |
| 91 | + try container.encode( |
| 92 | + self.swiftTestingVersionForTestTemplate, |
| 93 | + forKey: CodingKeys.swiftTestingVersionForTestTemplate |
| 94 | + ) |
| 95 | + } |
53 | 96 | }
|
0 commit comments