From c6ab663b6ac26032c7080ea329906a87989a787a Mon Sep 17 00:00:00 2001 From: zetanumbers Date: Fri, 4 Dec 2020 21:47:46 +0300 Subject: [PATCH] Elaborate on `BindStream` tests --- src/runtime/bind_stream.rs | 46 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/src/runtime/bind_stream.rs b/src/runtime/bind_stream.rs index 1204bdab5..794250024 100644 --- a/src/runtime/bind_stream.rs +++ b/src/runtime/bind_stream.rs @@ -138,40 +138,24 @@ mod tests { use super::*; #[test] - fn pending_without_change() { - use futures::{ - executor::{block_on, LocalPool}, - stream::StreamExt, - task::LocalSpawnExt, - }; - - let mut brt = BindStream::new(|| ()); - block_on(brt.next()).expect("BindStream should yield first revision immediately"); - let mut pool = LocalPool::new(); - pool.spawner() - .spawn_local(async move { - brt.next().await.unwrap(); - unreachable!() - }) - .unwrap(); - assert!(!pool.try_run_one()); - } + fn behavior_on_state_change() { + let (mut brt, key) = BindStream::init(|| crate::state(|| 0).1); - #[test] - fn has_changes() { - use futures::{executor::LocalPool, task::LocalSpawnExt}; + // state after initialization + assert!(brt.try_next().is_none()); - let (mut brt, key) = BindStream::init(|| crate::state(|| 0).1); - let mut pool = LocalPool::new(); - pool.spawner() - .spawn_local(async move { - brt.next().await; - }) - .unwrap(); - assert!(!pool.try_run_one()); + // no actual change in value key.set(0); - assert!(!pool.try_run_one()); + assert!(brt.try_next().is_none()); + + // actual change in value key.set(1); - assert!(pool.try_run_one()); + assert!(brt.try_next().is_some()); + + // two changes in one revision + key.set(2); + key.set(3); + assert!(brt.try_next().is_some()); + assert!(brt.try_next().is_none()); } }