From 155af91e662993de8f69779b7c4383134b43f930 Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Mon, 11 May 2026 17:03:47 +0200 Subject: [PATCH] test sweep: close small terminal coverage gaps (T-91) Four targeted tests covering the last single-line/short-tail gaps in the terminal tree: the PointerInputs.none / .all const constructors, the abstract TerminalMouseHandler const constructor (reached via a private subclass), the reflow-output-padding branch in Buffer.resize (line < newHeight), and the wide-char skip in TerminalPainter.paintLine. Coverage: pointer_input 1/3 -> 3/3; mouse/handler 33/34 -> 34/34; buffer/buffer 260/261 -> 261/261; painter 120/121 -> 121/121. Co-Authored-By: Claude Opus 4.7 (1M context) --- test/terminal/coverage_trivials_test.dart | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/terminal/coverage_trivials_test.dart diff --git a/test/terminal/coverage_trivials_test.dart b/test/terminal/coverage_trivials_test.dart new file mode 100644 index 00000000..ff5a05fa --- /dev/null +++ b/test/terminal/coverage_trivials_test.dart @@ -0,0 +1,59 @@ +/// Closeout tests for the last single-digit-uncovered lines in +/// `lib/src/terminal/`: pointer_input constructors, the abstract +/// TerminalMouseHandler constructor, the reflow padding branch in +/// Buffer.resize, and the wide-char skip branch in +/// TerminalPainter.paintLine. +library; + +import 'dart:ui'; + +import 'package:clide/src/terminal/src/core/mouse/handler.dart'; +import 'package:clide/src/terminal/src/terminal.dart'; +import 'package:clide/src/terminal/src/ui/painter.dart'; +import 'package:clide/src/terminal/src/ui/pointer_input.dart'; +import 'package:clide/src/terminal/src/ui/terminal_text_style.dart'; +import 'package:clide/src/terminal/src/ui/themes.dart'; +import 'package:flutter/painting.dart'; +import 'package:test/test.dart'; + +class _StubMouseHandler extends TerminalMouseHandler { + const _StubMouseHandler(); + @override + String? call(TerminalMouseEvent event) => null; +} + +void main() { + test('PointerInputs.none / .all produce expected sets', () { + expect(const PointerInputs.none().inputs, isEmpty); + expect(const PointerInputs.all().inputs, containsAll(PointerInput.values)); + }); + + test('TerminalMouseHandler abstract const constructor is reachable via a subclass', () { + const h = _StubMouseHandler(); + expect(h, isA()); + }); + + test('Buffer.resize pads reflow output up to the new height', () { + final t = Terminal(maxLines: 200, onOutput: (_) {}); + // Write content narrower than the new width — reflow should produce + // fewer lines than newHeight, triggering the pad-with-empty-lines + // branch in buffer.dart. + t.write('abc\r\n'); + // Resize to a wide + tall viewport. + t.resize(40, 50, 8, 16); + expect(t.buffer.lines.length, greaterThanOrEqualTo(50)); + }); + + test('TerminalPainter.paintLine handles wide (CJK) cells without skipping the skip', () { + final t = Terminal(maxLines: 100, onOutput: (_) {}); + // CJK ideograph — terminal stores it as a width-2 cell, so paintLine + // advances `i` twice and the wide-char branch fires. + t.write('漢字'); + final p = TerminalPainter( + theme: TerminalThemes.defaultTheme, + textStyle: const TerminalStyle(), + textScaler: const TextScaler.linear(1.0), + ); + p.paintLine(Canvas(PictureRecorder()), Offset.zero, t.buffer.lines[0]); + }); +}