From ce0cc706adf1c8af9d1e58103f647d04ee522e49 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 2 Jun 2020 11:37:45 +0200 Subject: [PATCH] layout: add test that Flex doesn't allocate Signed-off-by: Elias Naur --- layout/{stack_test.go => layout_test.go} | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) rename layout/{stack_test.go => layout_test.go} (73%) diff --git a/layout/stack_test.go b/layout/layout_test.go similarity index 73% rename from layout/stack_test.go rename to layout/layout_test.go index 46ca8eb0..8b1f0ce9 100644 --- a/layout/stack_test.go +++ b/layout/layout_test.go @@ -47,3 +47,21 @@ func TestStackAllocs(t *testing.T) { t.Errorf("expected no allocs, got %f", allocs) } } + +func TestFlexAllocs(t *testing.T) { + var ops op.Ops + allocs := testing.AllocsPerRun(1, func() { + ops.Reset() + gtx := Context{ + Ops: &ops, + } + Flex{}.Layout(gtx, + Rigid(func(gtx Context) Dimensions { + return Dimensions{Size: image.Point{X: 50, Y: 50}} + }), + ) + }) + if allocs != 0 { + t.Errorf("expected no allocs, got %f", allocs) + } +}