-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_test.go
40 lines (36 loc) · 1.1 KB
/
version_test.go
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
package semver
import "testing"
var versionTestBattery = map[string]*Version{
"1": NewVersion(1, 0, 0),
"1.3": NewVersion(1, 3, 0),
"1.2.1": NewVersion(1, 2, 1),
" 4.3.2 ": NewVersion(4, 3, 2),
"1.2.3-alpha.3": NewVersion(1, 2, 3, "alpha.3"),
"1.4.5+2342": NewVersion(1, 4, 5, "", "2342"),
"1.2.3-rc.4+34.a2": NewVersion(1, 2, 3, "rc.4", "34.a2"),
"0.0.0": NewVersion(0, 0, 0),
"..": nil,
"a.1.a": nil,
"a1.2.3a": nil,
"3.5.2 xxx": nil,
"foo": nil,
"": nil,
}
func TestParseVersion(t *testing.T) {
for verStr, expected := range versionTestBattery {
v, err := ParseVersion(verStr)
if expected == nil {
if err == nil || v != nil {
t.Errorf("Expected %q to not be parseable", verStr)
}
} else {
if expected.Major != v.Major ||
expected.Minor != v.Minor ||
expected.Patch != v.Patch ||
expected.PreRelease != v.PreRelease ||
expected.Build != v.Build {
t.Errorf("Parsed version %q does not match expected %q", v, expected)
}
}
}
}