(t *testing.T)
| 5 | ) |
| 6 | |
| 7 | func TestRingBuf(t *testing.T) { |
| 8 | rb := NewRingBuf(16, 0) |
| 9 | for i := 0; i < 2; i++ { |
| 10 | rb.Write([]byte("fghibbbbccccddde")) |
| 11 | rb.Write([]byte("fghibbbbc")) |
| 12 | rb.Resize(16) |
| 13 | off := rb.Evacuate(9, 3) |
| 14 | t.Log(string(rb.Dump())) |
| 15 | if off != rb.End()-3 { |
| 16 | t.Log(string(rb.Dump()), rb.End()) |
| 17 | t.Fatalf("off got %v", off) |
| 18 | } |
| 19 | off = rb.Evacuate(15, 5) |
| 20 | t.Log(string(rb.Dump())) |
| 21 | if off != rb.End()-5 { |
| 22 | t.Fatalf("off got %v", off) |
| 23 | } |
| 24 | rb.Resize(64) |
| 25 | rb.Resize(32) |
| 26 | data := make([]byte, 5) |
| 27 | rb.ReadAt(data, off) |
| 28 | if string(data) != "efghi" { |
| 29 | t.Fatalf("read at should be efghi, got %v", string(data)) |
| 30 | } |
| 31 | |
| 32 | off = rb.Evacuate(0, 10) |
| 33 | if off != -1 { |
| 34 | t.Fatal("evacutate out of range offset should return error") |
| 35 | } |
| 36 | |
| 37 | /* -- After reset the buffer should behave exactly the same as a new one. |
| 38 | * Hence, run the test once more again with reset buffer. */ |
| 39 | rb.Reset(0) |
| 40 | } |
| 41 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…