Skip to content

Commit a302bf0

Browse files
Merge pull request #2 from SwiftPackageIndex/support-swift-4.2
Support swift 4.2, 5.0, 5.1
2 parents 5bc3ff6 + f37bd4f commit a302bf0

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.2
1+
// swift-tools-version:4.2
22

33
import PackageDescription
44

Sources/SemanticVersion/SemanticVersion.swift

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension SemanticVersion: LosslessStringConvertible {
3939

4040

4141
extension SemanticVersion: Comparable {
42-
public static func < (lhs: Self, rhs: Self) -> Bool {
42+
public static func < (lhs: SemanticVersion, rhs: SemanticVersion) -> Bool {
4343
if lhs.major != rhs.major { return lhs.major < rhs.major }
4444
if lhs.minor != rhs.minor { return lhs.minor < rhs.minor }
4545
if lhs.patch != rhs.patch { return lhs.patch < rhs.patch }
@@ -57,17 +57,19 @@ extension SemanticVersion: Comparable {
5757

5858

5959
extension SemanticVersion {
60-
public var isStable: Bool { preRelease.isEmpty && build.isEmpty }
61-
public var isPreRelease: Bool { !isStable }
62-
public var isMajorRelease: Bool { isStable && (major > 0 && minor == 0 && patch == 0) }
63-
public var isMinorRelease: Bool { isStable && (minor > 0 && patch == 0) }
64-
public var isPatchRelease: Bool { isStable && patch > 0 }
65-
public var isInitialRelease: Bool { self == .init(0, 0, 0) }
60+
public var isStable: Bool { return preRelease.isEmpty && build.isEmpty }
61+
public var isPreRelease: Bool { return !isStable }
62+
public var isMajorRelease: Bool { return isStable && (major > 0 && minor == 0 && patch == 0) }
63+
public var isMinorRelease: Bool { return isStable && (minor > 0 && patch == 0) }
64+
public var isPatchRelease: Bool { return isStable && patch > 0 }
65+
public var isInitialRelease: Bool { return self == .init(0, 0, 0) }
6666
}
6767

6868

6969
// Source: https://regex101.com/r/Ly7O1x/3/
7070
// Linked from https://semver.org
71+
#if swift(>=5)
72+
7173
let semVerRegex = NSRegularExpression(#"""
7274
^
7375
v? # SPI extension: allow leading 'v'
@@ -91,3 +93,31 @@ v? # SPI extension: allow leading 'v'
9193
)?
9294
$
9395
"""#, options: [.allowCommentsAndWhitespace])
96+
97+
#else
98+
99+
let semVerRegex = NSRegularExpression("""
100+
^
101+
v? # SPI extension: allow leading 'v'
102+
(?<major>0|[1-9]\\d*)
103+
\\.
104+
(?<minor>0|[1-9]\\d*)
105+
\\.
106+
(?<patch>0|[1-9]\\d*)
107+
(?:-
108+
(?<prerelease>
109+
(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)
110+
(?:\\.
111+
(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)
112+
)
113+
*)
114+
)?
115+
(?:\\+
116+
(?<buildmetadata>[0-9a-zA-Z-]+
117+
(?:\\.[0-9a-zA-Z-]+)
118+
*)
119+
)?
120+
$
121+
""", options: [.allowCommentsAndWhitespace])
122+
123+
#endif

Tests/LinuxMain.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#if swift(>=5)
2+
3+
#else
4+
5+
import XCTest
6+
7+
@testable import SemanticVersionTests
8+
9+
extension SemanticVersionTests {
10+
static var allTests: [(String, (SemanticVersionTests) -> () throws -> Void)] = [
11+
("test_semVerRegex_valid", test_semVerRegex_valid),
12+
("test_allow_leading_v", test_allow_leading_v),
13+
("test_semVerRegex_invalid", test_semVerRegex_invalid),
14+
("test_init", test_init),
15+
("test_description", test_description),
16+
("test_Comparable", test_Comparable),
17+
("test_isStable", test_isStable),
18+
("test_isMajorRelease", test_isMajorRelease),
19+
("test_isMinorRelease", test_isMinorRelease),
20+
("test_isPatchRelease", test_isPatchRelease),
21+
]
22+
}
23+
24+
XCTMain([
25+
testCase(SemanticVersionTests.allTests)
26+
])
27+
28+
#endif

0 commit comments

Comments
 (0)