From ae462c371a4025bc34e4cb407403cabf5ab3c050 Mon Sep 17 00:00:00 2001 From: haraldmaida Date: Fri, 20 Feb 2026 02:45:06 +0100 Subject: [PATCH] refactor!: rename assertions `has_display_message` to `has_display_string` and `does_not_have_display_message` to `does_not_have_display_string` --- README.md | 8 ++++---- src/assertions.rs | 14 +++++++------- src/equality.rs | 22 +++++++++++----------- src/error/tests.rs | 20 ++++++++++---------- src/expectations.rs | 8 ++++---- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 59874da..123a015 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 333d5b6..d6bf56d 100644 --- a/src/assertions.rs +++ b/src/assertions.rs @@ -2354,10 +2354,10 @@ pub trait AssertHasDebugMessage { /// /// 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 c89678b..cd2890f 100644 --- a/src/equality.rs +++ b/src/equality.rs @@ -1,12 +1,12 @@ //! Implementation of the equality assertions. use crate::assertions::{ - AssertEquality, AssertHasDebugMessage, AssertHasDisplayMessage, AssertSameAs, + AssertEquality, AssertHasDebugMessage, AssertHasDisplayString, AssertSameAs, }; use crate::colored::{mark_diff, mark_diff_str}; use crate::expectations::{ - has_debug_message, has_display_message, is_equal_to, is_same_as, not, HasDebugMessage, - HasDisplayMessage, IsEqualTo, IsSameAs, + has_debug_message, has_display_string, is_equal_to, is_same_as, not, HasDebugMessage, + 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 HasDebugMessage {} -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 0155b2f..bbb4ff6 100644 --- a/src/error/tests.rs +++ b/src/error/tests.rs @@ -98,28 +98,28 @@ fn verify_error_does_not_have_debug_message_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 ccc4c6d..8af4739 100644 --- a/src/expectations.rs +++ b/src/expectations.rs @@ -646,12 +646,12 @@ pub struct HasDebugMessage { 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, }