Macro writeable::assert_writeable_eq

source ·
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:

  1. The Writeable under test
  2. The expected string value
  3. *_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

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