aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/encoding
diff options
context:
space:
mode:
authorDave Cheney <dave@cheney.net>2014-01-02 09:49:55 +1100
committerDave Cheney <dave@cheney.net>2014-01-02 09:49:55 +1100
commit66730120fa2ff7d58d22a7e1cf9a1a299572a907 (patch)
tree659b201738bcf47441ed29e4957baf458bfb5be1 /src/pkg/encoding
parent4d239bcea270a56f1554524598e49d87e5c48e4f (diff)
downloadgo-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.go23
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)
+ }
+ }
+}