(t *testing.T)
| 528 | } |
| 529 | |
| 530 | func TestUnreadByte(t *testing.T) { |
| 531 | b := new(Buffer) |
| 532 | |
| 533 | // check at EOF |
| 534 | if err := b.UnreadByte(); err == nil { |
| 535 | t.Fatal("UnreadByte at EOF: got no error") |
| 536 | } |
| 537 | if _, err := b.ReadByte(); err == nil { |
| 538 | t.Fatal("ReadByte at EOF: got no error") |
| 539 | } |
| 540 | if err := b.UnreadByte(); err == nil { |
| 541 | t.Fatal("UnreadByte after ReadByte at EOF: got no error") |
| 542 | } |
| 543 | |
| 544 | // check not at EOF |
| 545 | b.WriteString("abcdefghijklmnopqrstuvwxyz") |
| 546 | |
| 547 | // after unsuccessful read |
| 548 | if n, err := b.Read(nil); n != 0 || err != nil { |
| 549 | t.Fatalf("Read(nil) = %d,%v; want 0,nil", n, err) |
| 550 | } |
| 551 | if err := b.UnreadByte(); err == nil { |
| 552 | t.Fatal("UnreadByte after Read(nil): got no error") |
| 553 | } |
| 554 | |
| 555 | // after successful read |
| 556 | if _, err := b.ReadBytes('m'); err != nil { |
| 557 | t.Fatalf("ReadBytes: %v", err) |
| 558 | } |
| 559 | if err := b.UnreadByte(); err != nil { |
| 560 | t.Fatalf("UnreadByte: %v", err) |
| 561 | } |
| 562 | c, err := b.ReadByte() |
| 563 | if err != nil { |
| 564 | t.Fatalf("ReadByte: %v", err) |
| 565 | } |
| 566 | if c != 'm' { |
| 567 | t.Errorf("ReadByte = %q; want %q", c, 'm') |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | // Tests that we occasionally compact. Issue 5154. |
| 572 | func TestBufferGrowth(t *testing.T) { |
nothing calls this directly
no test coverage detected