test sweep: kernel commands + widgets coverage, ratchet floor to 93
Add tests for `keybindings.dart` (KeyEvent → Keybinding mapping, parse-error edges, resolver entries view), `toolchain_paths.dart` (the Flutter-free `ToolchainView.resolved` static view), and several `widgets/src/` primitives: tooltip hover/overlay, palette filter + submit, multitab controller `copyWith` + size getters, and additional markdown branches (h3–h6 headings, tables, strikethrough, default block fallback, record-link tap). Unfreezes the pre-push coverage floor that was held at 90 on 2026-05-14 by mistake and ratchets to 93. Tidies eight test files that had accumulated unused imports flagged by `unnecessary_import`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import 'package:clide/kernel/kernel.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('Keybinding.parse + equality', () {
|
||||
test('parses single-key bindings', () {
|
||||
final k = Keybinding.parse('g');
|
||||
@@ -20,10 +23,30 @@ void main() {
|
||||
expect(() => Keybinding.parse(''), throwsA(isA<ArgumentError>()));
|
||||
});
|
||||
|
||||
test('rejects spec ending in `+` (missing key)', () {
|
||||
expect(() => Keybinding.parse('ctrl+'), throwsA(isA<ArgumentError>()));
|
||||
});
|
||||
|
||||
test('canonical modifier order is deterministic', () {
|
||||
final k = Keybinding.parse('alt+ctrl+shift+x');
|
||||
expect(k.modifiers, ['alt', 'ctrl', 'shift']);
|
||||
});
|
||||
|
||||
test('canonical of modifier-free binding is just the key', () {
|
||||
expect(Keybinding.parse('escape').canonical, 'escape');
|
||||
});
|
||||
|
||||
test('hashCode matches for equal bindings, differs for distinct', () {
|
||||
final a = Keybinding.parse('ctrl+shift+g');
|
||||
final b = Keybinding.parse('Shift+Ctrl+G');
|
||||
final c = Keybinding.parse('ctrl+g');
|
||||
expect(a.hashCode, b.hashCode);
|
||||
expect(a.hashCode, isNot(c.hashCode));
|
||||
});
|
||||
|
||||
test('toString embeds canonical form', () {
|
||||
expect(Keybinding.parse('ctrl+k').toString(), 'Keybinding(ctrl+k)');
|
||||
});
|
||||
});
|
||||
|
||||
group('KeybindingResolver', () {
|
||||
@@ -41,5 +64,74 @@ void main() {
|
||||
r.unbind(k);
|
||||
expect(r.commandFor(k), isNull);
|
||||
});
|
||||
|
||||
test('entries exposes registered bindings', () {
|
||||
final r = KeybindingResolver();
|
||||
r.bind(Keybinding.parse('ctrl+p'), 'palette.open');
|
||||
r.bind(Keybinding.parse('ctrl+shift+p'), 'palette.commands');
|
||||
final commands = r.entries.map((e) => e.value).toSet();
|
||||
expect(commands, {'palette.open', 'palette.commands'});
|
||||
});
|
||||
});
|
||||
|
||||
group('KeybindingResolver.fromKeyEvent', () {
|
||||
late HardwareKeyboard kb;
|
||||
setUp(() => kb = HardwareKeyboard.instance);
|
||||
tearDown(() => kb.clearState());
|
||||
|
||||
test('returns null for KeyUpEvent', () {
|
||||
final up = KeyUpEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyG,
|
||||
logicalKey: LogicalKeyboardKey.keyG,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
expect(KeybindingResolver.fromKeyEvent(up, kb), isNull);
|
||||
});
|
||||
|
||||
test('returns null when logicalKey has no keyLabel', () {
|
||||
// A synthetic logical key with an unassigned id has an empty label.
|
||||
final unlabeled = LogicalKeyboardKey(0x1000fffff);
|
||||
final down = KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.controlLeft,
|
||||
logicalKey: unlabeled,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
expect(KeybindingResolver.fromKeyEvent(down, kb), isNull);
|
||||
});
|
||||
|
||||
test('maps a plain KeyDownEvent to a modifier-free Keybinding', () {
|
||||
final down = KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyG,
|
||||
logicalKey: LogicalKeyboardKey.keyG,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
final b = KeybindingResolver.fromKeyEvent(down, kb);
|
||||
expect(b, isNotNull);
|
||||
expect(b!.key, 'g');
|
||||
expect(b.modifiers, isEmpty);
|
||||
});
|
||||
|
||||
test('includes every held modifier in the resulting Keybinding', () {
|
||||
// Simulate ctrl+shift+alt+meta held, then a keyG down.
|
||||
_holdModifier(PhysicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlLeft);
|
||||
_holdModifier(PhysicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftLeft);
|
||||
_holdModifier(PhysicalKeyboardKey.altLeft, LogicalKeyboardKey.altLeft);
|
||||
_holdModifier(PhysicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaLeft);
|
||||
|
||||
final down = KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyG,
|
||||
logicalKey: LogicalKeyboardKey.keyG,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
final b = KeybindingResolver.fromKeyEvent(down, kb)!;
|
||||
expect(b.key, 'g');
|
||||
expect(b.modifiers.toSet(), {'ctrl', 'shift', 'alt', 'cmd'});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _holdModifier(PhysicalKeyboardKey physical, LogicalKeyboardKey logical) {
|
||||
HardwareKeyboard.instance.handleKeyEvent(
|
||||
KeyDownEvent(physicalKey: physical, logicalKey: logical, timeStamp: Duration.zero),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:clide/kernel/kernel.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -6,7 +6,6 @@ library;
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:clide/kernel/src/i18n/catalog_loader.dart';
|
||||
|
||||
@@ -3,7 +3,6 @@ library;
|
||||
|
||||
import 'package:clide/extension/extension.dart';
|
||||
import 'package:clide/kernel/kernel.dart';
|
||||
import 'package:clide/kernel/src/panels/drag_resize.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Binary file not shown.
@@ -6,10 +6,8 @@
|
||||
library;
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:clide/kernel/kernel.dart';
|
||||
import 'package:clide/kernel/src/theme/contrast.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/// Unit tests for `ToolchainView.resolved` (the Flutter-free `_StaticToolchain`)
|
||||
/// in `lib/kernel/src/toolchain_paths.dart`. The listenable `Toolchain` and the
|
||||
/// top-level `resolveToolchainPaths` are covered by `toolchain_test.dart`.
|
||||
library;
|
||||
|
||||
import 'package:clide/kernel/src/toolchain_paths.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('ToolchainView.resolved', () {
|
||||
test('exposes the supplied paths verbatim', () {
|
||||
final v = ToolchainView.resolved(const ResolvedPaths(
|
||||
git: '/opt/git',
|
||||
pql: '/opt/pql',
|
||||
tmux: '/opt/tmux',
|
||||
shell: '/usr/bin/zsh',
|
||||
gitEnv: {'GIT_EXEC_PATH': '/opt/git-core'},
|
||||
));
|
||||
expect(v.git, '/opt/git');
|
||||
expect(v.pql, '/opt/pql');
|
||||
expect(v.tmux, '/opt/tmux');
|
||||
expect(v.shell, '/usr/bin/zsh');
|
||||
expect(v.gitEnv, {'GIT_EXEC_PATH': '/opt/git-core'});
|
||||
expect(v.resolved, isTrue);
|
||||
expect(v.allOk, isTrue);
|
||||
expect(v.missing, isEmpty);
|
||||
});
|
||||
|
||||
test('falls back to bare command names when paths are null', () {
|
||||
final v = ToolchainView.resolved(const ResolvedPaths());
|
||||
expect(v.git, 'git');
|
||||
expect(v.pql, 'pql');
|
||||
expect(v.tmux, 'tmux');
|
||||
expect(v.shell, '/bin/bash');
|
||||
expect(v.gitEnv, isNull);
|
||||
expect(v.resolved, isTrue);
|
||||
expect(v.allOk, isFalse);
|
||||
expect(v.missing, ['git', 'pql', 'tmux']);
|
||||
});
|
||||
|
||||
test('missing reports only the unresolved tools', () {
|
||||
final v = ToolchainView.resolved(const ResolvedPaths(
|
||||
git: '/opt/git',
|
||||
// pql + tmux null → missing.
|
||||
));
|
||||
expect(v.missing, ['pql', 'tmux']);
|
||||
expect(v.allOk, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user