| 1 | package mlog |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "gotest.tools/v3/assert" |
| 7 | is "gotest.tools/v3/assert/cmp" |
| 8 | ) |
| 9 | |
| 10 | func BenchmarkLogAttrWriteBuf(b *testing.B) { |
| 11 | buf := &discardSliceWriter{} |
| 12 | attrs := make([]*Attr, b.N) |
| 13 | for i := 0; i < 100; i++ { |
| 14 | attrs = append(attrs, &Attr{ |
| 15 | Key: randString(10, false), |
| 16 | Value: randString(25, true), |
| 17 | }) |
| 18 | } |
| 19 | b.ResetTimer() |
| 20 | for i, attr := range attrs { |
| 21 | attr.writeBuf(buf) |
| 22 | if i != len(attrs)-1 { |
| 23 | buf.WriteByte(' ') |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestLogAttrWriteTo(t *testing.T) { |
| 29 | attr := Attr{"test", "this is \"a test\" of \t some \n a"} |
| 30 | buf := &sliceBuffer{make([]byte, 0, 1024)} |
| 31 | attr.writeBuf(buf) |
| 32 | n := `test="this is \"a test\" of \t some \n a"` |
| 33 | l := buf.String() |
| 34 | assert.Check(t, is.Equal(n, l), "did not match") |
| 35 | } |