From c25137b6d7d5945ae5cde2349a002d84c50d0e59 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 7 Feb 2023 13:24:02 -0700 Subject: decode: Fix decoding an actively growing file --- decode_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'decode_test.go') diff --git a/decode_test.go b/decode_test.go index 73ce903..456f363 100644 --- a/decode_test.go +++ b/decode_test.go @@ -5,6 +5,7 @@ package lowmemjson import ( + "bytes" "io" "strings" "testing" @@ -34,3 +35,16 @@ func TestDecodeObject(t *testing.T) { }) assert.ErrorContains(t, err, "did not consume entire") } + +func TestDecodeGrowing(t *testing.T) { + t.Parallel() + var buf bytes.Buffer + dec := NewDecoder(&buf) + var x any + assert.ErrorIs(t, dec.Decode(&x), io.EOF) + buf.WriteString("1\n") + assert.NoError(t, dec.Decode(&x)) + buf.WriteString("1\n") + assert.NoError(t, dec.Decode(&x)) + assert.ErrorIs(t, dec.Decode(&x), io.EOF) +} -- cgit v1.2.3-2-g168b