From 2bdf8c38515c255e55cb0b6128e1375d2f58497a Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 2 Jun 2020 11:36:36 +0200 Subject: [PATCH] layout: add test that Stack doesn't allocate Signed-off-by: Elias Naur --- layout/stack_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/layout/stack_test.go b/layout/stack_test.go index f46fbfcd..46ca8eb0 100644 --- a/layout/stack_test.go +++ b/layout/stack_test.go @@ -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) + } +}