Skip to content

Commit

Permalink
Elaborate on BindStream tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zetanumbers committed Dec 4, 2020
1 parent f87b753 commit c6ab663
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions src/runtime/bind_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit c6ab663

Please sign in to comment.