1
1
mirror of https://github.com/wader/fq.git synced 2024-11-24 03:05:22 +03:00
fq/internal/ansi/ansi_test.go
2021-09-12 13:08:50 +02:00

55 lines
955 B
Go

package ansi_test
import (
"bytes"
"fmt"
"log"
"testing"
"github.com/wader/fq/internal/ansi"
)
func Test(t *testing.T) {
c := ansi.FromString("blue")
b := &bytes.Buffer{}
fmt.Fprintf(b, "%s", c.F("bla"))
log.Printf("b.String(): %#+v\n", b.String())
}
func Test2(t *testing.T) {
c := ansi.FromString("blue+underline")
b := &bytes.Buffer{}
_, _ = c.W(b).Write([]byte("bla"))
log.Printf("b.String(): %#+v\n", b.String())
}
func TestLen(t *testing.T) {
testCases := []struct {
s string
l int
}{
{"", 0},
{"abc", 3},
{ansi.Red.SetString + "a" + "bc" + ansi.Red.ResetString + "d", 4},
{"a" + ansi.Red.SetString + "bc" + ansi.Red.ResetString + "d", 4},
{"a" + ansi.Red.SetString + "bcd" + ansi.Red.ResetString, 4},
{"a│b", 3},
}
for _, tC := range testCases {
t.Run(tC.s, func(t *testing.T) {
actualL := ansi.Len(tC.s)
if tC.l != actualL {
t.Errorf("expected %d, got %d", tC.l, actualL)
}
})
}
}