-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvnum_test.go
63 lines (59 loc) · 1.33 KB
/
vnum_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ocfl
import (
"testing"
)
func TestVersionHelpers(t *testing.T) {
for _, n := range []string{"", "v0", "v00", "v", "1", "v.10", "v3.0", "asdf"} {
v := VNum{}
err := ParseVNum(n, &v)
if err == nil {
t.Errorf("parsing %s did not fail as expected", n)
}
}
testVals := map[string][2]int{
"v1": {1, 0},
"v100": {100, 0},
"v0000010": {10, 7},
"v031": {31, 3},
}
for key, val := range testVals {
v := VNum{}
err := ParseVNum(key, &v)
if err != nil {
t.Error(err)
}
if v.num != val[0] {
t.Errorf("expected %s to parse to %d, got %d", key, val[0], v.num)
}
if v.padding != val[1] {
t.Errorf("expected %s to parse to padding: %d, got padding %d", key, val[1], v.padding)
}
}
}
func TestValidVersionSeq(t *testing.T) {
p := MustParseVNum
// valid sequences
valid := []VNums{
{p("v1")},
{p("v1"), p("v2"), p("v3"), p("v4"), p("v5")},
{p("v001"), p("v002"), p("v003")},
}
for _, seq := range valid {
err := seq.Valid()
if err != nil {
t.Error(err)
}
}
// invalid sequenecs
invalid := []VNums{
{p("v2")},
{p("v1"), p("v3"), p("v4"), p("v5")},
{p("v01"), p("v02"), p("v03"), p("v04"), p("v05"), p("v06"), p("v07"), p("v08"), p("v09"), p("v10")},
}
for _, seq := range invalid {
err := seq.Valid()
if err == nil {
t.Errorf("expected %v to be invalid", seq)
}
}
}