Diffstat (limited to 'tests/walker_struct.rs')
| -rw-r--r-- | tests/walker_struct.rs | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/tests/walker_struct.rs b/tests/walker_struct.rs index b467a4c..26f8935 100644 --- a/tests/walker_struct.rs +++ b/tests/walker_struct.rs @@ -1,12 +1,12 @@ use mockall::predicate::eq; use treaty::{ any::{BorrowedStatic, BorrowedStaticHrt, OwnedStatic, TypeNameId}, - effect::{Blocking, Effect, Future}, + effect::{Blocking, Effect, Future, ReadyValue}, protocol::{ visitor::{tags, SequenceProto, TagConst, TagProto, ValueProto, VisitResult}, DynVisitor, }, - walkers::core::r#struct::{StructTypeInfo, StructWalker}, + walkers::core::r#struct::{StaticType, StructTypeInfo, StructWalker}, Builder, DefaultMode, Flow, Walker, }; @@ -36,6 +36,8 @@ impl<'ctx, M> StructTypeInfo<'ctx, M> for Info { type FieldError = (); + type S = StaticType; + type T = X; fn walk_field<'a, E: Effect>( @@ -53,7 +55,7 @@ impl<'ctx, M> StructTypeInfo<'ctx, M> for Info { .unwrap(); // Emit the field value. - obj.visit(OwnedStatic(value.a)).await; + assert_eq!(obj.visit(OwnedStatic(value.a)).await, Flow::Done.into()); // There are more fields. Ok(Flow::Continue) @@ -65,7 +67,7 @@ impl<'ctx, M> StructTypeInfo<'ctx, M> for Info { .unwrap(); // Emit the field value. - obj.visit(OwnedStatic(value.b)).await; + assert_eq!(obj.visit(OwnedStatic(value.b)).await, Flow::Done.into()); // There are no more fields. Ok(Flow::Done) @@ -86,7 +88,7 @@ fn sequence_of_field_values() { let value = X { a: true, b: 42 }; // The struct walker using the info we provided about the struct. - let walker = StructWalker::<X, Info, DefaultMode, Blocking>::new(&value); + let walker = StructWalker::<Info, _, DefaultMode, Blocking>::new(&value); let mut builder = MockBuilder::<(), (), ()>::new(); @@ -102,7 +104,7 @@ fn sequence_of_field_values() { visitor.expect_visit().once().return_const( (|_, scope| { // The struct should have exactly 2 fields. - assert_eq!(scope.size_hint().into_inner(), (2, Some(2))); + assert_eq!(scope.size_hint().value(), (2, Some(2))); // Get the first field value. { @@ -129,7 +131,7 @@ fn sequence_of_field_values() { Some(Box::new(visitor)) }); - scope.next(Builder::<Blocking>::as_visitor(&mut visitor)); + assert_eq!(scope.next(Builder::<Blocking>::as_visitor(&mut visitor)).value(), Flow::Continue); } // Get the second field value. @@ -157,7 +159,7 @@ fn sequence_of_field_values() { Some(Box::new(visitor)) }); - scope.next(Builder::<Blocking>::as_visitor(&mut visitor)); + assert_eq!(scope.next(Builder::<Blocking>::as_visitor(&mut visitor)).value(), Flow::Done); } // We are done with the sequence of fields. @@ -175,7 +177,7 @@ fn sequence_of_field_values() { assert_eq!( walker .walk(Builder::<Blocking>::as_visitor(&mut builder)) - .into_inner(), + .value(), Ok(()) ); } @@ -186,7 +188,7 @@ fn has_struct_tag() { let value = X { a: true, b: 42 }; // The struct walker using the info we provided about the struct. - let walker = StructWalker::<X, Info, DefaultMode, Blocking>::new(&value); + let walker = StructWalker::<Info, _, DefaultMode, Blocking>::new(&value); let mut builder = MockBuilder::<(), (), ()>::new(); @@ -212,10 +214,7 @@ fn has_struct_tag() { let mut visitor = MockBuilder::<(), (), ()>::new(); // Walk the noop walker so there isn't an error. - assert_eq!( - walker.walk(DynVisitor(&mut visitor)).into_inner(), - Flow::Done - ); + assert_eq!(walker.walk(DynVisitor(&mut visitor)).value(), Flow::Done); // We are done, the walker should now stop early. VisitResult::Control(Flow::Done) @@ -228,7 +227,7 @@ fn has_struct_tag() { assert_eq!( walker .walk(Builder::<Blocking>::as_visitor(&mut builder)) - .into_inner(), + .value(), Ok(()) ); } @@ -239,7 +238,7 @@ fn has_map_backup_tag() { let value = X { a: true, b: 42 }; // The struct walker using the info we provided about the struct. - let walker = StructWalker::<X, Info, DefaultMode, Blocking>::new(&value); + let walker = StructWalker::<Info, _, DefaultMode, Blocking>::new(&value); let mut builder = MockBuilder::<(), (), ()>::new(); @@ -267,10 +266,7 @@ fn has_map_backup_tag() { let mut visitor = MockBuilder::<(), (), ()>::new(); // Walk the noop walker so there isn't an error. - assert_eq!( - walker.walk(DynVisitor(&mut visitor)).into_inner(), - Flow::Done - ); + assert_eq!(walker.walk(DynVisitor(&mut visitor)).value(), Flow::Done); // We are done, the walker should now stop early. VisitResult::Control(Flow::Done) @@ -283,7 +279,7 @@ fn has_map_backup_tag() { assert_eq!( walker .walk(Builder::<Blocking>::as_visitor(&mut builder)) - .into_inner(), + .value(), Ok(()) ); } @@ -294,7 +290,7 @@ fn borrowed_value_directly() { let value = X { a: true, b: 42 }; // The struct walker using the info we provided about the struct. - let walker = StructWalker::<X, Info, DefaultMode, Blocking>::new(&value); + let walker = StructWalker::<Info, _, DefaultMode, Blocking>::new(&value); let mut builder = MockBuilder::<(), (), ()>::new(); @@ -338,7 +334,7 @@ fn borrowed_value_directly() { assert_eq!( walker .walk(Builder::<Blocking>::as_visitor(&mut builder)) - .into_inner(), + .value(), Ok(()) ); } |