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

Function TestRing

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

Source from the content-addressed store, hash-verified

248}
249
250func TestRing(t *testing.T) {
251 ring := NewRing(New(3))
252 if ring.Len() != 0 {
253 t.Errorf("Ring non-empty start!")
254 }
255
256 if ring.Cap() != math.MaxInt64 {
257 t.Errorf("Ring has < max capacity")
258 }
259
260 ring.Write([]byte("abc"))
261 if ring.Len() != 3 {
262 t.Errorf("expected ring len == 3")
263 }
264
265 ring.Write([]byte("de"))
266 if ring.Len() != 3 {
267 t.Errorf("expected ring len == 3")
268 }
269
270 data := make([]byte, 12)
271 if n, err := ring.Read(data); err != nil {
272 t.Error(err.Error())
273 } else {
274 if !bytes.Equal(data[:n], []byte("cde")) {
275 t.Errorf("expected cde, got %s", data[:n])
276 }
277 }
278
279 if ring.Len() != 0 {
280 t.Errorf("ring should now be empty")
281 }
282
283 ring.Write([]byte("hello"))
284 ring.Reset()
285
286 if ring.Len() != 0 {
287 t.Errorf("ring should still be empty")
288 }
289}
290
291func TestGob(t *testing.T) {
292 str := "HelloWorld"

Callers

nothing calls this directly

Calls 7

NewRingFunction · 0.85
NewFunction · 0.85
LenMethod · 0.65
CapMethod · 0.65
ResetMethod · 0.65
WriteMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…