cartulary 0.3.0-alpha.1

The knowledge layer of your project — decisions, issues, docs, all in one place.
Documentation
use super::Source;
use crate::domain::model::body::Body;

/// A single Markdown file fed to the site walker. `content` carries the
/// raw file (frontmatter included); the walker parses it.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MarkdownEntry {
    pub source: Source,
    pub content: Body,
}

impl MarkdownEntry {
    pub fn new(source: Source, content: Body) -> Self {
        Self { source, content }
    }
}

#[cfg(test)]
pub mod strategy {
    use super::super::source::strategy::relative_path;
    use super::MarkdownEntry;
    use crate::domain::model::body::Body;
    use proptest::prelude::*;

    prop_compose! {
        pub fn markdown_entry()(
            source in relative_path(),
            content in ".{0,80}",
        ) -> MarkdownEntry {
            MarkdownEntry::new(source, Body::new(&content))
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use proptest::prelude::*;

    proptest! {
        #[test]
        fn round_trips_fields(e in strategy::markdown_entry()) {
            let again = MarkdownEntry::new(e.source.clone(), e.content.clone());
            prop_assert_eq!(again, e);
        }
    }

    fn src(s: &str) -> Source {
        Source::relative_path(s).unwrap()
    }

    #[test]
    fn carries_source_and_content() {
        let e = MarkdownEntry::new(src("intro.md"), Body::new("# Hi"));
        assert_eq!(e.source.as_str(), "intro.md");
        assert_eq!(e.content.as_str(), "# Hi");
    }
}