Add tests for impl FromStr for Version
This commit is contained in:
parent
17e52c2b01
commit
0fdfecf842
@ -198,18 +198,68 @@ impl PartialEq for Version {
|
||||
|
||||
impl Eq for Version {}
|
||||
|
||||
impl Ord for Version {
|
||||
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||
u128::from(*self).cmp(&u128::from(*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Version {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
||||
if self.arch == other.arch {
|
||||
Some(self.cmp(other))
|
||||
Some(u128::from(*self).cmp(&u128::from(*other)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::num::NonZeroU16;
|
||||
|
||||
#[test]
|
||||
fn from_str() {
|
||||
let mut version: Version = "2.4.1_alpha2-aarch64".parse().unwrap();
|
||||
assert_eq!(
|
||||
version,
|
||||
Version {
|
||||
kind: Kind::SemVer {
|
||||
major: 2,
|
||||
minor: 4,
|
||||
patch: 1
|
||||
},
|
||||
pre: PreRelease::Alpha(Some(NonZeroU16::new(2).unwrap())),
|
||||
arch: Arch::Arm64,
|
||||
}
|
||||
);
|
||||
version = "6.4-i486".parse().unwrap();
|
||||
assert_eq!(
|
||||
version,
|
||||
Version {
|
||||
kind: Kind::Rapid { major: 6, minor: 4 },
|
||||
pre: PreRelease::None,
|
||||
arch: Arch::X86,
|
||||
}
|
||||
);
|
||||
version = "3.14.6_git_r2d2xxx.1705881493-amd64".parse().unwrap();
|
||||
assert_eq!(
|
||||
version,
|
||||
Version {
|
||||
kind: Kind::SemVer {
|
||||
major: 3,
|
||||
minor: 14,
|
||||
patch: 6
|
||||
},
|
||||
pre: PreRelease::Git {
|
||||
hash: ['r', '2', 'd', '2', 'x', 'x', 'x'],
|
||||
datetime: epoch::DateTime {
|
||||
year: epoch::prelude::Year::Leap(2024),
|
||||
month: epoch::prelude::Month::Janurary,
|
||||
day: 21,
|
||||
hour: 23,
|
||||
minute: 58,
|
||||
second: 13,
|
||||
zone: epoch::prelude::TimeZone::Utc
|
||||
}
|
||||
},
|
||||
arch: Arch::X86_64,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user