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

View File

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

View File

@ -141,23 +141,17 @@ impl<'a> SharedFunctor<'a> for FutureInstance {
mod future_tests {
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};
type T = FutureInstance;
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> tests::ToEq<'a> for T {
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = A;
fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
futures::executor::block_on(fa)
}
}

View File

@ -111,13 +111,11 @@ mod lazy_tests {
type T = LazyInstance;
impl<'a> tests::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, left(), right())
impl<'a> tests::ToEq<'a> for T {
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = A;
fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
fa()
}
}

View File

@ -146,13 +146,11 @@ mod option_tests {
use super::OptionInstance as T;
impl<'a> tests::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, left, right)
impl<'a> tests::ToEq<'a> for T {
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<A>;
fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
fa
}
}
@ -207,4 +205,9 @@ mod option_tests {
fn fail_follows_laws() {
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>;
impl<'a> tests::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, left, right)
impl<'a> tests::ToEq<'a> for T {
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<A>;
fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
fa
}
}

View File

@ -125,13 +125,11 @@ mod solo_tests {
type T = SoloInstance;
impl<'a> tests::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, left, right)
impl<'a> tests::ToEq<'a> for T {
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Self::F<A>;
fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
fa
}
}
@ -152,4 +150,9 @@ mod solo_tests {
fn shared_follows_laws() {
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;
impl<'a> tests::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, left.evaluate(), right.evaluate())
impl<'a> tests::ToEq<'a> for T {
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = A;
fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
fa.evaluate()
}
}

View File

@ -207,23 +207,17 @@ impl<'a> MonadFailAny<'a> for FutureFailAny {
mod tryfuture_tests {
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};
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> tests::ToEq<'a> for T {
type Eq<A: 'a + Send + PartialEq + std::fmt::Debug> = Result<A, i32>;
fn to_eq<A: 'a + Send + PartialEq + std::fmt::Debug>(fa: Self::F<A>) -> Self::Eq<A> {
futures::executor::block_on(fa)
}
}

View File

@ -40,6 +40,22 @@ pub trait Eqr<'a>: WeakFunctor<'a> {
) -> 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 {
if left == right {
TestResults {