aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/decode_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/json/decode_test.go')
-rw-r--r--src/encoding/json/decode_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go
index 8dcb08cbd2..31ab61c733 100644
--- a/src/encoding/json/decode_test.go
+++ b/src/encoding/json/decode_test.go
@@ -2345,6 +2345,41 @@ func TestUnmarshalEmbeddedUnexported(t *testing.T) {
}
}
+func TestUnmarshalErrorAfterMultipleJSON(t *testing.T) {
+ tests := []struct {
+ in string
+ err error
+ }{{
+ in: `1 false null :`,
+ err: &SyntaxError{"invalid character ':' looking for beginning of value", 14},
+ }, {
+ in: `1 [] [,]`,
+ err: &SyntaxError{"invalid character ',' looking for beginning of value", 7},
+ }, {
+ in: `1 [] [true:]`,
+ err: &SyntaxError{"invalid character ':' after array element", 11},
+ }, {
+ in: `1 {} {"x"=}`,
+ err: &SyntaxError{"invalid character '=' after object key", 14},
+ }, {
+ in: `falsetruenul#`,
+ err: &SyntaxError{"invalid character '#' in literal null (expecting 'l')", 13},
+ }}
+ for i, tt := range tests {
+ dec := NewDecoder(strings.NewReader(tt.in))
+ var err error
+ for {
+ var v interface{}
+ if err = dec.Decode(&v); err != nil {
+ break
+ }
+ }
+ if !reflect.DeepEqual(err, tt.err) {
+ t.Errorf("#%d: got %#v, want %#v", i, err, tt.err)
+ }
+ }
+}
+
type unmarshalPanic struct{}
func (unmarshalPanic) UnmarshalJSON([]byte) error { panic(0xdead) }