1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
package ansi
import (
"bytes"
"testing"
)
func TestBuffer_PrintableRuneWidth(t *testing.T) {
t.Parallel()
var bb bytes.Buffer
bb.WriteString("\x1B[38;2;249;38;114mfoo")
b := Buffer{bb}
if n := b.PrintableRuneWidth(); n != 3 {
t.Fatalf("width should be 3, got %d", n)
}
}
// go test -bench=Benchmark_PrintableRuneWidth -benchmem -count=4
func Benchmark_PrintableRuneWidth(b *testing.B) {
s := "\x1B[38;2;249;38;114mfoo"
b.RunParallel(func(pb *testing.PB) {
b.ReportAllocs()
b.ResetTimer()
for pb.Next() {
PrintableRuneWidth(s)
}
})
}
|