import { describe, expect, it } from 'vitest';
import {
  projectDirectoryPath,
  projectFilePath,
  safeProjectFilePath,
} from '../project-path';

describe('project paths', () => {
  it.each([
    'main.tex',
    'Makefile',
    'LICENSE',
    '.git/HEAD',
    '.latexmkrc',
    'figures/plot.pdf',
    'chapters/01 introduction.tex',
  ])('accepts ordinary project file %s', (path) => {
    expect(projectFilePath(path)).toBe(path);
  });

  it.each([
    '../secret.tex',
    './main.tex',
    '/etc/passwd',
    'C:/secret.tex',
    'folder\\file.tex',
    'folder//file.tex',
  ])('rejects unsafe project file %s', (path) => {
    expect(safeProjectFilePath(path).ok).toBe(false);
  });

  it('normalizes directory paths with a trailing slash', () => {
    expect(projectDirectoryPath('figures')).toBe('figures/');
    expect(projectDirectoryPath('figures/generated/')).toBe(
      'figures/generated/',
    );
  });
});
