Skip to content

Commit b5eab1d

Browse files
authored
test: check for unsorted iteration (pubgrub-rs#183)
1 parent 4a74013 commit b5eab1d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/range.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,17 @@ impl<V: Ord> Range<V> {
222222
I: Iterator<Item = &'s V> + 's,
223223
V: 's,
224224
{
225+
#[cfg(debug_assertions)]
226+
let mut last: Option<&V> = None;
225227
versions.scan(0, move |i, v| {
228+
#[cfg(debug_assertions)]
229+
{
230+
assert!(
231+
last <= Some(v),
232+
"`contains_many` `versions` argument incorrectly sorted"
233+
);
234+
last = Some(v);
235+
}
226236
while let Some(segment) = self.segments.get(*i) {
227237
match within_bounds(v, segment) {
228238
Ordering::Less => return Some(false),
@@ -430,8 +440,18 @@ impl<V: Ord + Clone> Range<V> {
430440
I: Iterator<Item = &'v V> + 'v,
431441
V: 'v,
432442
{
443+
#[cfg(debug_assertions)]
444+
let mut last: Option<&V> = None;
433445
// Return the segment index in the range for each version in the range, None otherwise
434446
let version_locations = versions.scan(0, move |i, v| {
447+
#[cfg(debug_assertions)]
448+
{
449+
assert!(
450+
last <= Some(v),
451+
"`simplify` `versions` argument incorrectly sorted"
452+
);
453+
last = Some(v);
454+
}
435455
while let Some(segment) = self.segments.get(*i) {
436456
match within_bounds(v, segment) {
437457
Ordering::Less => return Some(None),

0 commit comments

Comments
 (0)