From: Dave Cheney Date: Wed, 1 Jan 2014 22:49:55 +0000 (+1100) Subject: encoding/json: add tests for InvalidUnmarshalError X-Git-Tag: go1.3beta1~1074 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=66730120fa2ff7d58d22a7e1cf9a1a299572a907;p=gostls13.git encoding/json: add tests for InvalidUnmarshalError R=golang-codereviews, shawn.p.smith CC=golang-codereviews https://golang.org/cl/41960047 --- diff --git a/src/pkg/encoding/json/decode_test.go b/src/pkg/encoding/json/decode_test.go index 22c5f89f79..c5a84ab832 100644 --- a/src/pkg/encoding/json/decode_test.go +++ b/src/pkg/encoding/json/decode_test.go @@ -1316,3 +1316,26 @@ func TestPrefilled(t *testing.T) { } } } + +var invalidUnmarshalTests = []struct { + v interface{} + want string +}{ + {nil, "json: Unmarshal(nil)"}, + {struct{}{}, "json: Unmarshal(non-pointer struct {})"}, + {(*int)(nil), "json: Unmarshal(nil *int)"}, +} + +func TestInvalidUnmarshal(t *testing.T) { + buf := []byte(`{"a":"1"}`) + for _, tt := range invalidUnmarshalTests { + err := Unmarshal(buf, tt.v) + if err == nil { + t.Errorf("Unmarshal expecting error, got nil") + continue + } + if got := err.Error(); got != tt.want { + t.Errorf("Unmarshal = %q; want %q", got, tt.want) + } + } +}