| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // TestClampWidth guards the inline-overflow fix: scrollback lines wider than the |
| 9 | // viewport get hard-broken (so the renderer's scroll estimate stays exact), while |
| 10 | // lines within width — including space-padded table rows — are left untouched. |
| 11 | func TestClampWidth(t *testing.T) { |
| 12 | // Within width: byte-for-byte identical (runs of spaces must NOT collapse). |
| 13 | row := "│ a │ bb │" |
| 14 | if got := clampWidth(row, 80); got != row { |
| 15 | t.Errorf("within-width line altered: %q -> %q", row, got) |
| 16 | } |
| 17 | // Over width: every resulting line fits, content is preserved. |
| 18 | long := strings.Repeat("x", 200) |
| 19 | out := clampWidth(long, 40) |
| 20 | for _, line := range strings.Split(out, "\n") { |
| 21 | if visibleWidth(line) > 40 { |
| 22 | t.Errorf("clamped line exceeds 40: width=%d", visibleWidth(line)) |
| 23 | } |
| 24 | } |
| 25 | if strings.ReplaceAll(out, "\n", "") != long { |
| 26 | t.Error("clampWidth lost or altered content") |
| 27 | } |
| 28 | // width <= 0 is a no-op (pre-sizing). |
| 29 | if clampWidth(long, 0) != long { |
| 30 | t.Error("width<=0 should be a no-op") |
| 31 | } |
| 32 | } |
| 33 |