Skip to content

Commit

Permalink
Better dropcr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zix99 committed May 22, 2022
1 parent 658783f commit 6a390d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 8 additions & 0 deletions pkg/readahead/buffered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func TestReadSingleCharString(t *testing.T) {
assert.Equal(t, []byte("A"), ra.ReadLine())
}

func TestBufferedDropCR(t *testing.T) {
r := strings.NewReader("test\r\nthing")
ra := NewBuffered(r, 3)
assert.Equal(t, []byte("test"), ra.ReadLine())
assert.Equal(t, []byte("thing"), ra.ReadLine())
assert.Nil(t, ra.ReadLine())
}

func TestErrorHandling(t *testing.T) {
errReader := iotest.TimeoutReader(strings.NewReader("Hello there you\nthis is a line\n"))
ra := NewBuffered(errReader, 20)
Expand Down
9 changes: 3 additions & 6 deletions pkg/readahead/util_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package readahead

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestDropCR(t *testing.T) {
r := strings.NewReader("test\r\nthing")
ra := NewBuffered(r, 3)
assert.Equal(t, []byte("test"), ra.ReadLine())
assert.Equal(t, []byte("thing"), ra.ReadLine())
assert.Nil(t, ra.ReadLine())
assert.Equal(t, []byte("test"), dropCR([]byte("test")))
assert.Equal(t, []byte("test\n"), dropCR([]byte("test\n")))
assert.Equal(t, []byte("test"), dropCR([]byte("test\r")))
}

func TestMaxi(t *testing.T) {
Expand Down

0 comments on commit 6a390d8

Please sign in to comment.