Add tests for parsing prereleases
This commit is contained in:
parent
bb12ee81f5
commit
1d9242480a
@ -1,6 +1,6 @@
|
|||||||
use std::{fmt, num::TryFromIntError};
|
use std::{fmt, num::TryFromIntError};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
FromUint,
|
FromUint,
|
||||||
ParsePreRelease,
|
ParsePreRelease,
|
||||||
|
@ -164,3 +164,47 @@ impl PartialOrd for PreRelease {
|
|||||||
Some(a.cmp(&b))
|
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::<PreRelease>().unwrap(),
|
||||||
|
PreRelease::Beta(None),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
"beta1".parse::<PreRelease>().unwrap(),
|
||||||
|
PreRelease::Beta(Some(NonZeroU16::new(1).unwrap()))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
"Beta2".parse::<PreRelease>().unwrap(),
|
||||||
|
PreRelease::Beta(Some(NonZeroU16::new(2).unwrap()))
|
||||||
|
);
|
||||||
|
assert_eq!("Beta2a".parse::<PreRelease>(), Err(Error::ParsePreRelease));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_rc() {
|
||||||
|
assert_eq!(
|
||||||
|
"rc3".parse::<PreRelease>().unwrap(),
|
||||||
|
PreRelease::RC(Some(NonZeroU16::new(3).unwrap()))
|
||||||
|
);
|
||||||
|
assert_eq!("Rc".parse::<PreRelease>().unwrap(), PreRelease::RC(None));
|
||||||
|
assert_eq!("RC".parse::<PreRelease>().unwrap(), PreRelease::RC(None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user