use smol_bytes::Utf8Bytes;
use super::AnnotatedQuestion;
struct Ask {
lang: Option<Utf8Bytes>,
tenant: Option<u32>,
}
impl AnnotatedQuestion<Utf8Bytes> for Ask {
fn carried(&self) -> Option<&Utf8Bytes> {
self.lang.as_ref()
}
}
impl AnnotatedQuestion<u32> for Ask {
fn carried(&self) -> Option<&u32> {
self.tenant.as_ref()
}
}
#[test]
fn a_question_says_whether_it_was_already_told() {
let told = Ask {
lang: Some(Utf8Bytes::from_static("ja")),
tenant: None,
};
let silent = Ask {
lang: None,
tenant: None,
};
assert_eq!(
AnnotatedQuestion::<Utf8Bytes>::carried(&told).map(Utf8Bytes::as_str),
Some("ja"),
"a caller's own value is what the stage reads back"
);
assert!(
AnnotatedQuestion::<Utf8Bytes>::carried(&silent).is_none(),
"an unfilled seat is the gap the stage exists to fill"
);
}
#[test]
fn one_question_carries_as_many_annotations_as_it_has_seats() {
let asked = Ask {
lang: Some(Utf8Bytes::from_static("zh-Hant")),
tenant: Some(7),
};
assert_eq!(
AnnotatedQuestion::<Utf8Bytes>::carried(&asked).map(Utf8Bytes::as_str),
Some("zh-Hant")
);
assert_eq!(AnnotatedQuestion::<u32>::carried(&asked), Some(&7));
}