-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathsemver_test.go
More file actions
69 lines (59 loc) · 1.49 KB
/
semver_test.go
File metadata and controls
69 lines (59 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package util
import (
"strings"
"testing"
"golang.org/x/mod/semver"
)
func TestNewSemVer(t *testing.T) {
type TestPair struct {
Input string
Expected string
}
// Check the special case for the empty string.
result := NewSemVer("")
if result != nil {
t.Errorf("Expected NewSemVer(\"\") to return nil, but got \"%s\".", result)
}
testData := []TestPair{
{"0", "v0"},
{"1.0", "v1.0"},
{"1.0.2", "v1.0.2"},
{"1.20", "v1.20"},
{"1.22.3", "v1.22.3"},
}
// prefixes should not affect the result
prefixes := []string{"", "go", "v"}
// suffixes
suffixes := []string{"", "rc1", "-rc1"}
// Check that we get what we expect for each of the test cases.
for _, pair := range testData {
for _, prefix := range prefixes {
for _, suffix := range suffixes {
// combine the input string with the current prefix and suffix
input := prefix + pair.Input + suffix
result := NewSemVer(input)
expected := pair.Expected
if suffix != "" {
expected = semver.Canonical(pair.Expected) + "-rc1"
}
if result.String() != expected {
t.Errorf(
"Expected NewSemVer(\"%s\") to return \"%s\", but got \"%s\".",
input,
expected,
result,
)
}
expected = strings.Replace(expected, "-rc1", "-rc.1", 1)
if result.StandardSemVer() != expected[1:] {
t.Errorf(
"Expected NewSemVer(\"%s\").StandardSemVer() to return \"%s\", but got \"%s\".",
input,
expected[1:],
result.StandardSemVer(),
)
}
}
}
}
}