-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline_test.go
45 lines (42 loc) · 1.12 KB
/
line_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package readers
import (
"bufio"
"fmt"
"github.com/stretchr/testify/assert"
"go/scanner"
"io"
"strings"
"testing"
)
func TestNewLineReader(t *testing.T) {
t.Run("normal", func(t *testing.T) {
r := NewLineReader(strings.NewReader("Hello world!\nHello new line!\n"))
for r.Next() {
a, err := io.ReadAll(r)
fmt.Println(len(a), string(a))
assert.NoError(t, err)
}
assert.NoError(t, r.Err())
})
t.Run("really long", func(t *testing.T) {
r := NewLineReader(strings.NewReader(strings.Repeat("Hello world! ", 1024) + "\na\n"))
for r.Next() {
a, err := io.ReadAll(r)
fmt.Println(len(a), string(a))
assert.NoError(t, err)
}
assert.NoError(t, r.Err())
})
t.Run("against scanner", func(t *testing.T) {
r := NewLineReader(strings.NewReader(strings.Repeat("Hello world! ", 409600) + "\na\n"))
for r.Next() {
a, err := io.ReadAll(r)
fmt.Println(len(a), string(a))
assert.NoError(t, err)
}
assert.NoError(t, r.Err())
sc := bufio.NewScanner(strings.NewReader(strings.Repeat("Hello world! ", 409600) + "\na\n"))
assert.False(t, sc.Scan())
assert.Error(t, sc.Err(), scanner.Error{})
})
}