Skip to content

Commit 1ba1ca7

Browse files
committed
added a test for the short-circuiting behaviour
1 parent b67ee44 commit 1ba1ca7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/core/tests/iter/traits/iterator.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,17 @@ fn test_edge_case_handling_iterator_with_duplicates() {
637637
assert!([1i32, 2i32, 2i32, 3i32].iter().has_item(&2i32));
638638
}
639639

640+
#[test]
641+
/// Tests that short-circuiting works correctly when using `has_item`
642+
/// When you run the function, it should move the iterator forward after the first appearance of the item
643+
fn test_short_circuiting() {
644+
let mut iterator = vec![1, 2, 3, 1, 1].into_iter();
645+
assert!(iterator.has_item(&1));
646+
assert_eq!(iterator.next(), Some(2));
647+
assert!(!iterator.has_item(&4));
648+
assert_eq!(iterator.next(), None);
649+
}
650+
640651
#[test]
641652
fn test_edge_case_handling_iterator_with_custom_struct() {
642653
#[derive(PartialEq)]

0 commit comments

Comments
 (0)