diff --git a/README.md b/README.md index 847f585..234dcaf 100644 --- a/README.md +++ b/README.md @@ -371,10 +371,10 @@ for types that implement `core::fmt::Debug`: for types that implement `core::fmt::Display`: -| assertion | description | -|-------------------------------|------------------------------------------------------------------------------| -| has_display_message | verify that a type formatted for display is equal to the expected string | -| does_not_have_display_message | verify that a type formatted for display is not equal to the expected string | +| assertion | description | +|------------------------------|------------------------------------------------------------------------------| +| has_display_string | verify that a type formatted for display is equal to the expected string | +| does_not_have_display_string | verify that a type formatted for display is not equal to the expected string | ### Emptiness diff --git a/src/assertions.rs b/src/assertions.rs index ff8e6ba..cdfe63c 100644 --- a/src/assertions.rs +++ b/src/assertions.rs @@ -2354,10 +2354,10 @@ pub trait AssertHasDebugString { /// /// let subject = Foo { hello: "World".into() }; /// -/// assert_that!(&subject).has_display_message("Hello World"); -/// assert_that!(&subject).does_not_have_display_message("Foo { hello: \"World\" }"); +/// assert_that!(&subject).has_display_string("Hello World"); +/// assert_that!(&subject).does_not_have_display_string("Foo { hello: \"World\" }"); /// ``` -pub trait AssertHasDisplayMessage { +pub trait AssertHasDisplayString { /// Verifies that a subject formatted for display results in the expected /// string. /// @@ -2378,10 +2378,10 @@ pub trait AssertHasDisplayMessage { /// /// let subject = Foo { hello: "World".into() }; /// - /// assert_that!(&subject).has_display_message("Hello World"); + /// assert_that!(&subject).has_display_string("Hello World"); /// ``` #[track_caller] - fn has_display_message(self, expected: E) -> Self; + fn has_display_string(self, expected: E) -> Self; /// Verifies that a subject formatted for display does not result in the /// expected string. @@ -2403,10 +2403,10 @@ pub trait AssertHasDisplayMessage { /// /// let subject = Foo { hello: "World".into() }; /// - /// assert_that!(&subject).does_not_have_display_message("Foo { hello: \"World\" }"); + /// assert_that!(&subject).does_not_have_display_string("Foo { hello: \"World\" }"); /// ``` #[track_caller] - fn does_not_have_display_message(self, expected: E) -> Self; + fn does_not_have_display_string(self, expected: E) -> Self; } /// Assert that a string contains a substring or character. diff --git a/src/equality.rs b/src/equality.rs index cf0b4fd..d580f23 100644 --- a/src/equality.rs +++ b/src/equality.rs @@ -1,12 +1,12 @@ //! Implementation of the equality assertions. use crate::assertions::{ - AssertEquality, AssertHasDebugString, AssertHasDisplayMessage, AssertSameAs, + AssertEquality, AssertHasDebugString, AssertHasDisplayString, AssertSameAs, }; use crate::colored::{mark_diff, mark_diff_str}; use crate::expectations::{ - has_debug_string, has_display_message, is_equal_to, is_same_as, not, HasDebugString, - HasDisplayMessage, IsEqualTo, IsSameAs, + has_debug_string, has_display_string, is_equal_to, is_same_as, not, HasDebugString, + HasDisplayString, IsEqualTo, IsSameAs, }; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; use crate::std::fmt::{Debug, Display}; @@ -138,22 +138,22 @@ where impl Invertible for HasDebugString {} -impl AssertHasDisplayMessage for Spec<'_, S, R> +impl AssertHasDisplayString for Spec<'_, S, R> where S: Display, E: AsRef, R: FailingStrategy, { - fn has_display_message(self, expected: E) -> Self { - self.expecting(has_display_message(expected)) + fn has_display_string(self, expected: E) -> Self { + self.expecting(has_display_string(expected)) } - fn does_not_have_display_message(self, expected: E) -> Self { - self.expecting(not(has_display_message(expected))) + fn does_not_have_display_string(self, expected: E) -> Self { + self.expecting(not(has_display_string(expected))) } } -impl Expectation for HasDisplayMessage +impl Expectation for HasDisplayString where S: Display, E: AsRef, @@ -173,9 +173,9 @@ where let expected = self.expected.as_ref(); let (marked_actual, marked_expected) = mark_diff_str(&actual.to_string(), expected, format); format!( - "expected {expression} to {not}have display message {expected:?}\n but was: \"{marked_actual}\"\n expected: {not}\"{marked_expected}\"", + "expected {expression} to {not}have a display string equal to {expected:?}\n but was: \"{marked_actual}\"\n expected: {not}\"{marked_expected}\"", ) } } -impl Invertible for HasDisplayMessage {} +impl Invertible for HasDisplayString {} diff --git a/src/error/tests.rs b/src/error/tests.rs index 1d11bd7..c7670ce 100644 --- a/src/error/tests.rs +++ b/src/error/tests.rs @@ -98,28 +98,28 @@ fn verify_error_does_not_have_debug_string_fails() { } #[test] -fn error_has_display_message() { +fn error_has_display_string() { let error = SuperError { source: SourceError::Bar, }; - assert_that(error).has_display_message("super-error caused by bar error"); + assert_that(error).has_display_string("super-error caused by bar error"); } #[test] -fn verify_error_has_display_message_fails() { +fn verify_error_has_display_string_fails() { let error = SuperError { source: SourceError::Foo, }; let failures = verify_that(error) - .has_display_message("super-error caused by bar error") + .has_display_string("super-error caused by bar error") .display_failures(); assert_eq!( failures, &[ - r#"expected subject to have display message "super-error caused by bar error" + r#"expected subject to have a display string equal to "super-error caused by bar error" but was: "super-error caused by foo error" expected: "super-error caused by bar error" "# @@ -128,28 +128,28 @@ fn verify_error_has_display_message_fails() { } #[test] -fn error_does_not_have_display_message() { +fn error_does_not_have_display_string() { let error = SuperError { source: SourceError::Bar, }; - assert_that(error).does_not_have_display_message("super-error caused by foo error"); + assert_that(error).does_not_have_display_string("super-error caused by foo error"); } #[test] -fn verify_error_does_not_have_display_message_fails() { +fn verify_error_does_not_have_display_string_fails() { let error = SuperError { source: SourceError::Foo, }; let failures = verify_that(error) - .does_not_have_display_message("super-error caused by foo error") + .does_not_have_display_string("super-error caused by foo error") .display_failures(); assert_eq!( failures, &[ - r#"expected subject to not have display message "super-error caused by foo error" + r#"expected subject to not have a display string equal to "super-error caused by foo error" but was: "super-error caused by foo error" expected: not "super-error caused by foo error" "# diff --git a/src/expectations.rs b/src/expectations.rs index 13e1b71..48ccd2c 100644 --- a/src/expectations.rs +++ b/src/expectations.rs @@ -646,12 +646,12 @@ pub struct HasDebugString { pub expected: E, } -/// Creates a [`HasDisplayMessage`] expectation. -pub fn has_display_message(expected: E) -> HasDisplayMessage { - HasDisplayMessage { expected } +/// Creates a [`HasDisplayString`] expectation. +pub fn has_display_string(expected: E) -> HasDisplayString { + HasDisplayString { expected } } -pub struct HasDisplayMessage { +pub struct HasDisplayString { pub expected: E, }