github.com/anacrolix/torrent@v1.61.0/type-sizes_test.go (about) 1 package torrent 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/anacrolix/chansync" 8 g "github.com/anacrolix/generics" 9 "github.com/go-quicktest/qt" 10 ) 11 12 func testSizeof[T any](t *testing.T, max g.Option[uintptr]) { 13 ty := reflect.TypeFor[T]() 14 size := ty.Size() 15 t.Logf("%v has size %v", ty, size) 16 if max.Ok { 17 qt.Check(t, qt.IsTrue(size <= max.Value), qt.Commentf("size of %v is %v, expected <= %v", ty, size, max.Value)) 18 } 19 } 20 21 func checkSizeLessThan[T any](t *testing.T, max uintptr) { 22 testSizeof[T](t, g.Some(max)) 23 } 24 25 func justLogSizeof[T any](t *testing.T) { 26 testSizeof[T](t, g.None[uintptr]()) 27 } 28 29 func TestTypeSizes(t *testing.T) { 30 justLogSizeof[[]*File](t) 31 checkSizeLessThan[Piece](t, 296) 32 justLogSizeof[map[*Peer]struct{}](t) 33 justLogSizeof[chansync.BroadcastCond](t) 34 35 justLogSizeof[g.Option[[32]byte]](t) 36 justLogSizeof[[]byte](t) 37 }