Skip to content

Commit

Permalink
test: check for unsorted iteration (pubgrub-rs#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 authored Feb 2, 2024
1 parent 4a74013 commit b5eab1d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,17 @@ impl<V: Ord> Range<V> {
I: Iterator<Item = &'s V> + 's,
V: 's,
{
#[cfg(debug_assertions)]
let mut last: Option<&V> = None;
versions.scan(0, move |i, v| {
#[cfg(debug_assertions)]
{
assert!(
last <= Some(v),
"`contains_many` `versions` argument incorrectly sorted"
);
last = Some(v);
}
while let Some(segment) = self.segments.get(*i) {
match within_bounds(v, segment) {
Ordering::Less => return Some(false),
Expand Down Expand Up @@ -430,8 +440,18 @@ impl<V: Ord + Clone> Range<V> {
I: Iterator<Item = &'v V> + 'v,
V: 'v,
{
#[cfg(debug_assertions)]
let mut last: Option<&V> = None;
// Return the segment index in the range for each version in the range, None otherwise
let version_locations = versions.scan(0, move |i, v| {
#[cfg(debug_assertions)]
{
assert!(
last <= Some(v),
"`simplify` `versions` argument incorrectly sorted"
);
last = Some(v);
}
while let Some(segment) = self.segments.get(*i) {
match within_bounds(v, segment) {
Ordering::Less => return Some(None),
Expand Down

0 comments on commit b5eab1d

Please sign in to comment.