1package rowtext23import (4 "testing"56 "github.com/charmbracelet/x/ansi"7)89// textCutter must cut exactly what ansi.Cut does, wide and combining10// characters included, for every way of splitting a line into columns.11func TestTextCutterMatchesCut(t *testing.T) {12 texts := []string{13 "plain ascii text",14 "Ça déjà vu, naïve café",15 "東京都の天気は晴れ",16 "é combining, 🙂🚀 emoji, 🇫🇷 flag, 👍🏽 tone",17 "a東b京c🙂d",18 "",19 }20 for _, s := range texts {21 tw := ansi.StringWidth(s)22 for step := 1; step <= 4; step++ {23 for off := range step {24 c := textCutter{s: s}25 for l := off; l < tw+step; l += step {26 if got, want := c.cut(l, l+step), ansi.Cut(s, l, l+step); got != want {27 t.Errorf("%q [%d,%d): got %q, want %q", s, l, l+step, got, want)28 }29 }30 }31 }32 }33}3435// textWidth must measure what ansi.StringWidth does, its ASCII shortcut36// included.37func TestTextWidthMatchesStringWidth(t *testing.T) {38 for _, s := range []string{"", "1234.5", " ~plain ascii! ", "tab\there", "\x1b[1mbold\x1b[0m", "café", "東京", "🙂 a", "á"} {39 if got, want := textWidth(s), ansi.StringWidth(s); got != want {40 t.Errorf("%q: got %d, want %d", s, got, want)41 }42 }43}