-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_example_test.go
143 lines (113 loc) · 2.49 KB
/
version_example_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package comver_test
import (
"fmt"
"github.com/typisttech/comver"
)
func ExampleParse() {
v, _ := comver.Parse("1.2.3")
fmt.Println(v)
// Output: 1.2.3.0
}
func ExampleParse_full() {
v, _ := comver.Parse("1.2.3.4-beta.5+foo")
fmt.Println(v)
// Output: 1.2.3.4-beta5
}
func ExampleParse_error() {
_, err := comver.Parse("not a version")
fmt.Println(err)
// Output: error parsing version string "not a version"
}
func ExampleVersion_Compare() {
v1 := comver.MustParse("1")
v2 := comver.MustParse("2")
w2 := comver.MustParse("2")
v3 := comver.MustParse("3")
v2v1 := v2.Compare(v1)
fmt.Println(v2v1)
v2w2 := v2.Compare(w2)
fmt.Println(v2w2)
v2v3 := v2.Compare(v3)
fmt.Println(v2v3)
// Output:
// 1
// 0
// -1
}
func ExampleVersion_Compare_patch() {
v1 := comver.MustParse("1")
v1p := comver.MustParse("1.patch")
got := v1.Compare(v1p)
fmt.Println(got)
// Output: -1
}
func ExampleVersion_Compare_preRelease() {
v1b5 := comver.MustParse("1.0.0-beta.5")
v1b6 := comver.MustParse("1.0.0-beta.6")
got := v1b5.Compare(v1b6)
fmt.Println(got)
// Output: -1
}
func ExampleVersion_Compare_metadata() {
foo := comver.MustParse("1.0.0+foo")
bar := comver.MustParse("1.0.0+bar")
got := foo.Compare(bar)
fmt.Println(got)
// Output: 0
}
func ExampleVersion_Short() {
ss := []string{
"1",
"1.2",
"1.2.3",
"1.2.3+foo",
"1.2.3.4",
"1.2.3.4.beta",
"1.2.3.4-beta5",
"1.2.3.4-beta5+foo",
"1.b5+foo",
}
for _, s := range ss {
v := comver.MustParse(s)
got := v.Short()
fmt.Printf("%-19q => %v\n", s, got)
}
// Output:
// "1" => 1
// "1.2" => 1.2
// "1.2.3" => 1.2.3
// "1.2.3+foo" => 1.2.3
// "1.2.3.4" => 1.2.3.4
// "1.2.3.4.beta" => 1.2.3.4-beta
// "1.2.3.4-beta5" => 1.2.3.4-beta5
// "1.2.3.4-beta5+foo" => 1.2.3.4-beta5
// "1.b5+foo" => 1-beta5
}
func ExampleVersion_Original() {
ss := []string{
"1",
"1.2",
"1.2.3",
"1.2.3+foo",
"1.2.3.4",
"1.2.3.4.beta",
"1.2.3.4-beta5",
"1.2.3.4-beta5+foo",
"1.b5+foo",
}
for _, s := range ss {
v := comver.MustParse(s)
got := v.Original()
fmt.Printf("%-19q => %v\n", s, got)
}
// Output:
// "1" => 1
// "1.2" => 1.2
// "1.2.3" => 1.2.3
// "1.2.3+foo" => 1.2.3+foo
// "1.2.3.4" => 1.2.3.4
// "1.2.3.4.beta" => 1.2.3.4.beta
// "1.2.3.4-beta5" => 1.2.3.4-beta5
// "1.2.3.4-beta5+foo" => 1.2.3.4-beta5+foo
// "1.b5+foo" => 1.b5+foo
}