Properly compute the padding by fixing the ansi escape regexp

This commit is contained in:
Arturo Filastò 2018-06-29 16:38:13 +02:00
commit c4c13cb279
3 changed files with 32 additions and 8 deletions

View file

@ -0,0 +1,19 @@
package util
import (
"testing"
"github.com/fatih/color"
ocolor "github.com/ooni/probe-cli/internal/colors"
)
func TestEscapeAwareRuneCountInString(t *testing.T) {
var bold = color.New(color.Bold)
var myColor = color.New(color.FgBlue)
s := myColor.Sprintf("•ABC%s%s", bold.Sprintf("DEF"), ocolor.Red("GHI"))
count := EscapeAwareRuneCountInString(s)
if count != 10 {
t.Errorf("Count was incorrect, got: %d, want: %d.", count, 10)
}
}