diff --git a/src/cargo/util/semver_ext.rs b/src/cargo/util/semver_ext.rs index 06f3cd340fcd..70f262cfd859 100644 --- a/src/cargo/util/semver_ext.rs +++ b/src/cargo/util/semver_ext.rs @@ -178,7 +178,10 @@ impl From for OptVersionReq { #[cfg(test)] mod matches_prerelease { + use semver::VersionReq; + use super::OptVersionReq; + use super::Version; #[test] fn prerelease() { @@ -238,4 +241,19 @@ mod matches_prerelease { assert_eq!(expected, matched, "req: {req}; ver: {ver}"); } } + + #[test] + fn opt_version_req_mathes_prerelease() { + let req_ver: VersionReq = "^1.2.3-rc.0".parse().unwrap(); + let to_ver: Version = "1.2.3-rc.0".parse().unwrap(); + + let req = OptVersionReq::Req(req_ver.clone()); + assert!(req.matches_prerelease(&to_ver)); + + let req = OptVersionReq::Locked(to_ver.clone(), req_ver.clone()); + assert!(!req.matches_prerelease(&to_ver)); + + let req = OptVersionReq::Locked(to_ver.clone(), req_ver.clone()); + assert!(!req.matches_prerelease(&to_ver)); + } }