-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreflect_test.go
67 lines (58 loc) · 1.17 KB
/
reflect_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
package karma
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReflect(t *testing.T) {
test := assert.New(t)
delimiter := BranchDelimiter
defer func() {
BranchDelimiter = delimiter
}()
BranchDelimiter = "* "
type Quo struct {
Q bool
w string
}
foo := struct {
Bar struct {
SliceStrings []string
SimpleStruct struct {
Int int
}
}
SliceStructs []Quo
Map map[string][]int
}{}
foo.Bar.SliceStrings = []string{"a", "b"}
foo.Bar.SimpleStruct.Int = 11
foo.SliceStructs = append(foo.SliceStructs, Quo{
Q: true,
w: "w1",
})
foo.SliceStructs = append(foo.SliceStructs, Quo{
Q: false,
w: "w",
})
foo.Map = map[string][]int{
"a": []int{1, 2},
"b": []int{3, 4},
}
values := DescribeDeep("foo", foo).GetKeyValuePairs()
chunks := []string{}
for i := 0; i < len(values); i += 2 {
chunks = append(chunks, fmt.Sprintf("%s=%v", values[i], values[i+1]))
}
test.EqualValues(
[]string{
"foo.Bar.SliceStrings[0]=a",
"foo.Bar.SliceStrings[1]=b",
"foo.Bar.SimpleStruct.Int=11",
"foo.SliceStructs[0].Q=true",
"foo.SliceStructs[1].Q=false",
"foo.Map=map[a:[1 2] b:[3 4]]",
},
chunks,
)
}