forked from hashicorp/go-version
-
Notifications
You must be signed in to change notification settings - Fork 3
/
version_collection_test.go
99 lines (90 loc) · 1.76 KB
/
version_collection_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
// SPDX-License-Identifier: MPL-2.0
package version
import (
"reflect"
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCollection(t *testing.T) {
versionsRaw := []string{
"1.1.1",
"1.0",
"1.2",
"2",
"0.7.1",
"1.2.3",
"1",
"1.2-5",
"1.2-beta.5",
"1.2.0-x.Y.0+metadata",
"1.2.0-x.Y.0+metadata-width-hypen",
"1.2.3-rc1-with-hypen",
"1.2.3.4",
"1.2.0.4-x.Y.0+metadata",
"1.2.0.4-x.Y.0+metadata-width-hypen",
"1.2.0-X-1.2.0+metadata~dist",
"1.2.3.4-rc1-with-hypen",
"1.2.3.4",
"V1.2.3",
"1.7rc2",
"v1.7rc2",
"v1.0-",
"2.28.0.618+gf4bc123cb7",
"1.13.0+dev-545-gb3b1c081b",
"2.28.0.618.gf4bc123cb7",
"2.29.0.rc0.261.g7178c9af9c",
"1.2.beta",
"1.21.beta",
"v1.13.0-rc1",
}
versions := make([]*Version, len(versionsRaw))
for i, raw := range versionsRaw {
t.Run(raw, func(t *testing.T) {
v, err := NewVersion(raw)
if !assert.NoError(t, err) {
t.FailNow()
}
versions[i] = v
})
}
sort.Sort(Collection(versions))
actual := make([]string, len(versions))
for i, v := range versions {
actual[i] = v.String()
}
expected := []string{
"0.7.1",
"1.0.0--",
"1.0.0",
"1.0.0",
"1.1.1",
"1.2.0-5",
"1.2.0-X-1.2.0+metadata~dist",
"1.2.0-beta",
"1.2.0-beta.5",
"1.2.0-x.Y.0+metadata",
"1.2.0-x.Y.0+metadata-width-hypen",
"1.2.0",
"1.2.0.4-x.Y.0+metadata",
"1.2.0.4-x.Y.0+metadata-width-hypen",
"1.2.3-rc1-with-hypen",
"1.2.3",
"1.2.3",
"1.2.3.4-rc1-with-hypen",
"1.2.3.4",
"1.2.3.4",
"1.7.0-rc2",
"1.7.0-rc2",
"1.13.0-rc1",
"1.13.0+dev-545-gb3b1c081b",
"1.21.0-beta",
"2.0.0",
"2.28.0.618-gf4bc123cb7",
"2.28.0.618+gf4bc123cb7",
"2.29.0-rc0.261.g7178c9af9c",
}
if !reflect.DeepEqual(actual, expected) {
assert.EqualValues(t, expected, actual)
}
}