mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Support wildcard Swift versions
This commit is contained in:
@@ -103,9 +103,7 @@ public struct Version: RawRepresentable, Comparable, ExpressibleByStringLiteral,
|
||||
|
||||
public init?(rawValue: String) {
|
||||
let rawValue = rawValue.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !rawValue.components(separatedBy: ".").contains(where: {
|
||||
!CharacterSet.decimalDigits.contains($0.unicodeScalars.first ?? " ")
|
||||
}) else {
|
||||
guard CharacterSet.decimalDigits.contains(rawValue.unicodeScalars.first ?? " ") else {
|
||||
return nil
|
||||
}
|
||||
self.rawValue = rawValue
|
||||
|
||||
@@ -50,4 +50,11 @@ class VersionTests: XCTestCase {
|
||||
XCTAssertLessThan(version ?? "0", "4.0")
|
||||
XCTAssertGreaterThan(version ?? "0", "2.0")
|
||||
}
|
||||
|
||||
func testWildcardVersion() throws {
|
||||
let version = Version(rawValue: "3.x")
|
||||
XCTAssertNotNil(version)
|
||||
XCTAssertLessThan(version ?? "0", "4.0")
|
||||
XCTAssertGreaterThan(version ?? "0", "2.0")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2173,6 +2173,7 @@ extension VersionTests {
|
||||
("testParsePreviewVersion", testParsePreviewVersion),
|
||||
("testParseThreePartVersion", testParseThreePartVersion),
|
||||
("testPreviewComparison", testPreviewComparison),
|
||||
("testWildcardVersion", testWildcardVersion),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user