use std::path::{Path, PathBuf};
use std::fs;
use tempfile::TempDir;
use seams::incremental::generate_aux_file_path;
pub struct TestFixture {
_temp_dir: TempDir,
pub root_path: PathBuf,
}
impl TestFixture {
pub fn new() -> Self {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let root_path = temp_dir.path().to_path_buf();
Self {
_temp_dir: temp_dir,
root_path,
}
}
pub fn create_gutenberg_file<P: AsRef<Path>>(&self, relative_path: P, content: &str) -> PathBuf {
let file_path = self.root_path.join(relative_path);
if let Some(parent) = file_path.parent() {
fs::create_dir_all(parent).expect("Failed to create parent directories");
}
fs::write(&file_path, content).expect("Failed to write test file");
file_path
}
pub fn generate_aux_file_path<P: AsRef<Path>>(&self, source_path: P) -> PathBuf {
generate_aux_file_path(source_path.as_ref())
}
#[allow(dead_code)]
pub fn create_partial_aux_file<P: AsRef<Path>>(&self, source_path: P, content: &str) -> PathBuf {
let aux_path = self.generate_aux_file_path(source_path);
fs::write(&aux_path, content.trim_end_matches('\n')).expect("Failed to write partial aux file");
aux_path
}
}