-
Notifications
You must be signed in to change notification settings - Fork 0
/
versionstring_test.go
103 lines (84 loc) · 1.69 KB
/
versionstring_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package versionstring
import (
"testing"
)
type TestParse struct {
in string
exp []int
}
func TestParseVersionString(t *testing.T) {
T := []TestParse{
{"1.02.3.", []int{1, 2, 3}},
{"1.2..3", []int{1, 2, 3}},
{"1.00.2", []int{1, 0, 2}},
}
for i := 0; i < len(T); i++ {
exp := T[i].exp
act := ParseVersionString(T[i].in)
if len(act) != len(exp) {
t.Errorf("Exp: %d != %d Act: (err: %v)", exp, act)
}
for j := 0; j < len(act); j++ {
if exp[j] != act[j] {
t.Errorf("Exp %d != %d Act", exp, act)
}
}
}
}
type TestMax struct {
in string
exp []int
}
func TestMaxVersion(t *testing.T) {
lvs := []int{1, 2, 3}
T := []TestMax{
{"1.2.3", []int{1, 2, 3}},
{"1.1", []int{1, 2, 3}},
{"1.3", []int{1, 3}},
{"1.2.4", []int{1, 2, 4}},
{"1.2.2", []int{1, 2, 3}},
{"1.2.2.2", []int{1, 2, 3}},
{"1.2.3.0.0", []int{1, 2, 3}},
{"1.2.3.2", []int{1, 2, 3, 2}},
{"1.2.3.2.4", []int{1, 2, 3, 2, 4}},
//_____|___
}
for i := 0; i < len(T); i++ {
exp := T[i].exp
input := ParseVersionString(T[i].in)
act := MaxVersion(lvs, input)
if len(act) != len(exp) {
t.Errorf("Exp: %d != %d Act", exp, act)
}
for j := 0; j < len(act); j++ {
if exp[j] != act[j] {
t.Errorf("Exp %d != %d Act", exp, act)
}
}
}
}
type TestComp struct {
in string
exp int
}
func TestCompareToString(t *testing.T) {
lvs := "1.2.3"
T := []TestComp{
{"1.2.3", 0},
{"1.1", -1},
{"1.3", 1},
{"1.2.4", 1},
{"1.2.2", -1},
{"1.2.2.2", -1},
{"1.2.3.0.0", 0},
{"1.2.3.2", 1},
{"1.2.3.2.4", 1},
//_____|___
}
for i := 0; i < len(T); i++ {
exp := T[i].exp
if act := CompareStrings(lvs, T[i].in); act != exp {
t.Errorf("Exp %d != %d Act", exp, act)
}
}
}