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