diff options
author | Daniel Martí <mvdan@mvdan.cc> | 2020-05-20 17:03:31 +0000 |
---|---|---|
committer | Daniel Martí <mvdan@mvdan.cc> | 2020-05-28 22:17:10 +0000 |
commit | 107ebb178176f00c988a40943446af6f672b1e63 (patch) | |
tree | fdcb3be3fe51241e9f50aa9792bf3ebabee44b32 /src/encoding/json/decode_test.go | |
parent | 86ed0955bf58ecb738b87892b4377e556e2cc88a (diff) | |
download | go-git-107ebb178176f00c988a40943446af6f672b1e63.tar.gz |
Revert "encoding/json: reuse values when decoding map elements"
This reverts golang.org/cl/179337.
Reason for revert: broke a few too many reasonably valid Go programs.
The previous behavior was perhaps less consistent, but the docs were
never very clear about when the decoder merges with existing values,
versus replacing existing values altogether.
Fixes #39149.
Change-Id: I1c1d857709b8398969fe421aa962f6b62f91763a
Reviewed-on: https://go-review.googlesource.com/c/go/+/234559
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Diffstat (limited to 'src/encoding/json/decode_test.go')
-rw-r--r-- | src/encoding/json/decode_test.go | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index a62488d447..5ac1022207 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -2569,57 +2569,3 @@ func TestUnmarshalMaxDepth(t *testing.T) { } } } - -func TestUnmarshalMapPointerElem(t *testing.T) { - type S struct{ Unchanged, Changed int } - input := []byte(`{"S":{"Changed":5}}`) - want := S{1, 5} - - // First, a map with struct pointer elements. The key-value pair exists, - // so reuse the existing value. - s := &S{1, 2} - ptrMap := map[string]*S{"S": s} - if err := Unmarshal(input, &ptrMap); err != nil { - t.Fatal(err) - } - if s != ptrMap["S"] { - t.Fatal("struct pointer element in map was completely replaced") - } - if got := *s; got != want { - t.Fatalf("want %#v, got %#v", want, got) - } - - // Second, a map with struct elements. The key-value pair exists, but - // the value isn't addresable, so make a copy and use that. - s = &S{1, 2} - strMap := map[string]S{"S": *s} - if err := Unmarshal(input, &strMap); err != nil { - t.Fatal(err) - } - if *s == strMap["S"] { - t.Fatal("struct element in map wasn't copied") - } - if got := strMap["S"]; got != want { - t.Fatalf("want %#v, got %#v", want, got) - } - - // Finally, check the cases where the key-value pair exists, but the - // value is zero. - want = S{0, 5} - - ptrMap = map[string]*S{"S": nil} - if err := Unmarshal(input, &ptrMap); err != nil { - t.Fatal(err) - } - if got := *ptrMap["S"]; got != want { - t.Fatalf("want %#v, got %#v", want, got) - } - - strMap = map[string]S{"S": {}} - if err := Unmarshal(input, &strMap); err != nil { - t.Fatal(err) - } - if got := strMap["S"]; got != want { - t.Fatalf("want %#v, got %#v", want, got) - } -} |