Skip to content

Commit

Permalink
Merge pull request #36 from kpcyrd/non-semver-version-numbers
Browse files Browse the repository at this point in the history
non-semver version numbers
  • Loading branch information
alexanderkjall committed Jan 16, 2024
2 parents 7c0f41c + 6bf66b0 commit 48e5a60
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ pub struct CacheEntry {
}

fn is_compatible(debversion: &str, crateversion: &VersionReq) -> Result<bool, Error> {
let debversion = debversion.replace('~', "-");
let mut debversion = debversion.replace('~', "-");
if let Some((version, _suffix)) = debversion.split_once('+') {
debversion = match version.matches('.').count() {
0 => format!("{version}.0.0"),
1 => format!("{version}.0"),
2 => version.to_owned(),
_ => bail!("wrong number of '.' characters in semver string: {version:?}"),
};
}
let debversion = Version::parse(&debversion)?;

Ok(crateversion.matches(&debversion))
Expand Down Expand Up @@ -183,7 +191,7 @@ impl Connection {
_ => &debversion,
};

// println!("{:?} ({:?}) => {:?}", debversion, version, is_compatible(debversion, version)?);
//println!("{:?} ({:?}) => {:?}", debversion, version, is_compatible(debversion, &version));

if is_compatible(debversion, &version)? {
info.version = debversion.to_string();
Expand Down Expand Up @@ -216,6 +224,11 @@ mod tests {
.unwrap());
}

#[test]
fn is_compatible_with_plus() {
assert!(is_compatible("4+20231122+dfsg", &VersionReq::parse("4.0.0").unwrap()).unwrap());
}

#[test]
fn is_compatible_follows_semver() {
assert!(is_compatible("0.1.1", &VersionReq::parse("0.1.0").unwrap()).unwrap());
Expand Down

0 comments on commit 48e5a60

Please sign in to comment.