#[cfg(test)]
mod tests {
- use super::*;
use std::path::PathBuf;
- fn create_test_file(path: &str, file_type: FileType) -> File {
+ use super::*;
+
+ use test_utilities::*;
+
+ fn create_test_internal_file(path: &str, file_type: FileType) -> File {
File {
path: PathBuf::from(path),
file_type,
#[test]
fn test_identify_unknown_file() {
let handler = FileHandler::default();
- let path = PathBuf::from("tests/fixtures");
+ let path = PathBuf::from("tests");
assert!(matches!(handler.identify(&path), FileType::Unknown));
}
#[test]
fn test_get_layout_success() {
+ let test_dir = setup_test_dir();
+ let layout_path = test_dir.join("_layout.html");
+ create_test_file(&layout_path, "");
+
let mut handler = FileHandler::default();
let files = vec![
- create_test_file("test.gmi", FileType::Gemini),
- create_test_file("tests/fixtures/_layout.html", FileType::Layout),
- create_test_file("regular.html", FileType::File),
+ create_test_internal_file("test.gmi", FileType::Gemini),
+ create_test_internal_file(&layout_path.to_str().expect("Could not encode layout"), FileType::Layout),
+ create_test_internal_file("regular.html", FileType::File),
];
assert!(handler.get_layout_or_panic(&files).is_ok());
fn test_get_layout_failure() {
let mut handler = FileHandler::default();
let files = vec![
- create_test_file("test.gmi", FileType::Gemini),
- create_test_file("regular.html", FileType::File),
+ create_test_internal_file("test.gmi", FileType::Gemini),
+ create_test_internal_file("regular.html", FileType::File),
];
assert!(handler.get_layout_or_panic(&files).is_err());
let mut handler = FileHandler::default();
handler.layout = Some("test layout".to_string());
- let file = create_test_file("tests/fixtures/test1.gmi", FileType::Gemini);
+ let file = create_test_internal_file("tests/fixtures/test1.gmi", FileType::Gemini);
// Should not panic with valid layout
handler.handle(
#[should_panic(expected = "Layout should be initialized before handling files")]
fn test_handle_without_layout() {
let handler = FileHandler::default();
- let file = create_test_file("test.gmi", FileType::Gemini);
+ let file = create_test_internal_file("test.gmi", FileType::Gemini);
handler.handle(
&PathBuf::from("source"),
#[test]
fn test_slice_handling() {
+ let test_dir = setup_test_dir();
+ let layout_path = test_dir.join("_layout.html");
+ create_test_file(&layout_path, "");
+
let mut handler = FileHandler::default();
let files = vec![
- create_test_file("tests/fixtures/test1.gmi", FileType::Gemini),
- create_test_file("tests/fixtures/_layout.html", FileType::Layout),
- create_test_file("tests/fixtures/test2.gmi", FileType::Gemini),
- create_test_file("tests/fixtures/test3.gmi", FileType::Gemini),
+ create_test_internal_file("tests/fixtures/test1.gmi", FileType::Gemini),
+ create_test_internal_file(&layout_path.to_str().expect("Could not encode layout"), FileType::Layout),
+ create_test_internal_file("tests/fixtures/test2.gmi", FileType::Gemini),
+ create_test_internal_file("tests/fixtures/test3.gmi", FileType::Gemini),
];
let _ = handler.get_layout_or_panic(&files[1..]);