MCPcopy Create free account
hub / github.com/djherbis/buffer / TestSwap

Function TestSwap

buffer_test.go:715–751  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

713}
714
715func 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
753func TestPanicReadAt(t *testing.T) {
754 defer func() {

Callers

nothing calls this directly

Calls 6

NewSwapFunction · 0.85
NewFunction · 0.85
runPerfectSeriesFunction · 0.85
LenMethod · 0.65
CapMethod · 0.65
ResetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…