-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
84 lines (79 loc) · 1.55 KB
/
utils_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
package simple_template
import (
"testing"
"reflect"
. "github.com/smartystreets/goconvey/convey"
)
func TestToParserValue(t *testing.T) {
Convey("test", t, func() {
testTable := []*struct {
Input interface{}
Output interface{}
}{
{
int(1),
float64(1),
},
{
float32(1),
float64(1),
},
{
[]byte("test"),
"test",
},
{
true,
true,
},
{
[]int{1, 2, 3},
[]interface{}{float64(1), float64(2), float64(3)},
},
{
[]string{"1", "2", "3"},
[]interface{}{"1", "2", "3"},
},
{
map[string]string{
"key1": "value1",
"key2": "2",
},
map[string]interface{}{
"key1": "value1",
"key2": "2",
},
},
{
map[string]interface{}{
"key1": "value1",
"key2": 2,
},
map[string]interface{}{
"key1": "value1",
"key2": float64(2),
},
},
}
for _, c := range testTable {
res, err := ToParserValue(c.Input)
So(err, ShouldBeNil)
if reflect.ValueOf(res).Type().Kind() == reflect.Array || reflect.ValueOf(res).Type().Kind() == reflect.Slice {
ra, ok := c.Output.([]interface{})
So(ok, ShouldBeTrue)
for i := 0; i < reflect.ValueOf(res).Len(); i++ {
ar := reflect.ValueOf(res).Index(i).Interface()
So(ar, ShouldEqual, ra[i])
So(ar, ShouldHaveSameTypeAs, ra[i])
}
continue
}
if reflect.ValueOf(res).Type().Kind() == reflect.Map {
So(reflect.DeepEqual(c.Output, res), ShouldBeTrue)
continue
}
So(res, ShouldEqual, c.Output)
So(res, ShouldHaveSameTypeAs, c.Output)
}
})
}