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