github.com/AndrienkoAleksandr/go@v0.0.19/src/log/slog/internal/buffer/buffer_test.go (about) 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 package buffer 6 7 import ( 8 "internal/race" 9 "internal/testenv" 10 "testing" 11 ) 12 13 func Test(t *testing.T) { 14 b := New() 15 defer b.Free() 16 b.WriteString("hello") 17 b.WriteByte(',') 18 b.Write([]byte(" world")) 19 b.WritePosIntWidth(17, 4) 20 21 got := b.String() 22 want := "hello, world0017" 23 if got != want { 24 t.Errorf("got %q, want %q", got, want) 25 } 26 } 27 28 func TestAlloc(t *testing.T) { 29 if race.Enabled { 30 t.Skip("skipping test in race mode") 31 } 32 testenv.SkipIfOptimizationOff(t) 33 got := int(testing.AllocsPerRun(5, func() { 34 b := New() 35 defer b.Free() 36 b.WriteString("not 1K worth of bytes") 37 })) 38 if got != 0 { 39 t.Errorf("got %d allocs, want 0", got) 40 } 41 }