import { describe, it, expect } from 'vitest' import { extractMarkedLabel } from './instanceSettings' // SearchItems escapes the haystack before highlighting, so `marked` carries // entities where the label had `& < > " '`. The offset walk counts unescaped // characters, so an entity must advance it by one — otherwise the label is // truncated early and can be sliced mid-entity. describe('extractMarkedLabel', () => { it('counts an escaped character as one, not as its entity length', () => { const label = 'A & B' expect(extractMarkedLabel('A & B — category', label.length)).toBe('A & B') }) it('keeps the mark wrapper and stops at the label boundary', () => { const label = 'Base URL' expect(extractMarkedLabel('Base URL — general', label.length)).toBe( 'Base URL' ) }) it('never slices an entity in half', () => { const label = '"q" & ' const out = extractMarkedLabel('"q" & <x> — trailing', label.length) expect(out).toBe('"q" & <x>') expect(out.endsWith(';')).toBe(true) }) })