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