// Tests for CJK-safe search text normalization + matching (F8). import 'package:flutter_test/flutter_test.dart'; import 'package:badnote/editor/search/search_text.dart'; void main() { group('normalizeForIndex', () { test('lowercases and collapses whitespace runs to single spaces', () { expect(normalizeForIndex('Hello World'), 'hello world'); expect(normalizeForIndex('a\t b\n\nc'), 'a b c'); }); test('trims leading/trailing whitespace', () { expect(normalizeForIndex(' padded '), 'padded'); }); test('collapses hard newlines from PDF/OCR mid-sentence', () { expect(normalizeForIndex('hello\nworld'), 'hello world'); }); test('leaves CJK intact (no tokenization/mangling)', () { expect(normalizeForIndex('你好 世界'), '你好 世界'); expect(normalizeForIndex('笔记\n应用'), '笔记 应用'); }); }); group('matchesNormalized', () { test('matches across a line break in the source', () { expect(matchesNormalized('hello\nworld', 'hello world'), isTrue); }); test('is case-insensitive', () { expect(matchesNormalized('The Quick Fox', 'quick'), isTrue); }); test('CJK substring match works', () { expect(matchesNormalized('这是一个笔记应用', '笔记'), isTrue); expect(matchesNormalized('这是一个笔记\n应用', '笔记 应用'), isTrue); }); test('empty query never matches', () { expect(matchesNormalized('anything', ''), isFalse); expect(matchesNormalized('anything', ' '), isFalse); }); test('non-match returns false', () { expect(matchesNormalized('hello world', 'zzz'), isFalse); }); }); }