Diffstat (limited to 'tests/protocol_visitor_value.rs')
| -rw-r--r-- | tests/protocol_visitor_value.rs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/tests/protocol_visitor_value.rs b/tests/protocol_visitor_value.rs index 821b9f6..cd835ea 100644 --- a/tests/protocol_visitor_value.rs +++ b/tests/protocol_visitor_value.rs @@ -4,13 +4,13 @@ use common::protocol::{ hint::{KnownFactory, MockHintWalker}, value::MockValueVisitor, }; +use effectful::is_send_sync; use mockall::predicate::eq; use treaty::{ any::{ AnyTrait, BorrowedStatic, BorrowedStaticHrt, OwnedStatic, TempBorrowedMutStatic, TempBorrowedMutStaticHrt, TypeNameId, }, - effect::blocking::Blocking, protocol::{ visitor::{visit_value, Value, ValueKnown, ValueProto, VisitResult}, walker::hint::Hint, @@ -19,6 +19,8 @@ use treaty::{ Flow, }; +use crate::common::Blocking; + mod common; /// Tests support for custom type support in the value protocol. @@ -30,6 +32,8 @@ fn custom_value_type() { #[derive(PartialEq, Debug, Clone)] struct MyValue; + is_send_sync!(MyValue); + let mut mock = MockValueVisitor::<OwnedStatic<MyValue>, Blocking>::new(); // Expect the visit method to be called once with the custom type. @@ -43,14 +47,14 @@ fn custom_value_type() { let visitor: &mut dyn Value<OwnedStatic<MyValue>, Blocking> = &mut mock; // Visit the value. - let result = visitor.visit(OwnedStatic(MyValue)).value(); + let result = visitor.visit(OwnedStatic(MyValue)).into_value(); // The mock returns that it is done. assert_eq!(result, VisitResult::Control(Flow::Done)); - let visitor: &mut (dyn AnyTrait + Send + Sync) = &mut mock; + let visitor: &mut dyn AnyTrait<Blocking> = &mut mock; assert_eq!( - visit_value::<_, Blocking>(DynVisitor(visitor), OwnedStatic(MyValue)).value(), + visit_value::<_, Blocking>(DynVisitor(visitor), OwnedStatic(MyValue)).into_value(), VisitResult::Control(Flow::Done) ); } @@ -83,13 +87,13 @@ fn borrowed_value() { // Visit the borrowed value. assert_eq!( - visitor.visit(BorrowedStatic(value)).value(), + visitor.visit(BorrowedStatic(value)).into_value(), Flow::Done.into() ); - let visitor: &mut (dyn AnyTrait + Send + Sync) = &mut mock; + let visitor: &mut dyn AnyTrait<Blocking> = &mut mock; assert_eq!( - visit_value::<_, Blocking>(DynVisitor(visitor), BorrowedStatic(value)).value(), + visit_value::<_, Blocking>(DynVisitor(visitor), BorrowedStatic(value)).into_value(), VisitResult::Control(Flow::Done) ); } @@ -130,7 +134,7 @@ fn temp_borrowed_value() { // Visit the context to show we can shorten the lifetime. // This would also force the lifetime to be to long if this wasn't the Temp form. assert_eq!( - visitor.visit(TempBorrowedMutStatic(value)).value(), + visitor.visit(TempBorrowedMutStatic(value)).into_value(), Flow::Done.into() ); @@ -141,7 +145,7 @@ fn temp_borrowed_value() { // Visit the temp value. assert_eq!( - visitor.visit(TempBorrowedMutStatic(&mut value)).value(), + visitor.visit(TempBorrowedMutStatic(&mut value)).into_value(), Flow::Done.into() ); } @@ -183,19 +187,19 @@ fn all_visit_results() { // Visit can return a done. assert_eq!( - visitor.visit(OwnedStatic(0)).value(), + visitor.visit(OwnedStatic(0)).into_value(), VisitResult::Control(Flow::Done) ); // Visit can return an error signal. assert_eq!( - visitor.visit(OwnedStatic(1)).value(), + visitor.visit(OwnedStatic(1)).into_value(), VisitResult::Control(Flow::Err) ); // Visit can return a continue. assert_eq!( - visitor.visit(OwnedStatic(2)).value(), + visitor.visit(OwnedStatic(2)).into_value(), VisitResult::Control(Flow::Continue) ); @@ -203,7 +207,7 @@ fn all_visit_results() { // This is for runtime visit support checking. // The value should be given back, but that's not forced. assert_eq!( - visitor.visit(OwnedStatic(3)).value(), + visitor.visit(OwnedStatic(3)).into_value(), VisitResult::Skipped(OwnedStatic(3)) ); } @@ -215,7 +219,7 @@ fn value_proto() { let id = TypeId::of::<ValueProto<OwnedStatic<i32>, Blocking>>(); // The type id for the lifetime containing value protocol trait object. - let name_id = TypeNameId::of_lower::<dyn Value<OwnedStatic<i32>, Blocking> + Send + Sync>(); + let name_id = TypeNameId::of_lower::<dyn Value<OwnedStatic<i32>, Blocking>, Blocking>(); // They should be the same. assert_eq!(id, name_id.into_type_id()); @@ -241,7 +245,7 @@ fn as_hint() { // The value protocol has no hint data, and it has no known data. assert_eq!( - walker.known(&()).value(), + walker.known(&()).into_value(), Ok(ValueKnown { preview: Some(&OwnedStatic(42)) }) @@ -263,7 +267,7 @@ fn as_hint() { // The value protocol has no hint data, and it has no known data. assert_eq!( - walker.known(&()).value(), + walker.known(&()).into_value(), Ok(ValueKnown { preview: Some(&BorrowedStatic(&42)) }) @@ -281,6 +285,6 @@ fn as_hint() { let walker: &mut dyn Hint<ValueProto<TempBorrowedMutStaticHrt<i32>, Blocking>> = &mut mock; // The value protocol has no hint data, and it has no known data. - assert_eq!(walker.known(&()).value(), Ok(ValueKnown { preview: None })); + assert_eq!(walker.known(&()).into_value(), Ok(ValueKnown { preview: None })); } } |