pub const SDFTD3_VERSION: &str = env!("SDFTD3_VERSION");
#[cfg(test)]
mod tests {
use super::SDFTD3_VERSION;
fn pinned_version() -> &'static str {
let version = include_str!("../build.rs")
.split("const SDFTD3_TAG: &str = \"v")
.nth(1)
.expect("build.rs must define SDFTD3_TAG as a v-prefixed string literal");
let version = version
.split('"')
.next()
.expect("SDFTD3_TAG literal must be terminated by a quote");
assert!(!version.is_empty(), "SDFTD3_TAG must not be empty");
version
}
fn is_plain_semver(version: &str) -> bool {
let mut parts = version.split('.');
let is_component = |part: Option<&str>| {
part.is_some_and(|p| !p.is_empty() && p.bytes().all(|b| b.is_ascii_digit()))
};
is_component(parts.next())
&& is_component(parts.next())
&& is_component(parts.next())
&& parts.next().is_none()
}
#[test]
fn pinned_version_is_plain_semver() {
assert!(
is_plain_semver(SDFTD3_VERSION),
"SDFTD3_VERSION = {SDFTD3_VERSION:?} must be `X.Y.Z` (three non-empty \
numeric components) derived from the v-prefixed tag"
);
}
#[test]
fn semver_check_rejects_malformed_and_non_numeric_versions() {
const INVALID: &[&str] = &[
"", "1", "1.4", "1.4.0.5", "1..0", "1..", ".4.0", "1.beta.gamma", "v1.4.0", "1.4.0-rc", "1.4.0rc", "1.4.0 ", ];
for version in INVALID {
assert!(
!is_plain_semver(version),
"{version:?} is not `X.Y.Z` and must be rejected"
);
}
for version in ["0.0.0", "0.5.1", "1.4.0", "10.20.30"] {
assert!(
is_plain_semver(version),
"{version:?} is `X.Y.Z` and must be accepted"
);
}
}
#[test]
fn reported_version_matches_the_pinned_tag() {
assert_eq!(
SDFTD3_VERSION,
pinned_version(),
"SDFTD3_VERSION must stay derived from the SDFTD3_TAG pin in build.rs"
);
}
}