-
Notifications
You must be signed in to change notification settings - Fork 3
/
int16_test.go
204 lines (151 loc) · 7.52 KB
/
int16_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
package convert_test
import (
"testing"
"time"
"github.com/Eun/go-convert/internal/testhelpers"
)
type SomeStructWithInt16Func struct{}
func (SomeStructWithInt16Func) Int16() int16 {
return 16
}
type SomeStructWithInt16FuncPtr struct{}
func (*SomeStructWithInt16FuncPtr) Int16() int16 {
return 16
}
type SomeStructWithInt16WithErrFunc struct{}
func (SomeStructWithInt16WithErrFunc) Int16() (int16, error) {
return 16, nil
}
type SomeStructWithInt16WithErrFuncPtr struct{}
func (*SomeStructWithInt16WithErrFuncPtr) Int16() (int16, error) {
return 16, nil
}
func TestInt16(t *testing.T) {
tests := []testhelpers.TestCase{
// nil
{nil, int16(0), int16(0), "", nil},
// string
{"6", int16(0), int16(6), "", nil},
{"", int16(0), int16(0), "", nil},
{"Hello World", int16(0), int16(0), `unable to convert string to int16: strconv.ParseInt: parsing "Hello World": invalid syntax`, nil},
// bool
{true, int16(0), int16(1), "", nil},
{false, int16(0), int16(0), "", nil},
// int
{6, int16(0), int16(6), "", nil},
// int8
{int8(6), int16(0), int16(6), "", nil},
// int16
{int16(6), int16(0), int16(6), "", nil},
// int32
{int32(6), int16(0), int16(6), "", nil},
// int64
{int64(6), int16(0), int16(6), "", nil},
// uint
{uint(6), int16(0), int16(6), "", nil},
// uint8
{uint8(6), int16(0), int16(6), "", nil},
// uint16
{uint16(6), int16(0), int16(6), "", nil},
// uint32
{uint32(6), int16(0), int16(6), "", nil},
// uint64
{uint64(6), int16(0), int16(6), "", nil},
// float32
{float32(6), int16(0), int16(6), "", nil},
// float64
{float64(6), int16(0), int16(6), "", nil},
// slice
{[]int{'H', 'e', 'l', 'l', 'o'}, int16(0), int16(0), "unable to convert []int to int16: no recipe", nil},
{[]byte{'H', 'e', 'l', 'l', 'o'}, int16(0), int16(0), "unable to convert []uint8 to int16: no recipe", nil},
{[]rune{'H', 'e', 'l', 'l', 'o'}, int16(0), int16(0), "unable to convert []int32 to int16: no recipe", nil},
{[]string{"H", "e", "l", "l", "o"}, int16(0), int16(0), "unable to convert []string to int16: no recipe", nil},
// struct
{struct{}{}, int16(0), int16(0), "unable to convert struct {} to int16: struct {} has no Int16() function", nil},
// time
{time.Unix(10, 10), int16(10), int16(10), "", nil},
{SomeStructWithIntFunc{}, int16(0), int16(8), "", nil},
{&SomeStructWithIntFunc{}, int16(0), int16(8), "", nil},
{SomeStructWithIntFuncPtr{}, int16(0), int16(8), "", nil},
{&SomeStructWithIntFuncPtr{}, int16(0), int16(8), "", nil},
{SomeStructWithIntWithErrFunc{}, int16(0), int16(8), "", nil},
{&SomeStructWithIntWithErrFunc{}, int16(0), int16(8), "", nil},
{SomeStructWithIntWithErrFuncPtr{}, int16(0), int16(8), "", nil},
{&SomeStructWithIntWithErrFuncPtr{}, int16(0), int16(8), "", nil},
{SomeStructWithInt8Func{}, int16(0), int16(8), "", nil},
{&SomeStructWithInt8Func{}, int16(0), int16(8), "", nil},
{SomeStructWithInt8FuncPtr{}, int16(0), int16(8), "", nil},
{&SomeStructWithInt8FuncPtr{}, int16(0), int16(8), "", nil},
{SomeStructWithInt8WithErrFunc{}, int16(0), int16(8), "", nil},
{&SomeStructWithInt8WithErrFunc{}, int16(0), int16(8), "", nil},
{SomeStructWithInt8WithErrFuncPtr{}, int16(0), int16(8), "", nil},
{&SomeStructWithInt8WithErrFuncPtr{}, int16(0), int16(8), "", nil},
{SomeStructWithInt16Func{}, int16(0), int16(16), "", nil},
{&SomeStructWithInt16Func{}, int16(0), int16(16), "", nil},
{SomeStructWithInt16FuncPtr{}, int16(0), int16(16), "", nil},
{&SomeStructWithInt16FuncPtr{}, int16(0), int16(16), "", nil},
{SomeStructWithInt16WithErrFunc{}, int16(0), int16(16), "", nil},
{&SomeStructWithInt16WithErrFunc{}, int16(0), int16(16), "", nil},
{SomeStructWithInt16WithErrFuncPtr{}, int16(0), int16(16), "", nil},
{&SomeStructWithInt16WithErrFuncPtr{}, int16(0), int16(16), "", nil},
{SomeStructWithInt32Func{}, int16(0), int16(32), "", nil},
{&SomeStructWithInt32Func{}, int16(0), int16(32), "", nil},
{SomeStructWithInt32FuncPtr{}, int16(0), int16(32), "", nil},
{&SomeStructWithInt32FuncPtr{}, int16(0), int16(32), "", nil},
{SomeStructWithInt32WithErrFunc{}, int16(0), int16(32), "", nil},
{&SomeStructWithInt32WithErrFunc{}, int16(0), int16(32), "", nil},
{SomeStructWithInt32WithErrFuncPtr{}, int16(0), int16(32), "", nil},
{&SomeStructWithInt32WithErrFuncPtr{}, int16(0), int16(32), "", nil},
{SomeStructWithInt64Func{}, int16(0), int16(64), "", nil},
{&SomeStructWithInt64Func{}, int16(0), int16(64), "", nil},
{SomeStructWithInt64FuncPtr{}, int16(0), int16(64), "", nil},
{&SomeStructWithInt64FuncPtr{}, int16(0), int16(64), "", nil},
{SomeStructWithInt64WithErrFunc{}, int16(0), int16(64), "", nil},
{&SomeStructWithInt64WithErrFunc{}, int16(0), int16(64), "", nil},
{SomeStructWithInt64WithErrFuncPtr{}, int16(0), int16(64), "", nil},
{&SomeStructWithInt64WithErrFuncPtr{}, int16(0), int16(64), "", nil},
{SomeStructWithUintFunc{}, int16(0), int16(16), "", nil},
{&SomeStructWithUintFunc{}, int16(0), int16(16), "", nil},
{SomeStructWithUintFuncPtr{}, int16(0), int16(16), "", nil},
{&SomeStructWithUintFuncPtr{}, int16(0), int16(16), "", nil},
{SomeStructWithUintWithErrFunc{}, int16(0), int16(16), "", nil},
{&SomeStructWithUintWithErrFunc{}, int16(0), int16(16), "", nil},
{SomeStructWithUintWithErrFuncPtr{}, int16(0), int16(16), "", nil},
{&SomeStructWithUintWithErrFuncPtr{}, int16(0), int16(16), "", nil},
{SomeStructWithUint8Func{}, int16(0), int16(8), "", nil},
{&SomeStructWithUint8Func{}, int16(0), int16(8), "", nil},
{SomeStructWithUint8FuncPtr{}, int16(0), int16(8), "", nil},
{&SomeStructWithUint8FuncPtr{}, int16(0), int16(8), "", nil},
{SomeStructWithUint8WithErrFunc{}, int16(0), int16(8), "", nil},
{&SomeStructWithUint8WithErrFunc{}, int16(0), int16(8), "", nil},
{SomeStructWithUint8WithErrFuncPtr{}, int16(0), int16(8), "", nil},
{&SomeStructWithUint8WithErrFuncPtr{}, int16(0), int16(8), "", nil},
{SomeStructWithUint16Func{}, int16(0), int16(16), "", nil},
{&SomeStructWithUint16Func{}, int16(0), int16(16), "", nil},
{SomeStructWithUint16FuncPtr{}, int16(0), int16(16), "", nil},
{&SomeStructWithUint16FuncPtr{}, int16(0), int16(16), "", nil},
{SomeStructWithUint16WithErrFunc{}, int16(0), int16(16), "", nil},
{&SomeStructWithUint16WithErrFunc{}, int16(0), int16(16), "", nil},
{SomeStructWithUint16WithErrFuncPtr{}, int16(0), int16(16), "", nil},
{&SomeStructWithUint16WithErrFuncPtr{}, int16(0), int16(16), "", nil},
{SomeStructWithUint32Func{}, int16(0), int16(32), "", nil},
{&SomeStructWithUint32Func{}, int16(0), int16(32), "", nil},
{SomeStructWithUint32FuncPtr{}, int16(0), int16(32), "", nil},
{&SomeStructWithUint32FuncPtr{}, int16(0), int16(32), "", nil},
{SomeStructWithUint32WithErrFunc{}, int16(0), int16(32), "", nil},
{&SomeStructWithUint32WithErrFunc{}, int16(0), int16(32), "", nil},
{SomeStructWithUint32WithErrFuncPtr{}, int16(0), int16(32), "", nil},
{&SomeStructWithUint32WithErrFuncPtr{}, int16(0), int16(32), "", nil},
{SomeStructWithUint64Func{}, int16(0), int16(64), "", nil},
{&SomeStructWithUint64Func{}, int16(0), int16(64), "", nil},
{SomeStructWithUint64FuncPtr{}, int16(0), int16(64), "", nil},
{&SomeStructWithUint64FuncPtr{}, int16(0), int16(64), "", nil},
{SomeStructWithUint64WithErrFunc{}, int16(0), int16(64), "", nil},
{&SomeStructWithUint64WithErrFunc{}, int16(0), int16(64), "", nil},
{SomeStructWithUint64WithErrFuncPtr{}, int16(0), int16(64), "", nil},
{&SomeStructWithUint64WithErrFuncPtr{}, int16(0), int16(64), "", nil},
}
for i, test := range tests {
testhelpers.RunTest(t, test, i)
}
}