]> Sergey Matveev's repositories - btrtrc.git/blob - internal/nestedmaps/nestedmaps_test.go
gorond test files
[btrtrc.git] / internal / nestedmaps / nestedmaps_test.go
1 package nestedmaps
2
3 import (
4         "testing"
5
6         g "github.com/anacrolix/generics"
7         qt "github.com/frankban/quicktest"
8 )
9
10 func TestNestedMaps(t *testing.T) {
11         c := qt.New(t)
12         var nest map[string]map[*int]map[byte][]int64
13         intKey := g.PtrTo(420)
14         var root = Begin(&nest)
15         var first = Next(root, "answer")
16         var second = Next(first, intKey)
17         var last = Next(second, 69)
18         c.Assert(root.Exists(), qt.IsFalse)
19         c.Assert(first.Exists(), qt.IsFalse)
20         c.Assert(second.Exists(), qt.IsFalse)
21         c.Assert(last.Exists(), qt.IsFalse)
22         last.Set([]int64{4, 8, 15, 16, 23, 42})
23         c.Assert(root.Exists(), qt.IsTrue)
24         c.Assert(first.Exists(), qt.IsTrue)
25         c.Assert(second.Exists(), qt.IsTrue)
26         c.Assert(last.Exists(), qt.IsTrue)
27         c.Assert(Next(second, 70).Exists(), qt.IsFalse)
28         secondIntKey := g.PtrTo(1337)
29         secondPath := Next(Next(Next(Begin(&nest), "answer"), secondIntKey), 42)
30         secondPath.Set(nil)
31         c.Assert(secondPath.Exists(), qt.IsTrue)
32         last.Delete()
33         c.Assert(last.Exists(), qt.IsFalse)
34         c.Assert(second.Exists(), qt.IsFalse)
35         c.Assert(root.Exists(), qt.IsTrue)
36         c.Assert(first.Exists(), qt.IsTrue)
37         // See if we get panics deleting an already deleted item.
38         last.Delete()
39         secondPath.Delete()
40         c.Assert(root.Exists(), qt.IsFalse)
41 }