Diffstat (limited to 'tests/walker_struct.rs')
| -rw-r--r-- | tests/walker_struct.rs | 124 |
1 files changed, 75 insertions, 49 deletions
diff --git a/tests/walker_struct.rs b/tests/walker_struct.rs index 01ae867..833b2dd 100644 --- a/tests/walker_struct.rs +++ b/tests/walker_struct.rs @@ -1,5 +1,8 @@ use effectful::{ - bound::{DynamicShim, ForceDynamic, Dynamic}, effective::Effective, environment::{Environment, NativeForm, DynBind}, SendSync + bound::{Dynamic, DynamicShim, ForceDynamic}, + effective::Effective, + environment::{DynBind, Environment, NativeForm}, + SendSync, }; use mockall::predicate::eq; use treaty::{ @@ -29,7 +32,7 @@ struct X { struct Info; // This gives the struct walker enough information to walk the X struct. -impl<'ctx, M, E: Environment> StructTypeInfo<'ctx, M, E> for Info +impl<'ctx, M, E: Environment> StructTypeInfo<'ctx, M, E> for Info where Dynamic<OwnedStatic<bool>>: DynBind<E>, Dynamic<OwnedStatic<i32>>: DynBind<E>, @@ -49,42 +52,44 @@ where value: &'ctx Self::T, mut visitor: DynVisitor<'a, 'ctx, E>, ) -> NativeForm<'a, Result<Flow, Self::FieldError>, E> { - E::future(unsafe { ForceDynamic::new(async move { - match index { - // A real impl would be expected to tag these values with the field name. - 0 => { - // Basic visit for the field value. - let obj = visitor - .upcast_mut::<ValueProto<OwnedStatic<bool>, E>>() - .unwrap(); - - // Emit the field value. - assert_eq!( - obj.visit(OwnedStatic(value.a)).into_future().await, - Flow::Done.into() - ); - - // There are more fields. - Ok(Flow::Continue) + E::future(unsafe { + ForceDynamic::new(async move { + match index { + // A real impl would be expected to tag these values with the field name. + 0 => { + // Basic visit for the field value. + let obj = visitor + .upcast_mut::<ValueProto<OwnedStatic<bool>, E>>() + .unwrap(); + + // Emit the field value. + assert_eq!( + obj.visit(OwnedStatic(value.a)).into_future().await, + Flow::Done.into() + ); + + // There are more fields. + Ok(Flow::Continue) + } + 1 => { + // Basic visit for the field value. + let obj = visitor + .upcast_mut::<ValueProto<OwnedStatic<i32>, E>>() + .unwrap(); + + // Emit the field value. + assert_eq!( + obj.visit(OwnedStatic(value.b)).into_future().await, + Flow::Done.into() + ); + + // There are no more fields. + Ok(Flow::Done) + } + _ => Ok(Flow::Done), } - 1 => { - // Basic visit for the field value. - let obj = visitor - .upcast_mut::<ValueProto<OwnedStatic<i32>, E>>() - .unwrap(); - - // Emit the field value. - assert_eq!( - obj.visit(OwnedStatic(value.b)).into_future().await, - Flow::Done.into() - ); - - // There are no more fields. - Ok(Flow::Done) - } - _ => Ok(Flow::Done), - } - })}) + }) + }) .cast() } } @@ -156,9 +161,10 @@ fn sequence_of_field_values() { visitor .expect_traits_mut() .once() - .with(eq( - TypeNameId::of::<ValueProto<OwnedStatic<i32>, Blocking>, Blocking>(), - )) + .with(eq(TypeNameId::of::< + ValueProto<OwnedStatic<i32>, Blocking>, + Blocking, + >())) .returning(|_| { let mut visitor = MockValueVisitor::<OwnedStatic<i32>, Blocking>::new(); @@ -190,7 +196,9 @@ fn sequence_of_field_values() { // Walk the struct. assert_eq!( - walker.walk(AsVisitor::as_visitor(&mut builder)).into_value(), + walker + .walk(AsVisitor::as_visitor(&mut builder)) + .into_value(), Ok(()) ); } @@ -219,7 +227,10 @@ fn has_struct_tag() { .expect_traits_mut() .once() .in_sequence(&mut seq) - .with(eq(TypeNameId::of::<TagProto<tags::Struct, Blocking>, Blocking>())) + .with(eq(TypeNameId::of::< + TagProto<tags::Struct, Blocking>, + Blocking, + >())) .returning(|_| { let mut visitor = MockTagVisitor::<tags::Struct, Blocking>::new(); @@ -227,7 +238,10 @@ fn has_struct_tag() { let mut visitor = MockBuilder::<(), (), (), Blocking>::new(); // Walk the noop walker so there isn't an error. - assert_eq!(walker.walk(DynVisitor(&mut visitor)).into_value(), Flow::Done); + assert_eq!( + walker.walk(DynVisitor(&mut visitor)).into_value(), + Flow::Done + ); // We are done, the walker should now stop early. VisitResult::Control(Flow::Done) @@ -238,7 +252,9 @@ fn has_struct_tag() { // Walk the struct. assert_eq!( - walker.walk(AsVisitor::as_visitor(&mut builder)).into_value(), + walker + .walk(AsVisitor::as_visitor(&mut builder)) + .into_value(), Ok(()) ); } @@ -269,7 +285,9 @@ fn has_map_backup_tag() { .expect_traits_mut() .once() .in_sequence(&mut seq) - .with(eq(TypeNameId::of::<TagProto<tags::Map, Blocking>, Blocking>())) + .with(eq( + TypeNameId::of::<TagProto<tags::Map, Blocking>, Blocking>(), + )) .returning(|_| { let mut visitor = MockTagVisitor::<tags::Map, Blocking>::new(); @@ -277,7 +295,10 @@ fn has_map_backup_tag() { let mut visitor = MockBuilder::<(), (), (), Blocking>::new(); // Walk the noop walker so there isn't an error. - assert_eq!(walker.walk(DynVisitor(&mut visitor)).into_value(), Flow::Done); + assert_eq!( + walker.walk(DynVisitor(&mut visitor)).into_value(), + Flow::Done + ); // We are done, the walker should now stop early. VisitResult::Control(Flow::Done) @@ -288,7 +309,9 @@ fn has_map_backup_tag() { // Walk the struct. assert_eq!( - walker.walk(AsVisitor::as_visitor(&mut builder)).into_value(), + walker + .walk(AsVisitor::as_visitor(&mut builder)) + .into_value(), Ok(()) ); } @@ -318,7 +341,8 @@ fn borrowed_value_directly() { .once() .in_sequence(&mut seq) .with(eq(TypeNameId::of::< - ValueProto<BorrowedStaticHrt<X>, Blocking>, Blocking + ValueProto<BorrowedStaticHrt<X>, Blocking>, + Blocking, >())) .returning(|_| { let mut visitor = MockValueVisitor::<BorrowedStaticHrt<X>, Blocking>::new(); @@ -341,7 +365,9 @@ fn borrowed_value_directly() { // Walk the struct. assert_eq!( - walker.walk(AsVisitor::as_visitor(&mut builder)).into_value(), + walker + .walk(AsVisitor::as_visitor(&mut builder)) + .into_value(), Ok(()) ); } |