diff --git a/Package.swift b/Package.swift index f185f76..01e2267 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.2 +// swift-tools-version:4.2 import PackageDescription diff --git a/Sources/SemanticVersion/SemanticVersion.swift b/Sources/SemanticVersion/SemanticVersion.swift index 9b2289e..f53daae 100644 --- a/Sources/SemanticVersion/SemanticVersion.swift +++ b/Sources/SemanticVersion/SemanticVersion.swift @@ -39,7 +39,7 @@ extension SemanticVersion: LosslessStringConvertible { extension SemanticVersion: Comparable { - public static func < (lhs: Self, rhs: Self) -> Bool { + public static func < (lhs: SemanticVersion, rhs: SemanticVersion) -> Bool { if lhs.major != rhs.major { return lhs.major < rhs.major } if lhs.minor != rhs.minor { return lhs.minor < rhs.minor } if lhs.patch != rhs.patch { return lhs.patch < rhs.patch } @@ -57,17 +57,19 @@ extension SemanticVersion: Comparable { extension SemanticVersion { - public var isStable: Bool { preRelease.isEmpty && build.isEmpty } - public var isPreRelease: Bool { !isStable } - public var isMajorRelease: Bool { isStable && (major > 0 && minor == 0 && patch == 0) } - public var isMinorRelease: Bool { isStable && (minor > 0 && patch == 0) } - public var isPatchRelease: Bool { isStable && patch > 0 } - public var isInitialRelease: Bool { self == .init(0, 0, 0) } + public var isStable: Bool { return preRelease.isEmpty && build.isEmpty } + public var isPreRelease: Bool { return !isStable } + public var isMajorRelease: Bool { return isStable && (major > 0 && minor == 0 && patch == 0) } + public var isMinorRelease: Bool { return isStable && (minor > 0 && patch == 0) } + public var isPatchRelease: Bool { return isStable && patch > 0 } + public var isInitialRelease: Bool { return self == .init(0, 0, 0) } } // Source: https://regex101.com/r/Ly7O1x/3/ // Linked from https://semver.org +#if swift(>=5) + let semVerRegex = NSRegularExpression(#""" ^ v? # SPI extension: allow leading 'v' @@ -91,3 +93,31 @@ v? # SPI extension: allow leading 'v' )? $ """#, options: [.allowCommentsAndWhitespace]) + +#else + +let semVerRegex = NSRegularExpression(""" +^ +v? # SPI extension: allow leading 'v' +(?0|[1-9]\\d*) +\\. +(?0|[1-9]\\d*) +\\. +(?0|[1-9]\\d*) +(?:- + (? + (?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*) + (?:\\. + (?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*) + ) + *) +)? +(?:\\+ + (?[0-9a-zA-Z-]+ + (?:\\.[0-9a-zA-Z-]+) + *) +)? +$ +""", options: [.allowCommentsAndWhitespace]) + +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..4a04bfd --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,28 @@ +#if swift(>=5) + +#else + +import XCTest + +@testable import SemanticVersionTests + +extension SemanticVersionTests { + static var allTests: [(String, (SemanticVersionTests) -> () throws -> Void)] = [ + ("test_semVerRegex_valid", test_semVerRegex_valid), + ("test_allow_leading_v", test_allow_leading_v), + ("test_semVerRegex_invalid", test_semVerRegex_invalid), + ("test_init", test_init), + ("test_description", test_description), + ("test_Comparable", test_Comparable), + ("test_isStable", test_isStable), + ("test_isMajorRelease", test_isMajorRelease), + ("test_isMinorRelease", test_isMinorRelease), + ("test_isPatchRelease", test_isPatchRelease), + ] +} + +XCTMain([ + testCase(SemanticVersionTests.allTests) +]) + +#endif