import { describe, expect, it } from 'vitest';
import {
  MemoryProjectStorage,
  projectFilePath,
} from '../index';

describe('MemoryProjectStorage', () => {
  it('preserves binary files without text conversion', async () => {
    const storage = new MemoryProjectStorage();
    const path = projectFilePath('figures/example.pdf');
    const input = new Uint8Array([0, 255, 1, 128, 42]);

    await storage.writeFile(path, input);
    input[0] = 99;

    expect(await storage.readFile(path)).toEqual(
      new Uint8Array([0, 255, 1, 128, 42]),
    );
  });

  it('supports extensionless Git and project files', async () => {
    const storage = new MemoryProjectStorage();
    await storage.writeFile(projectFilePath('Makefile'), new Uint8Array([1]));
    await storage.writeFile(projectFilePath('.git/HEAD'), new Uint8Array([2]));

    expect((await storage.listEntries()).map((entry) => entry.path)).toEqual([
      '.git/',
      '.git/HEAD',
      'Makefile',
    ]);
  });
});
