Files
clide/test/kernel/src/fuzzy_test.dart
T
jpmschweitzerandClaude 0e85f7f5e7 fuzzy-match + recency-rank the command palette
Completes the command-palette acceptance: the filter is now a
subsequence fuzzy match (was substring), and recently-invoked commands
float to the top and break score ties. The subsequence matcher is
extracted to a shared fuzzy helper so the palette and quick-open file
finder use one implementation instead of a private copy each.

Pinned commands and cross-session recency persistence are left as a
follow-up (they need a pin affordance + settings storage).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-06 09:40:56 +02:00

36 lines
1.3 KiB
Dart

import 'package:clide/kernel/src/fuzzy.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('fuzzyScore', () {
test('empty query scores 0 (matches anything)', () {
expect(fuzzyScore('anything', ''), 0);
});
test('returns null when query is not a subsequence', () {
expect(fuzzyScore('git commit', 'xyz'), isNull);
expect(fuzzyScore('abc', 'abcd'), isNull); // query longer / extra char
});
test('matches non-contiguous subsequences', () {
expect(fuzzyScore('git commit', 'gc'), isNotNull);
expect(fuzzyScore('theme pick', 'tp'), isNotNull);
});
test('lower score is better: contiguous + early beats gappy + late', () {
final contiguousEarly = fuzzyScore('abcxxxx', 'abc')!; // match at 0,1,2
final gappyLate = fuzzyScore('xxxxabc', 'abc')!; // starts at 4
expect(contiguousEarly, lessThan(gappyLate));
final tight = fuzzyScore('ab', 'ab')!; // adjacent
final spread = fuzzyScore('axb', 'ab')!; // a gap between a and b
expect(tight, lessThan(spread));
});
test('case sensitivity is the caller\'s responsibility', () {
expect(fuzzyScore('GIT', 'git'), isNull); // differing case → no match
expect(fuzzyScore('GIT'.toLowerCase(), 'git'), isNotNull);
});
});
}