-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathdedup_key_test.go
More file actions
57 lines (53 loc) · 1.71 KB
/
Copy pathdedup_key_test.go
File metadata and controls
57 lines (53 loc) · 1.71 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
package quamina
import (
"testing"
)
func TestTableShareKey_SharedBackings(t *testing.T) {
// Construct one smallTable, value-copy it (simulating post-embed share).
src := smallTable{
ceilings: []byte{'a', 'b', byte(byteCeiling)},
steps: []*faState{nil, nil, nil},
}
copy1 := src
copy2 := src
if newTableShareKey(©1) != newTableShareKey(©2) {
t.Errorf("value-copied tables should share key; got %v vs %v",
newTableShareKey(©1), newTableShareKey(©2))
}
}
func TestTableShareKey_DistinctBackings(t *testing.T) {
t1 := smallTable{
ceilings: []byte{'a', byte(byteCeiling)},
steps: []*faState{nil, nil},
}
t2 := smallTable{
ceilings: []byte{'a', byte(byteCeiling)},
steps: []*faState{nil, nil},
}
if newTableShareKey(&t1) == newTableShareKey(&t2) {
t.Errorf("independently-built tables should not share key")
}
}
// TestTableShareKey_AppendBreaksShare verifies that when a value-copy
// is mutated via append in a way that reallocates the backing array,
// the keys diverge. We force reallocation by starting at cap=1 and
// appending many entries.
func TestTableShareKey_AppendBreaksShare(t *testing.T) {
src := smallTable{
ceilings: make([]byte, 0, 1),
steps: make([]*faState, 0, 1),
}
src.ceilings = append(src.ceilings, byte(byteCeiling))
src.steps = append(src.steps, nil)
copy1 := src
// Appending 8 entries to a slice with cap=1 guarantees at least one
// realloc of the steps backing.
for i := 0; i < 8; i++ {
copy1.steps = append(copy1.steps, nil)
copy1.ceilings = append(copy1.ceilings, byte(i))
}
if newTableShareKey(&src) == newTableShareKey(©1) {
t.Errorf("expected keys to diverge after append-with-realloc; got equal: %v",
newTableShareKey(&src))
}
}