...

Source file src/arena/arena_test.go

Documentation: arena

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build goexperiment.arenas
     6  
     7  package arena_test
     8  
     9  import (
    10  	"arena"
    11  	"testing"
    12  )
    13  
    14  type T1 struct {
    15  	n int
    16  }
    17  type T2 [1 << 20]byte // 1MiB
    18  
    19  func TestSmoke(t *testing.T) {
    20  	a := arena.NewArena()
    21  	defer a.Free()
    22  
    23  	tt := arena.New[T1](a)
    24  	tt.n = 1
    25  
    26  	ts := arena.MakeSlice[T1](a, 99, 100)
    27  	if len(ts) != 99 {
    28  		t.Errorf("Slice() len = %d, want 99", len(ts))
    29  	}
    30  	if cap(ts) != 100 {
    31  		t.Errorf("Slice() cap = %d, want 100", cap(ts))
    32  	}
    33  	ts[1].n = 42
    34  }
    35  
    36  func TestSmokeLarge(t *testing.T) {
    37  	a := arena.NewArena()
    38  	defer a.Free()
    39  	for i := 0; i < 10*64; i++ {
    40  		_ = arena.New[T2](a)
    41  	}
    42  }
    43  

View as plain text