tryfuture tests
Some checks failed
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo clippy (1.65) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.

This commit is contained in:
AF 2023-10-15 17:19:53 +00:00
parent 8ee0a196c6
commit 31e6ac9429

View File

@ -202,3 +202,58 @@ impl<'a> MonadFailAny<'a> for FutureFailAny {
}) })
} }
} }
#[cfg(test)]
mod tryfuture_tests {
use std::sync::Arc;
use crate::func::{applicative_select::Selected, tests::Eqr, ApplicativeSelect};
use super::{test_suite, tests, TryFutureInstance};
type T = TryFutureInstance<i32>;
impl<'a> Eqr<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>(
name: &'a str,
left: Self::F<A>,
right: Self::F<A>,
) -> tests::R {
tests::eqr(
name,
futures::executor::block_on(left),
futures::executor::block_on(right),
)
}
}
impl<'a> test_suite::FunctorTestSuite<'a> for T {
fn sample<A: 'a + Send, F: FnMut(Arc<dyn test_suite::WrapFunction<'a, A, Self::F<A>>>)>(
mut f: F,
) {
f(Arc::new(|a| Box::pin(futures::future::ready(Ok(a)))));
f(Arc::new(|_| Box::pin(futures::future::ready(Err(0)))));
f(Arc::new(|_| Box::pin(futures::future::ready(Err(1)))));
f(Arc::new(|_| Box::pin(futures::future::ready(Err(2)))));
f(Arc::new(|_| Box::pin(futures::future::ready(Err(3)))));
}
}
#[test]
fn monad_follows_laws() {
test_suite::monad_follows_laws::<T>().unwrap();
}
#[test]
fn select_second() {
match futures::executor::block_on(T::select(
Box::pin(futures::future::pending::<Result<i32, _>>()),
Box::pin(futures::future::ready(Ok(2))),
))
.unwrap()
{
Selected::A(_, _) => panic!("first future ready"),
Selected::B(_, b) => assert_eq!(b, 2),
}
}
}