@@ -2332,6 +2332,47 @@ pub trait AssertHasDebugString<E> {
23322332 fn does_not_have_debug_string ( self , expected : E ) -> Self ;
23332333}
23342334
2335+ /// Mapping the subject into its debug string representation to do assertions on
2336+ /// its debug string.
2337+ ///
2338+ /// # Examples
2339+ ///
2340+ /// ```
2341+ /// use asserting::prelude::*;
2342+ ///
2343+ /// #[derive(Debug)]
2344+ /// struct Foo {
2345+ /// hello: String,
2346+ /// }
2347+ ///
2348+ /// let subject = Foo { hello: "World".into() };
2349+ ///
2350+ /// assert_that!(&subject).debug_string().contains("World");
2351+ /// assert_that!(&subject).debug_string().does_not_start_with("Bar");
2352+ /// ```
2353+ pub trait AssertDebugString < ' a , R > {
2354+ /// Maps the subject into its debug string representation to do assertions
2355+ /// on its debug string.
2356+ ///
2357+ /// # Examples
2358+ ///
2359+ /// ```
2360+ /// use asserting::prelude::*;
2361+ ///
2362+ /// #[derive(Debug)]
2363+ /// struct Foo {
2364+ /// hello: String,
2365+ /// }
2366+ ///
2367+ /// let subject = Foo { hello: "World".into() };
2368+ ///
2369+ /// assert_that!(&subject).debug_string().contains("World");
2370+ /// assert_that!(&subject).debug_string().does_not_start_with("Bar");
2371+ /// ```
2372+ #[ track_caller]
2373+ fn debug_string ( self ) -> Spec < ' a , String , R > ;
2374+ }
2375+
23352376/// Assert a type formatted into a display string.
23362377///
23372378/// The subject's type must implement `Display` and the expected type must
@@ -2409,6 +2450,57 @@ pub trait AssertHasDisplayString<E> {
24092450 fn does_not_have_display_string ( self , expected : E ) -> Self ;
24102451}
24112452
2453+ /// Mapping the subject into its display string representation to do assertions
2454+ /// on its display string.
2455+ ///
2456+ /// # Examples
2457+ ///
2458+ /// ```
2459+ /// use core::fmt::{self, Display};
2460+ /// use asserting::prelude::*;
2461+ ///
2462+ /// struct Foo {
2463+ /// hello: String,
2464+ /// }
2465+ ///
2466+ /// impl Display for Foo {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2467+ /// write!(f, "Hello, {}", self.hello)
2468+ /// }
2469+ /// }
2470+ ///
2471+ /// let subject = Foo { hello: "World".into() };
2472+ ///
2473+ /// assert_that!(&subject).display_string().is_equal_to("Hello, World");
2474+ /// assert_that!(&subject).display_string().does_not_end_with('!');
2475+ /// ```
2476+ pub trait AssertDisplayString < ' a , R > {
2477+ /// Maps the subject into its display string representation to do assertions
2478+ /// on its display string.
2479+ ///
2480+ /// # Examples
2481+ ///
2482+ /// ```
2483+ /// use core::fmt::{self, Display};
2484+ /// use asserting::prelude::*;
2485+ ///
2486+ /// struct Foo {
2487+ /// hello: String,
2488+ /// }
2489+ ///
2490+ /// impl Display for Foo {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2491+ /// write!(f, "Hello, {}", self.hello)
2492+ /// }
2493+ /// }
2494+ ///
2495+ /// let subject = Foo { hello: "World".into() };
2496+ ///
2497+ /// assert_that!(&subject).display_string().is_equal_to("Hello, World");
2498+ /// assert_that!(&subject).display_string().does_not_end_with('!');
2499+ /// ```
2500+ #[ track_caller]
2501+ fn display_string ( self ) -> Spec < ' a , String , R > ;
2502+ }
2503+
24122504/// Assert that a string contains a substring or character.
24132505///
24142506/// # Examples
0 commit comments