Crate test_format

source ·
Expand description

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, allowing for testing of Debug implementations. If you wish to test Display implementations, enable the std crate feature.

§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§

Structs§