gojay

high performance JSON encoder/decoder with stream API for Golang
git clone git://git.lair.cx/gojay
Log | Files | Refs | README | LICENSE

commit 7609d8b6ed1622f4be1cb3b5bd56d5b50e2c8ba1
parent f12fbfd432c9c3c4bde85f747db806a87501ae93
Author: francoispqt <francois@parquet.ninja>
Date:   Sat, 23 Mar 2019 15:17:41 +0800

add tests

Diffstat:
Mdecode_array.go | 2+-
Mdecode_array_test.go | 20++++++++++++++++++++
Mdecode_object_test.go | 2+-
Mdecode_slice_test.go | 8++++----
4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/decode_array.go b/decode_array.go @@ -212,7 +212,7 @@ func (dec *Decoder) AddArray(v UnmarshalerJSONArray) error { } // AddArrayNull decodes the JSON value within an object or an array to a UnmarshalerJSONArray. -func (dec *Decoder) AddArrayNull(v UnmarshalerJSONArray) error { +func (dec *Decoder) AddArrayNull(v interface{}) error { return dec.ArrayNull(v) } diff --git a/decode_array_test.go b/decode_array_test.go @@ -412,6 +412,26 @@ func TestDecodeArrayNullPtr(t *testing.T) { assert.Nil(t, err) assert.Nil(t, o.SubArray) }) + t.Run("sub array err, not closing arr", func(t *testing.T) { + var o = &ObjectArrayNull{} + var err = UnmarshalJSONObject([]byte(`{"subarray": [ `), o) + assert.NotNil(t, err) + }) + t.Run("sub array err, invalid string", func(t *testing.T) { + var o = &ObjectArrayNull{} + var err = UnmarshalJSONObject([]byte(`{"subarray":[",]}`), o) + assert.NotNil(t, err) + }) + t.Run("sub array err, invalid null", func(t *testing.T) { + var o = &ObjectArrayNull{} + var err = UnmarshalJSONObject([]byte(`{"subarray":nll}`), o) + assert.NotNil(t, err) + }) + t.Run("sub array err, empty", func(t *testing.T) { + var o = &ObjectArrayNull{} + var err = UnmarshalJSONObject([]byte(`{"subarray":`), o) + assert.NotNil(t, err) + }) } type testChannelArray chan *TestObj diff --git a/decode_object_test.go b/decode_object_test.go @@ -939,7 +939,7 @@ func (o *ObjectNull) UnmarshalJSONObject(dec *Decoder, k string) error { case "subobject": return dec.ObjectNull(&o.SubObject) case "subarray": - return dec.ArrayNull(&o.SubArray) + return dec.AddArrayNull(&o.SubArray) } return nil } diff --git a/decode_slice_test.go b/decode_slice_test.go @@ -78,28 +78,28 @@ func TestDecodeSlices(t *testing.T) { { name: "err slice float64", json: `{ - "sliceFloat64": ["",2.4,3.1] + "sliceFloat64": [1.3",2.4,3.1] }`, err: true, }, { name: "err slice str", json: `{ - "sliceString": [1,2.4,3.1] + "sliceString": [",""] }`, err: true, }, { name: "err slice int", json: `{ - "sliceInt": [true,2.4,3.1] + "sliceInt": [1t,2,3] }`, err: true, }, { name: "err slice bool", json: `{ - "sliceBool": [1,2.4,3.1] + "sliceBool": [truo,false] }`, err: true, },