+ #[test]
+ fn detects_description() {
+ let strategy = Strategy {};
+ assert!(strategy.is_description("--- description: What is this?"));
+ }
+
+ #[test]
+ fn does_not_detect_other_keys_as_description() {
+ let strategy = Strategy {};
+ assert!(!strategy.is_description("--- title: What is this?"));
+ }
+
+ #[test]
+ fn extracts_title() {
+ let strategy = Strategy {};
+ assert_eq!(strategy.get_title("--- title: Hello!").trim(), "Hello!");
+ }
+
+ #[test]
+ fn extracts_description() {
+ let strategy = Strategy {};
+ assert_eq!(
+ strategy
+ .get_description("--- description: What is this?")
+ .trim(),
+ "What is this?"
+ );
+ }
+
+ #[test]
+ fn identifies_gemini_file() {
+ let test_dir = setup_test_dir();
+ create_test_file(&test_dir.join("test.gmi"), "");
+ let strategy = Strategy {};
+ assert!(strategy.is(&test_dir.join("test.gmi")));
+ }
+
+ #[test]
+ fn rejects_non_gemini_file() {
+ let test_dir = setup_test_dir();
+ create_test_file(&test_dir.join("_layout.html"), "");
+ create_test_file(&test_dir.join("image.png"), "");
+ let strategy = Strategy {};
+ assert!(!strategy.is(&test_dir.join("_layout.html")));
+ assert!(!strategy.is(&test_dir.join("image.png")));
+ assert!(!strategy.is(&test_dir));
+ }
+
+ #[test]
+ fn identifies_gemini_type() {
+ let strategy = Strategy {};
+ assert!(matches!(strategy.identify(), FileType::Gemini));
+ }
+
+ #[test]
+ fn handles_gemini_type() {
+ let strategy = Strategy {};
+ assert!(strategy.can_handle(&FileType::Gemini));
+ }
+
+ #[test]
+ fn rejects_non_gemini_types() {
+ let strategy = Strategy {};
+ assert!(!strategy.can_handle(&FileType::Layout));
+ assert!(!strategy.can_handle(&FileType::File));
+ assert!(!strategy.can_handle(&FileType::Unknown));
+ }
+
+ #[test]
+ fn handles_html_generation() {
+ let test_dir = setup_test_dir();
+ let source_dir = test_dir.join("source");
+ let output_dir = test_dir.join("output");
+ create_dir_all(&source_dir).expect("Could not create source test directory");
+ create_dir_all(&output_dir).expect("Could not create output test directory");
+ let layout = "\
+<html>
+<head>
+<title>{{ title }}</title>
+<meta name=\"description\" content=\"{{ description }}\">
+</head>
+<body>{{ content }}</body>
+</html>
+";
+ create_test_file(
+ &source_dir.join("test.gmi"),
+ "\
+--- title: Page Is Cool!
+--- description: My Description
+# Test
+Hello world
+",
+ );
+
+ let strategy = Strategy {};
+ let file = File {
+ path: source_dir.join("test.gmi"),
+ file_type: FileType::Gemini,
+ };
+
+ strategy.handle_html(&source_dir, &output_dir, &file, &layout);
+
+ let html_output = output_dir.join("test.html");
+ assert!(html_output.exists());
+ assert_file_contents(
+ &html_output,
+ "\
+<html>
+<head>
+<title>Page Is Cool!</title>
+<meta name=\"description\" content=\"My Description\">
+</head>
+<body><section class=\"h1\">
+<h1> Test</h1>
+<p>Hello world</p>
+</section>
+</body>
+</html>
+",
+ );
+ }
+
+ #[test]
+ fn handles_gemini_generation() {
+ let test_dir = setup_test_dir();
+ let source_dir = test_dir.join("source");
+ let output_dir = test_dir.join("output");
+ create_dir_all(&source_dir).expect("Could not create source test directory");
+ create_dir_all(&output_dir).expect("Could not create output test directory");
+ create_test_file(
+ &source_dir.join("test.gmi"),
+ "\
+--- title: Page Is Cool!
+--- description: My Description
+# Test
+Hello world
+",
+ );
+
+ let strategy = Strategy {};
+ let file = File {
+ path: source_dir.join("test.gmi"),
+ file_type: FileType::Gemini,
+ };
+
+ strategy.handle_gemini(&source_dir, &output_dir, &file);
+
+ let gemini_output = output_dir.join("test.gmi");
+ assert!(gemini_output.exists());
+ assert_file_contents(
+ &gemini_output,
+ "\
+# Test
+Hello world
+",
+ );
+ }
+
+ #[test]
+ fn handles_nested_structure() {
+ let test_dir = setup_test_dir();
+ let source_dir = test_dir.join("source");
+ let output_dir = test_dir.join("output");
+ create_dir_all(&source_dir.join("nested")).expect("Could not create source test directory");
+ create_dir_all(&output_dir).expect("Could not create output test directory");
+ let layout = "\
+<html>
+<head>
+<title>{{ title }}</title>
+<meta name=\"description\" content=\"{{ description }}\">
+</head>
+<body>{{ content }}</body>
+</html>
+";
+ create_test_file(
+ &source_dir.join("nested/test.gmi"),
+ "\
+--- title: Page Is Cool!
+--- description: My Description
+# Test
+Hello world
+",
+ );
+
+ let strategy = Strategy {};
+ let file = File {
+ path: source_dir.join("nested/test.gmi"),
+ file_type: FileType::Gemini,
+ };
+
+ strategy.handle_html(&source_dir, &output_dir, &file, &layout);
+
+ let html_output = output_dir.join("nested/test.html");
+ assert!(html_output.exists());
+ assert_file_contents(
+ &html_output,
+ "\
+<html>
+<head>
+<title>Page Is Cool!</title>
+<meta name=\"description\" content=\"My Description\">
+</head>
+<body><section class=\"h1\">
+<h1> Test</h1>
+<p>Hello world</p>
+</section>
+</body>
+</html>
+",
+ );