alloc_test.go raw

   1  // SPDX-License-Identifier: Unlicense OR MIT
   2  
   3  // +build !race
   4  
   5  package layout
   6  
   7  import (
   8  	"image"
   9  	"testing"
  10  
  11  	"github.com/p9c/p9/pkg/gel/gio/op"
  12  )
  13  
  14  func TestStackAllocs(t *testing.T) {
  15  	var ops op.Ops
  16  	allocs := testing.AllocsPerRun(1, func() {
  17  		ops.Reset()
  18  		gtx := Context{
  19  			Ops: &ops,
  20  		}
  21  		Stack{}.Layout(gtx,
  22  			Stacked(func(gtx Context) Dimensions {
  23  				return Dimensions{Size: image.Point{X: 50, Y: 50}}
  24  			}),
  25  		)
  26  	})
  27  	if allocs != 0 {
  28  		t.Errorf("expected no allocs, got %f", allocs)
  29  	}
  30  }
  31  
  32  func TestFlexAllocs(t *testing.T) {
  33  	var ops op.Ops
  34  	allocs := testing.AllocsPerRun(1, func() {
  35  		ops.Reset()
  36  		gtx := Context{
  37  			Ops: &ops,
  38  		}
  39  		Flex{}.Layout(gtx,
  40  			Rigid(func(gtx Context) Dimensions {
  41  				return Dimensions{Size: image.Point{X: 50, Y: 50}}
  42  			}),
  43  		)
  44  	})
  45  	if allocs != 0 {
  46  		t.Errorf("expected no allocs, got %f", allocs)
  47  	}
  48  }
  49