diff --git a/frontend/src/lib/search.spec.ts b/frontend/src/lib/search.spec.ts index d6bd1397..512235c9 100644 --- a/frontend/src/lib/search.spec.ts +++ b/frontend/src/lib/search.spec.ts @@ -92,4 +92,19 @@ describe('applyOffsets', () => { { text: 'Brief', highlight: true } ]); }); + + it('clamps negative start to 0 and highlights from the beginning', () => { + // start = -2, length = 5 → effective range [-2, 3) → clamped to [0, 3) + expect(applyOffsets('Hello', [{ start: -2, length: 5 }])).toEqual([ + { text: 'Hel', highlight: true }, + { text: 'lo', highlight: false } + ]); + }); + + it('ignores offset whose end is also negative', () => { + // start = -5, length = 2 → end = -3, completely before text + expect(applyOffsets('Hi', [{ start: -5, length: 2 }])).toEqual([ + { text: 'Hi', highlight: false } + ]); + }); });