macro_rules! assert_writeable_eq { ($actual_writeable:expr, $expected_str:expr $(,)?) => { ... }; ($actual_writeable:expr, $expected_str:expr, $($arg:tt)+) => { ... }; (@internal, $actual_writeable:expr, $expected_str:expr, $($arg:tt)+) => { ... }; }
Expand description
Testing macros for types implementing Writeable
.
Arguments, in order:
- The
Writeable
under test - The expected string value
*_parts_eq
only: a list of parts ([(start, end, Part)]
)
Any remaining arguments get passed to format!
The macros tests the following:
- Equality of string content
- Equality of parts (
*_parts_eq
only) - Validity of size hint
- Reflexivity of
cmp_bytes
and order against largest and smallest strings
ยงExamples
const WORD: Part = Part {
category: "foo",
value: "word",
};
struct Demo;
impl Writeable for Demo {
fn write_to_parts<S: writeable::PartsWrite + ?Sized>(
&self,
sink: &mut S,
) -> fmt::Result {
sink.with_part(WORD, |w| w.write_str("foo"))
}
fn writeable_length_hint(&self) -> LengthHint {
LengthHint::exact(3)
}
}
writeable::impl_display_with_writeable!(Demo);
assert_writeable_eq!(&Demo, "foo");
assert_writeable_eq!(&Demo, "foo", "Message: {}", "Hello World");
assert_writeable_parts_eq!(&Demo, "foo", [(0, 3, WORD)]);
assert_writeable_parts_eq!(
&Demo,
"foo",
[(0, 3, WORD)],
"Message: {}",
"Hello World"
);