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); + } }