Some checks failed
CI / Windows build (push) Has been cancelled
Whole-project `flutter analyze` exited 1 on 17 pre-existing info/warning lints (no errors) in dev tools and test files. Clean them so analyze is green: - editor_repository_test: drop the redundant sqflite_common import; keep the used utils import with a transitive-dep ignore. - pen_* widget tests: `(_, __)` wildcard params -> `(_, _)`. - search_snippet_test / gen_bench_pdf / gen_dense_strokes: drop needless interpolation braces; remove an unused `Size` show and an unused local; mark the gen tool as print-allowed. No runtime behavior changed. flutter analyze: No issues found. Affected tests: 22/22 pass.
66 lines
2.2 KiB
Dart
66 lines
2.2 KiB
Dart
// Tests for pure search-snippet extraction (F8).
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:badnote/editor/search/search_snippet.dart';
|
|
|
|
void main() {
|
|
test('returns null for empty query, empty source, or no match', () {
|
|
expect(snippetFor('hello world', ''), isNull);
|
|
expect(snippetFor('', 'x'), isNull);
|
|
expect(snippetFor('hello world', 'zzz'), isNull);
|
|
});
|
|
|
|
test('case-insensitive match, offset preserved within the snippet', () {
|
|
final s = snippetFor('The Quick Brown Fox', 'quick', window: 80)!;
|
|
expect(s.match.toLowerCase(), 'quick');
|
|
expect(s.text.substring(s.matchStart, s.matchStart + s.matchLength),
|
|
'Quick');
|
|
});
|
|
|
|
test('short source is returned whole, no truncation', () {
|
|
final s = snippetFor('alpha beta gamma', 'beta', window: 80)!;
|
|
expect(s.text, 'alpha beta gamma');
|
|
expect(s.truncatedStart, isFalse);
|
|
expect(s.truncatedEnd, isFalse);
|
|
expect(s.matchStart, 'alpha '.length);
|
|
});
|
|
|
|
test('long source is windowed and truncated on both sides', () {
|
|
final source = '${'a' * 200} needle ${'b' * 200}';
|
|
final s = snippetFor(source, 'needle', window: 40)!;
|
|
expect(s.truncatedStart, isTrue);
|
|
expect(s.truncatedEnd, isTrue);
|
|
expect(s.match, 'needle');
|
|
// Window is ~40 + match; nowhere near the full 400+ source.
|
|
expect(s.text.length, lessThan(80));
|
|
});
|
|
|
|
test('match near the start has no leading truncation', () {
|
|
final source = 'needle ${'b' * 200}';
|
|
final s = snippetFor(source, 'needle', window: 40)!;
|
|
expect(s.truncatedStart, isFalse);
|
|
expect(s.matchStart, 0);
|
|
expect(s.truncatedEnd, isTrue);
|
|
});
|
|
|
|
test('match near the end has no trailing truncation', () {
|
|
final source = '${'a' * 200} needle';
|
|
final s = snippetFor(source, 'needle', window: 40)!;
|
|
expect(s.truncatedEnd, isFalse);
|
|
expect(s.truncatedStart, isTrue);
|
|
});
|
|
|
|
test('the full match is included even when longer than the window', () {
|
|
final long = 'x' * 100;
|
|
final s = snippetFor('pre $long post', long, window: 10)!;
|
|
expect(s.match, long);
|
|
expect(s.matchLength, 100);
|
|
});
|
|
|
|
test('finds the FIRST occurrence', () {
|
|
final s = snippetFor('cat dog cat', 'cat', window: 80)!;
|
|
expect(s.matchStart, 0);
|
|
});
|
|
}
|