overcast 0.1.3

Strongly typed changelogs for projects as changeable as the weather
Documentation
use crate::Changelog;
use askama::Template;

#[derive(Template)]
#[template(path = "markdown.md", whitespace = "minimize")]
pub struct Markdown<'a> {
    changelog: &'a Changelog,
}

/// Render a changelog as a markdown document
pub fn render_markdown(changelog: &Changelog) -> Result<String, askama::Error> {
    Markdown { changelog }.render()
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::release::Release;
    use crate::Change;
    use expect_test::expect;

    #[test]
    fn test_simple_output() {
        let changelog = Changelog::new("Test Changelog");

        let rendered = render_markdown(&changelog).unwrap();

        expect![[r#"
            # Test Changelog



        "#]]
        .assert_eq(&rendered)
    }

    #[test]
    fn test_header_rendering() {
        let changelog = Changelog::new("Test Changelog")
            .with_description("Test Description")
            .add_semantic_versioning_message()
            .add_keep_a_changelog_message();

        let rendered = render_markdown(&changelog).unwrap();

        expect![[r#"
            # Test Changelog

            Test Description

            The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

        "#]]
        .assert_eq(&rendered)
    }

    #[test]
    fn test_realease_rendering() {
        let changelog = Changelog::new("Test Changelog")
            .add_release(
                Release::unreleased()
                    .added(Change::new("Amazing feature").with_ticket_id("123"))
                    .added("Incredible bug!")
                    .fixed("Nothing"),
            )
            .add_release(
                Release::new(0, 1, 0)
                    .added("A")
                    .changed("B")
                    .deprecated("C")
                    .removed("D")
                    .fixed("E")
                    .security("F"),
            )
            .add_release(
                Release::new(2, 4, 0)
                    .with_date(1976, 5, 12)
                    .deprecated("The one useful feature you needed from this thing")
                    .yank(),
            );

        let rendered = render_markdown(&changelog).unwrap();

        expect![[r#"
            # Test Changelog



            ## Unreleased

            ### Added
            - Amazing feature (#123)

            - Incredible bug!


            ### Fixed
            - Nothing

            ## 0.1.0

            ### Added
            - A


            ### Changed
            - B


            ### Deprecated
            - C


            ### Removed
            - D


            ### Fixed
            - E


            ### Security
            - F

            ## 2.4.0 - 1976-05-12 - [YANKED]

            ### Deprecated
            - The one useful feature you needed from this thing

        "#]]
        .assert_eq(&rendered)
    }
}