use semver::{Version, VersionReq};
pub const WORKSPACE_DISCOVERY_PROTOCOL: &str = "0.1.0-draft.1";
const SPOKEN: &[&str] = &["=0.1.0-draft.1"];
#[must_use]
pub fn workspace_discovery_protocol() -> Version {
Version::parse(WORKSPACE_DISCOVERY_PROTOCOL)
.expect("the workspace discovery protocol constant is a SemVer version")
}
#[must_use]
pub fn speaks_workspace_discovery_protocol(version: &Version) -> bool {
SPOKEN.iter().any(|requirement| {
VersionReq::parse(requirement)
.expect("the spoken workspace discovery protocols are SemVer requirements")
.matches(version)
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn this_build_speaks_the_version_it_writes() {
assert!(speaks_workspace_discovery_protocol(
&workspace_discovery_protocol()
));
}
#[test]
fn a_draft_matches_only_exactly() {
for other in ["0.1.0-draft.2", "0.1.0", "0.1.1", "0.2.0-draft.1", "1.0.0"] {
assert!(
!speaks_workspace_discovery_protocol(&Version::parse(other).unwrap()),
"{other} must not be taken for {WORKSPACE_DISCOVERY_PROTOCOL}"
);
}
}
}