File tree 3 files changed +14
-12
lines changed
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 {
91
91
version = "v" + version
92
92
}
93
93
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 ) {
99
96
log .Fatalf ("%s is not a valid version string\n " , version )
100
97
}
101
98
102
- return semVer (canonical )
99
+ return semVer (version )
103
100
}
104
101
105
102
func (ver semVer ) Compare (other SemVer ) int {
Original file line number Diff line number Diff line change 1
1
package util
2
2
3
- import "testing"
3
+ import (
4
+ "testing"
5
+
6
+ "golang.org/x/mod/semver"
7
+ )
4
8
5
9
func TestNewSemVer (t * testing.T ) {
6
10
type TestPair struct {
@@ -15,10 +19,10 @@ func TestNewSemVer(t *testing.T) {
15
19
}
16
20
17
21
testData := []TestPair {
18
- {"0" , "v0.0.0 " },
19
- {"1.0" , "v1.0.0 " },
22
+ {"0" , "v0" },
23
+ {"1.0" , "v1.0" },
20
24
{"1.0.2" , "v1.0.2" },
21
- {"1.20" , "v1.20.0 " },
25
+ {"1.20" , "v1.20" },
22
26
{"1.22.3" , "v1.22.3" },
23
27
}
24
28
@@ -31,13 +35,13 @@ func TestNewSemVer(t *testing.T) {
31
35
for _ , pair := range testData {
32
36
for _ , prefix := range prefixes {
33
37
for _ , suffix := range suffixes {
34
- // c
38
+ // combine the input string with the current prefix and suffix
35
39
input := prefix + pair .Input + suffix
36
40
result := NewSemVer (input )
37
41
38
42
expected := pair .Expected
39
43
if suffix != "" {
40
- expected += "-rc1"
44
+ expected = semver . Canonical ( pair . Expected ) + "-rc1"
41
45
}
42
46
43
47
if result .String () != expected {
You can’t perform that action at this time.
0 commit comments