Files
lazyntfy/internal/textutil/text_test.go
T
ahp e412819d48 feat(textutil): add width-aware text wrapping and clipping
Wrap, Clip, and Pad plain text to a fixed rune width for the terminal panes.
2026-10-11 12:04:41 +03:30

33 lines
662 B
Go

package textutil
import "testing"
func TestClip(t *testing.T) {
if got := Clip("abcdef", 4); got != "abc…" {
t.Fatalf("clip: %q", got)
}
if got := Clip("ab", 4); got != "ab" {
t.Fatalf("short: %q", got)
}
if got := Clip("a\nb", 5); got != "a b" {
t.Fatalf("newline: %q", got)
}
}
func TestWrap(t *testing.T) {
got := Wrap("one two three", 7)
want := []string{"one two", "three"}
if len(got) != len(want) {
t.Fatalf("wrap %#v", got)
}
for i := range want {
if got[i] != want[i] {
t.Fatalf("line %d: %q", i, got[i])
}
}
blank := Wrap("a\n\nb", 10)
if len(blank) != 3 || blank[1] != "" {
t.Fatalf("blank lines: %#v", blank)
}
}