francoispqt / gojay

high performance JSON encoder/decoder with stream API for Golang
MIT License
2.11k stars 112 forks source link

Single-decimal float parse error #34

Closed sveniu closed 6 years ago

sveniu commented 6 years ago

This diff produces a test error:

diff --git a/decode_number_float_test.go b/decode_number_float_test.go
index fc9dd82..18d7bf9 100644
--- a/decode_number_float_test.go
+++ b/decode_number_float_test.go
@@ -20,6 +20,11 @@ func TestDecoderFloat64(t *testing.T) {
                errType        interface{}
        }{
                {
+                       name:           "basic-float",
+                       json:           "1.1",
+                       expectedResult: 1.1,
+               },
+               {
                        name:           "basic-exponent-positive-positive-exp",
                        json:           "1e2",
                        expectedResult: 100,

The test output:

-- FAIL: TestDecoderFloat64 (0.00s)
    --- FAIL: TestDecoderFloat64/basic-float (0.00s)
        decode_number_float_test.go:277:
                        Error Trace:    decode_number_float_test.go:277
                        Error:          Expected nil, but got: "Invalid JSON, wrong char '1' found at position 0"
                        Test:           TestDecoderFloat64/basic-float
                        Messages:       Err must be nil
        decode_number_float_test.go:280:
                        Error Trace:    decode_number_float_test.go:280
                        Error:          Not equal:
                                        expected: 1.1e+06
                                        actual  : 0
                        Test:           TestDecoderFloat64/basic-float
                        Messages:       v must be equal to 1.100000
FAIL

This diff works:

diff --git a/decode_number_float_test.go b/decode_number_float_test.go
index fc9dd82..afd8cd8 100644
--- a/decode_number_float_test.go
+++ b/decode_number_float_test.go
@@ -20,6 +20,11 @@ func TestDecoderFloat64(t *testing.T) {
                errType        interface{}
        }{
                {
+                       name:           "basic-float",
+                       json:           "1.12",
+                       expectedResult: 1.12,
+               },
+               {
                        name:           "basic-exponent-positive-positive-exp",
                        json:           "1e2",
                        expectedResult: 100,
francoispqt commented 6 years ago

Hi, releasing a fix. Bug was introduced in previous patch, sorry for that.

francoispqt commented 6 years ago

v1.0.3 released. Closing the issue.