-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_test.go
119 lines (111 loc) · 3.18 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
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
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"testing"
)
func Test_version(t *testing.T) {
v := version{1, 2, 3}
tests := []struct {
name string
method func() string
want string
}{
{name: "string", method: v.String, want: "1.2.3"},
{name: "next major", method: v.nextMajor, want: "2.0.0"},
{name: "next minor", method: v.nextMinor, want: "1.3.0"},
{name: "next patch", method: v.nextPatch, want: "1.2.4"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.method()
equal[E](t, got, tt.want)
})
}
}
func Test_parseVersion_valid(t *testing.T) {
test := func(input string, want version) {
t.Run(input, func(t *testing.T) {
got, err := parseVersion(input)
noerr[F](t, err)
equal[E](t, got, &want)
})
}
// data source: https://regex101.com/r/vkijKf/1/
test("0.0.4", version{0, 0, 4})
test("1.2.3", version{1, 2, 3})
test("10.20.30", version{10, 20, 30})
test("1.1.2-prerelease+meta", version{1, 1, 2})
test("1.1.2+meta", version{1, 1, 2})
test("1.1.2+meta-valid", version{1, 1, 2})
test("1.0.0-alpha", version{1, 0, 0})
test("1.0.0-beta", version{1, 0, 0})
test("1.0.0-alpha.beta", version{1, 0, 0})
test("1.0.0-alpha.beta.1", version{1, 0, 0})
test("1.0.0-alpha.1", version{1, 0, 0})
test("1.0.0-alpha0.valid", version{1, 0, 0})
test("1.0.0-alpha.0valid", version{1, 0, 0})
test("1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay", version{1, 0, 0})
test("1.0.0-rc.1+build.1", version{1, 0, 0})
test("2.0.0-rc.1+build.123", version{2, 0, 0})
test("1.2.3-beta", version{1, 2, 3})
test("10.2.3-DEV-SNAPSHOT", version{10, 2, 3})
test("1.2.3-SNAPSHOT-123", version{1, 2, 3})
test("1.0.0", version{1, 0, 0})
test("2.0.0", version{2, 0, 0})
test("1.1.7", version{1, 1, 7})
test("2.0.0+build.1848", version{2, 0, 0})
test("2.0.1-alpha.1227", version{2, 0, 1})
test("1.0.0-alpha+beta", version{1, 0, 0})
test("1.2.3----RC-SNAPSHOT.12.9.1--.12+788", version{1, 2, 3})
test("1.2.3----R-S.12.9.1--.12+meta", version{1, 2, 3})
test("1.2.3----RC-SNAPSHOT.12.9.1--.12", version{1, 2, 3})
test("1.0.0+0.build.1-rc.10000aaa-kk-0.1", version{1, 0, 0})
test("1.0.0-0A.is.legal", version{1, 0, 0})
}
func Test_parseVersion_invalid(t *testing.T) {
test := func(input string) {
t.Run(input, func(t *testing.T) {
_, err := parseVersion(input)
iserr[E](t, err, errInvalidFormat)
})
}
// data source: https://regex101.com/r/vkijKf/1/
test("1")
test("1.2")
test("1.2.3-0123")
test("1.2.3-0123.0123")
test("1.1.2+.123")
test("+invalid")
test("-invalid")
test("-invalid+invalid")
test("-invalid.01")
test("alpha")
test("alpha.beta")
test("alpha.beta.1")
test("alpha.1")
test("alpha+beta")
test("alpha_beta")
test("alpha.")
test("alpha..")
test("beta")
test("1.0.0-alpha_beta")
test("-alpha.")
test("1.0.0-alpha..")
test("1.0.0-alpha..1")
test("1.0.0-alpha...1")
test("1.0.0-alpha....1")
test("1.0.0-alpha.....1")
test("1.0.0-alpha......1")
test("1.0.0-alpha.......1")
test("01.1.1")
test("1.01.1")
test("1.1.01")
test("1.2")
test("1.2.3.DEV")
test("1.2-SNAPSHOT")
test("1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788")
test("1.2-RC-SNAPSHOT")
test("-1.0.3-gamma+b7718")
test("+justmeta")
test("9.8.7+meta+meta")
test("9.8.7-whatever+meta+meta")
}