Skip to content

Commit

Permalink
test: add opt_version_req_mathes_prerelease test
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Aug 16, 2024
1 parent 9a170d7 commit 2c27615
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/cargo/util/semver_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ impl From<VersionReq> for OptVersionReq {

#[cfg(test)]
mod matches_prerelease {
use semver::VersionReq;

use super::OptVersionReq;
use super::Version;

#[test]
fn prerelease() {
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 2c27615

Please sign in to comment.