mini-docs 0.7.0

A minimal, secure build-time Markdown to HTML generator for the mini-* family.
Documentation
use super::*;
use serde_json::json;

#[test]
fn parses_title_string_and_list_fields() {
    let input =
        "---\ntitle: Getting Started\nauthor: \"Jane Doe\"\ntags: [rust, docs, cli]\n---\n# Body\n";

    let (frontmatter, body) = split_frontmatter(input).expect("valid frontmatter");

    assert_eq!(
        frontmatter,
        json!({
            "title": "Getting Started",
            "author": "Jane Doe",
            "tags": ["rust", "docs", "cli"],
        })
    );
    assert_eq!(body, "# Body\n");
}

#[test]
fn no_leading_delimiter_returns_empty_frontmatter_and_full_body() {
    let input = "# Just Markdown\nNo frontmatter here.\n";

    let (frontmatter, body) = split_frontmatter(input).expect("no frontmatter is not an error");

    assert_eq!(frontmatter, json!({}));
    assert_eq!(body, input);
}

#[test]
fn unterminated_block_is_a_frontmatter_error() {
    let input = "---\ntitle: Unterminated\n# Body without closing delimiter\n";

    let err = split_frontmatter(input).expect_err("missing closing delimiter must error");

    assert!(matches!(err, DocError::Frontmatter(_)));
}

#[test]
fn empty_frontmatter_block_yields_empty_object() {
    let input = "---\n---\nbody text\n";

    let (frontmatter, body) = split_frontmatter(input).expect("empty block is valid");

    assert_eq!(frontmatter, json!({}));
    assert_eq!(body, "body text\n");
}

#[test]
fn duplicate_key_is_a_frontmatter_error() {
    let input = "---\ntitle: One\ntitle: Two\n---\nbody\n";

    let err = split_frontmatter(input).expect_err("duplicate key must error");

    assert!(matches!(err, DocError::Frontmatter(_)));
}

#[test]
fn bare_true_and_false_parse_as_booleans() {
    let input = "---\npinned: true\ndraft: false\n---\nbody\n";

    let (frontmatter, _) = split_frontmatter(input).expect("valid frontmatter");

    assert_eq!(frontmatter, json!({"pinned": true, "draft": false}));
}

#[test]
fn quoted_true_stays_a_string() {
    let input = "---\nnote: \"true\"\n---\nbody\n";

    let (frontmatter, _) = split_frontmatter(input).expect("valid frontmatter");

    assert_eq!(frontmatter, json!({"note": "true"}));
}

#[test]
fn version_number_stays_a_string_by_design() {
    let input = "---\nversion: 2\n---\nbody\n";

    let (frontmatter, _) = split_frontmatter(input).expect("valid frontmatter");

    assert_eq!(frontmatter, json!({"version": "2"}));
}