#[cfg(test)]
mod tests {
- use super::*;
- use crate::file_handler::FileType;
use std::collections::HashSet;
+ use std::path::PathBuf;
use std::fs::create_dir_all;
- fn fixtures_dir() -> PathBuf {
- PathBuf::from("tests/fixtures")
- }
+ use super::*;
- fn get_paths(files: &Vec<File>) -> HashSet<String> {
+ use crate::file_handler::FileType;
+ use crate::file_handler::File;
+ use test_utilities::*;
+
+ fn get_paths(root_directory: &PathBuf, files: &Vec<File>) -> HashSet<String> {
files
.iter()
- .map(|f| f.path.strip_prefix(&fixtures_dir()).unwrap().to_string_lossy().to_string())
+ .map( |file|
+ file.path
+ .strip_prefix(root_directory)
+ .unwrap()
+ .to_string_lossy()
+ .to_string()
+ )
.collect()
}
#[test]
fn finds_all_files() {
- let files = find_files(&fixtures_dir());
- let paths = get_paths(&files);
+ let test_dir = setup_test_dir();
+ create_dir_all(&test_dir.join("nested"))
+ .expect("Could not create nested test directory");
+ create_dir_all(&test_dir.join("assets"))
+ .expect("Could not create assets test directory");
+ create_test_file(&test_dir.join("test1.gmi"), "");
+ create_test_file(&test_dir.join("_layout.html"), "");
+ create_test_file(&test_dir.join("nested/nested.gmi"), "");
+ create_test_file(&test_dir.join("assets/style.css"), "");
+ create_test_file(&test_dir.join("image.png"), "");
+
+ let files = find_files(&test_dir);
+ let paths = get_paths(&test_dir, &files);
assert!(paths.contains("test1.gmi"));
assert!(paths.contains("_layout.html"));
#[test]
fn identifies_correct_file_types() {
- let files = find_files(&fixtures_dir());
+ let test_dir = setup_test_dir();
+ create_dir_all(&test_dir.join("nested"))
+ .expect("Could not create nested test directory");
+ create_dir_all(&test_dir.join("assets"))
+ .expect("Could not create assets test directory");
+ create_test_file(&test_dir.join("_layout.html"), "");
+ create_test_file(&test_dir.join("nested/nested.gmi"), "");
+ create_test_file(&test_dir.join("assets/style.css"), "");
+ create_test_file(&test_dir.join("image.png"), "");
+ let files = find_files(&test_dir);
for file in files {
let extension = file.path.extension().and_then(|e| e.to_str());
#[test]
fn ignores_git_directory() {
- let files = find_files(&fixtures_dir());
- let paths = get_paths(&files);
+ let test_dir = setup_test_dir();
+ create_dir_all(&test_dir.join("nested"))
+ .expect("Could not create nested test directory");
+ create_dir_all(&test_dir.join("assets"))
+ .expect("Could not create assets test directory");
+ create_dir_all(&test_dir.join(".git"))
+ .expect("Could not create git test directory");
+ create_test_file(&test_dir.join("_layout.html"), "");
+ create_test_file(&test_dir.join("nested/nested.gmi"), "");
+ create_test_file(&test_dir.join("assets/style.css"), "");
+ create_test_file(&test_dir.join("image.png"), "");
+ create_test_file(&test_dir.join(".git/config"), "");
+ let files = find_files(&test_dir);
+
+ let paths = get_paths(&test_dir, &files);
- // These files should exist in the fixtures but not be included
assert!(!paths.iter().any(|p| p.starts_with(".git/")));
assert!(!paths.contains(".gitignore"));
}
- #[test]
- fn handles_nested_directories() {
- let files = find_files(&fixtures_dir());
- let paths = get_paths(&files);
-
- // Check that files in nested directories are found
- assert!(paths.contains("nested/nested.gmi"));
- assert!(paths.contains("assets/style.css"));
-
- // Verify directory structure is preserved in paths
- let nested_files: Vec<_> = files.iter()
- .filter(|f| f.path.starts_with(fixtures_dir().join("nested")))
- .collect();
- assert!(!nested_files.is_empty());
- }
-
#[test]
fn returns_empty_for_empty_directory() {
- let empty_dir = fixtures_dir().join("empty");
- let _ = create_dir_all(&empty_dir);
- let files = find_files(&empty_dir);
+ let test_dir = setup_test_dir();
+ let files = find_files(&test_dir);
assert!(files.is_empty());
}
}