import { describe, expect, it } from 'vitest';
import { applySourceTextEdits } from '../text-edit';

describe('applySourceTextEdits', () => {
  it('applies multiple original-coordinate edits from the end of source', () => {
    expect(
      applySourceTextEdits('AA old BB text CC', [
        { from: 3, to: 6, text: 'much longer heading' },
        { from: 10, to: 14, text: 'paragraph' },
      ]),
    ).toBe('AA much longer heading BB paragraph CC');
  });

  it('rejects overlapping edits', () => {
    expect(() =>
      applySourceTextEdits('abcdef', [
        { from: 1, to: 4, text: 'x' },
        { from: 3, to: 5, text: 'y' },
      ]),
    ).toThrow('Overlapping source edits');
  });
});
