-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_test.go
More file actions
214 lines (176 loc) · 6.17 KB
/
types_test.go
File metadata and controls
214 lines (176 loc) · 6.17 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package config
import (
"flag"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
var (
_ flag.Value = &arrayInt{}
_ flag.Getter = &arrayInt{}
_ flag.Value = &arrayInt64{}
_ flag.Getter = &arrayInt64{}
_ flag.Value = &arrayUint{}
_ flag.Getter = &arrayUint{}
_ flag.Value = &arrayUint64{}
_ flag.Getter = &arrayUint64{}
_ flag.Value = &arrayFloat64{}
_ flag.Getter = &arrayFloat64{}
_ flag.Value = &arrayDuration{}
_ flag.Getter = &arrayDuration{}
_ flag.Value = &arrayString{}
_ flag.Getter = &arrayString{}
)
func Test_arrayInt(t *testing.T) {
Convey("test arrayInt type", t, func() {
ptr := new([]int)
val := []int{-1, 2, -3, 4, -5, 6, -7, 8, -9, 0}
arrInt := newArrayInt(val, ptr)
Convey("get actual []int value from arrayInt", func() {
So(arrInt.Get(), ShouldResemble, val)
})
Convey("parse new arrayInt value from a string", func() {
out := []int{0, -9, 8, -7, 6, -5, 4, -3, 2, -1}
arrInt.Set("0,-9,8,-7,6,-5,4,-3,2,-1")
So([]int(*arrInt), ShouldResemble, out)
})
Convey("try to parse invalid arrayInt from a string", func() {
So(arrInt.Set("false,42"), ShouldResemble, errCantUse("false,42", []int{}))
})
Convey("convert arrayInt to a string", func() {
So(arrInt.String(), ShouldEqual, "-1,2,-3,4,-5,6,-7,8,-9,0")
})
})
}
func Test_arrayUint(t *testing.T) {
Convey("test arrayUint type", t, func() {
ptr := new([]uint)
val := []uint{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
arrUint := newArrayUint(val, ptr)
Convey("get actual []uint value from arrayUint", func() {
So(arrUint.Get(), ShouldResemble, val)
})
Convey("parse new arrayUint value from a string", func() {
out := []uint{0, 9, 8, 7, 6, 5, 4, 3, 2, 1}
arrUint.Set("0,9,8,7,6,5,4,3,2,1")
So([]uint(*arrUint), ShouldResemble, out)
})
Convey("try to parse invalid arrayUint from a string", func() {
So(arrUint.Set("false,42"), ShouldResemble, errCantUse("false,42", []uint{}))
})
Convey("convert arrayUint to a string", func() {
So(arrUint.String(), ShouldEqual, "1,2,3,4,5,6,7,8,9,0")
})
})
}
func Test_arrayInt64(t *testing.T) {
Convey("test arrayInt64 type", t, func() {
ptr := new([]int64)
val := []int64{-1, 2, -3, 4, -5, 6, -7, 8, -9, 0}
arrInt64 := newArrayInt64(val, ptr)
Convey("get actual []int64 value from arrayInt64", func() {
So(arrInt64.Get(), ShouldResemble, val)
})
Convey("parse new arrayInt64 value from a string", func() {
out := []int64{0, -9, 8, -7, 6, -5, 4, -3, 2, -1}
arrInt64.Set("0,-9,8,-7,6,-5,4,-3,2,-1")
So([]int64(*arrInt64), ShouldResemble, out)
})
Convey("try to parse invalid arrayInt64 from a string", func() {
So(arrInt64.Set("false,42"), ShouldResemble, errCantUse("false,42", []int64{}))
})
Convey("convert arrayInt64 to a string", func() {
So(arrInt64.String(), ShouldEqual, "-1,2,-3,4,-5,6,-7,8,-9,0")
})
})
}
func Test_arrayUint64(t *testing.T) {
Convey("test arrayUint64 type", t, func() {
ptr := new([]uint64)
val := []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
arrUint64 := newArrayUint64(val, ptr)
Convey("get actual []uint64 value from arrayUint64", func() {
So(arrUint64.Get(), ShouldResemble, val)
})
Convey("parse new arrayUint64 value from a string", func() {
out := []uint64{0, 9, 8, 7, 6, 5, 4, 3, 2, 1}
arrUint64.Set("0,9,8,7,6,5,4,3,2,1")
So([]uint64(*arrUint64), ShouldResemble, out)
})
Convey("try to parse invalid arrayUint64 from a string", func() {
So(arrUint64.Set("false,42"), ShouldResemble, errCantUse("false,42", []uint64{}))
})
Convey("convert arrayUint64 to a string", func() {
So(arrUint64.String(), ShouldEqual, "1,2,3,4,5,6,7,8,9,0")
})
})
}
func Test_arrayFloat64(t *testing.T) {
Convey("test arrayFloat64 type", t, func() {
ptr := new([]float64)
val := []float64{-1.1, 2.2, -3.14, 4.56, -5.432, 6, -7, 8, -9, 0.01}
arrFloat64 := newArrayFloat64(val, ptr)
Convey("get actual []float64 value from arrayFloat64", func() {
So(arrFloat64.Get(), ShouldResemble, val)
})
Convey("parse new arrayFloat64 value from a string", func() {
out := []float64{0, -9, 8, -7, 6, -5, 4, -3, 2, -1}
arrFloat64.Set("0,-9,8,-7,6,-5,4,-3,2,-1")
So([]float64(*arrFloat64), ShouldResemble, out)
})
Convey("try to parse invalid arrayFloat64 from a string", func() {
So(arrFloat64.Set("false,42"), ShouldResemble, errCantUse("false,42", []float64{}))
})
Convey("convert arrayFloat64 to a string", func() {
So(arrFloat64.String(), ShouldEqual, "-1.1,2.2,-3.14,4.56,-5.432,6,-7,8,-9,0.01")
})
})
}
func Test_arrayDuration(t *testing.T) {
Convey("test arrayDuration type", t, func() {
ptr := new([]time.Duration)
val := []time.Duration{1, 1000, 1000000, 1000000000}
arrDuration := newArrayDuration(val, ptr)
Convey("get actual []time.Duration value from arrayDuration", func() {
So(arrDuration.Get(), ShouldResemble, val)
})
Convey("parse new arrayDuration value from a string", func() {
out := []time.Duration{
time.Duration(1000000000),
time.Duration(180000000000),
time.Duration(4210000000000),
}
arrDuration.Set("1s,3m,1h10m10s")
So([]time.Duration(*arrDuration), ShouldResemble, out)
})
Convey("try to parse invalid arrayDuration from a string", func() {
So(arrDuration.Set("1000"), ShouldResemble, errCantUse("1000", []time.Duration{}))
})
Convey("convert arrayDuration to a string", func() {
So(arrDuration.String(), ShouldEqual, "1ns,1µs,1ms,1s")
})
})
}
func Test_arrayString(t *testing.T) {
Convey("test arrayString type", t, func() {
ptr := new([]string)
val := []string{"foo", "bar"}
arrStr := newArrayString(val, ptr)
Convey("instantiate arrayString with constructor func", func() {
So(arrStr, ShouldHaveSameTypeAs, new(arrayString))
So(arrStr, ShouldImplement, (*flag.Value)(nil))
So(arrStr, ShouldImplement, (*flag.Getter)(nil))
})
Convey("get actual []string value from arrayString", func() {
So(arrStr.Get(), ShouldResemble, val)
})
Convey("parse new arrayString value from a string", func() {
out := []string{"this", "is", "new", "value"}
arrStr.Set("this,is,new,value")
So([]string(*arrStr), ShouldResemble, out)
})
Convey("convert arrayString to string", func() {
So(arrStr.String(), ShouldEqual, "foo,bar")
})
})
}