-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfunction_test.go
More file actions
144 lines (124 loc) · 2.92 KB
/
function_test.go
File metadata and controls
144 lines (124 loc) · 2.92 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package urlquery
import (
"reflect"
"testing"
)
type testStruct struct {
Id int
}
func Test_unpackQueryKey_NotEnd(t *testing.T) {
key := "hts"
pre, suf := unpackQueryKey(key)
if pre != "hts" || suf != "" {
t.Error("unpack error")
}
}
func Test_unpackQueryKey_RightSquareBracketEnd(t *testing.T) {
key := "hts[0]"
pre, suf := unpackQueryKey(key)
if pre != "hts" || suf != "[0]" {
t.Error("unpack error")
}
}
func Test_unpackQueryKey_LeftSquareBracketEnd(t *testing.T) {
key := "[hts][0]"
pre, suf := unpackQueryKey(key)
if pre != "hts" || suf != "[0]" {
t.Error("unpack error")
}
}
func Test_repackArrayQueryKey(t *testing.T) {
key := "[hts][0]"
target := repackArrayQueryKey(key)
if target != "[hts][]" {
t.Error("failed to execute repackArrayQueryKey function")
}
}
func Test_repackArrayQueryKey1(t *testing.T) {
key := "hts]"
target := repackArrayQueryKey(key)
if target != "hts]" {
t.Error("failed to execute repackArrayQueryKey function")
}
}
func Test_repackArrayQueryKey2(t *testing.T) {
key := "[hts"
target := repackArrayQueryKey(key)
if target != "[hts" {
t.Error("failed to execute repackArrayQueryKey function")
}
}
func Test_genNextParentNode(t *testing.T) {
if genNextParentNode("", "test") != "test" {
t.Error("failed to execute genNextParentNode")
}
if genNextParentNode("p", "test") != "p[test]" {
t.Error("failed to execute genNextParentNode")
}
}
func Test_isZeroValue_Bool(t *testing.T) {
var a bool
res := isZeroValue(reflect.ValueOf(a))
if res != true {
t.Error("isZeroValue is error for bool")
}
}
func Test_isZeroValue_Complex(t *testing.T) {
var a complex64
res := isZeroValue(reflect.ValueOf(a))
if res != true {
t.Error("isZeroValue is error for complex64")
}
}
func Test_isZeroValue_Float(t *testing.T) {
var a float32
res := isZeroValue(reflect.ValueOf(a))
if res != true {
t.Error("isZeroValue failed for float32")
}
}
func Test_isZeroValue_Array(t *testing.T) {
var a [3]int
res := isZeroValue(reflect.ValueOf(a))
if res != true {
t.Error("isZeroValue failed for array")
}
a[1] = 0
res = isZeroValue(reflect.ValueOf(a))
if res != true {
t.Error("isZeroValue failed for array 1")
}
a[2] = 2
res = isZeroValue(reflect.ValueOf(a))
if res != false {
t.Error("isZeroValue failed for array 2")
}
}
func Test_isZeroValue_Pointer(t *testing.T) {
var a *int
res := isZeroValue(reflect.ValueOf(a))
if res != true {
t.Error("isZeroValue failed for pointer")
}
}
func Test_isZeroValue_Struct(t *testing.T) {
a := testStruct{0}
res := isZeroValue(reflect.ValueOf(a))
if res != true {
t.Error("isZeroValue failed for struct")
}
a.Id = 1
res = isZeroValue(reflect.ValueOf(a))
if res != false {
t.Error("isZeroValue failed for struct 1")
}
}
func Test_isZeroValue_UndefinedType(t *testing.T) {
var a error
defer func() {
if err := recover(); err == nil {
t.Error("dont not panic at undefined type")
}
}()
isZeroValue(reflect.ValueOf(a))
}