File tree Expand file tree Collapse file tree 3 files changed +14
-12
lines changed Expand file tree Collapse file tree 3 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -91,15 +91,12 @@ func NewSemVer(version string) SemVer {
9191 version = "v" + version
9292 }
9393
94- // Convert the remaining version string to a canonical semantic version,
95- // and check that this was successful.
96- canonical := semver .Canonical (version )
97-
98- if canonical == "" {
94+ // Check that the remaining version string is valid.
95+ if ! semver .IsValid (version ) {
9996 log .Fatalf ("%s is not a valid version string\n " , version )
10097 }
10198
102- return semVer (canonical )
99+ return semVer (version )
103100}
104101
105102func (ver semVer ) Compare (other SemVer ) int {
Original file line number Diff line number Diff line change 11package util
22
3- import "testing"
3+ import (
4+ "testing"
5+
6+ "golang.org/x/mod/semver"
7+ )
48
59func TestNewSemVer (t * testing.T ) {
610 type TestPair struct {
@@ -15,10 +19,10 @@ func TestNewSemVer(t *testing.T) {
1519 }
1620
1721 testData := []TestPair {
18- {"0" , "v0.0.0 " },
19- {"1.0" , "v1.0.0 " },
22+ {"0" , "v0" },
23+ {"1.0" , "v1.0" },
2024 {"1.0.2" , "v1.0.2" },
21- {"1.20" , "v1.20.0 " },
25+ {"1.20" , "v1.20" },
2226 {"1.22.3" , "v1.22.3" },
2327 }
2428
@@ -31,13 +35,13 @@ func TestNewSemVer(t *testing.T) {
3135 for _ , pair := range testData {
3236 for _ , prefix := range prefixes {
3337 for _ , suffix := range suffixes {
34- // c
38+ // combine the input string with the current prefix and suffix
3539 input := prefix + pair .Input + suffix
3640 result := NewSemVer (input )
3741
3842 expected := pair .Expected
3943 if suffix != "" {
40- expected += "-rc1"
44+ expected = semver . Canonical ( pair . Expected ) + "-rc1"
4145 }
4246
4347 if result .String () != expected {
You can’t perform that action at this time.
0 commit comments