diff --git a/src/error.rs b/src/error.rs index 5d4ee41..793738f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use std::{fmt, num::TryFromIntError}; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum Error { FromUint, ParsePreRelease, diff --git a/src/prerelease.rs b/src/prerelease.rs index 20e5b24..76d5f2e 100644 --- a/src/prerelease.rs +++ b/src/prerelease.rs @@ -164,3 +164,47 @@ impl PartialOrd for PreRelease { Some(a.cmp(&b)) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_alpha() { + let alpha: PreRelease = "alpha".parse().unwrap(); + let alpha1: PreRelease = "Alpha1".parse().unwrap(); + let alpha2: PreRelease = "alpha2".parse().unwrap(); + let one = NonZeroU16::new(1).unwrap(); + let two = NonZeroU16::new(2).unwrap(); + assert_eq!(alpha, PreRelease::Alpha(None)); + assert_eq!(alpha1, PreRelease::Alpha(Some(one))); + assert_eq!(alpha2, PreRelease::Alpha(Some(two))); + } + + #[test] + fn parse_beta() { + assert_eq!( + "beta".parse::().unwrap(), + PreRelease::Beta(None), + ); + assert_eq!( + "beta1".parse::().unwrap(), + PreRelease::Beta(Some(NonZeroU16::new(1).unwrap())) + ); + assert_eq!( + "Beta2".parse::().unwrap(), + PreRelease::Beta(Some(NonZeroU16::new(2).unwrap())) + ); + assert_eq!("Beta2a".parse::(), Err(Error::ParsePreRelease)); + } + + #[test] + fn parse_rc() { + assert_eq!( + "rc3".parse::().unwrap(), + PreRelease::RC(Some(NonZeroU16::new(3).unwrap())) + ); + assert_eq!("Rc".parse::().unwrap(), PreRelease::RC(None)); + assert_eq!("RC".parse::().unwrap(), PreRelease::RC(None)); + } +}