Browse Source

goenv: remove WantGoVersion

pull/4501/head
Randy Reddig 3 weeks ago
parent
commit
7f96e9f47a
Failed to extract signature
  1. 10
      goenv/version.go
  2. 30
      goenv/version_test.go

10
goenv/version.go

@ -68,16 +68,6 @@ func Parse(version string) (major, minor, patch int, err error) {
return major, minor, patch, nil
}
// WantGoVersion returns true if Go version s is >= major and minor.
// Returns false if s is not a valid Go version string. See [Parse] for more information.
func WantGoVersion(s string, major, minor int) bool {
ma, mi, _, err := Parse(s)
if err != nil {
return false
}
return ma > major || (ma == major && mi >= minor)
}
// Compare compares two Go version strings.
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
// If either a or b is not a valid Go version, it is treated as "go0.0"

30
goenv/version_test.go

@ -39,36 +39,6 @@ func TestParse(t *testing.T) {
}
}
func TestWantGoVersion(t *testing.T) {
tests := []struct {
v string
major int
minor int
want bool
}{
{"", 0, 0, false},
{"go", 0, 0, false},
{"go1", 0, 0, false},
{"go.0", 0, 0, false},
{"go1.0", 1, 0, true},
{"go1.1", 1, 1, true},
{"go1.23", 1, 23, true},
{"go1.23.5", 1, 23, true},
{"go1.23.5-rc6", 1, 23, true},
{"go2.0", 1, 23, true},
{"go2.0", 2, 0, true},
}
for _, tt := range tests {
t.Run(tt.v, func(t *testing.T) {
got := WantGoVersion(tt.v, tt.major, tt.minor)
if got != tt.want {
t.Errorf("WantGoVersion(%q, %d, %d): expected %t; got %t",
tt.v, tt.major, tt.minor, tt.want, got)
}
})
}
}
func TestCompare(t *testing.T) {
tests := []struct {
a string

Loading…
Cancel
Save