From 2338478e5ae926fb579ae007d85c8b562e874455 Mon Sep 17 00:00:00 2001 From: Collin Styles Date: Sat, 21 Oct 2023 18:56:11 -0700 Subject: [PATCH] Add tests for `StreamExt::all` and `StreamExt::any` --- futures/tests/stream.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/futures/tests/stream.rs b/futures/tests/stream.rs index 41721f15c..4f042832f 100644 --- a/futures/tests/stream.rs +++ b/futures/tests/stream.rs @@ -552,3 +552,43 @@ fn select_with_strategy_doesnt_terminate_early() { assert_eq!(count.get(), times_should_poll + 1); } } + +async fn is_even(number: u8) -> bool { + number % 2 == 0 +} + +#[test] +fn all() { + block_on(async { + let empty: [u8; 0] = []; + let st = stream::iter(empty); + let all = st.all(is_even).await; + assert!(all); + + let st = stream::iter([2, 4, 6, 8]); + let all = st.all(is_even).await; + assert!(all); + + let st = stream::iter([2, 3, 4]); + let all = st.all(is_even).await; + assert!(!all); + }); +} + +#[test] +fn any() { + block_on(async { + let empty: [u8; 0] = []; + let st = stream::iter(empty); + let any = st.any(is_even).await; + assert!(!any); + + let st = stream::iter([1, 2, 3]); + let any = st.any(is_even).await; + assert!(any); + + let st = stream::iter([1, 3, 5]); + let any = st.any(is_even).await; + assert!(!any); + }); +}