diff --git a/jsoncjson.go b/jsoncjson.go index e98f654..3ab102b 100644 --- a/jsoncjson.go +++ b/jsoncjson.go @@ -54,7 +54,7 @@ func (t *jsoncTranslator) Read(jsonOut []byte) (n int, err error) { } } - return n, nil + return n + 1, nil } type token int8 diff --git a/jsoncjson_test.go b/jsoncjson_test.go index 833c52d..f58c04e 100644 --- a/jsoncjson_test.go +++ b/jsoncjson_test.go @@ -3,7 +3,9 @@ package jsoncjson_test import ( "bytes" "encoding/json" + "io/ioutil" "reflect" + "strconv" "strings" "testing" @@ -194,3 +196,27 @@ func testJSON(t *testing.T, in string, exp interface{}, got interface{}) { t.Fatalf("exp %+x, got: %+x", exp, got) } } + +func TestLargeJSON(t *testing.T) { + var data = make(map[string]int, bytes.MinRead) + for i := 0; i < bytes.MinRead; i++ { + data[strconv.Itoa(i)] = i + } + + var expBuf, err = json.Marshal(data) + if err != nil { + t.Fatalf("err: %s", err) + } + + var r = jsoncjson.NewReader(bytes.NewReader(expBuf)) + + var gotBuf []byte + gotBuf, err = ioutil.ReadAll(r) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !bytes.Equal(expBuf, gotBuf) { + t.Fatalf("exp len %d, got len: %d", len(expBuf), len(gotBuf)) + } +}