encoding/json: fix the broken "overwriting of data" tests
encoding/json: fix the broken "overwriting of data" tests

Because TestUnmarshal actually allocates a new value to decode into
using ptr's pointer type, any existing data is thrown away. This was
harmless in alomst all of the test cases, minus the "overwriting of
data" ones added in 2015 in CL 12209.

I spotted that nothing covered decoding a JSON array with few elements
into a slice which already had many elements. I initially assumed that
the code was buggy or that some code could be removed, when in fact
there simply wasn't any code covering the edge case.

Move those two tests to TestPrefilled, which already served a very
similar purpose. Remove the map case, as TestPrefilled already has
plenty of prefilled map cases. Moreover, we no longer reset an entire
map when decoding, as per the godoc:

	To unmarshal a JSON object into a map, Unmarshal first
	establishes a map to use. If the map is nil, Unmarshal allocates
	a new map. Otherwise Unmarshal reuses the existing map, keeping
	existing entries.

Finally, to ensure that ptr is used correctly in the future, make
TestUnmarshal error if it's anything other than a pointer to a zero
value. That is, the only correct use should be new(type). Don't rename
the ptr field, as that would be extremely noisy and cause unwanted merge
conflicts.

Change-Id: I41e3ecfeae42d877ac5443a6bd622ac3d6c8120c
Reviewed-on: https://go-review.googlesource.com/c/go/+/185738
Run-TryBot: Daniel Martí <29bf28b42a938ace12a5819da4ed4ba03d82f315@mvdan.cc>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>
Reviewed-by: Emmanuel Odeke <277f8eaa8c7dfbc55c17bf5e30561c1a9c45c569@gmail.com>

akutz/go,akutz/go,golang/go,CAFxX/go,nawawi/go,nawawi/go,nawawi/go,golang/go,akutz/go,nawawi/go,cloudflare/go,cloudflare/go,cloudflare/go,akutz/go,golang/go,nawawi/go,CAFxX/go,CAFxX/go,CAFxX/go,akutz/go,cloudflare/go,CAFxX/go,CAFxX/go,golang/go,akutz/go,golang/go,akutz/go,akutz/go,cloudflare/go,golang/go,cloudflare/go,CAFxX/go,cloudflare/go,nawawi/go,golang/go,nawawi/go,cloudflare/go,CAFxX/go,nawawi/go,golang/go