-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform_test.go
124 lines (118 loc) · 3.07 KB
/
transform_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
package go_property_mapper
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestTrasformSingleLevel(t *testing.T) {
a := &A{
Id: 90382,
Name: "KK",
Address: "Patna",
Phone: 9019010,
Salary: 55,
}
dest := &ADAO{}
obj, err := Transform(a, dest)
if err != nil {
panic(err)
}
dao := obj.(*ADAO)
assert.Equal(t, dao.Id, 90382)
assert.Equal(t, dao.Name, "KK")
assert.Equal(t, dao.Address, "Patna")
assert.Equal(t, dao.Phone, int64(9019010))
assert.Equal(t, dao.Salary, float64(55))
}
func TestTransformCollection(t *testing.T) {
aSlice := &ASlice{
Slice: []string{"Apple", "Ball", "Cat"},
}
bSlice := &BSlice{}
obj, err := Transform(aSlice, bSlice)
if err != nil {
panic(err)
}
bs := obj.(*BSlice)
assert.Equal(t, len(bs.Slice), 3)
assert.Equal(t, bs.Slice[0], "Apple")
assert.Equal(t, bs.Slice[1], "Ball")
assert.Equal(t, bs.Slice[2], "Cat")
aMap := &AMap{
Map: map[int]string{1: "one", 100: "hundred", 36: "thirty-six"},
}
bMap := &BMap{}
obj, err = Transform(aMap, bMap)
if err != nil {
panic(err)
}
bm := obj.(*BMap)
assert.Equal(t, len(bm.Map), 3)
assert.Equal(t, bm.Map[1], "one")
assert.Equal(t, bm.Map[100], "hundred")
assert.Equal(t, bm.Map[36], "thirty-six")
}
func TestTransformCollections(t *testing.T) {
aCollection := &ACollection{
Slice: []int{9, 11, 2001, 30, 9},
Map: map[string]float64{"house": 3.0, "car": 2.2, "weight": 74.72},
}
bCollection := &BCollection{}
obj, err := Transform(aCollection, bCollection)
if err != nil {
panic(err)
}
bm := obj.(*BCollection)
assert.Equal(t, len(bm.Slice), 5)
assert.Equal(t, len(bm.Map), 3)
assert.Equal(t, bm.Slice[0], 9)
assert.Equal(t, bm.Slice[1], 11)
assert.Equal(t, bm.Slice[2], 2001)
assert.Equal(t, bm.Slice[3], 30)
assert.Equal(t, bm.Slice[4], 9)
assert.Equal(t, bm.Map["house"], float64(3.0))
assert.Equal(t, bm.Map["car"], float64(2.2))
assert.Equal(t, bm.Map["weight"], float64(74.72))
}
func TestTransformComplex(t *testing.T) {
a := &A{
Id: 90382,
Name: "KK",
Address: "Patna",
Phone: 9019010,
Salary: 55,
}
aSlice := &ASlice{
Slice: []string{"Apple", "Ball", "Cat"},
}
aMap := &AMap{
Map: map[int]string{1: "one", 100: "hundred", 36: "thirty-six"},
}
aComplex := &AComplex{
A: a,
SlicePtr: aSlice,
MapPtr: aMap,
Info: "AComplex",
Row: 3112022,
}
bComplex := &BComplex{}
obj, err := Transform(aComplex, bComplex)
if err != nil {
panic(err)
}
bm := obj.(*BComplex)
assert.Equal(t, bm.A.Id, 90382)
assert.Equal(t, bm.A.Name, "KK")
assert.Equal(t, bm.A.Address, "Patna")
assert.Equal(t, bm.A.Phone, int64(9019010))
assert.Equal(t, bm.A.Salary, float64(55))
assert.Equal(t, len(bm.SlicePtr.Slice), 3)
assert.Equal(t, bm.SlicePtr.Slice[0], "Apple")
assert.Equal(t, bm.SlicePtr.Slice[1], "Ball")
assert.Equal(t, bm.SlicePtr.Slice[2], "Cat")
assert.Equal(t, len(bm.MapPtr.Map), 3)
assert.Equal(t, bm.MapPtr.Map[1], "one")
assert.Equal(t, bm.MapPtr.Map[100], "hundred")
assert.Equal(t, bm.MapPtr.Map[36], "thirty-six")
assert.Equal(t, bm.Info, "AComplex")
assert.Equal(t, bm.Row, 3112022)
}