gojay

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

commit c35963f96584327d30ee89005766d166d4b50626
parent 1426f53d34581ed3a2c2fff82ee7413811fd20d3
Author: francoispqt <francois@parquet.ninja>
Date:   Sat, 19 May 2018 18:45:48 +0800

add tests

Diffstat:
Mdecode_array_test.go | 6++++++
Mdecode_number.go | 1+
Mdecode_number_test.go | 7+++++++
3 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/decode_array_test.go b/decode_array_test.go @@ -42,6 +42,12 @@ func TestSliceInts(t *testing.T) { expectedResult: testSliceInts{}, }, { + name: "invalid-json", + json: "[", + expectedResult: testSliceInts{}, + err: true, + }, + { name: "floats", json: "[1,2,3,43567788543,457.7765,432,0,0.45]", expectedResult: testSliceInts{1, 2, 3, 43567788543, 457, 432, 0, 0}, diff --git a/decode_number.go b/decode_number.go @@ -96,6 +96,7 @@ func (dec *Decoder) getExponent() int64 { // if nothing return 0 // could raise error if start == end { + dec.raiseInvalidJSONErr(dec.cursor) return 0 } return dec.atoi64(start, end) diff --git a/decode_number_test.go b/decode_number_test.go @@ -14,4 +14,11 @@ func TestDecodeNumberExra(t *testing.T) { assert.NotNil(t, err, "err should not be nil") assert.IsType(t, InvalidJSONError(""), err, "err should be of type InvalidJSONError") }) + t.Run("get-exponent-err", func(t *testing.T) { + v := 0 + dec := NewDecoder(strings.NewReader("1.2Ea")) + err := dec.Decode(&v) + assert.NotNil(t, err, "err should not be nil") + assert.IsType(t, InvalidJSONError(""), err, "err should be of type InvalidJSONError") + }) }