verctl-core 0.9.5

Core configuration, manifest, fragment, changelog, and version domain logic for verctl
Documentation
use indoc::indoc;

use super::{Record, Stop, read, write};

fn limited() -> Stop {
    Stop::new(
        "shrub-process",
        "0.7.0",
        "429 Too Many Requests",
        Some("Fri, 13 Nov 2026 19:00:00 GMT".to_owned()),
    )
}

#[test]
fn a_record_reads_back_as_written() {
    let notes = indoc! {"
        ## shrub 0.7.0

        - Notes.
    "};
    let body = write(notes, &limited()).unwrap();
    assert_eq!(
        body,
        indoc! {r#"
            ## shrub 0.7.0

            - Notes.

            <!-- verctl:stop {"package":"shrub-process","version":"0.7.0","cause":"429 Too Many Requests","retry_after":"Fri, 13 Nov 2026 19:00:00 GMT"} -->
        "#}
    );
    assert_eq!(read(&body), Record::Read(limited()));
}

#[test]
fn an_unknown_field_is_unreadable() {
    let body = indoc! {r#"
        - Notes.

        <!-- verctl:stop {"package":"a","version":"1.0.0","cause":"x","extra":true} -->
    "#};
    assert_eq!(read(body), Record::Unreadable);
}

#[test]
fn a_comment_that_is_not_json_is_unreadable() {
    assert_eq!(read("<!-- verctl:stop not json -->"), Record::Unreadable);
    assert_eq!(read("<!-- verctl:stop"), Record::Unreadable);
}

#[test]
fn a_body_with_no_record_has_none() {
    let body = indoc! {"
        ## demo 1.0.0

        <!-- a comment -->
    "};
    assert_eq!(read(body), Record::Absent);
}

#[test]
fn writing_a_record_twice_keeps_one() {
    let first = write("- Notes.", &Stop::new("a", "1.0.0", "exit 1", None)).unwrap();
    let second = write(&first, &limited()).unwrap();
    assert_eq!(second.matches("verctl:stop").count(), 1, "{second}");
    assert!(second.starts_with("- Notes."), "{second}");
    assert_eq!(read(&second), Record::Read(limited()));
}

#[test]
fn a_cause_cannot_close_the_comment() {
    let stop = Stop::new("a", "1.0.0", "saw --> here", None);
    let body = write("", &stop).unwrap();
    assert_eq!(body.matches("-->").count(), 1, "{body}");
    assert_eq!(read(&body), Record::Read(stop));
}