@@ -22,39 +22,33 @@ func TestNewSemVer(t *testing.T) {
22
22
{"1.22.3" , "v1.22.3" },
23
23
}
24
24
25
- // Check that we get what we expect for each of the test cases.
26
- for _ , pair := range testData {
27
- result := NewSemVer (pair .Input )
28
-
29
- if result .String () != pair .Expected {
30
- t .Errorf ("Expected NewSemVer(\" %s\" ) to return \" %s\" , but got \" %s\" ." , pair .Input , pair .Expected , result )
31
- }
32
- }
25
+ // prefixes should not affect the result
26
+ prefixes := []string {"" , "go" , "v" }
27
+ // suffixes
28
+ suffixes := []string {"" , "rc1" , "-rc1" }
33
29
34
- // And again, but this time prefixed with "v"
35
- for _ , pair := range testData {
36
- result := NewSemVer ("v" + pair .Input )
37
-
38
- if result .String () != pair .Expected {
39
- t .Errorf ("Expected NewSemVer(\" v%s\" ) to return \" %s\" , but got \" %s\" ." , pair .Input , pair .Expected , result )
40
- }
41
- }
42
-
43
- // And again, but this time prefixed with "go"
44
- for _ , pair := range testData {
45
- result := NewSemVer ("go" + pair .Input )
46
-
47
- if result .String () != pair .Expected {
48
- t .Errorf ("Expected NewSemVer(\" go%s\" ) to return \" %s\" , but got \" %s\" ." , pair .Input , pair .Expected , result )
49
- }
50
- }
51
-
52
- // And again, but this time with an "rc1" suffix.
30
+ // Check that we get what we expect for each of the test cases.
53
31
for _ , pair := range testData {
54
- result := NewSemVer (pair .Input + "rc1" )
55
-
56
- if result .String () != pair .Expected + "-rc1" {
57
- t .Errorf ("Expected NewSemVer(\" %src1\" ) to return \" %s\" , but got \" %s\" ." , pair .Input , pair .Expected + "-rc1" , result )
32
+ for _ , prefix := range prefixes {
33
+ for _ , suffix := range suffixes {
34
+ // c
35
+ input := prefix + pair .Input + suffix
36
+ result := NewSemVer (input )
37
+
38
+ expected := pair .Expected
39
+ if suffix != "" {
40
+ expected += "-rc1"
41
+ }
42
+
43
+ if result .String () != expected {
44
+ t .Errorf (
45
+ "Expected NewSemVer(\" %s\" ) to return \" %s\" , but got \" %s\" ." ,
46
+ input ,
47
+ expected ,
48
+ result ,
49
+ )
50
+ }
51
+ }
58
52
}
59
53
}
60
54
}
0 commit comments