| 713 | } |
| 714 | |
| 715 | func TestSwap(t *testing.T) { |
| 716 | defer func() { |
| 717 | recover() |
| 718 | }() |
| 719 | buf := NewSwap(New(5), New(10)) |
| 720 | if buf.Len() != 0 { |
| 721 | t.Error("buffer should start empty got", buf.Len()) |
| 722 | } |
| 723 | if buf.Cap() != 10 { |
| 724 | t.Error("cap should be second buffer size (10) got", buf.Cap()) |
| 725 | } |
| 726 | io.WriteString(buf, "hey") |
| 727 | data, _ := ioutil.ReadAll(buf) |
| 728 | if string(data) != "hey" { |
| 729 | t.Error("expected hey got", string(data)) |
| 730 | } |
| 731 | io.WriteString(buf, "hey") |
| 732 | io.WriteString(buf, "hey") |
| 733 | io.WriteString(buf, "hey") |
| 734 | data, _ = ioutil.ReadAll(buf) |
| 735 | if string(data) != "heyheyhey" { |
| 736 | t.Error("expected heyheyhey got", string(data)) |
| 737 | } |
| 738 | io.WriteString(buf, "hey") |
| 739 | if buf.Len() != 3 { |
| 740 | t.Error("should have data") |
| 741 | } |
| 742 | buf.Reset() |
| 743 | if buf.Len() != 0 { |
| 744 | t.Error("should be empty") |
| 745 | } |
| 746 | |
| 747 | runPerfectSeries(t, NewSwap(New(512), New(1024))) |
| 748 | |
| 749 | NewSwap(New(1), New(0)) |
| 750 | t.Error("expected panic") |
| 751 | } |
| 752 | |
| 753 | func TestPanicReadAt(t *testing.T) { |
| 754 | defer func() { |