-
Notifications
You must be signed in to change notification settings - Fork 0
/
stacked_map_test.go
69 lines (62 loc) · 1.12 KB
/
stacked_map_test.go
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
package dscope
import "testing"
func TestStackedMap(t *testing.T) {
var m *_StackedMap
m = m.Append([]_Value{
{typeInfo: &_TypeInfo{TypeID: 1, Position: 1}},
{typeInfo: &_TypeInfo{TypeID: 2, Position: 2}},
{typeInfo: &_TypeInfo{TypeID: 2, Position: 3}},
{typeInfo: &_TypeInfo{TypeID: 2, Position: 4}},
{typeInfo: &_TypeInfo{TypeID: 3, Position: 5}},
})
m = m.Append([]_Value{
{typeInfo: &_TypeInfo{TypeID: 3, Position: 6}},
})
vs, ok := m.Load(1)
if !ok {
t.Fatal()
}
if len(vs) != 1 {
t.Fatal()
}
if vs[0].typeInfo.Position != 1 {
t.Fatal()
}
vs, ok = m.Load(2)
if !ok {
t.Fatal()
}
if len(vs) != 3 {
t.Fatalf("got %d", len(vs))
}
if vs[0].typeInfo.Position != 2 {
t.Fatal()
}
if vs[1].typeInfo.Position != 3 {
t.Fatal()
}
if vs[2].typeInfo.Position != 4 {
t.Fatal()
}
_, ok = m.Load(42)
if ok {
t.Fatal()
}
n := 0
if err := m.Range(func(ds []_Value) error {
for _, d := range ds {
n++
if d.typeInfo.TypeID == 3 {
if d.typeInfo.Position != 6 {
t.Fatal()
}
}
}
return nil
}); err != nil {
t.Fatal(err)
}
if n != 5 {
t.Fatalf("got %d", n)
}
}