test(search): add applyOffsets coverage for negative start offsets
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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 }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user