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);
}