diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-02-18 09:50:58 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-02-18 09:50:58 +0100 |
commit | c072558b90f1bbedc2022b0f30c8b1ac4712538e (patch) | |
tree | 67767591619e4bd8111fb05fac185cde94fb7378 /src/pkg/encoding | |
parent | 5859517b767c99749a45651c15d4bae5520ebae8 (diff) | |
download | golang-c072558b90f1bbedc2022b0f30c8b1ac4712538e.tar.gz |
Imported Upstream version 2011.02.15upstream/2011.02.15
Diffstat (limited to 'src/pkg/encoding')
-rw-r--r-- | src/pkg/encoding/binary/binary.go | 5 | ||||
-rw-r--r-- | src/pkg/encoding/line/line.go | 3 | ||||
-rw-r--r-- | src/pkg/encoding/line/line_test.go | 23 |
3 files changed, 29 insertions, 2 deletions
diff --git a/src/pkg/encoding/binary/binary.go b/src/pkg/encoding/binary/binary.go index 77ff3a9f3..ee2f23dbb 100644 --- a/src/pkg/encoding/binary/binary.go +++ b/src/pkg/encoding/binary/binary.go @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// This package implements translation between -// unsigned integer values and byte sequences. +// Package binary implements translation between +// unsigned integer values and byte sequences +// and the reading and writing of fixed-size values. package binary import ( diff --git a/src/pkg/encoding/line/line.go b/src/pkg/encoding/line/line.go index 779b5758a..f46ce1c83 100644 --- a/src/pkg/encoding/line/line.go +++ b/src/pkg/encoding/line/line.go @@ -105,6 +105,9 @@ func (l *Reader) ReadLine() (line []byte, isPrefix bool, err os.Error) { l.buf = l.buf[:oldLen+n] if readErr != nil { l.err = readErr + if len(l.buf) == 0 { + return nil, false, readErr + } } } panic("unreachable") diff --git a/src/pkg/encoding/line/line_test.go b/src/pkg/encoding/line/line_test.go index ff16d10c7..ff3d51669 100644 --- a/src/pkg/encoding/line/line_test.go +++ b/src/pkg/encoding/line/line_test.go @@ -7,6 +7,7 @@ package line import ( "bytes" "io" + "io/ioutil" "os" "testing" ) @@ -108,3 +109,25 @@ func TestReadAfterLines(t *testing.T) { t.Errorf("bad result for Read: got %q; expected %q", outbuf.String(), restData) } } + +func TestReadEmptyBuffer(t *testing.T) { + l := NewReader(bytes.NewBuffer(nil), 10) + line, isPrefix, err := l.ReadLine() + if err != os.EOF { + t.Errorf("expected EOF from ReadLine, got '%s' %t %s", line, isPrefix, err) + } +} + +func TestLinesAfterRead(t *testing.T) { + l := NewReader(bytes.NewBuffer([]byte("foo")), 10) + _, err := ioutil.ReadAll(l) + if err != nil { + t.Error(err) + return + } + + line, isPrefix, err := l.ReadLine() + if err != os.EOF { + t.Errorf("expected EOF from ReadLine, got '%s' %t %s", line, isPrefix, err) + } +} |