Skip to content

Commit b8db69e

Browse files
Add test
1 parent 612f234 commit b8db69e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/types/list.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,4 +1765,25 @@ mod tests {
17651765
assert_eq!(list.iter().count(), 3);
17661766
})
17671767
}
1768+
1769+
#[test]
1770+
fn test_new_from_non_exact_iter() {
1771+
Python::attach(|py| {
1772+
let iter = (0..5)
1773+
.filter(|_| true) // Filter does not implement ExactSizeIterator
1774+
.map(|item| item.into_pyobject(py).unwrap());
1775+
1776+
assert!(
1777+
matches!(iter.size_hint(), (0, _)),
1778+
"size_hint lower bound should be 0 because we do not now the final size after filer"
1779+
);
1780+
1781+
let list = PyList::new(py, iter).unwrap();
1782+
assert_eq!(
1783+
list.len(),
1784+
5,
1785+
"list should contain all elements even though size_hint is 0"
1786+
);
1787+
})
1788+
}
17681789
}

0 commit comments

Comments
 (0)