layout: add test that Stack doesn't allocate

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-02 11:36:36 +02:00
parent acc23a5b3e
commit 2bdf8c3851
+18
View File
@@ -29,3 +29,21 @@ func TestStack(t *testing.T) {
t.Errorf("Stack ignored Expanded size, got %v expected %v", got, exp)
}
}
func TestStackAllocs(t *testing.T) {
var ops op.Ops
allocs := testing.AllocsPerRun(1, func() {
ops.Reset()
gtx := Context{
Ops: &ops,
}
Stack{}.Layout(gtx,
Stacked(func(gtx Context) Dimensions {
return Dimensions{Size: image.Point{X: 50, Y: 50}}
}),
)
})
if allocs != 0 {
t.Errorf("expected no allocs, got %f", allocs)
}
}