Add methods and tests for SemVer

This commit is contained in:
Nathan Fisher 2024-01-06 12:53:25 -05:00
parent 825592175a
commit 0c192f4b82

View File

@ -61,6 +61,14 @@ impl From<SemVer> for u64 {
} }
} }
impl TryFrom<u64> for SemVer {
type Error = Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
todo!()
}
}
impl PartialEq for SemVer { impl PartialEq for SemVer {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.major == other.major 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);
}
} }