diff options
Diffstat (limited to 'third_party/rust/futures/tests/stream.rs')
-rw-r--r-- | third_party/rust/futures/tests/stream.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/third_party/rust/futures/tests/stream.rs b/third_party/rust/futures/tests/stream.rs new file mode 100644 index 0000000000..fd6a8b6da7 --- /dev/null +++ b/third_party/rust/futures/tests/stream.rs @@ -0,0 +1,32 @@ +use futures::executor::block_on; +use futures::stream::{self, StreamExt}; + +#[test] +fn select() { + fn select_and_compare(a: Vec<u32>, b: Vec<u32>, expected: Vec<u32>) { + let a = stream::iter(a); + let b = stream::iter(b); + let vec = block_on(stream::select(a, b).collect::<Vec<_>>()); + assert_eq!(vec, expected); + } + + select_and_compare(vec![1, 2, 3], vec![4, 5, 6], vec![1, 4, 2, 5, 3, 6]); + select_and_compare(vec![1, 2, 3], vec![4, 5], vec![1, 4, 2, 5, 3]); + select_and_compare(vec![1, 2], vec![4, 5, 6], vec![1, 4, 2, 5, 6]); +} + +#[test] +fn scan() { + futures::executor::block_on(async { + assert_eq!( + stream::iter(vec![1u8, 2, 3, 4, 6, 8, 2]) + .scan(1, |acc, e| { + *acc += 1; + futures::future::ready(if e < *acc { Some(e) } else { None }) + }) + .collect::<Vec<_>>() + .await, + vec![1u8, 2, 3, 4] + ); + }); +} |