-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil_test.go
138 lines (109 loc) · 2.7 KB
/
util_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
package monadgo
import "reflect"
func ExampleMakeMap() {
m := makeMap(reflect.TypeOf(int(0)), reflect.TypeOf(int64(0)), -1).Interface()
printGet(m)
printGet(len(m.(map[int]int64)))
m = makeMap(reflect.TypeOf(int(0)), reflect.TypeOf(float64(0.0)), 2).Interface()
printGet(m)
printGet(len(m.(map[int]float64)))
// Output:
// map[], map[int]int64
// 0, int
// map[], map[int]float64
// 0, int
}
func ExampleMakeSlice() {
s := makeSlice(reflect.TypeOf(int(0))).Interface()
printGet(s)
printGet(len(s.([]int)))
printGet(cap(s.([]int)))
s = makeSlice(reflect.TypeOf(int(0)), 1).Interface()
printGet(s)
printGet(len(s.([]int)))
printGet(cap(s.([]int)))
s = makeSlice(reflect.TypeOf(int(0)), 1, 2).Interface()
printGet(s)
printGet(len(s.([]int)))
printGet(cap(s.([]int)))
// Output:
// [], []int
// 0, int
// 0, int
// [0], []int
// 1, int
// 1, int
// [0], []int
// 1, int
// 2, int
}
func ExampleAppendSlice() {
x := reflect.Value{}
y := reflect.ValueOf(10)
z := appendSlice(x, y).Interface()
printGet(z)
x = reflect.ValueOf([]int{1})
y = reflect.ValueOf(100)
z = appendSlice(x, y).Interface()
printGet(z)
// Output:
// [10], []int
// [1 100], []int
}
func ExampleMergeSlice() {
x := reflect.Value{}
y := reflect.ValueOf(10)
z := mergeSlice(x, y).Interface()
printGet(z)
x = reflect.ValueOf(100)
y = reflect.ValueOf(101)
z = mergeSlice(x, y).Interface()
printGet(z)
x = reflect.ValueOf([]int{100, 101})
y = reflect.ValueOf(102)
z = mergeSlice(x, y).Interface()
printGet(z)
x = reflect.ValueOf([]int{100, 101})
y = reflect.ValueOf([]int{102, 103})
z = mergeSlice(x, y).Interface()
printGet(z)
// Output:
// 10, int
// [100 101], []int
// [100 101 102], []int
// [100 101 102 103], []int
}
func ExampleMergeMap() {
x := reflect.Value{}
y := reflect.ValueOf(PairOf(1, 2))
z := mergeMap(x, y).Interface()
printGet(z)
x = reflect.ValueOf(PairOf(1, 2))
y = reflect.ValueOf(PairOf(3, 4))
z = mergeMap(x, y).Interface()
printGet(z)
x = reflect.ValueOf(map[int]int{1: 11})
y = reflect.ValueOf(PairOf(2, 22))
z = mergeMap(x, y).Interface()
printGet(z)
x = reflect.ValueOf(map[int]int{1: 11, 2: 22})
y = reflect.ValueOf(map[int]int{3: 33, 4: 44})
z = mergeMap(x, y).Interface()
printGet(z)
// Output:
// map[1:2], map[int]int
// map[1:2 3:4], map[int]int
// map[1:11 2:22], map[int]int
// map[1:11 2:22 3:33 4:44], map[int]int
}
func ExampleMergeKeyValue() {
x := reflect.Value{}
z := mergeKeyValue(x, reflect.ValueOf(1), reflect.ValueOf(11)).Interface()
printGet(z)
x = reflect.ValueOf(map[int]int{1: 11})
z = mergeKeyValue(x, reflect.ValueOf(1), reflect.ValueOf(22)).Interface()
printGet(z)
// Output:
// map[1:11], map[int]int
// map[1:22], map[int]int
}