verctl-core 0.9.5

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

use super::{read, write};

#[test]
fn each_opener_marks_the_version() {
    let cases = [
        indoc! {"
            name: CI
            # version: 1.2.0
            on: push
        "},
        indoc! {"
            // version: 1.2.0
            export const x = 1;
        "},
        indoc! {"
            <!-- version: 1.2.0 -->
            # Title
        "},
    ];
    for raw in cases {
        assert_eq!(read(raw).unwrap(), "1.2.0", "{raw}");
        let next = write(raw, "1.2.1").unwrap();
        assert_eq!(next, raw.replace("1.2.0", "1.2.1"), "{raw}");
    }
}

#[test]
fn an_indented_crlf_marker_keeps_its_bytes() {
    let raw = "jobs:\r\n  # version: 0.3.0\r\n";
    assert_eq!(
        write(raw, "0.3.1").unwrap(),
        "jobs:\r\n  # version: 0.3.1\r\n"
    );
}

#[test]
fn a_file_with_no_marker_fails() {
    let raw = indoc! {"
        name: CI
        on: push
    "};
    let error = read(raw).unwrap_err();
    assert!(format!("{error:#}").contains("no marker line"), "{error:#}");
}

#[test]
fn two_markers_fail_and_name_both_lines() {
    let raw = indoc! {"
        # version: 1.2.0
        name: CI
        # version: 1.2.0
    "};
    let error = read(raw).unwrap_err();
    assert!(format!("{error:#}").contains("lines 1 and 3"), "{error:#}");
}

#[test]
fn a_marker_that_is_not_a_version_fails() {
    let error = read("# version: latest\n").unwrap_err();
    assert!(format!("{error:#}").contains("line 1"), "{error:#}");
}

#[test]
fn prose_about_a_version_is_not_a_marker() {
    let raw = indoc! {"
        # version: 1.0.0
        # The version: 2.0.0 changed things.
        # version:2.0.0
        # version: 3.0.0 and more
    "};
    assert_eq!(read(raw).unwrap(), "1.0.0");
}

/// A value past extra whitespace is not a marker, and a multibyte
/// character there must not split mid-byte.
#[test]
fn extra_space_before_a_multibyte_value_is_not_a_marker() {
    let raw = indoc! {"
        # version: 1.0.0
        # version:  é
    "};
    assert_eq!(read(raw).unwrap(), "1.0.0");
}