Skip to content

Commit 10ed323

Browse files
committed
add tests
1 parent be7260a commit 10ed323

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

decode_number_int_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,12 @@ func TestDecoderInt64(t *testing.T) {
734734
json: "3e-3",
735735
expectedResult: 0,
736736
},
737+
{
738+
name: "before-exp-err-too-big",
739+
json: "10.11231242345325435464364643e1",
740+
expectedResult: 0,
741+
err: true,
742+
},
737743
{
738744
name: "error3",
739745
json: "0E40",
@@ -1401,6 +1407,12 @@ func TestDecoderInt32(t *testing.T) {
14011407
json: "-8e+005",
14021408
expectedResult: -800000,
14031409
},
1410+
{
1411+
name: "before-exp-err-too-big",
1412+
json: "10.11231242345325435464364643e1",
1413+
expectedResult: 0,
1414+
err: true,
1415+
},
14041416
{
14051417
name: "exponent-err-",
14061418
json: "0.1e",
@@ -2016,6 +2028,11 @@ func TestDecoderInt16(t *testing.T) {
20162028
json: "1.2E2",
20172029
expectedResult: 120,
20182030
},
2031+
{
2032+
name: "exponent too big",
2033+
json: "1000.202302302422324435342E2",
2034+
err: true,
2035+
},
20192036
{
20202037
name: "basic-exponent-positive-positive-exp1",
20212038
json: "3.5e+001 ",
@@ -2751,6 +2768,7 @@ func TestDecoderInt8(t *testing.T) {
27512768
json: "-3e01",
27522769
expectedResult: -30,
27532770
},
2771+
27542772
{
27552773
name: "error3",
27562774
json: "0E40",
@@ -2764,6 +2782,12 @@ func TestDecoderInt8(t *testing.T) {
27642782
expectedResult: 0,
27652783
err: true,
27662784
},
2785+
{
2786+
name: "before-exp-err-too-big",
2787+
json: "10.11231242345325435464364643e1",
2788+
expectedResult: 0,
2789+
err: true,
2790+
},
27672791
{
27682792
name: "exponent-err-too-big",
27692793
json: "0.1e10000000000000000000",

decode_object_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,15 @@ func TestDecodeObjectNull(t *testing.T) {
10381038
assert.NotNil(t, o.SubObject)
10391039
},
10401040
)
1041+
t.Run(
1042+
"err empty json",
1043+
func(t *testing.T) {
1044+
var o = &ObjectNull{}
1045+
var dec = NewDecoder(strings.NewReader(``))
1046+
var _, err = dec.decodeObjectNull(&o)
1047+
assert.NotNil(t, err)
1048+
},
1049+
)
10411050
t.Run(
10421051
"should return an error as type is not ptr",
10431052
func(t *testing.T) {

decode_sqlnull_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func TestDecodeSQLNullKeys(t *testing.T) {
231231
name string
232232
json string
233233
expectedResult *SQLDecodeObject
234+
err bool
234235
}{
235236
{
236237
name: "basic all valid",
@@ -358,13 +359,55 @@ func TestDecodeSQLNullKeys(t *testing.T) {
358359
},
359360
},
360361
},
362+
{
363+
name: "err string key",
364+
json: `{
365+
"s": "`,
366+
err: true,
367+
},
368+
{
369+
name: "err float key",
370+
json: `{
371+
"s": null,
372+
"f": 1",
373+
"i": null,
374+
"b": null
375+
}`,
376+
err: true,
377+
},
378+
{
379+
name: "err int key",
380+
json: `{
381+
"s": null,
382+
"f": null,
383+
"i": 1",
384+
"b": null
385+
}`,
386+
err: true,
387+
},
388+
{
389+
name: "err bool key",
390+
json: `{
391+
"s": null,
392+
"f": null,
393+
"i": null,
394+
"b": tra
395+
}`,
396+
err: true,
397+
},
361398
}
362399

363400
for _, testCase := range testCases {
364401
t.Run(testCase.name, func(t *testing.T) {
365402
var o = &SQLDecodeObject{}
366403
var dec = NewDecoder(strings.NewReader(testCase.json))
367404
var err = dec.Decode(o)
405+
406+
if testCase.err {
407+
require.NotNil(t, err)
408+
return
409+
}
410+
368411
require.Nil(t, err)
369412
require.Equal(
370413
t,

decode_string_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,14 @@ func TestDecoderSkipEscapedStringError3(t *testing.T) {
702702
assert.IsType(t, InvalidJSONError(""), err, "err must be of type InvalidJSONError")
703703
}
704704

705+
func TestDecoderSkipEscapedStringError4(t *testing.T) {
706+
dec := NewDecoder(strings.NewReader(`\u12`))
707+
defer dec.Release()
708+
err := dec.skipEscapedString()
709+
assert.NotNil(t, err, "Err must be nil")
710+
assert.IsType(t, InvalidJSONError(""), err, "err must be of type InvalidJSONError")
711+
}
712+
705713
func TestDecoderSkipStringError(t *testing.T) {
706714
dec := NewDecoder(strings.NewReader(`invalid`))
707715
defer dec.Release()

0 commit comments

Comments
 (0)