Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The actual selection code already worked (except for the x/mod parser not reading the file), so all that is necessary is a test. For the test, move the version check up before the module line presence check. For #57001. Change-Id: Iaa4f9b92d38fcfd99dc1665ec8d3eb0e52007bb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/497555 TryBot-Bypass: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
- Loading branch information
Showing
6 changed files
with
136 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package gover | ||
|
||
import "strings" | ||
|
||
// ToolchainVersion returns the Go version for the named toolchain, | ||
// derived from the name itself (not by running the toolchain). | ||
// A toolchain is named "goVERSION" or "anything-goVERSION". | ||
// Examples: | ||
// | ||
// ToolchainVersion("go1.2.3") == "1.2.3" | ||
// ToolchainVersion("gccgo-go1.23rc4") == "1.23rc4" | ||
// ToolchainVersion("invalid") == "" | ||
func ToolchainVersion(name string) string { | ||
var v string | ||
if strings.HasPrefix(name, "go") && IsValid(name[2:]) { | ||
v = name[2:] | ||
} else if i := strings.Index(name, "-go"); i >= 0 && IsValid(name[i+3:]) { | ||
v = name[i+3:] | ||
} | ||
return v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters