1
|
|
|
package internal |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"fmt" |
5
|
|
|
"reflect" |
6
|
|
|
"testing" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
func TestIsArray(t *testing.T) { |
10
|
|
|
testData := getTestData() |
11
|
|
|
key := "is_array" |
12
|
|
|
test := testData[key] |
13
|
|
|
a := test.output |
14
|
|
|
b := IsArray(test.inputValue) |
15
|
|
|
if !reflect.DeepEqual(a, b) { |
16
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
func TestIsSlice(t *testing.T) { |
21
|
|
|
testData := getTestData() |
22
|
|
|
key := "is_slice" |
23
|
|
|
test := testData[key] |
24
|
|
|
a := test.output |
25
|
|
|
b := IsSlice(test.inputValue) |
26
|
|
|
if !reflect.DeepEqual(a, b) { |
27
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
func TestIsString(t *testing.T) { |
32
|
|
|
testData := getTestData() |
33
|
|
|
key := "is_string" |
34
|
|
|
test := testData[key] |
35
|
|
|
a := test.output |
36
|
|
|
b := IsString(test.inputValue) |
37
|
|
|
if !reflect.DeepEqual(a, b) { |
38
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
func TestIsBool(t *testing.T) { |
43
|
|
|
testData := getTestData() |
44
|
|
|
key := "is_bool" |
45
|
|
|
test := testData[key] |
46
|
|
|
a := test.output |
47
|
|
|
b := IsBool(test.inputValue) |
48
|
|
|
if !reflect.DeepEqual(a, b) { |
49
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
func TestIsInteger(t *testing.T) { |
54
|
|
|
testData := getTestData() |
55
|
|
|
key := "is_integer" |
56
|
|
|
test := testData[key] |
57
|
|
|
a := test.output |
58
|
|
|
b := IsInteger(test.inputValue) |
59
|
|
|
if !reflect.DeepEqual(a, b) { |
60
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
func TestIsFloat(t *testing.T) { |
65
|
|
|
testData := getTestData() |
66
|
|
|
key := "is_float" |
67
|
|
|
test := testData[key] |
68
|
|
|
a := test.output |
69
|
|
|
b := IsFloat(test.inputValue) |
70
|
|
|
if !reflect.DeepEqual(a, b) { |
71
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
func TestIsNumber(t *testing.T) { |
76
|
|
|
testData := getTestData() |
77
|
|
|
key := "is_number" |
78
|
|
|
test := testData[key] |
79
|
|
|
a := test.output |
80
|
|
|
b := IsNumber(test.inputValue) |
81
|
|
|
if !reflect.DeepEqual(a, b) { |
82
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
func TestIsFunc(t *testing.T) { |
87
|
|
|
testData := getTestData() |
88
|
|
|
key := "is_func" |
89
|
|
|
test := testData[key] |
90
|
|
|
a := test.output |
91
|
|
|
b := IsFunc(test.inputValue) |
92
|
|
|
if !reflect.DeepEqual(a, b) { |
93
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
func TestIsStruct(t *testing.T) { |
98
|
|
|
testData := getTestData() |
99
|
|
|
key := "is_struct" |
100
|
|
|
test := testData[key] |
101
|
|
|
a := test.output |
102
|
|
|
b := IsStruct(test.inputValue) |
103
|
|
|
if !reflect.DeepEqual(a, b) { |
104
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
func TestIsPointer(t *testing.T) { |
109
|
|
|
testData := getTestData() |
110
|
|
|
key := "is_pointer" |
111
|
|
|
test := testData[key] |
112
|
|
|
a := test.output |
113
|
|
|
b := IsPointer(test.inputValue) |
114
|
|
|
if !reflect.DeepEqual(a, b) { |
115
|
|
|
t.Errorf("operator.IsPointer does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
func TestIsChan(t *testing.T) { |
120
|
|
|
testData := getTestData() |
121
|
|
|
key := "is_chan" |
122
|
|
|
test := testData[key] |
123
|
|
|
a := test.output |
124
|
|
|
b := IsChan(test.inputValue) |
125
|
|
|
if !reflect.DeepEqual(a, b) { |
126
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
func TestIsMap(t *testing.T) { |
131
|
|
|
testData := getTestData() |
132
|
|
|
key := "is_map" |
133
|
|
|
test := testData[key] |
134
|
|
|
a := test.output |
135
|
|
|
b := IsMap(test.inputValue) |
136
|
|
|
if !reflect.DeepEqual(a, b) { |
137
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", key, a, b) |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
func TestIsEqual(t *testing.T) { |
142
|
|
|
a := IsEqual("hello gotilty", "hello gotilty") |
143
|
|
|
b := true |
144
|
|
|
if !reflect.DeepEqual(a, b) { |
145
|
|
|
t.Errorf("Convert.ToUint64 does not works expected\ncase: %s\nexpected: %v taken: %v", "is_equal", a, b) |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
func getTestData() map[string]struct { |
150
|
|
|
inputValue interface{} |
151
|
|
|
output bool |
152
|
|
|
} { |
153
|
|
|
testData := map[string]struct { |
154
|
|
|
inputValue interface{} |
155
|
|
|
output bool |
156
|
|
|
}{ |
157
|
|
|
"is_array": { |
158
|
|
|
inputValue: [4]int64{-100, -5, 30, 100}, |
159
|
|
|
output: true, |
160
|
|
|
}, |
161
|
|
|
"is_slice": { |
162
|
|
|
inputValue: []int64{-100, -5, 30, 100}, |
163
|
|
|
output: true, |
164
|
|
|
}, |
165
|
|
|
"is_string": { |
166
|
|
|
inputValue: "hello gotilty", |
167
|
|
|
output: true, |
168
|
|
|
}, |
169
|
|
|
"is_bool": { |
170
|
|
|
inputValue: false, |
171
|
|
|
output: true, |
172
|
|
|
}, |
173
|
|
|
"is_integer": { |
174
|
|
|
inputValue: int16(2), |
175
|
|
|
output: true, |
176
|
|
|
}, |
177
|
|
|
"is_float": { |
178
|
|
|
inputValue: float64(1523.2323), |
179
|
|
|
output: true, |
180
|
|
|
}, |
181
|
|
|
"is_number": { |
182
|
|
|
inputValue: float64(1523.2323), |
183
|
|
|
output: true, |
184
|
|
|
}, |
185
|
|
|
"is_func": { |
186
|
|
|
inputValue: func() { |
187
|
|
|
fmt.Println("hello gotilty") |
188
|
|
|
}, |
189
|
|
|
output: true, |
190
|
|
|
}, |
191
|
|
|
"is_struct": { |
192
|
|
|
inputValue: user{ |
193
|
|
|
name: "Martha", |
194
|
|
|
age: 15, |
195
|
|
|
}, |
196
|
|
|
output: true, |
197
|
|
|
}, |
198
|
|
|
"is_pointer": { |
199
|
|
|
inputValue: &user{ |
200
|
|
|
name: "Martha", |
201
|
|
|
age: 15, |
202
|
|
|
}, |
203
|
|
|
output: true, |
204
|
|
|
}, |
205
|
|
|
"is_chan": { |
206
|
|
|
inputValue: make(chan int), |
207
|
|
|
output: true, |
208
|
|
|
}, |
209
|
|
|
"is_map": { |
210
|
|
|
inputValue: map[string]struct { |
211
|
|
|
test bool |
212
|
|
|
}{ |
213
|
|
|
"test": { |
214
|
|
|
test: true, |
215
|
|
|
}, |
216
|
|
|
}, |
217
|
|
|
output: true, |
218
|
|
|
}, |
219
|
|
|
} |
220
|
|
|
return testData |
221
|
|
|
} |
222
|
|
|
|