-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader_test.go
60 lines (43 loc) · 1.17 KB
/
reader_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"bytes"
"testing"
)
func Test_Reader(t *testing.T) {
t.Run("typical", run(func(p *testpack) {
reader := bytes.NewReader([]byte(testContent1 + "\n" + testContent2))
readChan := connReader(reader)
line, ok := <-readChan
p.assert.True(ok)
p.assert.Equal([]byte(testContent1), line)
line, ok = <-readChan
p.assert.True(ok)
p.assert.Equal([]byte(testContent2), line)
line, ok = <-readChan
p.assert.False(ok)
p.assert.Nil(line)
}))
t.Run("trailing newline", run(func(p *testpack) {
reader := bytes.NewReader([]byte(testContent1 + "\n" + testContent2 + "\n"))
readChan := connReader(reader)
line, ok := <-readChan
p.assert.True(ok)
p.assert.Equal([]byte(testContent1), line)
line, ok = <-readChan
p.assert.True(ok)
p.assert.Equal([]byte(testContent2), line)
line, ok = <-readChan
p.assert.False(ok)
p.assert.Nil(line)
}))
t.Run("long input", run(func(p *testpack) {
reader := bytes.NewReader([]byte(testLongContent1))
readChan := connReader(reader)
line, ok := <-readChan
p.assert.True(ok)
p.assert.Equal([]byte(testLongContent1), line)
line, ok = <-readChan
p.assert.False(ok)
p.assert.Nil(line)
}))
}