ToEq
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.

This commit is contained in:
AF 2023-10-15 18:45:04 +00:00
parent a0c49787c8
commit b846e1040a
10 changed files with 78 additions and 77 deletions

View File

@ -187,13 +187,11 @@ mod composition_tests {
type T = CompositionInstance<OptionInstance, ResultInstance<i32>>; type T = CompositionInstance<OptionInstance, ResultInstance<i32>>;
impl<'a> tests::Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<A>;
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, fa
) -> tests::R {
tests::eqr(name, left, right)
} }
} }
@ -234,6 +232,11 @@ mod composition_tests {
test_suite::fail_functor_follows_laws::<T, _>().unwrap(); test_suite::fail_functor_follows_laws::<T, _>().unwrap();
} }
#[test]
fn local_follows_laws() {
test_suite::local_follows_laws::<T>().unwrap();
}
#[test] #[test]
fn select_second() { fn select_second() {
type T = CompositionInstance<TryFutureInstance<i32>, ResultInstance<i32>>; type T = CompositionInstance<TryFutureInstance<i32>, ResultInstance<i32>>;

View File

@ -221,17 +221,11 @@ mod effect_tests {
type T = EffectInstance<TestEffect>; type T = EffectInstance<TestEffect>;
impl<'a> tests::Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = (A, Arc<TestEffect>);
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, (fa.value, fa.effect.simplify())
) -> tests::R {
tests::eqr(
name,
(left.value, left.effect.simplify()),
(right.value, right.effect.simplify()),
)
} }
} }

View File

@ -141,23 +141,17 @@ impl<'a> SharedFunctor<'a> for FutureInstance {
mod future_tests { mod future_tests {
use std::sync::Arc; use std::sync::Arc;
use crate::func::{applicative_select::Selected, tests::Eqr, ApplicativeSelect}; use crate::func::{applicative_select::Selected, ApplicativeSelect};
use super::{test_suite, tests, FutureInstance}; use super::{test_suite, tests, FutureInstance};
type T = FutureInstance; type T = FutureInstance;
impl<'a> Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = A;
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, futures::executor::block_on(fa)
) -> tests::R {
tests::eqr(
name,
futures::executor::block_on(left),
futures::executor::block_on(right),
)
} }
} }

View File

@ -111,13 +111,11 @@ mod lazy_tests {
type T = LazyInstance; type T = LazyInstance;
impl<'a> tests::Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = A;
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, fa()
) -> tests::R {
tests::eqr(name, left(), right())
} }
} }

View File

@ -146,13 +146,11 @@ mod option_tests {
use super::OptionInstance as T; use super::OptionInstance as T;
impl<'a> tests::Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<A>;
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, fa
) -> tests::R {
tests::eqr(name, left, right)
} }
} }
@ -207,4 +205,9 @@ mod option_tests {
fn fail_follows_laws() { fn fail_follows_laws() {
test_suite::fail_functor_follows_laws::<T, _>().unwrap(); test_suite::fail_functor_follows_laws::<T, _>().unwrap();
} }
#[test]
fn local_follows_laws() {
test_suite::local_follows_laws::<T>().unwrap();
}
} }

View File

@ -254,13 +254,11 @@ mod result_tests {
type T = ResultInstance<i32>; type T = ResultInstance<i32>;
impl<'a> tests::Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<A>;
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, fa
) -> tests::R {
tests::eqr(name, left, right)
} }
} }

View File

@ -125,13 +125,11 @@ mod solo_tests {
type T = SoloInstance; type T = SoloInstance;
impl<'a> tests::Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<A>;
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, fa
) -> tests::R {
tests::eqr(name, left, right)
} }
} }
@ -152,4 +150,9 @@ mod solo_tests {
fn shared_follows_laws() { fn shared_follows_laws() {
test_suite::shared_follows_laws::<T>().unwrap(); test_suite::shared_follows_laws::<T>().unwrap();
} }
#[test]
fn local_follows_laws() {
test_suite::local_follows_laws::<T>().unwrap();
}
} }

View File

@ -270,13 +270,11 @@ mod stackless_test {
use super::StacklessInstance as T; use super::StacklessInstance as T;
impl<'a> tests::Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = A;
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, fa.evaluate()
) -> tests::R {
tests::eqr(name, left.evaluate(), right.evaluate())
} }
} }

View File

@ -207,23 +207,17 @@ impl<'a> MonadFailAny<'a> for FutureFailAny {
mod tryfuture_tests { mod tryfuture_tests {
use std::sync::Arc; use std::sync::Arc;
use crate::func::{applicative_select::Selected, tests::Eqr, ApplicativeSelect}; use crate::func::{applicative_select::Selected, ApplicativeSelect};
use super::{test_suite, tests, TryFutureInstance}; use super::{test_suite, tests, TryFutureInstance};
type T = TryFutureInstance<i32>; type T = TryFutureInstance<i32>;
impl<'a> Eqr<'a> for T { impl<'a> tests::ToEq<'a> for T {
fn eqr<A: 'a + Send + PartialEq + std::fmt::Debug>( type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Result<A, i32>;
name: &'a str,
left: Self::F<A>, fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
right: Self::F<A>, futures::executor::block_on(fa)
) -> tests::R {
tests::eqr(
name,
futures::executor::block_on(left),
futures::executor::block_on(right),
)
} }
} }

View File

@ -40,6 +40,22 @@ pub trait Eqr<'a>: WeakFunctor<'a> {
) -> R; ) -> R;
} }
pub trait ToEq<'a>: WeakFunctor<'a> {
type Eq<A: 'a + Send + PartialEq + Debug>: PartialEq + Debug;
fn to_eq<A: 'a + Send + PartialEq + Debug>(fa: Self::F<A>) -> Self::Eq<A>;
}
impl<'a, T: ToEq<'a>> Eqr<'a> for T {
fn eqr<A: 'a + Send + PartialEq + Debug>(
name: &'a str,
left: Self::F<A>,
right: Self::F<A>,
) -> R {
eqr(name, Self::to_eq(left), Self::to_eq(right))
}
}
pub fn eqr<T: PartialEq + Debug>(name: &str, left: T, right: T) -> R { pub fn eqr<T: PartialEq + Debug>(name: &str, left: T, right: T) -> R {
if left == right { if left == right {
TestResults { TestResults {