1
1
mirror of https://github.com/wader/fq.git synced 2024-11-24 11:16:09 +03:00
fq/internal/ansi/ansi_test.go

55 lines
955 B
Go
Raw Normal View History

2020-06-08 03:29:51 +03:00
package ansi_test
import (
"bytes"
"fmt"
"log"
"testing"
"github.com/wader/fq/internal/ansi"
2020-06-08 03:29:51 +03:00
)
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)
}
})
}
}