+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::fs;
+
+ fn setup() -> Strategy {
+ Strategy {}
+ }
+
+ fn fixtures_dir() -> PathBuf {
+ PathBuf::from("tests/fixtures")
+ }
+
+ fn fixture_path(filename: &str) -> PathBuf {
+ fixtures_dir().join(filename)
+ }
+
+ fn read_fixture(filename: &str) -> String {
+ fs::read_to_string(fixture_path(filename))
+ .unwrap_or_else(|_| panic!("Failed to read fixture file: {}", filename))
+ }
+
+ mod front_matter_tests {
+ use super::*;
+
+ #[test]
+ fn detects_title() {
+ let strategy = setup();
+ let content = read_fixture("test1.gmi");
+ let first_line = content.lines().next().unwrap();
+ assert!(strategy.is_title(first_line));
+ }
+
+ #[test]
+ fn detects_description() {
+ let strategy = setup();
+ let content = read_fixture("test1.gmi");
+ let second_line = content.lines().nth(1).unwrap();
+ assert!(strategy.is_description(second_line));
+ }
+
+ #[test]
+ fn extracts_title() {
+ let strategy = setup();
+ let content = read_fixture("test1.gmi");
+ let first_line = content.lines().next().unwrap();
+ assert_eq!(strategy.get_title(first_line).trim(), "Test Title");
+ }
+
+ #[test]
+ fn extracts_description() {
+ let strategy = setup();
+ let content = read_fixture("test1.gmi");
+ let second_line = content.lines().nth(1).unwrap();
+ assert_eq!(strategy.get_description(second_line).trim(), "Test Description");
+ }
+ }
+
+ mod file_type_tests {
+ use super::*;
+
+ #[test]
+ fn identifies_gemini_files() {
+ let strategy = setup();
+ assert!(strategy.is(&fixture_path("test1.gmi")));
+ assert!(!strategy.is(&fixture_path("_layout.html")));
+ assert!(!strategy.is(&fixtures_dir()));
+ }
+
+ #[test]
+ fn identifies_file_type() {
+ let strategy = setup();
+ assert!(matches!(strategy.identify(), FileType::Gemini));
+ }
+
+ #[test]
+ fn handles_correct_file_type() {
+ let strategy = setup();
+ assert!(strategy.can_handle(&FileType::Gemini));
+ assert!(!strategy.can_handle(&FileType::Layout));
+ assert!(!strategy.can_handle(&FileType::File));
+ assert!(!strategy.can_handle(&FileType::Unknown));
+ }
+ }
+
+ mod file_handling_tests {
+ use super::*;
+
+ #[test]
+ fn handles_html_generation() {
+ let strategy = setup();
+ let source = fixtures_dir();
+ let output = fixture_path("output");
+ let layout = read_fixture("_layout.html");
+
+ let file = File {
+ path: fixture_path("test1.gmi"),
+ file_type: FileType::Gemini,
+ };
+
+ strategy.handle_html(
+ &source,
+ &output,
+ &file,
+ &layout,
+ );
+
+ let generated_path = output.join("test1.html");
+ assert!(generated_path.exists());
+
+ let content = fs::read_to_string(generated_path.clone()).unwrap();
+ assert!(content.contains("Test Title"));
+ assert!(content.contains("<h1>"));
+
+ // Cleanup
+ let _ = fs::remove_file(generated_path);
+ }
+
+ #[test]
+ fn handles_gemini_generation() {
+ let strategy = setup();
+ let source = fixtures_dir();
+ let output = fixture_path("output");
+
+ let file = File {
+ path: fixture_path("test1.gmi"),
+ file_type: FileType::Gemini,
+ };
+
+ strategy.handle_gemini(
+ &source,
+ &output,
+ &file,
+ );
+
+ let generated_path = output.join("test1.gmi");
+ assert!(generated_path.exists());
+
+ let content = fs::read_to_string(&generated_path).unwrap();
+ assert!(content.contains("# Heading"));
+ assert!(!content.contains("Test Title")); // Front matter should be removed
+
+ // Cleanup
+ let _ = fs::remove_file(generated_path);
+ }
+
+ #[test]
+ fn handles_nested_structure() {
+ let strategy = setup();
+ let source = fixtures_dir();
+ let output = fixture_path("output");
+ let layout = read_fixture("_layout.html");
+
+ let file = File {
+ path: fixture_path("nested/nested.gmi"),
+ file_type: FileType::Gemini,
+ };
+
+ strategy.handle_html(
+ &source,
+ &output,
+ &file,
+ &layout,
+ );
+
+ let generated_path = output.join("nested").join("nested.html");
+ assert!(generated_path.exists());
+
+ // Cleanup
+ let _ = fs::remove_file(generated_path);
+ let _ = fs::remove_dir(output.join("nested"));
+ }
+ }
+}