...
1
2
3
4
5 package slog
6
7 import (
8 "testing"
9 "time"
10 )
11
12 func TestAttrNoAlloc(t *testing.T) {
13
14 var (
15 i int64
16 u uint64
17 f float64
18 b bool
19 s string
20 x any
21 p = &i
22 d time.Duration
23 )
24 a := int(testing.AllocsPerRun(5, func() {
25 i = Int64("key", 1).Value.Int64()
26 u = Uint64("key", 1).Value.Uint64()
27 f = Float64("key", 1).Value.Float64()
28 b = Bool("key", true).Value.Bool()
29 s = String("key", "foo").Value.String()
30 d = Duration("key", d).Value.Duration()
31 x = Any("key", p).Value.Any()
32 }))
33 if a != 0 {
34 t.Errorf("got %d allocs, want zero", a)
35 }
36 _ = u
37 _ = f
38 _ = b
39 _ = s
40 _ = x
41 }
42
View as plain text