Skip to content

Commit

Permalink
add a test that mutates the list during a fold
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Dec 13, 2024
1 parent e439dc9 commit 5b52e68
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/types/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,23 @@ mod tests {
});
}

#[test]
fn test_iter_fold_out_of_bounds() {
Python::with_gil(|py: Python<'_>| {
let list = PyList::new(py, [1, 2, 3]).unwrap();
let sum = list.iter().fold(0, |_, _| {
// clear the list to create a pathological fold operation
// that mutates the list as it processes it
for _ in 0..3 {
list.del_item(0).unwrap();
}
-5
});
assert_eq!(sum, -5);
assert!(list.len() == 0);
});
}

#[test]
fn test_iter_rfold() {
Python::with_gil(|py: Python<'_>| {
Expand Down

0 comments on commit 5b52e68

Please sign in to comment.