test sweep: cover Terminal orchestrator (T-91)

Adds test/terminal/terminal_test.dart — 54 unit tests covering the
`Terminal` class as a pure-Dart orchestrator: construction +
TerminalState defaults, the Observable mixin, write/writeChar,
keyInput / charInput / textInput / paste (with bracketed-paste +
ctrl/alt encodings, including macOS reservation), mouseInput
gating, resize (clamping + onResize callback + alt-buffer
scrollback clear), buffer switching (use{Alt,Main}Buffer +
clearAltBuffer), every SBC handler (bell / backspace / lineFeed /
CR / SO / SI / unknown), tab-stop manipulation (tab jump +
saturation, clearTabStopUnderCursor, clearAllTabStops, setTapStop),
every ANSI escape handler (save/restore cursor, index, nextLine,
reverseIndex, designateCharset), CSI cursor + erase + line/char
insert/delete + scroll + repeatPreviousCharacter (incl. no-op when
no preceding char), device-attribute and status reports, every
mode setter mirroring into its getter, every SGR set/unset attr +
colour setter, OSC handlers (setTitle / setIconName / unknownOSC),
and all the documented no-op fallbacks (unknownSBC, unkownEscape,
unknownCSI, setUnknownMode, setUnknownDecMode, setColumnMode,
unsupportedStyle).

Also fixes a real production bug surfaced while writing tests:
`BufferLine.eraseRange(0, 0, ...)` panicked with a `RangeError`
because the right-side wide-char guard read `_data[-1]` via
`getWidth(end - 1)` when `end == 0`. The left guard already had a
`start > 0` check; the right guard was missing the symmetric
`end > 0`. Real trigger path: `Terminal.eraseDisplayAbove`
(`ESC[1J`) with the cursor at column 0 — common after `ESC[H\x1b[1J`
home-then-erase-above sequences that many TUIs emit on redraw.
Regression test added in line_test.dart.

Coverage delta:
- terminal.dart: 0/283 → 291/291 (file grew by 8 LF for the
  fix's comment lines).
- base/observable.dart: 0/7 → 7/7 (covered transitively via
  Terminal's listener tests).
- Total project: 56.40% → 59.82%; coverage_floor bumped 56 → 59.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-05-07 08:21:18 +02:00
co-authored by Claude
parent 6008b4914c
commit 4642a2f25b
6 changed files with 814 additions and 110 deletions
+9
View File
@@ -177,6 +177,15 @@ void main() {
expect(l.getContent(0), 0);
});
test('eraseRange(0, 0, ...) does not panic when called at column 0', () {
// Surfaced by Terminal.eraseDisplayAbove when the cursor sits at
// column 0: eraseLineToCursor → eraseRange(0, _cursorX, ...) with
// _cursorX == 0. Without the `end > 0` guard, the right-side
// wide-char check reads _data[-1] via getWidth(-1).
final l = BufferLine(4);
l.eraseRange(0, 0, _styleEmpty);
});
test('extends one cell right when end-1 is the second cell of a wide char', () {
final l = BufferLine(4);
l.setCell(0, _aChar, 1, _styleEmpty);