mirror of
https://jturnerusa.dev/cgit/gentoo-utils/
synced 2025-12-03 03:28:35 -06:00
compare version letter in version cmp algo
This commit is contained in:
@@ -329,6 +329,7 @@ impl PartialEq for Version {
|
|||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.numbers == other.numbers
|
self.numbers == other.numbers
|
||||||
&& self.suffixes == other.suffixes
|
&& self.suffixes == other.suffixes
|
||||||
|
&& self.letter == other.letter
|
||||||
&& match (&self.rev, &other.rev) {
|
&& match (&self.rev, &other.rev) {
|
||||||
(Some(a), Some(b)) => {
|
(Some(a), Some(b)) => {
|
||||||
a.get().parse::<u64>().unwrap() == b.get().parse::<u64>().unwrap()
|
a.get().parse::<u64>().unwrap() == b.get().parse::<u64>().unwrap()
|
||||||
@@ -353,12 +354,28 @@ impl PartialOrd for Version {
|
|||||||
impl Ord for Version {
|
impl Ord for Version {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
match self.numbers.cmp(&other.numbers) {
|
match self.numbers.cmp(&other.numbers) {
|
||||||
Ordering::Less => Ordering::Less,
|
Ordering::Less => return Ordering::Less,
|
||||||
Ordering::Greater => Ordering::Greater,
|
Ordering::Greater => return Ordering::Greater,
|
||||||
Ordering::Equal => match self.suffixes.cmp(&other.suffixes) {
|
Ordering::Equal => (),
|
||||||
Ordering::Less => Ordering::Less,
|
}
|
||||||
Ordering::Greater => Ordering::Greater,
|
|
||||||
Ordering::Equal => match (&self.rev, &other.rev) {
|
match self.suffixes.cmp(&other.suffixes) {
|
||||||
|
Ordering::Less => return Ordering::Less,
|
||||||
|
Ordering::Greater => return Ordering::Greater,
|
||||||
|
Ordering::Equal => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
match (self.letter, other.letter) {
|
||||||
|
(Some(a), Some(b)) if a < b => return Ordering::Less,
|
||||||
|
(Some(a), Some(b)) if a > b => return Ordering::Greater,
|
||||||
|
(Some(a), Some(b)) if a == b => (),
|
||||||
|
(Some(_), None) => return Ordering::Greater,
|
||||||
|
(None, Some(_)) => return Ordering::Less,
|
||||||
|
(None, None) => (),
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
match (&self.rev, &other.rev) {
|
||||||
(Some(a), Some(b)) => a
|
(Some(a), Some(b)) => a
|
||||||
.get()
|
.get()
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
@@ -369,8 +386,6 @@ impl Ord for Version {
|
|||||||
(None, Some(b)) if b.get().chars().all(|c| c == '0') => Ordering::Equal,
|
(None, Some(b)) if b.get().chars().all(|c| c == '0') => Ordering::Equal,
|
||||||
(None, Some(_)) => Ordering::Less,
|
(None, Some(_)) => Ordering::Less,
|
||||||
(None, None) => Ordering::Equal,
|
(None, None) => Ordering::Equal,
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -738,4 +753,16 @@ mod test {
|
|||||||
assert_partial_cmp_display!(a, b, ordering);
|
assert_partial_cmp_display!(a, b, ordering);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_version_cmp_letter() {
|
||||||
|
let a = Version::parser()
|
||||||
|
.parse_finished(InputIter::new("1.0.0"))
|
||||||
|
.unwrap();
|
||||||
|
let b = Version::parser()
|
||||||
|
.parse_finished(InputIter::new("1.0.0a"))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_cmp_display!(a, b, Ordering::Less);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user