import { describe, expect, it } from 'vitest';
import { createProjectTextDiff, decodeGitText } from '../diff';

describe('project Git diff', () => {
  it('keeps context and marks changed lines', () => {
    expect(createProjectTextDiff('alpha\nbeta\ngamma', 'alpha\nBETA\ngamma')).toEqual([
      { kind: 'context', text: 'alpha' },
      { kind: 'remove', text: 'beta' },
      { kind: 'add', text: 'BETA' },
      { kind: 'context', text: 'gamma' },
    ]);
  });

  it('treats binary and invalid UTF-8 blobs as non-text', () => {
    expect(decodeGitText(new Uint8Array([1, 0, 2]))).toBeUndefined();
    expect(decodeGitText(new Uint8Array([0xff, 0xfe]))).toBeUndefined();
    expect(decodeGitText(new TextEncoder().encode('main.tex'))).toBe('main.tex');
  });
});
