Diffstat (limited to 'tests/builder_value.rs')
| -rw-r--r-- | tests/builder_value.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/builder_value.rs b/tests/builder_value.rs new file mode 100644 index 0000000..92f3450 --- /dev/null +++ b/tests/builder_value.rs @@ -0,0 +1,38 @@ +mod common; + +use treaty::{ + any::OwnedStatic, + effect::blocking::Blocking, + protocol::{ + visitor::{request_hint, ValueProto}, + DynWalker, + }, + BuildExt as _, Builder as _, Flow, +}; + +use crate::common::protocol::hint::MockHintWalker; + +#[test] +fn value_builder_gives_value_protocol_as_hint() { + // Create a builder for a i32. + let mut builder = i32::new_builder(); + + // Expect the value builder to hint the value protocol with a owned i32. + let mut walker = MockHintWalker::<ValueProto<OwnedStatic<i32>, Blocking>>::new(); + walker.expect_hint().once().returning(|visitor, ()| { + // Fulfill the hint by visiting with a i32 value. + assert_eq!(visitor.visit(OwnedStatic(42)).value(), Flow::Done.into()); + + // We are done as the walker. + Flow::Done + }); + + // Request a hint from the i32 builder for what protocol to use. + assert_eq!( + request_hint::<Blocking>(builder.as_visitor(), DynWalker(&mut walker)).value(), + Flow::Done.into() + ); + + // The builder should have the value. + assert_eq!(builder.build().value().unwrap(), 42); +} |