mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: document and test overwrite of slice, map during Unmarshal
Fixes #8837. Change-Id: Iaaecbb0b324004cb74b16b764126b01315e6a16e Reviewed-on: https://go-review.googlesource.com/12209 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
parent
2d25318f08
commit
749b391c55
2 changed files with 16 additions and 0 deletions
|
|
@ -217,6 +217,9 @@ type XYZ struct {
|
|||
Z interface{}
|
||||
}
|
||||
|
||||
func sliceAddr(x []int) *[]int { return &x }
|
||||
func mapAddr(x map[string]int) *map[string]int { return &x }
|
||||
|
||||
var unmarshalTests = []unmarshalTest{
|
||||
// basic types
|
||||
{in: `true`, ptr: new(bool), out: true},
|
||||
|
|
@ -303,6 +306,12 @@ var unmarshalTests = []unmarshalTest{
|
|||
{in: `["X"]`, ptr: &umslicepT, out: &umsliceT},
|
||||
{in: `{"M":"X"}`, ptr: &umstructT, out: umstructT},
|
||||
|
||||
// Overwriting of data.
|
||||
// This is different from package xml, but it's what we've always done.
|
||||
// Now documented and tested.
|
||||
{in: `[2]`, ptr: sliceAddr([]int{1}), out: []int{2}},
|
||||
{in: `{"key": 2}`, ptr: mapAddr(map[string]int{"old": 0, "key": 1}), out: map[string]int{"key": 2}},
|
||||
|
||||
{
|
||||
in: `{
|
||||
"Level0": 1,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue