1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
16 func (s Struct1) Method1() {}
18 type Interface1 interface {
24 ptrStruct = &Struct1{2}
25 emptyIface interface{} = Struct1{3}
26 iface1 Interface1 = Struct1{4}
27 sliceStruct = []Struct1{{5}, {6}, {7}}
28 ptrSliceStruct = []*Struct1{{8}, {9}, {10}}
30 valueMap = map[string]interface{}{
31 "bytes": []byte{0x61, 0x62, 0x63, 0x64},
44 "float32": float32(5),
45 "float64": float64(5),
46 "array": [5]int{1, 2, 3, 4, 5},
47 "slice": []int{1, 2, 3, 4, 5},
48 "emptyIf": emptyIface,
50 "map": map[string]string{"foo": "bar"},
51 "ptrStruct": ptrStruct,
53 "sliceStruct": sliceStruct,
54 "ptrSliceStruct": ptrSliceStruct,
58 // Test passing all kinds of data between serialize and deserialize.
59 func TestRoundTrip(t *testing.T) {
60 for _, expected := range valueMap {
61 bytes, err := Serialize(expected)
67 ptrActual := reflect.New(reflect.TypeOf(expected)).Interface()
68 err = Deserialize(bytes, ptrActual)
74 actual := reflect.ValueOf(ptrActual).Elem().Interface()
75 if !reflect.DeepEqual(expected, actual) {
76 t.Errorf("(expected) %T %v != %T %v (actual)", expected, expected, actual, actual)
81 func zeroMap(arg map[string]interface{}) map[string]interface{} {
82 result := map[string]interface{}{}
83 for key, value := range arg {
84 result[key] = reflect.Zero(reflect.TypeOf(value)).Interface()