Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2354,10 +2354,10 @@ pub trait AssertHasDebugString<E> {
///
/// 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<E> {
pub trait AssertHasDisplayString<E> {
/// Verifies that a subject formatted for display results in the expected
/// string.
///
Expand All @@ -2378,10 +2378,10 @@ pub trait AssertHasDisplayMessage<E> {
///
/// 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.
Expand All @@ -2403,10 +2403,10 @@ pub trait AssertHasDisplayMessage<E> {
///
/// 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.
Expand Down
22 changes: 11 additions & 11 deletions src/equality.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -138,22 +138,22 @@ where

impl<E> Invertible for HasDebugString<E> {}

impl<S, E, R> AssertHasDisplayMessage<E> for Spec<'_, S, R>
impl<S, E, R> AssertHasDisplayString<E> for Spec<'_, S, R>
where
S: Display,
E: AsRef<str>,
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<S, E> Expectation<S> for HasDisplayMessage<E>
impl<S, E> Expectation<S> for HasDisplayString<E>
where
S: Display,
E: AsRef<str>,
Expand All @@ -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<E> Invertible for HasDisplayMessage<E> {}
impl<E> Invertible for HasDisplayString<E> {}
20 changes: 10 additions & 10 deletions src/error/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"#
Expand All @@ -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"
"#
Expand Down
8 changes: 4 additions & 4 deletions src/expectations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,12 @@ pub struct HasDebugString<E> {
pub expected: E,
}

/// Creates a [`HasDisplayMessage`] expectation.
pub fn has_display_message<E>(expected: E) -> HasDisplayMessage<E> {
HasDisplayMessage { expected }
/// Creates a [`HasDisplayString`] expectation.
pub fn has_display_string<E>(expected: E) -> HasDisplayString<E> {
HasDisplayString { expected }
}

pub struct HasDisplayMessage<E> {
pub struct HasDisplayString<E> {
pub expected: E,
}

Expand Down
Loading