summaryrefslogtreecommitdiffstats
path: root/vendor/futures/tests/stream_unfold.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/futures/tests/stream_unfold.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/futures/tests/stream_unfold.rs')
-rw-r--r--vendor/futures/tests/stream_unfold.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/futures/tests/stream_unfold.rs b/vendor/futures/tests/stream_unfold.rs
new file mode 100644
index 000000000..16b10813b
--- /dev/null
+++ b/vendor/futures/tests/stream_unfold.rs
@@ -0,0 +1,32 @@
+use futures::future;
+use futures::stream;
+use futures_test::future::FutureTestExt;
+use futures_test::{assert_stream_done, assert_stream_next, assert_stream_pending};
+
+#[test]
+fn unfold1() {
+ let mut stream = stream::unfold(0, |state| {
+ if state <= 2 {
+ future::ready(Some((state * 2, state + 1))).pending_once()
+ } else {
+ future::ready(None).pending_once()
+ }
+ });
+
+ // Creates the future with the closure
+ // Not ready (delayed future)
+ assert_stream_pending!(stream);
+ // Future is ready, yields the item
+ assert_stream_next!(stream, 0);
+
+ // Repeat
+ assert_stream_pending!(stream);
+ assert_stream_next!(stream, 2);
+
+ assert_stream_pending!(stream);
+ assert_stream_next!(stream, 4);
+
+ // No more items
+ assert_stream_pending!(stream);
+ assert_stream_done!(stream);
+}