OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package bufio_test | 5 package bufio_test |
6 | 6 |
7 import ( | 7 import ( |
8 . "bufio" | 8 . "bufio" |
9 "bytes" | 9 "bytes" |
10 "errors" | 10 "errors" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } | 342 } |
343 } | 343 } |
344 // Test that we cannot unread any further. | 344 // Test that we cannot unread any further. |
345 if err := r.UnreadByte(); err == nil { | 345 if err := r.UnreadByte(); err == nil { |
346 t.Errorf("n = %d: expected error on UnreadByte", n) | 346 t.Errorf("n = %d: expected error on UnreadByte", n) |
347 } | 347 } |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 func TestUnreadByteOthers(t *testing.T) { | 351 func TestUnreadByteOthers(t *testing.T) { |
352 » // A list of readers to use in conjuction with UnreadByte. | 352 » // A list of readers to use in conjunction with UnreadByte. |
353 var readers = []func(*Reader, byte) ([]byte, error){ | 353 var readers = []func(*Reader, byte) ([]byte, error){ |
354 (*Reader).ReadBytes, | 354 (*Reader).ReadBytes, |
355 (*Reader).ReadSlice, | 355 (*Reader).ReadSlice, |
356 func(r *Reader, delim byte) ([]byte, error) { | 356 func(r *Reader, delim byte) ([]byte, error) { |
357 data, err := r.ReadString(delim) | 357 data, err := r.ReadString(delim) |
358 return []byte(data), err | 358 return []byte(data), err |
359 }, | 359 }, |
360 // ReadLine doesn't fit the data/pattern easily | 360 // ReadLine doesn't fit the data/pattern easily |
361 // so we leave it out. It should be covered via | 361 // so we leave it out. It should be covered via |
362 // the ReadSlice test since ReadLine simply calls | 362 // the ReadSlice test since ReadLine simply calls |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 | 1408 |
1409 func BenchmarkWriterFlush(b *testing.B) { | 1409 func BenchmarkWriterFlush(b *testing.B) { |
1410 b.ReportAllocs() | 1410 b.ReportAllocs() |
1411 bw := NewWriter(ioutil.Discard) | 1411 bw := NewWriter(ioutil.Discard) |
1412 str := strings.Repeat("x", 50) | 1412 str := strings.Repeat("x", 50) |
1413 for i := 0; i < b.N; i++ { | 1413 for i := 0; i < b.N; i++ { |
1414 bw.WriteString(str) | 1414 bw.WriteString(str) |
1415 bw.Flush() | 1415 bw.Flush() |
1416 } | 1416 } |
1417 } | 1417 } |
OLD | NEW |