Skip to content

Commit f37bd4f

Browse files
committed
Fix 4.2 compile and support running tests
1 parent 6d4fda6 commit f37bd4f

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

Sources/SemanticVersion/SemanticVersion.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ extension SemanticVersion {
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1-
//
2-
// File.swift
3-
//
4-
//
5-
// Created by Sven A. Schmidt on 01/09/2020.
6-
//
7-
8-
import Foundation
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)