From 0c192f4b82a94015ef5ab4429e3b3750ee735542 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Sat, 6 Jan 2024 12:53:25 -0500 Subject: [PATCH] Add methods and tests for `SemVer` --- src/semver.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/semver.rs b/src/semver.rs index 9c30acb..576b1eb 100644 --- a/src/semver.rs +++ b/src/semver.rs @@ -61,6 +61,14 @@ impl From for u64 { } } +impl TryFrom for SemVer { + type Error = Error; + + fn try_from(value: u64) -> Result { + todo!() + } +} + impl PartialEq for SemVer { fn eq(&self, other: &Self) -> bool { self.major == other.major @@ -115,4 +123,38 @@ mod tests { } ) } + + #[test] + fn to_string() { + let mut s = SemVer { + major: 1, + minor: 0, + patch: 2, + pre: PreRelease::None, + }; + assert_eq!(s.to_string(), "1.0.2"); + s = SemVer { + major: 2, + minor: 1, + patch: 14, + pre: PreRelease::Beta(Some(NonZeroU16::new(2).unwrap())), + }; + assert_eq!(s.to_string(), "2.1.14_beta2"); + } + + #[test] + fn eq() { + todo!() + } + + #[test] + fn ord() { + let a: SemVer = "1.0.2".parse().unwrap(); + let b: SemVer = "1.0.3".parse().unwrap(); + let c: SemVer = "1.0.2_alpha1".parse().unwrap(); + let d: SemVer = "1.0.2_alpha2".parse().unwrap(); + assert!(a < b); + assert!(c < a); + assert!(d > c); + } }