Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-semver version numbers #36

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,22 @@ pub struct CacheEntry {
}

fn is_compatible(debversion: &str, crateversion: &VersionReq) -> Result<bool, Error> {
let debversion = debversion.replace('~', "-");
let mut debversion = debversion.replace('~', "-");
if debversion.contains('+') {
let parts: Vec<&str> = debversion.split('+').collect();
debversion = match parts[0].matches('.').count() {
0 => {
format!("{}.0.0", parts[0])
}
1 => {
format!("{}.0", parts[0])
}
2 => parts[0].to_owned(),
_ => {
return Err(anyhow!("wrong number of '.' characters in semver string"));
}
};
}
alexanderkjall marked this conversation as resolved.
Show resolved Hide resolved
let debversion = Version::parse(&debversion)?;

Ok(crateversion.matches(&debversion))
Expand Down Expand Up @@ -183,7 +198,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 +231,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