summaryrefslogtreecommitdiffstats
path: root/third_party/rust/futures-0.1.31/tests/stream_catch_unwind.rs
blob: a06748d09a934535283a89efbadb4e37233621c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
extern crate futures;

use futures::stream;
use futures::prelude::*;

#[test]
fn panic_in_the_middle_of_the_stream() {
    let stream = stream::iter_ok::<_, bool>(vec![Some(10), None, Some(11)]);

    // panic on second element
    let stream_panicking = stream.map(|o| o.unwrap());
    let mut iter = stream_panicking.catch_unwind().wait();

    assert_eq!(Ok(10), iter.next().unwrap().ok().unwrap());
    assert!(iter.next().unwrap().is_err());
    assert!(iter.next().is_none());
}

#[test]
fn no_panic() {
    let stream = stream::iter_ok::<_, bool>(vec![10, 11, 12]);

    let mut iter = stream.catch_unwind().wait();

    assert_eq!(Ok(10), iter.next().unwrap().ok().unwrap());
    assert_eq!(Ok(11), iter.next().unwrap().ok().unwrap());
    assert_eq!(Ok(12), iter.next().unwrap().ok().unwrap());
    assert!(iter.next().is_none());
}