-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_slab_test.go
More file actions
55 lines (51 loc) · 1.44 KB
/
Copy pathbatch_slab_test.go
File metadata and controls
55 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package qdf
import "testing"
func TestBatchSlabAppendResolve(t *testing.T) {
s := newBatchSlab()
off1, ln1, _ := s.append([]byte("hello"))
off2, ln2, _ := s.append([]byte("world!"))
if got := s.str(Str{off: off1, len: ln1}); got != "hello" {
t.Fatalf("str1 = %q", got)
}
if got := s.str(Str{off: off2, len: ln2}); got != "world!" {
t.Fatalf("str2 = %q", got)
}
// Growth must preserve earlier offsets (grow-copy keeps offsets stable).
big := make([]byte, 1<<20)
for i := range big {
big[i] = byte(i)
}
_, _, _ = s.append(big)
if got := s.str(Str{off: off1, len: ln1}); got != "hello" {
t.Fatalf("str1 after grow = %q", got)
}
s.release()
s2 := newBatchSlab()
if s2 == nil {
t.Fatal("pool returned nil")
}
s2.release()
}
func TestBatchSlabEmptyStr(t *testing.T) {
s := newBatchSlab()
defer s.release()
if got := s.str(Str{}); got != "" {
t.Fatalf("zero handle = %q, want empty", got)
}
}
func TestBatchSlabBytesAndGrow(t *testing.T) {
s := newBatchSlab()
off, ln, _ := s.append([]byte{1, 2, 3})
if got := s.bytes(Bytes{off: off, len: ln}); len(got) != 3 || got[0] != 1 || got[2] != 3 {
t.Fatalf("bytes = %v", got)
}
if got := s.bytes(Bytes{}); got != nil {
t.Fatalf("zero Bytes handle = %v, want nil", got)
}
// grow reserves capacity; earlier offsets stay valid afterwards.
s.grow(1 << 16)
if got := s.bytes(Bytes{off: off, len: ln}); len(got) != 3 || got[1] != 2 {
t.Fatalf("bytes after grow = %v", got)
}
s.release()
}