macro_rules! assert_writeable_eq {
    ($actual_writeable:expr, $expected_str:expr $(,)?) => { ... };
    ($actual_writeable:expr, $expected_str:expr, $($arg:tt)+) => { ... };
}
Expand description

Testing macros for types implementing Writeable. The first argument should be a Writeable, the second argument a string, and the third argument (*_parts_eq only) a list of parts ([(usize, usize, Part)]).

The macros tests for equality of string content, parts (*_parts_eq only), and verify the size hint.

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