From 69f0513fc3bf7a4a13d4629df1da69386b99906c Mon Sep 17 00:00:00 2001 From: Davide Date: Sat, 2 Nov 2024 17:36:25 +0100 Subject: [PATCH] get computed name --- daedalus/src/lib.rs | 98 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/daedalus/src/lib.rs b/daedalus/src/lib.rs index a2a9e53..f044825 100644 --- a/daedalus/src/lib.rs +++ b/daedalus/src/lib.rs @@ -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 @@ -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); + } }