Diffstat (limited to 'tests/walker_struct.rs')
-rw-r--r--tests/walker_struct.rs153
1 files changed, 73 insertions, 80 deletions
diff --git a/tests/walker_struct.rs b/tests/walker_struct.rs
index 6cb6e36..5898475 100644
--- a/tests/walker_struct.rs
+++ b/tests/walker_struct.rs
@@ -12,11 +12,7 @@ use treaty::{
use crate::common::{
builder::{EmptyError, MockBuilder},
- protocol::{
- sequence::{MockSequenceVisitor, SequenceScopeFactory},
- tag::MockTagVisitor,
- value::MockValueVisitor,
- },
+ protocol::{sequence::MockSequenceVisitor, tag::MockTagVisitor, value::MockValueVisitor},
};
mod common;
@@ -107,81 +103,78 @@ fn sequence_of_field_values() {
let mut visitor = MockSequenceVisitor::<Blocking>::new();
// Expect the sequence visitor to be used.
- visitor.expect_visit().once().return_const(
- (|_, scope| {
- // The struct should have exactly 2 fields.
- assert_eq!(scope.size_hint().value(), (2, Some(2)));
-
- // Get the first field value.
- {
- let mut visitor = MockBuilder::<(), (), EmptyError>::new();
-
- // Expect a bool value for the field.
- visitor
- .expect_traits_mut()
- .once()
- .with(eq(
- TypeNameId::of::<ValueProto<OwnedStatic<bool>, Blocking>>(),
- ))
- .returning(|_| {
- let mut visitor =
- MockValueVisitor::<OwnedStatic<bool>, Blocking>::new();
-
- // Expect true.
- visitor
- .expect_visit()
- .once()
- .with(eq(OwnedStatic(true)))
- .return_const(Flow::Done);
-
- Some(Box::new(visitor))
- });
-
- assert_eq!(
- scope
- .next(Builder::<Blocking>::as_visitor(&mut visitor))
- .value(),
- Flow::Continue
- );
- }
-
- // Get the second field value.
- {
- let mut visitor = MockBuilder::<(), (), EmptyError>::new();
-
- // Expect a i32 value.
- visitor
- .expect_traits_mut()
- .once()
- .with(eq(
- TypeNameId::of::<ValueProto<OwnedStatic<i32>, Blocking>>(),
- ))
- .returning(|_| {
- let mut visitor =
- MockValueVisitor::<OwnedStatic<i32>, Blocking>::new();
-
- // Expect a 42.
- visitor
- .expect_visit()
- .once()
- .with(eq(OwnedStatic(42)))
- .return_const(Flow::Done);
-
- Some(Box::new(visitor))
- });
-
- assert_eq!(
- scope
- .next(Builder::<Blocking>::as_visitor(&mut visitor))
- .value(),
- Flow::Done
- );
- }
-
- // We are done with the sequence of fields.
- VisitResult::Control(Flow::Done)
- }) as SequenceScopeFactory<Blocking>,
- );
+ visitor.expect_visit().once().returning(|scope| {
+ // The struct should have exactly 2 fields.
+ assert_eq!(scope.size_hint().value(), (2, Some(2)));
+
+ // Get the first field value.
+ {
+ let mut visitor = MockBuilder::<(), (), EmptyError>::new();
+
+ // Expect a bool value for the field.
+ visitor
+ .expect_traits_mut()
+ .once()
+ .with(eq(
+ TypeNameId::of::<ValueProto<OwnedStatic<bool>, Blocking>>(),
+ ))
+ .returning(|_| {
+ let mut visitor =
+ MockValueVisitor::<OwnedStatic<bool>, Blocking>::new();
+
+ // Expect true.
+ visitor
+ .expect_visit()
+ .once()
+ .with(eq(OwnedStatic(true)))
+ .return_const(Flow::Done);
+
+ Some(Box::new(visitor))
+ });
+
+ assert_eq!(
+ scope
+ .next(Builder::<Blocking>::as_visitor(&mut visitor))
+ .value(),
+ Flow::Continue
+ );
+ }
+
+ // Get the second field value.
+ {
+ let mut visitor = MockBuilder::<(), (), EmptyError>::new();
+
+ // Expect a i32 value.
+ visitor
+ .expect_traits_mut()
+ .once()
+ .with(eq(
+ TypeNameId::of::<ValueProto<OwnedStatic<i32>, Blocking>>(),
+ ))
+ .returning(|_| {
+ let mut visitor = MockValueVisitor::<OwnedStatic<i32>, Blocking>::new();
+
+ // Expect a 42.
+ visitor
+ .expect_visit()
+ .once()
+ .with(eq(OwnedStatic(42)))
+ .return_const(Flow::Done);
+
+ Some(Box::new(visitor))
+ });
+
+ assert_eq!(
+ scope
+ .next(Builder::<Blocking>::as_visitor(&mut visitor))
+ .value(),
+ Flow::Done
+ );
+ }
+
+ // We are done with the sequence of fields.
+ VisitResult::Control(Flow::Done)
+ });
Some(Box::new(visitor))
});