forked from doublerebel/bellows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
87 lines (74 loc) · 1.3 KB
/
main_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
package bellows
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
var (
example = map[string]interface{}{
"a": "b",
"b": []string{"1", "2", "3"},
"c": []interface{}{
map[string]interface{}{"d": 1, "e": true, "k": []int{5, 6, 7}},
map[string]interface{}{"d": 2, "e": false, "t": "112"},
},
}
flat = Flatten(example)
)
type A struct {
B
F int
Inner Inner
}
type Inner struct {
B
V string
}
type B struct {
C string
D int
}
func TestAll(t *testing.T) {
assert := assert.New(t)
flat := Flatten(example)
expanded := Expand(flat)
expecting, _ := json.Marshal(example)
actual, _ := json.Marshal(expanded)
assert.Equal(expecting, actual)
}
func TestAnonStructFlatten(t *testing.T) {
expecting := map[string]interface{}{
"F": 1,
"C": "test",
"D": 2,
"Inner.C": "",
"Inner.D": 0,
"Inner.V": "",
}
src := A{
F: 1,
B: B{
C: "test",
D: 2,
},
Inner: Inner{},
}
actual := Flatten(src)
assert.Equal(t, expecting, actual)
}
func BenchmarkFlatten(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Flatten(example)
}
}
func BenchmarkExpand(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Expand(flat)
}
}
func BenchmarkAll(b *testing.B) {
for i := 0; i < b.N; i++ {
flat := Flatten(example)
_ = Expand(flat)
}
}