Skip to content

Commit

Permalink
Update Range to match upstream (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored and konstin committed May 2, 2024
1 parent a1515b9 commit 341dba7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/internal/incompatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,12 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> fmt::Display

#[cfg(test)]
pub mod tests {
use super::*;
use proptest::prelude::*;

use crate::range::Range;
use crate::term::tests::strategy as term_strat;
use proptest::prelude::*;

use super::*;

proptest! {

Expand Down
16 changes: 3 additions & 13 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<V: Ord> Range<V> {
.segments
.last()
.expect("if there is a first element, there must be a last element");
(bound_as_ref(start), bound_as_ref(&end.1))
(start.as_ref(), end.1.as_ref())
})
}

Expand Down Expand Up @@ -334,16 +334,6 @@ fn within_bounds<V: PartialOrd>(version: &V, segment: &Interval<V>) -> Ordering
Ordering::Greater
}

/// Implementation of [`Bound::as_ref`] which is currently marked as unstable.
fn bound_as_ref<V>(bound: &Bound<V>) -> Bound<&V> {
match bound {
Included(v) => Included(v),
Excluded(v) => Excluded(v),
Unbounded => Unbounded,
}
}

/// A valid segment is one where at least one version fits between start and end
fn valid_segment<T: PartialOrd>(start: &Bound<T>, end: &Bound<T>) -> bool {
match (start, end) {
// Singleton interval are allowed
Expand Down Expand Up @@ -737,7 +727,7 @@ impl<V: Display + Eq> Display for Range<V> {
} else {
for (idx, segment) in self.segments.iter().enumerate() {
if idx > 0 {
write!(f, ", ")?;
write!(f, " | ")?;
}
match segment {
(Unbounded, Unbounded) => write!(f, "*")?,
Expand All @@ -748,7 +738,7 @@ impl<V: Display + Eq> Display for Range<V> {
if v == b {
write!(f, "=={v}")?
} else {
write!(f, ">={v},<={b}")?
write!(f, ">={v}, <={b}")?
}
}
(Included(v), Excluded(b)) => write!(f, ">={v}, <{b}")?,
Expand Down
4 changes: 2 additions & 2 deletions tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ fn confusing_with_lots_of_holes() {
};
assert_eq!(
&DefaultStringReporter::report(&derivation_tree),
r#"Because there is no available version for bar and foo ==1, ==2, ==3, ==4, ==5 depends on bar, foo ==1, ==2, ==3, ==4, ==5 is forbidden.
And because there is no version of foo in <1, >1, <2, >2, <3, >3, <4, >4, <5, >5 and root ==1 depends on foo, root ==1 is forbidden."#
r#"Because there is no available version for bar and foo ==1 | ==2 | ==3 | ==4 | ==5 depends on bar, foo ==1 | ==2 | ==3 | ==4 | ==5 is forbidden.
And because there is no version of foo in <1 | >1, <2 | >2, <3 | >3, <4 | >4, <5 | >5 and root ==1 depends on foo, root ==1 is forbidden."#
);
derivation_tree.collapse_no_versions();
assert_eq!(
Expand Down

0 comments on commit 341dba7

Please sign in to comment.