| 1 |
package decoder |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"testing" |
| 6 |
"time" |
| 7 |
) |
| 8 |
|
| 9 |
type embeddedTime struct{ time.Time } |
| 10 |
|
| 11 |
type declaredTime struct{ time.Time } |
| 12 |
|
| 13 |
func (*declaredTime) UnmarshalJSON([]byte) error { return nil } |
| 14 |
|
| 15 |
func TestUnmarshalJSONDecoderRetainsNothing(t *testing.T) { |
| 16 |
// The bytes of the buffer are given to UnmarshalJSON of time.Time, and of a type which has it only by embedding |
| 17 |
// time.Time. |
| 18 |
if !newUnmarshalJSONDecoder(reflect.PointerTo(reflect.TypeOf(time.Time{})), "", "").retainsNothing { |
| 19 |
t.Fatal("time.Time is not known to keep nothing") |
| 20 |
} |
| 21 |
if !newUnmarshalJSONDecoder(reflect.PointerTo(reflect.TypeOf(embeddedTime{})), "", "").retainsNothing { |
| 22 |
t.Fatal("a type which only embeds time.Time is not known to keep nothing") |
| 23 |
} |
| 24 |
// A type which declares UnmarshalJSON may keep the bytes. |
| 25 |
if newUnmarshalJSONDecoder(reflect.PointerTo(reflect.TypeOf(declaredTime{})), "", "").retainsNothing { |
| 26 |
t.Fatal("a type which declares UnmarshalJSON may keep the bytes") |
| 27 |
} |
| 28 |
} |