github.com/Seikaijyu/gio@v0.0.1/layout/alloc_test.go (about)

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