Expand description
§Test Debug
and Display
implementations (with no_std
)
Testing of Debug and Display format implementations with support for no_std
via
assert_debug_fmt
and assert_display_fmt
macros.
§std
vs no_std
This crate builds in no_std
mode by default.
§Examples
Assume the following type Test
that we will use to provide some test data:
struct Test<'a>(&'a str, char, &'a str);
use core::fmt::{Debug, Write};
use test_format::assert_debug_fmt;
impl<'a> Debug for Test<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.0)?;
f.write_char(self.1)?;
f.write_str(self.2)
}
}
let input = Test("valid", ' ', "input");
assert_debug_fmt!(input, "valid input");
If the formatting fails, the assertion will fail:
ⓘ
let input = Test("valid", ' ', "inputs");
assert_debug_fmt!(input, "valid input"); // panics
Macros§
- assert_
debug_ fmt - Asserts that the
Debug
trait is correctly implemented. - assert_
display_ fmt - Asserts that the
Display
trait is correctly implemented.
Structs§
- Assert
Format - Functionality for testing
Debug
orDisplay
implementations.