1use itertools::Itertools;
2use itertools::{put_back, put_back_n};
3
4#[test]
5fn peeking_take_while_peekable() {
6 let mut r = (0..10).peekable();
7 r.peeking_take_while(|x| *x <= 3).count();
8 assert_eq!(r.next(), Some(4));
9}
10
11#[test]
12fn peeking_take_while_put_back() {
13 let mut r = put_back(0..10);
14 r.peeking_take_while(|x| *x <= 3).count();
15 assert_eq!(r.next(), Some(4));
16 r.peeking_take_while(|_| true).count();
17 assert_eq!(r.next(), None);
18}
19
20#[test]
21fn peeking_take_while_put_back_n() {
22 let mut r = put_back_n(6..10);
23 for elt in (0..6).rev() {
24 r.put_back(elt);
25 }
26 r.peeking_take_while(|x| *x <= 3).count();
27 assert_eq!(r.next(), Some(4));
28 r.peeking_take_while(|_| true).count();
29 assert_eq!(r.next(), None);
30}
31
32#[test]
33fn peeking_take_while_slice_iter() {
34 let v = [1, 2, 3, 4, 5, 6];
35 let mut r = v.iter();
36 r.peeking_take_while(|x| **x <= 3).count();
37 assert_eq!(r.next(), Some(&4));
38 r.peeking_take_while(|_| true).count();
39 assert_eq!(r.next(), None);
40}
41
42#[test]
43fn peeking_take_while_slice_iter_rev() {
44 let v = [1, 2, 3, 4, 5, 6];
45 let mut r = v.iter().rev();
46 r.peeking_take_while(|x| **x >= 3).count();
47 assert_eq!(r.next(), Some(&2));
48 r.peeking_take_while(|_| true).count();
49 assert_eq!(r.next(), None);
50}
51