-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_test.go
More file actions
71 lines (61 loc) · 1.57 KB
/
Copy pathmemory_test.go
File metadata and controls
71 lines (61 loc) · 1.57 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import "testing"
func TestAllocate(t *testing.T) {
resetAllocations()
defer resetAllocations()
packed := allocate(10)
if packed == 0 {
t.Fatal("allocate(10) returned 0")
}
if len(allocations) != 1 || len(allocations[0]) != 10 {
t.Errorf("allocations wrong: %v", allocations)
}
}
func TestAllocate_Zero(t *testing.T) {
resetAllocations()
if got := allocate(0); got != 0 {
t.Errorf("allocate(0) should return 0, got %d", got)
}
if len(allocations) != 0 {
t.Errorf("zero allocate should not pin a buffer")
}
}
func TestPackPointer_Empty(t *testing.T) {
if got := packPointer(nil); got != 0 {
t.Errorf("packPointer(nil) = %d; want 0", got)
}
if got := packPointer([]byte{}); got != 0 {
t.Errorf("packPointer(empty) = %d; want 0", got)
}
}
func TestWriteAndReadBytes_RoundTrip(t *testing.T) {
resetAllocations()
defer resetAllocations()
original := []byte("hello world")
packed := writeBytes(original)
if packed == 0 {
t.Fatal("writeBytes returned 0")
}
got := readBytes(packed)
if string(got) != "hello world" {
t.Errorf("round-trip mismatch: %q", got)
}
}
func TestWriteBytes_Empty(t *testing.T) {
if got := writeBytes(nil); got != 0 {
t.Errorf("writeBytes(nil) should be 0, got %d", got)
}
}
func TestReadBytes_Zero(t *testing.T) {
if got := readBytes(0); got != nil {
t.Errorf("readBytes(0) should be nil, got %v", got)
}
}
func TestResetAllocations(t *testing.T) {
_ = writeBytes([]byte("a"))
_ = writeBytes([]byte("b"))
resetAllocations()
if len(allocations) != 0 {
t.Errorf("after reset, allocations should be empty")
}
}