Diffstat (limited to 'tests/common/protocol/sequence.rs')
-rw-r--r--tests/common/protocol/sequence.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/common/protocol/sequence.rs b/tests/common/protocol/sequence.rs
new file mode 100644
index 0000000..ff4249f
--- /dev/null
+++ b/tests/common/protocol/sequence.rs
@@ -0,0 +1,58 @@
+use mockall::mock;
+use treaty::{
+ any::{any_trait, TypeName},
+ effect::{Effect, Future},
+ protocol::DynWalker,
+ protocol::{
+ visitor::{
+ DynSequenceScope, RequestHint, RequestHintProto, Sequence, SequenceProto,
+ SequenceScope, Value, ValueProto, VisitResult,
+ },
+ DynVisitor,
+ },
+ Flow,
+};
+
+pub type SequenceScopeFactory<E> = for<'a, 'ctx> fn(
+ &'ctx (),
+ DynSequenceScope<'a, 'ctx, E>,
+) -> VisitResult<DynSequenceScope<'a, 'ctx, E>>;
+
+mock! {
+ pub SequenceVisitor<E> {
+ pub fn visit(&mut self) -> SequenceScopeFactory<E>;
+ }
+}
+
+any_trait! {
+ impl['ctx, E] MockSequenceVisitor<E> = [
+ SequenceProto<E>
+ ] where
+ E: Effect,
+}
+
+impl<'ctx, E: Effect> Sequence<'ctx, E> for MockSequenceVisitor<E> {
+ fn visit<'a>(
+ &'a mut self,
+ scope: DynSequenceScope<'a, 'ctx, E>,
+ ) -> Future<'a, VisitResult<DynSequenceScope<'a, 'ctx, E>>, E> {
+ E::ready(self.visit()(&(), scope))
+ }
+}
+
+mock! {
+ pub SequenceScopeVisitor<E> {
+ pub fn size_hint(&mut self) -> (usize, Option<usize>);
+ pub fn next<'a, 'ctx>(&'a mut self, visitor: DynVisitor<'a, 'ctx>) -> Flow;
+ }
+}
+
+impl<'ctx, E: Effect> SequenceScope<'ctx, E> for MockSequenceScopeVisitor<E> {
+ fn size_hint(&mut self) -> Future<'_, (usize, Option<usize>), E> {
+ E::ready(self.size_hint())
+ }
+
+ fn next<'a>(&'a mut self, visitor: DynVisitor<'a, 'ctx>) -> Future<'a, Flow, E> {
+ E::ready(self.next(visitor))
+ }
+}