-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_test.go
339 lines (278 loc) · 11.7 KB
/
convert_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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
package assertion
import (
"testing"
)
func TestAssertion_Boolean_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Boolean", []interface{}{"true"}},
{"Boolean", []interface{}{"TRUE"}},
{"Boolean", []interface{}{"t"}},
{"Boolean", []interface{}{"T"}},
{"Boolean", []interface{}{"1"}},
{"Boolean", []interface{}{"false"}},
{"Boolean", []interface{}{"FALSE"}},
{"Boolean", []interface{}{"f"}},
{"Boolean", []interface{}{"F"}},
{"Boolean", []interface{}{"0"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Boolean_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Boolean", []interface{}{"on"}, "on is not a valid boolean string"},
{"Boolean", []interface{}{"yes"}, "yes is not a valid boolean string"},
{"Boolean", []interface{}{"y"}, "y is not a valid boolean string"},
{"Boolean", []interface{}{"off"}, "off is not a valid boolean string"},
{"Boolean", []interface{}{"no"}, "no is not a valid boolean string"},
{"Boolean", []interface{}{"n"}, "n is not a valid boolean string"},
{"Boolean", []interface{}{"ok"}, "ok is not a valid boolean string"},
{"Boolean", []interface{}{"ko"}, "ko is not a valid boolean string"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Truthy_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Truthy", []interface{}{"true"}},
{"Truthy", []interface{}{"TRUE"}},
{"Truthy", []interface{}{"t"}},
{"Truthy", []interface{}{"T"}},
{"Truthy", []interface{}{"1"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Truthy_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Truthy", []interface{}{"on"}, "on is not a valid truthy string"},
{"Truthy", []interface{}{"yes"}, "yes is not a valid truthy string"},
{"Truthy", []interface{}{"y"}, "y is not a valid truthy string"},
{"Truthy", []interface{}{"ok"}, "ok is not a valid truthy string"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Falsy_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Falsy", []interface{}{"false"}},
{"Falsy", []interface{}{"FALSE"}},
{"Falsy", []interface{}{"f"}},
{"Falsy", []interface{}{"F"}},
{"Falsy", []interface{}{"0"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Falsy_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Falsy", []interface{}{"off"}, "off is not a valid falsy string"},
{"Falsy", []interface{}{"off"}, "off is not a valid falsy string"},
{"Falsy", []interface{}{"no"}, "no is not a valid falsy string"},
{"Falsy", []interface{}{"n"}, "n is not a valid falsy string"},
{"Falsy", []interface{}{"ko"}, "ko is not a valid falsy string"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Integer_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Integer", []interface{}{"16174552211"}},
{"Integer", []interface{}{"110110101"}},
{"Integer", []interface{}{"110_110_101"}},
{"Integer", []interface{}{"0b110110101"}},
{"Integer", []interface{}{"0o110110101"}},
{"Integer", []interface{}{"0x110110101"}},
{"Integer", []interface{}{"-16174552211"}},
{"Integer", []interface{}{"-110110101"}},
{"Integer", []interface{}{"-110_110_101"}},
{"Integer", []interface{}{"-0b110110101"}},
{"Integer", []interface{}{"-0o110110101"}},
{"Integer", []interface{}{"-0x110110101"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Integer_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Integer", []interface{}{"0b110110102"}, "0b110110102 is not a valid integer"},
{"Integer", []interface{}{"0x11011010G"}, "0x11011010G is not a valid integer"},
{"Integer", []interface{}{"0o110110108"}, "0o110110108 is not a valid integer"},
{"Integer", []interface{}{"110.110.108"}, "110.110.108 is not a valid integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_IntegerBinary_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"IntegerBinary", []interface{}{"110110101"}},
{"IntegerBinary", []interface{}{"-110110101"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_IntegerBinary_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"IntegerBinary", []interface{}{"0b110110101"}, "0b110110101 is not a valid base-2 integer"},
{"IntegerBinary", []interface{}{"-0b110110101"}, "-0b110110101 is not a valid base-2 integer"},
{"IntegerBinary", []interface{}{"110110102"}, "110110102 is not a valid base-2 integer"},
{"IntegerBinary", []interface{}{"-110110102"}, "-110110102 is not a valid base-2 integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_IntegerOctal_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"IntegerOctal", []interface{}{"0767"}},
{"IntegerOctal", []interface{}{"-7605"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_IntegerOctal_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"IntegerOctal", []interface{}{"108"}, "108 is not a valid base-8 integer"},
{"IntegerOctal", []interface{}{"-108"}, "-108 is not a valid base-8 integer"},
{"IntegerOctal", []interface{}{"0o777"}, "0o777 is not a valid base-8 integer"},
{"IntegerOctal", []interface{}{"-0o777"}, "-0o777 is not a valid base-8 integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_IntegerHexadecimal_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"IntegerHexadecimal", []interface{}{"00ff"}},
{"IntegerHexadecimal", []interface{}{"00FF"}},
{"IntegerHexadecimal", []interface{}{"-00ff"}},
{"IntegerHexadecimal", []interface{}{"-00FF"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_IntegerHexadecimal_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"IntegerHexadecimal", []interface{}{"0x00ff"}, "0x00ff is not a valid base-16 integer"},
{"IntegerHexadecimal", []interface{}{"-0x00ff"}, "-0x00ff is not a valid base-16 integer"},
{"IntegerHexadecimal", []interface{}{"00fg"}, "00fg is not a valid base-16 integer"},
{"IntegerHexadecimal", []interface{}{"-00fg"}, "-00fg is not a valid base-16 integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_IntegerDecimal_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"IntegerDecimal", []interface{}{"0123456789"}},
{"IntegerDecimal", []interface{}{"-0123456789"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_IntegerDecimal_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"IntegerDecimal", []interface{}{"111_111_111"}, "111_111_111 is not a valid base-10 integer"},
{"IntegerDecimal", []interface{}{"-111_111_111"}, "-111_111_111 is not a valid base-10 integer"},
{"IntegerDecimal", []interface{}{"111.111.111"}, "111.111.111 is not a valid base-10 integer"},
{"IntegerDecimal", []interface{}{"111 111 111"}, "111 111 111 is not a valid base-10 integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Unsigned_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Integer", []interface{}{"16174552211"}},
{"Integer", []interface{}{"110110101"}},
{"Integer", []interface{}{"110_110_101"}},
{"Integer", []interface{}{"0b110110101"}},
{"Integer", []interface{}{"0o110110101"}},
{"Integer", []interface{}{"0x110110101"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Unsigned_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Integer", []interface{}{"0b110110102"}, "0b110110102 is not a valid integer"},
{"Integer", []interface{}{"0x11011010G"}, "0x11011010G is not a valid integer"},
{"Integer", []interface{}{"0o110110108"}, "0o110110108 is not a valid integer"},
{"Integer", []interface{}{"110.110.108"}, "110.110.108 is not a valid integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_UnsignedBinary_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"UnsignedBinary", []interface{}{"110110101"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_UnsignedBinary_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"UnsignedBinary", []interface{}{"0b110110101"}, "0b110110101 is not a valid base-2 unsigned integer"},
{"UnsignedBinary", []interface{}{"-0b110110101"}, "-0b110110101 is not a valid base-2 unsigned integer"},
{"UnsignedBinary", []interface{}{"110110102"}, "110110102 is not a valid base-2 unsigned integer"},
{"UnsignedBinary", []interface{}{"-110110102"}, "-110110102 is not a valid base-2 unsigned integer"},
{"UnsignedBinary", []interface{}{"-110110101"}, "-110110101 is not a valid base-2 unsigned integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_UnsignedOctal_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"UnsignedOctal", []interface{}{"0767"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_UnsignedOctal_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"UnsignedOctal", []interface{}{"108"}, "108 is not a valid base-8 unsigned integer"},
{"UnsignedOctal", []interface{}{"-108"}, "-108 is not a valid base-8 unsigned integer"},
{"UnsignedOctal", []interface{}{"-0767"}, "-0767 is not a valid base-8 unsigned integer"},
{"UnsignedOctal", []interface{}{"0o777"}, "0o777 is not a valid base-8 unsigned integer"},
{"UnsignedOctal", []interface{}{"-0o777"}, "-0o777 is not a valid base-8 unsigned integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_UnsignedHexadecimal_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"UnsignedHexadecimal", []interface{}{"00ff"}},
{"UnsignedHexadecimal", []interface{}{"00FF"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_UnsignedHexadecimal_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"UnsignedHexadecimal", []interface{}{"0x00ff"}, "0x00ff is not a valid base-16 unsigned integer"},
{"UnsignedHexadecimal", []interface{}{"-0x00ff"}, "-0x00ff is not a valid base-16 unsigned integer"},
{"UnsignedHexadecimal", []interface{}{"00fg"}, "00fg is not a valid base-16 unsigned integer"},
{"UnsignedHexadecimal", []interface{}{"-00fg"}, "-00fg is not a valid base-16 unsigned integer"},
{"UnsignedHexadecimal", []interface{}{"-00FF"}, "-00FF is not a valid base-16 unsigned integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_UnsignedDecimal_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"UnsignedDecimal", []interface{}{"0123456789"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_UnsignedDecimal_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"UnsignedDecimal", []interface{}{"111_111_111"}, "111_111_111 is not a valid base-10 unsigned integer"},
{"UnsignedDecimal", []interface{}{"-111_111_111"}, "-111_111_111 is not a valid base-10 unsigned integer"},
{"UnsignedDecimal", []interface{}{"111.111.111"}, "111.111.111 is not a valid base-10 unsigned integer"},
{"UnsignedDecimal", []interface{}{"111 111 111"}, "111 111 111 is not a valid base-10 unsigned integer"},
{"UnsignedDecimal", []interface{}{"-0123456789"}, "-0123456789 is not a valid base-10 unsigned integer"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Float_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Float", []interface{}{"3141516"}},
{"Float", []interface{}{"3.141516"}},
{"Float", []interface{}{"-3.141516"}},
{"Float", []interface{}{"1.234560e+02"}},
{"Float", []interface{}{"-1.234560e+02"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Float_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Float", []interface{}{"3.14.15"}, "3.14.15 is not a valid float"},
{"Float", []interface{}{"ffff"}, "ffff is not a valid float"},
}
assertAllReturnsFalse(t, data)
}
func TestAssertion_Base64_ReturnsTrue(t *testing.T) {
data := []MethodDataOK{
{"Base64", []interface{}{"c29tZSBkYXRhIHdpdGggACBhbmQg77u/"}},
}
assertAllReturnsTrue(t, data)
}
func TestAssertion_Base64_ReturnsFalse(t *testing.T) {
data := []MethodDataKO{
{"Base64", []interface{}{"c29tZSBkYXRhIHdpdGggACBhbmQg77u"}, "c29tZSBkYXRhIHdpdGggACBhbmQg77u is not a valid base64 encoded value"},
{"Base64", []interface{}{"c29tZSBkYXRhIHdpdGggACBhbmQg77u/,"}, "c29tZSBkYXRhIHdpdGggACBhbmQg77u/, is not a valid base64 encoded value"},
}
assertAllReturnsFalse(t, data)
}