Diffstat (limited to 'tests/common/protocol/value.rs')
-rw-r--r--tests/common/protocol/value.rs62
1 files changed, 40 insertions, 22 deletions
diff --git a/tests/common/protocol/value.rs b/tests/common/protocol/value.rs
index 898b21d..fe470fa 100644
--- a/tests/common/protocol/value.rs
+++ b/tests/common/protocol/value.rs
@@ -1,7 +1,11 @@
+use effectful::{
+ environment::{Environment, NativeForm},
+ bound::{Bool, IsSend, IsSync},
+ effective::Effective,
+};
use mockall::mock;
use treaty::{
any::{any_trait, OwnedStatic, TypeName},
- effect::{blocking::Blocking, Effect, Effective, ErasedEffective, Ss},
protocol::{
visitor::{visit_value, Value, ValueProto, VisitResult},
AsVisitor, DynVisitor,
@@ -9,75 +13,89 @@ use treaty::{
Flow,
};
+use crate::common::Blocking;
+
mock! {
- pub ValueVisitor<T: TypeName::MemberType, E>
+ pub ValueVisitor<T: TypeName::MemberType<E>, E: Environment>
where
- for<'a, 'ctx> TypeName::T<'a, 'ctx, T>: Sized
+ for<'a, 'ctx> TypeName::T<'a, 'ctx, T, E>: Sized
{
- pub fn visit<'a, 'ctx>(&'a mut self, value: &TypeName::T<'a, 'ctx, T>) -> VisitResult<()>;
+ pub fn visit<'a, 'ctx>(&'a mut self, value: &TypeName::T<'a, 'ctx, T, E>) -> VisitResult<()>;
}
}
+unsafe impl<T: TypeName::MemberType<E>, E: Environment, F: Bool> IsSend<F> for MockValueVisitor<T, E>
+where
+ for<'a, 'ctx> TypeName::T<'a, 'ctx, T, E>: Sized
+ {}
+unsafe impl<T: TypeName::MemberType<E>, E: Environment, F: Bool> IsSync<F> for MockValueVisitor<T, E>
+where
+ for<'a, 'ctx> TypeName::T<'a, 'ctx, T, E>: Sized
+ {}
+
any_trait! {
- impl['ctx, T, E] MockValueVisitor<T, E> = [
+ impl['ctx, T][E] MockValueVisitor<T, E> = [
ValueProto<T, E>
] where
- T: TypeName::MemberType + Ss,
- for<'a, 'b> TypeName::T<'a, 'b, T>: Sized,
- E: Effect,
+ T: TypeName::MemberType<E>,
+ for<'a, 'b> TypeName::T<'a, 'b, T, E>: Sized,
+ E: Environment,
}
-impl<'ctx, T: TypeName::MemberType, E: Effect> Value<'ctx, T, E> for MockValueVisitor<T, E>
+impl<'ctx, T: TypeName::MemberType<E>, E: Environment> Value<'ctx, T, E> for MockValueVisitor<T, E>
where
- for<'a, 'lt> TypeName::T<'a, 'lt, T>: Sized,
+ for<'a, 'lt> TypeName::T<'a, 'lt, T, E>: Sized,
{
fn visit<'a>(
&'a mut self,
- value: TypeName::T<'a, 'ctx, T>,
- ) -> ErasedEffective<'a, VisitResult<TypeName::T<'a, 'ctx, T>>, E>
+ value: TypeName::T<'a, 'ctx, T, E>,
+ ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, T, E>>, E>
where
- TypeName::T<'a, 'ctx, T>: Send,
'ctx: 'a,
{
- E::ready(match self.visit(&value) {
+ E::value(match self.visit(&value) {
VisitResult::Skipped(_) => VisitResult::Skipped(value),
VisitResult::Control(flow) => VisitResult::Control(flow),
- })
+ }).cast()
}
}
pub trait ValueVisitorExt<'ctx> {
fn visit_value_and_done<'a, T>(&'a mut self, value: T)
where
- T: TypeName::LowerType<'a, 'ctx>,
+ T: TypeName::LowerType<'a, 'ctx, Blocking>,
+ TypeName::HigherRanked<'a, 'ctx, T, Blocking>: TypeName::MemberType<Blocking>,
'ctx: 'a;
fn visit_value_and_skipped<'a, T>(&'a mut self, value: T)
where
- T: TypeName::LowerType<'a, 'ctx>,
+ T: TypeName::LowerType<'a, 'ctx, Blocking>,
+ TypeName::HigherRanked<'a, 'ctx, T, Blocking>: TypeName::MemberType<Blocking>,
'ctx: 'a;
}
impl<'ctx, U> ValueVisitorExt<'ctx> for U
where
- U: AsVisitor<'ctx>,
+ U: AsVisitor<'ctx, Blocking>,
{
fn visit_value_and_done<'a, T>(&'a mut self, value: T)
where
- T: TypeName::LowerType<'a, 'ctx>,
+ T: TypeName::LowerType<'a, 'ctx, Blocking>,
+ TypeName::HigherRanked<'a, 'ctx, T, Blocking>: TypeName::MemberType<Blocking>,
'ctx: 'a,
{
- let result = visit_value::<_, Blocking>(self.as_visitor(), value).value();
+ let result = visit_value::<_, Blocking>(self.as_visitor(), value).into_value();
assert_eq!(result, VisitResult::Control(Flow::Done));
}
fn visit_value_and_skipped<'a, T>(&'a mut self, value: T)
where
- T: TypeName::LowerType<'a, 'ctx>,
+ T: TypeName::LowerType<'a, 'ctx, Blocking>,
+ TypeName::HigherRanked<'a, 'ctx, T, Blocking>: TypeName::MemberType<Blocking>,
'ctx: 'a,
{
- let result = visit_value::<_, Blocking>(self.as_visitor(), value).value();
+ let result = visit_value::<_, Blocking>(self.as_visitor(), value).into_value();
assert_eq!(result.unit_skipped(), VisitResult::Skipped(()));
}