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)
| 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. |
| 47 | func 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 | } |
nothing calls this directly
no test coverage detected