Diffstat (limited to 'tests/common/protocol/recoverable.rs')
-rw-r--r--tests/common/protocol/recoverable.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/common/protocol/recoverable.rs b/tests/common/protocol/recoverable.rs
new file mode 100644
index 0000000..f1dab5c
--- /dev/null
+++ b/tests/common/protocol/recoverable.rs
@@ -0,0 +1,57 @@
+use mockall::mock;
+use treaty::{
+ any::{any_trait, TypeName},
+ effect::{Effect, Future},
+ protocol::{
+ visitor::{DynRecoverableScope, Recoverable, RecoverableProto, RecoverableScope},
+ DynWalker,
+ },
+ protocol::{
+ visitor::{
+ DynSequenceScope, RequestHint, RequestHintProto, Sequence, SequenceProto,
+ SequenceScope, Value, ValueProto, VisitResult,
+ },
+ DynVisitor,
+ },
+ Flow, Status,
+};
+
+pub type RecoverableScopeFactory<E> =
+ for<'a, 'ctx> fn(
+ &'ctx (),
+ DynRecoverableScope<'a, 'ctx, E>,
+ ) -> VisitResult<DynRecoverableScope<'a, 'ctx, E>>;
+
+mock! {
+ pub RecoverableVisitor<E> {
+ pub fn visit(&mut self) -> RecoverableScopeFactory<E>;
+ }
+}
+
+any_trait! {
+ impl['ctx, E] MockRecoverableVisitor<E> = [
+ RecoverableProto<E>
+ ] where
+ E: Effect,
+}
+
+impl<'ctx, E: Effect> Recoverable<'ctx, E> for MockRecoverableVisitor<E> {
+ fn visit<'a>(
+ &'a mut self,
+ scope: DynRecoverableScope<'a, 'ctx, E>,
+ ) -> Future<'a, VisitResult<DynRecoverableScope<'a, 'ctx, E>>, E> {
+ E::ready(self.visit()(&(), scope))
+ }
+}
+
+mock! {
+ pub RecoverableScopeVisitor<E> {
+ pub fn new_walk<'a, 'ctx>(&'a mut self, visitor: DynVisitor<'a, 'ctx>) -> Status;
+ }
+}
+
+impl<'ctx, E: Effect> RecoverableScope<'ctx, E> for MockRecoverableScopeVisitor<E> {
+ fn new_walk<'a>(&'a mut self, visitor: DynVisitor<'a, 'ctx>) -> Future<'a, Status, E> {
+ E::ready(self.new_walk(visitor))
+ }
+}