summaryrefslogtreecommitdiff
path: root/src/pkg/encoding/line/line_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/encoding/line/line_test.go')
-rw-r--r--src/pkg/encoding/line/line_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/pkg/encoding/line/line_test.go b/src/pkg/encoding/line/line_test.go
index 68d13b586..ff16d10c7 100644
--- a/src/pkg/encoding/line/line_test.go
+++ b/src/pkg/encoding/line/line_test.go
@@ -6,6 +6,7 @@ package line
import (
"bytes"
+ "io"
"os"
"testing"
)
@@ -87,3 +88,23 @@ func TestLineTooLong(t *testing.T) {
t.Errorf("bad result for third line: %x", line)
}
}
+
+func TestReadAfterLines(t *testing.T) {
+ line1 := "line1"
+ restData := "line2\nline 3\n"
+ inbuf := bytes.NewBuffer([]byte(line1 + "\n" + restData))
+ outbuf := new(bytes.Buffer)
+ maxLineLength := len(line1) + len(restData)/2
+ l := NewReader(inbuf, maxLineLength)
+ line, isPrefix, err := l.ReadLine()
+ if isPrefix || err != nil || string(line) != line1 {
+ t.Errorf("bad result for first line: isPrefix=%v err=%v line=%q", isPrefix, err, string(line))
+ }
+ n, err := io.Copy(outbuf, l)
+ if int(n) != len(restData) || err != nil {
+ t.Errorf("bad result for Read: n=%d err=%v", n, err)
+ }
+ if outbuf.String() != restData {
+ t.Errorf("bad result for Read: got %q; expected %q", outbuf.String(), restData)
+ }
+}