Skip to content

Commit 7609d8b

Browse files
committed
add tests
1 parent f12fbfd commit 7609d8b

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

decode_array.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (dec *Decoder) AddArray(v UnmarshalerJSONArray) error {
212212
}
213213

214214
// AddArrayNull decodes the JSON value within an object or an array to a UnmarshalerJSONArray.
215-
func (dec *Decoder) AddArrayNull(v UnmarshalerJSONArray) error {
215+
func (dec *Decoder) AddArrayNull(v interface{}) error {
216216
return dec.ArrayNull(v)
217217
}
218218

decode_array_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,26 @@ func TestDecodeArrayNullPtr(t *testing.T) {
412412
assert.Nil(t, err)
413413
assert.Nil(t, o.SubArray)
414414
})
415+
t.Run("sub array err, not closing arr", func(t *testing.T) {
416+
var o = &ObjectArrayNull{}
417+
var err = UnmarshalJSONObject([]byte(`{"subarray": [ `), o)
418+
assert.NotNil(t, err)
419+
})
420+
t.Run("sub array err, invalid string", func(t *testing.T) {
421+
var o = &ObjectArrayNull{}
422+
var err = UnmarshalJSONObject([]byte(`{"subarray":[",]}`), o)
423+
assert.NotNil(t, err)
424+
})
425+
t.Run("sub array err, invalid null", func(t *testing.T) {
426+
var o = &ObjectArrayNull{}
427+
var err = UnmarshalJSONObject([]byte(`{"subarray":nll}`), o)
428+
assert.NotNil(t, err)
429+
})
430+
t.Run("sub array err, empty", func(t *testing.T) {
431+
var o = &ObjectArrayNull{}
432+
var err = UnmarshalJSONObject([]byte(`{"subarray":`), o)
433+
assert.NotNil(t, err)
434+
})
415435
}
416436

417437
type testChannelArray chan *TestObj

decode_object_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ func (o *ObjectNull) UnmarshalJSONObject(dec *Decoder, k string) error {
939939
case "subobject":
940940
return dec.ObjectNull(&o.SubObject)
941941
case "subarray":
942-
return dec.ArrayNull(&o.SubArray)
942+
return dec.AddArrayNull(&o.SubArray)
943943
}
944944
return nil
945945
}

decode_slice_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,28 @@ func TestDecodeSlices(t *testing.T) {
7878
{
7979
name: "err slice float64",
8080
json: `{
81-
"sliceFloat64": ["",2.4,3.1]
81+
"sliceFloat64": [1.3",2.4,3.1]
8282
}`,
8383
err: true,
8484
},
8585
{
8686
name: "err slice str",
8787
json: `{
88-
"sliceString": [1,2.4,3.1]
88+
"sliceString": [",""]
8989
}`,
9090
err: true,
9191
},
9292
{
9393
name: "err slice int",
9494
json: `{
95-
"sliceInt": [true,2.4,3.1]
95+
"sliceInt": [1t,2,3]
9696
}`,
9797
err: true,
9898
},
9999
{
100100
name: "err slice bool",
101101
json: `{
102-
"sliceBool": [1,2.4,3.1]
102+
"sliceBool": [truo,false]
103103
}`,
104104
err: true,
105105
},

0 commit comments

Comments
 (0)