aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/bufio/bufio_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/bufio/bufio_test.go')
-rw-r--r--libgo/go/bufio/bufio_test.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/libgo/go/bufio/bufio_test.go b/libgo/go/bufio/bufio_test.go
index 9a9f102..cb68f3b 100644
--- a/libgo/go/bufio/bufio_test.go
+++ b/libgo/go/bufio/bufio_test.go
@@ -147,7 +147,7 @@ func TestReader(t *testing.T) {
for i := 0; i < len(texts)-1; i++ {
texts[i] = str + "\n"
all += texts[i]
- str += string(i%26 + 'a')
+ str += string(rune(i)%26 + 'a')
}
texts[len(texts)-1] = all
@@ -535,6 +535,23 @@ func TestReadWriteRune(t *testing.T) {
}
}
+func TestReadStringAllocs(t *testing.T) {
+ r := strings.NewReader(" foo foo 42 42 42 42 42 42 42 42 4.2 4.2 4.2 4.2\n")
+ buf := NewReader(r)
+ allocs := testing.AllocsPerRun(100, func() {
+ r.Seek(0, io.SeekStart)
+ buf.Reset(r)
+
+ _, err := buf.ReadString('\n')
+ if err != nil {
+ t.Fatal(err)
+ }
+ })
+ if allocs != 1 {
+ t.Errorf("Unexpected number of allocations, got %f, want 1", allocs)
+ }
+}
+
func TestWriter(t *testing.T) {
var data [8192]byte
@@ -1644,6 +1661,21 @@ func BenchmarkReaderWriteToOptimal(b *testing.B) {
}
}
+func BenchmarkReaderReadString(b *testing.B) {
+ r := strings.NewReader(" foo foo 42 42 42 42 42 42 42 42 4.2 4.2 4.2 4.2\n")
+ buf := NewReader(r)
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ r.Seek(0, io.SeekStart)
+ buf.Reset(r)
+
+ _, err := buf.ReadString('\n')
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+}
+
func BenchmarkWriterCopyOptimal(b *testing.B) {
// Optimal case is where the underlying writer implements io.ReaderFrom
srcBuf := bytes.NewBuffer(make([]byte, 8192))