Skip to content

Commit 16b94cb

Browse files
Make "swift-" prefix optional in MainSnapshotParser
Existing tools like `swiftenv` use `DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a` for main snapshots, without the `swift-` prefix. The `MainSnapshotParser` should be able to handle this and this change mirrors the `ReleaseSnapshotParser` in this regard, which already supports both `swift-` prefixed and unprefixed versions.
1 parent 7b773c7 commit 16b94cb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Sources/SwiftlyCore/ToolchainVersion.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,17 @@ struct ReleaseSnapshotParser: ToolchainSelectorParser {
411411
}
412412
}
413413

414-
/// Parser for selectors like the following:
414+
/// Parser for selectors like the following (with optional "swift-" prefix):
415415
/// - main-snapshot-YYYY-mm-dd
416416
/// - main-snapshot
417417
/// - main-SNAPSHOT-YYYY-mm-dd
418418
/// - main-SNAPSHOT
419-
/// - swift-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a
420-
/// - swift-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd
421-
/// - swift-DEVELOPMENT-SNAPSHOT
419+
/// - DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a
420+
/// - DEVELOPMENT-SNAPSHOT-YYYY-mm-dd
421+
/// - DEVELOPMENT-SNAPSHOT
422422
struct MainSnapshotParser: ToolchainSelectorParser {
423423
static let regex: Regex<(Substring, Substring?)> =
424-
try! Regex("^(?:main-snapshot|swift-DEVELOPMENT-SNAPSHOT|main-SNAPSHOT)(?:-([0-9]{4}-[0-9]{2}-[0-9]{2}))?(?:-a)?$")
424+
try! Regex("^(?:swift-)?(?:main-snapshot|DEVELOPMENT-SNAPSHOT|main-SNAPSHOT)(?:-([0-9]{4}-[0-9]{2}-[0-9]{2}))?(?:-a)?$")
425425

426426
func parse(_ input: String) throws -> ToolchainSelector? {
427427
guard let match = try Self.regex.wholeMatch(in: input) else {

Tests/SwiftlyTests/ToolchainSelectorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final class ToolchainSelectorTests: SwiftlyTests {
3434
"main-SNAPSHOT-2023-06-05",
3535
"swift-DEVELOPMENT-SNAPSHOT-2023-06-05",
3636
"swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a",
37+
"DEVELOPMENT-SNAPSHOT-2023-06-05-a",
3738
]
3839
try runTest(.snapshot(branch: .main, date: "2023-06-05"), parses)
3940
}

0 commit comments

Comments
 (0)