gojay

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

commit 7c729c5d9e969a2cb7528cd0c4a0382030a26439
parent d39ebfd77b4514e74dbbee7e589ea1d54eaeb82f
Author: francoispqt <francois@parquet.ninja>
Date:   Sun, 13 May 2018 17:45:35 +0800

add multiple edge case tests

Diffstat:
Mdecode_array_test.go | 8++++++++
Mdecode_number_test.go | 33+++++++++++++++++++++++++++++++++
Mdecode_object_test.go | 3++-
3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/decode_array_test.go b/decode_array_test.go @@ -241,6 +241,14 @@ func TestUnmarshalArrays(t *testing.T) { } } +func TestDecodeArrayNullError(t *testing.T) { + v := new(testDecodeSlice) + dec := NewDecoder(strings.NewReader("nall")) + err := dec.Decode(v) + assert.NotNil(t, err, "err should not be nil") + assert.IsType(t, InvalidJSONError(""), err, "err should be of type InvalidJSONError") +} + func TestSkipArray(t *testing.T) { testCases := []struct { json string diff --git a/decode_number_test.go b/decode_number_test.go @@ -380,6 +380,13 @@ func TestDecoderInt64(t *testing.T) { expectedResult: -800000, }, { + name: "basic-exponent-negative-positive-exp4", + json: "8ea+00a5", + expectedResult: 0, + err: true, + errType: InvalidJSONError(""), + }, + { name: "error1", json: "132zz4", expectedResult: 0, @@ -661,6 +668,11 @@ func TestDecoderInt32(t *testing.T) { }, { name: "basic-exponent-positive-positive-exp1", + json: "3.5e+005 ", + expectedResult: 350000, + }, + { + name: "basic-exponent-positive-positive-exp1", json: "3.5e+005", expectedResult: 350000, }, @@ -720,6 +732,11 @@ func TestDecoderInt32(t *testing.T) { expectedResult: -800000, }, { + name: "basic-float", + json: "8.32 ", + expectedResult: 8, + }, + { name: "error", json: "83zez4", expectedResult: 0, @@ -727,6 +744,13 @@ func TestDecoderInt32(t *testing.T) { errType: InvalidJSONError(""), }, { + name: "error", + json: "8ea00$aa5", + expectedResult: 0, + err: true, + errType: InvalidJSONError(""), + }, + { name: "error2", json: "-8e+00$aa5", expectedResult: 0, @@ -1121,3 +1145,12 @@ func TestDecoderFloat64(t *testing.T) { assert.IsType(t, InvalidJSONError(""), err, "err should be of type InvalidJSONError") }) } + +func TestDecodeNumberExra(t *testing.T) { + t.Run("skip-number-err", func(t *testing.T) { + dec := NewDecoder(strings.NewReader("123456afzfz343")) + _, err := dec.skipNumber() + assert.NotNil(t, err, "err should not be nil") + assert.IsType(t, InvalidJSONError(""), err, "err should be of type InvalidJSONError") + }) +} diff --git a/decode_object_test.go b/decode_object_test.go @@ -167,6 +167,7 @@ var jsonComplex = []byte(`{ } }, "testSkipNumber": 123.23, + "testSkipNumber2": 123.23 , "testBool": true, "testSkipBoolTrue": true, "testSkipBoolFalse": false, @@ -223,7 +224,7 @@ func TestDecodeObjComplex(t *testing.T) { result := jsonObjectComplex{} err := UnmarshalObject(jsonComplex, &result) assert.NotNil(t, err, "err should not be as invalid type as been encountered nil") - assert.Equal(t, `Cannot unmarshal to struct, wrong char '"' found at pos 614`, err.Error(), "err should not be as invalid type as been encountered nil") + assert.Equal(t, `Cannot unmarshal to struct, wrong char '"' found at pos 643`, err.Error(), "err should not be as invalid type as been encountered nil") assert.Equal(t, `{"test":"1","test1":2}`, result.Test, "result.Test is not expected value") assert.Equal(t, `\\\\\\n`, result.Test2, "result.Test2 is not expected value") assert.Equal(t, 1, result.Test3, "result.test3 is not expected value")