import { describe, it, expect } from 'vitest';
import { parseFocusTags } from '../src/lib/format.js';

describe('parseFocusTags', () => {
  it('trims, splits on commas, drops empties', () => {
    expect(parseFocusTags(' GDPR, Telemetry, , Policy ')).toEqual(['GDPR', 'Telemetry', 'Policy']);
  });

  it('caps at 3 entries', () => {
    expect(parseFocusTags('a,b,c,d,e')).toEqual(['a', 'b', 'c']);
  });

  it('caps each entry at 24 chars', () => {
    expect(parseFocusTags('a-very-long-tag-that-runs-on-forever')).toEqual(['a-very-long-tag-that-run']);
  });

  it('dedupes after normalisation', () => {
    expect(parseFocusTags('GDPR, gdpr, GDPR')).toEqual(['GDPR', 'gdpr']); // case-sensitive
    expect(parseFocusTags('Foo, Foo, Foo')).toEqual(['Foo']);
  });

  it('collapses internal whitespace so visually-identical tags merge', () => {
    expect(parseFocusTags('Healthcare  data, Healthcare data')).toEqual(['Healthcare data']);
  });

  it('strips ASCII control characters', () => {
    expect(parseFocusTags('Policy, Telemetry')).toEqual(['Policy', 'Telemetry']);
  });

  it('returns [] on empty input', () => {
    expect(parseFocusTags('')).toEqual([]);
    expect(parseFocusTags('   ')).toEqual([]);
    expect(parseFocusTags(',,,')).toEqual([]);
  });
});
