Skip to content

Commit

Permalink
get computed name
Browse files Browse the repository at this point in the history
  • Loading branch information
blarfoon committed Nov 2, 2024
1 parent a5c63f8 commit 69f0513
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions daedalus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ impl GradleSpecifier {
self.package.as_str() == "org.apache.logging.log4j"
}

/// Returns if the specifier matches the other specifier
pub fn get_computed_name(&self) -> String {
format!(
"{}:{}:{}",
self.package,
self.artifact,
self.identifier.clone().unwrap_or("".to_string())
)
}

/// Compares two versions
/// Returns Ordering::Equal if they are equal
/// Returns Ordering::Greater if self is greater than other
Expand Down Expand Up @@ -671,4 +681,92 @@ mod tests {
.join("example-1.0.0-identifier.zip")
);
}

#[test]
fn test_library_compare() {
let x = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.4-nightly-20150209".to_string(),
extension: "jar".to_string(),
};
let y = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.4-nightly-20150209".to_string(),
extension: "jar".to_string(),
};

assert_eq!(x.compare_versions(&y).unwrap(), Ordering::Equal);

let x = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.4-nightly-20150209".to_string(),
extension: "jar".to_string(),
};
let y = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.3".to_string(),
extension: "jar".to_string(),
};

assert_eq!(x.compare_versions(&y).unwrap(), Ordering::Greater);

let x = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.3".to_string(),
extension: "jar".to_string(),
};
let y = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.4-nightly-20150209".to_string(),
extension: "jar".to_string(),
};

assert_eq!(x.compare_versions(&y).unwrap(), Ordering::Less);

let x = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.4-nightly-20150209".to_string(),
extension: "jar".to_string(),
};
let y = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.4".to_string(),
extension: "jar".to_string(),
};

assert_eq!(x.compare_versions(&y).unwrap(), Ordering::Less);

let x = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.4-SNAPSHOT".to_string(),
extension: "jar".to_string(),
};
let y = GradleSpecifier {
package: "org.lwjgl".to_string(),
artifact: "lwjgl".to_string(),
identifier: None,
version: "2.9.4".to_string(),
extension: "jar".to_string(),
};

assert_eq!(x.compare_versions(&y).unwrap(), Ordering::Less);
}
}

0 comments on commit 69f0513

Please sign in to comment.