]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: add tests for InvalidUnmarshalError
authorDave Cheney <dave@cheney.net>
Wed, 1 Jan 2014 22:49:55 +0000 (09:49 +1100)
committerDave Cheney <dave@cheney.net>
Wed, 1 Jan 2014 22:49:55 +0000 (09:49 +1100)
R=golang-codereviews, shawn.p.smith
CC=golang-codereviews
https://golang.org/cl/41960047

src/pkg/encoding/json/decode_test.go

index 22c5f89f7981a1af5cb2c3f6d4ec44265e2ac1ed..c5a84ab832cab1c52834f9685c26db94c8da14a5 100644 (file)
@@ -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)
+               }
+       }
+}