MCPcopy Index your code
hub / github.com/codehamr/codehamr / TestWrapForScrollbackExpandsTabs

Function TestWrapForScrollbackExpandsTabs

internal/tui/render_test.go:44–60  ·  view source on GitHub ↗

Terminals expand a literal tab to the next 8-column stop while ansi.Wrap counts it as one cell, so a tab-bearing line (glamour preserves tabs inside code fences) could pass the width check yet physically overflow. Tabs must be expanded before counting; none may survive into the output.

(t *testing.T)

Source from the content-addressed store, hash-verified

42
43// Terminals expand a literal tab to the next 8-column stop while ansi.Wrap
44// counts it as one cell, so a tab-bearing line (glamour preserves tabs inside
45// code fences) could pass the width check yet physically overflow. Tabs must
46// be expanded before counting; none may survive into the output.
47func TestWrapForScrollbackExpandsTabs(t *testing.T) {
48 const width = 20
49 // 3 tabs + 16 chars: 19 counted cells with tab=1 (passes unwrapped), but
50 // 12 + 16 = 28 real cells once expanded - must wrap.
51 out := wrapForScrollback("\t\t\tabcdefghijklmnop", width)
52 if strings.Contains(out, "\t") {
53 t.Fatalf("tabs must not survive into scrollback output: %q", out)
54 }
55 if !strings.Contains(out, "\n") {
56 t.Fatalf("the expanded over-width line must be wrapped: %q", out)
57 }
58 for line := range strings.SplitSeq(out, "\n") {
59 if w := ansi.StringWidth(line); w > width {
60 t.Fatalf("expanded line width %d exceeds %d: %q", w, width, line)
61 }
62 }
63}

Callers

nothing calls this directly

Calls 1

wrapForScrollbackFunction · 0.85

Tested by

no test coverage detected