-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebversion_test.go
107 lines (92 loc) · 2.65 KB
/
debversion_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
104
105
106
107
package main
import "testing"
var testDebVersionComparison = []struct {
a string
b string
result int
}{
{"1.0", "1.0", 0},
{"1.0", "0.9", 1},
{"1.0", "1.1", -1},
{"1.0", "1.1", -1},
{"10.0", "1.0", 1},
{"1.0", "10.1", -1},
{"1a", "1", 1},
{"1a", "1b", -1},
{"1b.0", "1a.1", 1},
{"1a.0", "1b.1", -1},
{"1.0~1", "1.0", -1},
{"1:1.0~1", "1.0", 1},
{"1.0~1", "2:1.0", -1},
{"1.0-1~1", "1.0", 1},
{"1.0-1~1", "1.0-1", -1},
{"1.0-1", "1.0~1", 1},
{"1.0-7+bbm+b9.g24102c6.wheezy1", "1.0-6+bbm-b6.g442cbf8.wheezy1", -1},
{"2.3~pre1003.wheezy1", "2.3~pre1002.wheezy1", 1},
{"2.3~pre1003.wheezy1", "2.30~pre1002.wheezy1", -1},
}
func TestDebVersionComparison(t *testing.T) {
for i, tt := range testDebVersionComparison {
var err error
aVer, err := ParseDebVersion(tt.a)
if err != nil {
t.Errorf("%d. failed: %q\n", i, err.Error())
}
bVer, err := ParseDebVersion(tt.b)
if err != nil {
t.Errorf("%d. failed: %q\n", i, err.Error())
}
//log.Println("a: ", aVer)
//log.Println("b: ", bVer)
comparison := DebVersionCompare(aVer, bVer)
switch {
case tt.result == 0 && comparison != 0:
t.Errorf("%d. failed: expected 0 returned %d\n", i, comparison)
case tt.result == -1 && comparison >= 0:
t.Errorf("%d. failed: expected less than 0 , returned %d\n", i, comparison)
case tt.result == 1 && comparison <= 0:
t.Errorf("%d. failed: expected greater than 0, returned %d\n", i, comparison)
}
}
}
var testParseDebVersion = []struct {
in string
out *DebVersion
err error
}{
{"20a", &DebVersion{0, "20a", ""}, nil},
{"20a-1", &DebVersion{0, "20a", "1"}, nil},
{"2.01-1-1", &DebVersion{0, "2.01-1", "1"}, nil},
{"1:2.3-1", &DebVersion{1, "2.3", "1"}, nil},
{"1:2.3-1-1", &DebVersion{1, "2.3-1", "1"}, nil},
{"1:1:1.0-1-1~1", &DebVersion{1, "1:1.0-1", "1~1"}, nil},
{"2.3~pre13.wheezy1", &DebVersion{0, "2.3~pre13.wheezy1", ""}, nil},
}
func TestParseDebVersion(t *testing.T) {
for i, tt := range testParseDebVersion {
var err error
inVer, err := ParseDebVersion(tt.in)
if inVer != *tt.out || err != tt.err {
t.Errorf("%d. failed: expected %q got %q\n", i, tt.out, inVer)
}
}
}
var testDebVersionString = []struct {
in *DebVersion
out string
}{
{&DebVersion{0, "20a", ""}, "20a"},
{&DebVersion{0, "20a", "1"}, "20a-1"},
{&DebVersion{0, "2.01-1", "1"}, "2.01-1-1"},
{&DebVersion{1, "2.3", "1"}, "1:2.3-1"},
{&DebVersion{1, "2.3-1", "1"}, "1:2.3-1-1"},
{&DebVersion{1, "1:1.0-1", "1~1"}, "1:1:1.0-1-1~1"},
}
func TestDebVersionString(t *testing.T) {
for i, tt := range testDebVersionString {
outStr := tt.in.String()
if outStr != tt.out {
t.Errorf("%d. failed: expected %s got %s\n", i, tt.out, outStr)
}
}
}