diff options
| author | Dave Cheney <dave@cheney.net> | 2014-01-02 09:49:55 +1100 |
|---|---|---|
| committer | Dave Cheney <dave@cheney.net> | 2014-01-02 09:49:55 +1100 |
| commit | 66730120fa2ff7d58d22a7e1cf9a1a299572a907 (patch) | |
| tree | 659b201738bcf47441ed29e4957baf458bfb5be1 /src/pkg/encoding | |
| parent | 4d239bcea270a56f1554524598e49d87e5c48e4f (diff) | |
| download | go-66730120fa2ff7d58d22a7e1cf9a1a299572a907.tar.xz | |
encoding/json: add tests for InvalidUnmarshalError
R=golang-codereviews, shawn.p.smith
CC=golang-codereviews
https://golang.org/cl/41960047
Diffstat (limited to 'src/pkg/encoding')
| -rw-r--r-- | src/pkg/encoding/json/decode_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
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) + } + } +} |
