From 052950acc8771f194edb72786cf2c95de757b064 Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Mon, 12 Feb 2024 10:09:35 +0100 Subject: [PATCH] Add SwiftVersion.init(major:minor:) --- Sources/SPIManifest/SwiftVersion.swift | 6 +++++- Tests/SPIManifestTests/SwiftVersionTests.swift | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/SPIManifest/SwiftVersion.swift b/Sources/SPIManifest/SwiftVersion.swift index 302a478..c7062f7 100644 --- a/Sources/SPIManifest/SwiftVersion.swift +++ b/Sources/SPIManifest/SwiftVersion.swift @@ -19,9 +19,13 @@ public enum SwiftVersion: ShortVersion, Codable, CaseIterable { case v5_6 = "5.6" case v5_7 = "5.7" case v5_8 = "5.8" - case v5_9 = "5.9" // currently a pre-release version + case v5_9 = "5.9" public static var latestRelease: Self { .v5_9 } + + public init?(major: Int, minor: Int) { + self.init(rawValue: "\(major).\(minor)") + } } diff --git a/Tests/SPIManifestTests/SwiftVersionTests.swift b/Tests/SPIManifestTests/SwiftVersionTests.swift index 66ca257..e43b66b 100644 --- a/Tests/SPIManifestTests/SwiftVersionTests.swift +++ b/Tests/SPIManifestTests/SwiftVersionTests.swift @@ -18,6 +18,11 @@ import XCTest class SwiftVersionTests: XCTestCase { + func test_init() throws { + XCTAssertEqual(SwiftVersion(major: 5, minor: 9), .v5_9) + XCTAssertEqual(SwiftVersion(major: 5, minor: 5), nil) + } + func test_isLatestRelease() throws { XCTAssertEqual(SwiftVersion.v5_7.isLatestRelease, false) XCTAssertEqual(SwiftVersion.v5_8.isLatestRelease, false)