-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreflect_util_test.go
More file actions
126 lines (122 loc) · 2.64 KB
/
reflect_util_test.go
File metadata and controls
126 lines (122 loc) · 2.64 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
package nosql
import (
"reflect"
"testing"
)
func TestInspectObject(t *testing.T) {
type args struct {
any interface{}
}
tests := []struct {
name string
args args
want ObjectInfo
}{
{
"is Array",
args{
any: []int{1},
},
ObjectInfo{isArray: true, value: []int{1}},
},
{
"is Object",
args{ObjectInfo{}},
ObjectInfo{isObject: true, value: ObjectInfo{}},
},
{
"is Object",
args{map[string]string{}},
ObjectInfo{isObject: true, value: map[string]string{}},
},
{
"is String",
args{"hello world"},
ObjectInfo{isString: true, value: "hello world"},
},
{
"is Number",
args{1},
ObjectInfo{isNumber: true, value: 1},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := InspectObject(tt.args.any); !reflect.DeepEqual(got, tt.want) {
t.Errorf("InspectObject() = %v, want %v", got, tt.want)
}
})
}
}
func TestObjectInfo_Value(t *testing.T) {
type fields struct {
isArray bool
isObject bool
isString bool
isNumber bool
value interface{}
}
tests := []struct {
name string
fields fields
want interface{}
}{
{"Info.Value", fields{isString: true, value: "1"}, "1"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := &ObjectInfo{
isArray: tt.fields.isArray,
isObject: tt.fields.isObject,
isString: tt.fields.isString,
isNumber: tt.fields.isNumber,
value: tt.fields.value,
}
if got := o.Value(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ObjectInfo.Value() = %v, want %v", got, tt.want)
}
})
}
}
func TestObjectInfo_GetInnerInfo(t *testing.T) {
type fields struct {
isArray bool
isObject bool
isString bool
isNumber bool
value interface{}
}
tests := []struct {
name string
fields fields
want map[string]ObjectInfo
}{
{
"Info.GetInnerInfo for map",
fields{isString: true, value: map[string]interface{}{"hello": "world"}},
map[string]ObjectInfo{"hello": ObjectInfo{isString: true, value: "world"}},
},
{
"Info.GetInnerInfo for slice",
fields{isString: true, value: []string{"hello", "world"}},
map[string]ObjectInfo{
"0": ObjectInfo{isString: true, value: "hello"},
"1": ObjectInfo{isString: true, value: "world"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := &ObjectInfo{
isArray: tt.fields.isArray,
isObject: tt.fields.isObject,
isString: tt.fields.isString,
isNumber: tt.fields.isNumber,
value: tt.fields.value,
}
if got := o.GetInnerInfo(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ObjectInfo.GetInnerInfo() = %v, want %v", got, tt.want)
}
})
}
}