(t *testing.T)
| 258 | } |
| 259 | |
| 260 | func (s) TestBuffer_Split(t *testing.T) { |
| 261 | freed := make(chan struct{}) |
| 262 | data := []byte{1, 2, 3, 4} |
| 263 | buf := mem.NewBuffer(&data, poolFunc(func(*[]byte) { |
| 264 | close(freed) |
| 265 | })) |
| 266 | |
| 267 | buf, split1 := mem.SplitUnsafe(buf, 2) |
| 268 | if !bytes.Equal(buf.ReadOnlyData(), data[:2]) { |
| 269 | t.Fatalf("Buffer did not contain expected data. got %v, want %v", buf.ReadOnlyData(), data[:2]) |
| 270 | } |
| 271 | if !bytes.Equal(split1.ReadOnlyData(), data[2:]) { |
| 272 | t.Fatalf("Buffer did not contain expected data. got %v, want %v", split1.ReadOnlyData(), data[2:]) |
| 273 | } |
| 274 | |
| 275 | // Check that splitting the buffer more than once works as intended. |
| 276 | split1, split2 := mem.SplitUnsafe(split1, 1) |
| 277 | if !bytes.Equal(split1.ReadOnlyData(), data[2:3]) { |
| 278 | t.Fatalf("Buffer did not contain expected data. got %v, want %v", split1.ReadOnlyData(), data[2:3]) |
| 279 | } |
| 280 | if !bytes.Equal(split2.ReadOnlyData(), data[3:]) { |
| 281 | t.Fatalf("Buffer did not contain expected data. got %v, want %v", split2.ReadOnlyData(), data[3:]) |
| 282 | } |
| 283 | |
| 284 | // If any of the following frees actually free the buffer, the test will fail. |
| 285 | buf.Free() |
| 286 | split2.Free() |
| 287 | select { |
| 288 | case <-freed: |
| 289 | t.Fatalf("Freed too early") |
| 290 | default: |
| 291 | } |
| 292 | |
| 293 | split1.Free() |
| 294 | |
| 295 | select { |
| 296 | case <-freed: |
| 297 | default: |
| 298 | t.Fatalf("Still not freed") |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | func (s) TestBuffer_Slice(t *testing.T) { |
| 303 | freed := make(chan struct{}) |
nothing calls this directly
no test coverage detected