Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/SwiftlyCore/ToolchainVerison.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ struct StableReleaseParser: ToolchainSelectorParser {
}
}

/// Parser for selectors like the following:
/// Parser for selectors like the following (with optional "swift-" prefix):
/// - a.b-snapshot-YYYY-mm-dd
/// - a.b-snapshot
/// - a.b-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a
Expand All @@ -334,7 +334,7 @@ struct StableReleaseParser: ToolchainSelectorParser {
/// - a.b-SNAPSHOT
struct ReleaseSnapshotParser: ToolchainSelectorParser {
static let regex: Regex<(Substring, Substring, Substring, Substring?)> =
try! Regex("^([0-9]+)\\.([0-9]+)-(?:snapshot|DEVELOPMENT-SNAPSHOT|SNAPSHOT)(?:-([0-9]{4}-[0-9]{2}-[0-9]{2}))?(?:-a)?$")
try! Regex("^(?:swift-)?([0-9]+)\\.([0-9]+)-(?:snapshot|DEVELOPMENT-SNAPSHOT|SNAPSHOT)(?:-([0-9]{4}-[0-9]{2}-[0-9]{2}))?(?:-a)?$")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ease of implementation and maximum flexibility, I didn't bother creating separate regexes to only allow the prefix when using DEVELOPMENT-SNAPSHOT rather than the swiftly canonical name, so selectors like "swift-5.7-snapshot" are allowed.


func parse(_ input: String) throws -> ToolchainSelector? {
guard let match = try Self.regex.wholeMatch(in: input) else {
Expand Down
7 changes: 7 additions & 0 deletions Tests/SwiftlyTests/ToolchainSelectorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ final class ToolchainSelectorTests: SwiftlyTests {
"5.7-snapshot",
"5.7-SNAPSHOT",
"5.7-DEVELOPMENT-SNAPSHOT",
"swift-5.7-snapshot",
"swift-5.7-SNAPSHOT",
"swift-5.7-DEVELOPMENT-SNAPSHOT",
]
try runTest(.snapshot(branch: .release(major: 5, minor: 7), date: nil), parses)
}
Expand All @@ -53,6 +56,10 @@ final class ToolchainSelectorTests: SwiftlyTests {
"5.7-SNAPSHOT-2023-06-05",
"5.7-DEVELOPMENT-SNAPSHOT-2023-06-05",
"5.7-DEVELOPMENT-SNAPSHOT-2023-06-05-a",
"swift-5.7-snapshot-2023-06-05",
"swift-5.7-SNAPSHOT-2023-06-05",
"swift-5.7-DEVELOPMENT-SNAPSHOT-2023-06-05",
"swift-5.7-DEVELOPMENT-SNAPSHOT-2023-06-05-a",
]
try runTest(.snapshot(branch: .release(major: 5, minor: 7), date: "2023-06-05"), parses)
}
Expand Down