-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before this change, on streams shorter than 6 bytes, we would present up to 6 bytes of garbage at the start of the buffer. With this change in place, we now present exactly what we read. Introduced in e7ecaa2. Fixes #263.
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package m | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
// Test that ZReader works with an empty stream | ||
func TestZReaderEmpty(t *testing.T) { | ||
bytesReader := bytes.NewReader([]byte{}) | ||
|
||
zReader, err := ZReader(bytesReader) | ||
assert.NilError(t, err) | ||
|
||
all, err := io.ReadAll(zReader) | ||
assert.NilError(t, err) | ||
|
||
assert.Equal(t, 0, len(all)) | ||
} | ||
|
||
// Test that ZReader works with a one-byte stream | ||
func TestZReaderOneByte(t *testing.T) { | ||
bytesReader := bytes.NewReader([]byte{42}) | ||
|
||
zReader, err := ZReader(bytesReader) | ||
assert.NilError(t, err) | ||
|
||
all, err := io.ReadAll(zReader) | ||
assert.NilError(t, err) | ||
|
||
assert.Equal(t, 1, len(all)) | ||
assert.Equal(t, byte(42), all[0]) | ||
} |