//! Tests for fluent markdown processing

use rustelo_core_lib::fluent::{generate_slug, MarkdownProcessor};

#[test]
fn test_generate_slug() {
    assert_eq!(generate_slug("Hello World"), "hello-world");
    assert_eq!(
        generate_slug("Rust Web Development 2024"),
        "rust-web-development-2024"
    );
    assert_eq!(
        generate_slug("Test & Special Characters!"),
        "test-special-characters"
    );
}

#[test]
fn test_markdown_processor() {
    let processor = MarkdownProcessor::new();
    let markdown = "# Hello\n\nThis is a **test**.";
    let html = processor.markdown_to_html(markdown);
    assert!(html.contains("<h1>Hello</h1>"));
    assert!(html.contains("<strong>test</strong>"));
}

#[test]
fn test_frontmatter_extraction() {
    let processor = MarkdownProcessor::new();
    let markdown = r#"---
title: "Test Post"
published: true
featured: false
tags: ["rust", "web"]
---

# Content

This is the actual content."#;

    let (metadata, content) = processor.extract_frontmatter(markdown).unwrap();
    assert_eq!(metadata.title, Some("Test Post".to_string()));
    assert!(metadata.published);
    assert_eq!(metadata.tags, vec!["rust", "web"]);
    assert!(content.contains("# Content"));
}

#[test]
fn test_excerpt_extraction() {
    let processor = MarkdownProcessor::new();
    let html = "<h1>Title</h1><p>This is a long paragraph with many words that should be \
                truncated properly.</p>";
    let excerpt = processor.extract_excerpt(html, 50);
    assert!(excerpt.len() <= 53); // 50 + "..."
    assert!(excerpt.ends_with("..."));
}
