MCPcopy Index your code
hub / github.com/box-cli-maker/box-cli-maker / TestLongestLineBasicAndTabs

Function TestLongestLineBasicAndTabs

util_test.go:33–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestLongestLineBasicAndTabs(t *testing.T) {
34 lines := []string{"short", "longer"}
35 longest, expanded := longestLine(lines)
36
37 if longest != len("longer") {
38 t.Errorf("expected longest %d, got %d", len("longer"), longest)
39 }
40 if len(expanded) != len(lines) {
41 t.Fatalf("expected %d expanded lines, got %d", len(lines), len(expanded))
42 }
43 if expanded[0].line != "short" || expanded[0].len != len("short") {
44 t.Errorf("unexpected expansion for 'short': %#v", expanded[0])
45 }
46
47 // Tab expansion: tab stops every 8 columns; "a\tb" -> "a" + 7 spaces + "b" (visible width 9).
48 lines = []string{"a\tb"}
49 longest, expanded = longestLine(lines)
50 wantLine := "a" + strings.Repeat(" ", 7) + "b"
51 if expanded[0].line != wantLine {
52 t.Errorf("tab-expanded line mismatch: want %q, got %q", wantLine, expanded[0].line)
53 }
54 if longest != 9 {
55 t.Errorf("expected longest 9 for tab-expanded line, got %d", longest)
56 }
57
58 // ANSI-colored line should be measured by visible width
59 plain := "abc"
60 colored := "\x1b[31mabc\x1b[0m" // same visible width as plain
61 longest, _ = longestLine([]string{plain, colored})
62 if longest != len(plain) {
63 t.Errorf("expected longest visible width %d, got %d", len(plain), longest)
64 }
65}
66
67func TestFormatLine_LeftAlignAndError(t *testing.T) {
68 // Happy path: left-aligned content, no title

Callers

nothing calls this directly

Calls 1

longestLineFunction · 0.85

Tested by

no test coverage detected