This covers the following cases: - Recursive types - Non-builtin identifiers (and recursive types) - time.Time - map[string]string - anonymous structs
(t *testing.T)
| 92 | // - map[string]string |
| 93 | // - anonymous structs |
| 94 | func Test1EncodeDecode(t *testing.T) { |
| 95 | f := 32.00 |
| 96 | tt := &TestType{ |
| 97 | F: &f, |
| 98 | Els: map[string]string{ |
| 99 | "thing_one": "one", |
| 100 | "thing_two": "two", |
| 101 | }, |
| 102 | Obj: struct { |
| 103 | ValueA string `msg:"value_a"` |
| 104 | ValueB []byte `msg:"value_b"` |
| 105 | }{ |
| 106 | ValueA: "here's the first inner value", |
| 107 | ValueB: []byte("here's the second inner value"), |
| 108 | }, |
| 109 | Child: nil, |
| 110 | Time: time.Now(), |
| 111 | Appended: msgp.Raw([]byte{}), // 'nil' |
| 112 | MapStringEmpty: map[string]struct{}{"Key": {}, "Key2": {}}, |
| 113 | MapStringEmpty2: map[string]EmptyStruct{"Key3": {}, "Key4": {}}, |
| 114 | } |
| 115 | |
| 116 | var buf bytes.Buffer |
| 117 | |
| 118 | err := msgp.Encode(&buf, tt) |
| 119 | if err != nil { |
| 120 | t.Fatal(err) |
| 121 | } |
| 122 | |
| 123 | tnew := new(TestType) |
| 124 | |
| 125 | err = msgp.Decode(&buf, tnew) |
| 126 | if err != nil { |
| 127 | t.Error(err) |
| 128 | } |
| 129 | |
| 130 | if !tt.Equal(tnew) { |
| 131 | t.Logf("in: %#v", tt) |
| 132 | t.Logf("out: %#v", tnew) |
| 133 | t.Fatal("objects not equal") |
| 134 | } |
| 135 | if tnew.Time.Location() != time.UTC { |
| 136 | t.Errorf("time location not UTC: %v", tnew.Time.Location()) |
| 137 | } |
| 138 | |
| 139 | tanother := new(TestType) |
| 140 | |
| 141 | buf.Reset() |
| 142 | msgp.Encode(&buf, tt) |
| 143 | |
| 144 | var left []byte |
| 145 | left, err = tanother.UnmarshalMsg(buf.Bytes()) |
| 146 | if err != nil { |
| 147 | t.Error(err) |
| 148 | } |
| 149 | if len(left) > 0 { |
| 150 | t.Errorf("%d bytes left", len(left)) |
| 151 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…